yusijie
2023-04-03 218ef595b6ed283ba3cc0c4d21bc19cc28b13f20
WarM/²Ö¿â¹ÜÀí/Gy_BarCodeBill_ChaiMa.cs
@@ -1,4 +1,5 @@
using Pub_Class;
using gregn6Lib;
using Pub_Class;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -6,9 +7,10 @@
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace WarM.仓库管理
namespace WarM
{
    public partial class Gy_BarCodeBill_ChaiMa : Form
    {
@@ -40,7 +42,7 @@
        public const Int16 HMaterMould2 = 8;
        public const Int16 HBatchNo2 = 9;
        public const string ModName = "";                   //单据类型
        public const string ModName = "3302";                   //单据类型
        public const string ModCaption = "条码拆码";          //单据名称
        public const string ModRightName = "Gy_BarCodeBill_ChaiMa";
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;     //单据状态(新增,修改,浏览,更新单价,变更)
@@ -61,7 +63,24 @@
            oSumGrid_Pay.NoCol = HSnoCol2;
        }
       #region çª—体处理方法
        #region çª—体处理方法
        //初始化页签1数据
        private void intoDate()
        {
            try
            {
                DataSet Ds;
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                Ds = oCn.RunProcReturn("select * from h_v_Gy_BarCodeBill_ChaiMa", "h_v_Gy_BarCodeBill_ChaiMa");
                grdMain.DataSource = Ds.Tables[0].DefaultView;
            }
            catch (Exception ex )
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        //初始化页签1
        private void initGrid()
@@ -82,10 +101,15 @@
            ////隐藏列
            grdMain.Columns[HTagCol].Visible = false;
            grdMain.Columns[HInterID].Visible = false;
            //设置可编辑列
            string sAllowCol = HNum.ToString();
            //设置合计列
            string sTotalCol = HTagCol.ToString() + "0";
            //置灰
            grdMain.Columns[HSnoCol].ReadOnly = true;
            grdMain.Columns[HBarCode].ReadOnly = true;
            grdMain.Columns[HQty].ReadOnly = true;
            grdMain.Columns[HMaterCol].ReadOnly = true;
            grdMain.Columns[HMaterName].ReadOnly = true;
            grdMain.Columns[HMaterMould].ReadOnly = true;
            grdMain.Columns[HBatchNo].ReadOnly = true;
            //intoDate();
            //格式化网格
            //DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid_Mater);
        }
@@ -108,6 +132,14 @@
            ////隐藏列
            grdMain_Pay.Columns[HTagCol].Visible = false;
            grdMain_Pay.Columns[HInterID].Visible = false;
            //置灰
            grdMain_Pay.Columns[HSnoCol].ReadOnly = true;
            grdMain_Pay.Columns[HBarCode].ReadOnly = true;
            grdMain_Pay.Columns[HQty].ReadOnly = true;
            grdMain_Pay.Columns[HMaterCol].ReadOnly = true;
            grdMain_Pay.Columns[HMaterName].ReadOnly = true;
            grdMain_Pay.Columns[HMaterMould].ReadOnly = true;
            grdMain_Pay.Columns[HBatchNo].ReadOnly = true;
            //设置可编辑列
            string sAllowCol = HNum2.ToString();
            //设置合计列
@@ -134,26 +166,26 @@
            Sub_ClearBill();
        }
        //数据验证
        private bool Sub_AllowSave()
        {
            for (int i = 0; i <= grdMain_Pay.RowCount - 1; i++)
            {
                if (ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HSnoCol2].Value) != 0)
                {
                    if (ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HNum2].Value) ==null)
                    {
                        MessageBox.Show("请将表格拆分数量填写完整", "提示");
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        ////数据验证
        //private bool Sub_AllowSave()
        //{
        //    for (int i = 0; i <= grdMain_Pay.RowCount - 1; i++)
        //    {
        //        if (ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HSnoCol2].Value) != 0)
        //        {
        //            if (ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HNum2].Value) ==null)
        //            {
        //                MessageBox.Show("请将表格拆分数量填写完整", "提示");
        //                return false;
        //            }
        //        }
        //        else
        //        {
        //            return true;
        //        }
        //    }
        //    return true;
        //}
        
        //生成按钮
        private void xz_Click(object sender, EventArgs e)
@@ -170,13 +202,13 @@
                //判断会计期是否合理
                string HBillNo = txtHBillNo.Text;
                DataSet Ds;
                double sum = 0.00000000;
                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");
                Ds = oCn.RunProcReturn("select top 1* from Gy_BarCodeBill 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[HSnoCol2].Value) != 0)
                    {
                        Model.ClsGy_BarCodeEdit_Model model = new Model.ClsGy_BarCodeEdit_Model();
                        //固定赋值========================================
                        model.HEntryID = i + 1;
@@ -185,7 +217,7 @@
                        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.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMaterID"].ToString());
                        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());
@@ -198,7 +230,6 @@
                        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());
@@ -211,33 +242,40 @@
                        model.HMakeDate = DateTime.Now;
                        model.HMaker = ClsPub.CurUserName;
                        if (model.HPieceQty <= 0 || model.HPieceQty.ToString() == "")
                        if (model.HQty <= 0 || model.HQty.ToString() == "")
                        {
                            MessageBox.Show("第" + ClsPub.isStrNull(i + 1) + "行,拆分数量必须大于0!");
                            MessageBox.Show("页2第" + ClsPub.isStrNull(i + 1) + "行,拆分数量必须大于0!");
                            return false;
                        }
                        sum += model.HQty;
                        BillNew.DetailColl_Mater.Add(model);
                    }
                    else
                    {
                        break;
                    }
                }
                //保存
                bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                //提示
                if (bResult == true)
                if (sum > DBUtility.ClsPub.isDoule(grdMain.Rows[0].Cells[HQty].Value))
                {
                    MessageBox.Show("单据存盘完毕!单据号:" + this.txtHBillNo.Text.Trim(), "提示");
                    return true;
                     MessageBox.Show("页2拆分数量之和必须小于条码数量!");
                    return false;
                }
                else
                {
                    MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示");
                    return false;
                    //保存
                    bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo, HBillNo);
                    //提示
                    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)
