ch
2022-01-02 497807c8f2bf240703c8e899327d78a66fcc1f4d
WarM/ÌõÂë´òÓ¡/Gy_BarCodeBill.cs
@@ -27,8 +27,8 @@
        public const Int16 HMaterIDCol = 6;
        public const Int16 HMaterNumberCol = 7;
        public const Int16 HMaterNameCol = 8;
        public const Int16 HPinfanCol = 9;
        public const Int16 HMaterModelCol = 10;
        public const Int16 HPinfanCol = 9;//
        public const Int16 HMaterModelCol = 10;//
        public const Int16 HModelCol = 11;
        public const Int16 HAuxPropIDCol = 12;
        public const Int16 HAuxPropNumberCol = 13;
@@ -173,10 +173,31 @@
            cmbHBarCodeType.Items.Clear();
            cmbSourceBillType.Items.Clear();
            cmbHBarCodeType.Items.Add("唯一条码");
            cmbHBarCodeType.Items.Add("品种条码");
            cmbHBarCodeType.Items.Add("批次条码");
            //cmbHBarCodeType.Items.Add("托盘条码");
            //根据系统参数获取对应的条码类型(夏宝电器、博日   ä»¥åŽä½¿ç”¨æ¡ç è§„则表)
            ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
            string sCapName = oClsXt_SystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
            if(sCapName=="夏宝电器")
            {
                cmbHBarCodeType.Items.Add("内销机条码");
                cmbHBarCodeType.Items.Add("外销机条码");
                cmbHBarCodeType.Items.Add("半成品条码");
            }
            else if (sCapName == "博日科技")
            {
                cmbHBarCodeType.Items.Add("仪器外购件条码普通规则");
                cmbHBarCodeType.Items.Add("仪器外购件条码容器规则");
                cmbHBarCodeType.Items.Add("仪器成品条码规则");
                cmbHBarCodeType.Items.Add("试剂成品条码规则");
            }
            else
            {
                //
                cmbHBarCodeType.Items.Add("唯一条码");
                cmbHBarCodeType.Items.Add("品种条码");
                cmbHBarCodeType.Items.Add("批次条码");
                //cmbHBarCodeType.Items.Add("托盘条码");
            }
            //
            cmbSourceBillType.Items.Add("生产订单");
            cmbSourceBillType.Items.Add("生产汇报单");
@@ -631,7 +652,14 @@
                return false;
            }
            bc.Enabled = false;
            SaveBarCode();
            if (cmbHBarCodeType.Text == "仪器成品条码规则")
            {
                SaveBarCode_bori(); //物料编码+序列号+生产日期
            }
            else
            {
                SaveBarCode();
            }
            return true;
        }
@@ -642,7 +670,8 @@
            int LSHlen = 6;             //流水号长度
            int SumLen = 10;            //总长度
            string TM = "";             //条码
            string HNumber = "";        //物料代码
            string HNumber = "";        //物料内码
            string HMaterNumber = "";   //物料代码
            double HSumQty = 0;         //产品数量
            double HMinQty = 0;         //最小包装数
            int HBQty = 0;              //箱数
@@ -655,6 +684,11 @@
            string sPeriod = "";        //月
            string sDay = "";           //日
            string HBatchNo = "";       //批次
            string HYasuoji = "";       //压缩机
            string HModelName = "";       //机型
            string HICMOBillNo = "";       //源单号
            string HBarCodeBatchNo = "";       //条码批次号
            string HBarCodeDate = "";         //条码日期
            int k = 0;
            int n = 0;                  //同一批生成条码中的第几条
            string sTMNumber = "";      //条码自定义前缀
