ch
2022-05-30 f9ef44a67fbf73f073efe65600bc25e204fde04f
WarM/ÌõÂë´òÓ¡/Sc_ICMOToBarCode.cs
@@ -28,57 +28,131 @@
        public const string ModRightNameCheck = ModRightName + "_Check";
        public const string ModRightNameClose = ModRightName + "_Close";
        public const string ModRightNameDelete = ModRightName + "_Delete";
        public DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        //DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill();
        //public  Gy_ICBomBill oFrm;
        public int selectRow = 0;
        public int selectRow2 = 0;
        public string sDlgWhere = "";  //外窗体递入
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        public Int64 HInterID = 0;
        public const string ModName1 = "3783";
        public Int64 HInterID_TTM = 0;
        public string HBillNo_TTM = "";
        ClsCN SubCn = new ClsCN();
        //
        private void initGrid()
        {
            DBUtility.Xt_BaseBillFun.initGridList(grdMain,this.Name);
            DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name);
        }
        //
        private void Display()
        {
            ClsCN SubCn = new ClsCN();
            DataSet DSet;
            string sSql = "";
            string sFastSQL = "";
            //生产订单号
            //if (txtHICMOBillNo.Text.Trim() != "")
            //{
            //    sFastSQL = sFastSQL + " and HICMOBillNo  like '%" + txtHICMOBillNo.Text + "%'";
            //}
            string HICMOBillNo = "";
            HICMOBillNo = txtHICMOBillNo.Text.Trim().ToString();
            //销售订单号
            string HSeOrderBillNo = "";
            HICMOBillNo = txtHSeOrderBillNo.Text.Trim().ToString();
            //物料
            //if (txtHMaterID.Text.Trim() != "")
            //{
            //    sFastSQL = sFastSQL + " and HMaterName  like '%" + txtHMaterID.Text + "%'";
            //}
            string HMaterName = "";
            HMaterName = txtHMaterID.Text.Trim().ToString(); //物料代码
            //机台
            //if (txtHSourceID.Text.Trim() != "")
            //{
            //    sFastSQL = sFastSQL + " and HSourceName  like '%" + txtHSourceID.Text + "%'";
            //}
            string HSourceName = "";
            HSourceName = txtHSourceID.Text.Trim().ToString();
            //职员
            string HEmpName = "";
            HEmpName = txtHEmpID.Text.Trim().ToString();
            //判断开始日期
            //if (dtpHBeginDate.Checked)
            //{
            //    sFastSQL = sFastSQL + " and æ—¥æœŸ>='" + dtpHBeginDate.Value.ToShortDateString() + "'";
            //}
            string HBeginDate = "";
            HBeginDate = dtpHBeginDate.Value.ToShortDateString();
            //判断结束日期
            //if (dtpHEndDate.Checked)
            //{
            //    sFastSQL = sFastSQL + " and æ—¥æœŸ<='" + dtpHEndDate.Value.ToShortDateString() + "'";
            //}
            //string HEndDate = "";
            //HEndDate = dtpHEndDate.Value.ToShortDateString();
            //if (sFastSQL.Trim() == "")
            //{
            //    MessageBox.Show("没有输入条件!");
            //    return;
            //}
            //过滤条件
            if (frmCondition.SqlStr.Trim().Length == 0)
                return;
            sSql = "Select * from " + ViewName + " Where 1=1 "  + sDlgWhere + " order by HICMOBillNo asc";
            //
            DSet = SubCn.RunProcReturn(sSql, ViewName, ref DBUtility.ClsPub.sExeReturnInfo);
            DSet = SubCn.RunProcReturn("exec h_p_KSTMSC '" + HSeOrderBillNo + "' ,'" + HICMOBillNo + "' , '" + HMaterName + "' , '" + HSourceName + "' ,'" + HEmpName + "' ,'" + HBeginDate + "'", "h_p_KSTMSC", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
                //if (DSet == null|| DSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdMain.DataSource = DSet.Tables[0].DefaultView;
            //标准装箱
            for (int i = 0; i < grdMain.SelectedRows.Count; i++)
            else
            {
                txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[Fun_GetCol("HMiniQty")].Value);
                grdMain.DataSource = DSet.Tables[0].DefaultView;
                //把当前单据ID å­˜åˆ°ä¸€ä¸ªæŒ‰é’®é‡Œé¢   åˆ·æ–°æ—¶æ¯æ¬¡å­˜ä¸€é
                if (DSet.Tables[0].Rows.Count > 0)
                {
                    txtHMaterID.Tag = DBUtility.ClsPub.isInt(grdMain.Rows[0].Cells["HInterID"].Value);
                    txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["标准装箱"].Value);
                }
                else
                {
                }
            }
            //
            //标准装箱
            //for (int i = 0; i < grdMain.SelectedRows.Count; i++)
            //{
            //    txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[Fun_GetCol("HMiniQty")].Value);
            //    if (txtHMiniQty.Text.Trim() != "")
            //    {
            //        txtHMiniQty.Enabled = false;
            //    }
            //}
            //冻结
            int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            string s = frmCondition.cmbHComplete.Text;
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s,FrCol);
            //int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            //string s = frmCondition.cmbHComplete.Text;
            //DBUtility.Xt_BaseBillFun.DisplayGrid(grdMain, this.Name, s,FrCol);
            //画线
            GraphLine();
            // 
        }
        //
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled=false;
            timer1.Enabled = false;
            initGrid();
            Display();
        }
@@ -132,14 +206,53 @@
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
        private Int32 Fun_GetColList(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList);
        }
        //
        private void Sc_ICMOToBarCode_Load(object sender, EventArgs e)
        {
            //
            frmCondition = new frmBillQueryCondition_New();
            //frmCondition = new frmBillQueryCondition_New();
            this.Text = ModCaption;
            //lblCaption.Text = ModCaption;
            initGrid();
            cmbHBarCodeType.SelectedIndex = 0;
            dtpHBeginDate.Value = DateTime.Today;
            string HUserName = "";
            HUserName = ClsPub.isStrNull(DBUtility.ClsPub.CurUserName);
            Int64 HUserID = 0;
            HUserID = ClsPub.isInt(DBUtility.ClsPub.CurUserID);
            DataSet DSet;
            DSet = oCn.RunProcReturn("Select HEmpID from gy_czygl Where czymc='" + HUserName + "'", "gy_czygl", ref DBUtility.ClsPub.sExeReturnInfo);
            if (DSet == null)
            //if (DSet == null|| DSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            else
            {
                //grdMain.DataSource = DSet.Tables[0].DefaultView;
                //把当前单据ID å­˜åˆ°ä¸€ä¸ªæŒ‰é’®é‡Œé¢   åˆ·æ–°æ—¶æ¯æ¬¡å­˜ä¸€é
                if (DSet.Tables[0].Rows.Count > 0)
                {
                    txtHEmpID.Tag = DBUtility.ClsPub.isStrNull(DSet.Tables[0].Rows[0]["HEmpID"]);
                }
                else
                {
                }
            }
        }
        private void grdMain_DblClick(object sender, EventArgs e)
@@ -149,21 +262,21 @@
        private void cx_Click(object sender, EventArgs e)
        {
            frmCondition = new frmBillQueryCondition_New();
            SetCondition(frmCondition, ViewName, this.Name);
            frmCondition.ShowDialog();
            if (frmCondition.Tag.ToString() == "OK")
            {
                Display();
            }
            //frmCondition = new frmBillQueryCondition_New();
            //SetCondition(frmCondition, ViewName, this.Name);
            //frmCondition.ShowDialog();
            //if (frmCondition.Tag.ToString() == "OK")
            //{
            //    Display();
            //}
        }
        public void SetCondition(frmBillQueryCondition_New frmCondition, string ViewName, string Name)
        {
            frmCondition.Tag = "";
            frmCondition.ViewName = ViewName;
            frmCondition.ModName = Name;
        }
        //public void SetCondition(frmBillQueryCondition_New frmCondition, string ViewName, string Name)
        //{
        //    frmCondition.Tag = "";
        //    frmCondition.ViewName = ViewName;
        //    frmCondition.ModName = Name;
        //}
        private void xz_Click(object sender, EventArgs e)
        {
@@ -179,7 +292,7 @@
        //删除
        private void Sub_DeleteBill()
        {
        //    //编辑权限
            //    //编辑权限
            if (!DBUtility.ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
@@ -257,17 +370,17 @@
        private void timer2_Tick(object sender, EventArgs e)
        {
            timer2.Enabled = false;
            frmCondition = new frmBillQueryCondition_New();
            SetCondition(frmCondition, ViewName, this.Name);
            frmCondition.ShowDialog();
            if (frmCondition.Tag.ToString() == "OK")
            {
                timer1.Enabled = true;
            }
            //timer2.Enabled = false;
            //frmCondition = new frmBillQueryCondition_New();
            //SetCondition(frmCondition, ViewName, this.Name);
            //frmCondition.ShowDialog();
            //if (frmCondition.Tag.ToString() == "OK")
            //{
            //    timer1.Enabled = true;
            //}
        }
        private void bclk_Click(object sender, EventArgs e)
        {
@@ -282,11 +395,11 @@
        // 
        private void GraphLine()
        {
            int MainIDCol = Fun_GetCol("hmainid");
            int SubIDCol = Fun_GetCol("hsubid");
            string s = frmCondition.cmbHComplete.Text;
            long n=0;
            DBUtility.Xt_BaseBillFun.GraphLine(grdMain, MainIDCol, SubIDCol, s,ref n);
            //int MainIDCol = Fun_GetCol("hmainid");
            //int SubIDCol = Fun_GetCol("hsubid");
            //string s = frmCondition.cmbHComplete.Text;
            //long n=0;
            //DBUtility.Xt_BaseBillFun.GraphLine(grdMain, MainIDCol, SubIDCol, s,ref n);
            //显示
            //lbldj.Text = "查询出 " + n.ToString() + " å¼ å•据";
            //lbljl.Text = "共有 " + grdMain.RowCount.ToString() + " æ¡è®°å½•";
@@ -301,7 +414,7 @@
        private void Sub_CheckBill()
        {
            //审核权限
            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true,DBUtility.ClsPub.CurUserName))
            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
@@ -312,7 +425,7 @@
            lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value);
            if (lngBillKey == 0)
                return;
            DAL.ClsGy_ICBomBill  oBill = new DAL.ClsGy_ICBomBill();
            DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill();
            //查看是否已审核,关闭,作废
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
            {
@@ -343,7 +456,7 @@
        private void Sub_AbandonCheck()
        {
            //审核权限
            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true,DBUtility.ClsPub.CurUserName))
            if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
@@ -354,7 +467,7 @@
            lngBillKey = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.CurrentRow.Index].Cells[Fun_GetCol("hmainid")].Value);
            if (lngBillKey == 0)
                return;
            DAL.ClsGy_ICBomBill  oBill = new DAL.ClsGy_ICBomBill();
            DAL.ClsGy_ICBomBill oBill = new DAL.ClsGy_ICBomBill();
            //查看是否已审核,关闭,作废
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
            {
@@ -416,14 +529,14 @@
        private void Sub_SetReport(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                grdMain.Rows[i].Cells[0].Value = "";
            }
            for (int i = 0; i < grdMain.SelectedRows.Count; i++)
            {
                grdMain.Rows[grdMain.SelectedRows[i].Index].Cells[0].Value = "*";
            }
            //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[grdMain.SelectedRows[i].Index].Cells[0].Value = "*";
            //}
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
@@ -463,7 +576,7 @@
            try
            {
                DataTable ds = new DataTable();
                BLL.Utility.FillRecordToReport_Sel(Report, grdMain, ds, Fun_GetCol("选择"));
                BLL.Utility.FillRecordToReport_Sel(Report, grdList, ds, Fun_GetCol("选择"));
            }
            catch (Exception e)
            {
@@ -635,98 +748,1300 @@
            }
        }
        private void zf_Click(object sender, EventArgs e)
        {
            //Sub_AbandonCheck();
            if (!ClsPub.Security_Log(ModRightNameDelete, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            if (grdMain.CurrentRow == null)
                return;
            DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
            if (MessageBox.Show("确定要作废所选条码?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }
            for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
            {
                if (DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("HMaterID")].Value) != 0)
                {
                    if (!oBar.Cancelltion(DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value)))
                    {
                        MessageBox.Show("作废失败!", "提示");
                        return;
                    }
                }
            }
            MessageBox.Show("作废成功!", "提示");
        }
        private void fzf_Click(object sender, EventArgs e)
        {
            //this.Sub_CheckBill();
            if (!ClsPub.Security_Log(ModRightNameDelete, 1, true, DBUtility.ClsPub.CurUserName))
            {
                return;
            }
            if (grdMain.CurrentRow == null)
                return;
            DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
            if (MessageBox.Show("确定要反作废所选条码?", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }
            for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
            {
                if (DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("HMaterID")].Value) != 0)
                {
                    if (!oBar.UnCancelltion(DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value)))
                    {
                        MessageBox.Show("反作废失败!", "提示");
                        return;
                    }
                }
            }
            MessageBox.Show("反作废成功!", "提示");
        }
        private void cmdHSaveBill_Click(object sender, EventArgs e)
        {
            string sFastSQL = "";
            //生产订单号
            if (txtHICMOBillNo.Text.Trim() != "")
            Display();
        }
        string TTM = "";            //托条码
        string HTTMNumber = "";
        string HICMOBillNo = "";    //生产订单号
        int TLSH = 0;
        string TLSH2 = "";
        string HOrgNumber = "";
        //=======生成 å”¯ä¸€ç  å’Œ æ‰˜æ¡ç  ã€ç»„托单
        private void Sub_SaveBarCode()//分配时 è¦è€ƒè™‘ è®¢å•剩余数量已经是 è´Ÿæ•°çš„æƒ…况
        {
            try
            {
                sFastSQL = sFastSQL + " and HICMOBillNo  like '%" + txtHICMOBillNo.Text + "%'";
                string HMaterNumber = "";
                string HBatchNo = "";
                string HDate = "";
                string HYear = "";
                string HPeriod = "";
                string HDay = "";
                string HTMNumber = "";
                string HOrgNumber = "";
                DataSet Ds;
                int LSH = 0;                //流水号
                string LSH2 = "";           //流水号转换成字符
                double HZXQty = 0;         //装箱数量
                double HDDQty = 0;         //订单数量
                double HBQty = 0;         //箱数
                int k = 0;
                int n = 0;                  //同一批生成条码中的第几条
                string WeiShu = "";         //尾数
                int LSHlen = 6;             //流水号长度
                string TM = "";             //条码
                HDate = dtpHBeginDate.Value.ToShortDateString();
                HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2);
                HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString();
                HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2);
                HDay = "0" + ClsPub.isDate(HDate).Day.ToString();
                HDay = HDay.Substring(HDay.Length - 2, 2);
                //=============根据界面上已经分配的数据进行条码生成和打印。
                //获取本次生成的 ä¸»å†…码
                Int64 HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                Int64 HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo); //组托单内码
                string HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//组托单单号
                //0 å¼€å¯äº‹åŠ¡
                oCn.BeginTran();
                //00 å…ˆç”Ÿæˆ å”¯ä¸€çš„ æ‰˜æ¡ç 
                //生成一个外箱码
                string sPackStr = "ZXM" + HYear + HPeriod + HDay; //外箱码 å‰ç¼€
                DataSet  DsTM = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sPackStr + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号                                                                                          //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                Int64 TTM_LSH = ClsPub.isInt(DsTM.Tables[0].Rows[0][0]) + 1;
                string sPackBarCode = sPackStr + TTM_LSH.ToString();
                oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sPackStr + "'");
                //MessageBox.Show("11");
                oCn.RunProc("insert into Sc_PackUnionBillMain (HYear,HPeriod,HBillType,HInterID,HDate" +
                                   ",HBillNo,HBillStatus,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HWeight" +
                                   ",HPWeight,HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo " +
                                   ") values ("
                                   + HYear + "," + HPeriod + ",'3783'," + HInterID_TTM + ",'" + HDate + "'"
                                   + ", '" + sPackBarCode.ToString() + "',1,'','" + sPackBarCode.ToString() + "',0,0,0"
                                   + ",0,1,0,0,0,0,'','')");
                //MessageBox.Show("12");
                //1.循环网格,根据 æœ¬æ¬¡æ•°é‡ åˆ—  ç”Ÿæˆ å”¯ä¸€ç 
            for (int j = 0; j < grdMain.Rows.Count; j++)
                {
                    if (DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("本次数量")].Value) > 0)
                    {
                        HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料代码")].Value);
                        HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value);
                        HOrgNumber = ClsPub.HOrgNumber;
                        //HBQty = HBQty + ClsPub.isInt(txtHBQty.Text);
                        HZXQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("本次数量")].Value);
                        HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("生产订单数量")].Value);
                        HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value);
                        HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay;
                        Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        n = 0;
                        LSH2 = LSH.ToString();
                        while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                        {
                            LSH2 = "0" + LSH2;
                        }
                        //条码编号 = æ¡ç å‰ç¼€ + æµæ°´å·
                        TM = HTMNumber + LSH2;
                        if (TM.Trim() == "")
                        {
                            MessageBox.Show("条形码不能为空,不能生成条码!");
                            return;
                        }
                        string HWei = "";      //尾数
                        string HBarCode = "";
                        string HBarCodeType = "";
                        Int64 HMaterID1 = 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 = "";
                        Int64 HSourceID = 0;
                        //毛重
                        Double HMZQty = 0;
                        HMZQty = HZXQty * ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("克重")].Value)/1000;
                        HWei = WeiShu;
                        HBarCode = TM;
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value);
                        HAuxPropID = 0;
                        HUnitID = 0;
                        HQty2 = HZXQty;
                        HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value);
                        HSourceInterID = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HSourceInterID")].Value);
                        HSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HSourceEntryID")].Value);
                        HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value);
                        HSourceBillType = "3710";
                        HBarcodeQtys = 0;
                        HBarcodeNo = 0;
                        HSupID = 0;
                        HDeptID = 0;
                        HWhID = 0;
                        HSPID = 0;
                        HRemark = "";
                        HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料名称")].Value);
                        HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("规格型号")].Value);
                        HPinfan = "";
                        HMTONo = "";
                        HCusID = 0;
                        HCusType = "";
                        HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("日期")].Value);
                        HWorkLineName = "";
                        HSeOrderBillNo = "";
                        HInnerBillNo = sPackBarCode;
                        HSourceID = ClsPub.isInt(txtHSourceID.Tag);
                        oCn.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HMaterialMQty" +
                                            ",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,HSourceID,HInterID " +
                                            ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                            ") values ("
                                            + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString() + ", " + HMZQty.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 + "','" + HDate + "'"
                                            + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HSourceID.ToString() + "," + HInterID.ToString()
                                            + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
                        oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HTMNumber + "'");
                        DisplayTM();
                    }
                }
                //2.循环结束后,根据 æœ¬æ¬¡ç”Ÿæˆçš„ ä¸»å†…码,从后台数据库获取 æ¡ç åˆ—表,生成 ç»„托单 å’Œ æ‰˜æ¡ç ï¼Œ ç›´æŽ¥è°ƒç”¨å­˜å‚¨è¿‡ç¨‹
                 //根据外箱码 å†™å…¥ ç»„托单主表,组托单子表,SUM,外箱码档案,SUM档案
                oCn.RunProc("exec  h_p_WMS_PackUnionBill_AddNew  '" + sPackBarCode + "'," + HInterID_TTM.ToString() + ",'" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //根据箱条码,写入 ä¸»è¡¨ï¼Œå­è¡¨ ï¼Œç®±æ¡ç æ¡£æ¡ˆ
                oCn.RunProc("exec  h_p_WMS_PackUnionBill_SumSubBill  " + HInterID_TTM.ToString() + ",'" + sPackBarCode + "','3783','" + DBUtility.ClsPub.CurUserName + "'," + HInterID.ToString()); //根据箱条码,写入 SUM表,SUM条码档案
                sPackBarCode = "";
                DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList_CS Where HInterID=" + HInterID.ToString() + " and æ¡ç ç±»åž‹ = '托盘条码'", "h_v_IF_BarCodeBillList_CS", ref DBUtility.ClsPub.sExeReturnInfo);
                //生成首行标题
                if (DSet == null)
                {
                    MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                    return;
                }
                //
                grdList.DataSource = DSet.Tables[0].DefaultView;
                txtHZXQty.Text = "";
                //冻结
                int FrCol = 0;
                string s = "是";
                DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol);
                oCn.Commit();
                //DisplayTM();
                MessageBox.Show("条码生成完毕!");
                //0结束事务
                //
                //Display();
            }
            //物料
            if (txtHMaterID.Text.Trim() != "")
            catch (Exception e )
            {
                sFastSQL = sFastSQL + " and HMaterID  like '%" + txtHMaterID.Text + "%'";
                //回滚事务
                MessageBox.Show("生成条码失败!" + e.Message);
                Display();
            }
            //机台
            if (txtHSourceID.Text.Trim() != "")
        }
        private void button4_Click(object sender, EventArgs e)
        {
            //根据本箱数量 æ¥ åˆ†é…åˆ° æ¯ä¸ªç”Ÿäº§è®¢å•上(分配时 è¦è€ƒè™‘ è®¢å•剩余数量已经是 è´Ÿæ•°çš„æƒ…况)
            //如果有标准装箱数量 å…ˆé»˜è®¤å–标准装箱数量  æ²¡æœ‰å†å–手输的本箱数量
            //1.判断本箱数量 å¿…须大于0
            double HZXQty = 0;//整箱数量
            if (txtHZXQty.Text.Trim() != "")
            {
                sFastSQL = sFastSQL + " and HSourceID  like '%" + txtHSourceID.Text + "%'";
                HZXQty = ClsPub.isDoule(txtHZXQty.Text);
            }
            //判断开始日期
            if (dtpHBeginDate.Checked)
            else
            {
                sFastSQL = sFastSQL + " and æ—¥æœŸ>='" + dtpHBeginDate.Value.ToShortDateString() + "'";
                HZXQty = ClsPub.isDoule(txtHMiniQty.Text);
            }
            //判断结束日期
            if (dtpHEndDate.Checked)
            if (HZXQty <= 0)
            {
                sFastSQL = sFastSQL + " and æ—¥æœŸ<='" + dtpHEndDate.Value.ToShortDateString() + "'";
            }
            if (sFastSQL.Trim() == "")
            {
                MessageBox.Show("没有输入条件!");
                MessageBox.Show("请输入整箱数量!");
                return;
            }
            sDlgWhere = sFastSQL;
            Display();
            sDlgWhere = "";
            //2.刷新网格
            //Display();
            //3.把整箱数量 åˆ†é…åˆ° ç½‘格下面的每一个 ç”Ÿäº§è®¢å•上去。  å¾ªçŽ¯ç½‘æ ¼
            for(int i =0;i<grdMain.Rows.Count;i++)
            {
                if (HZXQty > 0)
                {
                    if (HZXQty > DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value))
                    {
                        HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                        grdMain.Rows[i].Cells["本次数量"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                        //MessageBox.Show("请点击超额生产按钮生成条码!");
                        //return;
                    }
                    else
                    {
                        grdMain.Rows[i].Cells["本次数量"].Value = HZXQty;
                        //
                        //HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                        //grdMain.Rows[i].Cells["本次数量"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                    }
                }
                else
                {
                    break;
                }
            }
            Sub_SaveBarCode();
            //
            ////1.获取界面上面整箱数量框输入的数量 èµ‹å€¼ç»™å˜é‡  å¹¶åˆ·æ–°ç½‘æ ¼
            //double HBarCodeQty = 0;
            //double HZXQty = 0;
            //HZXQty = ClsPub.isDoule(txtHZXQty.Text);
            //if (HZXQty ==0)
            //{
            //    MessageBox.Show("请输入整箱数量!");
            //    return;
            //}
            //Display();
            ////2.获取网格选中行物料ID
            ////int a = grdMain.CurrentRow.Index;
            ////long HMaterID = 0;
            //////HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[a].Cells[Fun_GetCol("HMaterID")].Value);
            ////    if (HMaterID == 0)
            ////    {
            ////        MessageBox.Show("没有选中任何记录!");
            ////        return;
            ////    }
            ////3.定义是否组托的变量
            //int Mul = 0;
            ////4.根据单据类型获取本次条码主内码HInterID
            //HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
            //for (int i = 0; i < grdMain.Rows.Count; i++)
            //{
            //    //获取网格里面每一行订单对应的订单数量
            //    double HDDQty = 0;
            //    HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("订单数量")].Value);
            //    //获取当前系统登陆组织代码
            //    HOrgNumber = ClsPub.HOrgNumber;
            //    //自动匹配逻辑  åˆ¤æ–­è®¢å•数量是否大于整箱数量   å¦‚果订单数量大于整箱数量  ç›´æŽ¥ç”Ÿæˆå”¯ä¸€ç 
            //    //如果订单数量小于整箱数量  åˆ™å¾ªçŽ¯ç”Ÿæˆå”¯ä¸€ç    ç”Ÿæˆå¯¹åº”的托条码
            //        if (HDDQty >= HZXQty)
            //        {
            //            HBarCodeQty = HZXQty;
            //            this.Sub_SaveBill_TTM();
            //            Display();
            //            Mul = Mul + 1;
            //            break;
            //        }
            //        else if(HDDQty < HZXQty)
            //        {
            //            HBarCodeQty = HDDQty;
            //            HZXQty = HZXQty - HDDQty;
            //            this.Sub_SaveBill_TTM();
            //            Mul = Mul + 1;
            //            continue;
            //        }
            //    //如果Mul>1 æ–°å¢žç»„托单主表
            //}
            //if (Mul > 1)
            //{
            //    //HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("生产订单号")].Value);
            //    DataSet DS1;
            //    HTTMNumber = HOrgNumber + HICMOBillNo;
            //    DS1 = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
            //    TLSH = ClsPub.isInt(DS1.Tables[0].Rows[0][0]);
            //    TLSH2 = TLSH.ToString();
            //    TTM = HTTMNumber + TLSH2;
            //    HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo);
            //    HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//得到新单号
            //    string HDate = "";
            //    string HYear = "";
            //    string HPeriod = "";
            //    string HDay = "";
            //    HDate = DateTime.Now.ToShortDateString();
            //    HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2);
            //    HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString();
            //    HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2);
            //    HDay = "0" + ClsPub.isDate(HDate).Day.ToString();
            //    HDay = HDay.Substring(HDay.Length - 2, 2);
            //    oCn.RunProc("insert into Sc_PackUnionBillMain (HYear,HPeriod,HBillType,HInterID,HDate" +
            //                       ",HBillNo,HBillStatus,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HWeight" +
            //                       ",HPWeight,HProdOrgID,HDeptID,HEmpID,HSNum,HPackNum,HBarCode_Cus,HBatchNo " +
            //                       ") values ("
            //                       + HYear + "," + HPeriod + ",'3783'," + HInterID_TTM + ",'" + HDate + "'"
            //                       + ", " + HBillNo_TTM.ToString() + ",1,''," + TTM.ToString() + ",0,0,0"
            //                       + ",0,1,0,0,0,0,'','')");
            //}
            ////3.先判断物料是否一致  å¦‚果一致开始循环网格
            //for (int i = 0; i < grdMain.Rows.Count; i++)
            //{
            //    //long HGrdMaterID = 0;
            //    //HGrdMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("HMaterID")].Value);
            //    //if (HGrdMaterID == HMaterID)
            //    //{
            //    //    double HDDQty = 0;
            //    //    HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("订单数量")].Value);
            //    //    //如果循环的该行记录的订单数量已经大于等于本次装箱数量  åˆ™ç›´æŽ¥ç”Ÿæˆå”¯ä¸€ç   å¹¶ä¸”刷新网格  åˆ·æ–°æ¡ç ä¿¡æ¯é¡µ
            //    //    if (HDDQty >= HZXQty)
            //    //    {
            //    //        double HBarCodeQty = 0;
            //    //        HBarCodeQty = HZXQty;
            //    //        this.Sub_SaveBill();
            //    //        Display();
            //    //    }
            //    //    //如果改行记录订单数量小于本次装箱数量 åˆ™ç»§ç»­å¾ªçޝ  èµ°ç”Ÿæˆæ‰˜æ¡ç æ–¹æ³•
            //    //    else
            //    //    {
            //    //        //查出符合条件的选中这条数量跟装箱数量的差异值
            //    //        double HCYQty = 0;
            //    //        HCYQty = HZXQty - DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.Rows[i].Index].Cells[Fun_GetCol("订单数量")].Value);
            //    //    }
            //    //}
            //    //else
            //    //{
            //    //}
            //}
        }
        private void Sub_SaveBill()
        {
            HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
            string HMaterNumber = "";
            string HBatchNo = "";
            string HDate = "";
            string HYear = "";
            string HPeriod = "";
            string HDay = "";
            string HTMNumber = "";
            string HOrgNumber = "";
            DataSet Ds;
            int LSH = 0;                //流水号
            string LSH2 = "";           //流水号转换成字符
            double HZXQty = 0;         //装箱数量
            double HDDQty = 0;         //订单数量
            double HBQty = 0;         //箱数
            int k = 0;
            int n = 0;                  //同一批生成条码中的第几条
            string WeiShu = "";         //尾数
            int LSHlen = 6;             //流水号长度
            string TM = "";             //条码
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料代码")].Value);
                HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value);
                HDate = DateTime.Now.ToShortDateString();
                HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2);
                HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString();
                HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2);
                HDay = "0" + ClsPub.isDate(HDate).Day.ToString();
                HDay = HDay.Substring(HDay.Length - 2, 2);
                HOrgNumber = ClsPub.HOrgNumber;
                //HBQty = HBQty + ClsPub.isInt(txtHBQty.Text);
                HZXQty = ClsPub.isDoule(txtHZXQty.Text);
                HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("订单数量")].Value);
                if (cmbHBarCodeType.Text == "唯一条码")
                {
                    HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay;
                    Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                    LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                }
                else if (cmbHBarCodeType.Text == "批次条码")
                {
                    TM = HOrgNumber + HMaterNumber + HBatchNo;
                }
                n = 0;
                    LSH2 = LSH.ToString();
                    while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                    {
                        LSH2 = "0" + LSH2;
                    }
                    if (cmbHBarCodeType.Text == "唯一条码")
                    {
                        //条码编号 = æ¡ç å‰ç¼€ + æµæ°´å·
                        TM = HTMNumber + LSH2;
                    }
                    if (TM.Trim() == "")
                    {
                        MessageBox.Show("条形码不能为空,不能生成条码!");
                        return;
                    }
                    string HWei = "";      //尾数
                    string HBarCode = "";
                    string HBarCodeType = "";
                    Int64 HMaterID1 = 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 = "";
                    try
                    {
                        oCn.BeginTran();
                        HWei = WeiShu;
                        HBarCode = TM;
                        HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                        HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value);
                        HAuxPropID = 0;
                        HUnitID = 0;
                        HQty2 = HZXQty;
                        HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value);
                        HSourceInterID = 0;
                        HSourceEntryID = 0;
                        HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value);
                        HSourceBillType = "3710";
                        HBarcodeQtys = 0;
                        HBarcodeNo = 0;
                        HSupID = 0;
                        HDeptID = 0;
                        HWhID = 0;
                        HSPID = 0;
                        HRemark = "";
                        HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料名称")].Value);
                        HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("规格型号")].Value);
                        HPinfan = "";
                        HMTONo = "";
                        HCusID = 0;
                        HCusType = "";
                        HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("日期")].Value);
                        HWorkLineName = "";
                        HSeOrderBillNo = "";
                        HInnerBillNo = "";
                        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 " +
                                            ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                            ") values ("
                                            + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.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 + "','" + HDate + "'"
                                            + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString()
                                            + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
                        oCn.Commit();
                        MessageBox.Show("条码生成完毕!");
                        //grdSub.RowCount = 0;
                        DisplayTM();
                    }
                    catch (Exception e1)
                    {
                        oCn.RollBack();
                        MessageBox.Show("条码生成失败!" + e1.Message);
                    }
            }
        }
        private void Sub_SaveBill_TTM()
        {
            HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
            HInterID_TTM = DBUtility.ClsPub.CreateBillID_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo);
            HBillNo_TTM = DBUtility.ClsPub.CreateBillCode_Prod(ModName1, ref DBUtility.ClsPub.sExeReturnInfo, true);//得到新单号
            string HMaterNumber = "";
            string HBatchNo = "";
            string HDate = "";
            string HYear = "";
            string HPeriod = "";
            string HDay = "";
            string HTMNumber = "";
            string HOrgNumber = "";
            DataSet Ds;
            int LSH = 0;                //流水号
            string LSH2 = "";           //流水号转换成字符
            double HZXQty = 0;         //装箱数量
            double HDDQty = 0;         //订单数量
            double HBQty = 0;         //箱数
            int k = 0;
            int n = 0;                  //同一批生成条码中的第几条
            string WeiShu = "";         //尾数
            int LSHlen = 6;             //流水号长度
            string TM = "";             //条码
            for (int j = 0; j < grdMain.Rows.Count; j++)
            {
                HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料代码")].Value);
                HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value);
                HDate = DateTime.Now.ToShortDateString();
                HYear = ClsPub.isDate(HDate).Year.ToString().Substring(2, 2);
                HPeriod = "0" + ClsPub.isDate(HDate).Month.ToString();
                HPeriod = HPeriod.Substring(HPeriod.Length - 2, 2);
                HDay = "0" + ClsPub.isDate(HDate).Day.ToString();
                HDay = HDay.Substring(HDay.Length - 2, 2);
                HOrgNumber = ClsPub.HOrgNumber;
                //HBQty = HBQty + ClsPub.isInt(txtHBQty.Text);
                HZXQty = ClsPub.isDoule(txtHZXQty.Text);
                HDDQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[Fun_GetCol("订单数量")].Value);
                HICMOBillNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value);
                if (cmbHBarCodeType.Text == "唯一条码")
                {
                    HTMNumber = HOrgNumber + HMaterNumber + HYear + HPeriod + HDay;
                    Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + HTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                    LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                }
                else if (cmbHBarCodeType.Text == "批次条码")
                {
                    TM = HOrgNumber + HMaterNumber + HBatchNo;
                }
                n = 0;
                LSH2 = LSH.ToString();
                while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
                {
                    LSH2 = "0" + LSH2;
                }
                if (cmbHBarCodeType.Text == "唯一条码")
                {
                    //条码编号 = æ¡ç å‰ç¼€ + æµæ°´å·
                    TM = HTMNumber + LSH2;
                }
                if (TM.Trim() == "")
                {
                    MessageBox.Show("条形码不能为空,不能生成条码!");
                    return;
                }
                string HWei = "";      //尾数
                string HBarCode = "";
                string HBarCodeType = "";
                Int64 HMaterID1 = 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 = "";
                try
                {
                    oCn.BeginTran();
                    HWei = WeiShu;
                    HBarCode = TM;
                    HBarCodeType = ClsPub.isStrNull(cmbHBarCodeType.Text);
                    HMaterID1 = ClsPub.isLong(grdMain.Rows[j].Cells[Fun_GetCol("HMaterID")].Value);
                    HAuxPropID = 0;
                    HUnitID = 0;
                    HQty2 = HZXQty;
                    HBatchNo2 = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("批次")].Value);
                    HSourceInterID = 0;
                    HSourceEntryID = 0;
                    HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("生产订单号")].Value);
                    HSourceBillType = "3710";
                    HBarcodeQtys = 0;
                    HBarcodeNo = 0;
                    HSupID = 0;
                    HDeptID = 0;
                    HWhID = 0;
                    HSPID = 0;
                    HRemark = "";
                    HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("物料名称")].Value);
                    HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[Fun_GetCol("规格型号")].Value);
                    HPinfan = "";
                    HMTONo = "";
                    HCusID = 0;
                    HCusType = "";
                    HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[Fun_GetCol("日期")].Value);
                    HWorkLineName = "";
                    HSeOrderBillNo = "";
                    HInnerBillNo = "";
                    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 " +
                                        ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo " +
                                        ") values ("
                                        + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID1.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 + "','" + HDate + "'"
                                        + ", " + ClsPub.HOrgID.ToString() + "," + ClsPub.HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString()
                                        + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "')");
                    oCn.RunProc("insert into Sc_PackUnionBillSub (HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo" +
                                        ",HSourceBillType,HMaterID,HUnitID,HQty,HSourceID,HEquipID,HGroupID" +
                                        ",HWorkerID,HScanDate,HBarCode,HBarCode_Pack,HStatus,HICMOEntryID " +
                                        ") values ("
                                        +  HInterID_TTM + "," + j + ",0,0,''"
                                        + ",'3710'," + HMaterID1.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString() + ",0,0,0"
                                        + ", 0,getdate(),'" + HBarCode + "','" + TTM + "',0,0)");
                    DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList Where HInterID=" + HInterID.ToString() + " and HBarCode like '%ZXM&' order by HItemID", "h_v_IF_BarCodeBillList", ref DBUtility.ClsPub.sExeReturnInfo);
                    //生成首行标题
                    if (DSet == null)
                    {
                        MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                        return;
                    }
                    //
                    grdList.DataSource = DSet.Tables[0].DefaultView;
                    oCn.Commit();
                    MessageBox.Show("条码生成完毕!");
                    //grdSub.RowCount = 0;
                    //DisplayTM();
                }
                catch (Exception e1)
                {
                    oCn.RollBack();
                    MessageBox.Show("条码生成失败!" + e1.Message);
                }
            }
        }
        private void DisplayTM()
        {
            //HInterID = DBUtility.ClsPub.isInt(txtHMaterID.Tag);
            DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList Where HinterID=" + HInterID.ToString() + " and æ¡ç ç±»åž‹ = '托盘条码' order by HItemID", "h_v_IF_BarCodeBillList", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果,条码不存在!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdList.DataSource = DSet.Tables[0].DefaultView;
            //冻结
            int FrCol = 0;
            string s = "是";
            DBUtility.Xt_BaseBillFun.DisplayGrid(grdList, this.Name + "grdList", s, FrCol);
            //画线
            //GraphLine();
            //
        }
        //private void button5_Click(object sender, EventArgs e)
        //{
        //    //判断是否已经生成条码
        //    for (int j = 0; j < grdMain.SelectedRows.Count; j++)
        //    {
        //        if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[j].Cells[Fun_GetCol("HBarCode")].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_SetReport(oFrm.sOpenTmp);
        //            Report.PrintPreview(false);
        //            Thread.Sleep(1000);
        //        }
        //    }
        //}
        //打印前判断条码是否已打印过
        //private bool ReportPrintBegin()
        //{
        //        string sRelQty = "";
        //        if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[j].Cells[Fun_GetCol("HBarCode")].Value), ref sRelQty))
        //        {
        //            MessageBox.Show("条码已经打印过,不可重复打印!");
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //}
        private void button1_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
            //打印前判断条码是否已打印过
            string sBarCode = "";
            string sRelQty = "";
            for (int i = 0; i < grdSub.SelectedRows.Count; i++)
            {
                sBarCode = sBarCode + "," + DBUtility.ClsPub.isStrNull(grdSub.Rows[grdSub.SelectedRows[i].Index].Cells[Fun_GetCol("HBarcode")].Value);
            }
            //if (oBar.Set_BPrintQty(sBarCode.Substring(1), ref sRelQty))
            //{
            //    MessageBox.Show(sRelQty);
            //    return;
            //}
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            //DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = ModCaption;
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                Sub_SetReport(oFrm.sOpenTmp);
                Report.Print(false);
                //oBar.Set_PrintQty(DBUtility.ClsPub.isStrNull(grdMain.Rows[CurRows].Cells[Fun_GetCol("条码编号")].Value));
                Thread.Sleep(1000);
            }
            //批量更新条码打印次数
            oBar.Set_EPrintQty(sBarCode.Substring(1));
        }
        private void cmdHSaveBill1_Click(object sender, EventArgs e)
        {
            Display1();
        }
        private void Display1()
        {
            ClsCN SubCn = new ClsCN();
            DataSet DSet;
            string sSql = "";
            string sFastSQL = "";
            //生产订单号
            //if (txtHICMOBillNo.Text.Trim() != "")
            //{
            //    sFastSQL = sFastSQL + " and HICMOBillNo  like '%" + txtHICMOBillNo.Text + "%'";
            //}
            string HICMOBillNo = "";
            HICMOBillNo = txtHICMOBillNo1.Text.Trim().ToString();
            //物料
            //if (txtHMaterID.Text.Trim() != "")
            //{
            //    sFastSQL = sFastSQL + " and HMaterName  like '%" + txtHMaterID.Text + "%'";
            //}
            string HMaterName = "";
            HMaterName = txtHMaterID1.Text.Trim().ToString();
            //判断开始日期
            //if (dtpHBeginDate.Checked)
            //{
            //    sFastSQL = sFastSQL + " and æ—¥æœŸ>='" + dtpHBeginDate.Value.ToShortDateString() + "'";
            //}
            string HBeginDate = "";
            HBeginDate = dtpHBeginDate1.Value.ToShortDateString();
            //判断结束日期
            //if (dtpHEndDate.Checked)
            //{
            //    sFastSQL = sFastSQL + " and æ—¥æœŸ<='" + dtpHEndDate.Value.ToShortDateString() + "'";
            //}
            string HEndDate = "";
            HEndDate = dtpHEndDate1.Value.ToShortDateString();
            //if (sFastSQL.Trim() == "")
            //{
            //    MessageBox.Show("没有输入条件!");
            //    return;
            //}
            //过滤条件
            //
            DSet = SubCn.RunProcReturn("exec h_p_KSTMCX '" + HICMOBillNo + "' , '" + HMaterName + "' ,'" + HBeginDate + "', '" + HEndDate + "'", "h_p_KSTMCX", ref DBUtility.ClsPub.sExeReturnInfo);
            //生成首行标题
            if (DSet == null)
            {
                MessageBox.Show("没有返回任何结果,请在过滤框中点击【恢复】按钮,尝试再次查询!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            //
            grdSub.DataSource = DSet.Tables[0].DefaultView;
            //冻结
            //int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text);
            //string s = frmCondition.cmbHComplete.Text;
            //DBUtility.Xt_BaseBillFun.DisplayGrid(grdSub, this.Name, s, FrCol);
            //画线
            GraphLine();
            //
        }
        private void cmdHSourceID_Click(object sender, EventArgs e)
        {
            Int64 HEmpID = 0;
            HEmpID = Convert.ToInt64(txtHEmpID.Tag);
            //MessageBox.Show(ClsPub.isStrNull(HEmpID));
            //string HEmpName = "";
            //HEmpName = ClsPub.isStrNull(txtHEmpID.Text);
            DAL.ClsGy_Source_View oSource = new DAL.ClsGy_Source_View();
            if (HEmpID != 0)
            {
                if (oSource.GetInfoByID_AoBang(HEmpID))
                {
                    this.txtHSourceID.Text = oSource.oModel.HName;
                    this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString();
                    //
                    Display();
                }
                else
                {
                    this.txtHSourceID.Text = "";
                }
            }
            else
            {
                if (oSource.RefreshView())
                {
                    this.txtHSourceID.Text = oSource.oModel.HName;
                    this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString();
                    //
                    Display();
                }
                else
                {
                    this.txtHSourceID.Text = "";
                }
            }
            //if (oSource.RefreshView())
            //{
            //    this.txtHSourceID.Text = oSource.oModel.HName;
            //    this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString();
            //    //
            //    Display();
            //}
            //DAL.ClsGy_WorkCenter_View oWork = new DAL.ClsGy_WorkCenter_View();
            //if (oWork.RefreshView())
            //{
            //    this.txtHSourceID.Text = oWork.oModel.HName;
            //    this.txtHSourceID.Tag = oWork.oModel.HItemID.ToString();
            //    //
            //    Display();
            //    //
            //}
            //else
            //{
            //    this.txtHSourceID.Text = "";
            //}
        }
        private void cmdHEmpID_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Employee_View oEmp = new DAL.ClsGy_Employee_View();
            if (oEmp.RefreshView())
            {
                this.txtHEmpID.Text = oEmp.oModel.HName;
                this.txtHEmpID.Tag = oEmp.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHEmpID.Text = "";
            }
        }
        private void cmdHMaterID_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Material_View oMater = new DAL.ClsGy_Material_View();
            if (oMater.RefreshView())
            {
                this.txtHMaterID.Text = oMater.oModel.HName;
                this.txtHMaterID.Tag = oMater.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHMaterID.Text = "";
            }
        }
        private void cmdHMaterID1_Click(object sender, EventArgs e)
        {
            DAL.ClsGy_Material_View oMater = new DAL.ClsGy_Material_View();
            if (oMater.RefreshView())
            {
                this.txtHMaterID1.Text = oMater.oModel.HName;
                this.txtHMaterID1.Tag = oMater.oModel.HItemID.ToString();
            }
            else
            {
                this.txtHMaterID1.Text = "";
            }
        }
        private void txtHMiniQty_TextChanged(object sender, EventArgs e)
        {
            //double HMiniQty = 0;
            //double HBQty = 0;
            //HMiniQty = DBUtility.ClsPub.isDoule(txtHMiniQty.Text.Trim());
            //HBQty =
        }
        private void txtHBQty_TextChanged(object sender, EventArgs e)
        {
            double HICMOQty = 0;
            double HMiniQty = 0;
            double HBQty = 0;
            for (int i = 0; i < grdMain.SelectedRows.Count; i++)
            {
                txtHZXQty.Text = DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("订单数量")].Value);
            }
            HICMOQty = DBUtility.ClsPub.isDoule(txtHZXQty.Text.Trim());
            HMiniQty = DBUtility.ClsPub.isDoule(txtHMiniQty.Text.Trim());
            if (HMiniQty == 0)
            {
                HBQty = 0;
            }
            else
            {
                HBQty = HICMOQty / HMiniQty;
            }
            HBQty = Math.Ceiling(HBQty);
            txtHBQty.Text = DBUtility.ClsPub.isStrNull(HBQty);
        }
        private void button5_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            for (int i = 0; i < grdList.SelectedRows.Count; i++)
            {
                if (DBUtility.ClsPub.isStrNull(grdList.SelectedRows[i].Cells[Fun_GetColList("条码编号")].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_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
        private bool ReportPrintBegin()
        {
            string sRelQty = "";
            if (oBar.Set_BPrintQty(DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetColList("条码编号")].Value), ref sRelQty))
            {
                MessageBox.Show("条码已经打印过,不可重复打印!");
                return true;
            }
            else
            {
                return false;
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
            //判断是否已经生成条码
            if (DBUtility.ClsPub.isStrNull(grdList.Rows[0].Cells[Fun_GetColList("条码编号")].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_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
        private void cz_Click(object sender, EventArgs e)
        {
            txtHBQty.Text = "";
            txtHEmpID.Text = "";
            txtHICMOBillNo.Text = "";
            txtHICMOBillNo1.Text = "";
            txtHZXQty.Text = "";
            txtHMaterID.Text = "";
            txtHMaterID1.Text = "";
            txtHMiniQty.Text = "";
            txtHSourceID.Text = "";
            cmbHBarCodeType.Items.Clear();
            grdList.DataSource = null;
            grdSub.DataSource = null;
            grdMain.DataSource = null;
            txtHEmpID.Tag = 0;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //获取网格第一行HInterID的值
            Int64 HInterID = 0;
            HInterID = DBUtility.ClsPub.isInt(txtHMaterID.Tag);
            DataSet DSBefore;
            DSBefore =  SubCn.RunProcReturn("exec h_p_PreviousMater "+ HInterID, "h_p_PreviousMater", ref DBUtility.ClsPub.sExeReturnInfo);
            grdMain.DataSource = DSBefore.Tables[0].DefaultView;
            //if (DSBefore.Tables[0].Rows.Count > 0)
            //{
            //    txtHMaterID.Tag = DBUtility.ClsPub.isInt(grdMain.Rows[0].Cells["HInterID"].Value);
            //}
            //else
            //{
            //}
            if (DSBefore == null || DSBefore.Tables[0].Rows.Count == 0)
            //if (DSet == null|| DSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("没有上一个物料,如果需要请找机修!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            else
            {
                grdMain.DataSource = DSBefore.Tables[0].DefaultView;
                txtHMaterID.Tag = DBUtility.ClsPub.isInt(grdMain.Rows[0].Cells["HInterID"].Value);
                txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["标准装箱"].Value);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            //根据
            Int64 HInterID = 0;
            //HInterID = DBUtility.ClsPub.isInt(grdMain.Rows[0].Cells[Fun_GetCol("HInterID")].Value);
            HInterID = DBUtility.ClsPub.isInt(txtHMaterID.Tag);
            DataSet DSBefore;
            DSBefore = SubCn.RunProcReturn("exec h_p_NextMater " + HInterID, "h_p_NextMater", ref DBUtility.ClsPub.sExeReturnInfo);
            if (DSBefore == null || DSBefore.Tables[0].Rows.Count == 0)
            //if (DSet == null|| DSet.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("没有下一个物料,如果需要请找机修!" + DBUtility.ClsPub.sExeReturnInfo);
                return;
            }
            else
            {
                grdMain.DataSource = DSBefore.Tables[0].DefaultView;
                txtHMaterID.Tag = DBUtility.ClsPub.isInt(grdMain.Rows[0].Cells["HInterID"].Value);
                txtHMiniQty.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["标准装箱"].Value);
            }
            //txtHMaterID.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[0].Cells["HInterID"].Value);
        }
        //超额打印
        private void button7_Click(object sender, EventArgs e)
        {
            //根据本箱数量 æ¥ åˆ†é…åˆ° æ¯ä¸ªç”Ÿäº§è®¢å•上,并且允许超过订单数量 ï¼ˆåˆ†é…æ—¶ è¦è€ƒè™‘ è®¢å•剩余数量已经是 è´Ÿæ•°çš„æƒ…况)
            //1.判断本箱数量 å¿…须大于0
            double HZXQty = 0;//整箱数量
            HZXQty = ClsPub.isDoule(txtHZXQty.Text);
            if (HZXQty <= 0)
            {
                MessageBox.Show("请输入整箱数量!");
                return;
            }
            //2.刷新网格
            //Display();
            //3.循环网格,累计全部剩余数量,判断是否 å‰©ä½™æ•°é‡ å°äºŽ æœ¬ç®±æ•°é‡ï¼›å¦‚æžœ å¤§äºŽåˆ™æŠ¥é”™ é€€å‡ºã€‚
            double sumLeftQty = 0;
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                if ( DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value)>0)
                {
                    sumLeftQty = sumLeftQty + DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                }
                else
                {
                }
            }
            if(sumLeftQty>= HZXQty )
            {
                MessageBox.Show("剩余数量大于本箱数量,不能超额打印,请用普通打印功能。");
                return;
            }
            //4.把整箱数量 åˆ†é…åˆ° ç½‘格下面的每一个 ç”Ÿäº§è®¢å•上去。  å¾ªçŽ¯ç½‘æ ¼
            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                if (HZXQty > DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value))
                {
                    if (i == grdMain.Rows.Count - 1)
                    {
                        grdMain.Rows[i].Cells["本次数量"].Value = HZXQty;
                    }
                    else
                    {
                        HZXQty = HZXQty - DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                        grdMain.Rows[i].Cells["本次数量"].Value = DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells["生产订单数量"].Value);
                    }
                }
                else
                {
                    //grdMain.Rows[i].Cells["本次数量"].Value = HZXQty;
                    break;
                }
            }
            Sub_SaveBarCode();
            //
        }
    }
}