ch
2022-01-19 8a2f4c5977834d55b889bef3d01e1e02442b735c
WarM/²Ö¿â¹ÜÀí/Gy_BarCodeBill_ChaiMa.cs
@@ -43,6 +43,7 @@
        public const string ModName = "";                   //单据类型
        public const string ModCaption = "条码拆码";          //单据名称
        public const string ModRightName = "Gy_BarCodeBill_ChaiMa";
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;     //单据状态(新增,修改,浏览,更新单价,变更)
        ClsGridViewSum oSumGrid_Mater = new ClsGridViewSum();
        ClsGridViewSum oSumGrid_Pay = new ClsGridViewSum();
        public DAL.ClsGy_BarCodeBill_ChaiMa BillNew = new DAL.ClsGy_BarCodeBill_ChaiMa();   //对应单据类
@@ -56,6 +57,8 @@
            txtHMaker.Text = DBUtility.ClsPub.CurUserName;
            initGrid();
            initGrid_Pay();
            oSumGrid_Mater.NoCol = HSnoCol;
            oSumGrid_Pay.NoCol = HSnoCol2;
        }
       #region çª—体处理方法
@@ -63,7 +66,7 @@
        //初始化页签1
        private void initGrid()
        {
            grdMain.ColumnCount = 9;                       //总列数
            grdMain.ColumnCount = 10;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name + "1");
            grdMain.Columns[HSnoCol].HeaderText = "序号";
            grdMain.Columns[HInterID].HeaderText = "HInterID";
@@ -84,33 +87,33 @@
            //设置合计列
            string sTotalCol = HTagCol.ToString() + "0";
            //格式化网格
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid_Mater);
            //DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid_Mater);
        }
        //初始化页签2
        private void initGrid_Pay()
        {
            grdMain.ColumnCount = 9;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name + "1");
            grdMain.Columns[HSnoCol2].HeaderText = "序号";
            grdMain.Columns[HInterID2].HeaderText = "HInterID";
            grdMain.Columns[HBarCode2].HeaderText = "条码编号";
            grdMain.Columns[HQty2].HeaderText = "条码数量";
            grdMain.Columns[HNum2].HeaderText = "拆分数量";
            grdMain.Columns[HMaterCol2].HeaderText = "物料代码";
            grdMain.Columns[HMaterName2].HeaderText = "物料名称";
            grdMain.Columns[HMaterMould2].HeaderText = "规格型号";
            grdMain.Columns[HBatchNo2].HeaderText = "批号";
            grdMain_Pay.ColumnCount = 10;                       //总列数
            DBUtility.Xt_BaseBillFun.initGridFst(grdMain_Pay, this.Name + "1");
            grdMain_Pay.Columns[HSnoCol2].HeaderText = "序号";
            grdMain_Pay.Columns[HInterID2].HeaderText = "HInterID";
            grdMain_Pay.Columns[HBarCode2].HeaderText = "条码编号";
            grdMain_Pay.Columns[HQty2].HeaderText = "条码数量";
            grdMain_Pay.Columns[HNum2].HeaderText = "拆分数量";
            grdMain_Pay.Columns[HMaterCol2].HeaderText = "物料代码";
            grdMain_Pay.Columns[HMaterName2].HeaderText = "物料名称";
            grdMain_Pay.Columns[HMaterMould2].HeaderText = "规格型号";
            grdMain_Pay.Columns[HBatchNo2].HeaderText = "批号";
            //=============================================================================
            ////隐藏列
            grdMain.Columns[HTagCol].Visible = false;
            grdMain.Columns[HInterID].Visible = false;
            grdMain_Pay.Columns[HTagCol].Visible = false;
            grdMain_Pay.Columns[HInterID].Visible = false;
            //设置可编辑列
            string sAllowCol = HNum2.ToString();
            //设置合计列
            string sTotalCol = HTagCol2.ToString() + "0";
            //格式化网格
            DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid_Pay);
            //DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid_Pay);
        }
        // åŸºæœ¬ä¸å˜
