啊鑫
2024-07-09 0552fcc8cb73fc3021e2915129f55a42ed3f20e5
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#region
 
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
 
#endregion
 
namespace CSFrameworkV5.Library.UserControls
{
    /// <summary>
    ///     应用CodeNamePicker组件,查询数据的事件
    /// </summary>
    /// <param name="code">编号</param>
    /// <param name="name">名称</param>
    /// <returns></returns>
    public delegate DataTable OnShowFiltredData(string code, string name);
 
    /// <summary>
    ///     标准编号名称选择框
    /// </summary>
    public partial class ucCodeNamePicker : UserControl
    {
        private EventHandler _OnClear;
 
        private LookupEditorPopupControlClick _OnRowClick;
 
        private OnShowFiltredData _OnShowFiltredData;
 
        private bool _ShowClear;
 
        public ucCodeNamePicker()
        {
            InitializeComponent();
        }
 
        public PopupContainerControl PopupContainer => popupContainerControl1;
 
        public bool ShowClear
        {
            set => _ShowClear = value;
            get => _ShowClear;
        }
 
        private void btnClose_Click(object sender, EventArgs e)
        {
            if (_OnClear != null)
            {
                _OnClear(sender, e);
                txt_Code.Text = "";
                txt_Name.Text = "";
            }
        }
 
        public void DoAddColumn(string fieldName, string caption, int width)
        {
            var col = new GridColumn();
            col.FieldName = fieldName;
            col.Name = "col" + fieldName;
            col.Width = width;
            col.Caption = caption;
            col.Visible = true;
            col.VisibleIndex = gvSummary.Columns.Count;
            gvSummary.Columns.Add(col);
        }
 
        public void DoSetCaption(string code, string name)
        {
            colID.Caption = code;
            colName.Caption = name;
        }
 
        public void DoSetEditorCaption(string code, string name)
        {
            lbCode.Text = code;
            lbName.Text = name;
        }
 
        public void DoSetField(string codeField, string nameField)
        {
            colID.FieldName = codeField;
            colName.FieldName = nameField;
        }
 
        public void DoSetSize(int height)
        {
            var i = 0;
            foreach (GridColumn c in gvSummary.Columns) i += c.Width;
 
            if (i + 50 < 300)
                Width = 300;
            else
                Width = i + 50;
 
            Height = height;
        }
 
        public void DoShowDefaultData(DataTable source)
        {
            gcSummary.DataSource = source;
            gcSummary.RefreshDataSource();
        }
 
        private void DoShowFiltredData()
        {
            if (_OnShowFiltredData != null)
            {
                var dt = _OnShowFiltredData(txt_Code.Text, txt_Name.Text);
                gcSummary.DataSource = null;
                gcSummary.DataSource = dt;
                gcSummary.RefreshDataSource();
            }
        }
 
        private void gvSummary_RowClick(object sender, RowClickEventArgs e)
        {
            if (_OnRowClick != null)
            {
                popupContainerControl1.Hide();
                _OnRowClick(gvSummary.GetDataRow(gvSummary.FocusedRowHandle));
                txt_Code.Text = "";
                txt_Name.Text = "";
            }
        }
 
        public event EventHandler OnClear
        {
            add => _OnClear = value;
            remove => _OnClear = null;
        }
 
        public event LookupEditorPopupControlClick OnRowClick
        {
            add => _OnRowClick = value;
            remove => _OnRowClick = null;
        }
 
        public event OnShowFiltredData OnShowFiltredData
        {
            add => _OnShowFiltredData = value;
            remove => _OnShowFiltredData = null;
        }
 
        private void txt_Code_EditValueChanged(object sender, EventArgs e)
        {
            DoShowFiltredData();
        }
 
        private void txt_Name_EditValueChanged(object sender, EventArgs e)
        {
            DoShowFiltredData();
        }
 
        private void ucCodeNamePicker_Load(object sender, EventArgs e)
        {
            btnClear.Visible = _ShowClear;
        }
    }
}