duhe
2023-05-31 7471f7ba4991636fa75d8f474687815eee583a21
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using gregn6Lib;
using Pub_Class;
 
namespace WorkM
{
    public partial class Kf_WIPBal_Add : Form
    {
        public Kf_WIPBal_Add()
        {
            InitializeComponent();
        }
 
 
        public const Int16 HTagCol = 0;
        public const Int16 HSnoCol = 1;
        public const Int16 HICMOInterIDCol = 2;
        public const Int16 HICMONoCol = 3;
        public const Int16 HMaterIDCol = 4;
        public const Int16 HMaterNumberCol = 5;
        public const Int16 HMaterNameCol = 6;
        public const Int16 HMaterModelCol = 7;
        public const Int16 HProcNoCol = 8;
        public const Int16 HProcIDCol = 9;
        public const Int16 HProcNumberCol = 10;
        public const Int16 HProcNameCol = 11;
        public const Int16 HQtyCol = 12;
 
        ClsGridViewSum oSumGrid = new ClsGridViewSum();
        public bool grdStatus=true;                                 //网格状态(不可编辑,可编辑)
 
        #region 窗体处理方法
        //初始化GRID
        private void initGrid()
        {
            //
            grdMain.ColumnCount = 13;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name);
            ////=
            grdMain.Columns[HICMONoCol].HeaderText = "任务单号";
            grdMain.Columns[HMaterNumberCol].HeaderText = "物料代码";
            grdMain.Columns[HMaterNameCol].HeaderText = "物料名称";
            grdMain.Columns[HMaterModelCol].HeaderText = "规格型号";
            grdMain.Columns[HProcNoCol].HeaderText = "工序号";
            grdMain.Columns[HProcNumberCol].HeaderText = "工序代码";
            grdMain.Columns[HProcNameCol].HeaderText = "工序名称";
            grdMain.Columns[HQtyCol].HeaderText = "期初数量";
            ////固定赋值=====================================================
            grdMain.Columns[HSnoCol].HeaderText = "序号";
            ////=============================================================================
            ////格式化 
            //////隐藏列
            grdMain.Columns[HTagCol].Visible = false;
            grdMain.Columns[HICMOInterIDCol].Visible = false;
            grdMain.Columns[HMaterIDCol].Visible = false;
            grdMain.Columns[HProcIDCol].Visible = false; 
 
            //设置可编辑列
            string sAllowCol = HICMONoCol.ToString() +
                            "," + HMaterNumberCol.ToString() +
                            "," + HProcNoCol.ToString() +
                            "," + HProcNumberCol.ToString() +
                            "," + HProcNameCol.ToString() +
                            "," + HQtyCol.ToString();
 
