/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_TAT_0403.cs * 2.功能描述:质量考核产品明细 * 编辑履历: * 作者 日期 版本 修改内容 * 宋扬 2014/12/11 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.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService; using Dongke.IBOSS.PRD.WCF.Proxys.TATModuleService; namespace Dongke.IBOSS.PRD.Client.TATModule { public partial class F_TAT_0403 : FormBase { #region 成员变量 // 窗体模式ID private Constant.FormMode _formType; // 操作实体ID private int? _entityId; // 选择窗体弹出标识 private bool _showFlag = true; // 数据源 private DataSet _dsSourse; // 产品数据源 private DataTable _dtGoodsSourse; // 窗体加载完毕标识 //private bool _pageLoadOK = false; #endregion #region 构造函数 /// /// 窗体构造 /// /// 窗体开启模式 /// 操作实体ID public F_TAT_0403(Constant.FormMode formType, int entityId) { InitializeComponent(); this._formType = formType; this._entityId = entityId; this.Text = FormTitles.F_TAT_0403; } #endregion #region 事件处理 /// /// 窗体加载 /// /// /// private void F_TAT_0403_Load(object sender, EventArgs e) { try { this.dgvJobs.AutoGenerateColumns = false; this.dgvGoods.AutoGenerateColumns = false; //绑定产品信息 this.GetGoods(); //绑定数据源与列表 this.BindData(); //如果是审核及观看模式 if (this._formType == Constant.FormMode.Display) { //不能删除 this.dgvGoods.AllowUserToDeleteRows = false; this.dgvJobs.AllowUserToDeleteRows = false; //列表设置为只读 this.dgvGoods.ReadOnly = true; this.dgvJobs.ReadOnly = true; this.dgvGoods.IsSetInputColumnsColor = false; this.dgvJobs.IsSetInputColumnsColor = false; //控件除关闭外全部不可用 this.tsbtnCreateGoods.Enabled = false; this.tsbtnCreateJobs.Enabled = false; this.btnSubmit.Enabled = false; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 关闭窗体 /// /// /// private void btnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 窗体自适应 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvJobs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); this.dgvGoods.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 提交操作 /// /// /// private void btnSubmit_Click(object sender, EventArgs e) { try { //提交操作 ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() => { return TATModuleProxy.Service.EditQualityDetail(Convert.ToInt32(this._entityId), this._dsSourse); }); ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text); if (srEntity.Status == Constant.ServiceResultStatus.Success) { this.DialogResult = DialogResult.OK; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 创建全部工种信息,并同时创建各工种对应的明细信息 /// /// /// private void tsbtnCreateJobs_Click(object sender, EventArgs e) { try { //这句话,因为新建的时候,莫名其妙会多出一个数据源不存在的空行,这样设定就不会出现了。 this.dgvJobs.AllowUserToAddRows = false; //获取全部工种 DataSet dsJobs = (DataSet)DoAsync(() => { return SystemModuleProxy.Service.GetJobsData(1); }); //如果获取到了工种 if (dsJobs != null && dsJobs.Tables.Count != Constant.INT_IS_ZERO) { DataTable dtSourse = this._dsSourse.Tables[Constant.INT_IS_ZERO]; //计数器 int dtSourseConut = dtSourse.Rows.Count; //判断是否以全部选择 if (dsJobs.Tables[Constant.INT_IS_ZERO].Rows.Count > dtSourseConut) { //循环生成工种信息并加入到数据源中 foreach (DataRow drFor in dsJobs.Tables[Constant.INT_IS_ZERO].Rows) { //首先查看该工种在现有数据源中是否存在 int JobIsHave = 0; if (dtSourse.Rows.Count > 0) { if (dtSourseConut != 0) { foreach (DataRow drSourse in dtSourse.Rows) { if (drSourse.RowState == DataRowState.Deleted) { dtSourseConut--; continue; } if (drSourse["JobsId"] == DBNull.Value) { drSourse["JobsId"] = drFor["JobsId"]; drSourse["JobsCode"] = drFor["JobsCode"]; drSourse["JobsName"] = drFor["JobsName"]; drSourse["BaseAmount"] = 0; drSourse["Isend"] = 0; dtSourseConut--; JobIsHave++; break; } int drForJobsId = Convert.ToInt32(drFor["JobsId"]); int drSourseJobsId = Convert.ToInt32(drSourse["JobsId"]); if (drForJobsId == drSourseJobsId) { dtSourseConut--; JobIsHave++; break; } } } } //如果不存在才重新生成 if (JobIsHave == 0 && drFor["JobsId"] != DBNull.Value) { DataRow drJobs = _dsSourse.Tables[Constant.INT_IS_ZERO].NewRow(); drJobs["JobsId"] = drFor["JobsId"]; drJobs["JobsCode"] = drFor["JobsCode"]; drJobs["JobsName"] = drFor["JobsName"]; drJobs["BaseAmount"] = 0; drJobs["Isend"] = 0; this._dsSourse.Tables[0].Rows.Add(drJobs); } } } else if (dtSourseConut > dsJobs.Tables[Constant.INT_IS_ZERO].Rows.Count) //判断是否有空行 { this._dsSourse.Tables[Constant.INT_IS_ZERO].Rows.RemoveAt(dtSourseConut-1); } //绑定 this.dgvJobs.DataSource = this._dsSourse.Tables[Constant.INT_IS_ZERO]; //并根据工种生成明细 this.BindDetail(); this.dgvGoods.IsSetInputColumnsColor = true; } //加载完毕 // this._pageLoadOK = true; this.dgvJobs.AllowUserToAddRows = true; this.dgvJobs.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 为某工种添加明细信息 /// /// /// private void tsbtnCreateGoods_Click(object sender, EventArgs e) { try { //如果选择了一个有效工种 if (this.dgvJobs.SelectedRows.Count != Constant.INT_IS_ZERO && this.dgvJobs.SelectedRows[Constant.INT_IS_ZERO].IsNewRow == false) { //获取工种ID DataGridViewRow gvrSelected = this.dgvJobs.SelectedRows[Constant.INT_IS_ZERO]; int JobsId = Convert.ToInt32(gvrSelected.Cells["JobsId"].Value); //遍历产品明细添加该工种的所有明细信息 foreach (DataRow drFor in this._dtGoodsSourse.Rows) { //首先查看该产品是否已存在 int GoodsIsHave = Constant.INT_IS_ZERO; foreach (DataGridViewRow gvrFor in this.dgvGoods.Rows) { if (Convert.ToInt32(gvrFor.Cells["GoodsID"].Value) == Convert.ToInt32(drFor["GoodsID"])) { GoodsIsHave++; break; } } //如果不存在才进行添加 if (GoodsIsHave == Constant.INT_IS_ZERO) { //向最终数据源添加扣罚明细信息 DataRow drDetail = this._dsSourse.Tables[Constant.INT_IS_ONE].NewRow(); drDetail["JobsId"] = gvrSelected.Cells["JobsId"].Value; drDetail["GoodsID"] = drFor["GoodsId"]; drDetail["GoodsCode"] = drFor["GoodsCode"]; drDetail["GoodsName"] = drFor["GoodsName"]; drDetail["ComplianceRate"] = 0; drDetail["IncrementSeed"] = 0; drDetail["IncrementAmount"] = 0; this._dsSourse.Tables[Constant.INT_IS_ONE].Rows.Add(drDetail); } } this.dgvGoods.IsSetInputColumnsColor = true; } else { //提示用户先选中一行工种信息 MessageBox.Show(Messages.MSG_TAT_W001, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 工种列表值变更 /// /// /// private void dgvJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { //变更后重新加载 if (this.dgvJobs.Rows.Count <= 1 || !this._showFlag) { return; } DataGridViewRow rowItem = this.dgvJobs.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex]; //打开多选页面进行值绑定 this._showFlag = false; FormUtility.BindJobsRowDataSource(this.dgvJobs, e.RowIndex, columnItem.Name, string.Empty); this._showFlag = true; //根据工种信息绑定明细信息 this.BindDetail(); // 设置可输入单元格的颜色 this.dgvJobs.IsSetInputColumnsColor = true; this.dgvGoods.IsSetInputColumnsColor = true; } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 工种删除 /// /// /// private void dgvJobs_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { try { if (e.Row.Cells["JobsId"].Value != DBNull.Value) { //获取删除的工种ID int JobsId = Convert.ToInt32(e.Row.Cells["JobsId"].Value); //将该工种对应的明细信息全部删除 this.DeleteGoods(JobsId); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 产品编号变更 /// /// /// private void dgvGoods_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (this.dgvGoods.Rows.Count <= 1) { return; } DataGridViewRow rowItem = this.dgvGoods.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvGoods.Columns[e.ColumnIndex]; // 用编号获取产品信息 if ("GoodsCode".Equals(columnItem.Name)) { FormUtility.BindGoodsRowDataSource(this.dgvGoods, e.RowIndex, columnItem.Name, string.Empty); // 设置可输入单元格的颜色 this.dgvGoods.IsSetInputColumnsColor = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 工种选择变更 /// /// /// private void dgvJobs_SelectionChanged(object sender, EventArgs e) { try { //根据选择的工种绑定对应的明细信息 if (this.dgvJobs.SelectedRows.Count != Constant.INT_IS_ZERO) { DataGridViewRow gvrNow = this.dgvJobs.SelectedRows[Constant.INT_IS_ZERO]; if (gvrNow.Cells["JobsId"].Value != DBNull.Value && gvrNow.Cells["JobsId"].Value != null) { DataTable dtDetail = this._dsSourse.Tables[Constant.INT_IS_ONE]; dtDetail.DefaultView.RowFilter = "JobsId=" + gvrNow.Cells["JobsId"].Value.ToString(); this.dgvGoods.DataSource = dtDetail; this.dgvGoods.IsSetInputColumnsColor = true; } else { this.dgvGoods.DataSource = null; } } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } #endregion #region 私有方法/函数 /// /// 绑定数据源 /// private void BindData() { try { if (this._entityId != 0 && this._entityId != null) { ServiceResultEntity srEntity = TATModuleProxy.Service.GetQualityDetailById(Convert.ToInt32(this._entityId)); if (srEntity.Data != null) { this._dsSourse = (DataSet)srEntity.Data; if (this._dsSourse.Tables.Count != Constant.INT_IS_TWO) { this.DialogResult = DialogResult.Cancel; } this.dgvJobs.DataSource = this._dsSourse.Tables[Constant.INT_IS_ZERO]; this.dgvJobs.IsSetInputColumnsColor = true; } } } catch (Exception ex) { throw ex; } } /// /// 批量生成明细信息并绑定 /// private void BindDetail() { try { //首先遍历选中的工种 foreach (DataGridViewRow gvrFor in this.dgvJobs.Rows) { //新行不进行该操作 if (gvrFor.IsNewRow) { return; } //已存在的工种不进行该操作 if (gvrFor.Cells["isHave"].Value != DBNull.Value) { continue; } //向符合条件的工种添加全部产品信息 foreach (DataRow drFor in this._dtGoodsSourse.Rows) { //向最终数据源添加扣罚明细信息 if (gvrFor.Cells["JobsId"].Value != DBNull.Value) { DataRow drDetail = this._dsSourse.Tables[Constant.INT_IS_ONE].NewRow(); drDetail["JobsId"] = gvrFor.Cells["JobsId"].Value; drDetail["GoodsID"] = drFor["GoodsId"]; drDetail["GoodsCode"] = drFor["GoodsCode"]; drDetail["GoodsName"] = drFor["GoodsName"]; drDetail["ComplianceRate"] = 0; drDetail["IncrementSeed"] = 0; drDetail["IncrementAmount"] = 0; this._dsSourse.Tables[Constant.INT_IS_ONE].Rows.Add(drDetail); } } gvrFor.Cells["isHave"].Value = 1; } } catch (Exception ex) { throw ex; } } /// /// 根据工种ID删除明细信息 /// /// private void DeleteGoods(int JobsId) { try { //遍历全部明细信息 for (int i = Constant.INT_IS_ZERO; i < this._dsSourse.Tables[Constant.INT_IS_ONE].Rows.Count; i++) { DataRow drFor = this._dsSourse.Tables[Constant.INT_IS_ONE].Rows[i]; //如果是已存在的才需要删除,新建的会直接消失 if (drFor.RowState != DataRowState.Deleted) { //如果是要删除的明细信息,进行移除并修改迭代变量 int drJobsId = Convert.ToInt32(drFor["JobsId"]); if (drJobsId == JobsId) { this._dsSourse.Tables[Constant.INT_IS_ONE].Rows.Remove(drFor); i--; } } } } catch (Exception ex) { throw ex; } } /// /// 获取全部产品信息 /// private void GetGoods() { try { GoodsEntity goods = new GoodsEntity(); goods.ValueFlag = 1; DataSet dsGoods = SystemModuleProxy.Service.SerachGoods(goods); if (dsGoods != null && dsGoods.Tables.Count != Constant.INT_IS_ZERO) { this._dtGoodsSourse = dsGoods.Tables[Constant.INT_IS_ZERO]; } } catch (Exception ex) { throw ex; } } #endregion } }