Ejemplo n.º 1
0
 /// <summary>
 /// TODO 打印裝箱單
 /// </summary>
 private void printCarton()
 {
     //打印装箱单号
     if (this.dataGridView1.Rows.Count > 0)
     {
         Carton carton = new Carton();
         carton.Workno       = firstScan.Workno;
         carton.Delmatno     = firstScan.Delmatno;
         carton.Cusno        = firstScan.Cusno;
         carton.PackType     = "0";              //包裝類型:0 整機, 1單出
         carton.Cusname      = firstScan.Cusname;
         carton.Cuspo        = firstScan.Cuspo;
         carton.Orderqty     = firstScan.Orderqty;
         carton.Cusmatno     = firstScan.Cusmatno;
         carton.Delmatno     = firstScan.Delmatno;
         carton.Offino       = firstScan.Offino;
         carton.Verno        = firstScan.Verno;
         carton.Woquantity   = firstScan.Woquantity;
         carton.SoOrder      = firstScan.SoOrder;
         carton.Ruleno       = codeRule.Ruleno;
         carton.ProdId       = this.comboBox2.SelectedValue.ToString();
         carton.ProdLineVal  = this.comboBox2.Text;
         carton.Modelno      = fileRelDel.FileNo;           //浪潮默認使用的打印模板
         carton.CartonStatus = "0";
         if (capacity != null)
         {
             carton.CapacityNo = capacity.Capacityno;
         }
         carton.ProdId      = this.comboBox2.SelectedValue.ToString();    //打印時 獲得線別編號
         carton.ProdLineVal = this.comboBox2.Text;
         carton.CartonQty   = countQty(ctCodeList);                       //裝箱單數量
         initCTSeq(ctCodeList, carton);
         carton.Datecode = dateTimePicker1.Value.ToString(comboBox3.Text);
         carton          = GenerateCarton.generateCartonNo(carton, codeRule, dateTimePicker1.Value);
         foreach (MandUnionFieldType mandTYpe in mandUnionFieldTypeList)
         {
             if (mandTYpe.FieldName.ToUpper().Equals("SpecialField".ToUpper()))
             {
                 StringBuilder special = new StringBuilder();
                 string        cusPn   = "";
                 string        verNo   = "";
                 foreach (MandUnionFieldType mandTYpe2 in mandUnionFieldTypeList)
                 {
                     if (mandTYpe2.FieldName.ToUpper().Equals("CusPN".ToUpper()))
                     {
                         cusPn = mandTYpe2.FieldValue;
                     }
                     if (mandTYpe2.FieldName.ToUpper().Equals("Versionno".ToUpper()))
                     {
                         verNo = mandTYpe2.FieldValue;
                     }
                 }
                 special.Append(cusPn);
                 special.Append(" {{" + carton.CartonQty + " {{PCS {{041098 {{" + carton.Datecode + " {{CHN {{" + carton.Cuspo + " {{/ {{" + carton.CartonNo + " {{" + carton.Datecode + " {{XY {{" + carton.Delmatno + " {{");
                 special.Append(verNo);
                 carton.SpecialField = special.ToString();
             }
             if (mandTYpe.FieldName.ToUpper().Equals("UnionField".ToUpper()))
             {
                 carton.UnionField = "BB" + carton.CartonNo + "||P" + carton.Cusmatno + "||Q" + carton.CartonQty + "||1P" + carton.Delmatno;
             }
             if (mandTYpe.FieldName.ToUpper().Equals("BoxNo".ToUpper()))
             {
                 if (mandTYpe.FieldValue.ToUpper().Equals("WorkQty".ToUpper()))                                     //当特殊字段为 四位工单流水 +  P + 4位工单数量
                 {
                     int currentNumber = cartonService.currentBoxQtyByCuspo(carton.Cuspo, carton.Delmatno, carton.Workno);
                     currentNumber = currentNumber == 0 ? 1 : (currentNumber + 1);
                     string tempStr = "";
                     for (int i = currentNumber.ToString().Length; i < 4; i++)
                     {
                         tempStr = tempStr + "0";
                     }
                     string prefix   = tempStr + currentNumber.ToString();
                     string tempStr2 = "";
                     string suffix   = "";
                     if (int.Parse(carton.Woquantity) < int.Parse(carton.Orderqty))
                     {
                         for (int i = carton.Woquantity.Length; i < 4; i++)
                         {
                             tempStr2 = tempStr2 + "0";
                         }
                         suffix = tempStr2 + carton.Woquantity;
                     }
                     else
                     {
                         for (int i = carton.Orderqty.Length; i < 4; i++)
                         {
                             tempStr2 = tempStr2 + "0";
                         }
                         suffix = tempStr2 + carton.Orderqty;
                     }
                     carton.BoxNo = prefix + "P/" + suffix;
                 }
                 else
                 {
                     int currentNumber = cartonService.queryCurrentBoxQty(carton.Workno);
                     currentNumber = currentNumber == 0 ? 1 : (currentNumber + 1);
                     string tempStr = "";
                     for (int i = currentNumber.ToString().Length; i < 3; i++)
                     {
                         tempStr = tempStr + "0";
                     }
                     carton.BoxNo = tempStr + currentNumber.ToString();
                 }
             }
         }
         //Thread thread = new Thread(() => {
         //    if (!cartonService.saveCartonByTrans(carton))
         //    {
         //        MessageBox.Show("保存裝箱單失敗!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
         //        return;
         //    }
         //});
         //clear();
         //thread.Start();
         if (cartonService.saveCartonByTrans(carton))
         {
             Thread threadPrint = new Thread(() =>
             {
                 bool judgePrint = barPrint.bactchPrintCartonByModel(filePath, cartonListToArray(carton, mandUnionFieldTypeList, (int)this.numericUpDown3.Value));
                 if (!judgePrint)
                 {
                     MessageBox.Show("打印失敗請聯係管理員!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     return;
                 }
             });
             threadPrint.Start();
         }
         else
         {
             MessageBox.Show("保存裝箱單失敗!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             return;
         }
         clear();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// TODO 打印裝箱單
        /// </summary>
        private void printCarton(bool isSave)
        {
            if (codeRule == null)
            {
                MessageBox.Show("请联系管理员,绑定箱号的编码规则", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox1.Focus();
                return;
            }
            //查询标签模板
            if (fileRelDel == null)
            {
                MessageBox.Show("请联系管理员,绑定标签模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBox1.Focus();
                return;
            }
            //查詢字段對應的規則信息
            if (mandUnionFieldTypeList == null)
            {
                MessageBox.Show("未找到該客戶出貨料號對應的打印字段規則信息,請維護相關信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Carton carton = new Carton();

            carton.ProdId      = this.comboBox2.SelectedValue.ToString();             //打印時 獲得線別編號
            carton.ProdLineVal = this.comboBox2.Text;
            carton.CartonQty   = (int)this.numericUpDown1.Value;                      //裝箱單數量
            carton.Datecode    = dateTimePicker1.Value.ToString(comboBox6.Text);
            carton.Ruleno      = codeRule.Ruleno;
            carton.Workno      = workNo;
            carton.Delmatno    = this.textBox8.Text;
            carton.Cusmatno    = this.textBox9.Text;
            carton.Cusno       = this.textBox7.Text;
            carton.PackType    = "1";                                                //包裝類型:0 整機, 1單出
            carton.Cusname     = this.textBox6.Text;
            carton.Orderqty    = this.textBox13.Text;
            carton.Woquantity  = this.textBox4.Text;
            carton.SoOrder     = this.textBox17.Text;
            carton.Cuspo       = this.comboBox3.Text == null ? "" : this.comboBox3.Text.ToString().Trim(); //Cuspo
            carton.ProdId      = this.comboBox2.SelectedValue.ToString();
            carton.Modelno     = fileRelDel.FileNo;                                                        //TYPE= 1 為裝箱單模板
            if (capacity != null)
            {
                carton.CapacityNo = capacity.Capacityno;
            }
            carton.CartonStatus = "0";
            carton = GenerateCarton.generateCartonNo(carton, codeRule, dateTimePicker1.Value);
            //顯示箱號:
            this.textBox10.Text = carton.CartonNo;;
            this.textBox3.Text  = carton.BatchNo;

            foreach (MandUnionFieldType mandTYpe in mandUnionFieldTypeList)
            {
                if (mandTYpe.FieldName.ToUpper().Equals("SpecialField".ToUpper()))
                {
                    StringBuilder special = new StringBuilder();
                    string        cusPn   = "";
                    string        verNo   = "";
                    foreach (MandUnionFieldType mandTYpe2 in mandUnionFieldTypeList)
                    {
                        if (mandTYpe2.FieldName.ToUpper().Equals("CusPN".ToUpper()))
                        {
                            cusPn = mandTYpe2.FieldValue;
                        }
                        if (mandTYpe2.FieldName.ToUpper().Equals("versionNo".ToUpper()))
                        {
                            verNo = mandTYpe2.FieldValue;
                        }
                    }
                    special.Append(cusPn);
                    special.Append(" {{" + carton.CartonQty + " {{PCS {{041098 {{" + carton.Datecode + " {{CHN {{" + carton.Cuspo + " {{/ {{" + carton.CartonNo + " {{" + carton.Datecode + " {{XY {{" + carton.Delmatno + " {{");
                    special.Append(verNo);
                    carton.SpecialField = special.ToString();
                }
                if (mandTYpe.FieldName.ToUpper().Equals("UnionField".ToUpper()))
                {
                    carton.UnionField = "BB" + carton.CartonNo + "||P" + carton.Cusmatno + "||Q" + carton.CartonQty + "||1P" + carton.Delmatno;
                }
                if (mandTYpe.FieldName.ToUpper().Equals("BoxNo".ToUpper()))
                {
                    if (mandTYpe.FieldValue.ToUpper().Equals("WorkQty".ToUpper()))                                     //当特殊字段为 四位工单流水 +  P + 4位工单数量
                    {
                        int currentNumber = cartonService.currentBoxQtyByCuspo(carton.Cuspo, carton.Delmatno, carton.Workno);
                        currentNumber = currentNumber == 0 ? 1 : (currentNumber + 1);
                        string tempStr = "";
                        for (int i = currentNumber.ToString().Length; i < 4; i++)
                        {
                            tempStr = tempStr + "0";
                        }
                        string prefix   = tempStr + currentNumber.ToString();
                        string tempStr2 = "";
                        string suffix   = "";
                        if (int.Parse(carton.Woquantity) < int.Parse(carton.Orderqty))
                        {
                            for (int i = carton.Woquantity.Length; i < 4; i++)
                            {
                                tempStr2 = tempStr2 + "0";
                            }
                            suffix = tempStr2 + carton.Woquantity;
                        }
                        else
                        {
                            for (int i = carton.Orderqty.Length; i < 4; i++)
                            {
                                tempStr2 = tempStr2 + "0";
                            }
                            suffix = tempStr2 + carton.Orderqty;
                        }
                        carton.BoxNo = prefix + "P/" + suffix;
                    }
                    else
                    {
                        int currentNumber = cartonService.queryCurrentBoxQty(carton.Workno);
                        currentNumber = currentNumber == 0 ? 1 : (currentNumber + 1);
                        string tempStr = "";
                        for (int i = currentNumber.ToString().Length; i < 3; i++)
                        {
                            tempStr = tempStr + "0";
                        }
                        carton.BoxNo = tempStr + currentNumber.ToString();
                    }
                }
            }

            bool judgePrint = barPrint.bactchPrintCartonByModel(filePath, cartonListToArray(carton, mandUnionFieldTypeList, (int)this.numericUpDown3.Value));

            if (judgePrint)
            {
                if (isSave)
                {
                    if (!cartonService.saveCarton(carton))
                    {
                        MessageBox.Show("保存裝箱單失敗!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("打印失敗請聯係管理員!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }