1
wtt
2024-09-29 19d0afadbe1c90e227b852db0a97ae413e90691f
WarM/ÌõÂë´òÓ¡/Kf_WeighToBarCode.cs
@@ -703,6 +703,7 @@
            Int64 HBadReasonID = 0;     //不良原因ID
            string HCusMaterName = "";  //客户物料名称
            string HCusModel = "";      //客户规格型号
            string HBarCode_Pack = "";  //托盘条码
            HBarCode = TM;
            HBarCodeType = DBUtility.ClsPub.isStrNull(cmbHBarCodeType.Text);
@@ -719,6 +720,7 @@
            HBadReasonID = DBUtility.ClsPub.isLong(txtHRemark.Tag);
            HCusMaterName = DBUtility.ClsPub.isStrNull(txtHCusMaterName.Text);
            HCusModel = DBUtility.ClsPub.isStrNull(txtHCusModel.Text);
            HBarCode_Pack = DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text);
            try
            {
@@ -730,7 +732,7 @@
                ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate,HMaterialJQty,HMaterialMQty,HNowQty " +
                ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HGiveAwayFlag " +
                ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HGiveAwayFlag,HBarCode_Pack " +
                ",HOrderInterID,HOrderEntryID,HOrderBillNo,HCustomQty1,HMaterialModel,HCusModel " +
                ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HLogo " +
                ") Values ("
@@ -739,7 +741,7 @@
                + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "',''"
                + ", 1," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                + ", 0,'',getdate(),'','" + sDate + "'," + HMaterialJQty.ToString() + "," + HMaterialMQty.ToString() + "," + HNowQty.ToString()
                + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0"
                + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0,'" + HBarCode_Pack + "'"
                + ", " + HProcessExchangeInterID.ToString() + ",0,'" + HProcessExchangeBillNo + "'," + HBadReasonID.ToString() + ",'" + HCusMaterName + "','" + HCusModel + "'"
                + ",'" + HMaterName + "','" + HMaterModel + "',''," + HAuxPropID.ToString() + ",'','','1')");
@@ -761,8 +763,8 @@
                    " Values("
                    + HInterID.ToString() + ",'" + HBillNo + "','" + HBillType + "'," + HMaterID.ToString() + "," + HAuxPropID.ToString() + ",0"
                    + "," + HWhID.ToString() + ",0," + HSPID.ToString() + ",0,0,''"
                    +",0," + HQty.ToString() + ",1,'" + HBatchNo + "','" + HBarCode + "',''"
                    +",'" + HMaker + "',getdate()," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillType + "','" + HSourceBillNo + "'"
                    +",0," + HQty.ToString() + ",1,'" + HBatchNo + "','" + HBarCode + "','" + HBarCode_Pack + "'"
                    + ",'" + HMaker + "',getdate()," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillType + "','" + HSourceBillNo + "'"
                    +",0,0,'',0,'',0"
                    +"," + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",'','称重入库生成','2'"
                    +",0,0,'',0)");
@@ -888,6 +890,11 @@
                        {
                            HRemark = HRemark + "、" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value);
                        }
                        if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码类型")].Value) == "托盘条码")
                        {
                            MessageBox.Show("所选条码编号:" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value) + " ä¸ºæ‰˜ç›˜æ¡ç ï¼Œä¸å…è®¸ä½œåºŸï¼", "提示");
                            return;
                        }
                    }
                    if (HRemark != "")
                    {
@@ -950,6 +957,7 @@
                    string HItemID = "";
                    string HBarCode = "";
                    string HBarCode2 = "";
                    string HBarCode_Pack = DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text);
                    for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
                    {
                        HItemID = HItemID + "," + DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("hmainid")].Value.ToString());
@@ -965,6 +973,17 @@
                        if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("作废标记")].Value) == "")
                        {
                            HRemark = HRemark + "、" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value);
                        }
                        if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码类型")].Value) == "托盘条码")
                        {
                            MessageBox.Show("所选条码编号:" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value) + " ä¸ºæ‰˜ç›˜æ¡ç ï¼Œä¸å…è®¸åä½œåºŸï¼", "提示");
                            return;
                        }
                        if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) != ""
                            && DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) != HBarCode_Pack)
                        {
                            MessageBox.Show("所选条码编号:" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("条码编号")].Value) + " å·²ç”Ÿæˆå¯¹åº”组托单,不允许反作废!", "提示");
                            return;
                        }
                    }
                    if (HRemark != "")
