using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using gregn6Lib; using Pub_Class; using System.Threading; namespace WarM { public partial class Gy_BarCodeBill_XiaBao : Form { public Gy_BarCodeBill_XiaBao() { InitializeComponent(); } //定义 public const Int16 HTagCol = 0; public const Int16 HSnoCol = 1; public const Int16 HMainIDCol = 2; public const Int16 HSubIDCol = 3; public const Int16 HBillNoCol = 4; public const Int16 HBillTypeCol = 5; public const Int16 HMaterIDCol = 6; public const Int16 HMaterNumberCol = 7; public const Int16 HMaterNameCol = 8; public const Int16 HPinfanCol = 9; public const Int16 HMaterModelCol = 10; public const Int16 HAuxPropIDCol = 11; public const Int16 HAuxPropNumberCol = 12; public const Int16 HAuxPropNameCol = 13; public const Int16 HBatchManagerCol = 14; public const Int16 HBatchNoCol = 15; public const Int16 HBarCodeTypeCol = 16; public const Int16 HQtyCol = 17; public const Int16 HMinQtyCol = 18; public const Int16 HBQtyCol = 19; public const Int16 HinitQtyCol = 20; public const Int16 HISKFPERIODCol = 21; public const Int16 HProduceDateCol = 22; public const Int16 HExpiryDateCol = 23; public const Int16 HEXPUNITCol = 24; public const Int16 HEXPPERIODCol = 25; public const Int16 HGiveAwayFlagCol = 26; public const Int16 HUnitIDCol = 27; public const Int16 HUnitNumberCol = 28; public const Int16 HUnitNameCol = 29; public const Int16 HWhIDCol = 30; public const Int16 HWhNumberCol = 31; public const Int16 HWhNameCol = 32; public const Int16 HSPIDCol = 33; public const Int16 HSPNumberCol = 34; public const Int16 HSPNameCol = 35; public const Int16 HMTONoCol = 36; public const Int16 HRemarkCol = 37; public const Int16 HDeptIDCol = 38; public const Int16 HDeptNumberCol = 39; public const Int16 HDeptNameCol = 40; public const Int16 HSourceIDCol = 41; public const Int16 HSourceNumberCol = 42; public const Int16 HSourceNameCol = 43; public const Int16 HSupIDCol = 44; public const Int16 HSupNumberCol = 45; public const Int16 HSupNameCol = 46; public const Int16 HGroupIDCol = 47; public const Int16 HGroupNumberCol = 48; public const Int16 HGroupNameCol = 49; public const Int16 HCusIDCol = 50; public const Int16 HCusNumberCol = 51; public const Int16 HCusNameCol = 52; public const Int16 HCusTypeCol = 53; public const Int16 HSeOrderBillNoCol = 54; public const Int16 HSeOrderSEQCol = 55; public const Int16 HInnerBillNoCol = 56; public const Int16 HEndDateCol = 57; public const Int16 HSourceBillQtyCol = 58; public const Int16 HAuxPropFlagCol = 59; public const Int16 HBarCodeCol = 60; //条码编号 public const Int16 HTMNumberCol = 61; //条码前缀 public const Int16 HLSHCol = 62; //生成条码时获取对应流水号 public const Int16 HBarcodeNoCol = 63; //记录需回填的流水号数量 // public string ModName = "85"; public string ModCaption = "调拨条码生成"; public const string ModRightName = "Gy_BarCodeBill_XiaBao"; public DBUtility.ClsPub.Enum_BillStatus BillStatus; public DBUtility.ClsXt_BaseBill BaseBill; public DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl(); ClsGridViewSum oSumGrid = new ClsGridViewSum(); SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); public Frm_Split oDlg = new Frm_Split(); public bool grdStatus; public int selectRow = 0; public Int64 HInterID = 0; //内码 public Int64 HOrgID = ClsPub.HOrgID; public string HOrgNumber = ClsPub.HOrgNumber; public string HOrgName = ClsPub.HOrgName; public string ERPMode = ""; //ERP模式(WISE、CLOUD) public string CampanyName = ""; //客户定制化名称 public string SourceQtyCtl = ""; //超源单数量控制 public long PrintQty = 0; //允许条码打印次数 public string PrintQtyCtl = ""; //条码打印次数控制 public string UpdatePrintQtyCtl = ""; //条码打印次数更新 public string sReturn = ""; public string HExpiryDate = ""; #region 固定代码 //清空界面 public void Sub_ClearBill() { cmbSourceBillType.Items.Clear(); cmbSourceBillType.Items.Add("调拨申请单"); DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp); //获取当前组织 DataSet Ds1 = oCn.RunProcReturn("select * from Xt_ORGANIZATIONS with(nolock) where HItemID=" + ClsPub.HOrgID, "Xt_ORGANIZATIONS", ref DBUtility.ClsPub.sExeReturnInfo); if (Ds1.Tables[0].Rows.Count != 0) { cmbHOrgID.Text = DBUtility.ClsPub.isStrNull(Ds1.Tables[0].Rows[0]["HName"]); } txtHMaker.Text = ClsPub.CurUserName; txtHMakeDate.Text = ""; txtHChecker.Text = ""; txtHCheckDate.Text = ""; txtHCloseMan.Text = ""; txtHCloseDate.Text = ""; txtHDeleteMan.Text = ""; txtHDeleteDate.Text = ""; txtHUpDater.Text = ""; txtHUpDateDate.Text = ""; initGrid(); grdList.DataSource = null; } //保存列宽 private void bclk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); DBUtility.Xt_BaseBillFun.SaveGrid(grdList, this.Name + "grdList"); } //默认列宽 private void mrlk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name); DBUtility.Xt_BaseBillFun.DefaultGridView(grdList, this.Name + "grdList"); } //增行按钮 private void AddRow_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.AddRow(oSumGrid); //设置特殊列 for (int i = 0; i < grdMain.Rows.Count; i++) { //网格打勾 //是否启用辅助属性 DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell(); oCell.ThreeState = false; oCell.Value = grdMain.Rows[i].Cells[HAuxPropFlagCol].Value != null ? grdMain.Rows[i].Cells[HAuxPropFlagCol].Value : 0; oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HAuxPropFlagCol] = oCell; //是否启用批次 DataGridViewCheckBoxCell oCell1 = new DataGridViewCheckBoxCell(); oCell1.ThreeState = false; oCell1.Value = grdMain.Rows[i].Cells[HBatchManagerCol].Value != null ? grdMain.Rows[i].Cells[HBatchManagerCol].Value : 0; oCell1.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HBatchManagerCol] = oCell1; //是否启用保质期 DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell(); oCell2.ThreeState = false; oCell2.Value = grdMain.Rows[i].Cells[HISKFPERIODCol].Value != null ? grdMain.Rows[i].Cells[HISKFPERIODCol].Value : 0; oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HISKFPERIODCol] = oCell2; //是否赠品 DataGridViewCheckBoxCell oCell3 = new DataGridViewCheckBoxCell(); oCell3.ThreeState = false; oCell3.Value = grdMain.Rows[i].Cells[HGiveAwayFlagCol].Value != null ? grdMain.Rows[i].Cells[HGiveAwayFlagCol].Value : 0; oCell3.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HGiveAwayFlagCol] = oCell3; //网格下拉选择框 DataGridViewComboBoxCell column = new DataGridViewComboBoxCell(); column.Items.Add("唯一条码"); grdMain.Rows[i].Cells[HBarCodeTypeCol] = column; if(ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0) { grdMain.Rows[i].Cells[HBarCodeTypeCol].Value = "唯一条码"; } } } //删行按纽 private void DelRow_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.DelRow(oSumGrid); //设置特殊列 //网格打勾 //是否启用辅助属性 DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell(); oCell.ThreeState = false; oCell.Value = 0; oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count-1].Cells[HAuxPropFlagCol] = oCell; //是否启用批次 DataGridViewCheckBoxCell oCell1 = new DataGridViewCheckBoxCell(); oCell1.ThreeState = false; oCell1.Value = 0; oCell1.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count - 1].Cells[HBatchManagerCol] = oCell1; //是否启用保质期 DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell(); oCell2.ThreeState = false; oCell2.Value = 0; oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count - 1].Cells[HISKFPERIODCol] = oCell2; //是否赠品 DataGridViewCheckBoxCell oCell3 = new DataGridViewCheckBoxCell(); oCell3.ThreeState = false; oCell3.Value = 0; oCell3.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count - 1].Cells[HGiveAwayFlagCol] = oCell3; //网格下拉选择框 DataGridViewComboBoxCell column = new DataGridViewComboBoxCell(); column.Items.Add("唯一条码"); grdMain.Rows[grdMain.Rows.Count - 1].Cells[HBarCodeTypeCol] = column; } //保存按钮 private void bc_Click(object sender, EventArgs e) { this.Sub_SaveBill(); Display(); } //重置按纽 private void cz_Click(object sender, EventArgs e) { if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew || BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify) { if (MessageBox.Show("确定要清空当前界面信息,重置界面?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { this.Sub_AddBill(); } } grdMain.Columns[HBillNoCol].ReadOnly = false; tabControl1.SelectedIndex = 0; } //新增单据 private void Sub_AddBill() { this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; this.Sub_OperStatus();//设置TOOLBAR this.Sub_ClearBill();//清空界面 } //退出按钮 private void tc_Click(object sender, EventArgs e) { this.Close(); } //离开单元格 private void grdMain_LeaveCell(object sender, EventArgs e) { oSumGrid.LeaveCell(); } //网格单元格变化事件 private void grdMain_RowColChange(object sender, EventArgs e) { if (!grdStatus) { return; } DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); // //if (oSumGrid.Changelock) // return; //if(oSumGrid.EditStatus) //{ if (!CheckGridRow(oSumGrid.OldCell.Row)) return; //} } private void Gy_BarCodeBill_XiaBao_Paint(object sender, PaintEventArgs e)//画线 { Graphics g = this.panel2.CreateGraphics(); Pen p = new Pen(Color.Gray); p.Width = 1; g.DrawLine(p, new Point(txtHMaker.Left, txtHMaker.Top + txtHMaker.Height), new Point(txtHMaker.Left + txtHMaker.Width, txtHMaker.Top + txtHMaker.Height)); g.DrawLine(p, new Point(txtHMakeDate.Left, txtHMakeDate.Top + txtHMakeDate.Height), new Point(txtHMakeDate.Left + txtHMakeDate.Width, txtHMakeDate.Top + txtHMakeDate.Height)); // g.DrawLine(p, new Point(txtHChecker.Left, txtHChecker.Top + txtHChecker.Height), new Point(txtHChecker.Left + txtHChecker.Width, txtHChecker.Top + txtHChecker.Height)); g.DrawLine(p, new Point(txtHCheckDate.Left, txtHCheckDate.Top + txtHCheckDate.Height), new Point(txtHCheckDate.Left + txtHCheckDate.Width, txtHCheckDate.Top + txtHCheckDate.Height)); // g.DrawLine(p, new Point(txtHCloseMan.Left, txtHCloseMan.Top + txtHCloseMan.Height), new Point(txtHCloseMan.Left + txtHCloseMan.Width, txtHCloseMan.Top + txtHCloseMan.Height)); g.DrawLine(p, new Point(txtHCloseDate.Left, txtHCloseDate.Top + txtHCloseDate.Height), new Point(txtHCloseDate.Left + txtHCloseDate.Width, txtHCloseDate.Top + txtHCloseDate.Height)); // g.DrawLine(p, new Point(this.txtHDeleteMan.Left, txtHDeleteMan.Top + txtHDeleteMan.Height), new Point(txtHDeleteMan.Left + txtHDeleteMan.Width, txtHDeleteMan.Top + txtHDeleteMan.Height)); g.DrawLine(p, new Point(txtHDeleteDate.Left, txtHDeleteDate.Top + txtHDeleteDate.Height), new Point(txtHDeleteDate.Left + txtHDeleteDate.Width, txtHDeleteDate.Top + txtHDeleteDate.Height)); // g.DrawLine(p, new Point(this.txtHUpDater.Left, txtHUpDater.Top + txtHUpDater.Height), new Point(txtHUpDater.Left + txtHUpDater.Width, txtHUpDater.Top + txtHUpDater.Height)); g.DrawLine(p, new Point(txtHUpDateDate.Left, txtHUpDateDate.Top + txtHUpDateDate.Height), new Point(txtHUpDateDate.Left + txtHUpDateDate.Width, txtHUpDateDate.Top + txtHUpDateDate.Height)); //控件位置设置 } //控件位置 private void Sub_ControlLocation() { //gbUp.Width = P1.Width - 20; //gbUp.Left = 10; //gbUp.Height = P1.Height - 35; //gbUp.Top = 30; } //窗体加载 private void Gy_BarCodeBill_XiaBao_Load(object sender, EventArgs e) { //打印初始化 oSumGrid.NoCol = HSnoCol; oSumGrid.ogrdMain = grdMain; oSumGrid.oGridsum = grdSum; this.Text = ModCaption; this.lblCaption.Text = ModCaption; //加载组织信息 Sub_AddOrdList(); //获取系统参数 ClsXt_SystemParameter oSystemParameter = new ClsXt_SystemParameter(); if (oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo) == false) { MessageBox.Show("获取系统参数失败!原因:" + DBUtility.ClsPub.sExeReturnInfo, "提示"); return; } else { ERPMode = oSystemParameter.omodel.WMS_WMSStockCtl_ERPMode; //ERP模式(WISE、CLOUD) CampanyName = oSystemParameter.omodel.WMS_CampanyName; //客户定制化名称 SourceQtyCtl = oSystemParameter.omodel.BarCode_SourceQtyCtl; //超源单数量控制 PrintQty = oSystemParameter.omodel.BarCode_PrintQty; //允许条码打印次数 PrintQtyCtl = oSystemParameter.omodel.BarCode_PrintQtyCtl; //条码打印次数控制 UpdatePrintQtyCtl = oSystemParameter.omodel.BarCode_UpdatePrintQtyCtl; //条码打印次数更新 } } //加载组织信息 private void Sub_AddOrdList() { DataSet ds; DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View(); ds = oClsGy_ORGANIZATIONS_View.GetList(); if (ds == null || ds.Tables[0].Rows.Count == 0) { MessageBox.Show("获取组织失败"); return; } cmbHOrgID.DataSource = null; cmbHOrgID.Items.Clear(); cmbHOrgID.DataSource = ds.Tables[0]; cmbHOrgID.DisplayMember = "HName"; cmbHOrgID.ValueMember = "HItemID"; } //窗体尺寸变化时 private void Gy_BarCodeBill_XiaBao_Resize(object sender, EventArgs e) { //Sub_ControlLocation(); } //根据编辑状态 设置 控件是否允许录入 private void Sub_LrtextStatus(bool TextEnabled) { if (TextEnabled == true) { //控件全部有效 gbUp.Enabled = true; grdMain.BackColor = ClsPub.EditColor; } else { //控件全部无效 gbUp.Enabled = false; grdMain.BackColor = ClsPub.ViewColor; } } //timer private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; Sub_ControlLocation(); if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View) { //this.Sub_ShowBill(); } else { this.Sub_AddBill(); } DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } //窗体卸载 private void Gy_BarCodeBill_XiaBao_FormClosing(object sender, FormClosingEventArgs e) { BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); } //TOOLBAR状态 按钮是否灰度 public void Sub_OperStatus() { switch (BillStatus) { case DBUtility.ClsPub.Enum_BillStatus.BillStatus_View: //浏览状态 yl.Enabled = true; AddRow.Enabled = false; DelRow.Enabled = false; bc.Enabled = false; cz.Enabled = false; tc.Enabled = true; //未审核 if (txtHChecker.Text.Trim() == "") { //未审核 pic1.Visible = false; pic1.Image = null; // } else if (txtHCloseMan.Text.Trim() == "" && txtHChecker.Text.Trim() != "")//审核未关闭 { // pic1.Visible = true; pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Checked.jpg"); // } else//已关闭 { // pic1.Visible = true; pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Closed.jpg"); // } if (txtHDeleteMan.Text.Trim() == "") { } else //已作废 { AddRow.Enabled = false; DelRow.Enabled = false; bc.Enabled = false; cz.Enabled = false; // pic1.Visible = true; pic1.Image = System.Drawing.Image.FromFile(ClsPub.AppPath + @"/Pic/Deleted.jpg"); // } Sub_LrtextStatus(false); grdStatus = false; break; case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew: //新增状态 yl.Enabled = true; AddRow.Enabled = true; DelRow.Enabled = true; bc.Enabled = true; cz.Enabled = true; tc.Enabled = true; Sub_LrtextStatus(true); grdStatus = true; //未审核 pic1.Visible = false; pic1.Image = null; // break; case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify: //修改状态 yl.Enabled = true; AddRow.Enabled = true; DelRow.Enabled = true; bc.Enabled = true; cz.Enabled = true; tc.Enabled = true; Sub_LrtextStatus(true); grdStatus = true; //未审核 pic1.Visible = false; pic1.Image = null; // break; } } #endregion #region 生成条码 private bool Sub_SaveBill() { //获取内码 HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo); lblCaption.Focus(); //生成条码前控制 if (!Sub_AllowSave()) { return false; } bc.Enabled = false; SaveBarCode(); return true; } #region 生成条码前控制 private bool Sub_AllowSave() { string sHRemark = ""; string sHRemark2 = ""; //明细表是否为零行 bool b = false; for (int i = 0; i < grdMain.RowCount; i++) { if (!IsNullRow(i)) { b = true; break; } } if (b == false) { MessageBox.Show("明细行不存在!", "提示"); return false; } for (int j = 0; j < grdMain.Rows.Count; j++) { sHRemark2 = ""; long HSno = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HSnoCol].Value); // 序号 long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value); // 物料内码 string HMaterNumber = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNumberCol].Value); // 物料代码 bool HBatchManager = DBUtility.ClsPub.isBool(grdMain.Rows[j].Cells[HBatchManagerCol].Value); // 是否启用批号 string HBatchNo = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value); // 批号 bool HAuxPropFlag = DBUtility.ClsPub.isBool(grdMain.Rows[j].Cells[HAuxPropFlagCol].Value); // 是否启用辅助属性 long HAuxPropID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HAuxPropIDCol].Value); // 辅助属性ID double HMinQty = DBUtility.ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value); // 最小包装数 bool HISKFPERIOD = DBUtility.ClsPub.isBool(grdMain.Rows[j].Cells[HISKFPERIODCol].Value); // 是否启用保质期 DateTime HProduceDate = DBUtility.ClsPub.isDate(grdMain.Rows[j].Cells[HProduceDateCol].Value); // 生产日期 string HEXPUNIT = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEXPUNITCol].Value); // 保质期单位 long HEXPPERIOD = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HEXPPERIODCol].Value); // 保质期 if (HMaterID != 0) { if(HMinQty<=0) { sHRemark2 = sHRemark2 + "重量不允许小于等于0;"; } if (HBatchManager && HBatchNo=="") { sHRemark2 = sHRemark2 + "物料启用批次管理,批次不允许为空;"; } else if (!HBatchManager && HBatchNo != "") { sHRemark2 = sHRemark2 + "物料未启用批次管理,不允许有批次;"; } if (HAuxPropFlag && HAuxPropID == 0) { sHRemark2 = sHRemark2 + "物料启用辅助属性管理,辅助属性不允许为空;"; } else if (!HAuxPropFlag && HAuxPropID != 0) { sHRemark2 = sHRemark2 + "物料未启用辅助属性管理,不允许有辅助属性;"; } if (HISKFPERIOD && (HEXPUNIT=="" || HEXPPERIOD==0)) { sHRemark2 = sHRemark2 + "物料启用保质期管理,物料基础资料中的保质期单位、保质期不允许为空;"; } //判断录入的生产日期、有效期至是否正确 if (HISKFPERIOD && HProduceDate < DBUtility.ClsPub.isDate("2000-01-01")) { sHRemark2 = sHRemark2 + "启用保质期管理,生产日期录入错误;"; } else if (HISKFPERIOD && ClsPub.isStrNull(grdMain.Rows[j].Cells[HExpiryDateCol].Value) == "") { sHRemark2 = sHRemark2 + "启用保质期管理,有效期至不能为空;"; } if (sHRemark2 != "") { sHRemark = sHRemark + " 第" + HSno + "行,物料:" + HMaterNumber + sHRemark2; } } } if (sHRemark != "") { MessageBox.Show(sHRemark); return false; } return true; } #endregion #region 生成条码 private void SaveBarCode() { try { string TM = ""; //条码 int LSHlen = 6; //流水号长度 double HMinQty = 0; //最小包装数 Int64 HBQty = 0; //箱数 Int64 LSH = 0; //流水号 string LSH2 = ""; //流水号转换成字符 string sDate = ""; //日期 string sYear = ""; //年 string sPeriod = ""; //月 string sDay = ""; //日 string sMaterID = ""; //物料ID转换成字符 string sTMNumber = ""; //条码自定义前缀 DataSet Ds; pb1.Value = 0; Int64 HEntryID = 0; //子ID string HBarCode = ""; //条形码 string HBarCodeType = ""; //条码类型 Int64 HMaterID = 0; //物料ID Int64 HUnitID = 0; //计量单位ID Int64 HAuxPropID = 0; //辅助属性ID string HBatchNo = ""; //批次号 string HMTONo = ""; //MTO号 double HQty = 0; //数量 double HinitQty = 0; //初始化数量(生成条码时数量) double HSourceBillQty = 0; //源单可生成条码数量 bool HGiveAwayFlag = false; //是否赠品 string HProduceDate; //生产日期(保质期用) string HExpiryDate; //保质期至(保质期用) bool HISKFPERIOD = false; //是否启用保质期 string HEXPUNIT = ""; //保质期单位 double HEXPPERIOD = 0; //保质期 Int64 HWhID = 0; //仓库ID Int64 HSPID = 0; //仓位ID Int64 HBarcodeQtys = 0; //总托数 Int64 HBarcodeNo = 0; //当前托号 string HEndQty = ""; //尾数 Int64 HSourceInterID = 0; //源单ID Int64 HSourceEntryID = 0; //源单子ID string HSourceBillNo = ""; //源单单号 string HSourceBillType = ""; //源单类型 Int64 HInitSourceEntryID = 0; //初始化源单子ID(生成条码时源单子ID) string HRemark = ""; //备注 Int64 HPrintQty = 0; //打印次数 Int64 HSTOCKORGID = 0; //组织ID Int64 HOWNERID = 0; //货主ID Int64 HDeptID = 0; //部门ID Int64 HSupID = 0; //往来单位ID Int64 HGroupID = 0; //生产班组ID Int64 HCusID = 0; //客户ID string HCusType = ""; //客户型号 string HSeOrderBillNo = ""; //销售订单号 Int64 HSeOrderSEQ = 0; //销售订单行号 string HInnerBillNo = ""; //内部采购订单号 string HWorkLineName = ""; //生产线 string HMaterName = ""; //产品名称 string HMaterModel = ""; //产品规格型号 string HPinfan = ""; //品番 DateTime HEndDate; //计划完工日期 oCn.BeginTran(); Application.DoEvents(); pb1.Maximum = grdMain.Rows.Count; //日期获取方式 sDate = dtpHDate.Value.ToShortDateString(); sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2); sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString(); sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2); sDay = "0" + ClsPub.isDate(sDate).Day.ToString(); sDay = sDay.Substring(sDay.Length - 2, 2); //获取第行对应条码编号、流水号信息等 for (int j = 0; j < grdMain.Rows.Count; j++) { if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0) { sMaterID = ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterIDCol].Value); HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value); HBarCodeType = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBarCodeTypeCol].Value); if (HBarCodeType == "唯一条码") { LSH = 0; LSH2 = ""; //条码前缀 = 组织代码 + 物料代码 + 年 + 月 + 日 sTMNumber = HOrgNumber + sMaterID + sYear + sPeriod + sDay; //循环判断该行前面所有行中是否存在相同物料 for (int i = 0; i < j; i++) { if(ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value)== ClsPub.isLong(grdMain.Rows[j - i - 1].Cells[HMaterIDCol].Value)) { LSH = ClsPub.isLong(grdMain.Rows[j - i - 1].Cells[HLSHCol].Value); HBarcodeNo = ClsPub.isLong(grdMain.Rows[j - i - 1].Cells[HBarcodeNoCol].Value); break; } } //该行前面所有行不存在与该行物料相同的行,获取最大流水号 if (LSH == 0) { Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo"); //获取最大流水号 LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]); LSH = LSH + 1; LSH2 = LSH.ToString(); while (LSH2.Length < LSHlen) //如果流水号位数小于 LSHlen 前面补0 { LSH2 = "0" + LSH2; } //条码编号 = 条码前缀 + 流水号 TM = sTMNumber + LSH2; grdMain.Rows[j].Cells[HBarCodeCol].Value = TM; grdMain.Rows[j].Cells[HTMNumberCol].Value = sTMNumber; grdMain.Rows[j].Cells[HLSHCol].Value = LSH; grdMain.Rows[j].Cells[HBarcodeNoCol].Value = 1; } //该行前面所有行中存在与该行物料相同的行,获取与该行相同物料的前一行流水号 else { LSH = LSH + 1; LSH2 = LSH.ToString(); while (LSH2.Length < LSHlen) //如果流水号位数小于 LSHlen 前面补0 { LSH2 = "0" + LSH2; } //条码编号 = 条码前缀 + 流水号 TM = sTMNumber + LSH2; grdMain.Rows[j].Cells[HBarCodeCol].Value = TM; grdMain.Rows[j].Cells[HTMNumberCol].Value = sTMNumber; grdMain.Rows[j].Cells[HLSHCol].Value = LSH; grdMain.Rows[j].Cells[HBarcodeNoCol].Value = HBarcodeNo + 1; } } else if (HBarCodeType == "品种条码") { TM = HOrgNumber + sMaterID; grdMain.Rows[j].Cells[HBarCodeCol].Value = TM; } else if (HBarCodeType == "批次条码") { TM = HOrgNumber + sMaterID + HBatchNo; grdMain.Rows[j].Cells[HBarCodeCol].Value = TM; } else { MessageBox.Show("错误的条码类型,不能生成条码!"); bc.Enabled = true; oCn.RollBack(); return; } } } //将条码信息写入条码档案 for (int j = 0; j < grdMain.Rows.Count; j++) { if (ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value) != 0) { HBQty = ClsPub.isLong(grdMain.Rows[j].Cells[HBQtyCol].Value); HMinQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HMinQtyCol].Value); HEntryID = j + 1; HBarCode = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBarCodeCol].Value); HMaterID = ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value); HUnitID = ClsPub.isLong(grdMain.Rows[j].Cells[HUnitIDCol].Value); HAuxPropID = ClsPub.isLong(grdMain.Rows[j].Cells[HAuxPropIDCol].Value); HBatchNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBatchNoCol].Value); HMTONo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HMTONoCol].Value); HQty = HMinQty; HinitQty = HMinQty; HSourceBillQty = ClsPub.isDoule(grdMain.Rows[j].Cells[HSourceBillQtyCol].Value); HGiveAwayFlag = ClsPub.isBool(grdMain.Rows[j].Cells[HGiveAwayFlagCol].Value); HISKFPERIOD = ClsPub.isBool(grdMain.Rows[j].Cells[HISKFPERIODCol].Value); if (HISKFPERIOD) { HProduceDate = ClsPub.isStrNull(ClsPub.isDate(grdMain.Rows[j].Cells[HProduceDateCol].Value)); HExpiryDate = ClsPub.isStrNull(grdMain.Rows[j].Cells[HExpiryDateCol].Value); } else { HProduceDate = ""; HExpiryDate = ""; } HEXPUNIT = ClsPub.isStrNull(grdMain.Rows[j].Cells[HEXPUNITCol].Value); HEXPPERIOD = ClsPub.isDoule(grdMain.Rows[j].Cells[HEXPPERIODCol].Value); HWhID = ClsPub.isLong(grdMain.Rows[j].Cells[HWhIDCol].Value); HSPID = ClsPub.isLong(grdMain.Rows[j].Cells[HSPIDCol].Value); HBarcodeQtys = HBQty; HBarcodeNo = ClsPub.isLong(grdMain.Rows[j].Cells[HBarcodeNoCol].Value); HSourceInterID = ClsPub.isLong(grdMain.Rows[j].Cells[HMainIDCol].Value); HSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[HSubIDCol].Value); HSourceBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBillNoCol].Value); HSourceBillType = ClsPub.isStrNull(grdMain.Rows[j].Cells[HBillTypeCol].Value); HInitSourceEntryID = ClsPub.isLong(grdMain.Rows[j].Cells[HSubIDCol].Value); HRemark = ClsPub.isStrNull(grdMain.Rows[j].Cells[HRemarkCol].Value); HPrintQty = 0; HSTOCKORGID = HOrgID; HOWNERID = HOrgID; HDeptID = ClsPub.isLong(grdMain.Rows[j].Cells[HDeptIDCol].Value); HSupID = ClsPub.isLong(grdMain.Rows[j].Cells[HSupIDCol].Value); HGroupID = ClsPub.isLong(grdMain.Rows[j].Cells[HGroupIDCol].Value); HCusID = ClsPub.isLong(grdMain.Rows[j].Cells[HCusIDCol].Value); HCusType = ClsPub.isStrNull(grdMain.Rows[j].Cells[HCusTypeCol].Value); HSeOrderBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HSeOrderBillNoCol].Value); HSeOrderSEQ = ClsPub.isLong(grdMain.Rows[j].Cells[HSeOrderSEQCol].Value); HInnerBillNo = ClsPub.isStrNull(grdMain.Rows[j].Cells[HInnerBillNoCol].Value); HWorkLineName = ClsPub.isStrNull(grdMain.Rows[j].Cells[HSourceNameCol].Value); HMaterName = ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterNameCol].Value); HMaterModel = ClsPub.isStrNull(grdMain.Rows[j].Cells[HMaterModelCol].Value); HPinfan = ClsPub.isStrNull(grdMain.Rows[j].Cells[HPinfanCol].Value); HEndDate = ClsPub.isDate(grdMain.Rows[j].Cells[HEndDateCol].Value); oCn.RunProc("insert into Gy_BarCodeBill" + "(HInterID,HEntryID,HBarCode,HBarCodeType,HMaterID,HUnitID" + ",HAuxPropID,HBatchNo,HMTONo,HQty,HinitQty,HSourceBillQty" + ",HProduceDate,HExpiryDate" + ",HISKFPERIOD,HEXPUNIT,HEXPPERIOD,HBarCodeDate,HGiveAwayFlag" + ",HWhID,HSPID,HBarcodeQtys,HBarcodeNo,HEndQty" + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HInitSourceEntryID,HRemark" + ",HPrintQty,HSTOCKORGID,HOWNERID,HDeptID,HSupID,HGroupID" + ",HCusID,HCusType,HSeOrderBillNo,HSeOrderSEQ,HInnerBillNo,HWorkLineName" + ",HMaterName,HMaterModel,HPinfan,HEndDate,HMaker,HMakeDate" + ") values (" + " " + HInterID.ToString() + "," + HEntryID.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + ", " + HAuxPropID.ToString() + ",'" + HBatchNo + "','" + HMTONo + "'," + HQty.ToString() + "," + HinitQty.ToString() + "," + HSourceBillQty.ToString() + ", " + (HProduceDate == "" ? "NULL" : "'" + HProduceDate + "'") + "," + (HExpiryDate == "" ? "NULL" : "'" + HExpiryDate + "'") + ", " + DBUtility.ClsPub.BoolToString(HISKFPERIOD) + ",'" + HEXPUNIT + "'," + HEXPPERIOD.ToString() + ",'" + sDate + "'," + DBUtility.ClsPub.BoolToString(HGiveAwayFlag) + ", " + HWhID.ToString() + "," + HSPID.ToString() + "," + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + ",'" + HEndQty + "'" + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "'," + HInitSourceEntryID.ToString() + ",'" + HRemark + "'" + ", " + HPrintQty.ToString() + "," + HSTOCKORGID.ToString() + "," + HOWNERID.ToString() + "," + HDeptID.ToString() + "," + HSupID.ToString() + "," + HGroupID.ToString() + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HSeOrderBillNo + "'," + HSeOrderSEQ.ToString() + ",'" + HInnerBillNo + "','" + HWorkLineName + "'" + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "','" + HEndDate.ToShortDateString() + "','" + ClsPub.CurUserName + "',getdate()" + ")"); } pb1.Value = j + 1; } //回填流水号信息 int nn = 0; //本次流水号累计使用个数 for (int j = 0; j < grdMain.Rows.Count; j++) { nn = 0; sTMNumber = ""; if (ClsPub.isLong(grdMain.Rows[grdMain.Rows.Count-j-1].Cells[HMaterIDCol].Value) != 0) { //获取物料不为空的最后一行的物料对应条码前缀、需累计回填的流水号数 if(j==0) { sTMNumber = ClsPub.isStrNull(grdMain.Rows[grdMain.Rows.Count - j - 1].Cells[HTMNumberCol].Value); nn = ClsPub.isInt(grdMain.Rows[grdMain.Rows.Count - j - 1].Cells[HBarcodeNoCol].Value); //回填流水号信息 oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "'," + nn.ToString() + " "); } else { //循环判断该行后面的所有行是否存在和该行物料相同的行,如不存在 则回填对应流水号信息,存在则不回填流水号信息 bool b = false; for (int i = 0; i < j; i++) { if (ClsPub.isLong(grdMain.Rows[grdMain.Rows.Count - j - 1].Cells[HMaterIDCol].Value) == ClsPub.isLong(grdMain.Rows[grdMain.Rows.Count - i - 1].Cells[HMaterIDCol].Value)) { b = true; break; } } if (b == false) { sTMNumber = ClsPub.isStrNull(grdMain.Rows[grdMain.Rows.Count - j - 1].Cells[HTMNumberCol].Value); nn = ClsPub.isInt(grdMain.Rows[grdMain.Rows.Count - j - 1].Cells[HBarcodeNoCol].Value); //回填流水号信息 oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "'," + nn.ToString() + " "); } } } } oCn.Commit(); MessageBox.Show("条码生成完毕!"); tabControl1.SelectedIndex = 1; } catch (Exception e) { bc.Enabled = true; oCn.RollBack(); MessageBox.Show("条码生成失败!" + e.Message); } } #endregion #region 刷新条码列表 private void Display() { DataSet DSet = oCn.RunProcReturn("select * from h_v_IF_BarCodeBillList where HInterID=" + HInterID.ToString() + " 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 GraphLine() { int MainIDCol = Fun_GetCol("hmainid"); int SubIDCol = Fun_GetCol("hsubid"); string s = "是"; long n = 0; DBUtility.Xt_BaseBillFun.GraphLine(grdList, MainIDCol, SubIDCol, s, ref n); } #endregion #endregion #region 窗体处理方法 //初始化GRID private void initGrid() { grdMain.RowCount = 0; grdMain.ColumnCount = 64; //总列数 DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); grdMain.Columns[HSnoCol].HeaderText = "序号"; grdMain.Columns[HMainIDCol].HeaderText = "源单主ID"; grdMain.Columns[HSubIDCol].HeaderText = "源单子ID"; grdMain.Columns[HBillNoCol].HeaderText = "源单单号"; grdMain.Columns[HBillTypeCol].HeaderText = "源单单据类型"; grdMain.Columns[HMaterIDCol].HeaderText = "物料ID"; grdMain.Columns[HMaterNumberCol].HeaderText = "物料代码"; grdMain.Columns[HMaterNameCol].HeaderText = "物料名称"; grdMain.Columns[HMaterModelCol].HeaderText = "规格型号"; grdMain.Columns[HPinfanCol].HeaderText = "品番"; grdMain.Columns[HUnitIDCol].HeaderText = "计量单位ID"; grdMain.Columns[HUnitNumberCol].HeaderText = "计量单位代码"; grdMain.Columns[HUnitNameCol].HeaderText = "计量单位名称"; grdMain.Columns[HAuxPropFlagCol].HeaderText = "是否启用辅助属性"; grdMain.Columns[HAuxPropIDCol].HeaderText = "辅助属性ID"; grdMain.Columns[HAuxPropNumberCol].HeaderText = "辅助属性代码"; grdMain.Columns[HAuxPropNameCol].HeaderText = "辅助属性名称"; grdMain.Columns[HBatchManagerCol].HeaderText = "是否启用批次"; grdMain.Columns[HBatchNoCol].HeaderText = "批号"; grdMain.Columns[HQtyCol].HeaderText = "数量"; grdMain.Columns[HMinQtyCol].HeaderText = "重量"; grdMain.Columns[HBQtyCol].HeaderText = "箱数"; grdMain.Columns[HinitQtyCol].HeaderText = "初始化数量"; grdMain.Columns[HSourceBillQtyCol].HeaderText = "源单可生成条码数量"; grdMain.Columns[HBarCodeTypeCol].HeaderText = "条码类型"; grdMain.Columns[HISKFPERIODCol].HeaderText = "是否启用保质期"; grdMain.Columns[HProduceDateCol].HeaderText = "生产日期"; grdMain.Columns[HExpiryDateCol].HeaderText = "有效期至"; grdMain.Columns[HEXPUNITCol].HeaderText = "保质期单位"; grdMain.Columns[HEXPPERIODCol].HeaderText = "保质期"; grdMain.Columns[HGiveAwayFlagCol].HeaderText = "是否赠品"; grdMain.Columns[HWhIDCol].HeaderText = "仓库ID"; grdMain.Columns[HWhNumberCol].HeaderText = "仓库代码"; grdMain.Columns[HWhNameCol].HeaderText = "仓库"; grdMain.Columns[HSPIDCol].HeaderText = "仓位ID"; grdMain.Columns[HSPNumberCol].HeaderText = "仓位代码"; grdMain.Columns[HSPNameCol].HeaderText = "仓位"; grdMain.Columns[HMTONoCol].HeaderText = "计划跟踪号"; grdMain.Columns[HRemarkCol].HeaderText = "备注"; grdMain.Columns[HDeptIDCol].HeaderText = "车间ID"; grdMain.Columns[HDeptNumberCol].HeaderText = "车间代码"; grdMain.Columns[HDeptNameCol].HeaderText = "车间"; grdMain.Columns[HSourceIDCol].HeaderText = "生产线ID"; grdMain.Columns[HSourceNumberCol].HeaderText = "生产线代码"; grdMain.Columns[HSourceNameCol].HeaderText = "生产线"; grdMain.Columns[HSupIDCol].HeaderText = "供应商ID"; grdMain.Columns[HSupNumberCol].HeaderText = "供应商代码"; grdMain.Columns[HSupNameCol].HeaderText = "供应商"; grdMain.Columns[HGroupIDCol].HeaderText = "生产班组ID"; grdMain.Columns[HGroupNumberCol].HeaderText = "生产班组代码"; grdMain.Columns[HGroupNameCol].HeaderText = "生产班组"; grdMain.Columns[HCusIDCol].HeaderText = "客户ID"; grdMain.Columns[HCusNumberCol].HeaderText = "客户代码"; grdMain.Columns[HCusNameCol].HeaderText = "客户"; grdMain.Columns[HCusTypeCol].HeaderText = "客户型号"; grdMain.Columns[HSeOrderBillNoCol].HeaderText = "销售订单号"; grdMain.Columns[HSeOrderSEQCol].HeaderText = "销售订单行号"; grdMain.Columns[HInnerBillNoCol].HeaderText = "内部采购订单号"; grdMain.Columns[HBarCodeCol].HeaderText = "条码编号"; grdMain.Columns[HTMNumberCol].HeaderText = "条码前缀"; grdMain.Columns[HLSHCol].HeaderText = "生成条码时获取对应流水号"; grdMain.Columns[HBarcodeNoCol].HeaderText = "记录需回填的流水号数量"; //格式化 隐藏列 grdMain.Columns[HTagCol].Visible = false; grdMain.Columns[HMainIDCol].Visible = false; grdMain.Columns[HSubIDCol].Visible = false; grdMain.Columns[HBillTypeCol].Visible = false; grdMain.Columns[HMaterIDCol].Visible = false; grdMain.Columns[HPinfanCol].Visible = false; grdMain.Columns[HUnitIDCol].Visible = false; grdMain.Columns[HAuxPropIDCol].Visible = false; grdMain.Columns[HinitQtyCol].Visible = false; grdMain.Columns[HSourceBillQtyCol].Visible = false; //grdMain.Columns[HExpiryDateCol].Visible = false; //grdMain.Columns[HEXPUNITCol].Visible = false; //grdMain.Columns[HEXPPERIODCol].Visible = false; grdMain.Columns[HWhIDCol].Visible = false; grdMain.Columns[HWhNumberCol].Visible = false; grdMain.Columns[HWhNameCol].Visible = false; grdMain.Columns[HSPIDCol].Visible = false; grdMain.Columns[HSPNumberCol].Visible = false; grdMain.Columns[HSPNameCol].Visible = false; grdMain.Columns[HMTONoCol].Visible = false; grdMain.Columns[HDeptIDCol].Visible = false; grdMain.Columns[HDeptNumberCol].Visible = false; grdMain.Columns[HDeptNameCol].Visible = false; grdMain.Columns[HSourceIDCol].Visible = false; grdMain.Columns[HSourceNumberCol].Visible = false; grdMain.Columns[HSourceNameCol].Visible = false; grdMain.Columns[HSupIDCol].Visible = false; grdMain.Columns[HSupNumberCol].Visible = false; grdMain.Columns[HSupNameCol].Visible = false; grdMain.Columns[HGroupIDCol].Visible = false; grdMain.Columns[HGroupNumberCol].Visible = false; grdMain.Columns[HGroupNameCol].Visible = false; grdMain.Columns[HCusIDCol].Visible = false; grdMain.Columns[HCusNumberCol].Visible = false; grdMain.Columns[HCusNameCol].Visible = false; grdMain.Columns[HCusTypeCol].Visible = false; grdMain.Columns[HSeOrderBillNoCol].Visible = false; grdMain.Columns[HSeOrderSEQCol].Visible = false; grdMain.Columns[HInnerBillNoCol].Visible = false; grdMain.Columns[HEndDateCol].Visible = false; grdMain.Columns[HBQtyCol].Visible = false; grdMain.Columns[HGiveAwayFlagCol].Visible = false; grdMain.Columns[HBarCodeCol].Visible = false; grdMain.Columns[HTMNumberCol].Visible = false; grdMain.Columns[HLSHCol].Visible = false; grdMain.Columns[HBarcodeNoCol].Visible = false; //设置可编辑列 string sAllowCol = HMinQtyCol.ToString() + "," + HMaterNumberCol.ToString() + "," + HUnitNumberCol.ToString() + "," + HAuxPropNumberCol.ToString() + "," + HBatchNoCol.ToString() + "," + HBarCodeTypeCol.ToString() + "," + HProduceDateCol.ToString() + "," + HRemarkCol.ToString(); //设置合计列 string sTotalCol = HMinQtyCol.ToString(); //设置特殊列 for (int i = 0; i < grdMain.Rows.Count; i++) { //网格打勾 //是否启用辅助属性 DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell(); oCell.ThreeState = false; oCell.Value = 0; oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HAuxPropFlagCol] = oCell; //是否启用批次 DataGridViewCheckBoxCell oCell1 = new DataGridViewCheckBoxCell(); oCell1.ThreeState = false; oCell1.Value = 0; oCell1.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HBatchManagerCol] = oCell1; //是否启用保质期 DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell(); oCell2.ThreeState = false; oCell2.Value = 0; oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HISKFPERIODCol] = oCell2; //是否赠品 DataGridViewCheckBoxCell oCell3 = new DataGridViewCheckBoxCell(); oCell3.ThreeState = false; oCell3.Value = 0; oCell3.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HGiveAwayFlagCol] = oCell3; //网格下拉选择框 DataGridViewComboBoxCell column = new DataGridViewComboBoxCell(); column.Items.Add("唯一条码"); grdMain.Rows[i].Cells[HBarCodeTypeCol] = column; } DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol,oSumGrid); DBUtility.Xt_BaseBillFun.GetGrid(grdMain, this.Name); DBUtility.Xt_BaseBillFun.initGridList(grdList, this.Name + "grdList"); } //是否是空行 private bool IsNullRow(int Row) { return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HMaterIDCol,grdMain); } //判断网格行的录入是否正确 private bool CheckGridRow(int Row) { Cell oCell = new Cell(); int c = 0; //if (ClsPub.isStrNull(grdMain.get_TextMatrix(Row, HTagCol)) != "*") //{ // return true; //} // for (c = 0; c < grdMain.ColumnCount; c++) { oCell.Row = Row; oCell.Col = c; //if (!CheckGridCell(oCell)) // return false; } return true; } //帮助函数 private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit) { string sWhere = ""; DAL.ClsIF_Material_View oMater = new DAL.ClsIF_Material_View();//物料 DAL.ClsIF_Unit_View oUnit = new DAL.ClsIF_Unit_View();//计量单位 DAL.ClsIF_Property_View oProperty = new DAL.ClsIF_Property_View();//辅助属性 if (!grdStatus) { return; } oSumGrid.EditStatus = true; switch (sKeyCode) { case 118: //F7 { switch (sCol) { case HMaterNumberCol: oMater.WherePart = ""; sWhere = " and HUSEORGID = " + HOrgID; if (oMater.RefreshViewForBig(sWhere)) { if (oMater.GetInfoByID(oMater.oModel.HItemID)) { grdMain.Rows[sRow].Cells[HMaterIDCol].Value = oMater.omodel.HItemID.ToString(); grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber; grdMain.Rows[sRow].Cells[HMaterNameCol].Value = oMater.omodel.HName; grdMain.Rows[sRow].Cells[HMaterModelCol].Value = oMater.omodel.HModel; grdMain.Rows[sRow].Cells[HMinQtyCol].Value = oMater.omodel.HQtyMin; grdMain.Rows[sRow].Cells[HUnitIDCol].Value = oMater.omodel.HUnitID.ToString(); grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = oMater.omodel.HUnitNumber; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = oMater.omodel.HUnitName; grdMain.Rows[sRow].Cells[HAuxPropFlagCol].Value = oMater.omodel.HAuxPropFlag; grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = oMater.omodel.HAuxPropID.ToString(); grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = oMater.omodel.HAuxPropNumber; grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = oMater.omodel.HAuxPropName; grdMain.Rows[sRow].Cells[HBatchManagerCol].Value = oMater.omodel.HBatchManager; grdMain.Rows[sRow].Cells[HISKFPERIODCol].Value = oMater.omodel.HISKFPERIOD; grdMain.Rows[sRow].Cells[HBarCodeTypeCol].Value = oMater.omodel.HBarCodeType; grdMain.Rows[sRow].Cells[HBQtyCol].Value = 1; //启用批次 if (oMater.omodel.HBatchManager) { grdMain.Rows[sRow].Cells[HBatchNoCol].Value = oMater.omodel.HBatchNo; } //启用保质期 if (oMater.omodel.HISKFPERIOD) { grdMain.Rows[sRow].Cells[HEXPUNITCol].Value = oMater.omodel.HEXPUNIT; grdMain.Rows[sRow].Cells[HEXPPERIODCol].Value = oMater.omodel.HEXPPERIOD; grdMain.Rows[sRow].Cells[HProduceDateCol].Value = dtpHDate.Value.ToShortDateString(); //获取有效期至 if (GetExpiryDate(dtpHDate.Value, oMater.omodel.HEXPUNIT, DBUtility.ClsPub.isInt(oMater.omodel.HEXPPERIOD), ref sReturn, ref HExpiryDate)) { grdMain.Rows[sRow].Cells[HExpiryDateCol].Value = HExpiryDate; } } else { grdMain.Rows[sRow].Cells[HEXPUNITCol].Value = ""; grdMain.Rows[sRow].Cells[HEXPPERIODCol].Value = ""; grdMain.Rows[sRow].Cells[HProduceDateCol].Value = ""; grdMain.Rows[sRow].Cells[HExpiryDateCol].Value = ""; } oEdit.Text = oMater.omodel.HNumber; } else { grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0; grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HMaterNameCol].Value = ""; grdMain.Rows[sRow].Cells[HMaterModelCol].Value = ""; grdMain.Rows[sRow].Cells[HMinQtyCol].Value = 0; grdMain.Rows[sRow].Cells[HUnitIDCol].Value = 0; grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = ""; grdMain.Rows[sRow].Cells[HAuxPropFlagCol].Value = 0; grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0; grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = ""; grdMain.Rows[sRow].Cells[HBatchManagerCol].Value = 0; grdMain.Rows[sRow].Cells[HBatchNoCol].Value = ""; grdMain.Rows[sRow].Cells[HBarCodeTypeCol].Value = ""; grdMain.Rows[sRow].Cells[HISKFPERIODCol].Value = 0; grdMain.Rows[sRow].Cells[HEXPUNITCol].Value = ""; grdMain.Rows[sRow].Cells[HEXPPERIODCol].Value = ""; grdMain.Rows[sRow].Cells[HProduceDateCol].Value = ""; grdMain.Rows[sRow].Cells[HExpiryDateCol].Value = ""; } } else { grdMain.Rows[sRow].Cells[HMaterIDCol].Value = 0; grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HMaterNameCol].Value = ""; grdMain.Rows[sRow].Cells[HMaterModelCol].Value = ""; grdMain.Rows[sRow].Cells[HMinQtyCol].Value = 0; grdMain.Rows[sRow].Cells[HUnitIDCol].Value = 0; grdMain.Rows[sRow].Cells[HUnitNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = ""; grdMain.Rows[sRow].Cells[HAuxPropFlagCol].Value = 0; grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0; grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = ""; grdMain.Rows[sRow].Cells[HBatchManagerCol].Value = 0; grdMain.Rows[sRow].Cells[HBatchNoCol].Value = ""; grdMain.Rows[sRow].Cells[HBarCodeTypeCol].Value = ""; grdMain.Rows[sRow].Cells[HISKFPERIODCol].Value = 0; grdMain.Rows[sRow].Cells[HEXPUNITCol].Value = ""; grdMain.Rows[sRow].Cells[HEXPPERIODCol].Value = ""; grdMain.Rows[sRow].Cells[HProduceDateCol].Value = ""; grdMain.Rows[sRow].Cells[HExpiryDateCol].Value = ""; } break; case HUnitNumberCol: BLL.ClsBaseSelect_InterFace.SetGridByUnit(grdMain, sRow, HUnitIDCol, HUnitNumberCol, HUnitNameCol); oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HUnitNumberCol].Value); break; case HAuxPropNumberCol: oProperty.WherePart = ""; if (ERPMode == "CLOUD") { sWhere = " and HMaterNumber = '" + DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.CurrentCell.RowIndex].Cells[HMaterNumberCol].Value) + "'"; } else { sWhere = ""; } if (oProperty.RefreshView(sWhere)) { grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = oProperty.oModel.HItemID.ToString(); grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = oProperty.oModel.HNumber; grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = oProperty.oModel.HName; oEdit.Text = oProperty.oModel.HNumber; } else { grdMain.Rows[sRow].Cells[HAuxPropIDCol].Value = 0; grdMain.Rows[sRow].Cells[HAuxPropNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HAuxPropNameCol].Value = ""; } break; case HDeptNumberCol: BLL.ClsBaseSelect_InterFace.SetGridByDept(grdMain, sRow, HDeptIDCol, HDeptNumberCol, HDeptNameCol); oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HDeptNumberCol].Value); break; case HCusNumberCol: BLL.ClsBaseSelect_InterFace.SetGridByCus(grdMain, sRow, HCusIDCol, HCusNumberCol, HCusNameCol); oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HCusNumberCol].Value); break; case HProduceDateCol: BLL.ClsPub_BLL.Sub_SelectDate(grdMain, sRow, HProduceDateCol); //获取有效期至 DateTime HProduceDate= DBUtility.ClsPub.isDate(grdMain.Rows[sRow].Cells[HProduceDateCol].Value); //生产日期 string HEXPUNIT = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HEXPUNITCol].Value); //保质期单位 int HEXPPERIOD = DBUtility.ClsPub.isInt(grdMain.Rows[sRow].Cells[HEXPPERIODCol].Value); //保质期 if (GetExpiryDate(HProduceDate, HEXPUNIT, HEXPPERIOD, ref sReturn, ref HExpiryDate)) { grdMain.Rows[sRow].Cells[HExpiryDateCol].Value = HExpiryDate; } oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HProduceDateCol].Value); break; default: break; } bc.Enabled = true; break; } case 117: //F6 { switch (sCol) { default: break; } break; } default: break; } } //网格编辑前判断 private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { int i = grdMain.CurrentCell.ColumnIndex; if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid,i)) { e.Cancel = true; } } //网格编辑后处理 private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); if (e.ColumnIndex == HProduceDateCol) { //获取有效期至 DateTime HProduceDate = DBUtility.ClsPub.isDate(grdMain.Rows[e.RowIndex].Cells[HProduceDateCol].Value); //生产日期 string HEXPUNIT = DBUtility.ClsPub.isStrNull(grdMain.Rows[e.RowIndex].Cells[HEXPUNITCol].Value); //保质期单位 int HEXPPERIOD = DBUtility.ClsPub.isInt(grdMain.Rows[e.RowIndex].Cells[HEXPPERIODCol].Value); //保质期 if (GetExpiryDate(HProduceDate, HEXPUNIT, HEXPPERIOD, ref sReturn, ref HExpiryDate)) { grdMain.Rows[e.RowIndex].Cells[HExpiryDateCol].Value = HExpiryDate; } } // if (this.EditingControl != null) //释放事件 { EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown); this.EditingControl = null; } } DataGridViewTextBoxEditingControl EditingControl; private void grdMain_CellLeave(object sender, DataGridViewCellEventArgs e) { if (!grdStatus) { return; } DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); // //if (oSumGrid.Changelock) // return; //if(oSumGrid.EditStatus) //{ if (!CheckGridRow(oSumGrid.OldCell.Row)) return; //} } private void grdMain_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } private void grdMain_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (grdMain.CurrentCell != null) { if (e.Control is DataGridViewTextBoxEditingControl) { this.EditingControl = (DataGridViewTextBoxEditingControl)e.Control; //增加委托处理 this.EditingControl.KeyDown += new KeyEventHandler(this.EditingControl_KeyDown); } } } private void EditingControl_KeyDown(object sender, KeyEventArgs e) { //业务处理 Sub_GridKey(e.KeyValue, grdMain.CurrentRow.Index, grdMain.CurrentCell.ColumnIndex, EditingControl); } private void grdMain_RowHeadersWidthChanged(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } private void grdMain_Scroll(object sender, ScrollEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); oSumGrid.DisplayCurRow(); } #endregion #region 选源单返回信息 按放大镜图标返回 private void cmdSourceBillNo_Click(object sender, EventArgs e) { if (cmbSourceBillType.Text.Trim() == "调拨申请单") { string sWhere = " and HOrgID =" + HOrgID.ToString(); DAL.Cls_S_IF_MoveStockRequestBillList oIF_MoveStockRequestBillList = new DAL.Cls_S_IF_MoveStockRequestBillList(); if (oIF_MoveStockRequestBillList.Refresh(sWhere)) //选择原单 { FillSelectData(oIF_MoveStockRequestBillList.oBillSelectColl); } } else { } } private void FillSelectData(List oList) { DataSet Ds; oSumGrid.Changelock = true; initGrid(); int i = -1; foreach (DBUtility.BillSelect oSelectRow in oList) { i = i + 1; //调拨申请单 if (oSelectRow.BillType == "1243") { grdMain.Rows.Add(); //网格打勾 //是否启用辅助属性 DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell(); oCell.ThreeState = false; oCell.Value = 0; oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count-1].Cells[HAuxPropFlagCol] = oCell; //是否启用批次 DataGridViewCheckBoxCell oCell1 = new DataGridViewCheckBoxCell(); oCell1.ThreeState = false; oCell1.Value = 0; oCell1.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count-1].Cells[HBatchManagerCol] = oCell1; //是否启用保质期 DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell(); oCell2.ThreeState = false; oCell2.Value = 0; oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count-1].Cells[HISKFPERIODCol] = oCell2; //是否赠品 DataGridViewCheckBoxCell oCell3 = new DataGridViewCheckBoxCell(); oCell3.ThreeState = false; oCell3.Value = 0; oCell3.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[grdMain.Rows.Count-1].Cells[HGiveAwayFlagCol] = oCell3; //网格下拉选择框 DataGridViewComboBoxCell column = new DataGridViewComboBoxCell(); column.Items.Add("唯一条码"); grdMain.Rows[grdMain.Rows.Count-1].Cells[HBarCodeTypeCol] = column; grdMain.Rows[i].Cells[HTagCol].Value = "*"; //得到信息 Ds = oCn.RunProcReturn("exec h_p_Gy_BarCodeBill_MoveStockRequestBillList " + oSelectRow.BillMainID.ToString() + "," + oSelectRow.BillSubID.ToString(), "h_p_Gy_BarCodeBill_MoveStockRequestBillList"); //写入信息 Sub_WriteInForm(Ds.Tables[0], i); } } // oSumGrid.Changelock = false; DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } //根据TABLE写入界面 private void Sub_WriteInForm(DataTable oTable, int i) { //加载表体 grdMain.Rows[i].Cells[HTagCol].Value = "*"; grdMain.Rows[i].Cells[HQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]); grdMain.Rows[i].Cells[HSourceBillQtyCol].Value = ClsPub.isDoule(oTable.Rows[0]["未生成条码数量"]); grdMain.Rows[i].Cells[HMainIDCol].Value = oTable.Rows[0]["hmainid"].ToString(); grdMain.Rows[i].Cells[HSubIDCol].Value = oTable.Rows[0]["hsubid"].ToString(); grdMain.Rows[i].Cells[HBillNoCol].Value = oTable.Rows[0]["单据号"].ToString(); grdMain.Rows[i].Cells[HBillTypeCol].Value = oTable.Rows[0]["HBillType"].ToString(); grdMain.Rows[i].Cells[HDeptIDCol].Value = oTable.Rows[0]["HDeptID"].ToString(); grdMain.Rows[i].Cells[HDeptNumberCol].Value = oTable.Rows[0]["部门代码"].ToString(); grdMain.Rows[i].Cells[HDeptNameCol].Value = oTable.Rows[0]["部门"].ToString(); grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[0]["HMaterID"].ToString(); grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[0]["物料代码"].ToString(); grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[0]["物料名称"].ToString(); grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[0]["规格型号"].ToString(); grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[0]["HBatchManager"].ToString(); grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[0]["批次"].ToString(); grdMain.Rows[i].Cells[HUnitIDCol].Value = oTable.Rows[0]["HUnitID"].ToString(); grdMain.Rows[i].Cells[HUnitNumberCol].Value = oTable.Rows[0]["计量单位代码"].ToString(); grdMain.Rows[i].Cells[HUnitNameCol].Value = oTable.Rows[0]["计量单位"].ToString(); grdMain.Rows[i].Cells[HRemarkCol].Value = oTable.Rows[0]["备注"].ToString(); grdMain.Rows[i].Cells[HMTONoCol].Value = oTable.Rows[0]["计划跟踪号"].ToString(); grdMain.Rows[i].Cells[HBarCodeTypeCol].Value = oTable.Rows[0]["HBarCodeType"].ToString(); grdMain.Rows[i].Cells[HISKFPERIODCol].Value = oTable.Rows[0]["HISKFPERIOD"].ToString(); grdMain.Rows[i].Cells[HMinQtyCol].Value = oTable.Rows[0]["最小包装数"].ToString(); grdMain.Rows[i].Cells[HAuxPropFlagCol].Value = oTable.Rows[0]["HAuxPropFlag"].ToString(); //启用辅助属性 if (DBUtility.ClsPub.isBool(oTable.Rows[0]["HAuxPropFlag"].ToString())) { grdMain.Rows[i].Cells[HAuxPropIDCol].Value = oTable.Rows[0]["HAuxPropID"].ToString(); grdMain.Rows[i].Cells[HAuxPropNumberCol].Value = oTable.Rows[0]["辅助属性代码"].ToString(); grdMain.Rows[i].Cells[HAuxPropNameCol].Value = oTable.Rows[0]["辅助属性"].ToString(); } else { grdMain.Rows[i].Cells[HAuxPropIDCol].Value = 0; grdMain.Rows[i].Cells[HAuxPropNumberCol].Value = ""; grdMain.Rows[i].Cells[HAuxPropNameCol].Value = ""; } //启用保质期 if (DBUtility.ClsPub.isBool(oTable.Rows[0]["HISKFPERIOD"].ToString())) { grdMain.Rows[i].Cells[HEXPUNITCol].Value = oTable.Rows[0]["HEXPUNIT"].ToString(); grdMain.Rows[i].Cells[HEXPPERIODCol].Value = DBUtility.ClsPub.isInt(oTable.Rows[0]["HEXPPERIOD"]).ToString(); //源单上有生产日期、有效期至取源单上,没有生产日期取界面所选日期 if (oTable.Rows[0]["生产日期"].ToString() == "" || oTable.Rows[0]["有效期至"].ToString() == "") { grdMain.Rows[i].Cells[HProduceDateCol].Value = dtpHDate.Value.ToShortDateString(); //获取有效期至 string HEXPUNIT = DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HEXPUNITCol].Value); //保质期单位 int HEXPPERIOD = DBUtility.ClsPub.isInt(grdMain.Rows[i].Cells[HEXPPERIODCol].Value); //保质期 if (GetExpiryDate(dtpHDate.Value, HEXPUNIT, HEXPPERIOD, ref sReturn, ref HExpiryDate)) { grdMain.Rows[i].Cells[HExpiryDateCol].Value = HExpiryDate; } } else { grdMain.Rows[i].Cells[HProduceDateCol].Value = oTable.Rows[0]["生产日期"].ToString(); grdMain.Rows[i].Cells[HExpiryDateCol].Value = oTable.Rows[0]["有效期至"].ToString(); } } else { grdMain.Rows[i].Cells[HEXPUNITCol].Value = ""; grdMain.Rows[i].Cells[HEXPPERIODCol].Value = ""; grdMain.Rows[i].Cells[HProduceDateCol].Value = ""; grdMain.Rows[i].Cells[HExpiryDateCol].Value = ""; } //-- //设置可编辑列 string sAllowCol = HMinQtyCol.ToString() + "," + HAuxPropNumberCol.ToString() + "," + HBatchNoCol.ToString() + "," + HBarCodeTypeCol.ToString() + "," + HProduceDateCol.ToString() + "," + HRemarkCol.ToString(); grdMain.Columns[HBillNoCol].ReadOnly = true; //设置合计列 string sTotalCol = HMinQtyCol.ToString(); // DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid); tabControl1.SelectedIndex = 0; bc.Enabled = true; } #endregion #region 选源单返回信息 按回车键返回 private void txtHSourceBillNo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Return)//回车带出源单信息 { if (txtHSourceBillNo.Text.Length < 4) { MessageBox.Show("请输入4位以上数据!"); return; } //根据源单类型 和源单号 获取信息 if (cmbSourceBillType.Text.Trim() == "调拨申请单") { DAL.Cls_S_IF_MoveStockRequestBillList oIF_MoveStockRequestBillList = new DAL.Cls_S_IF_MoveStockRequestBillList(); if (oIF_MoveStockRequestBillList.RefreshBySourceBillNo(" Where 单据号 like '%" + txtHSourceBillNo.Text + "' and HOrgID =" + HOrgID.ToString())) //选择原单 { FillSelectData(oIF_MoveStockRequestBillList.oBillSelectColl); txtHSourceBillNo.Text = ""; } else { MessageBox.Show("未查询到任务数据,请确认所选组织、源单类型与源单单号是否正确!"); return; } } else { MessageBox.Show("所选源单类型,不支持此功能!"); return; } } } #endregion #region //打印设置 GridppReport Report; string sBarCodeItemID = ""; //条码自增列 #region 预览 private void yl_Click(object sender, EventArgs e) { //判断是否已经生成条码 if (grdList.Rows.Count < 1) { 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); } } #endregion #region 打印 private void dy_Click(object sender, EventArgs e) { //判断是否已经生成条码 if (grdList.Rows.Count < 1) { 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.Print(true); Thread.Sleep(1000); } } #endregion //打印前判断条码是否超过允许可打印次数 private bool ReportPrintBegin() { string sHRemark = ""; if (PrintQtyCtl == "Y") { if (oBar.Set_CheckPrintQty_SD(HInterID, PrintQty, ref sHRemark)) { MessageBox.Show(sHRemark); return true; } return false; } else { return false; } } private void Sub_SetReport(string sOpenTmp) { //判断行数 for (int i = 0; i < grdList.Rows.Count; i++) { grdList.Rows[i].Cells[0].Value = "*"; } // Report = new GridppReport(); Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf"); //here . Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord); Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable); Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd); } //填入单据表头信息 private void ReportBeforePostRecord()// { try { //Report.FieldByName("备注").AsString = ClsPub.isStrNull(grdSub.Rows[CurRows].Cells[HRemark2Col].Value); } catch (Exception e) { MessageBox.Show("打印失败!表头:" + e.Message); } } //填入单据表体信息 private void ReportFetchRecordByDataTable() { try { DataTable ds = new DataTable(); BLL.Utility.FillRecordToReport_Sel(Report, grdList, ds, Fun_GetCol("选择")); } catch (Exception e) { MessageBox.Show("打印失败!表体:" + e.Message); } } //打印结束后回填条码打印次数 private void ReportPrintEnd() { if (UpdatePrintQtyCtl == "Y") { oBar.Set_UpdatePrintQty_SD(HInterID); } } private Int32 Fun_GetCol(string sCol) { return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdList); } #region 试打印 private void sdy_Click(object sender, EventArgs e) { //判断是否已经生成条码 if (grdList.Rows.Count < 1) { MessageBox.Show("条码未生成,请先生成条码后再浏览!"); return; } //打印前判断条码是否已打印过 if (ReportPrintBegin_SDY()) { return; } //选择打印模板 BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK) { Sub_SetReportView(oFrm.sOpenTmp); Report.PrintPreview(false); Thread.Sleep(1000); } } //打印前判断条码是否超过允许可打印次数 private bool ReportPrintBegin_SDY() { string sHRemark = ""; sBarCodeItemID = ""; for (int i = 0; i < grdList.SelectedRows.Count; i++) { sBarCodeItemID = sBarCodeItemID + "," + DBUtility.ClsPub.isLong(grdList.Rows[grdList.SelectedRows[i].Index].Cells[Fun_GetCol("HItemID")].Value).ToString(); } sBarCodeItemID = sBarCodeItemID.Remove(0, 1); if (PrintQtyCtl == "Y") { if (oBar.Set_CheckPrintQty(sBarCodeItemID, PrintQty, ref sHRemark)) { MessageBox.Show(sHRemark); return true; } return false; } else { return false; } } private void Sub_SetReportView(string sOpenTmp) { //判断行数 for (int i = 0; i < grdList.Rows.Count; i++) { grdList.Rows[i].Cells[0].Value = ""; } for (int i = 0; i < grdList.SelectedRows.Count; i++) { grdList.Rows[grdList.SelectedRows[i].Index].Cells[0].Value = "*"; } // Report = new GridppReport(); Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf"); //here . Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord); Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable); Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd_SDY); } //打印结束后回填条码打印次数 private void ReportPrintEnd_SDY() { if (UpdatePrintQtyCtl == "Y") { oBar.Set_UpdatePrintQty(sBarCodeItemID); } } #endregion #endregion #region 选择组织 private void cmbHOrgID_SelectionChangeCommitted(object sender, EventArgs e) { HOrgID = ClsPub.isLong(cmbHOrgID.SelectedValue); //清空初始化列表 initGrid(); grdMain.Columns[HBillNoCol].ReadOnly = false; } #endregion #region 选择日期 private void dtpHDate_ValueChanged(object sender, EventArgs e) { if (chkUpdateSubDate.Checked == true) { for (int j = 0; j < grdMain.Rows.Count; j++) { long HMaterID = DBUtility.ClsPub.isLong(grdMain.Rows[j].Cells[HMaterIDCol].Value); // 物料内码 if (HMaterID != 0 && DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HRemarkCol].Value) != "按库存生成") { //获取生产日期、有效期至 DateTime HProduceDate = dtpHDate.Value; //生产日期 string HEXPUNIT = DBUtility.ClsPub.isStrNull(grdMain.Rows[j].Cells[HEXPUNITCol].Value); //保质期单位 int HEXPPERIOD = DBUtility.ClsPub.isInt(grdMain.Rows[j].Cells[HEXPPERIODCol].Value); //保质期 //生产日期 grdMain.Rows[j].Cells[HProduceDateCol].Value = dtpHDate.Value.ToShortDateString(); if (GetExpiryDate(HProduceDate, HEXPUNIT, HEXPPERIOD, ref sReturn, ref HExpiryDate)) { //有效期至 grdMain.Rows[j].Cells[HExpiryDateCol].Value = HExpiryDate; } } } } } #endregion #region 获取有效期至 public bool GetExpiryDate(DateTime HProduceDate, string HEXPUNIT, int HEXPPERIOD, ref string sReturn, ref string HExpiryDate) { if (HEXPUNIT != "Y" && HEXPUNIT != "M" && HEXPUNIT != "D") { sReturn = "物料启用保质期管理,物料基础资料中的保质期单位不允许为空!"; return false; } else if (HEXPPERIOD == 0) { sReturn = "物料启用保质期管理,物料基础资料中的保质期不允许为空!"; return false; } else if (HEXPUNIT == "Y") { HExpiryDate = HProduceDate.AddYears(HEXPPERIOD).ToShortDateString(); return true; } else if (HEXPUNIT == "M") { HExpiryDate = HProduceDate.AddMonths(HEXPPERIOD).ToShortDateString(); return true; } else { HExpiryDate = HProduceDate.AddDays(HEXPPERIOD).ToShortDateString(); return true; } } #endregion #region 拆行 private void spRow_Click(object sender, EventArgs e) { oDlg.ShowDialog(); if (oDlg.IsOk == 1) { grdMainData_CF(DBUtility.ClsPub.isInt(oDlg.txtHQ.Text)); } } private void grdMainData_CF(int HQty) { if (grdMain.CurrentRow == null) { MessageBox.Show("请先选择需要拆分的行!", "提示"); return; } int row = grdMain.CurrentCell.RowIndex; grdMain.Rows.Insert(row + 1, HQty); for (int i = 0; i < HQty; i++) { int r = i + 1; grdMain.Rows[row + r].Cells[HTagCol].Value = grdMain.Rows[row].Cells[HTagCol].Value; grdMain.Rows[row + r].Cells[HMainIDCol].Value = grdMain.Rows[row].Cells[HMainIDCol].Value; grdMain.Rows[row + r].Cells[HSubIDCol].Value = grdMain.Rows[row].Cells[HSubIDCol].Value; grdMain.Rows[row + r].Cells[HBillNoCol].Value = grdMain.Rows[row].Cells[HBillNoCol].Value; grdMain.Rows[row + r].Cells[HBillTypeCol].Value = grdMain.Rows[row].Cells[HBillTypeCol].Value; grdMain.Rows[row + r].Cells[HMaterIDCol].Value = grdMain.Rows[row].Cells[HMaterIDCol].Value; grdMain.Rows[row + r].Cells[HMaterNumberCol].Value = grdMain.Rows[row].Cells[HMaterNumberCol].Value; grdMain.Rows[row + r].Cells[HMaterNameCol].Value = grdMain.Rows[row].Cells[HMaterNameCol].Value; grdMain.Rows[row + r].Cells[HPinfanCol].Value = grdMain.Rows[row].Cells[HPinfanCol].Value; grdMain.Rows[row + r].Cells[HMaterModelCol].Value = grdMain.Rows[row].Cells[HMaterModelCol].Value; grdMain.Rows[row + r].Cells[HAuxPropIDCol].Value = grdMain.Rows[row].Cells[HAuxPropIDCol].Value; grdMain.Rows[row + r].Cells[HAuxPropNumberCol].Value = grdMain.Rows[row].Cells[HAuxPropNumberCol].Value; grdMain.Rows[row + r].Cells[HAuxPropNameCol].Value = grdMain.Rows[row].Cells[HAuxPropNameCol].Value; grdMain.Rows[row + r].Cells[HBatchManagerCol].Value = grdMain.Rows[row].Cells[HBatchManagerCol].Value; grdMain.Rows[row + r].Cells[HBatchNoCol].Value = grdMain.Rows[row].Cells[HBatchNoCol].Value; grdMain.Rows[row + r].Cells[HQtyCol].Value = grdMain.Rows[row].Cells[HQtyCol].Value; grdMain.Rows[row + r].Cells[HMinQtyCol].Value = 0; grdMain.Rows[row + r].Cells[HBQtyCol].Value = grdMain.Rows[row].Cells[HBQtyCol].Value; grdMain.Rows[row + r].Cells[HinitQtyCol].Value = grdMain.Rows[row].Cells[HinitQtyCol].Value; grdMain.Rows[row + r].Cells[HISKFPERIODCol].Value = grdMain.Rows[row].Cells[HISKFPERIODCol].Value; grdMain.Rows[row + r].Cells[HProduceDateCol].Value = grdMain.Rows[row].Cells[HProduceDateCol].Value; grdMain.Rows[row + r].Cells[HExpiryDateCol].Value = grdMain.Rows[row].Cells[HExpiryDateCol].Value; grdMain.Rows[row + r].Cells[HEXPUNITCol].Value = grdMain.Rows[row].Cells[HEXPUNITCol].Value; grdMain.Rows[row + r].Cells[HEXPPERIODCol].Value = grdMain.Rows[row].Cells[HEXPPERIODCol].Value; grdMain.Rows[row + r].Cells[HGiveAwayFlagCol].Value = grdMain.Rows[row].Cells[HGiveAwayFlagCol].Value; grdMain.Rows[row + r].Cells[HUnitIDCol].Value = grdMain.Rows[row].Cells[HUnitIDCol].Value; grdMain.Rows[row + r].Cells[HUnitNumberCol].Value = grdMain.Rows[row].Cells[HUnitNumberCol].Value; grdMain.Rows[row + r].Cells[HUnitNameCol].Value = grdMain.Rows[row].Cells[HUnitNameCol].Value; grdMain.Rows[row + r].Cells[HWhIDCol].Value = grdMain.Rows[row].Cells[HWhIDCol].Value; grdMain.Rows[row + r].Cells[HWhNumberCol].Value = grdMain.Rows[row].Cells[HWhNumberCol].Value; grdMain.Rows[row + r].Cells[HWhNameCol].Value = grdMain.Rows[row].Cells[HWhNameCol].Value; grdMain.Rows[row + r].Cells[HSPIDCol].Value = grdMain.Rows[row].Cells[HSPIDCol].Value; grdMain.Rows[row + r].Cells[HSPNumberCol].Value = grdMain.Rows[row].Cells[HSPNumberCol].Value; grdMain.Rows[row + r].Cells[HSPNameCol].Value = grdMain.Rows[row].Cells[HSPNameCol].Value; grdMain.Rows[row + r].Cells[HMTONoCol].Value = grdMain.Rows[row].Cells[HMTONoCol].Value; grdMain.Rows[row + r].Cells[HRemarkCol].Value = grdMain.Rows[row].Cells[HRemarkCol].Value; grdMain.Rows[row + r].Cells[HDeptIDCol].Value = grdMain.Rows[row].Cells[HDeptIDCol].Value; grdMain.Rows[row + r].Cells[HDeptNumberCol].Value = grdMain.Rows[row].Cells[HDeptNumberCol].Value; grdMain.Rows[row + r].Cells[HDeptNameCol].Value = grdMain.Rows[row].Cells[HDeptNameCol].Value; grdMain.Rows[row + r].Cells[HSourceIDCol].Value = grdMain.Rows[row].Cells[HSourceIDCol].Value; grdMain.Rows[row + r].Cells[HSourceNumberCol].Value = grdMain.Rows[row].Cells[HSourceNumberCol].Value; grdMain.Rows[row + r].Cells[HSourceNameCol].Value = grdMain.Rows[row].Cells[HSourceNameCol].Value; grdMain.Rows[row + r].Cells[HSupIDCol].Value = grdMain.Rows[row].Cells[HSupIDCol].Value; grdMain.Rows[row + r].Cells[HSupNumberCol].Value = grdMain.Rows[row].Cells[HSupNumberCol].Value; grdMain.Rows[row + r].Cells[HSupNameCol].Value = grdMain.Rows[row].Cells[HSupNameCol].Value; grdMain.Rows[row + r].Cells[HGroupIDCol].Value = grdMain.Rows[row].Cells[HGroupIDCol].Value; grdMain.Rows[row + r].Cells[HGroupNumberCol].Value = grdMain.Rows[row].Cells[HGroupNumberCol].Value; grdMain.Rows[row + r].Cells[HGroupNameCol].Value = grdMain.Rows[row].Cells[HGroupNameCol].Value; grdMain.Rows[row + r].Cells[HCusIDCol].Value = grdMain.Rows[row].Cells[HCusIDCol].Value; grdMain.Rows[row + r].Cells[HCusNumberCol].Value = grdMain.Rows[row].Cells[HCusNumberCol].Value; grdMain.Rows[row + r].Cells[HCusNameCol].Value = grdMain.Rows[row].Cells[HCusNameCol].Value; grdMain.Rows[row + r].Cells[HCusTypeCol].Value = grdMain.Rows[row].Cells[HCusTypeCol].Value; grdMain.Rows[row + r].Cells[HSeOrderBillNoCol].Value = grdMain.Rows[row].Cells[HSeOrderBillNoCol].Value; grdMain.Rows[row + r].Cells[HSeOrderSEQCol].Value = grdMain.Rows[row].Cells[HSeOrderSEQCol].Value; grdMain.Rows[row + r].Cells[HInnerBillNoCol].Value = grdMain.Rows[row].Cells[HInnerBillNoCol].Value; grdMain.Rows[row + r].Cells[HEndDateCol].Value = grdMain.Rows[row].Cells[HEndDateCol].Value; grdMain.Rows[row + r].Cells[HSourceBillQtyCol].Value = grdMain.Rows[row].Cells[HSourceBillQtyCol].Value; grdMain.Rows[row + r].Cells[HAuxPropFlagCol].Value = grdMain.Rows[row].Cells[HAuxPropFlagCol].Value; //网格打勾 //是否启用辅助属性 DataGridViewCheckBoxCell oCell = new DataGridViewCheckBoxCell(); oCell.ThreeState = false; oCell.Value = grdMain.Rows[row].Cells[HAuxPropFlagCol].Value; oCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[row + r].Cells[HAuxPropFlagCol] = oCell; //是否启用批次 DataGridViewCheckBoxCell oCell1 = new DataGridViewCheckBoxCell(); oCell1.ThreeState = false; oCell1.Value = grdMain.Rows[row].Cells[HBatchManagerCol].Value; oCell1.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[row + r].Cells[HBatchManagerCol] = oCell1; //是否启用保质期 DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell(); oCell2.ThreeState = false; oCell2.Value = grdMain.Rows[row].Cells[HISKFPERIODCol].Value; oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[row + r].Cells[HISKFPERIODCol] = oCell2; //是否赠品 DataGridViewCheckBoxCell oCell3 = new DataGridViewCheckBoxCell(); oCell3.ThreeState = false; oCell3.Value = grdMain.Rows[row].Cells[HGiveAwayFlagCol].Value; oCell3.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[row + r].Cells[HGiveAwayFlagCol] = oCell3; //网格下拉选择框 DataGridViewComboBoxCell column = new DataGridViewComboBoxCell(); column.Items.Add("唯一条码"); grdMain.Rows[row + r].Cells[HBarCodeTypeCol] = column; grdMain.Rows[row + r].Cells[HBarCodeTypeCol].Value = grdMain.Rows[row].Cells[HBarCodeTypeCol].Value; } DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } #endregion } }