雅琪诺MES智能条码管理系统
jhz
2022-06-30 0d3b2bd4edaa7385e4ff96370c877be237af054b
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
 
namespace SCM
{
    public partial class Xs_SeOrderAutoSortBill : Form
    {
        public Xs_SeOrderAutoSortBill()
        {
            InitializeComponent();
        }
 
 
        SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1();
 
        private void txtHProcID_TextChanged(object sender, EventArgs e)
        {
 
        }
 
        private void label4_Click(object sender, EventArgs e)
        {
 
        }
 
        private void yd_Click(object sender, EventArgs e)
        {
            Display_UnSort();
        }
 
        private void Display_UnSort()
        {
            DataSet DSet;
            string sSql = "";
            string sWhere = "";
            //过滤条件 
            sSql = "EXEC h_p_Xs_SeOrderAutoSortBill_UnSort '',0  ";
            
            //
            DSet = oWeb.getDataSetBySQL(sSql, "h_p_Xs_SeOrderAutoSortBill_UnSort", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdSourceBill.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 = 0;
            string s = "是";
            ClsPub1.DisplayGrid(grdSourceBill, this.Name, s, FrCol);
            //画线
            //GraphLine();
            //Total();
        }
 
        private void Xs_SeOrderAutoSortBill_Load(object sender, EventArgs e)
        {
            //设置动态URL
            oWeb.Url = SCM.ClsPub1.WEBSURL;
            oWeb.Timeout = 30000;
        }
 
        private void pc_Click(object sender, EventArgs e)
        {
            //if (CheckSetupData() == false)
            //{
            //    return;
            //}
            if (MessageBox.Show("是否启动裁切排产?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                //this.DateSetup(false);
                return;
            }
            else
            {
                this.DateSetup(true);
            }
        }
 
        //排程 
        private bool DateSetup(bool bAuto)
        {
             
            //得到一个内码
            //HRelationInterID = DBUtility.ClsPub.CreateBillID(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
            //HBillNo = "";
            //弹出前置非模式窗体,显示进度
            DBUtility.Xt_ProcessWait oWait = new DBUtility.Xt_ProcessWait();
            oWait.lblCaption.Text = "正在排产请稍候...";
            oWait.lblHCount.Text = "";
            oWait.lblHMaterName.Text = "";
            oWait.pb1.Maximum = grdSourceBill.RowCount;
            oWait.pb1.Value = 0;
            oWait.Show();
            //grdMain.RowCount = 0;
            ////清空未锁定 排程记录
            //Sub_DeleteBillUnLock();
            //按任务单优先级 循环
            for (int i = 0; i < grdSourceBill.RowCount; i++)
            {
                //    //如果锁定计划,则不需要再排程
                //    if (DBUtility.ClsPub.isBool(grdSourceBill.Rows[i].Cells[HLockedCol].Value) == true)
                //    {
                //        continue;
                //    }
                //    //找到本任务单 可用生产资源
                //    lMainID = DBUtility.ClsPub.isLong(grdSourceBill.Rows[i].Cells[HICMOInterIDCol].Value);
                //    sICMOBillNo = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HICMOBillNoCol].Value);
                //    dEndDate = DBUtility.ClsPub.isDate(grdSourceBill.Rows[i].Cells[HLastEndDateCol].Value);
                //    sProdTimes = DBUtility.ClsPub.isSingle(grdSourceBill.Rows[i].Cells[HProdTimesCol].Value);
                //    sPlanQty = DBUtility.ClsPub.isSingle(grdSourceBill.Rows[i].Cells[HPlanQtyCol].Value);
                //    lHGroupID = DBUtility.ClsPub.isLong(grdSourceBill.Rows[i].Cells[HGroupIDCol].Value);
                //    sGroupName = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HGroupNameCol].Value);
                //    lMaterID = DBUtility.ClsPub.isLong(grdSourceBill.Rows[i].Cells[HMaterIDCol].Value);
                //    sMaterNumber = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HMaterNumberCol].Value);
                //    sMaterName = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HMaterNameCol].Value);
                //    sMaterModel = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HMaterModelCol].Value);
                //    sWorkQty = DBUtility.ClsPub.isSingle(grdSourceBill.Rows[i].Cells[HWorkQtyCol].Value);
                //    sYX = DBUtility.ClsPub.isLong(grdSourceBill.Rows[i].Cells[HYXCol].Value);
                //    //
                //    if (sICMOBillNo == "WORK155356")
                //    {
                //        sICMOBillNo = sICMOBillNo;
                //    }
                //    //剩余需求工时
                //    iLeftQty = sPlanQty;
                //    if (sWorkQty <= 0)
                //    {
                //        sLeftProdTimes = 0;
                //    }
                //    else
                //    {
                //        sLeftProdTimes = iLeftQty / sWorkQty;
                //    }
                //    //若本任务单已有安排资源(上次排程或者手工排程) 则不再寻找资源,直接排程
                //    if (DBUtility.ClsPub.isLong(grdSourceBill.Rows[i].Cells[HSourceIDCol].Value) != 0 &&
                //        DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HSourceNameCol].Value) != ""
                //        )
                //    {
                //        //获取该生产资源的剩余工时进行排程。
                //        lSourceID = DBUtility.ClsPub.isLong(grdSourceBill.Rows[i].Cells[HSourceIDCol].Value);
                //        sSourceName = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HSourceNameCol].Value);
                //        sSourceNumber = DBUtility.ClsPub.isStrNull(grdSourceBill.Rows[i].Cells[HSourceNumberCol].Value);
                //        //
                //        ds = Sc_ICMOSortBillFun.GetWorkSourceByICMO(oCn, lMaterID, dEndDate, lSourceID, sLeftProdTimes);
                //    }
                //    else //没有资源则 自动找到资源
                //    {
                //        //
                //        ds = Sc_ICMOSortBillFun.GetWorkSourceByICMO(oCn, lMaterID, dEndDate, sLeftProdTimes);
                //    }
                //    if (ds == null || ds.Tables[0].Rows.Count == 0) //没有可以排的资源
                //    {
                //        //跳到下一单  本单红色显示
                //        grdSourceBill.Rows[i].DefaultCellStyle.BackColor = Color.Brown;
                //        continue;
                //    }
                //    else
                //    {
                //        grdSourceBill.Rows[i].DefaultCellStyle.BackColor = Color.White;
                //        //开始排单 
                //        bFind = false;
                //        //超交货期  仍然排程
                //        for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                //        {
                //            //判断资源剩余工时,是否大于 生产周期
                //            if (DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[j]["剩余工时"]) > sLeftProdTimes)
                //            {
                //                if (iLeftQty > 0)
                //                {
                //                    //在本资源上生产
                //                    //获取该生产资源的剩余工时进行排程。
                //                    lSourceID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[j]["HitemID"]);
                //                    sSourceName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[j]["资源名称"]);
                //                    sSourceNumber = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[j]["资源代码"]);
                //                    grdSourceBill.Rows[i].Cells[HSourceIDCol].Value = lSourceID;
                //                    grdSourceBill.Rows[i].Cells[HSourceNameCol].Value = sSourceName;
                //                    grdSourceBill.Rows[i].Cells[HSourceNumberCol].Value = sSourceNumber;
                //                    dsSub = Sc_ICMOSortBillFun.GetWorkSourceTimeBySource(oCn, lSourceID);
                //                    if (dsSub == null || dsSub.Tables[0].Rows.Count == 0)
                //                    {
                //                        continue;
                //                    }
                //                    if (dsSub != null)//不加班排程
                //                    {
                //                        //将数据排到网格中
                //                        grdMain.RowCount = grdMain.RowCount + 1;  //  grdmain 新增一行
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOBillNoCol].Value = sICMOBillNo;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOInterIDCol].Value = lMainID;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecLeftQtyCol].Value = iLeftQty;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupIDCol].Value = lHGroupID;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupNameCol].Value = sGroupName;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterIDCol].Value = lMaterID;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNameCol].Value = sMaterName;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNumberCol].Value = sMaterNumber;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterModelCol].Value = sMaterModel;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanEndDateCol].Value = dEndDate;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanQtyCol].Value = sPlanQty;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceIDCol].Value = lSourceID;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNameCol].Value = sSourceName;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNumberCol].Value = sSourceNumber;
                //                        grdMain.Rows[grdMain.RowCount - 1].Cells[HSecYXCol].Value = sYX;
                //                        Sc_ICMOSortBillFun.SetInfoToGrid(grdMain, dsSub, null, grdMain.RowCount - 1, ref iLeftQty, sWorkQty, false, oClsGridValues);
                //                    }
                //                    bFind = true;
                //                }
                //            }
                //        }
                //        if (!bFind)
                //        {
                //            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                //            {
                //                //判断资源最大剩余工时,是否大于 生产周期
                //                if (DBUtility.ClsPub.isSingle(ds.Tables[0].Rows[j]["最大剩余工时"]) > sLeftProdTimes)
                //                {
                //                    if (iLeftQty > 0)
                //                    {
 
                //                        //在本资源上生产
                //                        grdMain.RowCount = grdMain.RowCount + 1;
                //                        //获取该生产资源的剩余工时进行排程。
                //                        lSourceID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[j]["HitemID"]);
                //                        sSourceName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[j]["资源名称"]);
                //                        sSourceNumber = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[j]["资源代码"]);
                //                        grdSourceBill.Rows[i].Cells[HSourceIDCol].Value = lSourceID;
                //                        grdSourceBill.Rows[i].Cells[HSourceNameCol].Value = sSourceName;
                //                        grdSourceBill.Rows[i].Cells[HSourceNumberCol].Value = sSourceNumber;
                //                        dsSub = Sc_ICMOSortBillFun.GetWorkSourceTimeBySource(oCn, lSourceID);
                //                        if (dsSub == null || dsSub.Tables[0].Rows.Count == 0)
                //                        {
                //                            continue;
                //                        }
                //                        if (dsSub != null)//加班排程
                //                        {
                //                            //将数据排到网格中
                //                            grdMain.RowCount = grdMain.RowCount + 1;  //  grdmain 新增一行
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOBillNoCol].Value = sICMOBillNo;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOInterIDCol].Value = lMainID;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecLeftQtyCol].Value = iLeftQty;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupIDCol].Value = lHGroupID;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupNameCol].Value = sGroupName;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterIDCol].Value = lMaterID;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNameCol].Value = sMaterName;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNumberCol].Value = sMaterNumber;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterModelCol].Value = sMaterModel;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanEndDateCol].Value = dEndDate;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanQtyCol].Value = sPlanQty;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceIDCol].Value = lSourceID;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNameCol].Value = sSourceName;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNumberCol].Value = sSourceNumber;
                //                            grdMain.Rows[grdMain.RowCount - 1].Cells[HSecYXCol].Value = sYX;
                //                            Sc_ICMOSortBillFun.SetInfoToGrid(grdMain, dsSub, null, grdMain.RowCount - 1, ref iLeftQty, sWorkQty, true, oClsGridValues);
                //                        }
                //                    }
                //                    bFind = true;
                //                }
                //            }
                //        }
                //        if (!bFind)
                //        {
                //            //如果没有找到合适资源则,直接排最后一个剩余最大的资源。
                //            //获取该生产资源的剩余工时进行排程。
                //            lSourceID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["HitemID"]);
                //            sSourceName = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["资源名称"]);
                //            sSourceNumber = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["资源代码"]);
                //            grdSourceBill.Rows[i].Cells[HSourceIDCol].Value = lSourceID;
                //            grdSourceBill.Rows[i].Cells[HSourceNameCol].Value = sSourceName;
                //            grdSourceBill.Rows[i].Cells[HSourceNumberCol].Value = sSourceNumber;
 
                //            //获取该生产资源的剩余工时进行排程。
                //            dsSub = Sc_ICMOSortBillFun.GetWorkSourceTimeBySource(oCn, lSourceID);
                //            if (dsSub == null || dsSub.Tables[0].Rows.Count == 0)
                //            {
                //                continue;
                //            }
                //            if (dsSub != null)//加班排程
                //            {
                //                //将数据排到网格中
                //                grdMain.RowCount = grdMain.RowCount + 1;  //  grdmain 新增一行
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOBillNoCol].Value = sICMOBillNo;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOInterIDCol].Value = lMainID;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecLeftQtyCol].Value = iLeftQty;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupIDCol].Value = lHGroupID;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupNameCol].Value = sGroupName;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterIDCol].Value = lMaterID;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNameCol].Value = sMaterName;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNumberCol].Value = sMaterNumber;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterModelCol].Value = sMaterModel;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanEndDateCol].Value = dEndDate;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanQtyCol].Value = sPlanQty;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceIDCol].Value = lSourceID;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNameCol].Value = sSourceName;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNumberCol].Value = sSourceNumber;
                //                grdMain.Rows[grdMain.RowCount - 1].Cells[HSecYXCol].Value = sYX;
                //                Sc_ICMOSortBillFun.SetInfoToGrid(grdMain, dsSub, null, grdMain.RowCount - 1, ref iLeftQty, sWorkQty, true, oClsGridValues);
                //            }
                //        }
                //    }
                //    //
                //    //保存生成派工单
                //    SaveSingeBill(i, grdMain.RowCount - 1, HRelationInterID, oClsGridValues);
                //////更新生产订单
                
                ////写入 进度等待框
                Thread.Sleep(100);
                Application.DoEvents();
                oWait.pb1.Value = i + 1;
                oWait.lblHCount.Text = oWait.pb1.Value.ToString() + "/" + oWait.pb1.Maximum.ToString();
                oWait.lblHMaterName.Text = "";
                Application.DoEvents();
            }
            oWeb.getRunProc(" EXEC h_p_Xs_SeOrderAutoSortBill_ToSort 1 "  , ref DBUtility.ClsPub.sExeReturnInfo);
            ////
            oWait.Close();
            Display_Sort();
            Display_UnSort();
            return true;
        }
 
        private void Display_Sort()
        {
            DataSet DSet;
            string sSql = "";
            string sWhere = "";
            //过滤条件 
            sSql = "EXEC h_p_Xs_SeOrderAutoSortBill_Sort '',0  ";
 
            //
            DSet = oWeb.getDataSetBySQL(sSql, "h_p_Xs_SeOrderAutoSortBill_Sort", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            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 = 0;
            string s = "是";
            ClsPub1.DisplayGrid(grdMain, this.Name, s, FrCol);
            //画线
            //GraphLine();
            //Total();
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            initGrid();
        }
 
        //
        private void initGrid()
        {
            ClsPub1.initGridList(grdMain, this.Name);
            ClsPub1.initGridList(grdSourceBill, this.Name + "grdSourceBill");
            ClsPub1.initGridList(grdSourceStatus, this.Name + "grdSourceStatus");
            grdMain.ReadOnly = true;
            grdSourceBill.ReadOnly = true;
            grdSourceStatus.ReadOnly = true;
        }
 
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        private void xs_Click(object sender, EventArgs e)
        {
 
        }
 
        private void sx_Click(object sender, EventArgs e)
        { 
            Display_Sort();
            Display_UnSort();
        }
 
    }
}