lu
2024-12-03 b7b06604c4057163332b4017e02fe38bb40f51e4
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using DevExpress.RichEdit.Export;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
 
namespace Gs.DevApp.DevFrm.Sys
{
    public partial class DocNoRule : XtraForm
    {
        public DocNoRule()
        {
            InitializeComponent();
            toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
            toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
            toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
            toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick;
            toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            gridView1.FocusedRowChanged += (s, e) =>
            {
                UtilityHelper.SetCheckIco(s, picCheckBox, this, "checkStatus", "");
            };
            getPageList(1, UtilityHelper.GetPageSize());
            pageBar1.PagerEvent += PageBar1_PagerEvent;
            getTree();
            txt_docCode.EditValueChanged += Txt_docCode_EditValueChanged;
            txxtItem1.EditValueChanged += TxxtItem1_EditValueChanged;
            txxtItem2.EditValueChanged += TxxtItem1_EditValueChanged;
            txxtItem3.EditValueChanged += TxxtItem1_EditValueChanged;
            txxtItem4.EditValueChanged += TxxtItem1_EditValueChanged;
            txt_noLength.ValueChanged += Txt_noLength_ValueChanged;
            txt_isIncludeDoc.CheckedChanged +=
                Txt_flagIncludeDocCode_CheckedChanged;
            txt_isSpilit.CheckedChanged +=
                Txt_flagIncludeDocCode_CheckedChanged;
 
           
        }
 
        /// <summary>
        ///     双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var rowGuid =
                UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
            if (!string.IsNullOrEmpty(rowGuid))
            {
                getModel(rowGuid, false, 999);
                txxtItem1.Enabled = txxtItem2.Enabled =
                    txxtItem3.Enabled = txxtItem4.Enabled = false;
            }
        }
 
        /// <summary>
        ///     分页事件
        /// </summary>
        /// <param name="curPage"></param>
        /// <param name="pageSize"></param>
        private void PageBar1_PagerEvent(int curPage, int pageSize)
        {
            getPageList(curPage, pageSize);
        }
 
        /// <summary>
        ///     反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_docCode, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
 
        /// <summary>
        ///     审核事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_docCode, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
 
