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; namespace BaseSet { public partial class Gy_ProcPrice : Form { public Gy_ProcPrice() { InitializeComponent(); } //定义 public const Int16 HTagCol = 0; public const Int16 HSnoCol = 1; public const Int16 HMaterIDCol = 2; public const Int16 HMaterNumberCol = 3; public const Int16 HMaterNameCol = 4; public const Int16 HMaterModelCol = 5; public const Int16 HProcIDCol = 6; public const Int16 HProcNumberCol = 7; public const Int16 HProcNameCol = 8; public const Int16 HSourceIDCol = 9; public const Int16 HSourceNumberCol = 10; public const Int16 HSourceNameCol =11; public const Int16 HPriceCol = 12; public const Int16 HDeptIDCol = 13; public const Int16 HDeptNumberCol = 14; public const Int16 HDeptNameCol = 15; public const Int16 HBeginDateCol = 16; public const Int16 HEndDateCol = 17; public const Int16 HCostFlagCol = 18; public const Int16 HFlowFlagCol = 19; public const Int16 HPayFlagCol = 20; public const Int16 HWorkCenterIDCol = 21; public const Int16 HWorkCenterNumberCol = 22; public const Int16 HWorkCenterNameCol = 23; public const Int16 HWorkQtyCol = 24; public const Int16 HStdEmpCol = 25; public const Int16 HChangeTimesCol = 26; public const Int16 HChangeMoneyCol = 27; public const Int16 HProcNoCol = 28; public const Int16 HPieceTimesCol = 29; public const Int16 HMouldQtyCol = 30; public const Int16 HChangeMouldMoneyCol = 31; public const Int16 HRushQtyCol = 32; public const Int16 HRemarkCol = 33; public bool BillChange; // public DBUtility.ClsPub.Enum_OKTag OkTag; public DBUtility.ClsPub.Enum_BillStatus BillStatus; public Int64 KeyID; public const string ModName = "工序工价资料维护"; //权限 public const string ModRightName = "Gy_ProcPriceList"; public const string ModRightNameEdit = ModRightName + "_Edit"; public const string ModRightNameCheck = ModRightName + "_Check"; // public bool grdStatus; public DAL.ClsGy_ProcPrice_Ctl BillNew = new DAL.ClsGy_ProcPrice_Ctl(); public Model.ClsGy_ProcPrice_Model BillOld = new Model.ClsGy_ProcPrice_Model(); ClsGridViewSum oSumGrid = new ClsGridViewSum(); SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); public Int64 sHOrgID = -1; //------------------------------------------------------------------------- #region 固定代码 private void Total() { oSumGrid.Total(); } private void bclk_Click(object sender, EventArgs e) { //保存列宽 DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name); } private void mrlk_Click(object sender, EventArgs e) { DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name); } //清空界面 public void Sub_ClearBill() { //清空界面控件 for 控件 foreach (Control ct in gbUp.Controls) { switch (ct.GetType().Name) { case "ListBox": ((ListBox)ct).Items.Clear(); break; case "CheckBox": ((CheckBox)ct).Checked = false; break; case "RadioButton": break; case "ComboBox": ((ComboBox)ct).SelectedIndex = 0; break; case "TextBox": ((TextBox)ct).Text = ""; break; case "DateTimePicker": ((DateTimePicker)ct).Value = DateTime.Today; break; default: break; } } //显示当前登入组织 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"]); sHOrgID = ClsPub.HOrgID; } // initGrid(); } //编辑单据 private void Sub_EditBill() { //删除权限 if (!DBUtility.ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName)) { return; } if (BillOld.HChecker != "" && BillOld.HChecker != null) { MessageBox.Show("此单据已经被审核,不允许修改", "提示"); return; } //if (this.BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Viewonly) //{ // MessageBox.Show("此单据已经被审核,不允许修改", "提示"); // return; //} this.BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify; this.Sub_OperStatus(); } //删除单据 private void Sub_DeleteBill() { //删除权限 if (!DBUtility.ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName)) { return; } // if (BillOld.HChecker != "" && BillOld.HChecker != null) { MessageBox.Show("此单据已经被审核,不允许删除", "提示"); return; } //if (this.BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Viewonly) //{ // MessageBox.Show("此单据已经被审核,不允许删除", "提示"); // return; //} if (MessageBox.Show("确定要删除当前单据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { if (BillNew.DeleteByID(BillOld.HItemID) != true) { BillChange = true; MessageBox.Show("删除失败,原因:" + ClsPub.sExeReturnInfo, "提示"); return; } MessageBox.Show("删除成功", "提示"); BillOld = new Model.ClsGy_ProcPrice_Model(); BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View; this.Sub_OperStatus(); } } //离开单元格 private void grdMain_LeaveCell(object sender, EventArgs e) { oSumGrid.LeaveCell(); } //网格单元格变化事件 private void grdMain_RowColChange(object sender, EventArgs e) { // if (!grdStatus) { return; } oSumGrid.SetGridsum(); oSumGrid.Total(); // //if (oSumGrid.Changelock) // return; //if(oSumGrid.EditStatus) //{ if (!CheckGridRow(oSumGrid.OldCell.Row)) return; //} } private void Gy_ProcPrice_Paint(object sender, PaintEventArgs e)//画线 { //控件位置设置 } //控件位置 private void Sub_ControlLocation() { gbUp.Width = P1.Width - 20; gbUp.Left = 10; gbUp.Height = P1.Height - 35; gbUp.Top = 30; } //窗体加载 private void Gy_ProcPrice_Load(object sender, EventArgs e) { //打印初始化 oSumGrid.NoCol = HSnoCol; oSumGrid.ogrdMain = grdMain; oSumGrid.oGridsum = grdSum; lblCaption.Text = ModName; this.Text = ModName; //加载组织信息 Sub_AddOrdList(); } //加载组织信息 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.Items.Clear(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { cmbHOrgID.Items.Add(DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HName"])); } } //审核单据 private void Sub_CheckBill() { if (BillNew.CheckBill(BillOld.HItemID, ref ClsPub.sExeReturnInfo) == true) { BillChange = true; txtHChecker.Text = ClsPub.CurUserName; txtHCheckDate.Text = BillOld.HCheckDate; BillOld.HChecker = ClsPub.CurUserName; BillOld.HCheckDate = ClsPub.GetServerDate(-1); this.Sub_OperStatus();//刷新TOOL按钮 } else { MessageBox.Show("审核失败!原因:" + ClsPub.sExeReturnInfo, "提示"); } } //反审单据 private void Sub_AbandonCheck() { if (BillNew.AbandonCheck(BillOld.HItemID, ref ClsPub.sExeReturnInfo) == true) { BillChange = true; txtHChecker.Text = ""; txtHCheckDate.Text = ""; BillOld.HChecker =""; BillOld.HCheckDate =""; this.Sub_OperStatus();//刷新TOOL按钮 } else { MessageBox.Show("反审核失败!原因:" + ClsPub.sExeReturnInfo, "提示"); } } //新增按纽 private void xz_Click(object sender, EventArgs e) { this.Sub_AddBill(); } //修改按纽 private void xg_Click(object sender, EventArgs e) { this.Sub_EditBill(); } //删除按钮 private void sc_Click(object sender, EventArgs e) { this.Sub_DeleteBill(); } //保存按钮 private void bc_Click(object sender, EventArgs e) { this.Sub_SaveBill(); } //审核按钮 private void sh_Click(object sender, EventArgs e) { this.Sub_CheckBill(); } //放弃审核按钮 private void qsh_Click(object sender, EventArgs e) { this.Sub_AbandonCheck(); } //退出按钮 private void tc_Click(object sender, EventArgs e) { this.Close(); } //窗体尺寸变化时 private void Gy_ProcPrice_Resize(object sender, EventArgs e) { Sub_ControlLocation(); } //根据编辑状态 设置 控件是否允许录入 private void Sub_LrtextStatus(bool TextEnabled) { if (TextEnabled == true) { //控件全部有效 gbUp.Enabled = true; } else { //控件全部无效 gbUp.Enabled = false; } } //timer private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; Sub_ControlLocation(); if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_View)//|| BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Viewonly { this.Sub_ShowBill(); } else { this.Sub_AddBill(); } oSumGrid.SetGridsum(); } //窗体卸载 private void Gy_ProcPrice_FormClosing(object sender, FormClosingEventArgs e) { BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; } //新增单据 private void Sub_AddBill() { this.BillNew = new DAL.ClsGy_ProcPrice_Ctl(); this.BillOld = new Model.ClsGy_ProcPrice_Model(); 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_View: //case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Viewonly: //浏览状态 yl.Enabled = true; xz.Enabled = true; xg.Enabled = true; sc.Enabled = true; AddRow.Enabled = false; DelRow.Enabled = false; bc.Enabled = false; tc.Enabled = true; //未审核 if (txtHChecker.Text.Trim() == "") { xg.Enabled = true; sc.Enabled = true; } else { xg.Enabled = false; sc.Enabled = false; } Sub_LrtextStatus(false); grdStatus = false; break; case DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew: //新增状态 yl.Enabled = false; xz.Enabled = false; xg.Enabled = false; sc.Enabled = false; AddRow.Enabled = true; DelRow.Enabled = true; bc.Enabled = true; tc.Enabled = true; Sub_LrtextStatus(true); grdStatus = true; break; case DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify: //修改状态 yl.Enabled = false; xz.Enabled = false; xg.Enabled = false; sc.Enabled = false; AddRow.Enabled = true; DelRow.Enabled = true; bc.Enabled = true; tc.Enabled = true; Sub_LrtextStatus(true); grdStatus = true; break; } } #endregion #region 读写类 //显示单据 public void Sub_ShowBill() { DAL.ClsIF_Material_View oMater = new DAL.ClsIF_Material_View(); DAL.ClsIF_Process_View oProc = new DAL.ClsIF_Process_View(); DAL.ClsIF_Department_View oDept = new DAL.ClsIF_Department_View(); DAL.ClsIF_Source_View oSource = new DAL.ClsIF_Source_View(); DAL.ClsIF_WorkCenter_View oWorkCenter = new DAL.ClsIF_WorkCenter_View(); //判断是否存在单据 if (BillNew.ShowBill(BillOld.HItemID,ref ClsPub.sExeReturnInfo)==false ) { MessageBox.Show(ClsPub.sExeReturnInfo, "提示"); return; } //清空 Sub_ClearBill(); //grid禁止刷新 //加载表头 //if (oDept.GetInfoByID(BillOld.HDeptID)) //{ // this.txtHDeptID.Text = oDept.omodel.HName; // this.txtHDeptID.Tag = oDept.omodel.HItemID.ToString().Trim(); //} //else //{ // this.txtHDeptID.Text = ""; //} // this.txtHMaker.Text = BillOld.HMaker; this.txtHMakeDate.Text = BillOld.HMakeDate; this.txtHChecker.Text = BillOld.HChecker; //加载表体 initGrid(); int i = 0; foreach (Model.ClsGy_ProcPrice_Model oSub in BillNew.DetailColl) { if (oDept.GetInfoByID(oSub.HDeptID)) { txtHDeptID.Tag = oDept.omodel.HItemID.ToString(); txtHDeptID.Text = oDept.omodel.HName; } else { txtHDeptID.Tag = ""; } // if (i >= grdMain.RowCount - 1) grdMain.Rows.Add(); grdMain.Rows[i].Cells[HTagCol].Value = "*"; grdMain.Rows[i].Cells[HMaterIDCol].Value = oSub.HMaterID.ToString(); if (oMater.GetInfoByID(oSub.HMaterID)) { grdMain.Rows[i].Cells[HMaterNumberCol].Value = oMater.omodel.HNumber; grdMain.Rows[i].Cells[HMaterNameCol].Value = oMater.omodel.HName; grdMain.Rows[i].Cells[HMaterModelCol].Value = oMater.omodel.HModel; } else { grdMain.Rows[i].Cells[HMaterNumberCol].Value = ""; grdMain.Rows[i].Cells[HMaterNameCol].Value = ""; grdMain.Rows[i].Cells[HMaterModelCol].Value = ""; } grdMain.Rows[i].Cells[HProcIDCol].Value = oSub.HProcID.ToString(); if (oProc.GetInfoByID(oSub.HProcID)) { grdMain.Rows[i].Cells[HProcNumberCol].Value = oProc.omodel.HNumber; grdMain.Rows[i].Cells[HProcNameCol].Value = oProc.omodel.HName; } else { grdMain.Rows[i].Cells[HProcNumberCol].Value = ""; grdMain.Rows[i].Cells[HProcNameCol].Value = ""; } grdMain.Rows[i].Cells[HSourceIDCol].Value = oSub.HSourceID.ToString(); if (oSource.GetInfoByID(oSub.HSourceID)) { grdMain.Rows[i].Cells[HSourceNumberCol].Value = oSource.omodel.HNumber; grdMain.Rows[i].Cells[HSourceNameCol].Value = oSource.omodel.HName; } else { grdMain.Rows[i].Cells[HSourceNumberCol].Value = ""; grdMain.Rows[i].Cells[HSourceNameCol].Value = ""; } if (oWorkCenter.GetInfoByID(oSub.HWorkCenterID)) { grdMain.Rows[i].Cells[HWorkCenterNumberCol].Value = oWorkCenter.omodel.HNumber; grdMain.Rows[i].Cells[HWorkCenterNameCol].Value = oWorkCenter.omodel.HName; } else { grdMain.Rows[i].Cells[HWorkCenterNumberCol].Value = ""; grdMain.Rows[i].Cells[HWorkCenterNameCol].Value = ""; } grdMain.Rows[i].Cells[HBeginDateCol].Value = oSub.HBeginDate.ToShortDateString(); grdMain.Rows[i].Cells[HEndDateCol].Value = oSub.HEndDate.ToShortDateString(); grdMain.Rows[i].Cells[HCostFlagCol].Value = oSub.HCostFlag.ToString(); grdMain.Rows[i].Cells[HFlowFlagCol].Value = oSub.HFlowFlag.ToString(); grdMain.Rows[i].Cells[HPayFlagCol].Value = oSub.HPayFlag.ToString(); grdMain.Rows[i].Cells[HPriceCol].Value = oSub.HPrice.ToString(); grdMain.Rows[i].Cells[HWorkQtyCol].Value = oSub.HWorkQty.ToString(); grdMain.Rows[i].Cells[HStdEmpCol].Value = oSub.HStdEmp.ToString(); grdMain.Rows[i].Cells[HChangeTimesCol].Value = oSub.HChangeTimes.ToString(); grdMain.Rows[i].Cells[HChangeMoneyCol].Value = oSub.HChangeMoney.ToString(); grdMain.Rows[i].Cells[HProcNoCol].Value = oSub.HProcNo.ToString(); grdMain.Rows[i].Cells[HPieceTimesCol].Value = oSub.HPieceTimes.ToString(); grdMain.Rows[i].Cells[HMouldQtyCol].Value = oSub.HMouldQty.ToString(); grdMain.Rows[i].Cells[HChangeMouldMoneyCol].Value = oSub.HChangeMouldMoney.ToString(); grdMain.Rows[i].Cells[HRushQtyCol].Value = oSub.HRushQty.ToString(); grdMain.Rows[i].Cells[HRemarkCol].Value = oSub.HRemark; i = i + 1; } //GRID允许刷新 DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); //合计 Total(); // Sub_OperStatus(); //oBillSub = null; } //单据完整性判断 未完成 private bool Sub_AllowSave() { //必输项目是否为空 //ClsK3_DepartmentHlp oDept = new ClsK3_DepartmentHlp(); //if(!oDept.GetInfoByID(ClsPub.isLong(txtHDeptID.Tag))) //{ // MessageBox.Show("部门不存在!"); // 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() { Model.ClsGy_ProcPrice_Model oBillSub = new Model.ClsGy_ProcPrice_Model(); Int32 i; bool bResult; BillNew = new DAL.ClsGy_ProcPrice_Ctl(); //编辑权限 //if (!ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName)) //{ // return false; //} //失去焦点 lblCaption.Focus(); // if (!Sub_AllowSave())//单据完整性判断 return false; // //明细类赋值 BillNew.DetailColl = new List(); for (i = 0; i <= grdMain.RowCount - 1; i++) { if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value) != 0 && DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HProcIDCol].Value) != 0) { Model.ClsGy_ProcPrice_Model oSub = new Model.ClsGy_ProcPrice_Model(); oSub.HMaterID = ClsPub.isLong(grdMain.Rows[i].Cells[HMaterIDCol].Value); oSub.HProcID = ClsPub.isLong(grdMain.Rows[i].Cells[HProcIDCol].Value); oSub.HSourceID = ClsPub.isLong(grdMain.Rows[i].Cells[HSourceIDCol].Value); oSub.HPrice = ClsPub.isDoule(grdMain.Rows[i].Cells[HPriceCol].Value); oSub.HBeginDate = ClsPub.isDate(grdMain.Rows[i].Cells[HBeginDateCol].Value); oSub.HEndDate = ClsPub.isDate(grdMain.Rows[i].Cells[HEndDateCol].Value); oSub.HCostFlag = ClsPub.GridToBool(grdMain.Rows[i].Cells[HCostFlagCol].Value); oSub.HFlowFlag = ClsPub.GridToBool(grdMain.Rows[i].Cells[HFlowFlagCol].Value); oSub.HPayFlag = ClsPub.GridToBool(grdMain.Rows[i].Cells[HPayFlagCol].Value); oSub.HDeptID = ClsPub.isLong(txtHDeptID.Tag); oSub.HStopflag = false; oSub.HMaker = ClsPub.CurUserName; oSub.HMakeDate = DateTime.Today.ToString(); oSub.HRemark = ClsPub.isStrNull(grdMain.Rows[i].Cells[HRemarkCol].Value); oSub.HWorkCenterID = ClsPub.isLong(grdMain.Rows[i].Cells[HWorkCenterIDCol].Value); oSub.HWorkQty = ClsPub.isSingle(grdMain.Rows[i].Cells[HWorkQtyCol].Value); oSub.HStdEmp = ClsPub.isSingle(grdMain.Rows[i].Cells[HStdEmpCol].Value); oSub.HChangeTimes = ClsPub.isSingle(grdMain.Rows[i].Cells[HChangeTimesCol].Value); oSub.HChangeMoney = ClsPub.isSingle(grdMain.Rows[i].Cells[HChangeMoneyCol].Value); oSub.HProcNo = ClsPub.isLong(grdMain.Rows[i].Cells[HProcNoCol].Value); oSub.HPieceTimes = ClsPub.isSingle(grdMain.Rows[i].Cells[HPieceTimesCol].Value); oSub.HMouldQty = ClsPub.isSingle(grdMain.Rows[i].Cells[HMouldQtyCol].Value); oSub.HChangeMouldMoney = ClsPub.isSingle(grdMain.Rows[i].Cells[HChangeMouldMoneyCol].Value); oSub.HRushQty = ClsPub.isSingle(grdMain.Rows[i].Cells[HRushQtyCol].Value); BillNew.DetailColl.Add(oSub); } } //保存完毕后处理 if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew) { bResult = BillNew.AddNew(); } else { bResult = BillNew.ModifyByID(BillOld.HItemID); } //提示 if (bResult == true) { BillChange = true; if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew) { MessageBox.Show("保存成功,最新数据请返回列表查看!", "提示"); this.Sub_AddBill(); } else if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify) { MessageBox.Show("修改成功!", "提示"); BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View; } this.Sub_OperStatus(); return true; } else { MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示"); return false; } } #endregion #region 窗体处理方法 private void txtHDeptID_TextChanged(object sender, EventArgs e) { if (txtHDeptID.Text.Trim() == "") { txtHDeptID.Tag = "0"; } } private void txtHCusID_TextChanged(object sender, EventArgs e) { if (txtHProcID.Text.Trim() == "") txtHProcID.Tag = "0"; } private void txtHMaterID_TextChanged(object sender, EventArgs e) { if (txtHMaterID.Text.Trim() == "") txtHMaterID.Tag = "0"; } //初始化GRID private void initGrid() { grdMain.RowCount = 0; grdMain.ColumnCount = 34; //总列数 DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); // grdMain.Columns[HMaterIDCol].HeaderText = "物料ID"; grdMain.Columns[HMaterNumberCol].HeaderText = "物料代码"; grdMain.Columns[HMaterNameCol].HeaderText = "物料名称"; grdMain.Columns[HMaterModelCol].HeaderText = "规格型号"; grdMain.Columns[HProcIDCol].HeaderText = "工序ID"; grdMain.Columns[HProcNumberCol].HeaderText = "工序代码"; grdMain.Columns[HProcNameCol].HeaderText = "工序名称"; grdMain.Columns[HSourceNumberCol].HeaderText = "资源代码"; grdMain.Columns[HSourceNameCol].HeaderText = "资源名称"; grdMain.Columns[HDeptIDCol].HeaderText = "部门ID"; grdMain.Columns[HDeptNumberCol].HeaderText = "部门代码"; grdMain.Columns[HDeptNameCol].HeaderText = "部门名称"; grdMain.Columns[HCostFlagCol].HeaderText = "成本必选"; grdMain.Columns[HFlowFlagCol].HeaderText = "流转默认"; grdMain.Columns[HPayFlagCol].HeaderText = "工资默认"; grdMain.Columns[HBeginDateCol].HeaderText = "开始日期"; grdMain.Columns[HEndDateCol].HeaderText = "结束日期"; grdMain.Columns[HPriceCol].HeaderText = "单价"; grdMain.Columns[HRemarkCol].HeaderText = "备注"; grdMain.Columns[HWorkCenterIDCol].HeaderText = "工作中心ID"; grdMain.Columns[HWorkCenterNumberCol].HeaderText = "工作中心代码"; grdMain.Columns[HWorkCenterNameCol].HeaderText = "工作中心名称"; grdMain.Columns[HWorkQtyCol].HeaderText = "小时产能"; grdMain.Columns[HStdEmpCol].HeaderText = "标准人力"; grdMain.Columns[HChangeTimesCol].HeaderText = "换线时间"; grdMain.Columns[HChangeMoneyCol].HeaderText = "换线补贴"; grdMain.Columns[HProcNoCol].HeaderText = "工艺路线流水号"; grdMain.Columns[HPieceTimesCol].HeaderText = "单件加工时间"; grdMain.Columns[HMouldQtyCol].HeaderText = "模具数量"; grdMain.Columns[HChangeMouldMoneyCol].HeaderText = "换模补贴"; grdMain.Columns[HRushQtyCol].HeaderText = "单件冲次次数"; // //设置特殊列 //HOldMaterBackFlagCol 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[HCostFlagCol] = oCell; } 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[HFlowFlagCol] = oCell; } 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[HPayFlagCol] = oCell; } grdMain.Columns[HTagCol].Visible = false; grdMain.Columns[HProcIDCol].Visible = false; grdMain.Columns[HSourceIDCol].Visible = false; grdMain.Columns[HMaterIDCol].Visible = false; grdMain.Columns[HDeptIDCol].Visible = false; grdMain.Columns[HDeptNumberCol].Visible = false; grdMain.Columns[HDeptNameCol].Visible = false; grdMain.Columns[HWorkCenterIDCol].Visible = false; // string sAllowCol = HMaterNumberCol.ToString() + "," + HProcNumberCol.ToString() + "," + HPriceCol.ToString() + "," + HSourceNumberCol.ToString() + "," + HEndDateCol.ToString() + "," + HBeginDateCol.ToString() + "," + HCostFlagCol.ToString() + "," + HFlowFlagCol.ToString() + "," + HPayFlagCol.ToString() + "," + HWorkCenterNumberCol.ToString() + "," + HWorkQtyCol.ToString() + "," + HStdEmpCol.ToString() + "," + HChangeTimesCol.ToString() + "," + HChangeMoneyCol.ToString() + "," + HProcNoCol.ToString() + "," + HPieceTimesCol.ToString() + "," + HMouldQtyCol.ToString() + "," + HChangeMouldMoneyCol.ToString() + "," + HRushQtyCol.ToString() + "," + HRemarkCol.ToString(); string sTotalCol = HPriceCol.ToString(); //格式化网格 DBUtility.Xt_BaseBillFun.initGridLast(sAllowCol, sTotalCol, oSumGrid); } //公式重算 private void RowCount(int sRow,int sTag) { if (sTag == 0) { //金额列=数量*单价 } else { //单价列=金额/数量 } } //增行按钮 未完成 private void AddRow_Click(object sender, EventArgs e) { oSumGrid.Sub_AddRow(); } //删行按纽 未完成 private void DelRow_Click(object sender, EventArgs e) { oSumGrid.Sub_DelRow(); } //选择 private void cmdHCusID_Click(object sender, EventArgs e) { BLL.ClsBaseSelect_InterFace.SetTextByProc(txtHProcID,txtHProcName); } private void cmdHDeptID_Click(object sender, EventArgs e) { BLL.ClsBaseSelect_InterFace.SetTextByDept(txtHDeptID); } //选择班组 private void cmdHMaterID_Click(object sender, EventArgs e) { string sWhere = ""; sWhere = " and HUSEORGID = " + sHOrgID; BLL.ClsBaseSelect_InterFace.SetTextByMater(sWhere,txtHMaterID, txtHMaterName,txtHMaterModel); } //核对选择的内容 public bool CheckGridCell(Cell oCell) { int Row; int Col; Row = oCell.Row; Col = oCell.Col; //输入代码得到信息 if (Col == HMaterNumberCol) //物料代码列 { return false; } else //其他列 { } // oSumGrid.EditStatus = false; return true; } //是否是空行 private bool IsNullRow(int Row) { if (ClsPub.isLong(grdMain.Rows[Row].Cells[HMaterIDCol].Value) == 0) { return true; } return false; } //'判断网格行的录入是否正确 private bool CheckGridRow(int Row) { //Cell oCell = new Cell(); //int c = 0; //for (c = 0; c < grdMain.Cols; 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 = ""; if (!grdStatus) { return; } //if (oSumGrid.FindAllowEditCol(sCol)) //{ oSumGrid.EditStatus = true; //} //else //{ // return; //} switch (sKeyCode) { case 118: { switch (sCol) { case HMaterNumberCol: sWhere = " and HUSEORGID = " + sHOrgID; BLL.ClsBaseSelect_InterFace.SetGridByMater(grdMain, sWhere, sRow, HMaterIDCol, HMaterNumberCol, HMaterNameCol, HMaterModelCol, 0, 0, 0); if (rbHSelectCus.Checked) { grdMain.Rows[sRow].Cells[HProcIDCol].Value = txtHProcID.Tag.ToString(); grdMain.Rows[sRow].Cells[HProcNameCol].Value = txtHProcName.Text.Trim(); grdMain.Rows[sRow].Cells[HProcNumberCol].Value = txtHProcID.Text.Trim(); } grdMain.Rows[sRow].Cells[HPriceCol].Value = 1; grdMain.Rows[sRow].Cells[HBeginDateCol].Value = DateTime.Today.Date.ToShortDateString(); grdMain.Rows[sRow].Cells[HEndDateCol].Value = "2100-01-01"; grdMain.Rows[sRow].Cells[HCostFlagCol].Value = true; oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HMaterNumberCol].Value); break; case HProcNumberCol: //BLL.ClsBaseSelect.SetGridByProc(grdMain, sRow, HProcIDCol, HProcNumberCol, HProcNameCol); BLL.ClsBaseSelect_InterFace.SetGridByProc(grdMain, sRow, HProcIDCol, HProcNumberCol, HProcNameCol); if (rbHSelectMater.Checked) { grdMain.Rows[sRow].Cells[HMaterIDCol].Value = txtHMaterID.Tag.ToString(); grdMain.Rows[sRow].Cells[HMaterNumberCol].Value = txtHMaterID.Text.Trim(); grdMain.Rows[sRow].Cells[HMaterNameCol].Value = txtHMaterName.Text.Trim(); grdMain.Rows[sRow].Cells[HMaterModelCol].Value = txtHMaterModel.Text.Trim(); } grdMain.Rows[sRow].Cells[HPriceCol].Value = 1; grdMain.Rows[sRow].Cells[HBeginDateCol].Value = DateTime.Today.Date.ToShortDateString(); grdMain.Rows[sRow].Cells[HEndDateCol].Value = "2100-01-01"; grdMain.Rows[sRow].Cells[HCostFlagCol].Value = true; oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HProcNumberCol].Value); break; case HSourceNumberCol: BLL.ClsBaseSelect_InterFace.SetGridBySource(grdMain, sRow, HSourceIDCol, HSourceNumberCol, HSourceNameCol); oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HSourceNumberCol].Value); break; case HWorkCenterNumberCol: BLL.ClsBaseSelect_InterFace.SetGridByWorkCenter(grdMain, sRow, HWorkCenterIDCol, HWorkCenterNumberCol, HWorkCenterNameCol); oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HWorkCenterNumberCol].Value); break; default: break; } break; } case 117: MessageBox.Show("此功能尚未开放!", "提示"); break; default: break; } } DataGridViewTextBoxEditingControl EditingControl; 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); RowCount(e.RowIndex, 0); //计算 金额 单价 // if (this.EditingControl != null) //释放事件 { EditingControl.KeyDown -= new KeyEventHandler(this.EditingControl_KeyDown); this.EditingControl = null; } } 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_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 //选择组织时触发 private void cmbHOrgID_TextChanged(object sender, EventArgs e) { DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View(); if (oClsGy_ORGANIZATIONS_View.GetInfoByName(cmbHOrgID.Text)) { sHOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID; } if (sHOrgID == -1) { MessageBox.Show("选择组织有错误!"); return; } } } }