@@ -128,141 +131,157 @@
            txtHBillNo.Text = "";
            txtNum.Text = "";
            txtHMaker.Text = DBUtility.ClsPub.CurUserName;
            Sub_ClearBill();
        }
        //数据验证
        private bool Sub_AllowSave()
        {
            int i = 0;
            while (grdMain_Pay.Rows[i].Cells[HSnoCol].Value.ToString() != "")
            for (int i = 0; i <= grdMain_Pay.RowCount - 1; i++)
            {
                if (grdMain_Pay.Rows[i].Cells[HNum2].Value.ToString() == "")
                if (ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HSnoCol2].Value) != 0)
                {
                    MessageBox.Show("请将表格拆分数量填写完整", "提示");
                    if (ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HNum2].Value) ==null)
                    {
                        MessageBox.Show("请将表格拆分数量填写完整", "提示");
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        //生成按钮
        private void xz_Click(object sender, EventArgs e)
        {
            this.SeverDate();
        }
        private bool SeverDate()
        {
            Int32 i;
            bool bResult;
            BillNew = new DAL.ClsGy_BarCodeBill_ChaiMa();
            if (!Sub_AllowSave())//单据完整性判断
                return false;
            //判断会计期是否合理
            string s = "";
            int sYear = 0;
            int sPeriod = 0;
            string HBillNo = txtHBillNo.Text;
            DataSet Ds;
            SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
            Ds = oCn.RunProcReturn("select top 1* from h_v_Gy_BarCodeBill_ChaiMa where HBarCode='" + HBillNo + "'", "h_v_Gy_BarCodeBill_ChaiMa");
            for (i = 0; i <= grdMain_Pay.RowCount - 1; i++)
            {
                if (ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HBarCode].Value) != 0)
            //if (Sub_AllowSave())
            //{
                //判断会计期是否合理
                string HBillNo = txtHBillNo.Text;
                DataSet Ds;
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                Ds = oCn.RunProcReturn("select top 1* from h_v_Gy_BarCodeBill_ChaiMa where æ¡ç ç¼–号='" + HBillNo + "'", "h_v_Gy_BarCodeBill_ChaiMa");
                for (i = 0; i <= grdMain_Pay.RowCount - 1; i++)
                {
                    Model.ClsGy_BarCodeEdit_Model model = new Model.ClsGy_BarCodeEdit_Model();
                    //固定赋值========================================
                    model.HEntryID = i + 1;
                    model.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                    model.HBarCode = DBUtility.ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HBarCode].Value);
                    model.HQty = DBUtility.ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HQty].Value);
                    model.HPieceQty = DBUtility.ClsPub.isInt(grdMain_Pay.Rows[i].Cells[HNum2].Value);
                    model.HBatchNo = DBUtility.ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HBatchNo].Value);
                    model.HMaterID = DBUtility.ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HMaterCol].Value);
                    model.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HUnitID"].ToString());
                    model.HSupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSupID"].ToString());
                    model.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"].ToString());
                    model.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"].ToString());
                    model.HBarCodeType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBarCodeType"].ToString());
                    model.HItemSubID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HItemSubID"].ToString());
                    model.HGroupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HGroupID"].ToString());
                    model.HSourceInterID= DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
                    model.HSourceEntryID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSourceEntryID"].ToString());
                    model.HSourceBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceBillNo"].ToString());
                    model.HSourceBillType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceBillType"].ToString());
                    model.HUseFlag = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUseFlag"].ToString());
                    model.HStopflag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HStopflag"].ToString());
                    model.HInitQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HInitQty"].ToString());
                    model.HSourceID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInitQty"].ToString());
                    model.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCusID"].ToString());
                    model.HSTOCKORGID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSTOCKORGID"].ToString());
                    model.HOWNERID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HOWNERID"].ToString());
                    model.HBarCodeDate= DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HBarCodeDate"].ToString());
                    model.HInnerBillNo= DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HInnerBillNo"].ToString());
                    model.HMZ= DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HMZ"].ToString());
                    model.HMakeDate = DateTime.Now;
                    model.HMaker = ClsPub.CurUserName;
                    if (model.HPieceQty <= 0|| model.HPieceQty.ToString() =="")
                    if (ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HSnoCol2].Value) != 0)
                    {
                        MessageBox.Show("第" + ClsPub.isStrNull(i + 1) + "行,拆分数量必须大于0!");
                        return false;
                        Model.ClsGy_BarCodeEdit_Model model = new Model.ClsGy_BarCodeEdit_Model();
                        //固定赋值========================================
                        model.HEntryID = i + 1;
                        model.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"].ToString());
                        model.HBarCode = DBUtility.ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HBarCode].Value);
                        model.HQty = DBUtility.ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HNum2].Value);
                        model.HQty = DBUtility.ClsPub.isInt(grdMain_Pay.Rows[i].Cells[HNum2].Value);
                        model.HBatchNo = DBUtility.ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HBatchNo].Value);
                        model.HMaterID = DBUtility.ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HMaterCol].Value);
                        model.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HUnitID"].ToString());
                        model.HSupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSupID"].ToString());
                        model.HDeptID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HDeptID"].ToString());
                        model.HEmpID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HEmpID"].ToString());
                        model.HBarCodeType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBarCodeType"].ToString());
                        model.HItemSubID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HItemSubID"].ToString());
                        model.HGroupID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HGroupID"].ToString());
                        model.HSourceInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
                        model.HSourceEntryID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSourceEntryID"].ToString());
                        model.HSourceBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceBillNo"].ToString());
                        model.HSourceBillType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HSourceBillType"].ToString());
                        model.HUseFlag = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUseFlag"].ToString());
                        model.HStopflag = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HStopflag"].ToString());
                        model.HInitQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HInitQty"].ToString());
                        model.HSourceID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInitQty"].ToString());
                        model.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCusID"].ToString());
                        model.HSTOCKORGID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HSTOCKORGID"].ToString());
                        model.HOWNERID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HOWNERID"].ToString());
                        model.HBarCodeDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HBarCodeDate"].ToString());
                        model.HInnerBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HInnerBillNo"].ToString());
                        model.HMZ = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HMZ"].ToString());
                        model.HMakeDate = DateTime.Now;
                        model.HMaker = ClsPub.CurUserName;
                        if (model.HPieceQty <= 0 || model.HPieceQty.ToString() == "")
                        {
                            MessageBox.Show("第" + ClsPub.isStrNull(i + 1) + "行,拆分数量必须大于0!");
                            return false;
                        }
                        BillNew.DetailColl_Mater.Add(model);
                    }
                    BillNew.DetailColl_Mater.Add(model);
                }
            }
            return true;
            //保存
            bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
            //提示
            if (bResult == true)
            {
                MessageBox.Show("单据存盘完毕!单据号:" + this.txtHBillNo.Text.Trim(), "提示");
                return true;
            }
            else
            {
                MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示");
                return false;
            }
        }
        //生成按钮
        private void xz_Click(object sender, EventArgs e)
        {
            this.SeverDate();
                //保存
                bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                //提示
                if (bResult == true)
                {
                    MessageBox.Show("单据存盘完毕!单据号:" + this.txtHBillNo.Text.Trim(), "提示");
                    return true;
                }
                else
                {
                    MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示");
                    return false;
                }
            //}
            //else
            //{
            //    return false;
            //}
        }
        //确定按钮
        private void button1_Click(object sender, EventArgs e)
        {
            if (DBUtility.ClsPub.isStrNull(txtHBillNo.Text) != ""|| DBUtility.ClsPub.isStrNull(txtNum.Text) != "")
            if (DBUtility.ClsPub.isStrNull(txtHBillNo.Text) != ""&& DBUtility.ClsPub.isStrNull(txtNum.Text) != "")
            {
                string HBillNo = txtHBillNo.Text;
                int HNum = int.Parse(txtNum.Text);
                int HNumCan = int.Parse(txtNum.Text);
                DataSet Ds;
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                Ds = oCn.RunProcReturn("select top 1* from h_v_Gy_BarCodeBill_ChaiMa where HBarCode='" + HBillNo + "'", "h_v_Gy_BarCodeBill_ChaiMa");
                grdMain.Rows[0].Cells[HTagCol].Value = "*";
                grdMain.Rows[0].Cells[HInterID].Value = Ds.Tables[0].Rows[0]["HInterID"].ToString();
                grdMain.Rows[0].Cells[HBarCode].Value = Ds.Tables[0].Rows[0]["条码编号"].ToString();
                grdMain.Rows[0].Cells[HQty].Value = Ds.Tables[0].Rows[0]["条码数量"].ToString();
                grdMain.Rows[0].Cells[HNum].Value = 0;
                grdMain.Rows[0].Cells[HMaterCol].Value = Ds.Tables[0].Rows[0]["物料代码"].ToString();
                grdMain.Rows[0].Cells[HMaterName].Value = Ds.Tables[0].Rows[0]["物料名称"].ToString();
                grdMain.Rows[0].Cells[HMaterMould].Value = Ds.Tables[0].Rows[0]["规格型号"].ToString();
                grdMain.Rows[0].Cells[HBatchNo].Value = Ds.Tables[0].Rows[0]["批号"].ToString();
                for (int i = 0; i < HNum; i++)
                Ds = oCn.RunProcReturn("select top 1* from h_v_Gy_BarCodeBill_ChaiMa where æ¡ç ç¼–号='" + HBillNo + "'", "h_v_Gy_BarCodeBill_ChaiMa");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    int Code = 65 + i;
                    System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                    byte[] byteArray = new byte[] { (byte)Code };
                    string A = asciiEncoding.GetString(byteArray);
                    string No = Ds.Tables[0].Rows[0]["条码编号"].ToString();
                    grdMain_Pay.Rows[i].Cells[HTagCol2].Value = "*";
                    grdMain_Pay.Rows[0].Cells[HInterID2].Value = Ds.Tables[0].Rows[0]["HInterID"].ToString();
                    grdMain_Pay.Rows[0].Cells[HBarCode2].Value = No + A;
                    grdMain_Pay.Rows[0].Cells[HQty2].Value = Ds.Tables[0].Rows[0]["条码数量"].ToString();
                    grdMain_Pay.Rows[0].Cells[HMaterCol2].Value = Ds.Tables[0].Rows[0]["物料代码"].ToString();
                    grdMain_Pay.Rows[0].Cells[HMaterName2].Value = Ds.Tables[0].Rows[0]["物料名称"].ToString();
                    grdMain_Pay.Rows[0].Cells[HMaterMould2].Value = Ds.Tables[0].Rows[0]["规格型号"].ToString();
                    grdMain_Pay.Rows[0].Cells[HBatchNo2].Value = Ds.Tables[0].Rows[0]["批号"].ToString();
                    MessageBox.Show("条码编号不存在", "提示");
                }
                else
                {
                    grdMain.Rows[0].Cells[HTagCol].Value = "*";
                    grdMain.Rows[0].Cells[HSnoCol].Value = 1;
                    grdMain.Rows[0].Cells[HInterID].Value = Ds.Tables[0].Rows[0]["HInterID"].ToString();
                    grdMain.Rows[0].Cells[HBarCode].Value = Ds.Tables[0].Rows[0]["条码编号"].ToString();
                    grdMain.Rows[0].Cells[HQty].Value = Ds.Tables[0].Rows[0]["条码数量"].ToString();
                    grdMain.Rows[0].Cells[HNum].Value = 0;
                    grdMain.Rows[0].Cells[HMaterCol].Value = Ds.Tables[0].Rows[0]["物料代码"].ToString();
                    grdMain.Rows[0].Cells[HMaterName].Value = Ds.Tables[0].Rows[0]["物料名称"].ToString();
                    grdMain.Rows[0].Cells[HMaterMould].Value = Ds.Tables[0].Rows[0]["规格型号"].ToString();
                    grdMain.Rows[0].Cells[HBatchNo].Value = Ds.Tables[0].Rows[0]["批号"].ToString();
                    for (int i = 0; i < HNumCan; i++)
                    {
                        int Code = 65 + i;
                        System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
                        byte[] byteArray = new byte[] { (byte)Code };
                        string A = asciiEncoding.GetString(byteArray);
                        string No = Ds.Tables[0].Rows[0]["条码编号"].ToString();
                        grdMain_Pay.Rows[i].Cells[HTagCol2].Value = "*";
                        grdMain_Pay.Rows[i].Cells[HSnoCol2].Value = HSnoCol2+i;
                        grdMain_Pay.Rows[i].Cells[HInterID2].Value = Ds.Tables[0].Rows[0]["HInterID"].ToString();
                        grdMain_Pay.Rows[i].Cells[HBarCode2].Value = No + A;
                        grdMain_Pay.Rows[i].Cells[HQty2].Value = Ds.Tables[0].Rows[0]["条码数量"].ToString();
                        grdMain_Pay.Rows[i].Cells[HMaterCol2].Value = Ds.Tables[0].Rows[0]["物料代码"].ToString();
                        grdMain_Pay.Rows[i].Cells[HMaterName2].Value = Ds.Tables[0].Rows[0]["物料名称"].ToString();
                        grdMain_Pay.Rows[i].Cells[HMaterMould2].Value = Ds.Tables[0].Rows[0]["规格型号"].ToString();
                        grdMain_Pay.Rows[i].Cells[HBatchNo2].Value = Ds.Tables[0].Rows[0]["批号"].ToString();
                    }
                }
            }
            else
@@ -271,5 +290,10 @@
            }
            
        }
        private void tc_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}