        /// <summary>
        ///     取消事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
        }
 
        /// <summary>
        ///     删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_docCode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
 
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
                return;
 
            var lst = new List<string>();
            lst.Add(rowGuid);
            var _obj = lst;
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    "DocNoRule/DeleteModel", JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getPageList(1, UtilityHelper.GetPageSize());
                }
 
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        /// <summary>
        ///     刷新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
        }
 
        /// <summary>
        ///     修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_docCode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
 
            getModel(rowGuid, true, 1);
            txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled =
                txxtItem4.Enabled = panelControl1.Enabled = true;
        }
 
        /// <summary>
        ///     新增事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValueByControl(panel1.Controls, true);
            txxtItem1.SelectedIndex = txxtItem2.SelectedIndex =
                txxtItem3.SelectedIndex = txxtItem4.SelectedIndex = 0;
            txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled =
                txxtItem4.Enabled = panelControl1.Enabled = true;
        }
 
        /// <summary>
        ///     保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            if (txt_docCode.EditValue == null ||
                string.IsNullOrEmpty(txt_docCode.EditValue.ToString()))
            {
                MsgHelper.Warning("请先选择单据类型!");
                txt_docCode.Focus();
                return;
            }
 
            if (txxtItem1.SelectedIndex + txxtItem2.SelectedIndex +
                txxtItem3.SelectedIndex + txxtItem4.SelectedIndex <= 0)
            {
                MsgHelper.Warning("请至少选择一个参数!");
                txxtItem1.Focus();
                return;
            }
 
            if (txt_docFormat.Text.Length <= 0)
            {
                MsgHelper.Warning("请先配置参数!");
                txt_docCode.Focus();
                return;
            }
 
            var _obj = new
            {
                guid =UtilityHelper.ToGuid( lbGuid.Text.Trim()), //主建
                docCode = txt_docCode.EditValue.ToString(),
                docFormat = txt_docFormat.Text,
                noLength = txt_noLength.Value.ToString(),
                resetZero = txt_resetZero.Checked,
                isSpilit = txt_isSpilit.Checked,
                isIncludeDoc = txt_isIncludeDoc.Checked
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("", "DocNoRule/EditModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnableByControl(panel1.Controls, false);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        /// <summary>
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage, int pageSize)
        {
            var pgq = new PageQueryModel(curPage, pageSize, "doc_Code");
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                var strReturn =
                    UtilityHelper.HttpPost("", "DocNoRule/GetListPage", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                if (dd.rtnCode > 0)
                {
                    DataTable dt = dd.rtnData.list;
                    gcMain.BindingContext = new BindingContext();
                    gcMain.DataSource = dt;
                    gcMain.ForceInitialize();
                    int dddd = dd.rtnData.pages;//总页
                    pageBar1.TotalPages = dddd;
                    pageBar1.RecordCount = dd.rtnData.total;//记录总数
                    pageBar1.CurrentPage = curPage;//当前页
                    pageBar1.setTxt();
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getModel(string strGuid, bool isEdit, int tabIdx)
        {
            if (string.IsNullOrEmpty(strGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
 
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid //主建
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("", "DocNoRule/GetModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    var dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(panel1.Controls, dy, isEdit);
                    txt_docCode.EditValue = dy.docCode.ToString();
                    string _rule = dy.docFormat.ToString();
                    var _ary = _rule.Split(new[] { '<' },
                        StringSplitOptions.RemoveEmptyEntries);
                    if (_ary.Length > 0)
                        txxtItem1.Text = "<" + _ary[0];
                    if (_ary.Length > 1)
                        txxtItem2.Text = "<" + _ary[1];
                    if (_ary.Length > 2)
                        txxtItem3.Text = "<" + _ary[2];
                    if (_ary.Length > 3)
                        txxtItem4.Text = "<" + _ary[3];
                }
                else
                {
                    MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getTree()
        {
            var dataTable = new DataTable();
            dataTable.Columns.Add("docCode", typeof(string));
            dataTable.Rows.Add("DH(到货单)");
            dataTable.Rows.Add("JY(检验单)");
            dataTable.Rows.Add("TL(退料单)");
            dataTable.Rows.Add("IN(入库单)");
            dataTable.Rows.Add("PB(批量排产)");
            dataTable.Rows.Add("SC(生产工单)");
            dataTable.Rows.Add("OUT(出库单)");
            dataTable.Rows.Add("HB(物料合并)");
            dataTable.Rows.Add("QTSQ(其他入库申请)");
            txt_docCode.Properties.DataSource = dataTable;
            txt_docCode.Properties.DisplayMember = "docCode"; // 显示的列
            txt_docCode.Properties.ValueMember = "docCode"; // 实际值的列
            txt_docCode.Properties.TextEditStyle =TextEditStyles.DisableTextEditor;
        }
 
        private void Txt_flagIncludeDocCode_CheckedChanged(object sender,
            EventArgs e)
        {
            DoPreviewCode();
        }
 
        private void Txt_noLength_ValueChanged(object sender, EventArgs e)
        {
            DoPreviewCode();
        }
 
        private void TxxtItem1_EditValueChanged(object sender, EventArgs e)
        {
            DoPreviewCode();
        }
 
        private void DoPreviewCode()
        {
            if (txt_docCode.Enabled == false
                || txxtItem1.Enabled == false
                || txxtItem2.Enabled == false
                || txxtItem3.Enabled == false
                || txxtItem4.Enabled == false)
                return;
            var text = txxtItem1.Text + txxtItem2.Text + txxtItem3.Text +
                       txxtItem4.Text;
            txt_docFormat.Text = text;
            if (txt_docFormat.Text == "")
            {
                lblPreview.Text = "请定义规则.";
            }
            else
            {
                // txtRuleFormat="<年年>", "<年年年年>", "<月月>", "<日日>" });
                var preview = txt_docFormat.Text;
                var length = int.Parse(txt_noLength.Value.ToString());
                var docCode = "";
                if (txt_isIncludeDoc.Checked)
                    docCode = txt_docCode.EditValue.ToString();
                preview = docCode + preview;
                preview = preview.Replace("<无>", "");
                preview = preview.Replace("<年年年年>", "2024");
                preview = preview.Replace("<年年>", "24");
                preview = preview.Replace("<月月>", "06");
                preview = preview.Replace("<日日>", "18");
                preview = preview + (txt_isSpilit.Checked ? "-" : "") +
                          "8".PadLeft(length, '0');
                lblPreview.Text = "生成编号:" + preview;
            }
        }
 
        private void Txt_docCode_EditValueChanged(object sender, EventArgs e)
        {
            DoPreviewCode();
        }
    }
}