zrg
2025-06-26 977616d74f913ae5ce1e14f8cfde3b7f4d5a21a2
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
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WFormReadData_SMR
{
    public partial class ZZ_GlueWeigh : Form
    {
        DataTable dataTable = new DataTable();
        private json objJsonResult = new json();
        public DBHelper oCN = new DBHelper();
        public ZZ_GlueWeigh()
        {
            InitializeComponent();
        }
 
        private void textBox2_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtHMaker.Text))
            {
                this.txtHMaker.ForeColor = Color.LightGray;
                txtHMaker.Text = "请输入用户编码!";
            }
        }
 
        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHMaker(this.txtHMaker.Text);
            }
        }
 
        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (txtHMaker.Text.Trim() == "请输入用户编码!")
            {
                txtHMaker.Text = "";
                this.txtHMaker.ForeColor = Color.Black;
            }
        }
 
        //查询职员信息
        public void SelectHMaker(string txtHMaker)
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  HItemID,HName,HNumber from Gy_Employee where HNumber='" + txtHMaker + "' or HName ='" + txtHMaker + "'", "Gy_Employee");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string HName = ds.Tables[0].Rows[0]["HName"].ToString();
                    string HMakerID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                    string HNumber = ds.Tables[0].Rows[0]["HNumber"].ToString();
                    this.txtHMaker.Text = HName;
                    this.txtHMakerNumber.Text = HNumber;
                    this.labHMakerID.Text = HMakerID;
                    this.txtHMaker.ReadOnly = true;
                }
                else
                {
                    MessageBox.Show(this.BeforeWeigh.Text + ",查无数据,可能是输入编码有误!", "提示");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "提示");
            }
        }
 
        //条形码回车
        private void txtLzk_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (this.txtHMaker.Text == "")
                {
                    MessageBox.Show("请输入制单人信息!");
                }
                else
                {
                    SelectHBardCode(this.txtLzk.Text);
                }
 
            }
        }
 
        //查询条形码
        public void SelectHBardCode(string HBillNo)
        {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  * from h_v_Sc_ProcessExchangeBillQuerySub where 单据号='" + HBillNo + "' and 工序代码<>'9999' order by HEntryID desc", "h_v_Sc_ProcessExchangeBillQuerySub");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("流转卡:" + HBillNo + ",查无数据!");
                }
                else
                {
                    string HProjectNum = ds.Tables[0].Rows[0]["HProjectNum"].ToString();
                    this.txtPcm.Text = HProjectNum;
                    this.txtLzk.Text = ds.Tables[0].Rows[0]["单据号"].ToString();
                    this.txtLzk.ReadOnly = true;
 
                    this.cmbPro.DataSource = ds.Tables[0];
                    this.cmbPro.DisplayMember = "工序名称";
                    this.cmbPro.ValueMember = "HProcID";
                    this.cmbPro.SelectedIndex = 0;
                    ShowData("CMR-F-001");//电子天平  CMR-F-001    测试 LMJC 
 
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "提示");
            }
        }
 
        private void ZZ_GlueWeigh_Load(object sender, EventArgs e)
        {
            this.cmbEquip.SelectedIndex = 0;
            this.cmbEquip.DropDownStyle = ComboBoxStyle.DropDownList;//只读
 
            this.cmbPro.DropDownStyle = ComboBoxStyle.DropDownList;//只读
            this.cmbJYSelect.DropDownStyle = ComboBoxStyle.DropDownList;//只读
            this.cmbJYSelect.SelectedIndex = 0; 
            this.txtHMakerNumber.ReadOnly = true;//只读
            this.txtPcm.ReadOnly = true;//只读
        }
 
        //查询称重的重量
        private void btnBeFoSelect_Click(object sender, EventArgs e)
        {
           
            string cmbEquip = this.cmbEquip.Text;
            if (cmbEquip == "全部")
            {
                MessageBox.Show("请选择组装设备!");
            }
            else {
                string HNumber = "";
                switch (cmbEquip)
                {
                    case "组装2":
                        HNumber = "CMR-ZD-SD-002S2";  // CMR-ZD-SD-002
                        break;
                    case "组装3":
                        HNumber = "CMR-ZD-SD-006S2";  //  CMR-ZD-SD-004
                        break;
                    default:
                        MessageBox.Show("设备错误!");
                        break;
                }
 
                //查询 顶部点胶重量 和  底部点胶重量 当前最大的数据
                DataSet ds = oCN.RunProcReturn(@"select top 1 HTechParamName,HResult,HCreateTime from Sb_EquipMentCollectionTechParam_Temp 
                where HSourceCode = '" + HNumber + @"' and HTechParamName = '顶部点胶重量' and HCreateTime in(
                select  max(HCreateTime) from  Sb_EquipMentCollectionTechParam_Temp 
                where HSourceCode = '" + HNumber + @"' and HTechParamName = '顶部点胶重量')
                union
                select top 1 HTechParamName,HResult,HCreateTime from Sb_EquipMentCollectionTechParam_Temp
                where HSourceCode = '" + HNumber + @"' and HTechParamName = '底部点胶重量' and HCreateTime in(
                select  max(HCreateTime) from  Sb_EquipMentCollectionTechParam_Temp 
                where HSourceCode = '" + HNumber + @"' and HTechParamName = '底部点胶重量')", "Sb_EquipMentCollectionTechParam_Temp");
 
                //DataSet ds = oCN.RunProcReturn(@"select top 1 '螺牙检测数据' HTechParamName,HResult,HCreateTime from Sb_EquipMentCollectionTechParam_Temp 
                //where  HTechParamName = '保压2'
                //union
                //select top 1 '同步测试' HTechParamName,HResult,HCreateTime from Sb_EquipMentCollectionTechParam_Temp
                //where  HTechParamName = '保压1'
                //order by HCreateTime desc", "Sb_EquipMentCollectionTechParam_Temp");
 
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //获取  顶部点胶重量 和 底部点胶重量
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        string HTechParamName = ds.Tables[0].Rows[i]["HTechParamName"].ToString();
                        for (int j = 0; j < dataTable.Rows.Count; j++)
                        {
                            if (HTechParamName == dataTable.Rows[j]["HQCCheckItemHName"].ToString())
                            {
                                string HResult = ds.Tables[0].Rows[i]["HResult"].ToString();
                                dataTable.Rows[j]["Actual"] = HResult;
 
                                switch (HTechParamName)
                                {
                                    case "顶部点胶重量":
                                        this.BeforeWeigh.Text = HResult;
                                        break;
                                    case "底部点胶重量":
                                        this.AfterWeigh.Text = HResult;
                                        break;
                                    default:
                                        MessageBox.Show("设备错误!");
                                        break;
                                }
 
                                //switch (HTechParamName)
                                //{
                                //    case "螺牙检测数据":
                                //        this.BeforeWeigh.Text = HResult;
                                //        break;
                                //    case "同步测试":
                                //        this.AfterWeigh.Text = HResult;
                                //        break;
                                //    default:
                                //        MessageBox.Show("设备错误!");
                                //        break;
                                //}
 
                                ListData.Items.Add("参数:" + ds.Tables[0].Rows[i]["HTechParamName"].ToString() + ",值:" + HResult);
                                break;
                            }
                        }
                    }
                }
            }
        }
        //更换流转卡
        private void btnRep_Click(object sender, EventArgs e)
        {
            this.txtLzk.Text = "";
            this.txtLzk.ReadOnly = false;
            this.txtPcm.Text = "";
            this.cmbPro.DataSource = null;
            this.ListData.Items.Clear();
            this.BeforeWeigh.Text = "";
            this.AfterWeigh.Text = "";
            this.btnSave.Enabled = true;
            this.cmbEquip.SelectedIndex = 0;
        }
 
        //保存
        private void btnSave_Click(object sender, EventArgs e)
        {
            string txtLzk = this.txtLzk.Text;
            if (txtLzk == "")
            {
                MessageBox.Show("流转卡没有扫描!");
            }
            else
            {
                //保存按钮灰掉
                this.btnSave.Enabled = false;
                string SelectTpye = this.cmbJYSelect.Text;
                switch (SelectTpye)
                {
                    case "首件检验单":
                        FistInspectionForm_Save();
                        break;
                    case "巡检检验单":
                        InspectionForm_Save();
                        break;
                    case "工序检验单":
                        FinalInspectionForm_Save();
                        break;
                    default:
                        MessageBox.Show("检验类型错误!");
                        break;
                }
            }
        }
 
 
        //判断流转卡对应的物料有没有检验方案
        public void ShowData(string HNumber)
        {
            //清空网格内容
            ListData.Items.Clear();
            //清空表格内容
            dataTable.Columns.Clear();
            dataTable.Rows.Clear();
 
            dataTable.Columns.Add("HQCSchemeID");
            dataTable.Columns.Add("CharacteristicID");
            dataTable.Columns.Add("HQCStd");
            dataTable.Columns.Add("Actual");
            dataTable.Columns.Add("HUpLimit");
            dataTable.Columns.Add("HDownLimit");
            dataTable.Columns.Add("HInspectInstruMentID");
            dataTable.Columns.Add("HQCCheckItemHName");
 
 
            //修改是在哪个设备上进行的数据采集 b.HInspectInstruMentID=1  三坐标1    轮廓仪2
            DataSet dataSet = oCN.RunProcReturn(@"select b.HInspectInstruMentID,a.HInterID HQCSchemeID,b.HQCCheckItemID, ch.HNumber HQCCheckItemNumber,ch.HName HQCCheckItemHName,m.HNumber,HUpLimit,HDownLimit,HTargetVal 
from Sc_ProcessExchangeBillMain pr with(nolock)
inner join Gy_QCCheckProjectMain a with(nolock) on pr.HMaterID=a.HMaterID
inner join Gy_QCCheckProjectSub b with(nolock) on a.HInterID=b.HInterID  
inner join Gy_InspectInstruMent men  with(nolock) on b.HInspectInstruMentID=men.HItemID   and men.HNumber='" + HNumber + @"'  
left join Gy_Material m with(nolock) on a.HMaterID=m.HItemID
left join Gy_QCCheckItem ch with(nolock) on b.HQCCheckItemID=ch.HItemID  
where pr.HBillNo='" + this.txtLzk.Text + "'", "Gy_QCCheckProjectMain");
 
            if (dataSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("当前流转卡对应的物料没有对应的检验方案!");
            }
            else
            {
                for (int j = 0; j < dataSet.Tables[0].Rows.Count; j++)
                {
                    DataRow dr = dataTable.NewRow();
                    dr["HQCSchemeID"] = dataSet.Tables[0].Rows[j]["HQCSchemeID"].ToString();
                    dr["CharacteristicID"] = dataSet.Tables[0].Rows[j]["HQCCheckItemID"].ToString();
                    dr["HQCStd"] = dataSet.Tables[0].Rows[j]["HTargetVal"].ToString();
                    dr["Actual"] = "0";
                    dr["HUpLimit"] = dataSet.Tables[0].Rows[j]["HUpLimit"].ToString();
                    dr["HDownLimit"] = dataSet.Tables[0].Rows[j]["HDownLimit"].ToString();
                    dr["HInspectInstruMentID"] = dataSet.Tables[0].Rows[j]["HInspectInstruMentID"].ToString();
                    dr["HQCCheckItemHName"] = dataSet.Tables[0].Rows[j]["HQCCheckItemHName"].ToString();
                    string HQCCheckItemHName = dataSet.Tables[0].Rows[j]["HQCCheckItemHName"].ToString();
                    ListData.Items.Add("参数:" + HQCCheckItemHName + ",上限值:" + dataSet.Tables[0].Rows[j]["HUpLimit"].ToString() + ",下限值:" + dataSet.Tables[0].Rows[j]["HDownLimit"].ToString());
                    if (dr.ItemArray.Length > 0)
                    {
                        dataTable.Rows.Add(dr);
                    }
                }
            }
        }
 
        //首件检验单保存
        public void FistInspectionForm_Save()
        {
            try
            {
                string HProcID = this.cmbPro.SelectedValue.ToString();
                string sExeReturnInfo = "";
                string BillType = "7505";
                long HInterID = oCN.CreateBillID_Prod(BillType, ref sExeReturnInfo);
                string HBillNo = oCN.CreateBillCode(BillType, ref sExeReturnInfo, true);
 
                //判断当前流转卡对应的工序有没有开工
                DataSet ds = oCN.RunProcReturn(@"select    staus.HSourceID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo,a.HPlanQty,a.HInterID HProcExchInterID,
staus.HSourceEntryID HProcExchEntryID,a.HBillNo HProcExchBillNo,a.HQty,a.HMaterID
from Sc_ProcessExchangeBillMain a with(nolock)
inner join Sc_ICMOBillStatus_Tmp staus with(nolock) on a.HInterID=staus.HSourceInterID  
where a.HBillNo='" + this.txtLzk.Text + "' and staus.HProcID=" + HProcID, "Sc_ProcessExchangeBillMain");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("当前工单没有开工数据!");
                    this.btnSave.Enabled = true;
                }
                else
                {
                    string HSourceID = ds.Tables[0].Rows[0]["HSourceID"].ToString();
                    string HICMOInterID = ds.Tables[0].Rows[0]["HICMOInterID"].ToString();
                    string HICMOEntryID = ds.Tables[0].Rows[0]["HICMOEntryID"].ToString();
                    string HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                    string HPlanQty = ds.Tables[0].Rows[0]["HPlanQty"].ToString();
                    string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                    string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                    string HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                    string HQty = ds.Tables[0].Rows[0]["HQty"].ToString();
                    string HMaterID = ds.Tables[0].Rows[0]["HMaterID"].ToString();
                    string HQCSchemeID = dataTable.Rows[0]["HQCSchemeID"].ToString();
                  
                    int HLastResults = 1;
                    
                    oCN.BeginTran();
 
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        decimal HWeigh = decimal.Parse(dataTable.Rows[i]["Actual"].ToString());
                        decimal HUpLimits = decimal.Parse(dataTable.Rows[i]["HUpLimit"].ToString()) + decimal.Parse(dataTable.Rows[i]["HQCStd"].ToString());
                        decimal HDownLimits = decimal.Parse(dataTable.Rows[i]["HDownLimit"].ToString()) + decimal.Parse(dataTable.Rows[i]["HQCStd"].ToString());
                        int HLastResult = (HWeigh <= HUpLimits && HDownLimits <= HWeigh) ? 1 : 0;
 
                        if (HLastResult == 1 && HLastResults != 0)
                        {
                            HLastResults = 1;
                        }
                        else
                        {
                            HLastResults = 0;
                        }
                        //新增子表
                        oCN.RunProc("Insert into QC_FirstPieceCheckBillSub " +
                        " (HInterID,HBillNo_bak,HEntryID,HCloseMan" +
                        ",HEntryCloseDate,HCloseType,HRemark,HSourceInterID" +
                        ",HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                        ",HQCCheckItemID,HQCStd,HUnit,HQCNote,HResult" +
                        ",HMax,HMin,HAvg,HSampleSchemeID,HSampleQty,HSampleDamageQty,HAcceptQty" +
                        ",HRejectQty,HSampleUnRightQty,HStatus,HUnitID,HInspectVal,HTargetVal" +
                        ",HUpLimit,HDownLimit,HUpOffSet,HDownOffSet,HKeyInspect,HAnalysisMethod,HInspectInstruMentID,HInspectResult" +
                        ") values("
                        + HInterID + ",'" + HBillNo + "'," + (i + 1) + ",''" +
                        ",getdate(),0,''," + HProcExchInterID +
                        "," + HProcExchEntryID + ",'" + HProcExchBillNo + "','',0,0" +
                        "," + dataTable.Rows[i]["CharacteristicID"].ToString() + ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "','','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + HLastResult + "'" +
                        ",'" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "',''" + ",0,0,0,0,0,0,'',0,'" + HWeigh + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "','','',0,'2'," + dataTable.Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" +
                        ") ");
                    }
 
                    string HMakeDate = DateTime.Now.ToString();
 
                    //主表
                    oCN.RunProc("Insert Into QC_FirstPieceCheckBillMain " +
                        "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
                        ",HYear,HPeriod,HRemark" +
                        ",HSourceID,HICMOInterID,HICMOBillNo,HICMOQty,HProcExchInterID,HProcExchEntryID" +
                        ",HProcExchBillNo,HProcExchQty,HMaterID,HFirstCheckEmp,HLastResult" +
                        ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HShiftsID,HErrTreatment" +
                        ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo,HProcID" +
                        ",HBatchNo) " +
                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,'" + HMakeDate + "','" + this.txtHMaker.Text + "',getdate()" +
                        "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                        "," + HSourceID + "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HPlanQty + "," + HProcExchInterID + "," + HProcExchEntryID +
                        ",'" + HProcExchBillNo + "'," + HQty + "," + HMaterID + ",'" + this.labHMakerID.Text + "', " + HLastResults +
                        "," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "',''," + HICMOEntryID + "," + HQCSchemeID + ",0,''" +
                        ",0,''," + HProcID + "" +
                        ",'" + this.txtPcm.Text + "') ");
 
                    oCN.Commit();
 
                    MessageBox.Show("保存成功!");
 
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                //保存按钮灰掉
                this.btnSave.Enabled = true;
                MessageBox.Show("保存失败!" + e.Message);
            }
        }
 
        //巡检检验单保存
        public void InspectionForm_Save()
        {
            try
            {
                string HProcID = this.cmbPro.SelectedValue.ToString();
                string sExeReturnInfo = "";
                string BillType = "7520";
                long HInterID = oCN.CreateBillID_Prod(BillType, ref sExeReturnInfo);
                string HBillNo = oCN.CreateBillCode(BillType, ref sExeReturnInfo, true);
 
                //判断当前流转卡对应的工序有没有开工
                DataSet ds = oCN.RunProcReturn(@"select    staus.HSourceID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo,a.HPlanQty,a.HInterID HProcExchInterID,
staus.HSourceEntryID HProcExchEntryID,a.HBillNo HProcExchBillNo,a.HQty,a.HMaterID
from Sc_ProcessExchangeBillMain a with(nolock)
inner join Sc_ICMOBillStatus_Tmp staus with(nolock) on a.HInterID=staus.HSourceInterID  
where a.HBillNo='" + this.txtLzk.Text + "' and staus.HProcID=" + HProcID, "Sc_ProcessExchangeBillMain");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("当前工单没有开工数据!");
                    this.btnSave.Enabled = true;
                }
                else
                {
                    string HSourceID = ds.Tables[0].Rows[0]["HSourceID"].ToString();
                    string HICMOInterID = ds.Tables[0].Rows[0]["HICMOInterID"].ToString();
                    string HICMOEntryID = ds.Tables[0].Rows[0]["HICMOEntryID"].ToString();
                    string HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                    string HPlanQty = ds.Tables[0].Rows[0]["HPlanQty"].ToString();
                    string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                    string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                    string HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                    string HQty = ds.Tables[0].Rows[0]["HQty"].ToString();
                    string HMaterID = ds.Tables[0].Rows[0]["HMaterID"].ToString();
                    string HQCSchemeID = dataTable.Rows[0]["HQCSchemeID"].ToString();
                    int HLastResults = 1;
 
                    oCN.BeginTran();
 
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        decimal HWeigh = decimal.Parse(dataTable.Rows[i]["Actual"].ToString());
                        decimal HUpLimits = decimal.Parse(dataTable.Rows[i]["HUpLimit"].ToString()) + decimal.Parse(dataTable.Rows[i]["HQCStd"].ToString());
                        decimal HDownLimits = decimal.Parse(dataTable.Rows[i]["HDownLimit"].ToString()) + decimal.Parse(dataTable.Rows[i]["HQCStd"].ToString());
                        int HLastResult = (HWeigh <= HUpLimits && HDownLimits <= HWeigh) ? 1 : 0;
 
                        if (HLastResult == 1 && HLastResults != 0)
                        {
                            HLastResults = 1;
                        }
                        else
                        {
                            HLastResults = 0;
                        }
 
                        oCN.RunProc("Insert into QC_PatrolProcCheckOtherBillSub " +
                        " (HInterID,HBillNo_bak,HEntryID,HCloseMan" +
                        ",HEntryCloseDate,HCloseType,HRemark,HSourceInterID" +
                        ",HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                        ",HQCCheckItemID,HQCStd,HUnit,HQCNote,HResult" +
                        ",HMax,HMin,HAvg,HSampleSchemeID,HSampleQty,HSampleDamageQty,HAcceptQty" +
                        ",HRejectQty,HSampleUnRightQty,HStatus,HUnitID,HInspectVal,HTargetVal" +
                        ",HUpLimit,HDownLimit,HUpOffSet,HDownOffSet,HKeyInspect,HAnalysisMethod,HInspectInstruMentID,HInspectResult" +
                        ") values("
                        + HInterID + ",'" + HBillNo + "'," + (i + 1) + ",''" +
                        ",getdate(),0,''," + HProcExchInterID +
                        "," + HProcExchEntryID + ",'" + HProcExchBillNo + "','',0,0," + dataTable.Rows[i]["CharacteristicID"].ToString() + ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "','','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + HLastResult + "'" +
                        ",'" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "',''" + ",0,0,0,0,0,0,'',0,'" + HWeigh + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "','','',0,'2'," + dataTable.Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" + ") ");
                    }
 
                    string HMakeDate = DateTime.Now.ToString();
 
                    //主表
                    oCN.RunProc("Insert Into QC_PatrolProcCheckOtherBillMain " +
                        "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
                        ",HYear,HPeriod,HRemark" +
                        ",HSourceID,HICMOInterID,HICMOBillNo,HICMOQty,HProcExchInterID,HProcExchEntryID" +
                        ",HProcExchBillNo,HProcExchQty,HMaterID,HFirstCheckEmp,HLastResult" +
                        ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HShiftsID,HErrTreatment" +
                        ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo,HProcID,HBatchNo) " +
                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,'" + HMakeDate + "','" + this.txtHMaker.Text + "',getdate()" +
                        "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                        "," + HSourceID + "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HPlanQty + "," + HProcExchInterID + "," + HProcExchEntryID +
                        ",'" + HProcExchBillNo + "'," + HQty + "," + HMaterID + ",'" + this.labHMakerID.Text + "', " + HLastResults +
                        "," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "',''," + HICMOEntryID + "," + HQCSchemeID + ",0,''" +
                        ",0,''," + HProcID + ",'" + this.txtPcm.Text + "') ");
 
                    oCN.Commit();
 
                    MessageBox.Show("保存成功!");
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                MessageBox.Show("保存失败!" + e.Message);
            }
        }
 
        //末检检验单
        public void FinalInspectionForm_Save()
        {
            try
            {
                string HProcID = this.cmbPro.SelectedValue.ToString();
                string sExeReturnInfo = "";
                string BillType = "7507";
                long HInterID = oCN.CreateBillID_Prod(BillType, ref sExeReturnInfo);
                string HBillNo = oCN.CreateBillCode(BillType, ref sExeReturnInfo, true);
 
                //判断当前流转卡对应的工序有没有开工
                DataSet ds = oCN.RunProcReturn(@"select    staus.HSourceID,a.HICMOInterID,a.HICMOEntryID,a.HICMOBillNo,a.HPlanQty,a.HInterID HProcExchInterID,
staus.HSourceEntryID HProcExchEntryID,a.HBillNo HProcExchBillNo,a.HQty,a.HMaterID,staus.HProcID
from Sc_ProcessExchangeBillMain a with(nolock)
inner join Sc_ICMOBillStatus_Tmp staus with(nolock) on a.HInterID=staus.HSourceInterID   
where a.HBillNo='" + this.txtLzk.Text + "' and staus.HProcID=" + HProcID, "Sc_ProcessExchangeBillMain");
 
                if (ds.Tables[0].Rows.Count == 0)
                {
                    MessageBox.Show("当前工单没有开工数据!");
                    this.btnSave.Enabled = true;
                }
                else
                {
                    string HSourceID = ds.Tables[0].Rows[0]["HSourceID"].ToString();
                    string HICMOInterID = ds.Tables[0].Rows[0]["HICMOInterID"].ToString();
                    string HICMOEntryID = ds.Tables[0].Rows[0]["HICMOEntryID"].ToString();
                    string HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                    string HPlanQty = ds.Tables[0].Rows[0]["HPlanQty"].ToString();
                    string HProcExchInterID = ds.Tables[0].Rows[0]["HProcExchInterID"].ToString();
                    string HProcExchEntryID = ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString();
                    string HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                    string HQty = ds.Tables[0].Rows[0]["HQty"].ToString();
                    string HMaterID = ds.Tables[0].Rows[0]["HMaterID"].ToString();
                    HProcID = ds.Tables[0].Rows[0]["HProcID"].ToString();
                    string HQCSchemeID = dataTable.Rows[0]["HQCSchemeID"].ToString();
                    int HLastResults = 1;
 
 
                    oCN.BeginTran();
 
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        decimal HWeigh = decimal.Parse(dataTable.Rows[i]["Actual"].ToString());
                        decimal HUpLimits = decimal.Parse(dataTable.Rows[i]["HUpLimit"].ToString()) + decimal.Parse(dataTable.Rows[i]["HQCStd"].ToString());
                        decimal HDownLimits = decimal.Parse(dataTable.Rows[i]["HDownLimit"].ToString()) + decimal.Parse(dataTable.Rows[i]["HQCStd"].ToString());
                        int HLastResult = (HWeigh <= HUpLimits && HDownLimits <= HWeigh) ? 1 : 0;
 
                        if (HLastResult == 1 && HLastResults != 0)
                        {
                            HLastResults = 1;
                        }
                        else
                        {
                            HLastResults = 0;
                        }
 
                        oCN.RunProc("Insert into QC_ProcessCheckBillSub " +
                        " (HInterID,HBillNo_bak,HEntryID,HCloseMan" +
                        ",HEntryCloseDate,HCloseType,HRemark,HSourceInterID" +
                        ",HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
                         ",HQCCheckClassID,HQCCheckItemID,HQCStd,HQCRelValue,HResult" +
                        ",HProcCheckEmp,HProcCheckTime,HSampleSchemeID,HSampleQty,HSampleDamageQty,HAcceptQty" +
                        ",HRejectQty,HSampleUnRightQty,HStatus,HUnitID,HInspectVal,HTargetVal" +
                        ",HUpLimit,HDownLimit,HUpOffSet,HDownOffSet,HKeyInspect,HAnalysisMethod,HInspectInstruMentID,HInspectResult" +
                        ",HQCNote) values("
                        + HInterID + ",'" + HBillNo + "'," + (i + 1) + ",''" +
                        ",getdate(),0,''," + HProcExchInterID +
                        "," + HProcExchEntryID + ",'" + HProcExchBillNo + "','',0,0,0," + dataTable.Rows[i]["CharacteristicID"].ToString() + ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "','','" + HLastResult + "'" +
                        ",0,'',0,0,0,0,0,0,'',0,'" + HWeigh + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() +
                                "','','',0,'2'," + dataTable.Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" +
                                ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "') ");
                    }
 
                    string HMakeDate = DateTime.Now.ToString();
 
                    //主表
                    oCN.RunProc("Insert Into QC_ProcessCheckBillMain " +
                    "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
                    ",HYear,HPeriod,HRemark" +
                    ",HICMOInterID,HICMOBillNo,HProcExchInterID,HProcExchEntryID,HProcExchBillNo" +
                    ",HMaterID,HProcID,HSourceID,HEmpID,HInStockQty" +
                    ",HCheckQty,HRightQty,HBadQty,HFirstCheckEmp,HLastResult" +
                    ",HBarCode,HLBatchNo,HCusID,HSortBillNo,HContrctBatchNo" +
                    ",HProdAreaID,HProdTypeID,HProdStoveNo,HRecipeID,HDiameter1" +
                    ",HDiameter2,HRoutingInterID,HDrawingDireID,HPackTypeID" +
                    ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HICMOQty" +
                    ",HProcExchQty,HShiftsID,HErrTreatment" +
                    ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo" +
                    ",HBatchNo,HCheckerResult) " +
                    " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,'" + HMakeDate + "','" + this.txtHMaker.Text + "',getdate()" +
                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                    "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "'" +
                    "," + HMaterID + "," + HProcID + "," + HSourceID + ",0,0,0,0,0," + this.labHMakerID.Text + ",'" + HLastResults + "'" +
                    ",'','',0,'',''" +
                    ",0,0,'',0,0,0,0,'',0," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "',''," + HICMOEntryID + "," + HQCSchemeID + "," + HPlanQty + "," + HQty + ",0,''" +
                    ",0,''" +
                    ",'" + this.txtPcm.Text + "','" + HLastResults + "') ");
 
 
                    oCN.Commit();
 
                    MessageBox.Show("保存成功!");
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                MessageBox.Show("保存失败!" + e.Message);
            }
        }
 
        private void btnAfterSelect_Click(object sender, EventArgs e)
        {
 
        }
        //更换用户
        private void btnHMaker_Click(object sender, EventArgs e)
        {
            this.txtHMaker.Text = "";
            this.txtHMaker.ReadOnly = false;
            this.txtHMakerNumber.Text = "";
            this.labHMakerID.Text = "0";
        }
 
        private void ZZ_GlueWeigh_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("确定要关闭吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
            }
        }
 
        private void ZZ_GlueWeigh_Activated(object sender, EventArgs e)
        {
            //光标选中制单人
            this.txtHMaker.Focus();
        }
    }
}