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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Pub_Class;
using SQLHelper;
 
namespace WorkM
{
    public partial class Sc_ICMOBillList_CLDDlgOrder : Form
    {
        public Sc_ICMOBillList_CLDDlgOrder()
        {
            InitializeComponent();
        }
        public long HICMOInterID = 0;
        public string HICMOBillNo = "";
        public long HMaterID = 0;
        public long HDeptID = 0;
        public double HPlanQty = 0;
        public string HOrderBillNo = "";
 
        public string HOrderProcNo = "";
        //
        public int HQtyCol = 0;
        public int HCountCol = 0;
 
        public int IsOk;
 
        private void cmdCancel_Click(object sender, EventArgs e)
        {
            IsOk = 2;
            this.Visible = false;
        }
 
        private bool AllowOK()
        {
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("Ñ¡Ôñ")].Value) == "¡Ì")
                {
                    if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("¹¤ÒÕ·Ïß")].Value) == "")
                    {
                        MessageBox.Show("Ñ¡ÔñµÄµÚ"+ Convert.ToString(i+1) +"ÐУ¬Ã»ÓÐÉèÖù¤ÒÕ·Ïߣ¬²»ÔÊÐíÏÂÍÆ£¡");
                        return false; 
                    }
                    if (DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[Fun_GetCol("Á÷ת¿¨ÊýÁ¿")].Value) <= 0)
                    {
                        MessageBox.Show("Ñ¡ÔñµÄµÚ" + Convert.ToString(i + 1) + "ÐУ¬Ã»ÓпÉÏÂÍÆÊýÁ¿£¬²»ÔÊÐíÏÂÍÆ£¡");
                        return false;
                    } 
                    if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("״̬")].Value) != "¿ª¹¤")
                    {
                        MessageBox.Show("Ñ¡ÔñµÄµÚ" + Convert.ToString(i + 1) + "ÐУ¬²»ÊÇ¡¾¿ª¹¤¡¿×´Ì¬£¬²»ÔÊÐíÏÂÍÆ£¡");
                        return false;
                    }
                }
            }
            return true;
        }
 
        private void cmdOK_Click(object sender, EventArgs e)
        {
            label4.Focus();
            int sCount = 0;
            if (!AllowOK())
            {
                return;
            }
            //
            int t = 0;
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
               
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("Ñ¡Ôñ")].Value) == "¡Ì")
                {
                //    sCount = DBUtility.ClsPub.isInt(grdMain.Rows[i].Cells[Fun_GetCol("Éú³ÉÕÅÊý")].Value);
                //    for (int c = 0; c <= sCount - 1; c++)
                //    {
                        WriteClass(i);
                    //}
                    t++;
                }
               
            }
            if (t == 0)
            {
                MessageBox.Show("ÇëÑ¡ÔñÐèÒªÏÂÍÆµÄÁ÷ת¿¨");
                return;
            }
            else 
            {
                MessageBox.Show("Éú³ÉÁ÷ת¿¨Íê±Ï£¡");
            }
            //
            IsOk = 1;
            this.Visible = false;
        }
 
        private void WriteClass(int irow)
        {
            ClsCN oCn = new ClsCN();
            DataSet Ds;
            DataSet oDsNo;
            DAL.ClsSc_ProcessExchangeBill BillNew = new DAL.ClsSc_ProcessExchangeBill();
            Int64 HKeyMaterID = 0;
            Int64 HMainMaterID = 0;
            Int64 HMaterID = 0;
            Int64 HUnitID = 0;
            Int64 HBomID = 0;
            DateTime HPlanCommitDate = DateTime.Now;
            DateTime HPlanFinishDate = DateTime.Now;
            Int64 HRoutingID = 0;
            double HQty = 0;
            Int64 HICMOEntryID = 0;
            HMainMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("hmaterid")].Value);
            HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("hmaterid")].Value);
            HUnitID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("HUnitID")].Value);
            HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[irow].Cells[Fun_GetCol("Éú²ú¶©µ¥ºÅ")].Value); 
            HICMOEntryID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("HSubID")].Value);
            HICMOInterID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("HMainID")].Value);
            HQty = DBUtility.ClsPub.isDoule(grdMain.Rows[irow].Cells[Fun_GetCol("Á÷ת¿¨ÊýÁ¿")].Value);
            HDeptID = DBUtility.ClsPub.isLong(grdMain.Rows[irow].Cells[Fun_GetCol("HDeptID")].Value);
            //HNum Á¬½ÓµÄÊÇ ¹¤ÒÕ×éµÄ´úÂë 
            Ds = oCn.RunProcReturn("select * from h_v_Gy_RoutingBillList where HMaterID=" + HMaterID , "h_v_Gy_RoutingBillList");
            if (Ds.Tables[0].Rows.Count > 0)
            {
                BillNew.omodel.HYear = 0;
                BillNew.omodel.HPeriod = 0;
                string sNo = "";
 
                //»ñÈ¡µ±Ç°¸ÄÈÎÎñµ¥ ×î´óÁ÷ת¿¨ºÅ£¬²¢ÀÛ¼ÆÔö¼Ó1¡£
                string sOldNo="";
 
                oDsNo = oCn.RunProcReturn("select top 1 HBillNo  from Sc_ProcessExchangeBillmain where hicmointerid=" + HICMOInterID + "  order by LEN(HBillno) desc, HbillNo desc ", "Sc_ProcessExchangeBillmain");
                if (oDsNo == null || oDsNo.Tables[0].Rows.Count == 0)
                {
                    sNo = "00001";
                }
                else
                {
                    sOldNo = DBUtility.ClsPub.isStrNull(oDsNo.Tables[0].Rows[0]["HBillNo"]);
                    sOldNo = sOldNo.Substring(sOldNo.Length - 3, 3);
                    if (sOldNo.Substring(0, 1) == "0" || sOldNo.Substring(0, 1) == "-")
                    {
                        sOldNo = sOldNo.Substring(sOldNo.Length - 2, 2);
                        if (sOldNo.Substring(0, 1) == "0")
                        {
                            sOldNo = sOldNo.Substring(sOldNo.Length - 1, 1);
                        }
                    } 
                    
                    sNo = "0000" + DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.isLong(sOldNo) + 1);
                }
 
                sNo = sNo.Substring(sNo.Length - 3, 3);
                string sBillNo = HICMOBillNo;
                sBillNo = sBillNo.Replace("WORKX", "");
                sBillNo = sBillNo.Replace("WORK", "");
                sBillNo = sBillNo.Replace("_", "-");
                sBillNo = sBillNo + "-" + sNo;
                //¹Ì¶¨¸³Öµ=================================
                BillNew.omodel.HBillNo = sBillNo;
                BillNew.omodel.HDate = DBUtility.ClsPub.isDate(ClsPub.GetServerDate(0));
                BillNew.omodel.HRemark = "";
                //====================================================
                BillNew.omodel.HWWOrderInterID = 0;
                BillNew.omodel.HWWOrderEntryID = 0;
                BillNew.omodel.HOrderProcNO = HOrderProcNo;
 
                BillNew.omodel.HICMOInterID = HICMOInterID;
                BillNew.omodel.HICMOEntryID = HICMOEntryID;
                BillNew.omodel.HICMOBillNo = HICMOBillNo;
                BillNew.omodel.HWWOrderBillNo = HICMOBillNo;
                //}
                BillNew.omodel.HMaterID = HMaterID;
                BillNew.omodel.HMaterID2 = HMaterID;
                BillNew.omodel.HMaterNumber = "";
                BillNew.omodel.HBatchNo = "";
                BillNew.omodel.HUnitID = HUnitID;
                BillNew.omodel.HUnitNumber = "";
                BillNew.omodel.HPlanQty = HQty;
                BillNew.omodel.HQty = HQty;
                BillNew.omodel.HPlanBeginDate = HPlanCommitDate;
                BillNew.omodel.HPlanEndDate = HPlanFinishDate;
                BillNew.omodel.HExplanation = "";
                BillNew.omodel.HInnerBillNo = "";
                BillNew.omodel.HWorkShopID = HDeptID;
                BillNew.omodel.HSupID = 0;
                BillNew.omodel.HWorkTypeNum = "lX1";     //Á÷ת¿¨ÀàÐÍ
                BillNew.omodel.HRoutingInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMainID"]);
                BillNew.omodel.HMainMaterID = HMainMaterID;
                BillNew.omodel.HKeyMaterID = HKeyMaterID; //¹Ø¼üÎïÁÏ  ¸ù¾Ýϼ¶BOM »ñÈ¡¹Ø¼ü¼þ
                //Ã÷ϸÀำֵ
                BillNew.DetailColl = new List<Model.ClsSc_ProcessExchangeBillSub>();
                for (int r = 0; r <= Ds.Tables[0].Rows.Count - 1; r++)
                {
                    Model.ClsSc_ProcessExchangeBillSub oSub = new Model.ClsSc_ProcessExchangeBillSub();
                    //¹Ì¶¨¸³Öµ========================================
                    oSub.HEntryID = r + 1;
                    oSub.HRemark = "";
                    oSub.HRelationQty = 0;
                    oSub.HRelationMoney = 0;
                    oSub.HCloseMan = "";
                    oSub.HEntryCloseDate = DBUtility.ClsPub.isDate("1990-01-01");
                    oSub.HCloseType = false;
                    //
                    oSub.HSourceInterID = HICMOInterID;
                    oSub.HSourceEntryID = HICMOEntryID;
                    oSub.HSourceBillType = "85";
                    oSub.HSourceBillNo = HICMOBillNo;
 
                    oSub.HICMOBillNo = HICMOBillNo;
                    oSub.HICMOInterID = HICMOInterID;
                    oSub.HICMOEntryID = HICMOEntryID;
                    
                    //=============================
                    oSub.HQty = HQty;
                    oSub.HProcNo = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["¹¤ÐòºÅ"]);
                    oSub.HProcID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["hprocid"]);
                    oSub.HProcNumber = "";
                    //oSub.HWorkRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[r]["±íÍ·±¸×¢"]);
                    oSub.HCenterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HCenterID"]);
                    oSub.HDeptID = HDeptID; 
                    oSub.HDeptNumber = "";
                    oSub.HGroupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HGroupID"]);
                    oSub.HGroupNumber = "";
                    oSub.HWorkerID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HWorkerID"]);
                    oSub.HWorkerNumber = "";
 
                    oSub.HSupFlag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[r]["ίÍâ±ê¼Ç"]);
                    oSub.HSupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HSupID"]);
                    oSub.HSourceID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[r]["HSourceID"]);
                    //oSub.HTimeUnit = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[r]["ʱ¼äµ¥Î»"]);
 
                    oSub.HPlanWorkTimes = 0;
 
                    oSub.HPlanBeginDate = HPlanCommitDate;
                    oSub.HPlanEndDate = HPlanFinishDate;
                    oSub.HRelBeginDate = DBUtility.ClsPub.isDate("1990-01-01");
                    oSub.HRelEndDate = DBUtility.ClsPub.isDate("1990-01-01");
 
                    oSub.HReadyTime = 0;
                    oSub.HQueueTime = 0;
                    oSub.HMoveTime = 0;
                    oSub.HBeginDayQty = 0;
                    oSub.HBeginFixQty = 0;
                    oSub.HFixWorkDays = 0;
                    oSub.HTrunWorkDays = 0;
                    oSub.HReadyTimes = 0;
                    oSub.HMyWorkDays = 0;
                    oSub.HOutPrice = DBUtility.ClsPub.isSingle(Ds.Tables[0].Rows[r]["¼Ó¹¤µ¥¼Û"]);
                    oSub.HOutMoney = 0;
                    oSub.HLastProc = "·ñ";
                    oSub.HFstProc = "·ñ";
                    oSub.HKeyProc = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[r]["ϵÀÁ÷ת¹¤Ðò"]); ;   //ϸö×ÔÖÆ¼þÊ×¹¤Ðò
 
                    oSub.HSeOrderInterID = 0;
                    oSub.HSeOrderEntryID = 0;
                    oSub.HSeOrderBillNo = "";
                    oSub.HWWOrderInterID = 0;
                    oSub.HWWOrderEntryID = 0;
                    oSub.HWWOrderBillNo = "";
                    BillNew.DetailColl.Add(oSub);
                }
                //ÐÂÔö
                if (!BillNew.AddBill(ref ClsPub.sExeReturnInfo))
                {
                    MessageBox.Show("±£´æÊ§°Ü!Ô­Òò:" + ClsPub.sExeReturnInfo, "Ìáʾ");
                    return;
                }
            }
        }
        private void Sc_ICMOBillList_CLDDlgOrder_Activated(object sender, EventArgs e)
        {
            IsOk = 0;
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
        }
 
        private void initGrid()
        {
            DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name);
            grdMain.ReadOnly = false;
        }
 
        /// <summary>
        /// °´¶©µ¥¸ú×ٺŷֽâ
        /// </summary>
        private void Display()
        {
            ClsCN SubCn = new ClsCN();
            DataSet DSet;
            string sSql = "";
            string sWhere = "";
 
            //¹ýÂËÌõ¼þ ¸ù¾Ý¶©µ¥¸ú×ٺŠ·µ»ØÈ«²¿Éú²ú¶©µ¥¡£
            sSql = "exec h_p_Sc_GetAllICMOByOrderProcNoQueryToLZK_CLD  '" + HOrderProcNo.ToString() + "'";
            //
            DSet = SubCn.RunProcReturn(sSql, "Gy_czygl", ref DBUtility.ClsPub.sExeReturnInfo);
            //Éú³ÉÊ×ÐбêÌâ
            if (DSet == null)
            {
                MessageBox.Show("ûÓвéѯµ½BOMÐÅÏ¢£¡" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //ÊͷŶ³½á
            DBUtility.Xt_BaseBillFun.CancelFrozenCol(grdMain);
            //
            grdMain.DataSource = DSet.Tables[0].DefaultView;
            //ÉèÖúϼÆÁÐ
            //string sTotalCol = "";
            //sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
            //string[] sT;
            //sT = sTotalCol.Split(Convert.ToChar(","));
            //oSumGrid.BuildTotalCols(sT);
            //  
            //¶³½á
            int FrCol = 4;
            string s = "ÊÇ";
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s, FrCol);
            //for (int i = 0; i < grdMain.ColumnCount; i++)
            //{
            //    grdMain.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; //ÁРÅÅÐòģʽ
 
            //}
            // 
            HQtyCol = Fun_GetCol("Á÷ת¿¨ÊýÁ¿");
            HCountCol = Fun_GetCol("Éú³ÉÕÅÊý");
        }
 
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
 
        private void GraphicsGrid()
        {
            DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain);
        }
 
        private void Sc_ICMOBillList_CLDDlgOrder_Load(object sender, EventArgs e)
        {
            DAL.ClsCLD_Material_View oMater = new DAL.ClsCLD_Material_View();
            
            if (oMater.GetInfoByID(HMaterID))
            {
                txtHMater.Tag = HMaterID;
                txtHMater.Text = oMater.omodel.HName;
                txtHModel.Text = oMater.omodel.HModel;
            }
            else
            {
                txtHMater.Tag = 0;
                txtHMater.Text = "";
                txtHModel.Text = "";
            }
            txtHOrderProcNo.Text = HOrderProcNo;
            initGrid();
            Display();
 
        }
 
        private void grdMain_Paint(object sender, PaintEventArgs e)
        {
            GraphicsGrid();
        }
 
        private void grdMain_DoubleClick(object sender, EventArgs e)
        {
            if (DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("Ñ¡Ôñ")].Value) == "")
            {
                grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("Ñ¡Ôñ")].Value = "¡Ì";
            }
            else
            {
                grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[Fun_GetCol("Ñ¡Ôñ")].Value = "";
            }
        }
 
        private void txtHPlanQty_TextChanged(object sender, EventArgs e)
        {
            //if (DBUtility.ClsPub.isDoule(txtHPlanQty.Text) <= 0)
            //{
            //    return;
            //}
            //double HConsultAuxQty = 0;
            //double HQty = DBUtility.ClsPub.isDoule(txtHPlanQty.Text);
            //for (int i = 0; i <= grdMain.RowCount - 1; i++)
            //{
            //    HConsultAuxQty = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[Fun_GetCol("HConsultAuxQty")].Value);
            //    grdMain.Rows[i].Cells[Fun_GetCol("²ÎÕÕÊýÁ¿")].Value = DBUtility.ClsPub.isDoule(HQty * HConsultAuxQty, 0);
            //    grdMain.Rows[i].Cells[Fun_GetCol("Á÷ת¿¨ÊýÁ¿")].Value = DBUtility.ClsPub.isDoule(HQty * HConsultAuxQty, 0);
            //}
 
        }
 
        private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            int i = grdMain.CurrentCell.ColumnIndex;
            if (i != HQtyCol && i != HCountCol)
            {
                e.Cancel = true;
            }
        }
 
        private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
        {
            DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
        }
 
        private void cmdcheck_Click(object sender, EventArgs e)
        {
            label4.Focus();
            int sCount = 0;
           
            int t = 0;
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
 
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("״̬")].Value) != "¿ª¹¤" || DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("¹¤ÒÕ·Ïß")].Value) == "" || DBUtility.ClsPub.isSingle(grdMain.Rows[i].Cells[Fun_GetCol("Á÷ת¿¨ÊýÁ¿")].Value) <=0)
                {
                    grdMain.Rows[i].Cells[Fun_GetCol("Ñ¡Ôñ")].Value = ""; 
                }
 
            }
           
        }
 
 
 
 
    }
}