/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PC_0101_1_6.cs * 2.功能描述:操作时间及备注录入 * 编辑履历: * 作者 日期 版本 修改内容 * 王鑫 2015/09/25 1.00 新建 *******************************************************************************/ using System; using System.Windows.Forms; using System.Data; using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.Client.CommonModule; namespace Dongke.IBOSS.PRD.Client.PCModule { public partial class F_PC_0101_1_6 : FormBase { #region 成员变量 // 窗体标题 private string _titleStr = ""; // 实例窗体 //private F_PC_0101 _fpc0101; private DataTable _dtBindSource = null; //默认模具编号 private string _defaultNo = ""; //成型线ID private int _groutingLineID = 0; private DataTable _orgdtBindSource = null; private int _lastGMouldRecordID = 0; #endregion #region 构造函数 //public F_PC_0101_1_6(F_PC_0101 fpc0101, string titleStr) //{ // InitializeComponent(); // this._titleStr = titleStr; // this._fpc0101 = fpc0101; // this._fpc0101.SetTimeOrRemarks(null, ""); // this.Text = _titleStr; // this.btnSave.Text = ButtonText.BTN_SAVE; //} public F_PC_0101_1_6(DataTable dtBindSource, string titleStr) { InitializeComponent(); _dtBindSource = dtBindSource; _orgdtBindSource = dtBindSource.Copy(); if (!this._dtBindSource.Columns.Contains("NewFlag")) { DataColumn colNew = new DataColumn(); colNew.ColumnName = "NewFlag"; colNew.DefaultValue = 0; _dtBindSource.Columns.Add(colNew); } if (!this._orgdtBindSource.Columns.Contains("NewFlag")) { DataColumn colNew2 = new DataColumn(); colNew2.ColumnName = "NewFlag"; colNew2.DefaultValue = 0; _orgdtBindSource.Columns.Add(colNew2); } if (dtBindSource != null && dtBindSource.Rows.Count > 0) { string[] subSplit = dtBindSource.Rows[0]["GroutingMouldCode"].ToString().Split('-'); for (int i = 0; i < subSplit.Length; i++) { if (i != subSplit.Length - 1) { _defaultNo += subSplit[i] + "-"; } } //_defaultNo = dtBindSource.Rows[0]["GroutingMouldCode"].ToString().Split('-')[0] + "-"; } this.Text = titleStr; this.btnSave.Text = ButtonText.BTN_SAVE; this.btnCancel.Text = ButtonText.BTN_CLOSE; _groutingLineID = Convert.ToInt32(dtBindSource.Rows[0]["groutingLineID"].ToString()); _lastGMouldRecordID = Convert.ToInt32(dtBindSource.Rows[0]["lastGMouldRecordID"].ToString()); this.txtGroutingLineCode.Text = dtBindSource.Rows[0]["GroutingLineCode"].ToString(); this.txtRecordRemarks.Text = dtBindSource.Rows[0]["RecordRemarks"].ToString(); } #endregion #region 事件 /// /// 保存按钮事件 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { //if (this.dkGoodsCode.GoodsID == null) //{ // MessageBox.Show("产品编码是必填项"); // return; //} DataTable dtName = this.dgvGroutingLineDetail.DataSource as DataTable; dtName.Copy(); dtName.TableName = "GMouldRecord"; if(dtName.Rows.Count==0) { return; } //this._orgdtBindSource.Merge(dtName); DataTable dtSave = dtName.Copy(); dtSave.Merge(this._orgdtBindSource); if (dtSave.Rows.Count > 0) { dtSave.Rows[0]["RecordRemarks"] = this.txtRecordRemarks.Text.Trim(); } int returnRow = (int)DoAsync(new BaseAsyncMethod(() => { return PCModuleProxy.Service.UpdateAllLineEndGroutingLineDetail(dtSave, Convert.ToInt32(this.dkGoodsCode.GoodsID)); })); if (returnRow > 0) { //停用成功 //MessageBox.Show(this.Text + "成功"); MessageBox.Show(this.Text + "成功", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } else if (returnRow == -500) { //停用成功 // MessageBox.Show("数据已经被修改,请重新编辑"); MessageBox.Show("数据已经被修改,请重新编辑", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.DialogResult = DialogResult.No; } else if (returnRow == -500) { //停用成功 //MessageBox.Show(this.Text + "失败"); MessageBox.Show(this.Text + "失败", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); this.DialogResult = DialogResult.No; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体加载事件 /// /// /// private void F_PC_0101_1_2_Load(object sender, EventArgs e) { this.dgvGroutingLineDetail.AutoGenerateColumns = false; DateTime accountDate = (DateTime)DoAsync(new BaseAsyncMethod(() => { return CommonModuleProxy.Service.GetAccountDate(); })); this.txtDateStart.Value = accountDate; _dtBindSource.Rows.Clear();// this.dgvGroutingLineDetail.DataSource = _dtBindSource; // 设置可输入单元格的颜色 this.dgvGroutingLineDetail.IsSetInputColumnsColor = true; } /// /// 追加模具 /// /// /// private void btnAddMould_Click(object sender, EventArgs e) { try { if (dkGoodsCode.GoodsID == null) { MessageBox.Show("产品编码是必填项", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtBeginNum.Text.Trim() == "") { MessageBox.Show("起始模具号是必填项", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtCount.Text.Trim() == "") { MessageBox.Show("模具数量是必填项", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (txtStandardGroutingCount.Text.Trim() == "") { MessageBox.Show("标准注浆次数", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int startNo = Convert.ToInt32(txtBeginNum.Text); int addCount = Convert.ToInt32(txtCount.Text); string filterNum = ""; bool isError = false; //声明临时表格,遍成每个模具编号是否重复,如果不重复则进行数据添加 for (int i = 0; i < Convert.ToInt32(addCount); i++) { filterNum = string.Format("{0}{1}", this._defaultNo, startNo.ToString().PadLeft(3, '0')); DataRow[] r = _dtBindSource.Select("GroutingMouldCode='" + filterNum + "'"); if (r.Length > 0) { isError = true; break; } startNo = startNo + 1; } if (isError) { MessageBox.Show("存在相同的模具编号" + filterNum); return; } startNo = Convert.ToInt32(txtBeginNum.Text); for (int i = 0; i < Convert.ToInt32(addCount); i++) { filterNum = string.Format("{0}{1}", this._defaultNo, startNo.ToString().PadLeft(3, '0')); DataRow dr = _dtBindSource.NewRow(); dr["GroutingLineID"] = this._groutingLineID; dr["GroutingMouldCode"] = filterNum; dr["GOODSCODE"] = this.dkGoodsCode.Text; dr["GoodsID"] = this.dkGoodsCode.GoodsID; dr["lastGMouldRecordID"] = this._lastGMouldRecordID; dr["StandardGroutingCount"] = txtStandardGroutingCount.DataValue.Value; dr["GroutingCount"] = 0; dr["GMOULDSTATUSNAME"] = "正常"; dr["GMouldStatus"] = 1; dr["NewFlag"] = 1;//1代表新建 _dtBindSource.Rows.Add(dr); startNo = startNo + 1; } _dtBindSource.AcceptChanges(); this.dgvGroutingLineDetail.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 删除模具按钮事件 /// /// /// private void btnDeleteSelected_Click(object sender, EventArgs e) { try { if (this.dgvGroutingLineDetail.CurrentCell != null) { if (this._dtBindSource == null || this._dtBindSource.Rows.Count == Constant.INT_IS_ZERO) { return; } string NewFlag = this.dgvGroutingLineDetail.Rows[this.dgvGroutingLineDetail.CurrentCell.RowIndex].Cells["NewFlag"].Value.ToString(); if (NewFlag == "0") { MessageBox.Show(Messages.MSG_PC_W002, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this._dtBindSource.Rows[this.dgvGroutingLineDetail.CurrentCell.RowIndex].Delete(); this._dtBindSource.AcceptChanges(); this.dgvGroutingLineDetail.IsSetInputColumnsColor = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 排序事件 /// /// /// private void dgvGroutingLineDetail_Sorted(object sender, EventArgs e) { this.dgvGroutingLineDetail.IsSetInputColumnsColor = true; } #endregion } }