/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PC_0102.cs * 2.功能描述:新建成型线信息 * 编辑履历: * 作者 日期 版本 修改内容 * 庄天威 2014/09/13 1.00 新建 *******************************************************************************/ using System; using System.Collections.Generic; using System.Data; 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.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.PCModuleService; namespace Dongke.IBOSS.PRD.Client.PCModule { public partial class F_PC_0102 : FormBase { #region 成员变量 //需要添加的成型线明细集合 public List _addDetailList = new List(); //模具总数量 private int _mouldCount = 0; //是否已经提示过删除模具的信息 private bool _isMessageShow = false; #endregion #region 构造函数 public F_PC_0102() { 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; } #endregion #region 事件 /// /// 添加成型线明细 /// 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 (this.txtCount.Text == string.Empty) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具数量"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.dkGoods.GoodsID == null) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具产品"), 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) { MessageBox.Show("生成模具信息后,修改成型线编码将导致清空模具信息。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this._isMessageShow = true; } for (int i = 0; i < Convert.ToInt32(this.txtCount.Text); i++) { int GroutingMouldCodeNum = i + _mouldCount; GroutingLineDetailEntity detailInfo = new GroutingLineDetailEntity(); detailInfo.GROUTINGMOULDCODE = this.txtGroutingLineCode.Text + "-" + (GroutingMouldCodeNum + 1).ToString().PadLeft(3, '0'); 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 = "-"; this._addDetailList.Add(detailInfo); } this._mouldCount += Convert.ToInt32(this.txtCount.Text); this.dgvDetail.AutoGenerateColumns = false; this.dgvDetail.DataSource = ListToTable(); } 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 { DataGridViewRow currentRow = this.dgvDetail.CurrentRow; if (currentRow == null || currentRow.Index < Constant.INT_IS_ZERO) { return; } this._addDetailList.RemoveAt(currentRow.Index); this.dgvDetail.DataSource = ListToTable(); } 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.dkType.Focus(); errorAddress = "成型线类别"; break; default: break; }; MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); return; } if (this._addDetailList.Count == Constant.INT_IS_ZERO) { MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具信息"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } 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; ginfo.MOULDTYPEID = this.dkType.MouldTypeID; ginfo.MouldStatus = Convert.ToInt32(Constant.GMouldStatus.Normal); ginfo.VALUEFLAG = Convert.ToInt32(Constant.ValueFlag.Effective); ginfo.MOULDQUANTITY = this._addDetailList.Count; int myReturn = (int)DoAsync(new BaseAsyncMethod(() => { return PCModuleProxy.Service.AddGroutingLine(ginfo, this._addDetailList); })); if (myReturn > Constant.INT_IS_ZERO) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "成型线信息", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else if (myReturn == -50) { MessageBox.Show("成型线编码已存在,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } 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; } } #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")); 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); } 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 (dkType.MouldTypeID == null) { ErrorId = 8; return ErrorId; } return ErrorId; } #endregion } }