| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624 |
- /*******************************************************************************
- * Copyright(c) 2016 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_1002.cs
- * 2.功能描述:半成品缺陷位置管理
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2016/06/23 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Basics.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- public partial class F_MST_1002 : FormBase
- {
- #region 成员变量
- //窗体的单例模式
- private static F_MST_1002 _instance;
- // 缺陷位置数据源
- private DataTable _dtSourse;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_1002()
- {
- InitializeComponent();
- // 窗体标题、按钮文字
- this.Text = FormTitles.F_MST_1002;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- }
- #endregion
- #region 单例模式
- /// <summary>
- /// 单例模式,防止重复创建窗体
- /// </summary>
- public static F_MST_1002 Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new F_MST_1002();
- }
- return _instance;
- }
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_1002_Load(object sender, System.EventArgs e)
- {
- try
- {
- // 设置datagridview不自动创建列
- this.dgvDataDefectPosition.AutoGenerateColumns = false;
- this.dgvDataDefectPosition.AllowUserToDeleteRows = false;
- // 窗体启动立即加载全部半成品缺陷位置信息
- this.GetAllScdefectPosition();
- this.RefreshDataGridViewData();
- this.dgvDataDefectPosition.IsSetInputColumnsColor = true;
- //权限控制
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- this.dgvDataDefectPosition.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 点击右上角关闭按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_1002_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- // 关闭的时候需要判断是否有数据变化
- if (DataJudge.IsChange((DataTable)this.dgvDataDefectPosition.DataSource))
- {
- DialogResult resultMsgBox = MessageBox.Show(Messages.MSG_CMN_Q001, this.Text,
- MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- // 保存改变的数据
- if (resultMsgBox == DialogResult.Yes)
- {
- DataGridViewRow row = dgvDataDefectPosition.CurrentRow;
- if (!row.IsNewRow)
- {
- // 判断缺陷位置编码不能为空
- if (row.Cells["DefectPositionCode"].Value == null
- || string.IsNullOrEmpty(row.Cells["DefectPositionCode"].Value + string.Empty))
- {
- // 错误消息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 判断缺陷位置名称不能为空
- if (row.Cells["DefectPositionName"].Value == null
- || string.IsNullOrEmpty(row.Cells["DefectPositionName"].Value + string.Empty))
- {
- // 单元格的错误消息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷Position名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- }
- // 异步处理
- object result = DoAsync(new BaseAsyncMethod(SaveScdefectPosition));
- if (result.Equals(Constant.INT_IS_ONE))
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "缺陷位置编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 如果保存出错,不关闭窗体
- if (Convert.ToInt32(result) > Constant.INT_IS_ZERO)
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "半成品缺陷位置", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.btnSave.Enabled = false;
- this._dtSourse.AcceptChanges();
- }
- else if (Convert.ToInt32(result) == (int)Constant.RETURN_IS_EXIST)
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "半成品缺陷位置名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- else
- {
- e.Cancel = true;
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "半成品缺陷位置", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else if (resultMsgBox == DialogResult.Cancel)
- {
- e.Cancel = true;
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 窗体关闭后,释放单例资源
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_1001_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 信息输入格式控制
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefectPosition_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
- {
- try
- {
- TextBox tb = (e.Control as TextBox);
- if (tb != null)
- {
- if ("DefectPositionCode" == this.dgvDataDefectPosition.Columns[this.dgvDataDefectPosition.CurrentCell.ColumnIndex].Name)
- {
- tb.CharacterCasing = CharacterCasing.Upper;
- }
- else
- {
- tb.CharacterCasing = CharacterCasing.Normal;
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 选中新行时,设置默认值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefect_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
- {
- // 设置有效属性为选中状态
- e.Row.Cells["ValueFlag"].Value = Constant.INT_IS_ONE;
- e.Row.Cells["DisplayNo"].Value = e.Row.Index + 1;
- }
- /// <summary>
- /// 根据数据是否变化,设置保存按钮的可用状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefectPosition_RowValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.SetSaveBtnStatus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 根据数据是否变化,设置保存按钮的可用状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefect_CellValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.SetSaveBtnStatus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 单元格验证,检查
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefect_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- try
- {
- if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
- {
- return;
- }
- if (!dgvDataDefectPosition.CurrentRow.IsNewRow)
- {
- DataGridViewRow rowItem = dgvDataDefectPosition.Rows[e.RowIndex];
- DataGridViewColumn columnItem = dgvDataDefectPosition.Columns[e.ColumnIndex];
- object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- // 缺陷位置编码
- if ("DefectPositionCode".Equals(columnItem.Name))
- {
- if (columnvalue != null && !string.IsNullOrEmpty(columnvalue + ""))
- {
- if (!Utility.IsUnique(columnvalue.ToString(),
- dgvDataDefectPosition.CurrentRow.Index, this.dgvDataDefectPosition, "DefectPositionCode"))
- {
- // 单元格的错误消息
- this.dgvDataDefectPosition.CurrentRow.ErrorText = string.Format(
- Messages.MSG_CMN_W006, "缺陷位置编码");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- }
- }
- // 清除单元格的错误消息
- this.dgvDataDefectPosition.CurrentRow.ErrorText = string.Empty;
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 行校验
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefectPosition_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- // 按Esc键时不校验
- if (!dgvDataDefectPosition.IsCurrentRowDirty)
- {
- this.dgvDataDefectPosition.IsSetInputColumnsColor = true;
- return;
- }
- if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
- {
- // 清除单元格的错误消息
- this.dgvDataDefectPosition.CurrentRow.ErrorText = string.Empty;
- return;
- }
- DataGridViewRow row = dgvDataDefectPosition.CurrentRow;
- if (!row.IsNewRow)
- {
- // 判断缺陷位置编码能为空
- if (row.Cells["DefectPositionCode"].Value == null
- || string.IsNullOrEmpty(row.Cells["DefectPositionCode"].Value + ""))
- {
- // 单元格的错误消息
- this.dgvDataDefectPosition.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "缺陷位置编码");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 判断缺陷位置名称不能为空
- if (row.Cells["DefectPositionName"].Value == null
- || string.IsNullOrEmpty(row.Cells["DefectPositionName"].Value + ""))
- {
- // 单元格的错误消息
- this.dgvDataDefectPosition.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "缺陷位置名称");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- // 清除单元格的错误消息
- this.dgvDataDefectPosition.CurrentRow.ErrorText = string.Empty;
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 根据是否选中停用数据,加载数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this.RefreshDataGridViewData();
- this.SetSaveBtnStatus();
- this.dgvDataDefectPosition.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 单元格输入时,给自动生成的行设置颜色
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDataDefectPosition_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- this.dgvDataDefectPosition.IsSetInputColumnsColor = true;
- }
- /// <summary>
- /// 保存缺陷位置数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- int results = Conservation();
- //单元格必输项不能为空
- if (results == Constant.INT_IS_ONE)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.btnSave.Enabled = false;
- return;
- }
- if (results == Constant.INT_IS_TWO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置名称"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.btnSave.Enabled = false;
- return;
- }
- // 异步处理
- this.btnSave.Enabled = false;
- this.btnCancel.Enabled = false;
- int result = (int)DoAsync(new BaseAsyncMethod(SaveScdefectPosition));
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- if (result == Constant.INT_IS_TWO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "半成品缺陷位置", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this._dtSourse.AcceptChanges();
- this.btnSave.Enabled = false;
- }
- else if (result == Constant.INT_IS_ONE)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "缺陷位置编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "缺陷位置", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- this.dgvDataDefectPosition.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- this.btnSave.Enabled = true;
- this.btnCancel.Enabled = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 点击关闭按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 设置列表排序时的颜色
- /// </summary>
- private void dgvDataDefectPosition_Sorted(object sender, EventArgs e)
- {
- this.dgvDataDefectPosition.IsSetInputColumnsColor = true;
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 加载缺陷位置数据
- /// </summary>
- /// <returns></returns>
- private DataSet GetDefectPositionData()
- {
- try
- {
- byte valueFlag = Convert.ToByte(chkDisplayDisabledData.Checked);
- DataSet dstemp = SystemModuleProxy.Service.GetDefectPositionData(valueFlag);
- return dstemp;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取缺陷位置管理的全部数据
- /// </summary>
- /// <returns></returns>
- /// <remarks>
- /// 2016.06.23 王鑫 新建
- /// </remarks>
- private void GetAllScdefectPosition()
- {
- try
- {
- DataSet dsResult = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllScdefectPosition();
- }));
- this._dtSourse = dsResult.Tables[0];
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 得到缺陷位置信息
- /// </summary>
- /// <returns></returns>
- private void RefreshDataGridViewData()
- {
- try
- {
- //如果checkbox未选中时标识符状态
- if (this.chkDisplayDisabledData.Checked == false)
- {
- this._dtSourse.DefaultView.RowFilter = "ValueFlag=1";
- }
- else
- {
- this._dtSourse.DefaultView.RowFilter = null;
- }
- this.dgvDataDefectPosition.DataSource = this._dtSourse;
- this.btnSave.Enabled = false;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 保存缺陷位置数据
- /// </summary>
- /// <returns>是否成功</returns>
- private object SaveScdefectPosition()
- {
- try
- {
- // 获取当前datatJobsData数据源
- DataTable dataDefectData = (DataTable)this.dgvDataDefectPosition.DataSource;
- int result = SystemModuleProxy.Service.SaveScdefectPosition(dataDefectData);
- return result;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- private void SetSaveBtnStatus()
- {
- if (DataJudge.IsChange((DataTable)this.dgvDataDefectPosition.DataSource))
- {
- this.btnSave.Enabled = true;
- }
- else
- {
- this.btnSave.Enabled = false;
- }
- }
- /// <summary>
- /// 保存时单元格必输项不能为空
- /// </summary>
- private int Conservation()
- {
- int isConservation = Constant.INT_IS_ZERO;
- DataTable datatJobsData = (DataTable)this.dgvDataDefectPosition.DataSource;
- foreach (DataRow drproductionData in datatJobsData.Rows)
- {
- //判断单元格必输项是否为空
- if (drproductionData["DefectPositionCode"].ToString() == string.Empty)
- {
- isConservation = Constant.INT_IS_ONE;
- break;
- }
- if (drproductionData["DefectPositionName"].ToString() == string.Empty)
- {
- isConservation = Constant.INT_IS_TWO;
- break;
- }
- }
- return isConservation;
- }
- #endregion
- }
- }
|