wmhysu

   :: 首页  :: 新随笔  :: 联系 ::  :: 管理

目前只实现了单表查询,多表连接会在后续

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace GreatWall.QueryFrm
{
 /// <summary>
 /// Query 的摘要说明。
 /// </summary>
 public class Query : System.Windows.Forms.Form
 {
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.Button button2;


  //***********************************************
  private DataGridTableStyle[] TableStyles; //样式表数组
  private System.Data.DataTable[] Tables;   //样式表对应的table数组
  private System.Drawing.Point startPoint;  //起始绘制位置
  private int X_CurrentPoint;              
  private int Y_CurrentPoint;
  private int X_PanleControl;
  private int Y_PanleControl;
  private int IntPanelIndex;
  private int IntControlIndex;
  private ArrayList panleArrayList;
  private ArrayList comboxsArrayList;
  private ArrayList valuesArrayList;
  private ArrayList opratersArrayList;
  private ArrayList continuesArrayList;
  private string[] TypeCodes;               //存储当前表格字段类型
  //***********************************************
  


  public Query(DataGridTableStyle[] tableStyles,System.Data.DataTable[] Tables)
  {
   InitializeComponent();
   this.InitedData(tableStyles,Tables);
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.button2 = new System.Windows.Forms.Button();
   this.SuspendLayout();
   this.button1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
   this.button1.Location = new System.Drawing.Point(168, 306);
   this.button1.Name = "button1";
   this.button1.TabIndex = 0;
   this.button1.Text = "生成查询条件";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   this.button2.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
   this.button2.Location = new System.Drawing.Point(276, 306);
   this.button2.Name = "button2";
   this.button2.TabIndex = 1;
   this.button2.Text = "恢复默认值";
   this.button2.Click += new System.EventHandler(this.button2_Click);
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(556, 363);
   this.Controls.Add(this.button2);
   this.Controls.Add(this.button1);
   this.Name = "Query";
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.Text = "数据查询窗口";
   this.Load += new System.EventHandler(this.Query_Load);
   this.ResumeLayout(false);

  }
  #endregion


  #region//初始化用户变量
  private void InitedData(DataGridTableStyle[] tableStyles,System.Data.DataTable[] Tables)
  {
   //********************************************初始化
   this.TableStyles = tableStyles;
   this.Tables = Tables;
   //********************************************初始化结束
   this.startPoint = new Point(20,20);
   this.X_CurrentPoint = this.startPoint.X;
   this.Y_CurrentPoint = this.startPoint.Y;
   this.X_PanleControl = this.X_CurrentPoint;
   this.Y_PanleControl = this.Y_CurrentPoint;
   this.comboxsArrayList = new ArrayList();
   this.valuesArrayList = new ArrayList();
   this.panleArrayList = new ArrayList();
   this.opratersArrayList = new ArrayList();
   this.continuesArrayList = new ArrayList();
   this.IntPanelIndex = 0;
   this.IntControlIndex = 0;
  }
  #endregion

  #region//循环绘制所有style所有字段
  private void DrawingPanelControls()
  {
   //循环
   int count = this.TableStyles.GetLength(0);
   for (int i = 0;i<count;i++ )
   {
    DrawingStylePanel(this.TableStyles[i],Tables[i],i);
   }
  }
  #endregion

  #region//在一个Panel上绘制的过程
  private void DrawingStylePanel(DataGridTableStyle tableStyle,System.Data.DataTable dt, int indexPanel)
  {
   Panel panel = new Panel();
   panel.Name = panel + this.IntPanelIndex.ToString();
   panel.Location = new System.Drawing.Point(this.X_CurrentPoint,this.Y_CurrentPoint);
   panel.Width = this.Width - this.startPoint.X*2;
   panel.Height = 60;
   panel.BackColor = System.Drawing.Color.Azure;   
   this.Controls.Add(panel);
   panleArrayList.Add(panel);
   ArrayList comboxArrayList = new ArrayList();
   ArrayList valueArrayList = new ArrayList();
   ArrayList opraterArrayList = new ArrayList();
   ArrayList continueArrayList = new ArrayList();
   
   comboxsArrayList.Add(comboxArrayList);
   valuesArrayList.Add(valueArrayList);
   opratersArrayList.Add(opraterArrayList);
   continuesArrayList.Add(continueArrayList);
   //this.Y_CurrentPoint += panel.Height;
   this.IntControlIndex = 0;

   int ColumnsCount = dt.Columns.Count;
   this.TypeCodes = new string[ColumnsCount];
   for ( int i = 0;i<ColumnsCount;i++ )
   {
    TypeCodes[i] = dt.Columns[i].ColumnName + "|" + dt.Columns[i].DataType.ToString();
   }
   DrawingConditionControl(tableStyle,indexPanel);
   this.IntPanelIndex ++;
   this.X_CurrentPoint = this.startPoint.X;
   this.Y_CurrentPoint += panel.Height-30;
   this.X_PanleControl = this.startPoint.X;
   this.Y_PanleControl += panel.Height-50;

  }


  private void DrawingConditionControl(DataGridTableStyle tableStyle,int indexPanel)
  {
   ComboxCodition(tableStyle,indexPanel);
   DrwaingOpraterConditon(indexPanel);
   DrwaingValueConditon(indexPanel);
   ContinueCondition(indexPanel);
   this.IntControlIndex ++;
   Panel panel = (Panel)panleArrayList[indexPanel];
   if ( panel.Height +30  >=240 )
   {
    if ( !panel.AutoScroll )
    {
     panel.AutoScroll = true;
    }
    panel.Height += 10;
   }
   else
   {
    panel.Height += 30 ;
   }

   
  }

  private void ComboxCodition(DataGridTableStyle tableStyle,int indexPanel)
  {
   ComboBox combox = new ComboBox();
   combox.DropDownStyle = ComboBoxStyle.DropDownList;
   combox.Name = "combox" + this.IntPanelIndex.ToString() + this.IntControlIndex.ToString();
   foreach ( DataGridColumnStyle columnStyle in tableStyle.GridColumnStyles )
   {
    combox.Items.Add(columnStyle.HeaderText);
   }
   combox.SelectedIndex = this.IntControlIndex;
   combox.Location = new Point(this.X_PanleControl,this.Y_PanleControl);
   combox.Width = 120;
   ((Panel)panleArrayList[indexPanel]).Controls.Add(combox);
   ((ArrayList)comboxsArrayList[indexPanel]).Add(combox);
   this.X_PanleControl += combox.Width + 10;

   combox.SelectionChangeCommitted += new EventHandler(combox_SelectionChangeCommitted);
  }
  
  private void DrwaingValueConditon(int indexPanel)
  {
   //内容框的绘制
   int index = ((ArrayList)comboxsArrayList[indexPanel]).Count;
   int intSelectedColumn= ((ComboBox)((ArrayList)comboxsArrayList[indexPanel])[index-1]).SelectedIndex;
   DataGridColumnStyle ColumnStyle = this.TableStyles[indexPanel].GridColumnStyles[intSelectedColumn];
   ValueCondition(indexPanel, ColumnStyle,-1);
  }

  private void DrwaingOpraterConditon(int indexPanel)
  {
   //符号操作符的绘制
   int index = ((ArrayList)comboxsArrayList[indexPanel]).Count;
   int intSelectedColumn= ((ComboBox)((ArrayList)comboxsArrayList[indexPanel])[index-1]).SelectedIndex;
   DataGridColumnStyle ColumnStyle = this.TableStyles[indexPanel].GridColumnStyles[intSelectedColumn];
   OpraterCondition(indexPanel, ColumnStyle,-1);
  }
  #endregion

  #region//字段选择项目变化相应事件
  private void combox_SelectionChangeCommitted(Object sender,System.EventArgs e)
  {
   Control controlPanel = ((Control)sender).Parent;
   int indexPanel = panleArrayList.IndexOf(controlPanel);
   int indexComb = ((ArrayList)comboxsArrayList[indexPanel]).IndexOf(sender);
   Control control = (Control)((ArrayList)valuesArrayList[indexPanel])[indexComb];
   if ( control!=null )
   {
    control.Dispose();
   }
   int intSelectedColumn= ((ComboBox)sender).SelectedIndex;
   DataGridColumnStyle ColumnStyle = this.TableStyles[indexPanel].GridColumnStyles[intSelectedColumn];
   this.X_PanleControl = ((Control)sender).Location.X + 213;
   this.Y_PanleControl = ((Control)sender).Location.Y;
   OpraterCondition(indexPanel, ColumnStyle,indexComb);
   ValueCondition(indexPanel, ColumnStyle,indexComb);
  }
  #endregion

  #region//绘制操作符号
  private void OpraterCondition(int indexPanel,DataGridColumnStyle ColumnStyle,int Index)
  {
   string ColumnName = ColumnStyle.MappingName;
   string DataTypeName = System.TypeCode.String.ToString();
   if ( Index!= -1 )
   {
    int ColumnsCount = this.Tables[indexPanel].Columns.Count;
    this.TypeCodes = new string[ColumnsCount];
    for ( int i = 0;i<ColumnsCount;i++ )
    {
     TypeCodes[i] = this.Tables[indexPanel].Columns[i].ColumnName + "|" + this.Tables[indexPanel].Columns[i].DataType.ToString();
    }
   }
   foreach ( string str in this.TypeCodes )
   {
    if (str.IndexOf(ColumnName + "|" )!=-1 )
    {
     DataTypeName = str.Replace(ColumnName + "|" ,"");
     break;
    }
   }
   ComboBox combox = new ComboBox();
   combox.DropDownStyle = ComboBoxStyle.DropDownList;
   combox.Name = "oprater" + this.IntPanelIndex.ToString()  + "_" +  this.IntControlIndex.ToString();
   combox.Width = 80;
   
   if ( Index ==-1)
   {
    combox.Location = new Point(this.X_PanleControl,this.Y_PanleControl);
    ((Panel)panleArrayList[indexPanel]).Controls.Add(combox);
    ((ArrayList)opratersArrayList[indexPanel]).Add(combox);
    this.X_PanleControl += combox.Width + 10;
   }
   else
   {
    combox.Location = new Point(this.X_PanleControl-83,this.Y_PanleControl);
    ((ComboBox)((ArrayList)opratersArrayList[indexPanel])[Index]).Dispose();
    ((Panel)panleArrayList[indexPanel]).Controls.Add(combox);
    ((ArrayList)opratersArrayList[indexPanel])[Index] = combox;    
   }
   switch ( DataTypeName )
   {    
    case "System.Boolean":
    case "System.Byte":
    {
     combox.Items.Clear();
     combox.Items.Add("等于");
     break;
    }
    case "System.Decimal":
    case "System.Double":
    case "System.Int16":
    case "System.Int32":
    {
     combox.Items.Clear();
     combox.Items.Add("等于");
     combox.Items.Add("小于");
     combox.Items.Add("小于等于");
     combox.Items.Add("大于");
     combox.Items.Add("大于等于");
     break;
    }
    case "System.DateTime":
    {
     combox.Items.Clear();
     combox.Items.Add("等于");
     combox.Items.Add("小于");
     combox.Items.Add("小于等于");
     combox.Items.Add("大于");
     combox.Items.Add("大于等于");
     break;
    }
    case "System.String":
    {
     combox.Items.Clear();
     combox.Items.Add("等于");
     combox.Items.Add("相似");
     break;
    }
    default:
    {
     combox.Items.Clear();
     combox.Items.Add("等于");
     combox.Items.Add("小于");
     combox.Items.Add("小于等于");
     combox.Items.Add("大于");
     combox.Items.Add("大于等于");
     combox.Items.Add("相似");
     break;
    }
   }
   combox.SelectedIndex = 0;

  }
  #endregion
  
  #region//绘制条件输入控件
  private void ValueCondition(int indexPanel,DataGridColumnStyle ColumnStyle,int Index)
  {
   string ColumnName = ColumnStyle.MappingName;
   string DataTypeName = System.TypeCode.String.ToString();
   if ( Index!= -1 )
   {
    int ColumnsCount = this.Tables[indexPanel].Columns.Count;
    this.TypeCodes = new string[ColumnsCount];
    for ( int i = 0;i<ColumnsCount;i++ )
    {
     TypeCodes[i] = this.Tables[indexPanel].Columns[i].ColumnName + "|" + this.Tables[indexPanel].Columns[i].DataType.ToString();
    }
   }
   foreach ( string str in this.TypeCodes )
   {
    if (str.IndexOf(ColumnName + "|" )!=-1 )
    {
     DataTypeName = str.Replace(ColumnName + "|" ,"");
     break;
    }
   }
   if ( Index !=-1)
   {
    this.X_PanleControl += 7;
   }
   switch ( DataTypeName )
   {    
    case "System.Boolean":
    case "System.Byte":
    {
     GroupBox groupbox = new GroupBox();
     groupbox.Name = "value" + this.IntPanelIndex.ToString()  + "_" +  this.IntControlIndex.ToString();
     groupbox.Location = new Point(this.X_PanleControl+3,this.Y_PanleControl-10);
     groupbox.Width = 120;
     groupbox.Height = 35;
     groupbox.Text = string.Empty;
     ((Panel)panleArrayList[indexPanel]).Controls.Add(groupbox);
     if ( Index == -1 )
     {
      ((ArrayList)valuesArrayList[indexPanel]).Add(groupbox);
     }
     else
     {
      ((ArrayList)valuesArrayList[indexPanel])[Index] = groupbox;
     }
     RadioButton radioBox1= new RadioButton();
     radioBox1.Name = "radioBox" + indexPanel.ToString() + "_1";
     radioBox1.Text = "是";
     radioBox1.Location = new Point(3,7);
     radioBox1.Width = 30;
     radioBox1.Checked = true;
     RadioButton radioBox2= new RadioButton();
     radioBox2.Name = "radioBox" + indexPanel.ToString() + "_2";
     radioBox2.Text = "否";
     radioBox2.Location = new Point(35,7);
     radioBox2.Width = 30;
     groupbox.Controls.Add(radioBox1);
     groupbox.Controls.Add(radioBox2);
     this.X_PanleControl += groupbox.Width + 20;
     break;
    }
    case "System.Decimal":
    case "System.Double":
    case "System.Int16":
    case "System.Int32":
    {
     NumericUpDown numericUpDown = new NumericUpDown();
     numericUpDown.Name = "value" + this.IntPanelIndex.ToString()  + "_" +  this.IntControlIndex.ToString();
     numericUpDown.Maximum = 10000000;
     numericUpDown.Minimum = -10000000;
     numericUpDown.Value = 0;
     numericUpDown.Location = new Point(this.X_PanleControl,this.Y_PanleControl);
     numericUpDown.Width = 120;
     ((Panel)panleArrayList[indexPanel]).Controls.Add(numericUpDown);
     if ( Index == -1 )
     {
      ((ArrayList)valuesArrayList[indexPanel]).Add(numericUpDown);
     }
     else
     {
      ((ArrayList)valuesArrayList[indexPanel])[Index] = numericUpDown;
     }

     this.X_PanleControl += numericUpDown.Width + 20;
     break;

    }
    case "System.DateTime":
    {
     DateTimePicker dateTimePicker1 = new DateTimePicker();
     dateTimePicker1.Name = "value" + this.IntPanelIndex.ToString()  + "_" +  this.IntControlIndex.ToString();
     dateTimePicker1.Location = new Point(this.X_PanleControl,this.Y_PanleControl);
     dateTimePicker1.Width = 120;
     dateTimePicker1.Value = DateTime.Now;
     ((Panel)panleArrayList[indexPanel]).Controls.Add(dateTimePicker1);
     if ( Index == -1 )
     {
      ((ArrayList)valuesArrayList[indexPanel]).Add(dateTimePicker1);
     }
     else
     {
      ((ArrayList)valuesArrayList[indexPanel])[Index] = dateTimePicker1;
     }

     this.X_PanleControl += dateTimePicker1.Width + 20;
     break;

    }
    case "System.String":
    default:
    {

     TextBox textBox = new TextBox();
     textBox.Name = "value" + this.IntPanelIndex.ToString()  + "_" +  this.IntControlIndex.ToString();
     textBox.Text = string.Empty;
     textBox.Location = new Point(this.X_PanleControl,this.Y_PanleControl);
     textBox.Width = 120;
     ((Panel)panleArrayList[indexPanel]).Controls.Add(textBox);
     if ( Index == -1 )
     {
      ((ArrayList)valuesArrayList[indexPanel]).Add(textBox);
     }
     else
     {
      ((ArrayList)valuesArrayList[indexPanel])[Index] = textBox;
     }

     this.X_PanleControl += textBox.Width + 20;
     break;
    }
   }
  }
  #endregion

  #region//绘制条件选择下拉列表
  private void ContinueCondition(int indexPanel)
  {
   ComboBox combox = new ComboBox();
   combox.DropDownStyle = ComboBoxStyle.DropDownList;
   combox.Name = "continue" + this.IntPanelIndex.ToString() + "_" + this.IntControlIndex.ToString();
   combox.Items.Add("选择");
   combox.Items.Add("而且");
   combox.Items.Add("或者");
   combox.SelectedIndex = 0;
   combox.Location = new Point(this.X_PanleControl,this.Y_PanleControl);
   combox.Width = 60;
   ((Panel)panleArrayList[indexPanel]).Controls.Add(combox);
   ((ArrayList)continuesArrayList[indexPanel]).Add(combox);
   this.X_PanleControl += combox.Width + 10;
   combox.SelectedIndexChanged += new EventHandler(Continue_SelectedIndexChanged);
  }
  #endregion

  #region//条件选择事件响应方法
  protected void Continue_SelectedIndexChanged(object sender,System.EventArgs e)
  {   
   ComboBox combox = (ComboBox)sender;
   Control control = combox.Parent;
   int index = panleArrayList.IndexOf(control);
   if ( combox.SelectedIndex == 0 )
   {
    return;
   }   
   if ( ((ArrayList)continuesArrayList[0]).IndexOf(sender)  == TableStyles[index].GridColumnStyles.Count-1 )
   {
    combox.SelectedIndex = 0;
    MessageBox.Show("您已经选择了全部的查询条件!","提示");    
    return;
   }
   combox.Enabled = false;
   this.X_PanleControl = control.Location.X;
   this.Y_PanleControl = combox.Location.Y+30;
   DrawingConditionControl(TableStyles[index],index);   
  }
  #endregion

  #region//循环遍历字段条件生成SQL语句
  private string CreatSqlCondition()
  {
   int panleCount = panleArrayList.Count;
   System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
   
   for (int i=0,k=0;i<panleCount;i++ )
   {
    int continueCount = ((ArrayList)continuesArrayList[i]).Count;
    string tableName = this.TableStyles[i].MappingName;
    for ( int j=0;j<continueCount;j++ )
    { 
     string txtComBox = ((ComboBox)((ArrayList)comboxsArrayList[i])[j]).SelectedItem.ToString();
     bool IsAddDot = true;
     System.TypeCode tyCode = System.TypeCode.String;
     foreach ( DataGridColumnStyle columnStyle in TableStyles[i].GridColumnStyles )
     {
      if ( columnStyle.HeaderText == txtComBox )
      {
       txtComBox = columnStyle.MappingName;
       string TypeValue = this.Tables[i].Columns[txtComBox].DataType.ToString();
       switch ( TypeValue )
       {    
        case "System.Boolean":
        case "System.Byte":
        {
         tyCode = System.TypeCode.Boolean;
         IsAddDot = false;
         break;
        }
        case "System.Decimal":
        case "System.Double":
        case "System.Int16":
        case "System.Int32":
        {
         tyCode = System.TypeCode.Decimal;
         IsAddDot = false;
         break;
        }
        case "System.DateTime":
        {
         tyCode = System.TypeCode.DateTime;
         IsAddDot = true;
         break;
        }
        default:
        {
         tyCode = System.TypeCode.String;
         IsAddDot = true;
         break;
        }
       }
      }
     }
     string txt = string.Empty;
     if ( tyCode == System.TypeCode.String )
     {
      txt = ((TextBox)((ArrayList)valuesArrayList[i])[j]).Text; 
     }
     else if ( tyCode == System.TypeCode.Boolean )
     {
      GroupBox groupbox = (GroupBox)((ArrayList)valuesArrayList[i])[j];
      RadioButton radioButton1 = (RadioButton)groupbox.Controls[0];
      RadioButton radioButton2 = (RadioButton)groupbox.Controls[1];
      if ( !radioButton1.Checked && radioButton2.Checked )
      {
       txt = "0";
      }
      else if ( radioButton1.Checked && !radioButton2.Checked )
      {
       txt = "1";
      }
     }
     else if ( tyCode == System.TypeCode.Decimal )
     {
      txt = ((NumericUpDown)((ArrayList)valuesArrayList[i])[j]).Value.ToString();
     }
     else if ( tyCode == System.TypeCode.DateTime )
     {
      txt = ((DateTimePicker)((ArrayList)valuesArrayList[i])[j]).Value.ToString();
     }
     if ( txt == string.Empty )
     {
      continue;
     }

     string txtOprater = ((ComboBox)((ArrayList)opratersArrayList[i])[j]).SelectedItem.ToString();
     txtOprater = this.Oprater(txtOprater);
     string txtContinue = string.Empty;
     if ( j>0 )
     {
      txtContinue = ((ComboBox)((ArrayList)continuesArrayList[i])[k]).SelectedItem.ToString();
      txtContinue = ContinueTxt(txtContinue);
      k++;
     }
     
     SqlStringCondition( txtComBox, txt,txtContinue,txtOprater,strBuilder,tableName, IsAddDot);

    }
    //添加and字符串连接多表查询条件
   }
   return strBuilder.ToString();
  }

  #endregion

  #region//生成相应字段的SQL语句并插入
  private void SqlStringCondition(string txtComBox,string txt, string txtContinue,string txtOprater,System.Text.StringBuilder strBuilder,string tableName,bool IsAddDot )
  {
   tableName +=".";
   if ( txtContinue == string.Empty || strBuilder.Length == 0 )
   {
    if ( txtOprater == "Like" )
    {
     strBuilder.Append(" (");
     strBuilder.Append(tableName);
     strBuilder.Append(txtComBox);
     strBuilder.Append(" ");
     strBuilder.Append(txtOprater);
     if ( IsAddDot )
     {
      strBuilder.Append(" \'*");
     }
     else
     {
      strBuilder.Append(" *");
     }

     strBuilder.Append(txt);
     if ( IsAddDot )
     {
      strBuilder.Append("*\' ) ");
     }
     else
     {
      strBuilder.Append("* ) ");
     }
     
    }
    else
    {
     strBuilder.Append(" (");
     strBuilder.Append(tableName);
     strBuilder.Append(txtComBox);
     strBuilder.Append(" ");
     strBuilder.Append(txtOprater);
     if ( IsAddDot )
     {
      strBuilder.Append(" \'");
     }
     else
     {
      strBuilder.Append(" ");
     }
     strBuilder.Append(txt);
     if ( IsAddDot )
     {
      strBuilder.Append("\' ) ");
     }
     else
     {
      strBuilder.Append(" ) ");
     }
    }
   }
   else
   {
    if ( txtOprater == "Like" )
    {
     strBuilder.Append(" ");
     strBuilder.Append(txtContinue);
     strBuilder.Append(" (");
     strBuilder.Append(tableName);
     strBuilder.Append(txtComBox);
     strBuilder.Append(" ");
     strBuilder.Append(txtOprater);
     if ( IsAddDot )
     {
      strBuilder.Append(" \'*");
     }
     else
     {
      strBuilder.Append(" *");
     }     
     strBuilder.Append(txt);
     if ( IsAddDot )
     {
      strBuilder.Append("*\' ) ");
     }
     else
     {
      strBuilder.Append("* ) ");
     }
     
    }
    else
    {
     strBuilder.Append(" ");
     strBuilder.Append(txtContinue);
     strBuilder.Append(" (");
     strBuilder.Append(tableName);
     strBuilder.Append(txtComBox);
     strBuilder.Append(" ");
     strBuilder.Append(txtOprater);
     if ( IsAddDot )
     {
      strBuilder.Append(" \'");
     }
     else
     {
      strBuilder.Append(" ");
     }
     strBuilder.Append(txt);
     if ( IsAddDot )
     {
      strBuilder.Append("\' ) ");
     }
     else
     {
      strBuilder.Append(" ) ");
     }
    }
   }
  }
  #endregion

  #region//符号转换
  private string ContinueTxt(string Txt)
  {
   string result = string.Empty;
   switch (Txt)
   {
    case "而且":
    {
     result = "And";
     break;
    }
    case "或者":
    {
     result = "Or";
     break;
    }
   }
   return result;
  }

  private string Oprater(string Txt)
  {
   string result = string.Empty;
   switch (Txt)
   {
    case "等于":
    {
     result = "=";
     break;
    }
    case "小于":
    {
     result = "<";
     break;
    }
    case "大于":
    {
     result = ">";
     break;
    }
    case "小于等于":
    {
     result = "<=";
     break;
    }
    case "大于等于":
    {
     result = ">=";
     break;
    }
    case "相似":
    {
     result = "Like";
     break;
    }
   }
   return result;
  }
  #endregion

  #region//恢复窗体默认值以及界面
  private void SetDefaultFace()
  {
   if ( this.CreatSqlCondition() != string.Empty )
   {
    DialogResult result = System.Windows.Forms.MessageBox.Show("这个操作会取消你当前设置的查询条件!\r你确定要这么做吗?","提示",System.Windows.Forms.MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button1);
    if ( result == System.Windows.Forms.DialogResult.No )
    {
     return;
    }
   }
   foreach (System.Windows.Forms.Control control in this.Controls )
   {
    if ( control.GetType().ToString() == "System.Windows.Forms.Button" )
    {
     continue;
    }
    control.Dispose();
   }
   this.InitedData(this.TableStyles,this.Tables);
   this.DrawingPanelControls();
  }
  #endregion


  private void Query_Load(object sender, System.EventArgs e)
  {
   this.DrawingPanelControls();   
  }


  private void button2_Click(object sender, System.EventArgs e)
  {
   this.SetDefaultFace();
  }


  private void button1_Click(object sender, System.EventArgs e)
  {
   string sql = this.CreatSqlCondition();
  }
 }
 
}

posted on 2007-01-03 10:19  空谷幽兰  阅读(545)  评论(0)    收藏  举报