| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_PM_1602.cs
- * 2.功能描述:新增/编辑半检数据
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2014/12/4 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Data;
- 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.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
- using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
- namespace Dongke.IBOSS.PRD.Client.PMModule
- {
- /// <summary>
- /// 新增/编辑半检数据
- /// </summary>
- public partial class F_PM_1602 : FormBase
- {
- #region 成员变量
- // 半检数据ID
- int _semiTestID = -1;
- // 过滤数 用来过滤产品对应的缺陷
- int _filterCount = 0;
- // 当前过滤数
- int _currentfilterCount = 0;
- // 默认检验明细数据源
- private DataSet _dsSemiTestDetail = null;
- // 默认缺陷明细数据源
- private DataSet _dsSemiTestDefecDetail = null;
- // 临时表名
- private string _TableName = "Temp";
- // 时间戳
- private DateTime _OPTimeStamp;
- // 操作工号权限
- private string _userPurviews = "";
- // 编辑行
- int editRow = 0;
- #endregion
- #region 属性
- /// <summary>
- /// 默认检验明细数据源
- /// </summary>
- public DataSet DSTableSemiTestDetail
- {
- set
- {
- _dsSemiTestDetail = value;
- }
- get
- {
- if (_dsSemiTestDetail == null)
- {
- _dsSemiTestDetail = new DataSet();
- return _dsSemiTestDetail;
- }
- else
- {
- return _dsSemiTestDetail;
- }
- }
- }
- /// <summary>
- /// 默认缺陷明细数据源
- /// </summary>
- public DataSet DSTableSemiTestDefectDetail
- {
- set
- {
- _dsSemiTestDefecDetail = value;
- }
- get
- {
- if (_dsSemiTestDefecDetail == null)
- {
- _dsSemiTestDefecDetail = new DataSet();
- return _dsSemiTestDefecDetail;
- }
- else
- {
- return _dsSemiTestDefecDetail;
- }
- }
- }
- #endregion
- #region 构造函数
- public F_PM_1602()
- {
- InitializeComponent();
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CANCEL;
- this.Text = FormTitles.F_PM_1602_ADD;
- }
- public F_PM_1602(int semiTestID)
- {
- InitializeComponent();
- this._semiTestID = semiTestID;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CANCEL;
- this.Text = FormTitles.F_PM_1602_EDIT;
- }
- #endregion
- #region 事件
- // 页面窗体加载事件
- private void F_PM_1602_Load(object sender, EventArgs e)
- {
- try
- {
- this.dgvSemiTestDetail.IsSetInputColumnsColor = true;
- this.dgvDefectDetail.IsSetInputColumnsColor = true;
- // 加载权限
- FormPermissionManager.FormPermissionControl(this.Name, this,
- Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
- Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- this.dgvSemiTestDetail.AutoGenerateColumns = false; //半检明细
- this.dgvDefectDetail.AutoGenerateColumns = false; //缺陷明细
- this.dgvSemiTestDetail.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
- this.dgvDefectDetail.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
- if (DSTableSemiTestDetail.Tables.IndexOf(_TableName + _filterCount) == -Constant.INT_IS_ONE)
- {
- DataTable dtSemiTestDetail = new DataTable(_TableName + _filterCount);
- dtSemiTestDetail.Columns.Add("GroutingUserCode");
- dtSemiTestDetail.Columns.Add("GroutingUserID", typeof(decimal));
- dtSemiTestDetail.Columns.Add("GoodsID", typeof(decimal));
- dtSemiTestDetail.Columns.Add("GoodsCode");
- dtSemiTestDetail.Columns.Add("GoodsName");
- dtSemiTestDetail.Columns.Add("GoodsSpecification");
- dtSemiTestDetail.Columns.Add("GoodsModel");
- dtSemiTestDetail.Columns.Add("GoodsTypeName");
- dtSemiTestDetail.Columns.Add("TestNum");
- dtSemiTestDetail.Columns.Add("ScrapNum");
- dtSemiTestDetail.Columns.Add("ScrapReason");
- dtSemiTestDetail.Columns.Add("Feedback");
- dtSemiTestDetail.Columns.Add("FilterCount");
- DSTableSemiTestDetail.Tables.Add(dtSemiTestDetail);
- }
- if (DSTableSemiTestDefectDetail.Tables.IndexOf(_TableName + _filterCount) == -Constant.INT_IS_ONE)
- {
- DataTable dtSemiTestDefectDetail = new DataTable(_TableName + _filterCount);
- dtSemiTestDefectDetail.Columns.Add("DefectID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectPositionID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectNum");
- dtSemiTestDefectDetail.Columns.Add("FilterCount");
- DSTableSemiTestDefectDetail.Tables.Add(dtSemiTestDefectDetail);
- }
- this.dgvSemiTestDetail.DataSource = DSTableSemiTestDetail.Tables[_TableName + _filterCount];
- this.dgvDefectDetail.DataSource = DSTableSemiTestDefectDetail.Tables[_TableName + _filterCount];
- //设置操作工号数据源
- getPurview();//
- // 获取检验工号数据源
- SUserEntity userEntity = new SUserEntity();
- userEntity.IsWorker = 1;//生产工号
- DataSet dsUser = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.SearchUserData(userEntity);
- }));
- if (dsUser != null && dsUser.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- //this.dropUserID.DisplayMember = "UserCode";
- //this.dropUserID.ValueMember = "UserID";
- //this.dropUserID.DataSource = dsUser.Tables[0];
- //this.GroutingUserID.DisplayMember = "UserCode";
- //this.GroutingUserID.ValueMember = "UserID";
- //this.GroutingUserID.DataSource = dsUser.Tables[0];
- if (this._userPurviews != string.Empty)
- {
- this.dropUserID.DisplayMember = "UserCode";
- this.dropUserID.ValueMember = "UserID";
- DataView dvUser = dsUser.Tables[0].DefaultView;
- dvUser.RowFilter = "UserID in(" + this._userPurviews + ")";
- DataTable dt = dvUser.ToTable();
- DataRow dr = dt.NewRow();
- dr["UserID"] = -1;
- dr["UserCode"] = "";
- dt.Rows.InsertAt(dr, 0);
- this.dropUserID.DataSource = dt;
- // 设置成检工号数据源
- this.GroutingUserID.DisplayMember = "UserCode";
- this.GroutingUserID.ValueMember = "UserID";
- this.GroutingUserID.DataSource = dt;
- }
- }
- // 获取产品档案
- GoodsEntity goodsEntity = new GoodsEntity();
- goodsEntity.ValueFlag = 1;//有效标记
- DataSet dsGoods = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.SerachGoods(goodsEntity);
- }));
- if (dsGoods != null && dsGoods.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- // 设置产品数据源
- this.GoodsID.DisplayMember = "GoodsCode";
- this.GoodsID.ValueMember = "GoodsID";
- this.GoodsID.DataSource = dsGoods.Tables[0];
- }
- // 获取缺陷
- DataSet dsDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetDictionaryData(0, "TPC005");
- }));
- if (dsDefect != null && dsDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.DefectID.DisplayMember = "DictionaryValue";
- this.DefectID.ValueMember = "DictionaryID";
- this.DefectID.DataSource = dsDefect.Tables[0];
- }
- // 获取缺陷位置
- DataSet dsDefectPosition = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetDictionaryData(0, "TPC006");
- }));
- if (dsDefectPosition != null && dsDefectPosition.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.DefectPositionID.DisplayMember = "DictionaryValue";
- this.DefectPositionID.ValueMember = "DictionaryID";
- this.DefectPositionID.DataSource = dsDefectPosition.Tables[0];
- }
- // 获取半检类别
- DataSet dsType = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetDictionaryData(0, "TPC007");
- }));
- if (dsType != null && dsType.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.dropSemiTestType.DisplayMember = "DictionaryValue";
- this.dropSemiTestType.ValueMember = "DictionaryID";
- this.dropSemiTestType.DataSource = dsType.Tables[0];
- }
- this.dtpDate.Value = DateTime.Now; //设置检验日期,默认当天
- if (this._semiTestID > Constant.INT_IS_ZERO) // 编辑数据
- {
- SetEditDataSource();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- //添加行事件
- private void dgvSemiTestDetail_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- string UpFilterCount = "";
- if (this.dgvSemiTestDetail.Rows[e.Row.Index - 1].Cells["FilterCount"].Value != null
- && this.dgvSemiTestDetail.Rows[e.Row.Index - 1].Cells["FilterCount"].Value.ToString() != string.Empty)
- {
- UpFilterCount = this.dgvSemiTestDetail.Rows[e.Row.Index - 1].Cells["FilterCount"].Value.ToString();
- }
- if (UpFilterCount == string.Empty)
- {
- this.dgvSemiTestDetail.Rows[e.Row.Index - 1].Cells["FilterCount"].Value = this._filterCount.ToString();
- }
- this._filterCount = this._filterCount + 1;
- this.dgvSemiTestDetail.Rows[e.Row.Index].Cells["FilterCount"].Value = this._filterCount.ToString();
- this._currentfilterCount = this._filterCount;
- // 添加时把对应只读去掉,防止上来先选择缺陷
- this.dgvDefectDetail.ReadOnly = false;
- dgvSemiTestDetail_SelectionChanged(sender, e);
- }
- /// <summary>
- /// 保存按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dropUserID.SelectedValue == null || this.dropUserID.SelectedValue.ToString() == "-1")
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "检验工号"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (this.dropSemiTestType.SelectedValue == null
- || this.dropSemiTestType.SelectedValue.ToString() == string.Empty)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "半检类别"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (this._semiTestID > Constant.INT_IS_ZERO)
- {
- int ValidateRow = (int)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.ValidateOPTimeStamp(this._semiTestID, _OPTimeStamp);
- }));
- if (ValidateRow == Constant.INT_IS_NEGATIE_ONE)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W012, "编辑半检", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- }
- SemiTestEntity[] semiTestEntitys = new SemiTestEntity[1];
- SemiTestEntity semiTestEntity = new SemiTestEntity();
- semiTestEntity.TestUserID = Convert.ToInt32(this.dropUserID.SelectedValue);
- semiTestEntity.TestDate = this.dtpDate.Value;
- semiTestEntity.Remarks = this.txtRemarks.Text.Trim();
- semiTestEntity.AuditStatus = 0;
- semiTestEntity.ValueFlag = 1;
- semiTestEntity.SemiTestType = Convert.ToInt32(this.dropSemiTestType.SelectedValue);
- semiTestEntitys[0] = semiTestEntity;
- bool isError = false; // 是否存在错误
- int ErrorType = -1; // 默认-1 明细1 缺陷2
- int CurrentRowIndex = -1; //错误行号
- int DetailCurrentRowIndex = -1; //错误行号
- int FilterCount = -1;
- List<SemiTestDetailEntity> semiTestDetailEntitys = new List<SemiTestDetailEntity>();
- SemiTestDetailEntity semiTestDetailEntity = null;
- for (int i = 0; i < this.DSTableSemiTestDetail.Tables[0].Rows.Count; i++) //半检明细表
- {
- semiTestDetailEntity = new SemiTestDetailEntity();
- if (this.DSTableSemiTestDetail.Tables[0].Rows[i]["GroutingUserID"].ToString() == string.Empty)
- {
- isError = true;//有错误 未选择成型工号
- ErrorType = 1; //明细
- CurrentRowIndex = i;
- break;
- }
- semiTestDetailEntity.GroutingUserID = Convert.ToInt32(this.DSTableSemiTestDetail.Tables[0].Rows[i]["GroutingUserID"]);
- if (this.DSTableSemiTestDetail.Tables[0].Rows[i]["GoodsCode"].ToString() == string.Empty)
- {
- isError = true;//有错误 未选择产品ID
- ErrorType = 1; //明细
- CurrentRowIndex = i;
- break;
- }
- semiTestDetailEntity.GoodsID = Convert.ToInt32(this.DSTableSemiTestDetail.Tables[0].Rows[i]["GoodsID"]);
- semiTestDetailEntity.GoodsCode = this.DSTableSemiTestDetail.Tables[0].Rows[i]["GoodsCode"].ToString();
- semiTestDetailEntity.GoodsName = this.DSTableSemiTestDetail.Tables[0].Rows[i]["GoodsName"].ToString();
- semiTestDetailEntity.TestNum = this.DSTableSemiTestDetail.Tables[0].Rows[i]["TestNum"].ToString() == string.Empty ? 0 :
- Convert.ToInt32(this.DSTableSemiTestDetail.Tables[0].Rows[i]["TestNum"]);
- semiTestDetailEntity.ScrapNum = this.DSTableSemiTestDetail.Tables[0].Rows[i]["ScrapNum"].ToString() == string.Empty ? 0 :
- Convert.ToInt32(this.DSTableSemiTestDetail.Tables[0].Rows[i]["ScrapNum"]);
- semiTestDetailEntity.ScrapReason = this.DSTableSemiTestDetail.Tables[0].Rows[i]["ScrapReason"].ToString();
- semiTestDetailEntity.Feedback = this.DSTableSemiTestDetail.Tables[0].Rows[i]["Feedback"].ToString();
- semiTestDetailEntity.ValueFlag = 1;
- // 遍历产品对应的缺陷
- List<SemiTestDefectEntity> semiTestDefectEntitys = new List<SemiTestDefectEntity>();
- if (this.DSTableSemiTestDefectDetail.Tables.Contains(string.Format("{0}{1}", this._TableName,
- this.DSTableSemiTestDetail.Tables[0].Rows[i]["FilterCount"].ToString())))
- {
- SemiTestDefectEntity semiTestDefectEntity = null;
- DataTable dtTemp = this.DSTableSemiTestDefectDetail.Tables[string.Format("{0}{1}", this._TableName,
- this.DSTableSemiTestDetail.Tables[0].Rows[i]["FilterCount"].ToString())];
- int Row = 0;
- foreach (DataRow drStaff in dtTemp.Rows)
- {
- semiTestDefectEntity = new SemiTestDefectEntity();
- if (drStaff["DefectID"] == null || drStaff["DefectID"].ToString() == string.Empty)
- {
- isError = true;//有错误 缺陷ID
- ErrorType = 2; //缺陷明细
- CurrentRowIndex = Row;
- DetailCurrentRowIndex = i;
- FilterCount = Convert.ToInt32(drStaff["FilterCount"].ToString());
- break;
- }
- semiTestDefectEntity.DefectID = Convert.ToInt32(drStaff["DefectID"]);
- if (drStaff["DefectPositionID"] == null || drStaff["DefectPositionID"].ToString() == string.Empty)
- {
- isError = true;//有错误 缺陷位置ID
- ErrorType = 2; //缺陷明细
- CurrentRowIndex = Row;
- DetailCurrentRowIndex = i;
- FilterCount = Convert.ToInt32(drStaff["FilterCount"].ToString());
- break;
- }
- semiTestDefectEntity.DefectPositionID = Convert.ToInt32(drStaff["DefectPositionID"]);
- semiTestDefectEntity.DefectNum = drStaff["DefectNum"].ToString() == string.Empty ? 0 :
- Convert.ToInt32(drStaff["DefectNum"]);
- semiTestDefectEntity.ValueFlag = 1;
- semiTestDefectEntitys.Add(semiTestDefectEntity);
- Row++;
- }
- //semiTestDetailEntity.SemiTestDefects = semiTestDefectEntitys.ToArray();
- semiTestDetailEntity.SemiTestDefects = semiTestDefectEntitys;
- }
- semiTestDetailEntitys.Add(semiTestDetailEntity);
- }
- //semiTestEntitys[0].SemiTestDetails = semiTestDetailEntitys.ToArray();
- semiTestEntitys[0].SemiTestDetails = semiTestDetailEntitys;
- if (isError)
- {
- if (ErrorType == Constant.INT_IS_ONE)
- {
- this.dgvSemiTestDetail.CurrentCell = null;
- this.dgvSemiTestDetail.Rows[CurrentRowIndex].Selected = true;
- // 提示信息
- MessageBox.Show("半检明细添加不完整",
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- else if (ErrorType == Constant.INT_IS_TWO)
- {
- this.dgvSemiTestDetail.CurrentCell = null;
- this.dgvSemiTestDetail.Rows[DetailCurrentRowIndex].Selected = true;
- this.dgvDefectDetail.DataSource =
- this.DSTableSemiTestDefectDetail.Tables[string.Format("{0}{1}", this._TableName,
- FilterCount)];
- this.dgvDefectDetail.CurrentCell = null;
- this.dgvDefectDetail.Rows[CurrentRowIndex].Selected = true;
- this.dgvDefectDetail.ReadOnly = false;
- // 提示信息
- MessageBox.Show("半检缺陷明细添加不完整",
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- // 最外层For循环结束
- if (semiTestEntitys.Length > Constant.INT_IS_ZERO && this.DSTableSemiTestDetail.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- string returnValue = (string)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.AddSemiTest(semiTestEntitys);
- }));
- if (string.IsNullOrEmpty(returnValue))//成功
- {
- //保存成功后,并且为编辑时候,把上次编辑的数据禁用
- if (this._semiTestID > Constant.INT_IS_ZERO)
- {
- int deleteRow = (int)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.DeleteSemiTestDataByID(this._semiTestID);
- }));
- }
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建" + this.Text, "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- // 保存成功后,清空相应数据源
- this.dtpDate.Value = DateTime.Now;
- this.txtRemarks.Text = "";
- this.DSTableSemiTestDetail.Tables[0].Rows.Clear();
- this.DSTableSemiTestDetail.Tables[0].AcceptChanges();
- this.DSTableSemiTestDefectDetail.Tables.Clear();
- this.dgvSemiTestDetail.DataSource = this.DSTableSemiTestDetail.Tables[0];
- this.dgvDefectDetail.DataSource = null;
- }
- else
- {
- // 提示信息
- MessageBox.Show(returnValue,
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- 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 dgvSemiTestDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- if (e.ColumnIndex == Constant.INT_IS_TWO && e.RowIndex != -Constant.INT_IS_ONE)
- {
- // 当前过滤数
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value.ToString() != string.Empty)
- {
- this._currentfilterCount = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value);
- }
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsID"].Value.ToString() != string.Empty)
- {
- DataTable dtGoods = this.GoodsID.DataSource as DataTable;
- if (dtGoods != null && dtGoods.Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow[] dr = dtGoods.Select("GoodsID=" + this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsID"].Value.ToString());
- if (dr.Length > Constant.INT_IS_ZERO)
- {
- this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsCode"].Value = dr[0]["GoodsCode"];
- this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsName"].Value = dr[0]["GoodsName"];
- this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsSpecification"].Value = dr[0]["GoodsSpecification"];
- this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsModel"].Value = dr[0]["GoodsModel"];
- this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["GoodsTypeName"].Value = dr[0]["GoodsTypeName"];
- }
- }
- }
- }
- if (e.RowIndex != -Constant.INT_IS_ONE)
- {
- // 当前过滤数
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value != null)
- {
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value.ToString() != string.Empty)
- {
- this._currentfilterCount = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value);
- }
- if (DSTableSemiTestDefectDetail.Tables.IndexOf(_TableName + this._currentfilterCount) == -Constant.INT_IS_ONE)
- {
- DataTable dtSemiTestDefectDetail = new DataTable(_TableName + this._currentfilterCount);
- dtSemiTestDefectDetail.Columns.Add("DefectID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectPositionID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectNum");
- dtSemiTestDefectDetail.Columns.Add("FilterCount");
- DSTableSemiTestDefectDetail.Tables.Add(dtSemiTestDefectDetail);
- }
- dgvDefectDetail.DataSource = DSTableSemiTestDefectDetail.Tables[_TableName + this._currentfilterCount];
- }
- }
- }
- /// <summary>
- /// 半检明细选定项改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvSemiTestDetail_SelectionChanged(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvSemiTestDetail.CurrentCell != null)
- {
- // 当前过滤数
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value != null
- && this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value.ToString() != string.Empty)
- {
- dgvDefectDetail.ReadOnly = false;
- this._currentfilterCount = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value);
- dgvDefectDetail.DataSource = DSTableSemiTestDefectDetail.Tables[_TableName + this._currentfilterCount];
- }
- else
- {
- dgvDefectDetail.ReadOnly = 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 dgvDefectDetail_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- int row = 0;
- if (e.Row.Index != -Constant.INT_IS_ONE)
- {
- this.dgvDefectDetail.Rows[e.Row.Index].Selected = true;
- row = this.dgvDefectDetail.CurrentCell.RowIndex;
- }
- else
- {
- this.dgvDefectDetail.Rows[0].Selected = true;
- }
- string UpFilterCount = "";
- if (this.dgvDefectDetail.Rows[row].Cells["DefectFilterCount"].Value != null)
- {
- UpFilterCount = this.dgvDefectDetail.Rows[row].Cells["DefectFilterCount"].Value.ToString();
- }
- if (dgvSemiTestDetail.CurrentCell != null)
- {
- this._currentfilterCount = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value);
- }
- int temp = this._currentfilterCount;
- if (this.dgvSemiTestDetail.CurrentCell != null)
- {
- // 当前过滤数
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value != null
- && this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value.ToString() != string.Empty)
- {
- temp = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value);
- }
- }
- if (DSTableSemiTestDefectDetail.Tables.IndexOf(_TableName + temp) == -Constant.INT_IS_ONE)
- {
- DataTable dtSemiTestDefectDetail = new DataTable(_TableName + temp);
- dtSemiTestDefectDetail.Columns.Add("DefectID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectPositionID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectNum");
- dtSemiTestDefectDetail.Columns.Add("FilterCount");
- DSTableSemiTestDefectDetail.Tables.Add(dtSemiTestDefectDetail);
- }
- if (UpFilterCount == string.Empty)
- {
- this.dgvDefectDetail.Rows[this.dgvDefectDetail.CurrentCell.RowIndex].Cells["DefectFilterCount"].Value = temp;
- }
- this.dgvDefectDetail.Rows[this.dgvDefectDetail.CurrentCell.RowIndex].Cells["DefectFilterCount"].Value = temp;
- }
- /// <summary>
- /// 当前是否有未提交数据事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvDefectDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvDefectDetail.CurrentCell != null)
- {
- // 记录最后选择行
- if (this.dgvDefectDetail.CurrentCell.ColumnIndex == Constant.INT_IS_ZERO
- && this.dgvDefectDetail.CurrentCell.RowIndex != -Constant.INT_IS_ONE)
- {
- if (dgvDefectDetail.IsCurrentCellDirty)
- {
- dgvDefectDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
- }
- }
- }
- }
- 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 dgvDefectDetail_SelectionChanged(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvDefectDetail.CurrentCell != null)
- {
- if (dgvSemiTestDetail.CurrentCell != null)
- {
- this._currentfilterCount = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["FilterCount"].Value);
- this.dgvDefectDetail.ReadOnly = false;
- }
- else
- {
- dgvDefectDetail.ReadOnly = 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 dgvSemiTestDetail_CurrentCellDirtyStateChanged(object sender, EventArgs e)
- {
- try
- {
- //if (this.dgvSemiTestDetail.CurrentCell != null)
- //{
- // // 记录最后选择行
- // if (this.dgvSemiTestDetail.CurrentCell.ColumnIndex == Constant.INT_IS_ONE
- // && this.dgvSemiTestDetail.CurrentCell.RowIndex != -Constant.INT_IS_ONE)
- // {
- // if (dgvSemiTestDetail.IsCurrentCellDirty)
- // {
- // editRow = this.dgvSemiTestDetail.CurrentCell.RowIndex;
- // dgvSemiTestDetail.CommitEdit(DataGridViewDataErrorContexts.Commit);
- // }
- // }
- //}
- }
- 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 dgvSemiTestDetail_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- try
- {
- if (e.ColumnIndex == 9 && e.RowIndex != -Constant.INT_IS_ONE)
- {
- DataGridViewRow rowItem = dgvSemiTestDetail.Rows[e.RowIndex];
- DataGridViewColumn columnItem = dgvSemiTestDetail.Columns[e.ColumnIndex];
- object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- int ScrapNum = 0;
- if (columnvalue.ToString() != string.Empty)
- {
- ScrapNum = Convert.ToInt32(columnvalue.ToString());
- }
- else
- {
- this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["ScrapNum"].Value = 0;
- }
- int TestNum = 0;
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["TestNum"].Value.ToString() != string.Empty)
- {
- TestNum = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["TestNum"].Value);
- }
- if (ScrapNum > TestNum)
- {
- //提示信息
- MessageBox.Show(string.Format("报废数不能大于总数"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- e.Cancel = true;
- return;
- }
- }
- if (e.ColumnIndex == 8 && e.RowIndex != -Constant.INT_IS_ONE)
- {
- DataGridViewRow rowItem = dgvSemiTestDetail.Rows[e.RowIndex];
- DataGridViewColumn columnItem = dgvSemiTestDetail.Columns[e.ColumnIndex];
- object columnvalue = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- int TestNum = 0;
- int ScrapNum = 0;
- if (columnvalue.ToString() != string.Empty)
- {
- TestNum = Convert.ToInt32(columnvalue.ToString());
- }
- if (this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["ScrapNum"].Value.ToString() != string.Empty)
- {
- ScrapNum = Convert.ToInt32(this.dgvSemiTestDetail.Rows[this.dgvSemiTestDetail.CurrentCell.RowIndex].Cells["ScrapNum"].Value);
- }
- if (ScrapNum > TestNum)
- {
- //提示信息
- MessageBox.Show(string.Format("总数不能小于报废数"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- e.Cancel = true;
- return;
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 编辑后设置数据源
- /// </summary>
- private void SetEditDataSource()
- {
- try
- {
- DataSet dsSemiTest = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.GetSemiTestByID(this._semiTestID);
- }));
- if (dsSemiTest != null && dsSemiTest.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- this.dropUserID.SelectedValue = dsSemiTest.Tables[0].Rows[0]["UserID"].ToString();
- this.dtpDate.Value = Convert.ToDateTime(dsSemiTest.Tables[0].Rows[0]["TestDate"]);
- this.txtRemarks.Text = dsSemiTest.Tables[0].Rows[0]["Remarks"].ToString();
- this._OPTimeStamp = Convert.ToDateTime(dsSemiTest.Tables[0].Rows[0]["OPTimeStamp"]);
- if (dsSemiTest.Tables[0].Rows[0]["UserID"].ToString() != string.Empty)
- {
- this.dropSemiTestType.SelectedValue = dsSemiTest.Tables[0].Rows[0]["SemiTestType"].ToString();
- }
- // 审核通过,只能查看,禁用控件
- if (Convert.ToInt32(dsSemiTest.Tables[0].Rows[0]["AuditStatus"]) == Constant.INT_IS_ONE)
- {
- this.dropUserID.Enabled = false;
- this.dtpDate.Enabled = false;
- this.dgvSemiTestDetail.ReadOnly = true;
- this.dgvDefectDetail.ReadOnly = true;
- this.btnSave.Enabled = false;
- this.dropSemiTestType.Enabled = false;
- this.txtRemarks.Enabled = false;
- }
- }
- if (dsSemiTest != null && dsSemiTest.Tables[1].Rows.Count > Constant.INT_IS_ZERO)
- {
- for (int i = 0; i < dsSemiTest.Tables[1].Rows.Count; i++)
- {
- DataRow dr = DSTableSemiTestDetail.Tables[_TableName + "0"].NewRow();
- dr["GroutingUserCode"] = string.Empty;
- dr["GroutingUserID"] = dsSemiTest.Tables[1].Rows[i]["GroutingUserID"];
- dr["GoodsID"] = dsSemiTest.Tables[1].Rows[i]["GoodsID"];
- dr["GoodsCode"] = dsSemiTest.Tables[1].Rows[i]["GoodsCode"];
- dr["GoodsName"] = dsSemiTest.Tables[1].Rows[i]["GoodsName"];
- dr["GoodsSpecification"] = dsSemiTest.Tables[1].Rows[i]["GoodsSpecification"];
- dr["GoodsModel"] = dsSemiTest.Tables[1].Rows[i]["GoodsModel"];
- dr["GoodsTypeName"] = dsSemiTest.Tables[1].Rows[i]["GoodsTypeName"];
- dr["TestNum"] = dsSemiTest.Tables[1].Rows[i]["TestNum"];
- dr["ScrapNum"] = dsSemiTest.Tables[1].Rows[i]["ScrapNum"];
- dr["ScrapReason"] = dsSemiTest.Tables[1].Rows[i]["ScrapReason"];
- dr["Feedback"] = dsSemiTest.Tables[1].Rows[i]["Feedback"];
- dr["FilterCount"] = i;
- DSTableSemiTestDetail.Tables[_TableName + "0"].Rows.Add(dr);
- // 产品对应的缺陷
- DataRow[] drRow = dsSemiTest.Tables[2].Select("SemiTestDetailID=" + dsSemiTest.Tables[1].Rows[i]["SemiTestDetailID"]);
- if (drRow.Length > Constant.INT_IS_ZERO)
- {
- foreach (DataRow r in drRow)
- {
- if (DSTableSemiTestDefectDetail.Tables.IndexOf(_TableName + i) == -Constant.INT_IS_ONE)
- {
- DataTable dtSemiTestDefectDetail = new DataTable(_TableName + i);
- dtSemiTestDefectDetail.Columns.Add("DefectID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectPositionID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectNum");
- dtSemiTestDefectDetail.Columns.Add("FilterCount");
- DSTableSemiTestDefectDetail.Tables.Add(dtSemiTestDefectDetail);
- }
- DataRow drDefect = DSTableSemiTestDefectDetail.Tables[_TableName + i].NewRow();
- drDefect["DefectID"] = r["DefectID"];
- drDefect["DefectPositionID"] = r["DefectPositionID"];
- drDefect["DefectNum"] = r["DefectNum"];
- drDefect["FilterCount"] = i;
- DSTableSemiTestDefectDetail.Tables[_TableName + i].Rows.Add(drDefect);
- }
- }
- else
- {
- if (DSTableSemiTestDefectDetail.Tables.IndexOf(_TableName + i) == -Constant.INT_IS_ONE)
- {
- DataTable dtSemiTestDefectDetail = new DataTable(_TableName + i);
- dtSemiTestDefectDetail.Columns.Add("DefectID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectPositionID", typeof(decimal));
- dtSemiTestDefectDetail.Columns.Add("DefectNum");
- dtSemiTestDefectDetail.Columns.Add("FilterCount");
- DSTableSemiTestDefectDetail.Tables.Add(dtSemiTestDefectDetail);
- }
- }
- this._filterCount = this._filterCount + 1;
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取当前工号权限
- /// </summary>
- protected void getPurview()
- {
- try
- {
- StringBuilder sbUserPurview = new StringBuilder();
- //获取用户权限集
- DataSet dsUserPurview = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetUserPurview(4, Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.UserID);
- }));
- //拼接字符串
- if (dsUserPurview != null)
- {
- foreach (DataRow dr in dsUserPurview.Tables[Constant.INT_IS_ZERO].Rows)
- {
- sbUserPurview.Append(dr[Constant.INT_IS_ZERO].ToString() + ",");
- }
- if (sbUserPurview.Length != Constant.INT_IS_ZERO)
- {
- this._userPurviews = sbUserPurview.ToString().Substring(Constant.INT_IS_ZERO, sbUserPurview.Length - 1);
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|