/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PM_0102.cs * 2.功能描述:注浆登记 * 编辑履历: * 作者 日期 版本 修改内容 * 陈晓野 2015/03/25 1.00 新建 *******************************************************************************/ using System; using System.Data; using System.Reflection; using System.Text; 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.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; namespace Dongke.IBOSS.PRD.Client.PMModule { /// /// 注浆登记新建和编辑页面 /// public partial class F_PM_0102 : DKFormBase { #region 成员变量 // 窗体模式ID private Constant.FormMode _formMode = Constant.FormMode.Add; // 未注浆原因,传给选择页面 private DataTable _dtNotGroutingRreason; // 注浆日报ID private int _dailyId; // 注浆日期 private DateTime _groutingDate = DateTime.Now.Date; // 账务日期 private DateTime _accountDate = DateTime.Now.Date; //private decimal? _logoid = null; private bool _canEdit = true; #endregion #region 构造函数 /// /// 构造函数 /// public F_PM_0102() :this(0) { } /// /// 构造函数 /// /// 注浆日报ID:新建时为0 public F_PM_0102(int dailyID) { this.InitializeComponent(); this._dailyId = dailyID; this.InitializeControls(); } #endregion #region 属性 /// /// 注浆登记的ID(多个用【,】隔开) /// public string GroutingDailyIDs { get; private set; } #endregion #region 事件 /// /// 窗体加载 /// private void F_PM_0102_Load(object sender, EventArgs e) { try { this.lblGroutingDateValue.Text = string.Empty; DataSet logoInfo = SystemModuleProxy.Service.GetLogoInfo(); if (logoInfo != null && logoInfo.Tables.Count > 0) { this.cmbLogo.DataSource = logoInfo.Tables[0]; this.cmbLogo.DisplayMember = "LogoNameCode"; this.cmbLogo.ValueMember = "LogoID"; this.colLogo.DataSource = logoInfo.Tables[0].Copy(); this.colLogo.DisplayMember = "LogoNameCode"; this.colLogo.ValueMember = "LogoID"; //if(logoInfo.Tables[0].Rows.Count > 0) //{ // _logoid = Convert.ToDecimal(logoInfo.Tables[0].Rows[0]["LogoID"]); //} } // 设置列表未注浆原因选项数据源 this.InitializeData(); } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 全线注浆按钮按下,生成该成型班长的所有注浆信息 /// /// /// private void tsbtnAllGrouting_Click(object sender, EventArgs e) { try { // 获取登录用户所有的注浆信息,并绑定 this.txtGrouting.Clear(); this.dgvDetail.DataSource = null; this.DataSource = null; this.DataSource = this.GetGroutingDailyInfo(null, null); if (this.DataSource != null && this.DataSource.Tables.Count == 2) { StringBuilder groutingLines = new StringBuilder(); foreach (DataRow row in this.DataSource.Tables[0].Rows) { if (groutingLines.Length > 0) { groutingLines.Append(", "); } groutingLines.Append(string.Format("{0}({1})", row["GroutingLineCode"], row["MouldQuantity"])); } this.DataSource.Tables[1].Columns.Add("NoGroutingRreason", typeof(decimal)); this.DataSource.Tables[1].Columns.Add("Remarks", typeof(string)); //DataColumn dc = new DataColumn("LogoID", typeof(decimal)); //if (_logoid.HasValue) //{ // dc.DefaultValue = _logoid.Value; //} //this.DataSource.Tables[1].Columns.Add(dc); this.txtGrouting.Text = groutingLines.ToString(); this.dgvDetail.DataSource = this.DataSource.Tables[1]; this.dgvDetail.IsSetInputColumnsColor = true; // 按钮状态 this.tsbtnAllGrouting.Enabled = false; this.tsbtnGrouting.Enabled = false; this.tsbtnClearDetail.Enabled = true; this.tsbtnChangeGroutingUser.Enabled = true; this.btnSave.Enabled = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 部分注浆按钮按下,弹出选择成型线窗体 /// /// /// private void tsbtnGrouting_Click(object sender, EventArgs e) { try { // 打开选择成型线页面 F_PM_0104_1 frmPM0104 = new F_PM_0104_1(); frmPM0104.NotGroutingRreason = this._dtNotGroutingRreason; DialogResult dialogResult = frmPM0104.ShowDialog(); if (DialogResult.OK == dialogResult && frmPM0104.GroutingInfo.Length > 0) { // 根据选择成型线页面返回成型线,取得注浆明细数据 string groutingLineIDs = string.Empty; foreach (DataRow dataRow in frmPM0104.GroutingInfo) { if (groutingLineIDs.Length > 0) { groutingLineIDs += ","; } groutingLineIDs += dataRow["GroutingLineID"].ToString(); } this.txtGrouting.Clear(); this.dgvDetail.DataSource = null; this.DataSource = null; this.DataSource = this.GetGroutingDailyInfo(frmPM0104.GroutingDate, groutingLineIDs); // 组成页面的注浆日期、注浆成型线显示信息,并且绑定注浆信息的数据源 if (this.DataSource != null && this.DataSource.Tables.Count == 2) { StringBuilder groutingLines = new StringBuilder(); // 根据成型线选择注浆原因,控制注浆列表的未注浆选择列 this.DataSource.Tables[1].Columns.Add("NoGroutingRreason", typeof(decimal)); this.DataSource.Tables[1].Columns.Add("Remarks", typeof(string)); //DataColumn dc = new DataColumn("LogoID", typeof(decimal)); //if (_logoid.HasValue) //{ // dc.DefaultValue = _logoid.Value; //} //this.DataSource.Tables[1].Columns.Add(dc); foreach (DataRow dataRow in frmPM0104.GroutingInfo) { string sqlWhere = "GroutingLineID = " + dataRow["GroutingLineID"].ToString(); DataRow[] drLines = this.DataSource.Tables[0].Select(sqlWhere); if (drLines == null || drLines.Length == 0) { continue; } DataRow[] drs = this.DataSource.Tables[1].Select("GroutingLineID = " + dataRow["GroutingLineID"].ToString()); if (drs == null || drs.Length == 0) { drLines[0].Delete(); continue; } if (groutingLines.Length > 0) { groutingLines.Append(", "); } groutingLines.Append(string.Format("{0}({1})[{2}]", drLines[0]["GroutingLineCode"], drLines[0]["MouldQuantity"], drLines[0]["monitorcode"])); drLines[0]["UserID"] = dataRow["GroutingUserID"]; drLines[0]["UserCode"] = dataRow["GroutingUserCode"]; string canManyTimes = drLines[0]["CanManyTimes"].ToString(); int num = System.Convert.ToInt32(dataRow["GroutingNum"]); int batchNo = System.Convert.ToInt32(drLines[0]["GroutingBatchNo"]); if (num > 1 && "1" == canManyTimes) { for (int i = 1; i < num; i++) { DataRow newRow = this.DataSource.Tables[0].Rows.Add(drLines[0].ItemArray); newRow["GroutingBatchNo"] = batchNo + i; } } foreach (DataRow detailDataRow in drs) { detailDataRow["GroutingUserID"] = dataRow["GroutingUserID"]; detailDataRow["GroutingUserCode"] = dataRow["GroutingUserCode"]; object NoGroutingRreason = dataRow["NoGroutingRreason"]; if (NoGroutingRreason != null && NoGroutingRreason != DBNull.Value) { detailDataRow["GroutingFlag"] = (int)Constant.GroutingFlag.No; detailDataRow["NoGroutingRreason"] = dataRow["NoGroutingRreason"]; } if (num > 1 && "1" == canManyTimes) { for (int i = 1; i < num; i++) { DataRow newRow = this.DataSource.Tables[1].Rows.Add(detailDataRow.ItemArray); newRow["GroutingBatchNo"] = batchNo + i; } } } } this.DataSource.AcceptChanges(); this.DataSource.Tables[1].DefaultView.Sort = "GroutingLineCode, GroutingBatchNo, GroutingMouldCode"; this.txtGrouting.Text = groutingLines.ToString(); this.dgvDetail.DataSource = this.DataSource.Tables[1]; this.dgvDetail.IsSetInputColumnsColor = true; // 按钮状态 this.tsbtnAllGrouting.Enabled = false; this.tsbtnGrouting.Enabled = false; this.tsbtnClearDetail.Enabled = true; this.tsbtnChangeGroutingUser.Enabled = true; this.btnSave.Enabled = true; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 更改成型工按钮按下,整个成型线更换成型工 /// /// /// private void tsbtnChangeGroutingUser_Click(object sender, EventArgs e) { try { } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 清空注浆明细按钮按钮,清空注浆信息,可以重新进行注浆 /// /// /// private void tsbtnClearDetail_Click(object sender, EventArgs e) { this.txtGrouting.Clear(); this.dgvDetail.DataSource = null; this.DataSource = null; this.lblGroutingDateValue.Text = this._accountDate.Date.ToString(Constant.S_DATE_YYYY_MM_DD); // 清空注浆信息后,清空明细、更换成型工按钮不可用 this.tsbtnAllGrouting.Enabled = true; this.tsbtnGrouting.Enabled = true; this.tsbtnClearDetail.Enabled = false; this.tsbtnChangeGroutingUser.Enabled = false; this.btnSave.Enabled = false; } /// /// 提交选择列内容的修改 /// /// /// private void dgvDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e) { try { if (this.dgvDetail.CurrentRow != null && this.dgvDetail.IsCurrentCellDirty) { if ("GroutingFlag".Equals(this.dgvDetail.Columns [this.dgvDetail.CurrentCell.ColumnIndex].Name)) { this.dgvDetail.CommitEdit(DataGridViewDataErrorContexts.Commit); } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 未注浆时,未注浆原因才可以输入 /// private void dgvDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex != Constant.INT_IS_NEGATIE_ONE && this._canEdit) { DataGridViewRow dataGridViewRow = this.dgvDetail.Rows[e.RowIndex]; // 如果是改变了注浆标识,则对未注浆原因进行控制输入 if ( "GroutingFlag".Equals(this.dgvDetail.Columns[e.ColumnIndex].Name)) { // 选择了未注浆 if (((int)Constant.GroutingFlag.Yes).ToString() != dataGridViewRow.Cells["GroutingFlag"].Value.ToString()) { dataGridViewRow.Cells["NoGroutingRreason"].ReadOnly = false; } else { dataGridViewRow.Cells["NoGroutingRreason"].ReadOnly = true; this.dgvDetail.Rows[e.RowIndex].Cells["NoGroutingRreason"].Value = DBNull.Value; } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 排序后设置Grid状态 /// /// /// private void dgvDetail_Sorted(object sender, EventArgs e) { this.SetEditGrid(); this.dgvDetail.IsSetInputColumnsColor = true; } /// /// 自动列宽 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 页面关闭 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } /// /// 保存数据 /// private void btnSave_Click(object sender, EventArgs e) { // 没有注浆数据 if (this.DataSource == null || this.DataSource.Tables.Count != 2) { return; } try { DataRow[] noGroutingDataRow = this.DataSource.Tables[1].Select("GroutingFlag = 0 AND NoGroutingRreason IS NULL"); if (noGroutingDataRow != null && noGroutingDataRow.Length > 0) { string mc = null; foreach (DataRow dataRow in noGroutingDataRow) { if (mc != null) { mc += ","; } mc += dataRow["GroutingMouldCode"].ToString(); } DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_C_006, "以下模具编号既没有注浆也没有未注浆原因" + Environment.NewLine + mc); return; } DateTime? date = null; if (this._formMode == Constant.FormMode.Add) { date = this._groutingDate; } ServiceResultEntity sre = this.DoAsync(() => { return PMModuleProxyNew.Service.SetFPM0102Data(date, this.DataSource); } ); if (sre.Status == Constant.ServiceResultStatus.Success) { DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_002); if (sre.Result != null) { this.GroutingDailyIDs = sre.Result.ToString(); } this.DialogResult = DialogResult.OK; this.Close(); return; } if (sre.Status == Constant.ServiceResultStatus.Other) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message); } this.SetEditGrid(); } catch (Exception ex) { this.SetEditGrid(); // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 关闭窗体 /// private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; this.Close(); } /// /// 设置注浆状态和未注浆原因 /// /// /// private void btnNGRSetting_Click(object sender, EventArgs e) { if (this.cboNoGroutingRreason.SelectedIndex < 0 || !this._canEdit) { return; } try { object noGroutingRreason = null; // 未注浆原因 if (Constant.CBO_SELECT_ALL_VALUE.ToString() != this.cboNoGroutingRreason.SelectedValue.ToString()) { noGroutingRreason = this.cboNoGroutingRreason.SelectedValue; } foreach (DataGridViewRow row in this.dgvDetail.Rows) { if (!row.Cells["GroutingFlag"].ReadOnly) { if (noGroutingRreason == null) { row.Cells["NoGroutingRreason"].Value = DBNull.Value; row.Cells["GroutingFlag"].Value = (int)Constant.GroutingFlag.Yes; } else { row.Cells["NoGroutingRreason"].Value = noGroutingRreason; row.Cells["GroutingFlag"].Value = (int)Constant.GroutingFlag.No; } DataRowView dataRow = row.DataBoundItem as DataRowView; if (dataRow != null) { dataRow.EndEdit(); } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } #endregion #region 私有方法 /// /// 初始化控件 /// private void InitializeControls() { // 窗体名称赋值 if (this._dailyId > 0) { this._formMode = Constant.FormMode.Edit; this.Text = FormTitles.F_PM_0102_EDIT; this.tsbtnAllGrouting.Enabled = false; this.tsbtnGrouting.Enabled = false; this.BarCode.Visible = true; this.ScrapFlag.Visible = true; } else { this._formMode = Constant.FormMode.Add; this.Text = FormTitles.F_PM_0102_ADD; this.BarCode.Visible = false; this.ScrapFlag.Visible = false; } // 功能按钮文本赋值 this.tsbtnAllGrouting.Text = ButtonText.TSBTN_ALLGROUTING; this.tsbtnGrouting.Text = ButtonText.TSBTN_GROUTING; this.tsbtnClearDetail.Text = ButtonText.TSBTN_CLEARDETAIL; this.tsbtnChangeGroutingUser.Text = ButtonText.TSBTN_CHANGEGROUTINGUSER; this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE; this.btnSave.Text = ButtonText.BTN_SAVE; this.btnClose.Text = ButtonText.BTN_CLOSE; this.dgvDetail.AutoGenerateColumns = false; } /// /// 设置列表中未注浆原因的数据源 /// private void InitializeData() { try { // 获取成型线类型数据并绑定到控件上 ServiceResultEntity sre = this.DoAsync(() => { return PMModuleProxyNew.Service.GetFPM0102IData(this._dailyId); } ); if (sre.Status == Constant.ServiceResultStatus.Other) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message); this.DialogResult = DialogResult.Cancel; this.Close(); return; } if (sre.Status != Constant.ServiceResultStatus.Success) { return; } if (sre.Data != null && sre.Data.Tables.Count > 0) { // 设置全部注浆选项 DataTable ngrDataTable = sre.Data.Tables[0].Copy(); DataRow ngrDataRow = ngrDataTable.NewRow(); ngrDataRow["DictionaryID"] = Constant.CBO_SELECT_ALL_VALUE; ngrDataRow["DictionaryValue"] = "全部注浆"; ngrDataRow["DisplayNo"] = 0; ngrDataTable.Rows.InsertAt(ngrDataRow, 0); this.cboNoGroutingRreason.ValueMember = "DictionaryID"; this.cboNoGroutingRreason.DisplayMember = "DictionaryValue"; this.cboNoGroutingRreason.DataSource = ngrDataTable; this._dtNotGroutingRreason = sre.Data.Tables[0]; // 设置空选项 DataRow dataRow = this._dtNotGroutingRreason.NewRow(); dataRow["DictionaryID"] = DBNull.Value; dataRow["DictionaryValue"] = Constant.CBO_SELECT_EMPTY_NAME; dataRow["DisplayNo"] = 0; this._dtNotGroutingRreason.Rows.InsertAt(dataRow, 0); } this.NoGroutingRreason.ValueMember = "DictionaryID"; this.NoGroutingRreason.DisplayMember = "DictionaryValue"; this.NoGroutingRreason.DataSource = this._dtNotGroutingRreason; if (this._formMode == Constant.FormMode.Edit) { _canEdit = ((int)sre.Result == 1); // 编辑时,修改未注浆原因 if (_canEdit) { this.lblNoGroutingRreason.Visible = true; this.cboNoGroutingRreason.Visible = true; this.btnNGRSetting.Visible = true; } else { this.txtGrouting1.Visible = true; this.txtGrouting.Visible = false; this.gbxInfo.Height -= 30;// 67; this.dgvDetail.Top -= 30; this.dgvDetail.Height += 30; } sre.Data.Tables.RemoveAt(0); this.DataSource = sre.Data; if (this.DataSource != null && this.DataSource.Tables.Count == 2) { DataRow gdDataRow = this.DataSource.Tables[0].Rows[0]; this.txtGrouting.Text = string.Format("{0}({1})", gdDataRow["GroutingLineCode"], gdDataRow["MouldQuantity"]); this.txtGrouting1.Text = this.txtGrouting.Text; this._groutingDate = Convert.ToDateTime(gdDataRow["GroutingDate"]); //this._accountDate = this._groutingDate; this.dgvDetail.DataSource = this.DataSource.Tables[1]; this.SetEditGrid(); this.dgvDetail.IsSetInputColumnsColor = true; // 按钮状态 this.btnSave.Enabled = true; } // 编辑时,修改未注浆原因 if (!_canEdit) { this.txtGrouting1.Text += System.Environment.NewLine + System.Environment.NewLine + sre.Message; this.txtGrouting1.ForeColor = System.Drawing.Color.Red; } this.dgvDetail.Focus(); } else { if (sre.Result != null) { this._accountDate = Convert.ToDateTime(sre.Result); this._groutingDate = this._accountDate; } } this.lblGroutingDateValue.Text = this._groutingDate.ToString(Constant.S_DATE_YYYY_MM_DD); } catch (Exception ex) { throw ex; } } /// /// 取得可注浆信息 /// /// 注浆日期 /// 成型线ID(多个用【,】隔开) /// 可注浆信息 private DataSet GetGroutingDailyInfo(DateTime? groutingDate, string groutingLineIDs) { try { // 根据注浆日期、成型线获取所有可注浆模具信息 ServiceResultEntity sre = this.DoAsync(() => { return PMModuleProxyNew.Service.GetFPM0102_GroutingLine(groutingDate, groutingLineIDs); } ); // 取注浆日期 if (sre.Result != null) { this._groutingDate = Convert.ToDateTime(sre.Result); } else if (groutingDate.HasValue) { this._groutingDate = groutingDate.Value.Date; } else { this._groutingDate = DateTime.Now.Date; } this.lblGroutingDateValue.Text = this._groutingDate.ToString(Constant.S_DATE_YYYY_MM_DD); // 异常情况处理 if (sre.Status > Constant.ServiceResultStatus.Success) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, sre.Message); return null; } return sre.Data; } catch (Exception ex) { throw ex; } } /// /// 编辑模式下设置Grid编辑状态 /// private void SetEditGrid() { if(this._formMode != Constant.FormMode.Edit) { return; } foreach (DataGridViewRow row in this.dgvDetail.Rows) { // 交坯后,不能编辑 object deliverFlag = (row.DataBoundItem as DataRowView)["DeliverFlag"]; if (deliverFlag != null && "1" == deliverFlag.ToString()) { row.Cells["colLogo"].ReadOnly = true; row.Cells["GroutingFlag"].ReadOnly = true; row.Cells["NoGroutingRreason"].ReadOnly = true; } // 绑定条码后,不能编辑 object barCode = row.Cells["BarCode"].Value; object scrapFlag = row.Cells["ScrapFlag"].Value; if ((barCode != null && !string.IsNullOrWhiteSpace(barCode.ToString())) || (scrapFlag != null && ((int)Constant.GroutingScrapFlag.Yes).ToString() == scrapFlag.ToString())) { row.Cells["GroutingFlag"].ReadOnly = true; row.Cells["NoGroutingRreason"].ReadOnly = true; row.Cells["NoGroutingRreason"].Value = DBNull.Value; //row.Cells["Remarks"].ReadOnly = false; continue; } // 未注浆,可以输入未注浆原因 if (((int)Constant.GroutingFlag.No).ToString() == row.Cells["GroutingFlag"].Value.ToString()) { row.Cells["NoGroutingRreason"].ReadOnly = false; } else { row.Cells["NoGroutingRreason"].Value = DBNull.Value; row.Cells["NoGroutingRreason"].ReadOnly = true; } } if (!this._canEdit) { dgvDetail.Columns["GroutingFlag"].ReadOnly = true; dgvDetail.Columns["NoGroutingRreason"].ReadOnly = true; } } #endregion private void c_Button1_Click(object sender, EventArgs e) { if (this.cmbLogo.SelectedIndex < 0) { return; } try { foreach (DataGridViewRow row in this.dgvDetail.Rows) { if (!row.Cells["colLogo"].ReadOnly) { row.Cells["colLogo"].Value = this.cmbLogo.SelectedValue; DataRowView dataRow = row.DataBoundItem as DataRowView; if (dataRow != null) { dataRow.EndEdit(); } } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }