啊鑫
2024-07-11 afbf8700d137710713db61955879d0f5acb73738
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#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
{
    /// <summary>
    ///     通用模糊查询选择窗体
    /// </summary>
    public partial class frmFuzzySearch : frmBaseDialog
    {
        //打开查询窗体的业务逻辑层
        private IFuzzySearchSupportable _BLL;
 
        private DataRow _ReturnRow; //返回一条记录.
 
        //私有构造器
        private frmFuzzySearch()
        {
            InitializeComponent();
        }
 
        /// <summary>
        ///     取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        /// <summary>
        ///     关闭窗体返回当前选择的记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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);
            }
        }
 
        /// <summary>
        ///     搜索查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnQuery_Click(object sender, EventArgs e)
        {
            DoQuery(txtValue.Text);
        }
 
        /// <summary>
        ///     执行查询
        /// </summary>
        /// <param name="content">查询的内容</param>
        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);
            }
        }
 
        /// <summary>
        ///     打开查询窗体
        /// </summary>
        /// <param name="Sender">事件发起人</param>
        /// <param name="callBack">回调函数,当选择一个条记录后关闭窗体时调用</param>
        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);
        }
 
        /// <summary>
        ///     打开产品资料查询窗体.
        /// </summary>
        /// <returns></returns>
        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);
        }
 
        /// <summary>
        ///     双击按钮关闭查询窗体并返回结果
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gvSummary_DoubleClick(object sender, EventArgs e)
        {
            if (gvSummary.RowCount > 0) btnOk.PerformClick();
        }
    }
}