@@ -666,8 +700,29 @@
                if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                {
                    HNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value);
                    HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);
                    HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
                    //日期获取方式
                    sDate = dtpHDate.Value.ToShortDateString();
                    //
                    if (cmbHBarCodeType.Text == "仪器外购件条码普通规则" || cmbHBarCodeType.Text == "仪器外购件条码容器规则") //单据日期(收料通知单)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
                    }
                    else if (cmbHBarCodeType.Text == "试剂成品条码规则")// å¤±æ•ˆæ—¥æœŸï¼ˆç”Ÿäº§è®¢å•)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
                    }
                    else if (CampanyName == "夏宝电器")// æ—¥æœŸï¼šç”Ÿäº§è®¢å• æ¡ç æ—¥æœŸ
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HDateCol].Value);
                    }
                    HYasuoji= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanCol].Value); //压缩机代码(夏宝电器)
                    HModelName= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusTypeCol].Value); //机型(夏宝电器)
                    HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceBillNoCol].Value); //生产订单号(夏宝电器)
                    HBarCodeBatchNo= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value); //条码批次号(夏宝电器)
                    HBarCodeDate= DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HSupNumberCol].Value); //条码日期(夏宝电器)
                    //
                    sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                    sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                    sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
@@ -722,6 +777,71 @@
                    else if (cmbHBarCodeType.Text == "批次条码")
                    {
                        TM = HOrgNumber + HNumber + HBatchNo;
                    }//博日特殊处理
                    else if(cmbHBarCodeType.Text == "仪器外购件条码普通规则" || cmbHBarCodeType.Text == "仪器外购件条码容器规则")
                    {
                        //物料编码+单据日期(YYMMDD)+流水4位
                        sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                    }
                    else if (cmbHBarCodeType.Text == "仪器成品条码规则") //另外处理了
                    {
                        //物料编码+序列号+生产日期
                        //sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
                        //Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        //                                                                                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        //LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                    }
                    else if (cmbHBarCodeType.Text == "试剂成品条码规则")
                    {
                        //物料编码+生产批号+失效日期(YYMMDD)+流水号6位-
                        sTMNumber = HMaterNumber + HBatchNo + sYear + sPeriod + sDay;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 6;
                    }
                    else if (cmbHBarCodeType.Text == "内销机条码")
                    {
                        //制造本部1位(默认1)+机型代码5位()+å¹´2位+月1位(A、B、C代替10月份)
                        //+日2位+条码批次码2位+压缩机代码1位+00+流水号4位+校验码(默认0)
                        sTMNumber = "1" + HModelName + HBarCodeDate + HBarCodeBatchNo + HYasuoji + "00" ;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                        if (sTMNumber.Length != 16)
                        {
                            MessageBox.Show("条码长度不够16位,是否数据不全!制造本部1位:[0] + æœºåž‹ä»£ç 5位:[" + HModelName + "] + å¹´æœˆæ—¥5位:["+ HBarCodeDate + "] + æ‰¹æ¬¡å·2位:[" + HBarCodeBatchNo  + "]+ åŽ‹ç¼©æœº1位:["+ HYasuoji + "]+00 ; ");
                            return;
                        }
                    }
                    else if (cmbHBarCodeType.Text == "外销机条码")
                    {
                        //物料代码11位+å¹´2位+月1位(A、B、C代替10月份)+日2位+批次2位+流水号4位
                        //sTMNumber = HMaterNumber.Replace(Convert.ToChar("."),Convert.ToChar("")) + HBarCodeDate + HBarCodeBatchNo;
                        sTMNumber = HMaterNumber.Replace( "."  ,  "" ) + HBarCodeDate + HBarCodeBatchNo;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                        if (sTMNumber.Length != 18)
                        {
                            MessageBox.Show("条码长度不够18位,是否数据不全!物料代码11位:["+ HMaterNumber.Replace(".", "") + "]+年月日5位:["+ HBarCodeDate + "]+批次号2位:[" + HBarCodeBatchNo  + "];");
                            return;
                        }
                    }
                    else if (cmbHBarCodeType.Text == "半成品条码")
                    {
                        //生产订单号+4位流水号
                        sTMNumber = HICMOBillNo;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                    }
                    //else if (cmbHBarCodeType.Text == "托盘条码")
                    //{
@@ -768,7 +888,17 @@
                            //条码编号 = æ¡ç å‰ç¼€ + æµæ°´å·
                            TM = sTMNumber + LSH2;
                        }
                        else if(cmbHBarCodeType.Text == "仪器外购件条码普通规则" || cmbHBarCodeType.Text == "仪器外购件条码容器规则" || cmbHBarCodeType.Text == "试剂成品条码规则"
                            || cmbHBarCodeType.Text == "半成品条码" || cmbHBarCodeType.Text == "外销机条码")
                        {
                            TM = sTMNumber + LSH2;
                        }
                        else if (cmbHBarCodeType.Text == "内销机条码")
                        {
                            TM = sTMNumber + LSH2 + "0";
                        }
                        //
                        if (i + 1 > grdSub.Rows.Count)
                        {
                            grdSub.RowCount = grdSub.RowCount + 1;
@@ -886,7 +1016,361 @@
                    {
                        HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
                        HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
                        //
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        if (CampanyName == "博日科技" || CampanyName == "夏宝电器")
                        {
                            HBarCodeType = "唯一条码";
                        }
                        //
                        HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        HAuxPropID = ClsPub.isLong(grdSub.Rows[i].Cells[HAuxPropID2Col].Value);
                        HUnitID = ClsPub.isLong(grdSub.Rows[i].Cells[HUnitID2Col].Value);
                        HQty2 = ClsPub.isDoule(grdSub.Rows[i].Cells[HQty2Col].Value);
                        HBatchNo2 = ClsPub.isStrNull(grdSub.Rows[i].Cells[HBatchNo2Col].Value);
                        HSourceInterID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceInterID2Col].Value);
                        HSourceEntryID = ClsPub.isLong(grdSub.Rows[i].Cells[HSourceEntryID2Col].Value);
                        HSourceBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillNo2Col].Value);
                        HSourceBillType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceBillType2Col].Value);
                        HBarcodeQtys = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeQtysCol].Value);
                        HBarcodeNo = ClsPub.isLong(grdSub.Rows[i].Cells[HBarcodeNoCol].Value);
                        HSupID = ClsPub.isLong(grdSub.Rows[i].Cells[HSupID2Col].Value);
                        HDeptID = ClsPub.isLong(grdSub.Rows[i].Cells[HDeptID2Col].Value);
                        HWhID = ClsPub.isLong(grdSub.Rows[i].Cells[HWhID2Col].Value);
                        HSPID = ClsPub.isLong(grdSub.Rows[i].Cells[HSPID2Col].Value);
                        HRemark = ClsPub.isStrNull(grdSub.Rows[i].Cells[HRemark2Col].Value);
                        HMaterName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterName2Col].Value);
                        HMaterModel = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterModel2Col].Value);
                        HPinfan = ClsPub.isStrNull(grdSub.Rows[i].Cells[HPinfan2Col].Value);
                        HMTONo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMTONo2Col].Value);
                        HCusID = ClsPub.isLong(grdSub.Rows[i].Cells[HCusID2Col].Value);
                        HCusType = ClsPub.isStrNull(grdSub.Rows[i].Cells[HCusType2Col].Value);
                        HEndDate = ClsPub.isDate(grdSub.Rows[i].Cells[HEndDate2Col].Value);
                        HWorkLineName = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSourceName2Col].Value);
                        HSeOrderBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value);
                        HInnerBillNo = ClsPub.isStrNull(grdSub.Rows[i].Cells[HInnerBillNo2Col].Value);
                        HGiveAwayFlag = ClsPub.isBool(grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value);
                        oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                                    ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                    ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " +
                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID " +
                                    ",HGiveAwayFlag " +
                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
                                    + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'"
                                    + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                                    + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + sDate + "'"
                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString()
                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag)
                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
                        //HNumber = ClsPub.isStrNull(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        //if (cmbHBarCodeType.Text == "唯一条码")
                        //{
                        //    if (CampanyName == "卓力") //系统参数  å®¢æˆ·å®šåˆ¶åŒ–名称
                        //    {
                        //        //条码前缀 = ç‰©æ–™ä»£ç  + å¹´ + æœˆ + æ—¥
                        //        sTMNumber = HNumber + sYear + sPeriod + sDay;
                        //    }
                        //    else if (CampanyName == "飞龙")
                        //    {
                        //        string HWorksNumber = "";
                        //        HWorksNumber = cmbHWorksNumber.Text;
                        //        if (HWorksNumber == "")
                        //        {
                        //            MessageBox.Show("工厂代码不能为空!");
                        //            return;
                        //        }
                        //        //条码前缀 = å·¥åŽ‚ä»£ç  + ç‰©æ–™å†…码 + æ—¥æœŸ
                        //        sTMNumber = HWorksNumber + HNumber + sYear + sPeriod + sDay;
                        //    }
                        //    else  //通用方法
                        //    {
                        //        //条码前缀 = ç»„织代码 + ç‰©æ–™ä»£ç  + å¹´ + æœˆ + æ—¥
                        //        sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay;
                        //    }
                        //}
                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    }
                }
                //增加 æ¡ç è¶…过未生成功能控制
                //
                oCn.Commit();
                MessageBox.Show("条码生成完毕!");
                //grdSub.RowCount = 0;
                tabControl1.SelectedIndex = 1;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                MessageBox.Show("条码生成失败!" + e.Message);
                grdSub.RowCount = 0;
            }
        }
        ////月份转化
        //private string Sub_PeriodChange(string sPeriod)
        //{
        //    if(sPeriod=="10")
        //    {
        //        return "A";
        //    }
        //    else if (sPeriod == "11")
        //    {
        //        return "B";
        //    }
        //    else if (sPeriod == "12")
        //    {
        //        return "C";
        //    }
        //    else
        //    {
        //        return sPeriod.Substring(1, 1);
        //    }
        //}
        //生成条码 åšæ—¥
        //物料编码+序列号+生产日期
        private void SaveBarCode_bori()
        {
            grdSub.Rows.Clear();
            int LSHlen = 6;             //流水号长度
            int SumLen = 10;            //总长度
            string TM = "";             //条码
            string HNumber = "";        //物料内码
            string HMaterNumber = "";   //物料代码
            double HSumQty = 0;         //产品数量
            double HMinQty = 0;         //最小包装数
            int HBQty = 0;              //箱数
            double HQty = 0;            //数量
            string WeiShu = "";         //尾数
            //int LSH = 0;                //流水号
            string LSH2 = "";           //流水号转换成字符
            string sDate = "";          //日期
            string sYear = "";          //å¹´
            string sPeriod = "";        //月
            string sDay = "";           //日
            string HBatchNo = "";       //批次
            int k = 0;
            int n = 0;                  //同一批生成条码中的第几条
            string sTMNumber = "";      //条码自定义前缀
            DataSet Ds;
            //Ds = oCn.RunProcReturn("exec GetLSH '" + ClsPub.GetServerDate(0) + "'", "GetLSH");
            //LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0)
                {
                    HNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value);
                    HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value);
                    HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value);
                    //日期获取方式
                    sDate = dtpHDate.Value.ToShortDateString();
                    //
                    if (cmbHBarCodeType.Text == "试剂成品条码规则")// å¤±æ•ˆæ—¥æœŸï¼ˆç”Ÿäº§è®¢å•)
                    {
                        sDate = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEndDateCol].Value);
                    }
                    //
                    sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
                    sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
                    sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
                    sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
                    sDay = sDay.Substring(sDay.Length - 2, 2);
                    //==================================
                    //if (cmbHBarCodeType.Text == "试剂成品条码规则")
                    //{
                    //    //条码前缀 = ç»„织代码 + ç‰©æ–™ä»£ç  + å¹´ + æœˆ + æ—¥
                    //sTMNumber = HMaterNumber + HNumber + sYear + sPeriod + sDay;
                    //    Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                    //    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    //    LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                    //}
                    //else
                    //{
                    //    MessageBox.Show("错误的条码类型,不能生成条码!");
                    //    return;
                    //}
                    HBQty = HBQty + ClsPub.isInt(grdMain.Rows[j].Cells[HBQtyCol].Value);
                    HMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value);
                    HSumQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HQtyCol].Value);
                    n = 0;
                    //从金蝶序列号表获取序列号
                    DataSet DSet = oCn.RunProcReturn("exec h_p_CLD_GetBarCodeSno  "+ ClsPub.isStrNull(grdMain.Rows[j].Cells[HMainIDCol].Value) + "," + ClsPub.isStrNull(grdMain.Rows[j].Cells[HSubIDCol].Value) + "  ", "h_p_CLD_GetBarCodeSno", ref DBUtility.ClsPub.sExeReturnInfo);
                    //生成首行标题
                    if (DSet == null)
                    {
                        MessageBox.Show("没有返回任何结果,金蝶云序列号不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                        continue;
                    }
                    //
                    for (int i = k; i < DSet.Tables[0].Rows.Count; i++)
                    //for (int i = k; i < HBQty; i++)
                    {
                        if (HSumQty - HMinQty > 0)
                        {
                            WeiShu = "";
                            HSumQty = HSumQty - HMinQty;
                        }
                        else
                        {
                            if (HSumQty == HMinQty)
                            {
                                WeiShu = "";
                            }
                            else
                            {
                                WeiShu = "尾数";
                            }
                            HMinQty = HSumQty;
                        }
                        //
                        //LSH = LSH + 1;
                        LSH2 =DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[n]["SHNO"]);
                        //while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                        //{
                        //    LSH2 = "0" + LSH2;
                        //}
                        //if (cmbHBarCodeType.Text == "唯一条码")
                        //{
                            //条码编号 = æ¡ç å‰ç¼€ + æµæ°´å·
                            //T/*M*/ = HMaterNumber + LSH2 + sYear + sPeriod + sDay;
                        TM =  LSH2 + sYear + sPeriod + sDay;
                        //}
                        if (i + 1 > grdSub.Rows.Count)
                        {
                            grdSub.RowCount = grdSub.RowCount + 1;
                        }
                        grdSub.Rows[i].Cells[HSno2Col].Value = ClsPub.isStrNull(i + 1);
                        if (TM.Trim() == "")
                        {
                            MessageBox.Show("条形码不能为空,不能生成条码!");
                            return;
                        }
                        grdSub.Rows[i].Cells[HTMCol].Value = TM;
                        grdSub.Rows[i].Cells[HMaterID2Col].Value = grdMain.Rows[j].Cells[HMaterIDCol].Value;
                        grdSub.Rows[i].Cells[HMaterNumber2Col].Value = grdMain.Rows[j].Cells[HMaterNumberCol].Value;
                        grdSub.Rows[i].Cells[HMaterName2Col].Value = grdMain.Rows[j].Cells[HMaterNameCol].Value;
                        grdSub.Rows[i].Cells[HMaterModel2Col].Value = grdMain.Rows[j].Cells[HMaterModelCol].Value;
                        grdSub.Rows[i].Cells[HPinfan2Col].Value = grdMain.Rows[j].Cells[HPinfanCol].Value;
                        grdSub.Rows[i].Cells[HPinfanBarCode2Col].Value = grdMain.Rows[j].Cells[HPinfanBarCodeCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropID2Col].Value = grdMain.Rows[j].Cells[HAuxPropIDCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropNumber2Col].Value = grdMain.Rows[j].Cells[HAuxPropNumberCol].Value;
                        grdSub.Rows[i].Cells[HAuxPropName2Col].Value = grdMain.Rows[j].Cells[HAuxPropNameCol].Value;
                        grdSub.Rows[i].Cells[HUnitID2Col].Value = grdMain.Rows[j].Cells[HUnitIDCol].Value;
                        grdSub.Rows[i].Cells[HUnitNumber2Col].Value = grdMain.Rows[j].Cells[HUnitNumberCol].Value;
                        grdSub.Rows[i].Cells[HUnitName2Col].Value = grdMain.Rows[j].Cells[HUnitNameCol].Value;
                        grdSub.Rows[i].Cells[HQty2Col].Value = HMinQty;
                        grdSub.Rows[i].Cells[HBatchNo2Col].Value = grdMain.Rows[j].Cells[HBatchNoCol].Value;
                        grdSub.Rows[i].Cells[HSourceInterID2Col].Value = grdMain.Rows[j].Cells[HMainIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceEntryID2Col].Value = grdMain.Rows[j].Cells[HSubIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceBillNo2Col].Value = grdMain.Rows[j].Cells[HBillNoCol].Value;
                        grdSub.Rows[i].Cells[HSourceBillType2Col].Value = grdMain.Rows[j].Cells[HBillTypeCol].Value;
                        grdSub.Rows[i].Cells[HPrintCol].Value = "0";
                        grdSub.Rows[i].Cells[HWeiCol].Value = WeiShu;
                        grdSub.Rows[i].Cells[HBarcodeNoCol].Value = n + 1;
                        grdSub.Rows[i].Cells[HBarcodeQtysCol].Value = grdMain.Rows[j].Cells[HBQtyCol].Value;
                        grdSub.Rows[i].Cells[HSupID2Col].Value = grdMain.Rows[j].Cells[HSupIDCol].Value;
                        grdSub.Rows[i].Cells[HSupNumber2Col].Value = grdMain.Rows[j].Cells[HSupNumberCol].Value;
                        grdSub.Rows[i].Cells[HSupName2Col].Value = grdMain.Rows[j].Cells[HSupNameCol].Value;
                        grdSub.Rows[i].Cells[HDeptID2Col].Value = grdMain.Rows[j].Cells[HDeptIDCol].Value;
                        grdSub.Rows[i].Cells[HDeptNumber2Col].Value = grdMain.Rows[j].Cells[HDeptNumberCol].Value;
                        grdSub.Rows[i].Cells[HDeptName2Col].Value = grdMain.Rows[j].Cells[HDeptNameCol].Value;
                        grdSub.Rows[i].Cells[HRemark2Col].Value = grdMain.Rows[j].Cells[HRemarkCol].Value;
                        grdSub.Rows[i].Cells[HDate2Col].Value = grdMain.Rows[j].Cells[HDateCol].Value;
                        grdSub.Rows[i].Cells[HShowDate2Col].Value = grdMain.Rows[j].Cells[HShowDateCol].Value;
                        grdSub.Rows[i].Cells[HWhID2Col].Value = grdMain.Rows[j].Cells[HWhIDCol].Value;
                        grdSub.Rows[i].Cells[HWhNumber2Col].Value = grdMain.Rows[j].Cells[HWhNumberCol].Value;
                        grdSub.Rows[i].Cells[HWhName2Col].Value = grdMain.Rows[j].Cells[HWhNameCol].Value;
                        grdSub.Rows[i].Cells[HSPID2Col].Value = grdMain.Rows[j].Cells[HSPIDCol].Value;
                        grdSub.Rows[i].Cells[HSPNumber2Col].Value = grdMain.Rows[j].Cells[HSPNumberCol].Value;
                        grdSub.Rows[i].Cells[HSPName2Col].Value = grdMain.Rows[j].Cells[HSPNameCol].Value;
                        grdSub.Rows[i].Cells[HMTONo2Col].Value = grdMain.Rows[j].Cells[HMTONoCol].Value;
                        grdSub.Rows[i].Cells[HCusID2Col].Value = grdMain.Rows[j].Cells[HCusIDCol].Value;
                        grdSub.Rows[i].Cells[HCusNumber2Col].Value = grdMain.Rows[j].Cells[HCusNumberCol].Value;
                        grdSub.Rows[i].Cells[HCusName2Col].Value = grdMain.Rows[j].Cells[HCusNameCol].Value;
                        grdSub.Rows[i].Cells[HCusType2Col].Value = grdMain.Rows[j].Cells[HCusTypeCol].Value;
                        grdSub.Rows[i].Cells[HSourceID2Col].Value = grdMain.Rows[j].Cells[HSourceIDCol].Value;
                        grdSub.Rows[i].Cells[HSourceNumber2Col].Value = grdMain.Rows[j].Cells[HSourceNumberCol].Value;
                        grdSub.Rows[i].Cells[HSourceName2Col].Value = grdMain.Rows[j].Cells[HSourceNameCol].Value;
                        grdSub.Rows[i].Cells[HEndDate2Col].Value = grdMain.Rows[j].Cells[HEndDateCol].Value;
                        grdSub.Rows[i].Cells[HSeOrderBillNo2Col].Value = grdMain.Rows[j].Cells[HSeOrderBillNoCol].Value;
                        grdSub.Rows[i].Cells[HInnerBillNo2Col].Value = grdMain.Rows[j].Cells[HInnerBillNoCol].Value;
                        grdSub.Rows[i].Cells[HMaker2Col].Value = grdMain.Rows[j].Cells[HMakerCol].Value;
                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value = grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value;
                        //网格打勾
                        DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell();
                        oCell.ThreeState = false;
                        oCell.Value = grdSub.Rows[i].Cells[HGiveAwayFlag2Col].Value;
                        oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        grdSub.Rows[i].Cells[HGiveAwayFlag2Col] = oCell;
                        k = k + 1;
                        n = n + 1;
                        //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                    }
                }
            }
            string HWei = "";      //尾数
            string HBarCode = "";
            string HBarCodeType = "";
            Int64 HMaterID = 0;
            Int64 HAuxPropID = 0;
            Int64 HUnitID = 0;
            double HQty2 = 0;
            string HBatchNo2 = "";
            Int64 HSupID = 0;
            Int64 HGroupID = 0;
            int HPrintQty = 0;
            Int64 HSourceInterID = 0;
            Int64 HSourceEntryID = 0;
            string HSourceBillNo = "";
            string HSourceBillType = "";
            Int64 HBarcodeNo = 0;       //托号
            Int64 HBarcodeQtys = 0;     //总托数
            Int64 HDeptID = 0;
            Int64 HWhID = 0;
            Int64 HSPID = 0;
            string HRemark = "";
            string HMaterName = "";
            string HMaterModel = "";
            string HPinfan = "";
            string HMTONo = "";
            Int64 HCusID = 0;
            string HCusType = "";
            DateTime HEndDate;
            string HWorkLineName = "";
            string HSeOrderBillNo = "";
            string HInnerBillNo = "";
            bool HGiveAwayFlag = false;
            try
            {
                oCn.BeginTran();
                for (int i = 0; i < grdSub.Rows.Count; i++)
                {
                    if (ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value) != 0)
                    {
                        HWei = ClsPub.isStrNull(grdSub.Rows[i].Cells[HWeiCol].Value);
                        HBarCode = ClsPub.isStrNull(grdSub.Rows[i].Cells[HTMCol].Value);
                        //
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        if (CampanyName == "博日科技" || CampanyName == "夏宝电器")
                        {
                            HBarCodeType = "唯一条码";
                        }
                        //
                        HMaterID = ClsPub.isLong(grdSub.Rows[i].Cells[HMaterID2Col].Value);
                        HAuxPropID = ClsPub.isLong(grdSub.Rows[i].Cells[HAuxPropID2Col].Value);
                        HUnitID = ClsPub.isLong(grdSub.Rows[i].Cells[HUnitID2Col].Value);
@@ -1841,8 +2325,9 @@
            grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString();
            grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HSourceBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString(); //博日 æ”¶æ–™å•据日期
            grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
            grdMain.Rows[i].Cells[HSupIDCol].Value = oTable.Rows[0]["hsupid"].ToString();
            grdMain.Rows[i].Cells[HSupNumberCol].Value = oTable.Rows[0]["供应商代码"].ToString();
@@ -1865,13 +2350,21 @@
            grdMain.Rows[i].Cells[HCusNumberCol].Value = oTable.Rows[0]["客户代码"].ToString();
            grdMain.Rows[i].Cells[HCusNameCol].Value = oTable.Rows[0]["客户"].ToString();
            grdMain.Rows[i].Cells[HCusTypeCol].Value = oTable.Rows[0]["客户型号"].ToString();
            grdMain.Rows[i].Cells[HPinfanBarCodeCol].Value = oTable.Rows[0]["HPinfanBarCode"].ToString();
            grdMain.Rows[i].Cells[HPinfanCol].Value = oTable.Rows[0]["HPinfan"].ToString();
            //grdMain.Rows[i].Cells[HSourceIDCol].Value = oTable.Rows[0]["HSourceID"].ToString();
            //grdMain.Rows[i].Cells[HSourceNumberCol].Value = oTable.Rows[0]["生产线代码"].ToString();
            grdMain.Rows[i].Cells[HSourceNameCol].Value = oTable.Rows[0]["生产线"].ToString();
            grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["计划完工日期"].ToString();
            if (cmbHBarCodeType.Text == "批次条码" && CampanyName == "博日科技")
            grdMain.Rows[i].Cells[HEndDateCol].Value = oTable.Rows[0]["计划完工日期"].ToString();//博日 ç”Ÿäº§è®¢å• å¤±æ•ˆæ—¥æœŸ
            if (cmbHBarCodeType.Text == "仪器外购件条码容器规则" )
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            }
            else if (cmbHBarCodeType.Text == "仪器外购件条码普通规则"
                || cmbHBarCodeType.Text == "仪器成品条码规则"
                || cmbHBarCodeType.Text == "试剂成品条码规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
            }
            else
            {
@@ -1910,7 +2403,7 @@
            grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString();
            grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString();
            grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString();
            grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[0]["日期"].ToString(); //博日 å•据日期
            grdMain.Rows[i].Cells[HShowDateCol].Value = dtpHDate.Value.ToShortDateString();
            grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString();
            grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString();
@@ -1926,9 +2419,13 @@
            grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString();
            grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString();
            grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString();
            if (cmbHBarCodeType.Text == "批次条码" && CampanyName == "博日科技")
            if (cmbHBarCodeType.Text == "仪器外购件条码容器规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]);
            }
            else if (cmbHBarCodeType.Text == "仪器外购件条码普通规则")
            {
                grdMain.Rows[i].Cells[HMinQtyCol].Value = "1";
            }
            else
            {
@@ -2257,6 +2754,26 @@
            for (int i = 0; i < grdList.Rows.Count; i++)
            {
                grdList.Rows[i].Cells[0].Value = "*";
            }
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
            Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
        }
        private void Sub_SetReportView(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdList.Rows.Count; i++)
            {
                grdList.Rows[i].Cells[0].Value = "";
            }
            for (int i = 0; i < grdList.SelectedRows.Count; i++)
            {
                grdList.Rows[grdList.SelectedRows[i].Index].Cells[0].Value = "*";
            }
            //
            Report = new GridppReport();
@@ -2664,10 +3181,32 @@
            }
        }
        private void sdy_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdSub.Rows[0].Cells[HTMCol].Value) == "")
            {
                MessageBox.Show("条码未生成,请先生成条码后再预览!");
                return;
            }
            //打印前判断条码是否已打印过
            if (ReportPrintBegin())
            {
                return;
            }
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                Sub_SetReportView(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
    }
}