#region
using System;
using System.Data;
using System.Drawing;
using CSFrameworkV5.Common;
using CSFrameworkV5.Interfaces;
using CSFrameworkV5.Library.CommonClass;
using DevExpress.XtraEditors;
#endregion
namespace CSFrameworkV5.Library
{
///
/// 通用模糊查询选择窗体
///
public partial class frmFuzzySearch : frmBaseDialog
{
//打开查询窗体的业务逻辑层
private IFuzzySearchSupportable _BLL;
private DataRow _ReturnRow; //返回一条记录.
//私有构造器
private frmFuzzySearch()
{
InitializeComponent();
}
///
/// 取消
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
///
/// 关闭窗体返回当前选择的记录
///
///
///
private void btnOk_Click(object sender, EventArgs e)
{
try
{
if (gvSummary.FocusedRowHandle < 0) return;
//返回当前选择的记录.
_ReturnRow = gvSummary.GetDataRow(gvSummary.FocusedRowHandle);
Close();
}
catch (Exception ex)
{
Msg.ShowException(ex);
}
}
///
/// 搜索查询
///
///
///
private void btnQuery_Click(object sender, EventArgs e)
{
DoQuery(txtValue.Text);
}
///
/// 执行查询
///
/// 查询的内容
private void DoQuery(string content)
{
if (_BLL == null) throw new CustomException("没有指定业务层,无法执行查询!");
try
{
frmWaitingEx.ShowMe(this);
btnQuery.Enabled = false;
var dt = _BLL.FuzzySearch(content);
gvSummary.GridControl.DataSource = dt;
}
finally
{
btnQuery.Enabled = true;
frmWaitingEx.HideMe(this);
}
}
///
/// 打开查询窗体
///
/// 事件发起人
/// 回调函数,当选择一个条记录后关闭窗体时调用
public static void Execute(ButtonEdit Sender,
IFuzzySearchSupportable BLL, SearchCallBack callBack)
{
var form = new frmFuzzySearch();
form._BLL = BLL;
form.txtValue.Text = Sender.Text;
form.DoQuery(form.txtValue.Text);
form.ShowDialog();
if (callBack != null) callBack(form._ReturnRow);
}
///
/// 打开产品资料查询窗体.
///
///
public static DataRow Execute(IFuzzySearchSupportable BLL)
{
var form = new frmFuzzySearch();
form._BLL = BLL;
form.ShowDialog();
return form._ReturnRow;
}
private void frmFuzzySearch_Load(object sender, EventArgs e)
{
btnOk.Location = new Point(331, 10);
btnCancel.Location = new Point(440, 10);
}
///
/// 双击按钮关闭查询窗体并返回结果
///
///
///
private void gvSummary_DoubleClick(object sender, EventArgs e)
{
if (gvSummary.RowCount > 0) btnOk.PerformClick();
}
}
}