在数据库的编程中,常常要对数据库的数据根据条件查询,查询条件生成器正是因此而生。
一、查询条件生成器源码
查询条件生成器由以下六个文件组成
1、接口IFilter.cs
- using System;
- namespace SearchFilter
- {
- /// <summary>
- /// IFilter 的摘要说明
- /// 描述: 定义属性
- /// 作者: xlFancy
- /// 日期: 2008.05.10
- /// 版本: 1.0.0.0
- /// </summary>
- public interface IFilter
- {
- string Name { get;}
- string Text { get;}
- DataType DataType { get;}
- string CompareCode { set;get;}
- string LogicalCode { set;get;}
- string BracketCode { set;get;}
- string Value { set;get;}
- }
- }
2、接口IFilterString.cs
- using System;
- namespace SearchFilter
- {
- /// <summary>
- /// IFilterString 的摘要说明
- /// 描述: 定义属性,索引,方法
- /// 作者: xlFancy
- /// 日期: 2008.05.10
- /// 版本: 1.0.0.0
- /// </summary>
- public interface IFilterString
- {
- int FieldCount { get; }
- IFilter this[int Index] { set; get; }
- IFilter this[string Key] { set; get; }
- /// <summary>
- /// 返回查询条件表达式,能自动删除错误的或不匹配的左括弧、右括弧
- /// </summary>
- string FilterText { get; }
- void FilterClear();
- }
- }
3、数据类型枚举EnumConst.cs
- using System;
- namespace SearchFilter
- {
- /// <summary>
- /// DataType 的摘要说明
- /// 描述: 定义数据类型
- /// 作者: xlFancy
- /// 日期: 2008.05.10
- /// 版本: 1.0.0.0
- /// </summary>
- public enum DataType
- {
- /// <summary>
- /// 布尔类型
- /// </summary>
- Boolen,
- /// <summary>
- /// 日期类型
- /// </summary>
- DataTime,
- /// <summary>
- /// 字符类型
- /// </summary>
- String,
- /// <summary>
- /// 数值类型
- /// </summary>
- Number
- }
- }
4、实现接口IFilter类Filter.cs
- using System;
- namespace SearchFilter
- {
- /// <summary>
- /// Filter 的摘要说明
- /// 功能: 实现IFilter所定义的属性
- /// 作者: xlFancy
- /// 日期: 2008.05.10
- /// 版本: 1.0.0.0
- /// </summary>
- class Filter:IFilter
- {
- private string _name = "";
- private string _text = "";
- private DataType _datatype = DataType.String;
- private string _comparecode = "LIKE";
- private string _logicalcode = "";
- private string _bracketcode = "";
- private string _value = "";
- /// <summary>
- /// 初始化供查询的字段
- /// </summary>
- /// <param name="FieldName">字段名称</param>
- /// <param name="FieldText">字段文本,用于显示</param>
- /// <param name="FieldType">字段类型,只能是DataType枚举值</param>
- public Filter(string FieldName, string FieldText, DataType FieldType)
- {
- _name=FieldName;
- _text=FieldText;
- _datatype=FieldType;
- }
- public string Name { get { return _name; } }
- public string Text { get { return _text; } }
- public DataType DataType { get { return _datatype; } }
- public string CompareCode
- {
- get { return _comparecode; }
- set { _comparecode = value; }
- }
- public string LogicalCode
- {
- get { return _logicalcode; }
- set { _logicalcode = value; }
- }
- public string BracketCode
- {
- get { return _bracketcode; }
- set { _bracketcode = value; }
- }
- public string Value
- {
- get
- {
- if (this.CompareCode =="LIKE" || this.CompareCode =="NOT LIKE")
- {
- return string.Format("'%{0}%'", _value);
- }
- else
- {
- if (this.DataType == DataType.Boolen || this.DataType == DataType.Number) return _value;
- else return string.Format("'{0}'", _value);
- }
- }
- set { _value = value; }
- }
- }
- }
5、实现接口IFilterString类FilterString.cs
- using System;
- using System.Text;
- using System.Collections;
- namespace SearchFilter
- {
- /// <summary>
- /// FilterString 的摘要说明
- /// 功能: 实现IFilterString所定义的属性,索引,方法
- /// 作者: xlFancy
- /// 日期: 2008.05.10
- /// 版本: 1.0.0.0
- /// </summary>
- public class FilterString:IFilterString
- {
- private int _count=0;
- private IFilter[] _filter;
- private Hashtable _result = new Hashtable();
- /// <summary>
- /// 初始化查询条件生成器
- /// </summary>
- /// <param name="FieldCount">提供选择的字段数量</param>
- public FilterString(int FieldCount)
- {
- _count=FieldCount;
- _filter=new Filter[FieldCount];
- }
- public int FieldCount { get { return _count; } }
- public IFilter this[int Index]
- {
- set { _filter[Index]=value; }
- get { return _filter[Index]; }
- }
- public IFilter this[string Key]
- {
- set { _result[Key]=value; }
- get { return (IFilter)_result[Key]; }
- }
- public void FilterClear()
- {
- _result.Clear();
- }
- /// <summary>
- /// 返回查询条件表达式,能自动删除错误的或不匹配的左括弧、右括弧
- /// </summary>
- public string FilterText
- {
- get
- {
- if (_result.Count==0) return "";
- string key;
- StringBuilder sb=new StringBuilder(500);
- for (int i=0;i<_result.Count;i++)
- {
- key=i.ToString();
- if (this[key].BracketCode.IndexOf("(")!=-1) sb.AppendFormat(" {0}",this[key].BracketCode.TrimStart(')'));
- sb.AppendFormat(" {0} {1} {2}", this[key].Name, this[key].CompareCode, this[key].Value);
- if (this[key].BracketCode.IndexOf(")")!=-1) sb.AppendFormat(" {0}",this[key].BracketCode.TrimEnd('('));
- sb.AppendFormat(" {0}",this[key].LogicalCode);
- }
- return BracketMatch(sb.ToString());
- }
- }
- /// <summary>
- /// 清除不匹配的左括弧,右括弧
- /// </summary>
- /// <param name="exp">查询条件表达式</param>
- /// <returns></returns>
- private string BracketMatch(string exp)
- {
- Stack left=new Stack(); //定义空栈,保存左括弧位置
- Stack right=new Stack(); //定义空栈,保存右括弧位置
- for (int i=0;i<exp.Length;i++)
- {
- switch (exp.Substring(i,1))
- {
- case "(":
- left.Push(i);
- break;
- case ")":
- if (left.Count ==0) right.Push(i); //栈为空,则当前的右括弧是非法的,将其位置进栈
- else left.Pop(); //左括弧位置退栈
- break;
- }
- }
- //清除不匹配的左括弧
- for (int i=0;i<left.Count;i++) exp=exp.Remove((int)left.Pop(),1);
- //清除不匹配的右括弧
- for (int i=0;i<right.Count;i++) exp=exp.Remove((int)right.Pop(),1);
- return exp.Trim();
- }
- }
- }
6、用户选择查询条件窗体界面
- using System;
- using System.Data;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace SearchFilter
- {
- /// <summary>
- /// SearchFilter 的摘要说明
- /// 功能: 生成查询条件表达式,能自动删除错误的或不匹配的左括弧、右括弧
- /// 作者: xlFancy
- /// 日期: 2008.05.10
- /// 版本: 1.0.0.0
- /// </summary>
- public class SearchFilter : System.Windows.Forms.Form
- {
- private System.ComponentModel.IContainer components;
- private System.Windows.Forms.ComboBox comCompareCode;
- private System.Windows.Forms.TextBox txtValue;
- private System.Windows.Forms.ImageList imageList1;
- private System.Windows.Forms.ToolBar toolBar1;
- private System.Windows.Forms.ToolBarButton tbarAddNew;
- private System.Windows.Forms.ToolBarButton tbarDelete;
- private System.Windows.Forms.ToolBarButton tbarExit;
- private IFilterString _fs;
- private System.Windows.Forms.ComboBox comFieldText;
- private System.Windows.Forms.ComboBox comLogicalCode;
- private System.Windows.Forms.ToolBarButton tbarSep1;
- private System.Windows.Forms.ToolBarButton tbarSearch;
- private System.Windows.Forms.ToolBarButton tbarSep2;
- private System.Windows.Forms.TextBox txtBracketCode;
- private System.Windows.Forms.Button btnBracketLeft;
- private System.Windows.Forms.Button btnBracketRight;
- private System.Windows.Forms.ListView listView1;
- private System.Windows.Forms.ColumnHeader colFieldName;
- private System.Windows.Forms.ColumnHeader colCompareCode;
- private System.Windows.Forms.ColumnHeader colValue;
- private System.Windows.Forms.ColumnHeader colLogicalCode;
- private System.Windows.Forms.ColumnHeader colBracketCode;
- private System.Windows.Forms.ColumnHeader colFieldIndex;
- private System.Windows.Forms.Button btnBracketClear;
- public SearchFilter(IFilterString FilterString)
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- _fs=FilterString;
- //初始化字段列表
- for (int i=0;i<_fs.FieldCount;i++) this.comFieldText.Items.Add(_fs[i].Text);
- //设置默认值
- this.comFieldText.SelectedIndex =0;
- this.comCompareCode.SelectedIndex=0;
- this.comLogicalCode.SelectedIndex =0;
- }
- /// <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.components = new System.ComponentModel.Container();
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(SearchFilter));
- this.comFieldText = new System.Windows.Forms.ComboBox();
- this.comCompareCode = new System.Windows.Forms.ComboBox();
- this.txtValue = new System.Windows.Forms.TextBox();
- this.imageList1 = new System.Windows.Forms.ImageList(this.components);
- this.toolBar1 = new System.Windows.Forms.ToolBar();
- this.tbarAddNew = new System.Windows.Forms.ToolBarButton();
- this.tbarDelete = new System.Windows.Forms.ToolBarButton();
- this.tbarSep1 = new System.Windows.Forms.ToolBarButton();
- this.tbarSearch = new System.Windows.Forms.ToolBarButton();
- this.tbarSep2 = new System.Windows.Forms.ToolBarButton();
- this.tbarExit = new System.Windows.Forms.ToolBarButton();
- this.comLogicalCode = new System.Windows.Forms.ComboBox();
- this.txtBracketCode = new System.Windows.Forms.TextBox();
- this.btnBracketLeft = new System.Windows.Forms.Button();
- this.btnBracketRight = new System.Windows.Forms.Button();
- this.btnBracketClear = new System.Windows.Forms.Button();
- this.listView1 = new System.Windows.Forms.ListView();
- this.colFieldName = new System.Windows.Forms.ColumnHeader();
- this.colCompareCode = new System.Windows.Forms.ColumnHeader();
- this.colValue = new System.Windows.Forms.ColumnHeader();
- this.colLogicalCode = new System.Windows.Forms.ColumnHeader();
- this.colBracketCode = new System.Windows.Forms.ColumnHeader();
- this.colFieldIndex = new System.Windows.Forms.ColumnHeader();
- this.SuspendLayout();
- //
- // comFieldText
- //
- this.comFieldText.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comFieldText.Location = new System.Drawing.Point(8, 312);
- this.comFieldText.Name = "comFieldText";
- this.comFieldText.Size = new System.Drawing.Size(200, 21);
- this.comFieldText.TabIndex = 2;
- //
- // comCompareCode
- //
- this.comCompareCode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comCompareCode.Items.AddRange(new object[] {
- "LIKE",
- "NOT LIKE",
- "<",
- "=",
- ">",
- "<=",
- ">=",
- "<>"});
- this.comCompareCode.Location = new System.Drawing.Point(216, 312);
- this.comCompareCode.Name = "comCompareCode";
- this.comCompareCode.Size = new System.Drawing.Size(88, 21);
- this.comCompareCode.TabIndex = 3;
- //
- // txtValue
- //
- this.txtValue.Location = new System.Drawing.Point(312, 312);
- this.txtValue.Name = "txtValue";
- this.txtValue.Size = new System.Drawing.Size(120, 23);
- this.txtValue.TabIndex = 4;
- this.txtValue.Text = "";
- //
- // imageList1
- //
- this.imageList1.ImageSize = new System.Drawing.Size(20, 20);
- this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
- this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
- //
- // toolBar1
- //
- this.toolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
- this.toolBar1.AutoSize = false;
- this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
- this.tbarAddNew,
- this.tbarDelete,
- this.tbarSep1,
- this.tbarSearch,
- this.tbarSep2,
- this.tbarExit});
- this.toolBar1.ButtonSize = new System.Drawing.Size(48, 48);
- this.toolBar1.DropDownArrows = true;
- this.toolBar1.ImageList = this.imageList1;
- this.toolBar1.Location = new System.Drawing.Point(0, 0);
- this.toolBar1.Name = "toolBar1";
- this.toolBar1.ShowToolTips = true;
- this.toolBar1.Size = new System.Drawing.Size(666, 50);
- this.toolBar1.TabIndex = 0;
- this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
- //
- // tbarAddNew
- //
- this.tbarAddNew.ImageIndex = 0;
- this.tbarAddNew.Tag = "Add";
- this.tbarAddNew.Text = "Add";
- //
- // tbarDelete
- //
- this.tbarDelete.ImageIndex = 1;
- this.tbarDelete.Tag = "Delete";
- this.tbarDelete.Text = "Delete";
- //
- // tbarSep1
- //
- this.tbarSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // tbarSearch
- //
- this.tbarSearch.ImageIndex = 3;
- this.tbarSearch.Tag = "Search";
- this.tbarSearch.Text = "Search";
- //
- // tbarSep2
- //
- this.tbarSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
- //
- // tbarExit
- //
- this.tbarExit.ImageIndex = 4;
- this.tbarExit.Tag = "Exit";
- this.tbarExit.Text = "Exit";
- //
- // comLogicalCode
- //
- this.comLogicalCode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comLogicalCode.Items.AddRange(new object[] {
- "AND",
- "OR"});
- this.comLogicalCode.Location = new System.Drawing.Point(440, 312);
- this.comLogicalCode.Name = "comLogicalCode";
- this.comLogicalCode.Size = new System.Drawing.Size(88, 21);
- this.comLogicalCode.TabIndex = 5;
- //
- // txtBracketCode
- //
- this.txtBracketCode.BackColor = System.Drawing.SystemColors.Window;
- this.txtBracketCode.Enabled = false;
- this.txtBracketCode.ForeColor = System.Drawing.SystemColors.WindowText;
- this.txtBracketCode.Location = new System.Drawing.Point(536, 312);
- this.txtBracketCode.Name = "txtBracketCode";
- this.txtBracketCode.ReadOnly = true;
- this.txtBracketCode.Size = new System.Drawing.Size(80, 23);
- this.txtBracketCode.TabIndex = 6;
- this.txtBracketCode.Text = "";
- //
- // btnBracketLeft
- //
- this.btnBracketLeft.Location = new System.Drawing.Point(616, 312);
- this.btnBracketLeft.Name = "btnBracketLeft";
- this.btnBracketLeft.Size = new System.Drawing.Size(16, 23);
- this.btnBracketLeft.TabIndex = 7;
- this.btnBracketLeft.Text = "(";
- this.btnBracketLeft.Click += new System.EventHandler(this.btnBracketLeft_Click);
- //
- // btnBracketRight
- //
- this.btnBracketRight.Location = new System.Drawing.Point(632, 312);
- this.btnBracketRight.Name = "btnBracketRight";
- this.btnBracketRight.Size = new System.Drawing.Size(16, 23);
- this.btnBracketRight.TabIndex = 8;
- this.btnBracketRight.Text = ")";
- this.btnBracketRight.Click += new System.EventHandler(this.btnBracketRight_Click);
- //
- // btnBracketClear
- //
- this.btnBracketClear.Location = new System.Drawing.Point(648, 312);
- this.btnBracketClear.Name = "btnBracketClear";
- this.btnBracketClear.Size = new System.Drawing.Size(16, 23);
- this.btnBracketClear.TabIndex = 9;
- this.btnBracketClear.Text = "X";
- this.btnBracketClear.Click += new System.EventHandler(this.btnBracketClear_Click);
- //
- // listView1
- //
- this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
- this.colFieldName,
- this.colCompareCode,
- this.colValue,
- this.colLogicalCode,
- this.colBracketCode,
- this.colFieldIndex});
- this.listView1.FullRowSelect = true;
- this.listView1.GridLines = true;
- this.listView1.Location = new System.Drawing.Point(0, 54);
- this.listView1.Name = "listView1";
- this.listView1.Size = new System.Drawing.Size(664, 248);
- this.listView1.TabIndex = 1;
- this.listView1.TabStop = false;
- this.listView1.View = System.Windows.Forms.View.Details;
- //
- // colFieldName
- //
- this.colFieldName.Text = "FieldName";
- this.colFieldName.Width = 200;
- //
- // colCompareCode
- //
- this.colCompareCode.Text = "CompareCode";
- this.colCompareCode.Width = 90;
- //
- // colValue
- //
- this.colValue.Text = "Value";
- this.colValue.Width = 130;
- //
- // colLogicalCode
- //
- this.colLogicalCode.Text = "LogicalCode";
- this.colLogicalCode.Width = 90;
- //
- // colBracketCode
- //
- this.colBracketCode.Text = "BracketCode";
- this.colBracketCode.Width = 90;
- //
- // colFieldIndex
- //
- this.colFieldIndex.Text = "FieldIndex";
- this.colFieldIndex.Width = 0;
- //
- // SearchFilter
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(7, 16);
- this.ClientSize = new System.Drawing.Size(666, 342);
- this.Controls.Add(this.btnBracketClear);
- this.Controls.Add(this.btnBracketRight);
- this.Controls.Add(this.btnBracketLeft);
- this.Controls.Add(this.txtBracketCode);
- this.Controls.Add(this.txtValue);
- this.Controls.Add(this.comLogicalCode);
- this.Controls.Add(this.toolBar1);
- this.Controls.Add(this.comCompareCode);
- this.Controls.Add(this.comFieldText);
- this.Controls.Add(this.listView1);
- this.Font = new System.Drawing.Font("宋体", 10F);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "SearchFilter";
- this.ShowInTaskbar = false;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
- this.Text = "Search Filter";
- this.Closing += new System.ComponentModel.CancelEventHandler(this.SearchFilter_Closing);
- this.ResumeLayout(false);
- }
- #endregion
- private bool IsBoolen(ref string Value)
- {
- try
- {
- bool b=Convert.ToBoolean(Value);
- Value=b.ToString();
- return true;
- }
- catch { return false; }
- }
- private bool IsDateTime(ref string Value)
- {
- try
- {
- DateTime d=Convert.ToDateTime(Value);
- Value=d.ToString("yyyy-MM-dd");
- return true;
- }
- catch { return false; }
- }
- private bool IsNumber(ref string Value)
- {
- try
- {
- double n=Convert.ToDouble(Value);
- Value=n.ToString();
- return true;
- }
- catch { return false; }
- }
- private bool IsValid(DataType Type, ref string Value)
- {
- bool result=false;
- switch (Type)
- {
- case DataType.Boolen:
- result=IsBoolen(ref Value);
- break;
- case DataType.DataTime:
- result=IsDateTime(ref Value);
- break;
- case DataType.Number:
- result=IsNumber(ref Value);
- break;
- case DataType.String:
- result=true;
- break;
- }
- return result;
- }
- private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
- {
- switch (e.Button.Tag.ToString())
- {
- case "Add":
- AddNew();
- break;
- case "Delete":
- Delete();
- break;
- //case "Filter":
- // Filter();
- // break;
- case "Search":
- Search();
- break;
- case "Exit":
- Exit();
- break;
- }
- }
- private void AddNew()
- {
- string Value=this.txtValue.Text.Trim().Replace("'","");
- if (IsValid(_fs[this.comFieldText.SelectedIndex].DataType, ref Value)==true)
- {
- ListViewItem lvi=new ListViewItem(this.comFieldText.Text);
- lvi.SubItems.Add(this.comCompareCode.Text);
- lvi.SubItems.Add(Value);
- lvi.SubItems.Add(this.comLogicalCode.Text);
- lvi.SubItems.Add(this.txtBracketCode.Text);
- lvi.SubItems.Add(this.comFieldText.SelectedIndex.ToString());
- this.listView1.Items.Add(lvi);
- this.txtBracketCode.Text ="";
- }
- else
- {
- MessageBox.Show("The " + _fs[this.comFieldText.SelectedIndex].DataType.ToString() + " field value is invalid.",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
- this.txtValue.Focus();
- }
- }
- private void Delete()
- {
- if (this.listView1.Items.Count ==0) return;
- if (this.listView1.SelectedItems.Count ==0) return;
- //listView1.Items.RemoveAt(listView1.SelectedItems[0].Index);
- for (int i=this.listView1.Items.Count-1;i>=0;i--)
- {
- if (this.listView1.Items[i].Selected) this.listView1.Items[i].Remove();
- }
- this.txtBracketCode.Text ="";
- }
- private void FillFilter()
- {
- int m;
- string key;
- _fs.FilterClear();
- for (int i=0;i<this.listView1.Items.Count;i++)
- {
- key=i.ToString();
- m=Convert.ToInt32(this.listView1.Items[i].SubItems[5].Text);
- _fs[key]=new Filter(_fs[m].Name, _fs[m].Text, _fs[m].DataType);
- _fs[key].CompareCode=this.listView1.Items[i].SubItems[1].Text;
- _fs[key].Value=this.listView1.Items[i].SubItems[2].Text;
- if (i!=this.listView1.Items.Count-1) _fs[key].LogicalCode=this.listView1.Items[i].SubItems[3].Text; //去掉最后一个条件的逻辑运算符
- _fs[key].BracketCode=this.listView1.Items[i].SubItems[4].Text;
- }
- }
- // private void Filter()
- // {
- // FillFilter();
- //
- // MessageBox.Show(_fs.FilterText,"Filter expression",MessageBoxButtons.OK,MessageBoxIcon.Information);
- // }
- private void Search()
- {
- FillFilter();
- this.DialogResult=DialogResult.OK;
- this.Close();
- }
- private void Exit()
- {
- this.DialogResult=DialogResult.Cancel;
- this.Close();
- }
- private void btnBracketLeft_Click(object sender, System.EventArgs e)
- {
- this.txtBracketCode.Text =this.txtBracketCode.Text + "(";
- }
- private void btnBracketRight_Click(object sender, System.EventArgs e)
- {
- this.txtBracketCode.Text =this.txtBracketCode.Text + ")";
- }
- private void btnBracketClear_Click(object sender, System.EventArgs e)
- {
- this.txtBracketCode.Text ="";
- }
- private void SearchFilter_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- if (this.DialogResult!=DialogResult.OK) _fs.FilterClear();
- }
- }
- }
二、使用方法
- IFilterString fs=new FilterString(7);
- fs[0]=new Filter("UserID","用户ID",DataType.Number);
- fs[1]=new Filter("UserName","用户名",DataType.String);
- fs[2]=new Filter("Dept","部门",DataType.String);
- fs[3]=new Filter("Title","职位",DataType.String);
- fs[4]=new Filter("Account","局域网帐号",DataType.String);
- fs[5]=new Filter("EDate","入厂日期",DataType.DataTime);
- fs[6]=new Filter("Isexp","是否在职",DataType.Boolen);
- Form frm=new SearchFilter(fs);
- frm.ShowDialog();
- string s=fs.FilterText;
- MessageBox.Show(s);
三、源码下载