| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_TAT_0102.cs
- * 2.功能描述:缺陷扣罚策略明细
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 庄天威 2014/11/18 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
- {
- /// <summary>
- /// 缺陷扣罚策略明细
- /// </summary>
- public partial class F_TAT_0102 : 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 构造函数
- /// <summary>
- /// 窗体构造
- /// </summary>
- /// <param name="formType">窗体开启模式</param>
- /// <param name="entityId">操作实体ID</param>
- public F_TAT_0102(Constant.FormMode formType, int entityId)
- {
- InitializeComponent();
- this._formType = formType;
- this._entityId = entityId;
- this.Text = FormTitles.F_TAT_0102;
- this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
- this.tsbtnCreateJobs.Text = ButtonText.TSBTN_CREATEJOBS;
- this.tsbtnCreateGoods.Text = ButtonText.TSBTN_CREATEGOODS;
- this.btnEdit.Text = ButtonText.BTN_EDIT;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_TAT_0102_Load(object sender, EventArgs e)
- {
- try
- {
- //绑定产品信息
- this.GetGoods();
- //绑定数据源与列表
- this.BindData();
- this.dgvJobs.AutoGenerateColumns = false;
- this.dgvGoods.AutoGenerateColumns = false;
- //页面加载完毕
- this._pageLoadOK = true;
- //如果是审核及观看模式
- if (this._formType == Constant.FormMode.Display)
- {
- //列表设置为只读
- this.dgvGoods.ReadOnly = true;
- this.dgvJobs.ReadOnly = true;
- this.dgvGoods.AllowUserToDeleteRows = false;
- this.dgvJobs.AllowUserToDeleteRows = false;
- //控件除关闭外全部不可用
- this.tsbtnCreateGoods.Enabled = false;
- this.tsbtnCreateJobs.Enabled = false;
- this.btnEdit.Enabled = false;
- this.txtMoney.Enabled = false;
- this.btnSave.Enabled = false;
- }
- }
- 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 dgvJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- //变更后重新加载
- this._pageLoadOK = false;
- if (this.dgvJobs.Rows.Count <= Constant.INT_IS_ONE || !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();
- //加载OK
- this._pageLoadOK = true;
- // 设置可输入单元格的颜色
- this.dgvJobs.IsSetInputColumnsColor = true;
- this.dgvGoods.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 btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 保存操作
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- //提交操作
- ServiceResultEntity srEntity =
- (ServiceResultEntity)DoAsync(() =>
- {
- return TATModuleProxy.Service.EditDefectFineDetail(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);
- }
- }
- /// <summary>
- /// 创建全部工种信息,并同时创建各工种对应的明细信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnCreateJobs_Click(object sender, EventArgs e)
- {
- try
- {
- //需重新加载
- this._pageLoadOK = false;
- //这句话,因为新建的时候,莫名其妙会多出一个数据源不存在的空行,这样设定就不会出现了。
- this.dgvJobs.AllowUserToAddRows = false;
- //获取全部工种
- DataSet dsJobs = (DataSet)DoAsync(() =>
- {
- return SystemModuleProxy.Service.GetJobsData(1);
- });
- //如果获取到了工种
- if (dsJobs != null && dsJobs.Tables.Count != Constant.INT_IS_ZERO)
- {
- //循环生成工种信息并加入到数据源中
- foreach (DataRow drFor in dsJobs.Tables[0].Rows)
- {
- //首先查看该工种在现有数据源中是否存在
- int JobIsHave = 0;
- foreach (DataRow drSourse in this._dsSourse.Tables[0].Rows)
- {
- if (drSourse.RowState == DataRowState.Deleted)
- {
- continue;
- }
- int drForJobsId = Convert.ToInt32(drFor["JobsId"]);
- int drSourseJobsId = Convert.ToInt32(drSourse["JobsId"]);
- if (drForJobsId == drSourseJobsId)
- {
- JobIsHave++;
- break;
- }
- }
- //如果不存在才重新生成
- if (JobIsHave == 0 && drFor["JobsId"] != DBNull.Value)
- {
- DataRow drJobs = _dsSourse.Tables[0].NewRow();
- drJobs["JobsId"] = drFor["JobsId"];
- drJobs["JobsCode"] = drFor["JobsCode"];
- drJobs["JobsName"] = drFor["JobsName"];
- this._dsSourse.Tables[0].Rows.Add(drJobs);
- }
- }
- //绑定
- this.dgvJobs.AutoGenerateColumns = false;
- this.dgvJobs.DataSource = this._dsSourse.Tables[0];
- //并根据工种生成明细
- 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);
- }
- }
- /// <summary>
- /// 为某工种添加明细信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnCreateGoods_Click(object sender, EventArgs e)
- {
- try
- {
- //如果选择了一个有效工种
- if (this.dgvJobs.SelectedRows.Count != Constant.INT_IS_ZERO && this.dgvJobs.SelectedRows[0].IsNewRow == false)
- {
- //获取工种ID
- DataGridViewRow gvrSelected = this.dgvJobs.SelectedRows[0];
- int JobsId = Convert.ToInt32(gvrSelected.Cells["JobsId"].Value);
- //遍历产品明细添加该工种的所有明细信息
- foreach (DataRow drFor in this._dtGoodsSourse.Rows)
- {
- //首先查看该产品是否已存在
- int GoodsIsHave = 0;
- foreach (DataGridViewRow gvrFor in this.dgvGoods.Rows)
- {
- if (Convert.ToInt32(gvrFor.Cells["GoodsID"].Value)
- == Convert.ToInt32(drFor["GoodsID"]))
- {
- GoodsIsHave++;
- break;
- }
- }
- //如果不存在才进行添加
- if (GoodsIsHave == 0)
- {
- //向最终数据源添加扣罚明细信息
- DataRow drDetail = this._dsSourse.Tables[1].NewRow();
- drDetail["JobsId"] = gvrSelected.Cells["JobsId"].Value;
- drDetail["GoodsID"] = drFor["GoodsId"];
- drDetail["GoodsCode"] = drFor["GoodsCode"];
- drDetail["GoodsName"] = drFor["GoodsName"];
- drDetail["FineAmount"] = 0;
- this._dsSourse.Tables[1].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);
- }
- }
- /// <summary>
- /// 工种删除
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvJobs_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
- {
- try
- {
- //获取删除的工种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);
- }
- }
- /// <summary>
- /// 批量更新扣罚金额
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnEdit_Click(object sender, EventArgs e)
- {
- try
- {
- if (!string.IsNullOrWhiteSpace(this.txtMoney.Text))
- {
- //批量更新现工种对应的明细信息
- foreach (DataGridViewRow gvrFor in this.dgvGoods.Rows)
- {
- gvrFor.Cells["FineAmount"].Value = this.txtMoney.Text;
- }
- this.dgvGoods.Focus();
- }
- }
- 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 dgvGoods_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- if (this.dgvGoods.Rows.Count <= Constant.INT_IS_ONE)
- {
- 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);
- }
- }
- /// <summary>
- /// 工种选择变更
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvJobs_SelectionChanged(object sender, EventArgs e)
- {
- try
- {
- this.dgvGoods.AutoGenerateColumns = false;
- //根据选择的工种绑定对应的明细信息
- if (this.dgvJobs.SelectedRows.Count != Constant.INT_IS_ZERO)
- {
- DataGridViewRow gvrNow = this.dgvJobs.SelectedRows[0];
- if (gvrNow.Cells["JobsId"].Value != DBNull.Value && gvrNow.Cells["JobsId"].Value != null)
- {
- DataTable dtDetail = this._dsSourse.Tables[1];
- dtDetail.DefaultView.RowFilter = "JobsId=" + gvrNow.Cells["JobsId"].Value.ToString();
- this.dgvGoods.DataSource = dtDetail;
- if (this._formType != Constant.FormMode.Display)
- {
- this.dgvGoods.IsSetInputColumnsColor = true;
- }
- }
- else
- {
- this.dgvGoods.DataSource = null;
- }
- }
- }
- 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 tsbtnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvJobs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- this.dgvGoods.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 绑定数据源
- /// </summary>
- private void BindData()
- {
- try
- {
- if (this._entityId != 0 && this._entityId != null)
- {
- ServiceResultEntity srEntity = TATModuleProxy.Service.GetDefectFineDetailById(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[0];
- if (this._formType != Constant.FormMode.Display)
- {
- this.dgvJobs.IsSetInputColumnsColor = true;
- }
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 批量生成明细信息并绑定
- /// </summary>
- 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[1].NewRow();
- drDetail["JobsId"] = gvrFor.Cells["JobsId"].Value;
- drDetail["GoodsID"] = drFor["GoodsId"];
- drDetail["GoodsCode"] = drFor["GoodsCode"];
- drDetail["GoodsName"] = drFor["GoodsName"];
- drDetail["FineAmount"] = 0;
- this._dsSourse.Tables[1].Rows.Add(drDetail);
- }
- }
- gvrFor.Cells["isHave"].Value = 1;
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 获取全部产品信息
- /// </summary>
- 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[0];
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据工种ID删除明细信息
- /// </summary>
- /// <param name="JobsId"></param>
- private void DeleteGoods(int JobsId)
- {
- try
- {
- //遍历全部明细信息
- for (int i = 0; i < this._dsSourse.Tables[1].Rows.Count; i++)
- {
- DataRow drFor = this._dsSourse.Tables[1].Rows[i];
- //如果是已存在的才需要删除,新建的会直接消失
- if (drFor.RowState != DataRowState.Deleted)
- {
- //如果是要删除的明细信息,进行移除并修改迭代变量
- int drJobsId = Convert.ToInt32(drFor["JobsId"]);
- if (drJobsId == JobsId)
- {
- this._dsSourse.Tables[1].Rows.Remove(drFor);
- i--;
- }
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|