            //设置合计列
            string sTotalCol = HQtyCol.ToString();
            //格式化网格
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid);
        }
        
        //帮助函数
        private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit)
        {
            DAL.ClsK3_ICMOBill_View oICMO = new DAL.ClsK3_ICMOBill_View();
            DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
            DAL.ClsK3_Process_View oProc = new DAL.ClsK3_Process_View();
       
            oSumGrid.EditStatus = true; 
            switch (sKeyCode)
            {
                case 118:          //F7
                    {
                        switch (sCol)
                        {
                            case HICMONoCol:
                                oICMO.WherePart = "";
                                if (oICMO.RefreshView())
                                {
                                    if (oICMO.GetInfoByID(oICMO.oModel.HItemID))
                                    {
                                        grdMain.Rows[sRow].Cells[HICMOInterIDCol].Value = oICMO.oModel.HItemID.ToString();
                                        grdMain.Rows[sRow].Cells[HICMONoCol].Value = oICMO.oModel.HNumber;
                                        if (oICMO.omodel.HMaterID != 0)
                                        {
                                            if (oMater.GetInfoByID(oICMO.omodel.HMaterID))
                                            {
                                                grdMain.Rows[sRow].Cells[HMaterIDCol].Value = oMater.omodel.HItemID.ToString();
                                                grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber;
                                                grdMain.Rows[sRow].Cells[HMaterNameCol].Value = oMater.omodel.HName;
                                                grdMain.Rows[sRow].Cells[HMaterModelCol].Value = oMater.omodel.HModel;
                                            }
                                            else
                                            {
                                                grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0;
                                                grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = "";
                                                grdMain.Rows[sRow].Cells[HMaterNameCol].Value = "";
                                                grdMain.Rows[sRow].Cells[HMaterModelCol].Value = "";
                                            }
                                        }
                                        oEdit.Text = oICMO.oModel.HNumber;
                                    }
                                    else
                                    {
                                        grdMain.Rows[sRow].Cells[HICMOInterIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HICMONoCol].Value = "";
                                    }
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HICMOInterIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HICMONoCol].Value = "";
                                }
                                break;
 
                            //case HMaterNumberCol:
                            //    BLL.ClsBaseSelect_K3.SetGridByMater_K3(grdMain, sRow, HMaterIDCol, HMaterNumberCol, HMaterNameCol, HMaterModelCol, 0, 0, 0, 0, 0);
 
                            //    //BLL.ClsBaseSelect.SetGridByMater(grdMain, sRow, HMaterIDCol, HMaterNumberCol, HMaterNameCol, HMaterModelCol, HUnitIDCol, HUnitNumberCol, HUnitNameCol, HSubjoinCol, HColorCol);
                            //    //BLL.ClsPub_BLL.SetGridWarehouse(DBUtility.ClsPub.isLong(txtHWHID.Tag), grdMain, HMaterIDCol, sRow, HWHIDCol, HWHNameCol, HWHNumberCol);
                              
                            //    oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HMaterNumberCol].Value);
                            //    break;
 
                            case HMaterNumberCol:
                                oMater.WherePart = "";
                                if (oMater.RefreshView())
                                {
                                    if (oMater.GetInfoByID(oMater.omodel.HItemID))
                                    {
                                        grdMain.Rows[sRow].Cells[HMaterIDCol].Value = oMater.omodel.HItemID.ToString();
                                        grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber;
                                        grdMain.Rows[sRow].Cells[HMaterNameCol].Value = oMater.omodel.HName;
                                        grdMain.Rows[sRow].Cells[HMaterModelCol].Value = oMater.omodel.HModel;
                                        oEdit.Text = oMater.omodel.HNumber;
                                    }
                                    else
                                    {
                                        grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HMaterNameCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HMaterModelCol].Value = "";
                                    }
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HMaterNameCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HMaterModelCol].Value = "";
                                }
                                break;
 
                            case HProcNumberCol:
                                oProc.WherePart = "";
                                if (oProc.RefreshView())
                                {
                                    if (oProc.GetInfoByID(oProc.oModel.HItemID))
                                    {
                                        grdMain.Rows[sRow].Cells[HProcIDCol].Value = oProc.oModel.HItemID.ToString();
                                        grdMain.Rows[sRow].Cells[HProcNumberCol].Value = oProc.oModel.HNumber;
                                        grdMain.Rows[sRow].Cells[HProcNameCol].Value = oProc.oModel.HName;
                                        oEdit.Text = oProc.omodel.HNumber;
                                    }
                                    else
                                    {
                                        grdMain.Rows[sRow].Cells[HProcIDCol].Value = 0;
                                        grdMain.Rows[sRow].Cells[HProcNumberCol].Value = "";
                                        grdMain.Rows[sRow].Cells[HProcNameCol].Value = ""; 
                                    }
                                }
                                else
                                {
                                    grdMain.Rows[sRow].Cells[HProcIDCol].Value = 0;
                                    grdMain.Rows[sRow].Cells[HProcNumberCol].Value = "";
                                    grdMain.Rows[sRow].Cells[HProcNameCol].Value = ""; 
                                }
                                break;
 
                            default:
                                break;
                        }
               
 
                        break;
                    }
                case 117:  //F6
                    {
                        switch (sCol)
                        {
                            default:
                                break;
                        }
                        break;
                    }
                default:
                    break;
            }
        }
 
        #region  基本不变
 
        //是否是空行
        private bool IsNullRow(int Row)
        {
            //return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HEmpIDCol, grdMain);
            return true;
        }
 
 
        //网格编辑前判断
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i))
            {
                e.Cancel = true;
            }
        }
 
        private void grdMain_Scroll(object sender, ScrollEventArgs e)
        {
            //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //oSumGrid.DisplayCurRow();
        }
 
        //网格编辑后处理
        private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            //RowCount(e.RowIndex, 0);  //计算 金额 单价
            //根据任务单号 返回 内码和物料 
            DAL.ClsK3_Process_View oProc = new DAL.ClsK3_Process_View();
            DAL.ClsK3_ICMOBill_View oICMO = new DAL.ClsK3_ICMOBill_View();
            DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
            int sRow = e.RowIndex;
            if (DBUtility.ClsPub.isStrNull(EditingControl.Text).Length >=1  &&  e.ColumnIndex == HProcNameCol)
            {
                if (oProc.GetInfoByName(EditingControl.Text))
                {
                    grdMain.Rows[sRow].Cells[HProcIDCol].Value = oProc.omodel.HItemID.ToString();
                    grdMain.Rows[sRow].Cells[HProcNumberCol].Value = oProc.omodel.HNumber.ToString();
                    grdMain.Rows[sRow].Cells[HProcNameCol].Value = oProc.omodel.HName;
                }
                else
                {
                    grdMain.Rows[sRow].Cells[HProcIDCol].Value =0;
                    grdMain.Rows[sRow].Cells[HProcNumberCol].Value ="";
                    grdMain.Rows[sRow].Cells[HProcNameCol].Value = "";
                }
            }
            if (DBUtility.ClsPub.isStrNull(EditingControl.Text).Length > 5 && e.ColumnIndex == HICMONoCol)
            {
                if (oICMO.GetInfoByNumberLike(DBUtility.ClsPub.isStrNull(EditingControl.Text)))
                {
                    grdMain.Rows[sRow].Cells[HICMOInterIDCol].Value = oICMO.omodel.HInterID.ToString();
                    //EditingControl.Text = oICMO.oModel.HNumber;
                    grdMain.Rows[sRow].Cells[HICMONoCol].Value = oICMO.omodel.HBillNo;
 
                    if (oICMO.omodel.HMaterID != 0)
                    {
                        if (oMater.GetInfoByID(oICMO.omodel.HMaterID))
                        {
                            grdMain.Rows[sRow].Cells[HMaterIDCol].Value = oMater.omodel.HItemID.ToString();
                            grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber;
                            grdMain.Rows[sRow].Cells[HMaterNameCol].Value = oMater.omodel.HName;
                            grdMain.Rows[sRow].Cells[HMaterModelCol].Value = oMater.omodel.HModel;
                        }
                        else
                        {
                            grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0;
                            grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = "";
                            grdMain.Rows[sRow].Cells[HMaterNameCol].Value = "";
                            grdMain.Rows[sRow].Cells[HMaterModelCol].Value = "";
                        }
                    }
                }
                else
                {
                    //grdMain.Rows[sRow].Cells[HICMOInterIDCol].Value = 0;
                    //grdMain.Rows[sRow].Cells[HICMONoCol].Value = "";
                }
            }
            //
            //
            if (this.EditingControl != null)      //释放事件
            {
                EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown);
                this.EditingControl = null;
            }
        }
        DataGridViewTextBoxEditingControl EditingControl;
 
        private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            //
            if (!grdStatus)
            {
                return;
            }
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
            // 
            //if (!CheckGridRow(oSumGrid.OldCell.Row))
            //    return;
        }
 
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
        private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            if (grdMain.CurrentCell != null)
            {
                if (e.Control is DataGridViewTextBoxEditingControl)
                {
                    this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control;
                    //增加委托处理 
                    this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown);
                }
            }
        }
        private void EditingControl_KeyDown(object sender, KeyEventArgs e)
        {
            //业务处理 
            Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl);
        }
        private void grdMain_RowHeadersWidthChanged(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid);
        }
 
 
        #endregion
 
        private void Kf_WIPBal_Add_Load(object sender, EventArgs e)
        {
            oSumGrid.NoCol = HSnoCol;
            oSumGrid.ogrdMain = grdMain;
            oSumGrid.oGridsum = grdSum;
            initGrid();
 
 
 
        }
 
        #endregion
 
        private void cmbOK_Click(object sender, EventArgs e)
        {    //失去焦点
            label7.Focus();
            int HYear = ClsPub.isInt(cmbHYear.Text);
            int HPeriod = ClsPub.isInt(cmbHPeriod.Text);
            if (MessageBox.Show("确定要新增" + HYear + "年," + HPeriod + "月的期初记录?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                DataSet Ds;
                long HICMOInterID;
                long HMaterID;
                long HProcNo;
                long HProcID;
                double HQty;
                int j = 0;
                for (int i = 0; i < grdMain.Rows.Count; i++)
                {
                    if (ClsPub.isLong(grdMain.Rows[i].Cells[HICMOInterIDCol].Value) != 0)
                    {
                        j = j + 1;
                        HICMOInterID = ClsPub.isLong(grdMain.Rows[i].Cells[HICMOInterIDCol].Value);
                        HMaterID = ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value);
                        HProcNo = ClsPub.isLong(grdMain.Rows[i].Cells[HProcNoCol].Value);
                        HProcID = ClsPub.isLong(grdMain.Rows[i].Cells[HProcIDCol].Value);
                        HQty = ClsPub.isDoule(grdMain.Rows[i].Cells[HQtyCol].Value);
                        if (HMaterID == 0)
                        {
                            MessageBox.Show("第" + (i + 1) + "行,物料不能为空!", "提示");
                            return;
                        }
                        if (HProcNo <= 0)
                        {
                            MessageBox.Show("第" + (i + 1) + "行,工序号不能小于0!", "提示");
                            return;
                        }
                        if (HProcID == 0)
                        {
                            MessageBox.Show("第" + (i + 1) + "行,工序不能为空!", "提示");
                            return;
                        }
                        if (HQty == 0)
                        {
                            MessageBox.Show("第" + (i + 1) + "行,数量不能为0!", "提示");
                            return;
                        }
                        Ds = oCn.RunProcReturn("select 1 from Kf_WIPBal where HYear=" + HYear + " and HPeriod=" + HPeriod + " and HICMOInterID=" + HICMOInterID + " and HMaterID=" + HMaterID + " and HProcNo=" + HProcNo + " and HProcID=" + HProcID, "Kf_WIPBal");
                        if (Ds.Tables[0].Rows.Count > 0)
                        {
                            MessageBox.Show("第" + (i + 1) + "行,已存在期初记录!", "提示");
                            return;
                        }
                    }
                }
                if (j == 0)
                {
                    MessageBox.Show("请输入明细记录!", "提示");
                    return;
                }
                for (int i = 0; i < grdMain.Rows.Count; i++)
                {
                    if (ClsPub.isLong(grdMain.Rows[i].Cells[HICMOInterIDCol].Value) != 0)
                    {
                        HICMOInterID = ClsPub.isLong(grdMain.Rows[i].Cells[HICMOInterIDCol].Value);
                        HMaterID = ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value);
                        HProcNo = ClsPub.isLong(grdMain.Rows[i].Cells[HProcNoCol].Value);
                        HProcID = ClsPub.isLong(grdMain.Rows[i].Cells[HProcIDCol].Value);
                        HQty = ClsPub.isDoule(grdMain.Rows[i].Cells[HQtyCol].Value);
                        oCn.RunProc("exec h_p_Kf_WIPBal_Add " + HYear + "," + HPeriod + "," + HICMOInterID + "," + HMaterID + "," + HProcNo + "," + HProcID + "," + HQty + ",'" + ClsPub.CurUserName + "'");
                    }
                }
                MessageBox.Show("保存完毕!", "提示");
                this.Close();
            }
 
        }
 
        private void cmbCanCel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void bclk_Click(object sender, EventArgs e)
        { 
            //保存列宽
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
 
        private void mrlk_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
        }
 
        private void AddRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.AddRow(oSumGrid);
        }
 
        private void DelRow_Click(object sender, EventArgs e)
        {
            DBUtility.Xt_BaseBillFun.DelRow(oSumGrid);
        }
 
 
    }
}