@@ -999,7 +1018,7 @@
                        ",HCusID,HDeptID,HCusBarCode,HMulSourceBill) " +
                        " select " + HInterID.ToString() + ",'" + HBillNo + "','" + HBillType + "',HMaterID,HAuxPropID,0" +
                        ",HWhID,0,HSPID,0,0,''" +
                        ",0,HQty,1,HBatchNo,HBarCode,''" +
                        ",0,HQty,1,HBatchNo,HBarCode,HBarCode_Pack" +
                        ",'" + HMaker + "',getdate(),HSourceInterID,HSourceEntryID,HSourceBillType,HSourceBillNo" +
                        ",0,0,'',0,'',0" +
                        ",HSTOCKORGID,HSTOCKORGID,HSTOCKORGID,'','称重入库生成-反作废','2'" +
@@ -1043,6 +1062,229 @@
        #endregion
        #region  //开始组托
        private void cmdHBPack_Click(object sender, EventArgs e)
        {
            if (!PackSub_AllowSave())
            {
                return;
            }
            SavePackBarCode();
            BarCode_Display();
            grdMain.Rows[0].Selected = true;
            txtHBarCode_Pack.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[0].Index].Cells[Fun_GetCol("条码编号")].Value);
            cmdHBPack.Enabled = false;
            sBarCodeItemID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.SelectedRows[0].Index].Cells[Fun_GetCol("HItemID")].Value).ToString();
            //自动打印
            if (chkHDYFlag.Checked == true)
            {
                //打印条码
                Sub_SetReport("托盘条码");
                Report.Print(false);
                Thread.Sleep(1000);
            }
            else
            {
                //选择打印模板
                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.Print(false);
                    Thread.Sleep(1000);
                }
            }
        }
        //条码生成前判断
        private bool PackSub_AllowSave()
        {
            //判断当前单据ID是否已上传生成单据
            DataSet Ds = oCn.RunProcReturn("select top 1 1 from KF_WeighSource_Temp with(nolock) where HInterID=" + HInterID.ToString() + " and HRelationInterID=1 ", "KF_WeighSource_Temp", ref DBUtility.ClsPub.sExeReturnInfo);
            if (Ds == null || Ds.Tables[0].Rows.Count == 0)
            {
            }
            else
            {
                MessageBox.Show("当前条码记录已换班上传生成单据,请退出后重新进入该模块进行条码生成操作!", "提示");
                return false;
            }
            if (HInterID == 0 || HBillNo == "")
            {
                MessageBox.Show("获取条码对应单据ID或单据号失败,请重新刷新界面!", "提示");
                return false;
            }
            return true;
        }
        //生成托盘条码
        private void SavePackBarCode()
        {
            int LSHlen = 6;             //流水号长度
            Int64 LSH = 0;              //流水号
            string LSH2 = "";           //流水号转换成字符
            string sDate = "";          //日期
            string sYear = "";          //å¹´
            string sPeriod = "";        //月
            string sDay = "";           //日
            string sTMNumber = "";      //条码自定义前缀
            string TM = "";             //条码编号
            DataSet Ds;
            //日期获取方式
            sDate = dtpHDate.Value.ToShortDateString();
            sYear = DBUtility.ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
            sPeriod = "0" + DBUtility.ClsPub.isDate(sDate).Month.ToString();
            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
            sDay = "0" + DBUtility.ClsPub.isDate(sDate).Day.ToString();
            sDay = sDay.Substring(sDay.Length - 2, 2);
            //==================================
            //条码前缀 = 'TP' + ç»„织代码 + å¹´ + æœˆ + æ—¥
            sTMNumber = "TP" + DBUtility.ClsPub.HOrgNumber + sYear + sPeriod + sDay;
            Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
            LSH = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
            LSH = LSH + 1;
            LSH2 = LSH.ToString();
            while (LSH2.Length < LSHlen)  //如果流水号小于6位数前面补0
            {
                LSH2 = "0" + LSH2;
            }
            TM = sTMNumber + LSH2;
            string HBarCode = "";
            string HBarCodeType = "托盘条码";
            HBarCode = TM;
            HBarCodeType = "";
            try
            {
                oCn.BeginTran();
                //写入条码档案
                oCn.RunProc("Insert into Gy_BarCodeBill " +
                "(HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HBarCode_Pack" +
                ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
                ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate,HMaterialJQty,HMaterialMQty,HNowQty " +
                ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HGiveAwayFlag " +
                ",HOrderInterID,HOrderEntryID,HOrderBillNo,HCustomQty1,HMaterialModel,HCusModel " +
                ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HLogo " +
                ") Values ("
                + "'" + HBarCode + "','" + HBarCodeType + "',0,0,1,'" + HBarCode + "'"
                + ",'',0,0,'" + HMaker + "',getdate(),0,1"
                + ",0,0,'','',''"
                + ",1,0,0,0,0,''"
                + ", 0,'',getdate(),'','" + sDate + "',0,0,0"
                + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0"
                + ", " + HProcessExchangeInterID.ToString() + ",0,'',0,'',''"
                + ",'','','',0,'','','1')");
                //回填最大流水号
                oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "',1 ");
                oCn.Commit();
            }
            catch (Exception e)
            {
                oCn.RollBack();
                MessageBox.Show("托盘条码生成失败!" + e.Message);
            }
        }
        #endregion
        #region  //结束组托
        private void cmdHEPack_Click(object sender, EventArgs e)
        {
            string HBarCode_Pack = DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text);
            //生成组托单前判断
            if(HBarCode_Pack=="")
            {
                MessageBox.Show("请先点击开始组托,进行条码组托操作!", "提示");
                return;
            }
            bool b = false;
            for (int i = 0; i < grdMain.RowCount; i++)
            {
                if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("条码类型")].Value) == "唯一条码"
                    && DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) == HBarCode_Pack)
                {
                    b = true;
                    break;
                }
            }
            if (b == false)
            {
                MessageBox.Show("当前托盘条码下还没生成对应条码,不允许生成组托单!", "提示");
                return;
            }
            //判断会计期是否合理
            string s = "";
            int sYear = 0;
            int sPeriod = 0;
            if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
            {
                MessageBox.Show(s, "提示");
                return;
            }
            try
            {
                oCn.BeginTran();
                //生成生产组托单
                Int64 HPUInterID = DBUtility.ClsPub.CreateBillID_Prod("3783", ref DBUtility.ClsPub.sExeReturnInfo);         //得到最新生产组托单ID
                string HPUBillNo = DBUtility.ClsPub.CreateBillCode_Prod("3783", ref DBUtility.ClsPub.sExeReturnInfo, true); //得到最新生产组托单号
                //写入生产组托单主表
                oCn.RunProc("Insert Into Sc_PackUnionBillMain " +
                    "(HInterID,HBillNo,HBillType,HBillSubType,HDate,HRemark" +
                    ",HYear,HPeriod,HChecker,HCheckDate,HMaker,HMakeDate" +
                    ",HICMOInterID,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HProdOrgID" +
                    ") Values ("
                    + " " + HPUInterID.ToString() + ",'" + HPUBillNo + "','3783','3783',convert(varchar(10),getdate(),120),''"
                    + "," + sYear.ToString() + "," + sPeriod.ToString() + ",'" + HMaker + "',getdate(),'" + HMaker + "',getdate()"
                    + ",0,'','" + HBarCode_Pack + "',0,0," + HStockOrgID.ToString() + ") ");
                //写入生产装箱单子表
                oCn.RunProc("Insert into Sc_PackUnionBillSub " +
                "(HInterID,HEntryID,HRelationQty,HRelationMoney,HRemark" +
                ",HMaterID,HUnitID,HQty,HBarCode,HBarCode_Pack,HScanDate" +
                ",HAuxPropID,HBatchNo,HMTONo" +
                ",HSourceID,HEquipID,HGroupID,HWorkerID,HStatus" +
                ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType) " +
                " select " + HPUInterID.ToString() + ",HItemID,'0,0,''" +
                ",HMaterID,HUnitID,HQty,HBarCode,HBarCode_Pack,getdate()" +
                ",HAuxPropID,HBatchNo,HMTONo" +
                ",0,0,0,0,0" +
                ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
                "from Gy_BarCodeBill with(nolock) where HInterID=" + HInterID.ToString() + " and HBarCode_Pack='" + HBarCode_Pack + "' and HStopflag=0"
                );
                MessageBox.Show("生成生产组托单:" + HPUBillNo + " æˆåŠŸï¼", "提示");
                txtHBarCode_Pack.Text = "";
                cmdHBPack.Enabled = true;
                oCn.Commit();
                return;
            }
            catch (Exception e2)
            {
                oCn.RollBack();
                MessageBox.Show("生成生产组托单失败!" + e2.Message);
                return;
            }
        }
        #endregion
@@ -1343,7 +1585,12 @@
                fs.Close();
            }
        }
        #endregion
        #endregion
    }
}