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 K3_Material_EditList : Form { public K3_Material_EditList() { InitializeComponent(); } //定义 public const Int16 HTagCol = 0; public const Int16 HSnoCol = 1; public const Int16 HParentIDCol = 2; public const Int16 HParentNumberCol = 3; public const Int16 HChartNumberCol = 4; public const Int16 HLongNumberCol = 5; public const Int16 HShortNumberCol = 6; public const Int16 HNameCol = 7; public const Int16 HModelCol = 8; public const Int16 HUnitGroupIDCol = 9; public const Int16 HUnitGroupNumberCol = 10; public const Int16 HUnitGroupNameCol =11; public const Int16 HUnitIDCol = 12; public const Int16 HUnitNumberCol = 13; public const Int16 HUnitNameCol =14; public const Int16 HErpClsIDCol = 15; public const Int16 HErpClsNameCol = 16; public const Int16 HRemarkCol = 17; 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 = "K3_Material_EditList"; public const string ModRightNameEdit = ModRightName + ""; public const string ModRightNameCheck = ModRightName + ""; // public bool grdStatus; //public DAL.ClsK3_Material_EditList_Ctl BillNew = new DAL.ClsK3_Material_EditList_Ctl(); //public Model.ClsK3_Material_EditList_Model BillOld = new Model.ClsK3_Material_EditList_Model(); ClsGridViewSum oSumGrid = new ClsGridViewSum(); //------------------------------------------------------------------------- #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; } } // initGrid(); } //编辑单据 private void Sub_EditBill() { //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.ClsK3_Material_EditList_Model(); // BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View; // this.Sub_OperStatus(); //} } //离开单元格 private void grdMain_LeaveCell(object sender, EventArgs e) { oSumGrid.LeaveCell(); } private void K3_Material_EditList_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 K3_Material_EditList_Load(object sender, EventArgs e) { //打印初始化 oSumGrid.NoCol = HSnoCol; oSumGrid.ogrdMain = grdMain; oSumGrid.oGridsum = grdSum; lblCaption.Text = ModName; this.Text = ModName; } //审核单据 private void Sub_CheckBill() { //if (BillNew.CheckBill(BillOld.HItemID, ref ClsPub.sExeReturnInfo) == true) //{ // BillChange = true; // txtHChecker.Text = ClsPub.CurUserName; // txtHCheckDate.Text = BillOld.HCheckDate.ToShortDateString(); // 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 = ""; // 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 K3_Material_EditList_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 K3_Material_EditList_FormClosing(object sender, FormClosingEventArgs e) { BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew; } //新增单据 private void Sub_AddBill() { //this.BillNew = new DAL.ClsK3_Material_EditList_Ctl(); //this.BillOld = new Model.ClsK3_Material_EditList_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 = true; DelRow.Enabled = true; bc.Enabled = true; tc.Enabled = true; //未审核 //if (txtHChecker.Text.Trim() == "") //{ // xg.Enabled = true; // sc.Enabled = true; //} //else //{ // xg.Enabled = false; // sc.Enabled = false; //} Sub_LrtextStatus(false); grdStatus = true; 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 读写类 //从临时BOM中 获取 未导入K3物料 public void Sub_ShowBill() { //清空 Sub_ClearBill(); //grid禁止刷新 //加载表头 //加载表体 initGrid(); //从临时BOM表 找到 K3中不存在的 物料 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); DataSet ds; ds = oCn.RunProcReturn("exec h_p_K3_Gy_GetNeedMaterICBomBillMain_tmp " + KeyID.ToString(), "h_t_Gy_ICBomBillMain_tmp"); if (ds == null || ds.Tables[0].Rows.Count ==0) { MessageBox.Show("没有需要导入K3的物料!", "提示"); return; } // for (int i = 0; i < ds.Tables[0].Rows.Count;i ++ ) { grdMain.Rows[i].Cells[HParentIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HMaterGroupID"]); grdMain.Rows[i].Cells[HParentNumberCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HParentNumber"]); grdMain.Rows[i].Cells[HUnitGroupIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitGroupID"]); grdMain.Rows[i].Cells[HUnitGroupNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HUnitGroupName"]); //grdMain.Rows[i].Cells[HUnitGroupNumberCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitGroupNumber"]); grdMain.Rows[i].Cells[HUnitIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitID"]); //grdMain.Rows[i].Cells[HUnitNumberCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitNumber"]); grdMain.Rows[i].Cells[HUnitNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HUnitName"]); grdMain.Rows[i].Cells[HErpClsIDCol].Value = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HErpClsID"]); grdMain.Rows[i].Cells[HErpClsNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HErpClsName"]); grdMain.Rows[i].Cells[HNameCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HMaterName"]); grdMain.Rows[i].Cells[HModelCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HMaterModel"]); grdMain.Rows[i].Cells[HShortNumberCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HChartNumber"]); grdMain.Rows[i].Cells[HLongNumberCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HMaterNumber"]); grdMain.Rows[i].Cells[HChartNumberCol].Value = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["HChartNumber"]); } //GRID允许刷新 //DBUtility.Xt_BaseBillFun.SetSumGrid(oSumGrid); //合计 Total(); // Sub_OperStatus(); //oBillSub = null; } //单据完整性判断 未完成 private bool Sub_AllowSave() { //必输项目是否为空 DAL.ClsIF_Material_View oMater = new DAL.ClsIF_Material_View(); //明细表是否为零行 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 i = 0; i < grdMain.RowCount; i++) { if (!IsNullRow(i)) { if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HLongNumberCol].Value) == "") { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 长代码!请录入!", "提示"); return false; } if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HShortNumberCol].Value) == "") { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 短代码!请录入!", "提示"); return false; } if (oMater.AllowNumber(DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HShortNumberCol].Value)) == false) { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 短代码存在【.】!不能保存!", "提示"); return false; } if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HChartNumberCol].Value) == "") { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 图号!请录入!", "提示"); return false; } if (oMater.AllowNumber(DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HChartNumberCol].Value)) == false) { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 图号存在【.】!不能保存!", "提示"); return false; } if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HNameCol].Value) == "") { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 物料名称!请录入!", "提示"); return false; } //if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[HModelCol].Value) == "") //{ // MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 规格型号!请录入!", "提示"); // return false; //} if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HUnitGroupIDCol].Value) == 0) { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 计量单位组!请录入!", "提示"); return false; } if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HUnitIDCol].Value) == 0) { MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 计量单位!请录入!", "提示"); return false; } //if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HErpClsIDCol].Value) == 0) //{ // MessageBox.Show("表体第" + Convert.ToString(i + 1) + "行 没有设置 物料属性!请录入!", "提示"); // return false; //} } } return true; } //保存单据 private bool Sub_SaveBill() { Int32 i; bool bResult; //编辑权限 //if (!ClsPub.Security_Log(ModRightNameEdit, 1, true, DBUtility.ClsPub.CurUserName)) //{ // return false; //} //失去焦点 lblCaption.Focus(); // if (!Sub_AllowSave())//单据完整性判断 return false; // pb1.Maximum = grdMain.RowCount ; pb1.Value = 0; //明细类赋值 DAL.ClsK3_Material_Edit_Ctl oMater; for (i = 0; i <= grdMain.RowCount - 1; i++) { System.Windows.Forms.Application.DoEvents(); // if (DBUtility.ClsPub.isLong(grdMain.Rows[i].Cells[HParentIDCol].Value) != 0 ) { oMater = new DAL.ClsK3_Material_Edit_Ctl(); //判断物料是否存在 if (oMater.IsExistsSameMaterial(ClsPub.isStrNull(grdMain.Rows[i].Cells[HLongNumberCol].Value), ClsPub.isStrNull(grdMain.Rows[i].Cells[HChartNumberCol].Value)) == false) { oMater.oModel.HParentID = ClsPub.isLong(grdMain.Rows[i].Cells[HParentIDCol].Value); oMater.oModel.HShortNumber = ClsPub.isStrNull(grdMain.Rows[i].Cells[HShortNumberCol].Value); oMater.oModel.HNumber = ClsPub.isStrNull(grdMain.Rows[i].Cells[HLongNumberCol].Value); oMater.oModel.HFullName = ClsPub.isStrNull(grdMain.Rows[i].Cells[HLongNumberCol].Value); oMater.oModel.HName = ClsPub.isStrNull(grdMain.Rows[i].Cells[HNameCol].Value); oMater.oModel.HModel = ClsPub.isStrNull(grdMain.Rows[i].Cells[HModelCol].Value); oMater.oModel.HUnitGroupID = ClsPub.isLong(grdMain.Rows[i].Cells[HUnitGroupIDCol].Value); oMater.oModel.HUnitID = ClsPub.isLong(grdMain.Rows[i].Cells[HUnitIDCol].Value); oMater.oModel.HChartNumber = ClsPub.isStrNull(grdMain.Rows[i].Cells[HChartNumberCol].Value); oMater.oModel.HErpClsID = ClsPub.isLong(grdMain.Rows[i].Cells[HErpClsIDCol].Value); oMater.oModel.HUserID = DBUtility.ClsPub.GetUser_K3(ClsPub.CurUserName); oMater.oModel.HUserName = ClsPub.CurUserName; oMater.oModel.HAcctID = 112; oMater.oModel.HLevel = DBUtility.ClsPub.GetLevel(ClsPub.isStrNull(grdMain.Rows[i].Cells[HLongNumberCol].Value)); oMater.oModel.HRemark = ""; if (oMater.AddNew() == false) { MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示"); return false; } grdMain.Rows[i].Cells[HRemarkCol].Value = "已导入"; } else { grdMain.Rows[i].Cells[HRemarkCol].Value = "已存在"; } } System.Windows.Forms.Application.DoEvents(); pb1.Value = i + 1; System.Windows.Forms.Application.DoEvents(); } bResult = true; //提示 if (bResult == true) { BillChange = true; MessageBox.Show("存盘完毕!", "提示"); //if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_AddNew) //{ // this.Sub_AddBill(); //} //else if (BillStatus == DBUtility.ClsPub.Enum_BillStatus.BillStatus_Modify) //{ // BillStatus = DBUtility.ClsPub.Enum_BillStatus.BillStatus_View; //} this.Sub_OperStatus(); return true; } else { MessageBox.Show("保存失败!原因:" + ClsPub.sExeReturnInfo, "提示"); return false; } } #endregion #region 窗体处理方法 //初始化GRID private void initGrid() { grdMain.ColumnCount = 18; //总列数 DBUtility.Xt_BaseBillFun.initGridFst(grdMain, this.Name); // grdMain.Columns[HSnoCol].HeaderText = "序号"; grdMain.Columns[HParentNumberCol].HeaderText = "上级代码"; grdMain.Columns[HChartNumberCol].HeaderText = "图号"; grdMain.Columns[HLongNumberCol].HeaderText = "长代码"; grdMain.Columns[HShortNumberCol].HeaderText = "短代码"; grdMain.Columns[HNameCol].HeaderText = "物料名称"; grdMain.Columns[HModelCol].HeaderText = "规格型号"; grdMain.Columns[HUnitGroupNumberCol].HeaderText = "计量单位组代码"; grdMain.Columns[HUnitGroupNameCol].HeaderText = "计量单位组"; grdMain.Columns[HUnitNumberCol].HeaderText = "计量单位代码"; grdMain.Columns[HUnitNameCol].HeaderText = "计量单位"; grdMain.Columns[HErpClsNameCol].HeaderText = "物料属性"; grdMain.Columns[HRemarkCol].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; //} grdMain.Columns[HTagCol].Visible = false; grdMain.Columns[HParentIDCol].Visible = false; grdMain.Columns[HUnitIDCol].Visible = false; grdMain.Columns[HUnitGroupIDCol].Visible = false; grdMain.Columns[HErpClsIDCol].Visible = false; grdMain.Columns[HErpClsNameCol].Visible = false; grdMain.Columns[HUnitNumberCol].Visible = false; grdMain.Columns[HUnitGroupNumberCol].Visible = false; // string sAllowCol = HNameCol.ToString() + "," + HModelCol.ToString() + "," + HUnitGroupNameCol.ToString() + "," + HUnitNameCol.ToString() + //"," + HErpClsNameCol.ToString() + "," + HRemarkCol.ToString(); string sTotalCol = HTagCol.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 bool IsNullRow(int Row) { if (ClsPub.isLong(grdMain.Rows[Row].Cells[HParentIDCol].Value) == 0) { return true; } return false; } //帮助函数 private void Sub_GridKey(int sKeyCode, int sRow, int sCol, DataGridViewTextBoxEditingControl oEdit) { DAL.ClsK3_UnitGroup_View oUnitGroup = new DAL.ClsK3_UnitGroup_View(); DAL.ClsK3_Unit_View oUnit = new DAL.ClsK3_Unit_View(); if (!grdStatus) { return; } //if (oSumGrid.FindAllowEditCol(sCol)) //{ oSumGrid.EditStatus = true; //} //else //{ // return; //} switch (sKeyCode) { case 118: { switch (sCol) { case HParentNumberCol: //BLL.ClsBaseSelect_K3.SetGridByMaterGroup_K3(grdMain, sRow, HParentIDCol, HParentNumberCol,HParentNumberCol); ////修改长代码 //grdMain.Rows[sRow].Cells[HLongNumberCol].Value = ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HParentNumberCol].Value) + "." + ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HChartNumberCol].Value); //oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HParentNumberCol].Value); break; case HUnitNameCol: if (oUnit.RefreshView(DBUtility.ClsPub.isLong(grdMain.Rows[sRow].Cells[HUnitGroupIDCol].Value))) { if (oUnit.GetInfoByID(oUnit.oModel.HItemID)) { grdMain.Rows[sRow].Cells[HUnitIDCol].Value = oUnit.omodel.HItemID.ToString(); grdMain.Rows[sRow].Cells[HUnitNameCol].Value = oUnit.omodel.HName; } else { grdMain.Rows[sRow].Cells[HUnitIDCol].Value = "0"; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = ""; } } else { grdMain.Rows[sRow].Cells[HUnitIDCol].Value = "0"; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = ""; } oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HUnitNameCol].Value); break; case HUnitGroupNameCol: if (oUnitGroup.RefreshView()) { if (oUnitGroup.GetInfoByID(oUnitGroup.oModel.HItemID)) { grdMain.Rows[sRow].Cells[HUnitGroupIDCol].Value = oUnitGroup.omodel.HItemID.ToString(); grdMain.Rows[sRow].Cells[HUnitGroupNumberCol].Value = oUnitGroup.omodel.HNumber; grdMain.Rows[sRow].Cells[HUnitGroupNameCol].Value = oUnitGroup.omodel.HName; grdMain.Rows[sRow].Cells[HUnitIDCol].Value = oUnitGroup.omodel.HUnitID.ToString(); grdMain.Rows[sRow].Cells[HUnitNameCol].Value = oUnitGroup.omodel.HUnitName; } else { grdMain.Rows[sRow].Cells[HUnitGroupIDCol].Value = "0"; grdMain.Rows[sRow].Cells[HUnitGroupNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HUnitGroupNameCol].Value = ""; grdMain.Rows[sRow].Cells[HUnitIDCol].Value = "0"; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = ""; } } else { grdMain.Rows[sRow].Cells[HUnitGroupIDCol].Value = "0"; grdMain.Rows[sRow].Cells[HUnitGroupNumberCol].Value = ""; grdMain.Rows[sRow].Cells[HUnitGroupNameCol].Value = ""; grdMain.Rows[sRow].Cells[HUnitIDCol].Value = "0"; grdMain.Rows[sRow].Cells[HUnitNameCol].Value = ""; } oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HUnitGroupNameCol].Value); break; case HErpClsNameCol: BLL.ClsBaseSelect_K3.SetGridByErpCls_K3(grdMain, sRow, HErpClsIDCol, HErpClsNameCol); oEdit.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[sRow].Cells[HErpClsNameCol].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 } }