@@ -295,5 +333,118 @@
        {
            this.Close();
        }
        GridppReport Report;
        private void yl_Click(object sender, EventArgs e)
        {
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = "条码档案列表";
            oFrm.ShowDialog();
            if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
            {
                Sub_SetReport(oFrm.sOpenTmp);
                Report.PrintPreview(false);
                Thread.Sleep(1000);
            }
        }
        private void dy_Click(object sender, EventArgs e)
        {
            //打印前判断条码是否已打印过
            string sBarCode = "";
            string sRelQty = "";
            int i = 0;
            DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
            if (ClsPub.isLong(grdMain_Pay.Rows[0].Cells[HSnoCol2].Value) == 0)
            {
                MessageBox.Show("请先生成拆码条码!");
            }
            while (ClsPub.isLong(grdMain_Pay.Rows[i].Cells[HSnoCol2].Value) != 0)
            {
                sBarCode = sBarCode + "," + DBUtility.ClsPub.isStrNull(grdMain_Pay.Rows[i].Cells[HBarCode2].Value);
                i++;
            }
            //选择打印模板
            BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
            oFrm.sBillName = ModName;
            oFrm.sBillModel = "条码档案列表";
            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 Sub_SetReport(string sOpenTmp)
        {
            //判断行数
            for (int i = 0; i < grdMain_Pay.Rows.Count; i++)
            {
                grdMain_Pay.Rows[i].Cells[0].Value = "";
            }
            for (int i = 0; i < grdMain_Pay.SelectedRows.Count; i++)
            {
                grdMain_Pay.Rows[grdMain_Pay.SelectedRows[i].Index].Cells[0].Value = "*";
            }
            //
            Report = new GridppReport();
            Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf");  //here .
            Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
            Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
        }
        //填入单据表头信息
        private void ReportBeforePostRecord()//your report?kao
        {
            try
            {
                //Report.FieldByName("物料代码").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("物料代码")].Value.ToString();
                //Report.FieldByName("物料名称").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("物料名称")].Value.ToString();
                //Report.FieldByName("规格型号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("规格型号")].Value.ToString();
                //Report.FieldByName("自定义规格").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("自定义规格")].Value.ToString();
                //Report.FieldByName("条码编号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("条码编号")].Value.ToString();
                //Report.FieldByName("数量").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("数量")].Value.ToString();
                //Report.FieldByName("批次").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("批号")].Value.ToString();
                //Report.FieldByName("源单单号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("源单单号")].Value.ToString();
                //Report.FieldByName("销售订单号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("销售订单号")].Value.ToString();
                //Report.FieldByName("采购订单号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("采购订单号")].Value.ToString();
                //Report.FieldByName("供应商").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("往来单位")].Value.ToString();
                //Report.FieldByName("生产车间").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("生产车间")].Value.ToString();
                //Report.FieldByName("备注").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("备注")].Value.ToString();
                //Report.FieldByName("总托数").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("总托数")].Value.ToString();
                //Report.FieldByName("托号").AsString = grdMain.Rows[CurRows].Cells[Fun_GetCol("托号")].Value.ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表头:" + e.Message);
            }
            //CurRows = CurRows + 1;
        }
        private void ReportFetchRecordByDataTable()
        {
            try
            {
                DataTable ds = new DataTable();
                BLL.Utility.FillRecordToReport_Sel(Report, grdMain_Pay, ds, Fun_GetCol("序号"));
            }
            catch (Exception e)
            {
                MessageBox.Show("打印失败!表体:" + e.Message);
            }
        }
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain_Pay);
        }
    }
}