/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PC_0102_1_1.cs * 2.功能描述:新建成型线信息 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2015/09/25 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.Client.DataModels; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.PCModule { public partial class F_PC_0102_1_1 : FormBase { #region 成员变量 //需要添加的成型线明细集合 public List _addDetailList = new List(); //需要添加的成型工号明细集合 public List _addDetailUserList = new List(); //模具总数量 private int _mouldCount = 0; //是否已经提示过删除模具的信息 private bool _isMessageShow = false; // private string _userCodeValue; private bool _ShowFlag = true; #endregion #region 构造函数 public F_PC_0102_1_1() { InitializeComponent(); this.Text = FormTitles.F_PC_0102; this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; this.btnAddMould.Text = ButtonText.BTN_ADDMOULD; this.btnDeleteSelected.Text = ButtonText.BTN_DELETESELECTED; //this.dkUser.IsWorker = true; this.dgvUser.AutoGenerateColumns = false; this.dgvDetail.AutoGenerateColumns = false; DataTable dtUser = new DataTable(); dtUser.Columns.Add("UserID"); dtUser.Columns.Add("UserCode"); dtUser.Columns.Add("UserName"); dtUser.Columns.Add("StaffNames"); dtUser.Columns.Add("Remark"); dtUser.Columns["UserID"].Unique = true; this.dgvUser.DataSource = dtUser; this.scbUser1.DisplayMember = "USERNAMECode"; this.scbUser1.ValueMember = "UserID"; } #endregion #region 事件 /// /// 自适应列宽 /// /// /// private void btnAdaptive_Click(object sender, EventArgs e) { this.dgvUser.AutoResizeColumns(); this.dgvDetail.AutoResizeColumns(); } /// /// 添加成型线明细 /// private void btnAddMould_Click(object sender, EventArgs e) { try { if (this.txtGroutingLineCode.Text == string.Empty) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "成型线编码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(this.txtBeginNum.Text)) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "起始模具号"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.txtCount.Text == string.Empty) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具数量"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.scbGoods.SearchedPKMember == 0) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具产品"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (Convert.ToInt32(txtBeginNum.Text) + Convert.ToInt32(txtCount.Text) > 999) { MessageBox.Show("成型线模具数量不可超过999个!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //if (this._mouldCount == 999) //{ // MessageBox.Show("成型线模具数量不可超过999个!", this.Text, // MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} if (this._isMessageShow == false) { DialogResult msgBoxResult = MessageBox.Show("添加模具后,成型线编码相关信息不予许修改,是否继续。", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (msgBoxResult == DialogResult.No) { return; } else { this.txtBuildingNo.ReadOnly = true; this.txtFloorNo.ReadOnly = true; this.txtGroutingLineNo.ReadOnly = true; } this._isMessageShow = true; } //for (int i = 0; i < _addDetailList.Count; i++) //{ // DataRow drRow = dtDataSourse.NewRow(); // drRow["GROUTINGMOULDCODE"] = _addDetailList[i].GROUTINGMOULDCODE; // drRow["GOODSNAME"] = _addDetailList[i].GOODSNAME; // drRow["GoodsCode"] = _addDetailList[i].GOODSCODE; // drRow["GoodsSpecification"] = _addDetailList[i].GoodsSpecification; // drRow["GOODSID"] = _addDetailList[i].GOODSID; // dtDataSourse.Rows.Add(drRow); //} bool isError = false; DataTable dtDetail = this.dgvDetail.DataSource as DataTable; int BeginNum = Convert.ToInt32(this.txtBeginNum.Text); for (int i = 0; i < Convert.ToInt32(this.txtCount.Text); i++) { ////// int GroutingMouldCodeNum = BeginNum + _mouldCount; //// int GroutingMouldCodeNum = BeginNum ; //// GroutingLineDetailEntity detailInfo = new GroutingLineDetailEntity(); //// detailInfo.GROUTINGMOULDCODE = this.txtGroutingLineCode.Text + "-" + (GroutingMouldCodeNum).ToString().PadLeft(3, '0'); //// if (dtDetail != null) //// { //// DataRow[] dr = dtDetail.Select("GROUTINGMOULDCODE='" + detailInfo.GROUTINGMOULDCODE + "'"); //// if (dr.Length > 0) //// { //// isError = true; //// break; //// } //// } //// detailInfo.MOULDCODE = Guid.NewGuid().ToString(); //// detailInfo.GOODSID = Convert.ToInt32(this.dkGoods.GoodsID); //// detailInfo.GOODSNAME = this.dkGoods.GoodsName; //// detailInfo.GOODSCODE = this.dkGoods.GoodsCode; //// detailInfo.GoodsSpecification = this.dkGoods.GoodsSpecification; //// detailInfo.GROUTINGCOUNT = Constant.INT_IS_ZERO; //// detailInfo.MOULDSTATUS = Convert.ToInt32(Constant.GMouldStatus.Normal); //// detailInfo.REMARKS = ""; //// detailInfo.VALUEFLAG = 1; //// this._addDetailList.Add(detailInfo); //// BeginNum = BeginNum + 1; int GroutingMouldCodeNum = BeginNum; //GroutingLineDetailEntity detailInfo = new GroutingLineDetailEntity(); string MOULDCODE = this.txtGroutingLineCode.Text + "-" + (GroutingMouldCodeNum).ToString().PadLeft(3, '0'); DataTable dtInfo = this.dgvDetail.DataSource as DataTable; DataRow[] dr = dtInfo.Select("GroutingMouldCode='" + MOULDCODE + "'"); if (dr.Length > 0) { isError = true; break; }; //if (dtDetail != null) //{ // DataRow[] dr = dtDetail.Select("GROUTINGMOULDCODE='" + detailInfo.GROUTINGMOULDCODE + "'"); // if (dr.Length > 0) // { // isError = true; // break; // } //} DataRow r = dtInfo.NewRow(); r["GroutingMouldCode"] = MOULDCODE; r["MouldSource"] = "0"; r["MOULDCODE"] = Guid.NewGuid().ToString(); r["GOODSID"] = scbGoods.SearchedPKMember; r["GOODSNAME"] = scbGoods.SearchedItem["GOODSNAME"]; r["GOODSCODE"] = scbGoods.SearchedItem["GOODSCODE"]; r["GoodsSpecification"] = scbGoods.SearchedItem["GOODSSPECIFICATION"]; r["GROUTINGCOUNT"] = Convert.ToInt32(this.txtGroutingCount.DataValue ?? 0); r["StandardGroutingCount"] = Convert.ToInt32(this.txtStandardGroutingCount.DataValue.Value); r["MOULDSTATUS"] = Convert.ToInt32(Constant.GMouldStatus.Normal); //r["REMARKS"] = ""; r["VALUEFLAG"] = "1"; dtInfo.Rows.Add(r); //this._addDetailList.Add(detailInfo); BeginNum = BeginNum + 1; } if (isError) { BeginNum = Convert.ToInt32(this.txtBeginNum.Text); //有错误 MessageBox.Show("存在相同的模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { this.txtBeginNum.DataValue = BeginNum; } this._mouldCount += Convert.ToInt32(this.txtCount.Text); //this.dgvDetail.AutoGenerateColumns = false; //this.dgvDetail.DataSource = ListToTable(); //this.dgvDetail.IsSetInputColumnsColor = true; //this.tabControl1.SelectTab(1); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 关闭窗体 /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } /// /// 删除明细 /// private void btnDeleteSelected_Click(object sender, EventArgs e) { try { DataRowView drv = this.dgvDetail.CurrentRow.DataBoundItem as DataRowView; if (drv == null) { return; } // 一模多产时,同一模具一同清除。 add by chenxy 2018-10-29 if (drv["MouldID"] != DBNull.Value) { DataTable dt = this.dgvDetail.DataSource as DataTable; DataRow[] drs = dt.Select("MouldID = " + drv["MouldID"]); if (drs.Length > 1) { foreach (DataRow item in drs) { item.Delete(); } } else { drv.Delete(); } } else { drv.Delete(); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 提交新建 /// private void btnSave_Click(object sender, EventArgs e) { try { int ErrorId = ValidationText(); if (ErrorId != Constant.INT_IS_ZERO) { string errorAddress = ""; switch (ErrorId) { case 1: this.txtBuildingNo.Focus(); errorAddress = "楼号"; break; case 2: this.txtFloorNo.Focus(); errorAddress = "楼层"; break; case 3: this.txtGroutingLineNo.Focus(); errorAddress = "线号"; break; case 4: this.txtGroutingLineCode.Focus(); errorAddress = "成型线编码"; break; case 5: this.txtGroutingLineName.Focus(); errorAddress = "成型线名称"; break; //case 7: // this.dkUser.Focus(); // errorAddress = "工号"; // break; case 8: this.scbGMouldType.Focus(); errorAddress = "成型线类别"; break; default: break; }; MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (LogInUserInfo.CurrentUser.CurrentUserEntity.AccountCode == "imex" && this.scbUser1.SearchedValue == null) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "成型班长"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } DataTable dtInfo = this.dgvDetail.DataSource as DataTable; if (dtInfo.Rows.Count == Constant.INT_IS_ZERO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具信息"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DataTable dtUser = this.dgvUser.DataSource as DataTable; dtUser.TableName = "dtUser"; dtUser.AcceptChanges(); if (dtUser.Rows.Count == Constant.INT_IS_ZERO) { /* 成型线可以不绑定成型工号 chenxy 2019-10-08 MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "成型工号"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.tabControl1.SelectTab(0); return; */ } else { DataRow[] dr = dtUser.Select("UserName='' or UserName is null"); if (dr.Length > 0) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "成型工号"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.tabControl1.SelectTab(0); return; } } //更新注浆次数 DataTable dtDetail = this.dgvDetail.DataSource as DataTable; dtDetail.TableName = "dtDetail"; GroutingLineEntity ginfo = new GroutingLineEntity(); ginfo.BUILDINGNO = this.txtBuildingNo.Text.Trim(); ginfo.FLOORNO = this.txtFloorNo.Text.Trim(); ginfo.GROUTINGLINENO = this.txtGroutingLineNo.Text.Trim(); ginfo.GROUTINGLINECODE = this.txtGroutingLineCode.Text.Trim(); ginfo.GROUTINGLINENAME = this.txtGroutingLineName.Text.Trim(); ginfo.REMARKS = this.txtRemarks.Text.Trim(); //ginfo.USERID = this.dkUser.UserID; if (dtUser.Rows.Count > 0) { ginfo.USERID = Convert.ToInt32(dtUser.Rows[0]["UserID"]); } else { ginfo.USERID = null; } //xuwei add 2019-11-13 高压注浆 ginfo.HIGHPRESSUREFLAG = HighPressureFlag.Checked ? 1 : 0; //xuwei end ginfo.MOULDTYPEID = this.scbGMouldType.SearchedPKMember; ginfo.MouldStatus = Convert.ToInt32(Constant.GMouldStatus.Normal); ginfo.VALUEFLAG = Convert.ToInt32(Constant.ValueFlag.Effective); ginfo.MOULDQUANTITY = dtDetail.Rows.Count;//this._addDetailList.Count; if (this.scbUser1.SearchedValue != null) { ginfo.MonitorID = Convert.ToInt32(this.scbUser1.SearchedValue); ginfo.MonitorCode = this.scbUser1.SearchedItem["Usercode"]+""; } this._addDetailUserList.Clear(); //for (int i = 0; i < dtDetail.Rows.Count; i++) //{ // _addDetailList[i].GROUTINGCOUNT = Convert.ToDecimal(dtDetail.Rows[i]["GROUTINGCOUNT"]); //} //foreach (DataRow r in dtUser.Rows) //{ // GroutingLineUserEntity entity = new GroutingLineUserEntity(); // entity.USERID = Convert.ToInt32(r["USERID"]); // entity.REMARK = r["REMARK"].ToString(); // this._addDetailUserList.Add(entity); //} //DataTable dt = this.dgvDetail.DataSource as DataTable; //if (dt != null) //{ // for (int i = 0; i < dt.Rows.Count; i++) // { // this._addDetailList[i].REMARKS = dt.Rows[i]["Remarks"].ToString(); // } //} ServiceResultEntity myReturn = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() => { //return PCModuleProxy.Service.AddGroutingLine_New(ginfo, this._addDetailList, this._addDetailUserList); return PCModuleProxy.Service.AddGroutingLine_NewLine(ginfo, dtDetail, dtUser); })); if (myReturn != null) { if (myReturn.Status == Constant.ServiceResultStatus.Success) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "成型线信息", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else if (myReturn.OtherStatus == -50) { MessageBox.Show("成型线编码已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (myReturn.OtherStatus == -2) { MessageBox.Show(Messages.MSG_CMN_W029, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "成型线信息", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 编号变更 /// private void txtBuildingNo_TextChanged(object sender, EventArgs e) { this.txtGroutingLineCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + this.txtGroutingLineNo.Text.Trim(); this.txtGroutingLineName.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + this.txtGroutingLineNo.Text.Trim(); } /// /// 编号变更 /// private void txtFloorNo_TextChanged(object sender, EventArgs e) { this.txtGroutingLineCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + this.txtGroutingLineNo.Text.Trim(); this.txtGroutingLineName.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + this.txtGroutingLineNo.Text.Trim(); } /// /// 编号变更 /// private void txtGroutingLineNo_TextChanged(object sender, EventArgs e) { this.txtGroutingLineCode.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + this.txtGroutingLineNo.Text.Trim(); this.txtGroutingLineName.Text = this.txtBuildingNo.Text + this.txtFloorNo.Text.PadLeft(2, '0') + this.txtGroutingLineNo.Text.Trim(); } /// /// 成型线文本改变事件 /// /// /// private void txtGroutingLineCode_TextChanged(object sender, EventArgs e) { if (this._addDetailList.Count != Constant.INT_IS_ZERO) { MessageBox.Show("成型线编码变更后,需重新生成模具信息!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this._addDetailList.Clear(); this._mouldCount = 0; this.dgvDetail.DataSource = null; } } /// /// 成型工号开始编辑事件 /// /// /// private void dgvUser_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { try { if (this.dgvUser.Rows.Count <= 1) { return; } DataGridViewColumn columnItem = this.dgvUser.Columns[e.ColumnIndex]; if ("UserCode".Equals(columnItem.Name)) { _userCodeValue = this.dgvUser.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 工号单元格值改变事件 /// /// /// private void dgvUser_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (this.dgvUser.Rows.Count <= 1 || !_ShowFlag) { return; } DataGridViewRow rowItem = this.dgvUser.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvUser.Columns[e.ColumnIndex]; // 用编号获取产品信息 if ("UserCode".Equals(columnItem.Name)) { _ShowFlag = false; FormUtility.BindUserRowDataSource(this.dgvUser, e.RowIndex, columnItem.Name, _userCodeValue); // 设置可输入单元格的颜色 this.dgvUser.IsSetInputColumnsColor = true; } _ShowFlag = true; } catch (Exception ex) { //_ShowFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体加载事件 /// /// /// private void F_PC_0102_1_1_Load(object sender, EventArgs e) { // dgvDetail.IsSetInputColumnsColor = true; //dgvUser.IsSetInputColumnsColor = true; //窗体加载模具数据源 this.dgvDetail.AutoGenerateColumns = false; DataTable dtGroutingInfo = new DataTable(); dtGroutingInfo.Columns.Add("MouldSource"); dtGroutingInfo.Columns.Add("MOULDID", typeof(int)); dtGroutingInfo.Columns.Add("MOULDBarcode"); dtGroutingInfo.Columns.Add("MOULDCODE"); dtGroutingInfo.Columns.Add("GOODSID", typeof(int)); dtGroutingInfo.Columns.Add("GOODSNAME"); dtGroutingInfo.Columns.Add("GOODSCODE"); dtGroutingInfo.Columns.Add("GoodsSpecification"); dtGroutingInfo.Columns.Add("GROUTINGCOUNT", typeof(int)); dtGroutingInfo.Columns.Add("StandardGroutingCount", typeof(int)); dtGroutingInfo.Columns.Add("MOULDSTATUS", typeof(int)); dtGroutingInfo.Columns.Add("REMARKS"); dtGroutingInfo.Columns.Add("VALUEFLAG"); dtGroutingInfo.Columns.Add("GroutingMouldCode"); dtGroutingInfo.Columns.Add("MouldOutputNo", typeof(int)); dtGroutingInfo.DefaultView.Sort = "GroutingMouldCode"; dtGroutingInfo.Columns["GroutingMouldCode"].Unique = true; this.dgvDetail.DataSource = dtGroutingInfo; DataSet dsSetting = SystemModuleProxy.Service.GetSystemSettingDataByCode(Constant.SettingType.S_PC_001.ToString()); if (dsSetting != null && dsSetting.Tables[0].Rows.Count > 0) { string flag = dsSetting.Tables[0].Rows[0]["SettingValue"].ToString(); if (flag == "2") { this.rabBinding.Checked = true; this.rabAuto.Enabled = false; } else if (flag == "1") { this.rabBinding.Checked = true; } else { this.rabAuto.Checked = true; } } } /// /// 窗体加载后显示事件 /// /// /// private void F_PC_0102_1_1_Shown(object sender, EventArgs e) { //dgvDetail.IsSetInputColumnsColor = true; dgvUser.IsSetInputColumnsColor = true; } /// /// 工号排序事件 /// /// /// private void dgvUser_Sorted(object sender, EventArgs e) { this.dgvUser.IsSetInputColumnsColor = true; } /// /// 窗口切换事件 /// /// /// private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { //dgvDetail.IsSetInputColumnsColor = true; this.dgvUser.IsSetInputColumnsColor = true; } /// /// 行绘制前,控制Cell只读 /// /// /// private void dgvDetail_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (this.dgvDetail.ReadOnly || e.RowIndex < 0) { return; } try { if (string.IsNullOrEmpty(dgvDetail.Rows[e.RowIndex].Cells["MouldID"].Value + "")) { // 自动生成模具 this.dgvDetail.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = false; this.dgvDetail.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = false; //this.dgvDetail.Rows[e.RowIndex].Cells["GroutingCount"].Style.BackColor // = ColorTranslator.FromHtml(ControlsConst.ALLOW_MODIFY_AREA_BACKGROUND_COLOR); //this.dgvDetail.Rows[e.RowIndex].Cells["StandardGroutingCount"].Style.BackColor // = ColorTranslator.FromHtml(ControlsConst.ALLOW_MODIFY_AREA_BACKGROUND_COLOR); } else { // 模具档案 this.dgvDetail.Rows[e.RowIndex].Cells["GroutingCount"].ReadOnly = true; this.dgvDetail.Rows[e.RowIndex].Cells["StandardGroutingCount"].ReadOnly = true; //this.dgvDetail.Rows[e.RowIndex].Cells["GroutingCount"].Style.BackColor // = Color.White; //this.dgvDetail.Rows[e.RowIndex].Cells["StandardGroutingCount"].Style.BackColor //= Color.White; } foreach (DataGridViewColumn item in dgvDetail.Columns) { if (!item.Visible) { continue; } if (item.ReadOnly || this.dgvDetail.Rows[e.RowIndex].Cells[item.Index].ReadOnly) { this.dgvDetail.Rows[e.RowIndex].Cells[item.Index].Style.BackColor = Color.White; } else { this.dgvDetail.Rows[e.RowIndex].Cells[item.Index].Style.BackColor = ColorTranslator.FromHtml(ControlsConst.ALLOW_MODIFY_AREA_BACKGROUND_COLOR); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 编辑前,控制Cell只读 /// /// /// private void dgvDetail_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { try { } catch (Exception ex) { //_ShowFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 切换模具来源 /// /// /// private void rabAuto_CheckedChanged(object sender, EventArgs e) { this.pnlAuto.Enabled = this.rabAuto.Checked; this.pnlBinding.Enabled = this.rabBinding.Checked; } /// /// 验证模具号 /// /// /// private void txtGMouldCode_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (this.txtGMouldCode.Text == "" || this.dgvDetail.Rows.Count == 0) { return; } try { string gMouldCode = this.txtGroutingLineCode.Text + "-" + this.txtGMouldCode.DataValue.Value.ToString().PadLeft(3, '0'); DataTable dtInfo = this.dgvDetail.DataSource as DataTable; DataRow[] dr = dtInfo.Select("GroutingMouldCode='" + gMouldCode + "'"); if (dr.Length > 0) { MessageBox.Show("存在相同的模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); e.Cancel = true; return; }; } catch (Exception ex) { //_ShowFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 验证模具条码 /// /// /// private void txtBarcode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.btnAddMouldBarcode_Click(null, null); } } /// /// 添加模具 /// /// /// private void btnAddMouldBarcode_Click(object sender, EventArgs e) { if (this.txtGroutingLineCode.Text == string.Empty) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "成型线编码"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.txtGMouldCode.Text == "") { MessageBox.Show("没有设定模具号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtGMouldCode.Focus(); return; } string barcode = this.txtBarcode.Text.Trim(); if (barcode == "") { MessageBox.Show("没有输入模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtBarcode.Focus(); return; } try { string gMouldCode = this.txtGroutingLineCode.Text + "-" + this.txtGMouldCode.DataValue.Value.ToString().PadLeft(3, '0'); DataTable dtInfo = this.dgvDetail.DataSource as DataTable; DataRow[] dr = dtInfo.Select("GroutingMouldCode='" + gMouldCode + "'"); if (dr.Length > 0) { MessageBox.Show("存在相同的模具编号", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtGMouldCode.Focus(); this.txtGMouldCode.SelectAll(); return; }; dr = dtInfo.Select("MouldBarcode = '" + barcode + "'"); if (dr.Length > 0) { MessageBox.Show("存在相同的模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtBarcode.Focus(); this.txtBarcode.SelectAll(); return; }; if (this._isMessageShow == false) { DialogResult msgBoxResult = MessageBox.Show("添加模具后,成型线编码相关信息不予许修改,是否继续。", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (msgBoxResult == DialogResult.No) { return; } else { this.txtBuildingNo.ReadOnly = true; this.txtFloorNo.ReadOnly = true; this.txtGroutingLineNo.ReadOnly = true; } this._isMessageShow = true; } // 验证模具条码状态 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "PC_Mould"; cre.Name = "GetMouldData"; cre.Properties["MouldBarcode"] = barcode; ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre); if (sre == null || sre.Data == null || sre.Data.Tables.Count == 0 || sre.Data.Tables[0].Rows.Count == 0) { MessageBox.Show("无效模具条码", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtBarcode.Focus(); this.txtBarcode.SelectAll(); return; } DataRow item = sre.Data.Tables["InfoData"].Rows[0]; int mouldStatus = Convert.ToInt32(item["MouldStatus"]); if (mouldStatus != 1 && mouldStatus != 3) { MessageBox.Show("此模具当前状态为【" + item["MouldStatusName"] + "】,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtBarcode.Focus(); this.txtBarcode.SelectAll(); return; } int outputCount = Convert.ToInt32(item["OutputCount"]); if (outputCount == 1) { DataRow r = dtInfo.NewRow(); r["GroutingMouldCode"] = gMouldCode; r["MouldSource"] = "1"; r["MOULDID"] = item["MOULDID"]; r["MOULDCODE"] = item["MOULDCODE"]; r["MOULDBarcode"] = item["MOULDBarcode"]; r["GOODSID"] = item["GOODSID"]; r["GOODSNAME"] = item["GOODSNAME"]; r["GOODSCODE"] = item["GOODSCODE"]; r["GoodsSpecification"] = item["GoodsSpecification"]; r["GROUTINGCOUNT"] = item["GroutingNums"]; r["StandardGroutingCount"] = item["StandardGroutingNum"]; r["MOULDSTATUS"] = Convert.ToInt32(Constant.GMouldStatus.Normal); //r["REMARKS"] = ""; r["VALUEFLAG"] = "1"; dtInfo.Rows.Add(r); } else { // 一模多产时,必须绑定连续成型模具编号。 add by chenxy 2018-10-29 string minGMouldCode = gMouldCode; int minIndex = Convert.ToInt32(this.txtGMouldCode.DataValue.Value); string maxGMouldCode = this.txtGroutingLineCode.Text + "-" + (minIndex + outputCount).ToString("000"); DataRow[] grows = dtInfo.Select("GroutingMouldCode>='" + minGMouldCode + "' and GroutingMouldCode<'" + maxGMouldCode + "'"); if (grows.Length > 0) { MessageBox.Show("此模具的产出数量为【" + outputCount + "】,当前成型模具编号不能连续添加,不能添加到成型线。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtBarcode.Focus(); this.txtBarcode.SelectAll(); return; } //for (int i = 0; i < outputCount; i++) foreach (DataRow itemOutput in sre.Data.Tables["InfoData"].Rows) { DataRow r = dtInfo.NewRow(); r["GroutingMouldCode"] = minGMouldCode; r["MouldSource"] = "1"; r["MOULDID"] = item["MOULDID"]; r["MOULDCODE"] = item["MOULDCODE"]; r["MOULDBarcode"] = item["MOULDBarcode"]; r["GOODSID"] = item["GOODSID"]; r["GOODSNAME"] = item["GOODSNAME"]; r["GOODSCODE"] = item["GOODSCODE"]; r["GoodsSpecification"] = item["GoodsSpecification"]; r["GROUTINGCOUNT"] = itemOutput["GroutingNum"]; r["MouldOutputNo"] = itemOutput["OutputNo"]; r["StandardGroutingCount"] = item["StandardGroutingNum"]; r["MOULDSTATUS"] = Convert.ToInt32(Constant.GMouldStatus.Normal); //r["REMARKS"] = ""; r["VALUEFLAG"] = "1"; dtInfo.Rows.Add(r); minGMouldCode = this.txtGroutingLineCode.Text + "-" + (++minIndex).ToString("000"); } } //foreach (DataGridViewRow row in dgvDetail.Rows) //{ // if (string.IsNullOrEmpty(row.Cells["MouldID"].Value + "")) // { // // 自动生成模具 // row.Cells["GroutingCount"].ReadOnly = false; // row.Cells["StandardGroutingCount"].ReadOnly = false; // } // else // { // // 模具档案 // row.Cells["GroutingCount"].ReadOnly = true; // row.Cells["StandardGroutingCount"].ReadOnly = true; // } //} //this.dgvDetail.IsSetInputColumnsColor = true; //this.txtGMouldCode.DataValue = this.txtGMouldCode.DataValue.Value + 1; this.txtGMouldCode.DataValue = this.txtGMouldCode.DataValue.Value + outputCount; this.txtBarcode.Clear(); this.txtBarcode.Focus(); } catch (Exception ex) { //_ShowFlag = true; // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } #endregion #region 私有方法 /// /// 将实体数据转换为DataTable,绑定到控件中 /// protected DataTable ListToTable() { try { DataTable dtDataSourse = new DataTable(); dtDataSourse.Columns.Add("GROUTINGMOULDCODE", System.Type.GetType("System.String")); dtDataSourse.Columns.Add("GOODSNAME", System.Type.GetType("System.String")); dtDataSourse.Columns.Add("GoodsCode", System.Type.GetType("System.String")); dtDataSourse.Columns.Add("GoodsSpecification", System.Type.GetType("System.String")); dtDataSourse.Columns.Add("GOODSID", System.Type.GetType("System.String")); dtDataSourse.Columns.Add("Remarks", System.Type.GetType("System.String")); dtDataSourse.Columns.Add("GROUTINGCOUNT", System.Type.GetType("System.String")); for (int i = 0; i < _addDetailList.Count; i++) { DataRow drRow = dtDataSourse.NewRow(); drRow["GROUTINGMOULDCODE"] = _addDetailList[i].GROUTINGMOULDCODE; drRow["GOODSNAME"] = _addDetailList[i].GOODSNAME; drRow["GoodsCode"] = _addDetailList[i].GOODSCODE; drRow["GoodsSpecification"] = _addDetailList[i].GoodsSpecification; drRow["GOODSID"] = _addDetailList[i].GOODSID; drRow["Remarks"] = _addDetailList[i].REMARKS; drRow["GROUTINGCOUNT"] = _addDetailList[i].GROUTINGCOUNT; dtDataSourse.Rows.Add(drRow); } return dtDataSourse; } catch (Exception ex) { throw ex; } } /// /// 验证添加项 /// protected int ValidationText() { int ErrorId = 0; string txtBuildingNo = this.txtBuildingNo.Text.Trim(); string txtFloorNo = this.txtFloorNo.Text.Trim(); string txtGroutingLineNo = this.txtGroutingLineNo.Text.Trim(); string txtGroutingLineCode = this.txtGroutingLineCode.Text.Trim(); string txtGroutingLineName = this.txtGroutingLineName.Text.Trim(); string txtRemarks = this.txtRemarks.Text.Trim(); if (txtBuildingNo == string.Empty) { ErrorId = 1; return ErrorId; } if (txtFloorNo == string.Empty) { ErrorId = 2; return ErrorId; } if (txtGroutingLineNo == string.Empty) { ErrorId = 3; return ErrorId; } if (txtGroutingLineCode == string.Empty) { ErrorId = 4; return ErrorId; } if (txtGroutingLineName == string.Empty) { ErrorId = 5; return ErrorId; } //if (dkUser.UserID == null) //{ // ErrorId = 7; // return ErrorId; //} if (scbGMouldType.SearchedPKMember == 0) { ErrorId = 8; return ErrorId; } return ErrorId; } #endregion } }