yusijie
2025-03-18 1e9a12d7b0bbc7dc9c125a9767727d7246411966
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
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 BaseSet
{
    public partial class Gy_DataIn_RoutingBill :BLL.Gy_DataInTmp
    {
        public Gy_DataIn_RoutingBill()
        {
            InitializeComponent();
        }
 
        public int HCollectIDCol = 1;         //²É¼¯Æ÷ÄÚÂë
        public int HRoomIDCol = 5;            //Òµ»§ÄÚÂë
        public int HBeginDateCol = 13;         //¿ªÊ¼ÈÕÆÚ
        public int HEndDateCol = 10;           //½áÊøÈÕÆÚ
        public int HItMoneyIDCol = 5;         //·ÑÓÃÏîÄ¿
        public int HQtyCol = 6;               //ÊýÁ¿
        public int HPriceCol = 7;             //µ¥¼Û
        public int HMoneyCol = 8;             //½ð¶î
        public int HBeginBalanceCol = 12;      //¿ªÊ¼ÊýÖµ
        public int HEndBalanceCol = 9;        //½áÊøÊýÖµ
        //
        public const int HBeginRow = 2;         //ÓÐЧÊý¾Ý£¬¿ªÊ¼ÐÐÊý
        //
        public DAL.ClsGy_Process_Ctl oProc = new DAL.ClsGy_Process_Ctl();
        public DAL.ClsGy_Process_View oProcHlp = new DAL.ClsGy_Process_View();
        public DAL.ClsK3_Department_View oFactory = new DAL.ClsK3_Department_View();
        DAL.ClsGy_WorkCenter_View oCen = new DAL.ClsGy_WorkCenter_View();
        DAL.ClsK3_Material_View oMater = new DAL.ClsK3_Material_View();
        DAL.ClsK3_Unit_View oUnit = new DAL.ClsK3_Unit_View();
        public DAL.ClsGy_RoutingBill BillNew = new DAL.ClsGy_RoutingBill();
        DAL.ClsK3_Material_View oMaterHlp = new DAL.ClsK3_Material_View();
        long j = 0;
        int c = 0;
        //public DAL.ClsCB_ItemMoneyBill_Tmp oBill = new DAL.ClsCB_ItemMoneyBill_Tmp();
        //public DAL.ClsGy_ItemMoney_View oItemMoney = new DAL.ClsGy_ItemMoney_View();
        //public DAL.ClsGy_Room_View oRoom = new DAL.ClsGy_Room_View();
        //public DAL.ClsGy_Collect_View oCollect = new DAL.ClsGy_Collect_View();
        //public DAL.ClsGy_Building_View oBuilding = new DAL.ClsGy_Building_View();
 
        /// <summary>
        ///  ³õʼ»¯½çÃæ
        /// </summary>
        public override void initData()
        {
            base.initData();
            base.sSheetName = "¹¤ÒÕ·Ïß"; 
            base.ModRightName = "Gy_DataIn_RoutingBill";
            base.ModRightNameCheck = base.ModRightName + base.ModRightNameCheck;
            base.ModRightNameClose = base.ModRightName + base.ModRightNameClose;
            base.ModRightNameDelete = base.ModRightName + base.ModRightNameDelete;
            base.ModRightNameEdit = base.ModRightName + base.ModRightNameEdit;
            base.ModRightNameMoney = base.ModRightName + base.ModRightNameMoney;
            base.ModRightNameQty = base.ModRightName + base.ModRightNameQty;
            base.ModCaption = "¹¤ÒÕ·Ïßµ¼Èë";
            this.Text = base.ModCaption;
            lblCaption.Text = base.ModCaption;
            //
            DBUtility.Gy_BaseFun.SetComboxYear(cmbHYear);
            DBUtility.Gy_BaseFun.SetComboxPeriod(cmbHPeriod);
            //
        }
        //µ¼Èë
        public override void Sub_DataIn()
        {
            string hnumber = "";
            string HBillNo = "";
            //
            if (!Checkdata()) return;
            if (grdMain.Rows.Count > 0)
            { 
                hnumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells[0].Value);
                HBillNo = ClsPub.CreateBillCode(BillNew.BillType, ref ClsPub.sExeReturnInfo, true);
                BillNew.omodel.HStandard = false;
                BillNew.omodel.HMainTimeUnit = "Сʱ";
                BillNew.omodel.HYear = 2011;
                BillNew.omodel.HPeriod = 1;
                BillNew.omodel.HBillNo = HBillNo;
                BillNew.omodel.HDate = DateTime.Today.Date;
                BillNew.DetailColl.Clear();
            } 
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
                string sHNumber = "";
                int sCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úÆ·´úÂë", grdMain);
 
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[0].Value) != "" && DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[3].Value) != "")
                {
                    //
                    sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sCol].Value);
                    //ÉóºË´úÂëÊÇ·ñºÏÀí
                    if (!DBUtility.ClsPub.AllowNumber(sHNumber))
                    {
                        MessageBox.Show("ÎïÁÏ´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
                        return;
                    }
 
                    if (hnumber == DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[0].Value))
                    {
                        //µÃµ½ÎïÁÏÄÚÂë
                        if (oMaterHlp.GetInfoByNumber(sHNumber))
                        {
                            if (BillNew.omodel.HMaterID != oMaterHlp.omodel.HItemID)
                            {
                                BillNew.omodel.HMaterID = oMaterHlp.omodel.HItemID;
                                BillNew.omodel.HMaterNumber = oMaterHlp.omodel.HNumber;
                                BillNew.omodel.HUnitID = oMaterHlp.omodel.HUnitID;
                                BillNew.omodel.HUnitNumber = oMaterHlp.omodel.HUnitNumber;
                            }
 
                        }
                        else
                        {
                            BillNew.omodel.HMaterID = 0;
                            MessageBox.Show("µÚ" + i.ToString() + "ÐÐ," + sHNumber + "ûÓÐÕÒµ½¶ÔÓ¦µÄÎïÁÏ£¡");
                            return;
                        }
                        j++;
                        //дÈëÀà
                        WriteClass(i);
 
                    }
                    else
                    {
                        DataSet Ds;
                        ClsCN oCn=new ClsCN();
                        bool b = false;
                        Ds = oCn.RunProcReturn("Select HMaterID from Gy_RoutingBillMain Where HMaterID=" + BillNew.omodel.HMaterID.ToString(), "Gy_RoutingBillMain");
                        if (checkadd.Checked == true)
                        {
                            if (Ds.Tables[0].Rows.Count == 0)
                            {
                                b = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                                if (b == false) return;
                                c++;
                                BillNew.CheckBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                            }
                        }
                        else
                        {
                            b = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                            if (b == false) return;
                            c++;
                            BillNew.CheckBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                        }
 
 
                        BillNew.DetailColl.Clear();
                        hnumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[0].Value);
                        sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sCol].Value);
                        
                        //ÉóºË´úÂëÊÇ·ñºÏÀí
                        if (!DBUtility.ClsPub.AllowNumber(sHNumber))
                        {
                            MessageBox.Show("ÎïÁÏ´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
                            return;
                        }
                        //µÃµ½ÎïÁÏÄÚÂë
                        if (oMaterHlp.GetInfoByNumber(sHNumber))
                        {
                            if (BillNew.omodel.HMaterID != oMaterHlp.omodel.HItemID)
                            {
                                BillNew.omodel.HMaterID = oMaterHlp.omodel.HItemID;
                                BillNew.omodel.HMaterNumber = oMaterHlp.omodel.HNumber;
                                BillNew.omodel.HUnitID = oMaterHlp.omodel.HUnitID;
                                BillNew.omodel.HUnitNumber = oMaterHlp.omodel.HUnitNumber;
                            }
 
                        }
                        else
                        {
                            BillNew.omodel.HMaterID = 0;
                            MessageBox.Show("µÚ" + i.ToString() + "ÐÐ," + sHNumber + "ûÓÐÕÒµ½¶ÔÓ¦µÄÎïÁÏ£¡");
                            return;
                        }
                        j = 1;
                        HBillNo = ClsPub.CreateBillCode(BillNew.BillType, ref ClsPub.sExeReturnInfo, true);
                        BillNew.omodel.HBillNo = HBillNo;
                        //дÈëÀà
                        WriteClass(i);
 
                    }
 
                }
                else
                {
                    //if (BillNew.DetailColl.Count > 0)
                    //{ 
                    //    BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                    //    BillNew.CheckBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                    //} 
                    MessageBox.Show("ÎïÁÏ´úÂë»ò¹¤Ðò´úÂëΪ¿Õ!Ô­Òò:" + DBUtility.ClsPub.sExeReturnInfo, "Ìáʾ");
                    return;
                }
            }
            //×îºóÒ»¸öÎïÁÏ´¦Àí
            if (BillNew.DetailColl.Count > 0)
            {
 
                DataSet Ds;
                ClsCN oCn = new ClsCN();
                bool b = false;
                Ds = oCn.RunProcReturn("Select HMaterID from Gy_RoutingBillMain Where HMaterID=" + BillNew.omodel.HMaterID.ToString(), "Gy_RoutingBillMain");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    b = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                    if (b == false) return;
                    c++;
                    BillNew.CheckBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                }
                MessageBox.Show("µ¼ÈëÍê±Ï:¹²"+c.ToString()+"¸ö¹¤ÒÕ·Ïß");
                grdMain.DataSource = null;
            }
            c = 0;
        }
 
        //дÈëÀ࠴ӿؼþ
        private bool WriteClass(int row)
        {
            string sHNumber = "";
            string sHNamePoc = "";
            string sHNumberProc = "";
            string sHNumberCen = "";
            Single sHWorkQty;
            Single sHBeginDayQty;
            Single sHBeginFixQty;
            //long HItemID = 0;
            int sCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úÆ·´úÂë", grdMain);
            int sColProc = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤Ðò´úÂë", grdMain);
            int sHNamePocCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤ÐòÃû³Æ", grdMain);
            int sCenCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤×÷ÖÐÐÄ´úÂë", grdMain);
            //
            sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[row].Cells[sCol].Value);
            sHNumberProc = DBUtility.ClsPub.isStrNull(grdMain.Rows[row].Cells[sColProc].Value);
            sHNumberCen = DBUtility.ClsPub.isStrNull(grdMain.Rows[row].Cells[sCenCol].Value);
            sHNamePoc = DBUtility.ClsPub.isStrNull(grdMain.Rows[row].Cells[sHNamePocCol].Value);
            sHWorkQty = DBUtility.ClsPub.isSingle(grdMain.Rows[row].Cells[DBUtility.ClsPub.isInt(DBUtility.Gy_BaseFun.Fun_GetCol("¼Ó¹¤ÊýÁ¿", grdMain))].Value);
            sHBeginDayQty = DBUtility.ClsPub.isSingle(grdMain.Rows[row].Cells[DBUtility.ClsPub.isInt(DBUtility.Gy_BaseFun.Fun_GetCol("±¾µÀ¹Ì¶¨¿ª¹¤ÌìÊý", grdMain))].Value);
            sHBeginFixQty = DBUtility.ClsPub.isSingle(grdMain.Rows[row].Cells[DBUtility.ClsPub.isInt(DBUtility.Gy_BaseFun.Fun_GetCol("±¾µÀ¿ª¹¤ÓàÁ¿", grdMain))].Value);
            //ÅжÏÊÇ·ñÔÊÐí ±£´æ
            //ÉóºË´úÂëÊÇ·ñºÏÀí
            //if (!DBUtility.ClsPub.AllowNumber(sHNumber))
            //{
            //    MessageBox.Show("ÎïÁÏ´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
            //    return false;
            //}
            Model.ClsGy_RoutingBillSub oSub=new Model.ClsGy_RoutingBillSub();
 
            //µÃµ½¹¤ÐòÄÚÂë
            if (oProcHlp.GetInfoByNumber(sHNumberProc))
            {
                oSub.HProcID = oProcHlp.omodel.HItemID;
            }
            //else
            //{
            //    oSub.HProcID = 0;
            //    MessageBox.Show("µÚ" + row.ToString() + "ÐÐ," + sHNumberProc + "ûÓÐÕÒµ½¶ÔÓ¦µÄ¹¤Ðò£¡");
            //    return false;
            //}
 
            //µÃµ½³µ¼äÄÚÂë
            if (oCen.GetInfoByNumber(sHNumberCen))
            {
                oSub.HCenterID = oCen.omodel.HItemID;
            }
            //else
            //{
            //    oProc.oModel.HDeptID = 0;
            //    MessageBox.Show("µÚ" + row.ToString() + "ÐÐ," + sHNumberCen + "ûÓÐÕÒµ½¶ÔÓ¦µÄ¹¤×÷ÖÐÐÄ£¡");
            //    return false;
            //}
            //дÈëÐÅÏ¢
            oSub.HEntryID = j;
 
            oSub.HProcNo = 0;
            oSub.HUnitTime = 1;
            oSub.HWorkQty = sHWorkQty;
            oSub.HRemark = "";
            oSub.HTimeUnit = "Сʱ";
            oSub.HReadyTime = 0;
            oSub.HQueueTime = 0;
            oSub.HMoveTime = 0;
            //
            oSub.HCloseMan = "";
            oSub.HCloseType = false;
            oSub.HSourceInterID = 0;
            oSub.HSourceEntryID = 0;
            oSub.HSourceBillType = "";
            oSub.HSourceBillNo ="";
            oSub.HRelationQty = 0;
            oSub.HRelationMoney = 0;
 
            oSub.HFixPrice = 0;
            oSub.HProcPrice = 0;
            oSub.HBadPrice = 0;
            oSub.HWasterPrice = 0;
            oSub.HStdFlag = false;
            oSub.HBeginDayQty = sHBeginDayQty;
            oSub.HBeginFixQty = sHBeginFixQty;
 
            BillNew.DetailColl.Add(oSub);
            return true;
        }
        //¼ì²éÎïÁÏ
        private bool Checkdata()
        {
            for (int i = 0; i <= grdMain.Rows.Count - 1; i++)
            {
                string sHNumber = "";
                string sHNamePoc = "";
                string sHNumberProc = "";
                string sHNumberCen = "";
                int sCol = DBUtility.Gy_BaseFun.Fun_GetCol("²úÆ·´úÂë", grdMain);
                int sColProc = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤Ðò´úÂë", grdMain);
                int sHNamePocCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤ÐòÃû³Æ", grdMain);
                int sCenCol = DBUtility.Gy_BaseFun.Fun_GetCol("¹¤×÷ÖÐÐÄ´úÂë", grdMain);
                //
                sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sCol].Value);
                sHNumberProc = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sColProc].Value);
                sHNumberCen = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sCenCol].Value);
                sHNamePoc = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sHNamePocCol].Value);
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[0].Value) != "" && DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[3].Value) != "")
                {
                    //
                    sHNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[sCol].Value);
                    //ÉóºË´úÂëÊÇ·ñºÏÀí
                    if (!DBUtility.ClsPub.AllowNumber(sHNumber))
                    {
                        MessageBox.Show("ÎïÁÏ´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
                        return false;
                    }
                    if (!DBUtility.ClsPub.AllowNumber(sHNumberProc))
                    {
                        MessageBox.Show("¹¤Ðò´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
                        return false;
                    }
                    if (!DBUtility.ClsPub.AllowNumber(sHNumberCen))
                    {
                        MessageBox.Show("¹¤×÷ÖÐÐÄ´úÂëÖв»ÄܳöÏÖÁ¬Ðø¡®.¡¯²¢ÇÒÊ×λĩλ²»ÄÜΪ¡®.¡¯£¡", "Ìáʾ");
                        return false;
                    }
                    //µÃµ½ÎïÁÏÄÚÂë
                    int j = i + 2;
                    if (!oMaterHlp.GetInfoByNumber(sHNumber))
                    {
 
                        MessageBox.Show("µÚ" + j.ToString() + "ÐÐ," + sHNumber + "ûÓÐÕÒµ½¶ÔÓ¦µÄÎïÁÏ£¡");
                        return false;
                    }
                    //µÃµ½¹¤ÐòÄÚÂë
                    if (!oProcHlp.GetInfoByNumber(sHNumberProc))
                    {
                        MessageBox.Show("µÚ" + j.ToString() + "ÐÐ," + sHNumberProc + "ûÓÐÕÒµ½¶ÔÓ¦µÄ¹¤Ðò£¡");
                        return false;
                    }
 
                    //µÃµ½³µ¼äÄÚÂë
                    if (!oCen.GetInfoByNumber(sHNumberCen))
                    {
 
                        MessageBox.Show("µÚ" + j.ToString() + "ÐÐ," + sHNumberCen + "ûÓÐÕÒµ½¶ÔÓ¦µÄ¹¤×÷ÖÐÐÄ£¡");
                        return false;
 
                    }
                    return true;
 
                }               
            }
            return true;
 
        }
    }
}