1
yangle
3 天以前 861794e4cc962de1059ab01ca1e2bd81e2bac643
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
using Microsoft.VisualBasic.FileIO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WFormReadData_SMR
{
    public partial class ReadCSV : Form
    {
        public DBHelper oCN = new DBHelper();
 
        public ReadCSV()
        {
            InitializeComponent();
        }
        public static int num = 0;
        public static DateTime time = DateTime.Now.AddMinutes(-5);
 
        //更换条形码
        private void btnGH_Click(object sender, EventArgs e)
        {
            this.txtHBardCode.Text = "";
            this.txtHBath.Text = "";
            this.txtHBardCode.ReadOnly = false;
        }
 
        //查询条形码
        public void SelectHBardCode(string HBillNo)
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from Sc_ProcessExchangeBillMain where HBillNo='" + HBillNo + "' ", "Sc_ProcessExchangeBillMain");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查无数据!");
                }
                else
                {
                    DataSet dataSet= oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBillNo + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                    if (dataSet.Tables[0].Rows.Count > 0)
                    {
                        string HProjectNum = ds.Tables[0].Rows[0]["HProjectNum"].ToString();
                        this.txtHBath.Text = HProjectNum.Split('-')[0];
                        this.txtHBardCode.ReadOnly = true;
                        list.Clear();
                    }
                    else {
                        MessageBox.Show(HBillNo + ",流转卡未开工!");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "提示");
            }
        }
 
        private void txtHBardCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHBardCode(this.txtHBardCode.Text);
            }
        }
 
        //员工编码回车
        private void HEmpCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHEmpCode(this.HEmpCode.Text);
            }
        }
 
        //查询员工
        public void SelectHEmpCode(string HNumber)
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from Gy_Employee where HNumber='" + HNumber + "' ", "Gy_Employee");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查无数据!");
                }
                else
                {
                    string HEmpCodeName = ds.Tables[0].Rows[0]["HName"].ToString();
                    string HEmpCodeNumber = ds.Tables[0].Rows[0]["HNumber"].ToString();
                    this.HEmpCodeName.Text = HEmpCodeName;
                    this.HEmpCode.Text = HEmpCodeNumber;
                    this.HEmpCode.ReadOnly = true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "提示");
            }
        }
 
        //更换员工
        private void btnSelect_Click(object sender, EventArgs e)
        {
            this.HEmpCode.ReadOnly = false;
            this.HEmpCode.Focus();
            this.HEmpCode.Text = "";
            this.HEmpCodeName.Text = "";
 
            this.HSouce.ReadOnly = false;
            this.HSouce.Focus();
            this.HSouce.Text = "";
            this.HSouceName.Text = "";
        }
 
        //读取数据
        private void btnReadData_Click(object sender, EventArgs e)
        {
 
            if (this.HEmpCode.Text == "" || this.txtHBath.Text == ""|| this.HSouceName.Text == "")
            {
 
                MessageBox.Show("请输入生产资源,员工编码,者条形码!");
            }
            else {
                if (num == 0)
                {
                    this.btnReadData.Text = "暂停";
                    this.timer1.Enabled = true;
                    this.btnGH.Enabled = false;
                    this.btnSelect.Enabled = false;
                    num = 1;
                    //ReadCsv();
                }
                else if (num == 1)
                {
                    this.btnReadData.Text = "启动";
                    this.timer1.Enabled = false;
                    this.btnGH.Enabled = true;
                    this.btnSelect.Enabled = true;
                    num = 0;
                }
            }
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this.HEmpCode.Text == ""|| this.txtHBath.Text == "")
            {
                MessageBox.Show("请输入员工编码或者流转卡!");
            }
            else
            {
                ReadCsv();
            }
        }
        public static List<string> list = new List<string>();
 
        //读取csv格式文件
        private void ReadCsv()
        {
            string Date = DateTime.Now.ToString("yyMMdd");
            string HBath = this.txtHBath.Text;
 
            string Year = DateTime.Now.Year.ToString();
            Year = Year.Substring(Year.Length - 2, 2);
            string Month = DateTime.Now.Month.ToString();
            Month = Month.Length > 1 ? Month : "0" + Month;
            string Day = DateTime.Now.Day.ToString();
            Day = Day.Length > 1 ? Day : "0" + Day;
 
            //注:斯莫尔组装3 在E盘  _332009
            //其余在D盘 _C332001_2M
            //string csv_file_path = $@"C:\Users\admin\Desktop\新建文件夹 (2)\250933P9_250403_C332001_2M.csv";
            string csv_file_path = $@"D:\THLCR_Data\{HBath}\{HBath}_{Date}_C332001_2M.csv"; //组装1 组装2路径 
            //string csv_file_path = $@"E:\THLCR_Data\{HBath}\{HBath}_{Date}_332009.csv";  //组装3路径
            //15车间缺少路径 D:\DATA SAVE\年\年月\年月日\批次号\数据保存.csv
            //string csv_file_path = $@"D:\DATA SAVE\{Year}\{Year + Month}\{Year + Month + Day}\{HBath}\数据保存.csv";  
 
 
            bool flag = File.Exists(csv_file_path);
 
            if (flag)
            {
                DataTable dt = new DataTable();
                string HTypeName = "无尘";
                //string csv_file_path_Read = @"C:\Users\admin\Desktop\新建文件夹 (2)\250933P9_250403_C332001_2M_1.csv";
                string csv_file_path_Read = $@"D:\THLCR_Data\{HBath}\{HBath}_{Date}_C332001_2M_Read.csv"; //组装1 组装2路径 
                //string csv_file_path_Read = $@"E:\THLCR_Data\{HBath}\{HBath}_{Date}_332009_Read.csv";  //组装3路径
 
                //string HTypeName = "15";
                ////15车间缺少路径 D:\DATA SAVE\年\年月\年月日\批次号\数据保存.csv
                ////string csv_file_path_Read = $@"C:\Users\admin\Desktop\新建文件夹 (2)\DATA SAVE\数据保存_MES读取.csv";
 
                //string csv_file_path_Read = $@"D:\DATA SAVE\{Year}\{Year + Month}\{Year + Month + Day}\{HBath}\数据保存_MES读取.csv";
 
                //复制一份文件
                File.Copy(csv_file_path, csv_file_path_Read, true);
 
                string contents = File.ReadAllText(csv_file_path_Read, Encoding.GetEncoding("gb2312"));
               
                TextFieldParser parser = new TextFieldParser(new StringReader(contents));
 
                parser.HasFieldsEnclosedInQuotes = true;
                parser.SetDelimiters(",");
 
                string[] fields;
 
                while (!parser.EndOfData)
                {
                    fields = parser.ReadFields();
 
                    if (dt.Columns.Count == 0)
                    {
                        foreach (string field in fields)
                        {
                            dt.Columns.Add(new DataColumn(string.IsNullOrWhiteSpace(field.Trim('\"')) ? null : field.Trim('\"'), typeof(string)));
                        }
                    }
                    else
                    {
                        dt.Rows.Add(fields.Select(item => string.IsNullOrWhiteSpace(item.Trim('\"')) ? null : item.Trim('\"')).ToArray());
                    }
                }
                parser.Close();
 
                //获取当前时间
                DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-20).ToString("yyyy-MM-dd  HH:mm:ss"));
                DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd  HH:mm:00"));
                bool flag_1 = false;
                bool flag_2 = false;
                foreach (DataRow item in dt.Rows)
                {
                    if (HTypeName == "无尘")
                    {
                        DateTime NowTime = DateTime.Parse(item["测试时间"].ToString());
                        string HBadCodeSN = item["序号"].ToString();
 
                        if (((NowTime >= ActionTime && NowTime < EndTime) || dt.Rows.Count <= 20) && HBadCodeSN != "" && list.Contains(HBadCodeSN)==false)
                        {
 
                            string HSourceCode = this.HSouce.Text; //设备编号 组装1 9994 组装2 9995 组装3 9996
                            string HEmpCode = this.HEmpCode.Text;
                            string HBarCode = item["序号"].ToString();
                            string HCreateTime = item["测试时间"].ToString();
                            string HDate = DateTime.Parse(item["测试时间"].ToString()).ToString("yyyy-MM-dd");
                            string HResult = item["分选"].ToString() == "PASS" ? "OK" : "NG";
                            string HProcNumber = "005"; //005
                            int HFlag = 0;
                            //string HEmpCode = "";
                            //判断条码不为空
                            if (HBadCodeSN != "")
                            {
                                string HType = "";
                                int HCount = 1;
 
                                //DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN");
 
                                if (true)
                                {
                                    if (Get_AllowLoadData(HBarCode, HProcNumber, flag_1,out flag_2))
                                    {
                                        string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
                    values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')";
                                        oCN.RunProc(sql);
                                        ListSelect.Items.Add("条码:" + HBarCode + ",当前日期:" + DateTime.Now.ToString() + ",日期:" + HCreateTime + ",结果:" + HResult);
                                        list.Add(HBarCode);
 
                                        //新增工艺参数
                                        for (int i = 0; i < dt.Columns.Count; i++)
                                        {
                                            if (dt.Columns[i].ColumnName.Contains("Hz"))
                                            {
                                                HType = dt.Columns[i].ColumnName;
                                                string HCount_1 = item[HType].ToString();
 
                                                //查询当天条码 对应的工艺参数有没有插入到里面 如果没有则新增
                                                DataSet ds1 = oCN.RunProcReturn(@"select * from Sb_EquipMentCollectionTechParam_SN where HBarCode='" + HBarCode + "' and HType='" + HType + "'", "Sb_EquipMentCollectionTechParam_SN");
 
                                                if (ds1.Tables[0].Rows.Count == 0)
                                                {
                                                    string sql1 = $@"insert into Sb_EquipMentCollectionTechParam_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount_1}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')";
                                                    oCN.RunProc(sql1);
                                                    //ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
                                                }
                                            }
                                        }
                                    }
                                    else {
                                        flag_1 = flag_2;
                                    }
                                }
                            }
                        }
                    }
 
                    if (HTypeName == "15")
                    {
                        DateTime NowTime = DateTime.Parse(item["CS_时间"].ToString());
                        string HBadCodeSN = item["CS_DM码"].ToString();
 
                        if (((NowTime >= ActionTime && NowTime < EndTime) || dt.Rows.Count <= 20) && HBadCodeSN != "")
                        {
 
                            string HSourceCode = this.HSouce.Text; //设备编号 组装1 9994 组装2 9995 组装3 9996
                            string HEmpCode = this.HEmpCode.Text;
                            string HBarCode = item["CS_DM码"].ToString();
                            string HCreateTime = item["CS_时间"].ToString();
                            string HDate = DateTime.Parse(item["CS_时间"].ToString()).ToString("yyyy-MM-dd");
                            string HResult = item["CS_总结果"].ToString();
                            string HProcNumber = "005";
                            int HFlag = 0;
 
                            if (HResult != "") {
                                if (HBadCodeSN != "")
                                {
                                    string HType = "";
                                    int HCount = 1;
 
                                    DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN");
 
 
                                    if (ds.Tables[0].Rows.Count == 0)
                                    {
                                        if (Get_AllowLoadData(HBarCode, HProcNumber, flag_1, out flag_2))
                                        {
                                            string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
                    values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')";
                                            oCN.RunProc(sql);
                                            ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
 
                                            for (int i = 0; i < dt.Columns.Count; i++)
                                            {
                                                if (dt.Columns[i].ColumnName.Contains("CS_"))
                                                {
                                                    HType = dt.Columns[i].ColumnName;
                                                    string HCount_1 = item[HType].ToString();
                                                    string HResult_TechParam = "";
                                                    if (HType != "CS_时间" && HType != "CS_DM码" && HType != "CS_总结果")
                                                    {
                                                        HResult_TechParam = HCount_1;
                                                        double number = 0;
                                                        if (!Double.TryParse(HCount_1, out number))
                                                        {
                                                            HCount_1 = "0";
                                                        }
 
                                                        DataSet ds1 = oCN.RunProcReturn(@"select * from Sb_EquipMentCollectionTechParam_SN where HBarCode='" + HBarCode + "' and HType='" + HType + "'", "Sb_EquipMentCollectionTechParam_SN");
 
                                                        if (ds1.Tables[0].Rows.Count == 0)
                                                        {
                                                            string sql1 = $@"insert into Sb_EquipMentCollectionTechParam_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag)
values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{(HCount_1 == "" ? " 0" : HCount_1)}','{HCreateTime}','{HDate}','{HResult_TechParam}','{HProcNumber}','{HFlag}')";
                                                            oCN.RunProc(sql1);
                                                            //ListSelect.Items.Add("条码:" + HBarCode + ",日期:" + HCreateTime + ",结果:" + HResult);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            flag_1 = flag_2;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 
        public static string AllProcessExchange = "-1";
        public static string AllProcessExchangeHProcExchBillNo = "";
        public static string AllProcessExchangeHProcExchInterID = "";
        public static string AllSNBarcodeProcCtrl = "";
        public static string AllHProcID = "0";
        public static string AllHProName = "";
        public static double AllHQty = 0;
        //根据条码 判断是否保存
        public bool Get_AllowLoadData(string HBarCode,string HProcNumber,bool flag_1,out bool flag_2)
        {
            decimal hqty = 2;
            if (HBarCode.Length != 29 && HBarCode.Length != 50)
            {
                flag_2 = false;
                return false;
            }
 
            //判断长度是否为29位 无尘车间
            string HProcExchBillNo = "";
            string HProcExchInterID = "";
            if (HBarCode.Length == 29)
            {
                string str1 = HBarCode.Substring(18, 8);
                //string str2 = HBarCode.Substring(23, 3);
                if (AllProcessExchange != str1) {
                    DataSet ds = oCN.RunProcReturn("select  HInterID,HBillNo from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%' order by HMakeDate desc", "Sc_ProcessExchangeBillMain");
                    //判断是否能找到对应的流转卡
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        AllProcessExchangeHProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                        AllProcessExchangeHProcExchInterID = ds.Tables[0].Rows[0]["HInterID"].ToString();
 
                    }
                    else
                    {
                        //错误信息弹出框 定时超过2分钟弹一次
                        if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                        {
                            time = DateTime.Now;
                            MessageBox.Show(new Form { TopMost = true }, "条码:" + HBarCode + ",流转卡不存在!");
                        }
                        DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
                        flag_2 = true;
                        return false;
                    }
                    AllProcessExchange = str1;
                }
            }
            //判断长度是否为50位  15车间
            else if (HBarCode.Length == 50)
            {
                string str1 = HBarCode.Substring(42, 8);
                DataSet ds = oCN.RunProcReturn("select  HBillNo from Sc_ProcessExchangeBillMain where HProjectNum like'" + str1 + "-1%'", "Sc_ProcessExchangeBillMain");
                //判断是否能找到对应的流转卡
                if (ds.Tables[0].Rows.Count > 0)
                {
                    AllProcessExchangeHProcExchBillNo = ds.Tables[0].Rows[0]["HBillNo"].ToString();
                }
                else {
                    //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + ",流转卡不存在!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + ",流转卡不存在!", DateTime.Now.ToString("yyyy-MM-dd"));
                  
                    flag_2 = true;
                    return false;
                }
            }
 
            //赋值
            HProcExchBillNo = AllProcessExchangeHProcExchBillNo;
            HProcExchInterID = AllProcessExchangeHProcExchInterID;
 
            DataSet ds1;
 
            //第一次流转卡+工序和后面的做对比 如果是同一个流转卡就不进行判断
            if ((HProcExchBillNo + HProcNumber) != AllSNBarcodeProcCtrl) {
                //查询工序
                ds1 = oCN.RunProcReturn(@"SELECT  HItemID,HName FROM Gy_Process WHERE HNumber='" + HProcNumber + "'", "Gy_Process");
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    AllHProcID = ds1.Tables[0].Rows[0]["HItemID"].ToString();
                    AllHProName = ds1.Tables[0].Rows[0]["HName"].ToString();
                }
 
                //查询流转卡数量
                ds1 = oCN.RunProcReturn(@"SELECT  HQty FROM Sc_ProcessExchangeBillSub  where HInterID=" + HProcExchInterID + " and HProcID=" + AllHProcID, "Sc_ProcessExchangeBillSub");
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    AllHQty = double.Parse(ds1.Tables[0].Rows[0]["HQty"].ToString());
                }
 
                AllSNBarcodeProcCtrl = HProcExchBillNo + HProcNumber;
            }
               
            string HProcID = AllHProcID;
            string HProName = AllHProName;
            ////第一次流转卡+工序和后面的做对比 如果是同一个流转卡就不进行判断
            //if ((HProcExchBillNo + HProcNumber) == AllSNBarcodeProcCtrl)
            //{
                //判断 当前工序 条码 的上一道工序有没有过站
                ds1 = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + HBarCode + "'," + HProcID, "h_v_Gy_QualifiedRecordsList");
 
                if (ds1.Tables[0].Rows.Count == 0)
                {
                    //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + "工序:" + HProName + ",工序控制查无数据!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + HProName + ",工序控制查无数据!", DateTime.Now.ToString("yyyy-MM-dd"));
                  
                    flag_2 = true;
                    return false;
                }
                else if (ds1.Tables[0].Rows[0]["HBack"].ToString() == "2")
                {
                    //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                    if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                    {
                        time = DateTime.Now;
                        MessageBox.Show("条码:" + HBarCode + "工序:" + HProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!");
                    }
                    DBHelper.CustomWriteLog("条码:" + HBarCode + "工序:" + HProcID + "," + ds1.Tables[0].Rows[0]["HBackRemark"].ToString() + "!", DateTime.Now.ToString("yyyy-MM-dd"));
                   
                    flag_2 = true;
                    return false;
                }
            //}
 
            //查询出站数量是否超过流转卡数量
            ds1 = oCN.RunProcReturn($@"select ({AllHQty}-sum(isnull(ou.HQty,0))-sum(isnull(ou.HBadCount,0))) HQty from Sc_StationOutBillMain ou WITH(NOLOCK)
where ou.HProcExchInterID={HProcExchInterID} and ou.HProcID={AllHProcID}
group by  ou.HProcExchInterID,ou.HProcExchEntryID,ou.HQty", "Sc_StationOutBillMain");
 
            //获取流转卡数量
            double hqtyOut = AllHQty;
 
            //流转卡数量-出站单数量大于0 
            if (ds1.Tables[0].Rows.Count > 0)
            {
                hqtyOut = double.Parse(ds1.Tables[0].Rows[0][0].ToString());
            }
 
            //如果数量<0 则代表出站单数量超出流转卡数量 
            if (hqtyOut <= 0)
            {
                //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                {
                    time = DateTime.Now;
                    MessageBox.Show("流转卡:" + HProcExchBillNo + ",出站数量超过流转卡数量!");
                }
                DBHelper.CustomWriteLog("流转卡:" + HProcExchBillNo + ",出站数量超过流转卡数量!", DateTime.Now.ToString("yyyy-MM-dd"));
                flag_2 = true;
                return false;
            }
 
            //拍照工序除外
            if (HProcNumber != "013") {
                //增加产线组装追溯单
                //查询当前流转卡对应的工序有没有配件信息,如果有 则判断配件单的数量是否为0
                DataSet dataSet = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + HProcExchBillNo + "'," + HProcID, "h_p_Gy_BarCodeBillBomList");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    //判配件数量是否等于0
                    for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
                    {
                        double SYHQty = double.Parse(dataSet.Tables[0].Rows[i]["配件数量"].ToString());
                        string HMaterNamePJ = dataSet.Tables[0].Rows[i]["配件代码"].ToString();
                        string HMaterBarCode = dataSet.Tables[0].Rows[i]["HBarCode"].ToString();
                        if (SYHQty == 0)
                        {
                            //flag_1=只有第一次进来才会弹出 错误信息弹出框 定时超过2分钟弹一次
                            if (!flag_1 && (DateTime.Now - time).Minutes > hqty)
                            {
                                time = DateTime.Now;
                                MessageBox.Show("流转卡:" + HProcExchBillNo + ",配件条码:" + HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!");
                            }
                            DBHelper.CustomWriteLog("流转卡:" + HProcExchBillNo + ",配件条码:" + HMaterBarCode + ",配件代码:" + HMaterNamePJ + ",数量为0!", DateTime.Now.ToString("yyyy-MM-dd"));
                            flag_2 = true;
                            return false;
                        }
                    }
                }
            }
                
            flag_2 = false;
            return true;
        }
 
        //生产资源回车
        private void HSouce_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHSouc(this.HSouce.Text);
            }
        }
 
        //查询生产资源
        public void SelectHSouc(string HNumber)
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from Gy_Source where HNumber='" + HNumber + "' ", "Gy_Source");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("查无数据!");
                }
                else
                {
                    string HSouceName = ds.Tables[0].Rows[0]["HName"].ToString();
                    string HSouceNumber = ds.Tables[0].Rows[0]["HNumber"].ToString();
                    this.HSouceName.Text = HSouceName;
                    this.HSouce.Text = HSouceNumber;
                    this.HSouce.ReadOnly = true;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "提示");
            }
        }
 
        private void ReadCSV_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (num == 1)
            {
                MessageBox.Show("当前按钮未暂停,不允许关闭!");
                e.Cancel = true;
            }
            else if (MessageBox.Show("确定要关闭吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
            }
        }
    }
}