lu
2025-03-21 1b23b7f2e874036accaf5a565852ce1e01589281
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Text;
using System.Windows.Forms;
using DevExpress.Pdf.Native.BouncyCastle.Utilities.Collections;
using DevExpress.PivotGrid.OLAP.Mdx;
using DevExpress.Utils.DirectXPaint;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base.ViewInfo;
using FastReport.MSChart;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
 
namespace Gs.DevApp.UserControl
{
    public partial class ShowFilter : XtraForm
    {
        private readonly GridColumnCollection _columns;
        private readonly string _fullName;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Columns">列名</param>
        /// <param name="list">默认值</param>
        /// <param name="FullName">类名</param>
        public ShowFilter(GridColumnCollection Columns,
            List<FilterEntity> list = null, string FullName = "")
        {
            FilterList = list;
            _columns = Columns;
            _fullName = FullName;
            InitializeComponent();
            repositoryItemComboBox1.TextEditStyle =
                TextEditStyles.DisableTextEditor;
            repositoryItemComboBox1.SelectedIndexChanged +=
                RepositoryItemComboBox1_SelectedIndexChanged;
            repositoryItemComboBox1.ParseEditValue +=
                RepositoryItemComboBox1_ParseEditValue;
            repositoryItemComboBox2.TextEditStyle =
                TextEditStyles.DisableTextEditor;
            repositoryItemComboBox2.SelectedIndexChanged +=
                RepositoryItemComboBox2_SelectedIndexChanged;
            repositoryItemComboBox2.ParseEditValue +=
                RepositoryItemComboBox2_ParseEditValue;
            gridView1.OptionsFind.ShowSearchNavButtons = false;
            // this.gridView1.OptionsView.ShowAutoFilterRow = true;
            gridView1.OptionsView.ShowGroupPanel = false;
            gvQuery.OptionsView.ShowGroupPanel = false;
            gvTable.OptionsView.ShowGroupPanel = false;
            btnEsc.Click += BtnEsc_Click;
            btnQuery.Click += BtnQuery_Click;
            getPageList();
            //下面为查询配置
            this.btnSqlTable.Click += BtnSqlTable_Click;
            getPageListQuery();
        }
 
 
 
        /// <summary>
        ///     查询集合
        /// </summary>
        public List<FilterEntity> FilterList { get; set; }
 
        /// <summary>
        ///     回调事件
        /// </summary>
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
 
        private void BtnQuery_Click(object sender, EventArgs e)
        {
            gridView1.CloseEditor();
            gridView1.UpdateCurrentRow();
            var sbWhere = new StringBuilder();
            var list = new List<FilterEntity>();
            for (var i = 0; i < gridView1.DataRowCount; i++)
            {
                if (string.IsNullOrEmpty(gridView1.GetRowCellValue(i, "field")
                        .ToString())
                    || string.IsNullOrEmpty(gridView1
                        .GetRowCellValue(i, "fieldWhere").ToString())
                    || string.IsNullOrEmpty(gridView1
                        .GetRowCellValue(i, "fieldValue").ToString())
                   )
                    continue;
                string _fieId, _fileIdDec;
                (_fieId, _fileIdDec) =
                    _getFiled(gridView1.GetRowCellValue(i, "field").ToString());
                string _fileWhere, _fileWhereDec;
                (_fileWhere, _fileWhereDec) = _getFiled(gridView1
                    .GetRowCellValue(i, "fieldWhere").ToString());
                var _fieldValue = gridView1.GetRowCellValue(i, "fieldValue")
                    .ToString();
                if (_fileWhere.Contains("like"))
                {
                    _fileWhere = " like ";
                    _fieldValue = "%" + _fieldValue + "%";
                }
 
                list.Add(new FilterEntity(_fieId, _fileIdDec, _fileWhere,
                    _fileWhereDec, _fieldValue));
            }
 
            UpdateParent?.Invoke(this,
                new UpdateParentEventArgs { FilterList = list });
            Close();
        }
 
        /// <summary>
        /// </summary>
        private void getPageList()
        {
            foreach (GridColumn col in _columns)
                if (col.Tag != null && col.Tag.ToString().StartsWith("query"))
                {
                    var item = new CboItemEntity();
                    item.Text = col.Tag.ToString().Replace("query_", "") +
                                "(" + col.Caption + ")";
                    //item.Value = col.FieldName;
                    item.Value = col.Tag.ToString().Replace("query_", "");
                    repositoryItemComboBox1.Items.Add(item);
                }
 
            var d2 = new Dictionary<string, string>();
            d2.Add(">", "大于");
            d2.Add("<", "小于");
            d2.Add("=", "等于");
            d2.Add("<>", "不等于");
            d2.Add("like", "包含");
            foreach (var kvp in d2)
            {
                var item = new CboItemEntity();
                item.Text = kvp.Key + "(" + kvp.Value + ")";
                item.Value = kvp.Key;
                repositoryItemComboBox2.Items.Add(item);
            }
            try
            {
                var dt = new DataTable();
                dt.Columns.Add("field", typeof(string));
                dt.Columns.Add("fieldWhere", typeof(string));
                dt.Columns.Add("fieldValue", typeof(string));
                foreach (var _sql in FilterList)
                {
                    var dr = dt.NewRow();
                    dr["field"] = _sql.fileId + "(" + _sql.fileIdDec;
                    dr["fieldWhere"] = _sql.fileOper + "(" + _sql.fileOperDec;
                    dr["fieldValue"] = _sql.fileValue.Replace("%", "");
                    dt.Rows.Add(dr);
                }
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = dt;
                gcMain.ForceInitialize();
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private (string, string) _getFiled(string _field)
        {
            return (_field.Split('(')[0], _field.Split('(')[1]);
        }
 
        private void BtnEsc_Click(object sender, EventArgs e)
        {
            Close();
        }
 
        private void RepositoryItemComboBox2_ParseEditValue(object sender,
            ConvertEditValueEventArgs e)
        {
            if (e.Value != null)
            {
                e.Value = e.Value.ToString();
                e.Handled = true;
            }
        }
 
        private void RepositoryItemComboBox2_SelectedIndexChanged(object sender,
            EventArgs e)
        {
        }
 
        private void RepositoryItemComboBox1_ParseEditValue(object sender,
            ConvertEditValueEventArgs e)
        {
            if (e.Value != null)
            {
                e.Value = e.Value.ToString();
                e.Handled = true;
            }
        }
 
        private void RepositoryItemComboBox1_SelectedIndexChanged(object sender,
            EventArgs e)
        {
        }
 
 
        /// <summary>
        /// 移出一行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void repositoryItemButtonEdit1_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            gridView1.CloseEditor();
            gridView1.UpdateCurrentRow();
            var rowhandle = gridView1.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                var dr = gridView1.GetDataRow(rowhandle);
                gridView1.DeleteRow(rowhandle);
                return;
            }
        }
 
 
        #region MyRegion
        /// <summary>
        ///     截取表名
        /// </summary>
        /// <param name="strName"></param>
        /// <returns></returns>
        private string _getTableName(string strName)
        {
            var _tableName = strName.Split('(')[0];
            return _tableName;
        }
        private void BtnSqlTable_Click(object sender, EventArgs e)
        {
            //System.Text.StringBuilder sb = new System.Text.StringBuilder();
            //var list = txt_table.Properties.Items.GetCheckedValues();
            //foreach (var obj in list)
            //{
            //    if (sb.Length > 0)
            //        sb.Append(",");
            //    sb.Append(_getTableName(obj.ToString()));
 
            //}
 
            //if (sb.Length < 0)
            //{
            //    Gs.DevApp.ToolBox.MsgHelper.Warning("请选择关联表!");
            //    txt_table.Focus();
            //    return;
            //}
 
            //var _obj = new
            //{
            //    guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
            //    djlx = djlx,//单据类型
            //    salesId = _sqGuid,//销售单号
            //    inRemark = FNote.Trim(),//备注
            //    list = new List<dynamic>(),
            //};
            //try
            //{
            //    string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj));
            //    ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
            //    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            //    if (_rtn.rtnCode > 0)
            //    {
            //        lbGuid.Text = _rtn.rtnData.outGuid;
            //        txt_billNo.Text = _rtn.rtnData.outNo;
            //        toolBarMenu1.isSetBtn = true;
            //        List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
            //        gvList.Add(gvMx1);
            //        UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false, gvList);
            //        toolBarMenu1.currentAction = "";
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            //}
 
        }
        private void getPageListQuery()
        {
            repositoryItemComboBoxSql.Items.Clear();
            repositoryItemComboBoxSql.Items.Add("1");
            repositoryItemComboBoxSql.Items.Add("1");
            repositoryItemComboBoxSql.Items.Add("1");
            var _obj = new
            {
                formPath = this._fullName,
                list = new List<dynamic>(),
            };
            foreach (GridColumn col in _columns)
            {
                _obj.list.Add(new
                {
                    colName = col.Name.ToString(),
                    colCap = col.Caption
                });
            }
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    "Fm/GetQuery", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                JObject _job = JObject.Parse(strJson);
                ////////////
                JArray array = new JArray();
                foreach (var a in _job["rtnData"]["list"])
                {
                    array.Add(a);
                }
                DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
                gcTable.BindingContext = new BindingContext();
                gcTable.DataSource = dt;
                gcTable.ForceInitialize();
                ////////////
                JArray array2 = new JArray();
                foreach (var a in _job["rtnData"]["list2"])
                {
                    array2.Add(a);
                }
                DataTable dt2 = JsonConvert.DeserializeObject<DataTable>(array2.ToString());
                gcQuery.BindingContext = new BindingContext();
                gcQuery.DataSource = dt2;
                gcQuery.ForceInitialize();
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        #endregion
    }
}