191 lines
6.3 KiB
C#
191 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
using DevExpress.XtraGrid.Columns;
|
|
|
|
namespace WMS.Ctrl
|
|
{
|
|
public partial class FrmGridViewColFind : Form
|
|
{
|
|
#region 定义变量
|
|
private GridView _MyGridView = null;
|
|
#endregion
|
|
|
|
#region 构造函数
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
/// <param name="gv"></param>
|
|
public FrmGridViewColFind(GridView gv)
|
|
{
|
|
InitializeComponent();
|
|
_MyGridView = gv;
|
|
}
|
|
#endregion
|
|
|
|
#region 初始化
|
|
/// <summary>
|
|
/// 初始化
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmGridViewColFind_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.Cursor = Cursors.WaitCursor;
|
|
this.txtActiveFilterString.Text = _MyGridView.ActiveFilterString;
|
|
//获取列信息
|
|
ColumnsList myColumnsList=new ColumnsList();
|
|
List<ColumnsList> mycolList = myColumnsList.LoadQueryColumn(_MyGridView);
|
|
//绑定
|
|
this.lupCol1.Properties.DataSource = mycolList;
|
|
this.lupCol2.Properties.DataSource = mycolList;
|
|
if (this.txtActiveFilterString.Text == null || this.txtActiveFilterString.Text == "")
|
|
{
|
|
this.chkAnd.Checked = false;
|
|
this.chkOr.Checked = false;
|
|
this.chkDelete.Checked = false;
|
|
}
|
|
|
|
this.Cursor = Cursors.Default;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Cursor = Cursors.Default;
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 按钮事件
|
|
/// <summary>
|
|
/// 确定
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void bOK_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//获取之前的查询条件
|
|
string myActiveFilterString = _MyGridView.ActiveFilterString;
|
|
if (myActiveFilterString == null) myActiveFilterString = "";
|
|
|
|
//第一列
|
|
if (this.lupCol1.EditValue == null || this.lupCol1.EditValue.ToString() == "")
|
|
{
|
|
MessageBox.Show("请选择对比列", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
this.lupCol1.Focus();
|
|
return;
|
|
}
|
|
string colFieldName1 = this.lupCol1.EditValue.ToString();
|
|
|
|
//本次查询条件
|
|
string findType = "";
|
|
if (this.comFindType.Text == "大于") findType = ">";
|
|
if (this.comFindType.Text == "大于等于") findType = ">=";
|
|
if (this.comFindType.Text == "小于") findType = "<";
|
|
if (this.comFindType.Text == "小于等于") findType = "<=";
|
|
if (this.comFindType.Text == "等于") findType = "==";
|
|
if (this.comFindType.Text == "不等于") findType = "!=";
|
|
|
|
//第二列
|
|
string where = "";
|
|
if (this.chkFindValue.Checked == true)
|
|
{
|
|
string colFieldName2 = this.txtFindValue.Text;
|
|
if (colFieldName2 == null) colFieldName2 = "";
|
|
//查询条件
|
|
where = "[" + colFieldName1 + "] " + findType + " '" + colFieldName2 + "'";
|
|
}
|
|
else
|
|
{
|
|
if (this.lupCol2.EditValue == null || this.lupCol2.EditValue == "")
|
|
{
|
|
MessageBox.Show("请选择对比列", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
this.lupCol2.Focus();
|
|
return;
|
|
}
|
|
string colFieldName2 = this.lupCol2.EditValue.ToString();
|
|
//查询条件
|
|
where = "[" + colFieldName1 + "] " + findType + " [" + colFieldName2 + "]";
|
|
}
|
|
|
|
//组合条件
|
|
if (this.chkDelete.Checked == false)
|
|
{
|
|
myActiveFilterString = "";
|
|
}
|
|
if (myActiveFilterString == "")
|
|
{
|
|
myActiveFilterString = where;
|
|
}
|
|
else
|
|
{
|
|
if (this.chkAnd.Checked == false) myActiveFilterString = myActiveFilterString + " && " + where;
|
|
if (this.chkOr.Checked == false) myActiveFilterString = myActiveFilterString + " || " + where;
|
|
}
|
|
|
|
_MyGridView.ActiveFilterString = myActiveFilterString;
|
|
|
|
//返回
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
this.Cursor = Cursors.Default;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Cursor = Cursors.Default;
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void bCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.DialogResult = DialogResult.Cancel;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自定义值 事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void chkFindValue_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.chkFindValue.Checked == true)
|
|
{
|
|
this.txtFindValue.Visible = true;
|
|
this.lupCol2.Visible = false;
|
|
}
|
|
else
|
|
{
|
|
this.txtFindValue.Visible = false;
|
|
this.lupCol2.Visible = true;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Cursor = Cursors.Default;
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|