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 SQLHelper; namespace WorkM { public partial class Sc_ProcessExchangeBill_DH : Form { public Sc_ProcessExchangeBill_DH() { InitializeComponent(); } //定义列 public const Int16 HSnoCol = 0; // 序号 public const Int16 HICMOInterIDCol = 1; // 生产订单内码 public const Int16 HICMOEntryIDCol = 2; // 生产订单子内码 public const Int16 HICMOBillNoCol = 3; // 生产订单号 public const Int16 HWorkShopIDCol = 4; // 生产车间 public const Int16 HMaterIDCol = 5; // HMaterID public const Int16 HMaterNumberCol = 6; // 物料代码 public const Int16 HMaterNameCol = 7; // 物料名称 public const Int16 HMaterModelCol = 8; // 规格型号 public const Int16 HQtyCol = 9; // 订单总数 public const Int16 HProQtyCol = 10; // 流转卡数量 public const Int16 HBatchNoCol = 11; // 批次号 public const Int16 HProjectNumCol = 12; // 项目编号 public const Int16 HMateOutBatchNoCol = 13; // 原料批次 public const Int16 HMouldNumCol = 14; // 模穴号 public const Int16 HGroupNumberCol = 15; // 班组 public const Int16 HBatchManagerCol = 16; // 启用批次 public const Int16 HRoutingInterIDCol = 17; // 工艺路线内码 public const Int16 HRoutingNameCol = 18; // 工艺路线 public const Int16 HRoutingNumberCol = 19; // 工艺路线 public const Int16 HDateCol = 20; // 流转卡日期 public const Int16 HInterIDCol = 21; // 流转卡内码 public const Int16 HBillNoCol = 22; // 流转卡号 public const Int16 HEditCol = 23; // 总列数 public const Int16 TotalColumnCount = 24; // public const string ModName = "3772"; //单据类型 public string ModCaption = "工序流转卡"; //单据名称 public const string ModRightName = "Sc_ProcessExchangeBill"; public const string ModRightNameEdit = ModRightName + "_Edit"; public const string ModRightNameCheck = ModRightName + "_Check"; public const string ModRightNameClose = ModRightName + "_Close"; public const string ModRightNameDelete = ModRightName + "_Delete"; public const string ModRightNameMoney = ModRightName + "_Money"; public const string ModRightNameQty = ModRightName + "_Qty"; public bool BillChange; //单据修改状态 // public DBUtility.ClsPub.Enum_BillStatus BillStatus; //单据状态(新增,修改,浏览,更新单价,变更) public Int64 KeyID; //单据主内码 public bool grdStatus; //网格状态(不可编辑,可编辑) public DAL.ClsSc_ProcessExchangeBill BillNew = new DAL.ClsSc_ProcessExchangeBill(); //对应单据类 public DAL.ClsSc_ProcessExchangeBill BillOld = new DAL.ClsSc_ProcessExchangeBill(); //对应单据类 ClsGridViewSum oSumGrid = new ClsGridViewSum(); public DataSet oXT; public string CampanyName = ""; //客户定制化名称 DateTime dt = DateTime.Now; SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); DataSet ds; // 添加属性来接收选中的订单ID public List SelectedOrderIds { get; set; } public string HSouceBillType { get; set; } //------------------------------------------------------------------------- #region 固定代码 //清空界面 public void Sub_ClearBill() { txtHMaker.Text = ClsPub.CurUserName; txtHMakeDate.Text = ""; txtHChecker.Text = ""; txtHCheckDate.Text = ""; txtHCloseMan.Text = ""; txtHCloseDate.Text = ""; txtHDeleteMan.Text = ""; txtHDeleteDate.Text = ""; txtHUpDater.Text = ""; txtHUpDateDate.Text = ""; initGrid(); } //保存列宽 private void bclk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); } //增行按钮 private void AddRow_Click(object sender, EventArgs e) { if (grdMain.CurrentRow == null) { return; } if (DBUtility.ClsPub.isBool(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HEditCol].Value) == false) { DBUtility.Xt_BaseBillFun.AddRow(oSumGrid); } } //删行按纽 private void DelRow_Click(object sender, EventArgs e) { if (grdMain.CurrentRow == null) { return; } if (DBUtility.ClsPub.isBool(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HEditCol].Value) == false) { DBUtility.Xt_BaseBillFun.DelRow(oSumGrid); } } private void mrlk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name); } private void Sub_AbandonBill() { 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(); } } } private void Sc_ProcessExchangeBill_Paint(object sender, PaintEventArgs e)//画线 { } //控件位置 private void Sub_ControlLocation() { } //窗体加载 private void Sc_ProcessExchangeBill_Load(object sender, EventArgs e) { //打印初始化 oSumGrid.NoCol = HSnoCol; oSumGrid.ogrdMain = grdMain; oSumGrid.oGridsum = grdSum; // this.Text = ModCaption; //命名窗体标题 this.lblCaption.Text = ModCaption;//命名单据标题 } //保存按钮 private void bc_Click(object sender, EventArgs e) { this.Sub_SaveBill(); } //放弃按钮 private void fq_Click(object sender, EventArgs e) { this.Sub_AbandonBill(); } //退出按钮 private void tc_Click(object sender, EventArgs e) { this.Close(); } //根据编辑状态 设置 控件是否允许录入 private void Sub_LrtextStatus(bool TextEnabled) { if (TextEnabled == true) { //控件全部有效 grdMain.BackColor = ClsPub.EditColor; } else { //控件全部无效 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) { } else { this.Sub_AddBill(); DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } // 如果有选中的订单ID,直接查询并显示数据 if (SelectedOrderIds != null && SelectedOrderIds.Count > 0) { LoadAndDisplaySelectedOrders(); } else if (oXT != null) { Sub_WriteInForm(oXT.Tables[0], 0); } } //窗体卸载 private void Sc_ProcessExchangeBill_FormClosing(object sender, FormClosingEventArgs e) { BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); } //新增单据 private void Sub_AddBill() { this.BillNew = new DAL.ClsSc_ProcessExchangeBill(); this.BillOld = new DAL.ClsSc_ProcessExchangeBill(); this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; this.Sub_OperStatus();//设置TOOLBAR this.Sub_ClearBill();//清空界面 } //TOOLBAR状态 按钮是否灰度 public void Sub_OperStatus() { switch (BillStatus) { case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew: //新增状态 yl.Enabled = false; dy.Enabled = false; AddRow.Enabled = true; DelRow.Enabled = true; bc.Enabled = true; fq.Enabled = true; tc.Enabled = true; Sub_LrtextStatus(true); grdStatus = true; pic1.Visible = false; pic1.Image = null; // break; } } #endregion #region 读写类 //单据完整性判断 private bool Sub_AllowSave() { //获取系统参数 Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); if (oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo) == false) { DBUtility.ClsPub.sExeReturnInfo = "保存失败,获取系统参数失败! " + DBUtility.ClsPub.sExeReturnInfo; return false; } //明细表是否为零行 bool b = false; for (int i = 0; i < grdMain.RowCount; i++) { if (!IsNullRow(i)) { b = true; break; } } if (b == false) { MessageBox.Show("表体明细行不存在!请录入!", "提示"); return false; } return true; } //保存单据 private bool Sub_SaveBill() { try { bool bResult = true; BillNew = new DAL.ClsSc_ProcessExchangeBill(); //失去焦点 lblCaption.Focus(); if (!Sub_AllowSave())//单据完整性判断 return false; for (int i = 0; i < grdMain.Rows.Count; i++) { if (IsNullRow(i)) continue; var row = grdMain.Rows[i]; // 获取关键值 Int64 HICMOInterID = DBUtility.ClsPub.isLong(row.Cells[HICMOInterIDCol].Value); Int64 HICMOEntryID = DBUtility.ClsPub.isLong(row.Cells[HICMOEntryIDCol].Value); Int64 HRoutingInterID = DBUtility.ClsPub.isLong(row.Cells[HRoutingInterIDCol].Value); Int64 HQty = DBUtility.ClsPub.isLong(row.Cells[HQtyCol].Value); Int64 HProQty = DBUtility.ClsPub.isLong(row.Cells[HProQtyCol].Value); Int64 HMaterID = DBUtility.ClsPub.isLong(row.Cells[HMaterIDCol].Value); string HICMOBillNo = row.Cells[HICMOBillNoCol].Value?.ToString() ?? ""; // 日期处理 DateTime HDateValue; if (!DateTime.TryParse(row.Cells[HDateCol].Value?.ToString(), out HDateValue)) { HDateValue = DateTime.Now; } string HBatchNo = row.Cells[HBatchNoCol].Value?.ToString() ?? ""; string HProjectNum = row.Cells[HProjectNumCol].Value?.ToString() ?? ""; string HMateOutBatchNo = row.Cells[HMateOutBatchNoCol].Value?.ToString() ?? ""; string HMouldNum = row.Cells[HMouldNumCol].Value?.ToString() ?? "0#"; string HGroupNumber = row.Cells[HGroupNumberCol].Value?.ToString() ?? ""; Int64 HInterID = DBUtility.ClsPub.isLong(row.Cells[HInterIDCol].Value); string HBillNo = row.Cells[HBillNoCol].Value?.ToString() ?? ""; // 查询获取完整数据 string sql = "select * from h_v_Sc_ProcessExchangeBill_BatchSplit where hmainid = " + HICMOInterID + " and hentryid = " + HICMOEntryID + " and HRoutingID = " + HRoutingInterID.ToString(); ds = oCn.RunProcReturn(sql, "h_v_Sc_ProcessExchangeBill_BatchSplit"); // 主表赋值 if (ds.Tables[0].Rows.Count > 0 && ds != null) { BillNew.omodel.HInterID = HInterID; BillNew.omodel.HBillNo = HBillNo; BillNew.omodel.HBillSubType = "3772"; BillNew.omodel.HMainSourceBillSubType = "3710"; BillNew.omodel.HDate = DateTime.Now.Date; BillNew.omodel.HMaker = ClsPub.CurUserName; BillNew.omodel.HMakeDate = DateTime.Now.ToString("G"); BillNew.omodel.HPrevMainSourceInterID = 0; BillNew.omodel.HYear = HDateValue.Year; BillNew.omodel.HPeriod = HDateValue.Month; BillNew.omodel.HRemark = ""; BillNew.omodel.HBatchNo = HBatchNo; BillNew.omodel.HProjectNum = HProjectNum; BillNew.omodel.HMateOutBatchNo = HMateOutBatchNo; BillNew.omodel.HMouldNum = HMouldNum; BillNew.omodel.HMainMaterID = 0; BillNew.omodel.HKeyMaterID = 0; BillNew.omodel.HNo = 0; BillNew.omodel.HOrderProcNO = ds.Tables[0].Rows[0]["HPlanOrderProcNo"].ToString(); BillNew.omodel.HWWOrderInterID = 0; BillNew.omodel.HWWOrderEntryID = 0; BillNew.omodel.HWWOrderBillNo = ""; BillNew.omodel.HEquipMentID = 0; BillNew.omodel.HICMOBillNo = HICMOBillNo; BillNew.omodel.HMaterID = HMaterID; BillNew.omodel.HMaterNumber = ds.Tables[0].Rows[0]["HMaterNumber"].ToString(); BillNew.omodel.HUnitID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0]["HUnitID"]); BillNew.omodel.HUnitNumber = ds.Tables[0].Rows[0]["HUnitNumber"].ToString(); BillNew.omodel.HMaterID2 = HMaterID; BillNew.omodel.HPlanQty = HQty; BillNew.omodel.HQty = HProQty; BillNew.omodel.HPlanBeginDate = Convert.ToDateTime(dt.ToShortDateString()); BillNew.omodel.HPlanEndDate = Convert.ToDateTime(dt.ToShortDateString()); BillNew.omodel.HExplanation = ""; BillNew.omodel.HInnerBillNo = ""; BillNew.omodel.HSupID = 0; BillNew.omodel.HWorkShopID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[0]["HDeptID"]); BillNew.omodel.HWorkTypeNum = ""; BillNew.omodel.HProdMaterCode = ""; BillNew.omodel.HSeOrderBillNo = ds.Tables[0].Rows[0]["HSeOrderBillNo"].ToString(); BillNew.omodel.HCusShortName = ""; BillNew.omodel.HCusNeedMaterial = ""; BillNew.omodel.HPlanSendGoodsDate = dt.ToShortDateString(); BillNew.omodel.HProdMaterName = ""; BillNew.omodel.HCusName = ""; BillNew.omodel.HWorkRemark = ""; BillNew.omodel.HImportNote = ""; BillNew.omodel.HMaterNumber_A = ""; BillNew.omodel.HMaterNumber_B = ""; BillNew.omodel.HMaterNumber_C = ""; BillNew.omodel.HMaterNumber_D = ""; BillNew.omodel.HProdType = ""; BillNew.omodel.HMaterShortName = ""; BillNew.omodel.HMaterIDA = ""; BillNew.omodel.HMaterIDB = ""; BillNew.omodel.HMaterIDC = ""; BillNew.omodel.HMaterIDD = ""; BillNew.omodel.HICMOInterID = HICMOInterID; BillNew.omodel.HICMOEntryID = HICMOEntryID; BillNew.omodel.HPicNumVer = ""; BillNew.omodel.HPicNumAssemble = ""; BillNew.omodel.HMaterTexture = ""; BillNew.omodel.HProductNum = ""; BillNew.omodel.HVerNum = ""; BillNew.omodel.HPRDORGID = DBUtility.ClsPub.HOrgID; BillNew.omodel.HBLFlag = false; BillNew.omodel.HCusNumber = ""; BillNew.omodel.HPickLabel = ""; BillNew.omodel.HPickLabelNumber = ""; BillNew.omodel.HXTNumber = ""; BillNew.omodel.HXTModel = ""; BillNew.omodel.HWorkBillSortNo = ""; BillNew.omodel.HRoutingBillID = HRoutingInterID.ToString(); BillNew.omodel.HMaterModel = ds.Tables[0].Rows[0]["HMaterModel"].ToString(); BillNew.omodel.HWidth = 0; BillNew.omodel.HWeight = 0; BillNew.omodel.HAuxQty = 0; BillNew.omodel.HAuxUnit = 0; BillNew.omodel.HAuxQty2 = 0; BillNew.omodel.HAuxUnit2 = 0; BillNew.omodel.HSplitNo = 0; BillNew.omodel.HHeight = ""; BillNew.omodel.HInches = ""; BillNew.omodel.HAl1Long = ""; BillNew.omodel.HDensity = ""; BillNew.omodel.HTela = ""; BillNew.omodel.HUnderTela = ""; BillNew.omodel.HSizing = ""; BillNew.omodel.HSellDate = dt.ToShortDateString(); BillNew.omodel.HRemark2 = "批量拆分下推"; BillNew.omodel.HRemark3 = ""; BillNew.omodel.HEmpID = 0; BillNew.omodel.HCusID = 0; BillNew.omodel.HColorRemark = ""; BillNew.omodel.HSplitSumQty = 0; BillNew.omodel.HSplitColorQty = 0; BillNew.omodel.HMachineLine = ""; BillNew.omodel.HMainSourceInterID = 0; BillNew.omodel.HMainSourceEntryID = 0; BillNew.omodel.HMainSourceBillNo = ""; BillNew.omodel.HOrderLevID = 0; BillNew.omodel.HWidth_New = 0; BillNew.omodel.HRemark_New = ""; BillNew.omodel.HWeight_New = 0; BillNew.omodel.HPlanOrderProcNo = ds.Tables[0].Rows[0]["HPlanOrderProcNo"].ToString(); } // 子表赋值 for (int j = 0; j < ds.Tables[0].Rows.Count; j++) { Model.ClsSc_ProcessExchangeBillSub oBillSub = new Model.ClsSc_ProcessExchangeBillSub(); oBillSub.HEntryID = j + 1; oBillSub.HBillNo_bak = HBillNo; oBillSub.HCloseMan = ""; oBillSub.HEntryCloseDate = Convert.ToDateTime(dt.ToShortDateString()); oBillSub.HCloseType = false; oBillSub.HRemark = ""; oBillSub.HSourceInterID = HICMOInterID; oBillSub.HSourceEntryID = HICMOEntryID; oBillSub.HSourceBillNo = HICMOBillNo; oBillSub.HSourceBillType = "3710"; oBillSub.HRelationQty = 0; oBillSub.HRelationMoney = 0; oBillSub.HRelationQty_In = 0; oBillSub.HRelationQty_Out = 0; oBillSub.HRelationQty_WWOrder = 0; oBillSub.HRelationQty_Bad = 0; oBillSub.HProcNo = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HProcNo"]); oBillSub.HProcID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HProcID"]); oBillSub.HProcNumber = ds.Tables[0].Rows[j]["HProcNumber"].ToString(); oBillSub.HWorkRemark = ""; oBillSub.HCenterID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HCenterID"]); oBillSub.HDeptID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HDeptID"]); oBillSub.HDeptNumber = ds.Tables[0].Rows[j]["HDeptNumber"].ToString(); oBillSub.HGroupID = 0; oBillSub.HGroupNumber = HGroupNumber; oBillSub.HWorkerID = 0; oBillSub.HWorkerNumber = ""; oBillSub.HSourceID = 0; oBillSub.HQty = HProQty; oBillSub.HTimeUnit = ""; oBillSub.HPlanWorkTimes = 0; oBillSub.HPlanBeginDate = Convert.ToDateTime(dt.ToShortDateString()); oBillSub.HPlanEndDate = Convert.ToDateTime(dt.ToShortDateString()); oBillSub.HRelBeginDate = Convert.ToDateTime(dt.ToShortDateString()); oBillSub.HRelEndDate = Convert.ToDateTime(dt.ToShortDateString()); oBillSub.HReadyTime = 0; oBillSub.HQueueTime = 0; oBillSub.HMoveTime = 0; oBillSub.HBeginDayQty = 0; oBillSub.HBeginFixQty = 0; oBillSub.HFixWorkDays = 0; oBillSub.HTrunWorkDays = 0; oBillSub.HReadyTimes = 0; oBillSub.HMyWorkDays = 0; oBillSub.HOutPrice = 0; oBillSub.HOutMoney = 0; oBillSub.HPassRate = 0; oBillSub.HLastProc = ""; oBillSub.HKeyProc = ""; oBillSub.HFstProc = ""; oBillSub.HICMOInterID = HICMOInterID; oBillSub.HICMOBillNo = HICMOBillNo; oBillSub.HWWOrderInterID = 0; oBillSub.HWWOrderEntryID = 0; oBillSub.HWWOrderBillNo = ""; oBillSub.HReportQty = 0; oBillSub.HBackProc = false; oBillSub.HSupID = 0; oBillSub.HSupFlag = false; oBillSub.HOverRate = 0; oBillSub.HMaxQty = 0; oBillSub.HTechnologyParameter = ""; oBillSub.HProcCheckNote = ""; oBillSub.HPicNum = ""; oBillSub.HMouldNo = ""; oBillSub.HProcWorkNum = ""; oBillSub.HSeOrderInterID = 0; oBillSub.HSeOrderEntryID = 0; oBillSub.HSNCtrl = false; oBillSub.HRoutingBillMainID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HRoutingID"]); oBillSub.HRoutingBillEntryID = Pub_Class.ClsPub.isLong(ds.Tables[0].Rows[j]["HRoutingEntryID"]); BillNew.DetailColl.Add(oBillSub);//添加明细行值 } //调用保存方法 bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo); BillNew.DetailColl.Clear();//清空明细行值 if (!bResult) { break; } } if (bResult) { BillChange = true; MessageBox.Show("单据保存完毕!", "提示"); this.Sub_OperStatus(); return true; } else { MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示"); return false; } } catch(Exception e1) { MessageBox.Show(ClsPub.sExeReturnInfo + e1.Message); return false; } } #endregion #region 窗体处理方法 //初始化GRID private void initGrid() { // grdMain.ColumnCount = 24; //总列数 DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); // grdMain.RowsDefaultCellStyle.WrapMode = DataGridViewTriState.True; grdMain.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; //标题行高 调整模式 grdMain.RowHeadersVisible = true; grdMain.AllowUserToResizeRows = true; //允许调整行高--否 // 设置列标题和属性 // 序号列(自动编号) grdMain.Columns[HSnoCol].HeaderText = "序号"; grdMain.Columns[HSnoCol].Width = 100; grdMain.Columns[HSnoCol].ReadOnly = true; // 生产订单内码 - 隐藏 grdMain.Columns[HICMOInterIDCol].HeaderText = "生产订单内码"; grdMain.Columns[HICMOInterIDCol].Width = 100; grdMain.Columns[HICMOInterIDCol].Visible = false; // 生产订单子内码 - 隐藏 grdMain.Columns[HICMOEntryIDCol].HeaderText = "生产订单子内码"; grdMain.Columns[HICMOEntryIDCol].Width = 100; grdMain.Columns[HICMOEntryIDCol].Visible = false; // 生产订单号 grdMain.Columns[HICMOBillNoCol].HeaderText = "生产订单号"; grdMain.Columns[HICMOBillNoCol].Width = 120; grdMain.Columns[HICMOBillNoCol].ReadOnly = true; // 生产车间 - 隐藏 grdMain.Columns[HWorkShopIDCol].HeaderText = "生产车间"; grdMain.Columns[HWorkShopIDCol].Width = 100; grdMain.Columns[HWorkShopIDCol].Visible = false; // HMaterID - 隐藏 grdMain.Columns[HMaterIDCol].HeaderText = "HMaterID"; grdMain.Columns[HMaterIDCol].Width = 100; grdMain.Columns[HMaterIDCol].Visible = false; // 物料代码 grdMain.Columns[HMaterNumberCol].HeaderText = "物料代码"; grdMain.Columns[HMaterNumberCol].Width = 150; grdMain.Columns[HMaterNumberCol].ReadOnly = true; // 物料名称 grdMain.Columns[HMaterNameCol].HeaderText = "物料名称"; grdMain.Columns[HMaterNameCol].Width = 150; grdMain.Columns[HMaterNameCol].ReadOnly = true; // 规格型号 - 隐藏 grdMain.Columns[HMaterModelCol].HeaderText = "规格型号"; grdMain.Columns[HMaterModelCol].Width = 100; grdMain.Columns[HMaterModelCol].Visible = false; // 订单总数 grdMain.Columns[HQtyCol].HeaderText = "订单总数"; grdMain.Columns[HQtyCol].Width = 110; grdMain.Columns[HQtyCol].ReadOnly = true; // 流转卡数量 - 可编辑 grdMain.Columns[HProQtyCol].HeaderText = "流转卡数量"; grdMain.Columns[HProQtyCol].Width = 110; grdMain.Columns[HProQtyCol].ReadOnly = false; // 批次号 - 隐藏 grdMain.Columns[HBatchNoCol].HeaderText = "批次号"; grdMain.Columns[HBatchNoCol].Width = 110; grdMain.Columns[HBatchNoCol].Visible = false; grdMain.Columns[HBatchNoCol].ReadOnly = false; // 项目编号 - 隐藏 grdMain.Columns[HProjectNumCol].HeaderText = "项目编号"; grdMain.Columns[HProjectNumCol].Width = 110; grdMain.Columns[HProjectNumCol].Visible = false; grdMain.Columns[HProjectNumCol].ReadOnly = false; // 原料批次 - 隐藏 grdMain.Columns[HMateOutBatchNoCol].HeaderText = "原料批次"; grdMain.Columns[HMateOutBatchNoCol].Width = 110; grdMain.Columns[HMateOutBatchNoCol].Visible = false; grdMain.Columns[HMateOutBatchNoCol].ReadOnly = false; // 模穴号 - 隐藏 grdMain.Columns[HMouldNumCol].HeaderText = "模穴号"; grdMain.Columns[HMouldNumCol].Width = 110; grdMain.Columns[HMouldNumCol].Visible = false; // 班组 - 隐藏 grdMain.Columns[HGroupNumberCol].HeaderText = "班组"; grdMain.Columns[HGroupNumberCol].Width = 110; grdMain.Columns[HGroupNumberCol].Visible = false; grdMain.Columns[HGroupNumberCol].ReadOnly = false; // 启用批次 - 隐藏 grdMain.Columns[HBatchManagerCol].HeaderText = "启用批次"; grdMain.Columns[HBatchManagerCol].Width = 110; grdMain.Columns[HBatchManagerCol].Visible = false; // 工艺路线内码 - 隐藏 grdMain.Columns[HRoutingInterIDCol].HeaderText = "工艺路线内码"; grdMain.Columns[HRoutingInterIDCol].Width = 150; grdMain.Columns[HRoutingInterIDCol].Visible = false; // 工艺路线代码 grdMain.Columns[HRoutingNumberCol].HeaderText = "工艺路线代码"; grdMain.Columns[HRoutingNumberCol].Width = 170; grdMain.Columns[HRoutingNumberCol].ReadOnly = true; // 工艺路线 grdMain.Columns[HRoutingNameCol].HeaderText = "工艺路线"; grdMain.Columns[HRoutingNameCol].Width = 170; grdMain.Columns[HRoutingNameCol].ReadOnly = true; // 流转卡日期 - 可编辑 grdMain.Columns[HDateCol].HeaderText = "流转卡日期"; grdMain.Columns[HDateCol].Width = 120; grdMain.Columns[HDateCol].ReadOnly = false; // 流转卡内码 - 隐藏 grdMain.Columns[HInterIDCol].HeaderText = "流转卡内码"; grdMain.Columns[HInterIDCol].Width = 130; grdMain.Columns[HInterIDCol].Visible = false; grdMain.Columns[HEditCol].HeaderText = "不可编辑"; grdMain.Columns[HEditCol].Visible = false; // 流转卡号 grdMain.Columns[HBillNoCol].HeaderText = "流转卡号"; grdMain.Columns[HBillNoCol].Width = 170; grdMain.Columns[HBillNoCol].ReadOnly = true; // 设置可编辑列 string sAllowCol = HProQtyCol.ToString() + "," + HBatchNoCol.ToString() + "," + HProjectNumCol.ToString() + "," + HMateOutBatchNoCol.ToString() + "," + HGroupNumberCol.ToString() + "," + HDateCol.ToString(); // 设置合计列 string sTotalCol = HQtyCol.ToString() + "," + HProQtyCol.ToString(); for (int i = 0; i < grdMain.Rows.Count; i++) { DataGridViewCheckBoxCell oCell2 = new DataGridViewCheckBoxCell(); oCell2.ThreeState = false; oCell2.Value = 0; oCell2.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; grdMain.Rows[i].Cells[HEditCol] = oCell2; } //格式化网格 DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid); oSumGrid.SetGridMain(); DBUtility.ClsPub.HideGridView(grdMain, Name, ClsPub.AppPath);//设置隐藏列 } //公式重算 /// /// /// /// /// public void Sub_RowCount(int sRow, int sCol) { if (IsNullRow(sRow)) return; if (sCol == 0) { } else { } } //重算全部行 public void ReCountAllRow() { for (int i = 0; i < grdMain.Rows.Count; i++) { } } //核对选择的内容 public bool CheckGridCell(Cell oCell) { int Row; int Col; Row = oCell.Row; Col = oCell.Col; oSumGrid.EditStatus = false; return true; } //'判断网格行的录入是否正确 private bool CheckGridRow(int Row) { Cell oCell = new Cell(); int c = 0; return true; } //帮助函数 private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit) { if (!grdStatus) { return; } oSumGrid.EditStatus = true; switch (sKeyCode) { default: break; } } #region 基本不变 //是否是空行 private bool IsNullRow(int Row) { return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HICMOInterIDCol, grdMain); } //网格编辑前判断 private void grdMain_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { int i = grdMain.CurrentCell.ColumnIndex; if (DBUtility.ClsPub.isBool(grdMain.Rows[grdMain.CurrentRow.Index].Cells[HEditCol].Value) == true) { e.Cancel = true; } if (DBUtility.Xt_BaseBillFun.AllowEdit(grdStatus, oSumGrid, i)) { e.Cancel = true; } } private void grdMain_Scroll(object sender, ScrollEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); oSumGrid.DisplayCurRow(); } //网格编辑后处理 private void grdMain_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); Sub_RowCount(e.RowIndex, 0); //计算 金额 单价 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 (!CheckGridRow(oSumGrid.OldCell.Row)) return; } 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_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e) { DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } #endregion #endregion #region //打印设置 GridppReport Report; //预览 private void yl_Click(object sender, EventArgs e) { //选择打印模板 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(true); } } //找到对应打印模块 private void Sub_SetReport(string sOpenTmp) { // Report = new GridppReport(); Report.LoadFromFile(ClsPub.AppPath + @"\" + sOpenTmp + ".grf"); //here . Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord); Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable); } //赋值表头 private void ReportBeforePostRecord()// { try { //Report.FieldByName("流转卡编号").AsString = txtHBillNo.Text; //Report.FieldByName("流转卡数量").AsString = txtHQty.Text; //Report.FieldByName("产品代码").AsString = txtHMaterNumber2.Text; //Report.FieldByName("产品名称").AsString = txtHMaterID2.Text; //Report.FieldByName("计划开工日期").AsString = dtpHPlanBeginDate.Value.ToShortDateString(); //Report.FieldByName("计划完工日期").AsString = dtpHPlanEndDate.Value.ToShortDateString(); //Report.FieldByName("订单跟踪号").AsString = txtHOrderProcNO.Text; //Report.FieldByName("原料批次").AsString = txtHMateOutBatchNo.Text; //Report.FieldByName("模具设备").AsString = txtHEquipMentID.Text; //Report.FieldByName("项目号").AsString = txtHProjectNum.Text; //Report.FieldByName("图号版本").AsString = textHPicNumVer.Text; //Report.FieldByName("总装图号").AsString = textHPicNumAssemble.Text; //Report.FieldByName("材质").AsString = textHMaterTexture.Text; //Report.FieldByName("成品编号").AsString = textHProductNum.Text; //Report.FieldByName("版本").AsString = textHVerNum.Text; } catch (Exception e) { MessageBox.Show("打印失败,[项目号],[流转卡编号],[流转卡数量],[产品代码],[产品名称],[计划开工日期],[计划完工日期],[订单跟踪号],[原料批次],[模具设备],[图号版本],[总装图号],[材质],[成品编号],[版本]." + e.Message); } } //赋值表体 private void ReportFetchRecordByDataTable() { DataTable oDt = new DataTable(); BLL.Utility.FillRecordToReport(Report, grdMain, oDt, HBillNoCol); } //打印设置 private void set_Click(object sender, EventArgs e) { // BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp(); oFrm.sBillName = ModName; oFrm.sBillModel = ModCaption; oFrm.ShowDialog(); } //打印 private void dy_Click(object sender, EventArgs e) { //选择打印模板 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); BillOld.Set_PrintQty(DBUtility.ClsPub.isLong(BillOld.omodel.HInterID)); Report.Print(true); } } #endregion #region 源单处理 #endregion private void yc_Click(object sender, EventArgs e) { BLL.Gy_GridView_Hide oHide = new BLL.Gy_GridView_Hide(); oHide.KeyItem = this.Name; oHide.oGrd = grdMain; oHide.ShowDialog(); // DBUtility.ClsPub.HideGridView(grdMain, Name, ClsPub.AppPath);//设置隐藏列 } private void 隐藏列设置ToolStripMenuItem_Click(object sender, EventArgs e) { } private void grdMain_KeyDown(object sender, KeyEventArgs e) { } private void grdMain_MouseUp(object sender, MouseEventArgs e) { if (grdMain.CurrentRow == null) return; } //显示库存 private void ShowStockQty(int sRow) { } private void tm_Click(object sender, EventArgs e) { Sub_ShowBill_Sub(); } //显示单据 条码 public void Sub_ShowBill_Sub() { DAL.ClsIF_Warehouse_View oWare = new DAL.ClsIF_Warehouse_View(); DAL.ClsIF_Material_View oMater = new DAL.ClsIF_Material_View(); //加载表体 int i = 0; } private void cmdSourceBillNo_Click(object sender, EventArgs e) { DAL.Cls_S_IF_ICMOBillList oYD = new DAL.Cls_S_IF_ICMOBillList(); string sWhere = " "; if (oYD.Refresh(sWhere)) //选择原单 { FillSelectData(oYD.oBillSelectColl); //为什么这里是0 } } private void FillSelectData(List oList) { DataSet Ds; SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); oSumGrid.Changelock = true; initGrid(); int i = -1; foreach (DBUtility.BillSelect oSelectRow in oList) { i = i + 1; // if (oSelectRow.BillType == "85") { grdMain.Rows.Add(); Application.DoEvents(); //得到信息 Ds = oCn.RunProcReturn("select * from h_v_S_Sc_ICMOBillList where hmainid=" + oSelectRow.BillMainID, "h_v_S_Sc_ICMOBillList"); //写入信息 Sub_WriteInForm(Ds.Tables[0], i); Application.DoEvents(); } } // oSumGrid.Changelock = false; DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); } //根据TABLE写入界面 public void Sub_WriteInForm(DataTable oTable, int j) { DataSet Ds; SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); string sNo = ""; int row = oTable.Rows.Count - 1; // 用于记录当前的生产订单和对应的流转卡信息 string currentSourceInterID = ""; string currentSourceEntryID = ""; string baseBillNo = ""; int k = 1; // 序号计数器 for (int i = 0; i <= oTable.Rows.Count - 1; i++) { if (i >= grdMain.RowCount - 1) grdMain.Rows.Add(); string icmoInterID = oTable.Rows[i]["HICMOInterID"].ToString(); string icmoEntryID = oTable.Rows[i]["HICMOEntryID"].ToString(); string hInterID = "0"; // 默认内码为0 string hBillNo = ""; // 流转卡号 if (i == 0) { // 首次进入,获取基础流转卡单号 baseBillNo = ClsPub.CreateBillCode_Prod("3772", ref ClsPub.sExeReturnInfo, true); hBillNo = baseBillNo + "-" + k.ToString().PadLeft(2, '0'); currentSourceInterID = icmoInterID; currentSourceEntryID = icmoEntryID; } else if (currentSourceInterID == icmoInterID && currentSourceEntryID == icmoEntryID) { // 同一个生产订单,递增序号 k++; hBillNo = baseBillNo + "-" + k.ToString().PadLeft(2, '0'); } else { // 新的生产订单,重置序号和基础单号 baseBillNo = ClsPub.CreateBillCode_Prod("3772", ref ClsPub.sExeReturnInfo, true); k = 1; hBillNo = baseBillNo + "-" + k.ToString().PadLeft(2, '0'); currentSourceInterID = icmoInterID; currentSourceEntryID = icmoEntryID; } // 加载表体数据到新定义的列 grdMain.Rows[i].Cells[HICMOInterIDCol].Value = oTable.Rows[i]["HICMOInterID"].ToString(); grdMain.Rows[i].Cells[HICMOEntryIDCol].Value = oTable.Rows[i]["HICMOEntryID"].ToString(); grdMain.Rows[i].Cells[HICMOBillNoCol].Value = oTable.Rows[i]["HICMOBillNo"].ToString(); grdMain.Rows[i].Cells[HWorkShopIDCol].Value = oTable.Rows[i]["HWorkShopID"].ToString(); grdMain.Rows[i].Cells[HMaterIDCol].Value = oTable.Rows[i]["HMaterID"].ToString(); grdMain.Rows[i].Cells[HMaterNumberCol].Value = oTable.Rows[i]["物料代码"].ToString(); grdMain.Rows[i].Cells[HMaterNameCol].Value = oTable.Rows[i]["物料名称"].ToString(); grdMain.Rows[i].Cells[HMaterModelCol].Value = oTable.Rows[i]["规格型号"].ToString(); grdMain.Rows[i].Cells[HQtyCol].Value = DBUtility.ClsPub.isDoule(oTable.Rows[i]["HQty"], 0); grdMain.Rows[i].Cells[HProQtyCol].Value = DBUtility.ClsPub.isDoule(oTable.Rows[i]["HProQty"], 0); grdMain.Rows[i].Cells[HBatchNoCol].Value = oTable.Rows[i]["HBatchNo"].ToString(); grdMain.Rows[i].Cells[HProjectNumCol].Value = ""; grdMain.Rows[i].Cells[HMateOutBatchNoCol].Value = ""; grdMain.Rows[i].Cells[HMouldNumCol].Value = "0#"; grdMain.Rows[i].Cells[HGroupNumberCol].Value = ""; grdMain.Rows[i].Cells[HBatchManagerCol].Value = oTable.Rows[i]["是否启用批次"].ToString(); grdMain.Rows[i].Cells[HRoutingInterIDCol].Value = oTable.Rows[i]["HRoutingInterID"].ToString(); grdMain.Rows[i].Cells[HRoutingNumberCol].Value = oTable.Rows[i]["HRoutingNumber"].ToString(); grdMain.Rows[i].Cells[HRoutingNameCol].Value = oTable.Rows[i]["HRoutingName"].ToString(); grdMain.Rows[i].Cells[HDateCol].Value = oTable.Rows[i]["HDate"].ToString(); grdMain.Rows[i].Cells[HInterIDCol].Value = hInterID; // 默认为0,保存时再生成实际内码 grdMain.Rows[i].Cells[HBillNoCol].Value = hBillNo; grdMain.Rows[i].Cells[HEditCol].Value = false; // 明确设置为可编辑 } } private void yc_Click_1(object sender, EventArgs e) { BLL.Gy_GridView_Hide oHide = new BLL.Gy_GridView_Hide(); oHide.KeyItem = this.Name; oHide.oGrd = grdMain; oHide.ShowDialog(); // DBUtility.ClsPub.HideGridView(grdMain, Name, ClsPub.AppPath);//设置隐藏列 } private void Sc_ProcessExchangeBill_KeyDown(object sender, KeyEventArgs e) { if (e.Modifiers == Keys.Control && e.KeyCode == Keys.S) //按Ctrl+ S触发 { this.Sub_SaveBill(); } } private void cmdWorkType_Click(object sender, EventArgs e) { } private void txtHPlanQty_TextChanged(object sender, EventArgs e) { } private void 隐藏列设置ToolStripMenuItem_Click_1(object sender, EventArgs e) { BLL.Gy_GridView_Hide oHide = new BLL.Gy_GridView_Hide(); oHide.KeyItem = this.Name; oHide.oGrd = grdMain; oHide.ShowDialog(); // DBUtility.ClsPub.HideGridView(grdMain, Name, ClsPub.AppPath);//设置隐藏列 } private void grdMain_CellContentClick(object sender, DataGridViewCellEventArgs e) { } // 新增方法:根据选中的订单ID查询并显示数据 private void LoadAndDisplaySelectedOrders() { try { ClsCN oCn = new ClsCN(); DataTable combinedTable = null; foreach (string orderId in SelectedOrderIds) { // 解析订单ID格式:主内码@子内码 string[] parts = orderId.Split('@'); if (parts.Length != 2) continue; Int64 HICMOID = DBUtility.ClsPub.isLong(parts[0]); Int64 HEntryID = DBUtility.ClsPub.isLong(parts[1]); string sql = "exec h_p_Sc_ProcessExchange_DH '" + HICMOID + "','" + HEntryID + "'"; DataSet Ds = oCn.RunProcReturn(sql, "h_p_Sc_ProcessExchange_DH"); if (Ds != null && Ds.Tables[0].Rows.Count > 0) { if (combinedTable == null) { combinedTable = Ds.Tables[0].Copy(); } else { // 合并数据 combinedTable.Merge(Ds.Tables[0]); } } } if (combinedTable != null && combinedTable.Rows.Count > 0) { // 直接调用现有的写入方法显示数据到明细页签 Sub_WriteInForm(combinedTable, 0); } else { MessageBox.Show("未能加载选中的生产订单数据!"); } } catch (Exception ex) { MessageBox.Show("加载订单数据失败:" + ex.Message); } } } }