| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_PAM_0103.cs
- * 2.功能描述:新建/编辑工种工资方案
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2015/08/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.Basics.DockPanel;
- 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;
- namespace Dongke.IBOSS.PRD.Client.PAMModule
- {
- public partial class F_PAM_0103 : FormBase
- {
- #region 成员变量
- // 窗体模式ID
- private Constant.FormMode _formType;
- // 操作实体ID(方案)
- private int? _entityId;
- // 操作实体信
- private RptProcedureEntity _rptProcedureEntity = new RptProcedureEntity();
- // 工序数据源
- private DataTable _dtProcedure = new DataTable();
- // 工序
- private DataSet _dsProcedure = new DataSet();
- //记录数据来源Code
- private string _rptProcedureCode = string.Empty;
- // 工种编码值
- private string _JobsCodeValue;
- private bool _ShowFlag = true;
- // 数据源
- DataTable dt = null;
- // 当前工资方案ID
- private int? _currentPayPlanID = null;
- // 数据集
- DataTable dtAllData = null;
- #endregion
- #region 构造函数
- /// <summary>
- /// 窗体构造
- /// </summary>
- /// <param name="formType">窗体打开模式</param>
- /// <param name="entityId">操作实体ID</param>
- public F_PAM_0103(Constant.FormMode formType, int entityId)
- {
- InitializeComponent();
- this._formType = formType;
- this._entityId = entityId;
- // 窗体显示的Title
- if (this._formType == Constant.FormMode.Add)
- {
- this.Text = FormTitles.F_PAM_0103_ADD;
- }
- else if (this._formType == Constant.FormMode.Edit)
- {
- this.Text = FormTitles.F_PAM_0103_EDIT;
- }
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- }
- #endregion
- #region 事件处理
- /// <summary>
- /// 窗体加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0702_Load(object sender, EventArgs e)
- {
- try
- {
- this.dgvPayPlan.AutoGenerateColumns = false;
- this.dgvJobs.AutoGenerateColumns = false;
- //如果是修改,要绑定选中的信息
- if (this._formType == Constant.FormMode.Edit)
- {
- BindJobsData();//编辑工种数据源
- BindData();//绑定工资工种数据源
- }
- //如果是新建,选项默认值设定
- else if (this._formType == Constant.FormMode.Add)
- {
- //绑定全部的工资工种列表,用于过滤筛选
- DataSet dsProductionData = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PAMModuleProxy.Service.GetJobsPayPlan("", "");
- }));
- BindData();//绑定工资方案数据源
- if (dsProductionData != null && dsProductionData.Tables[0].Rows.Count > 0)
- {
- this.dgvJobs.DataSource = dsProductionData.Tables[0];//新建时默认数据源
- }
- else
- {
- dt = new DataTable();
- dt.Columns.Add("JobsID");
- dt.Columns.Add("JobsCode");
- dt.Columns.Add("JobsName");
- dt.Columns.Add("PayPlanID");
- this.dgvJobs.DataSource = dt;//新建时默认数据源
- }
- dtAllData = this.dgvJobs.DataSource as DataTable;
- }
- if (dgvPayPlan.RowCount > 0)
- {
- dgvJobs.AllowUserToAddRows = 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 F_MST_0702_FormClosed(object sender, FormClosedEventArgs e)
- {
- this.Dispose();
- }
- /// <summary>
- /// 数据来源工序变更
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvRptSProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- }
- 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 dgvRptTProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- if (this.dgvJobs.Rows.Count <= 1 || !_ShowFlag)
- {
- return;
- }
- DataGridViewRow rowItem = this.dgvJobs.Rows[e.RowIndex];
- DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex];
- if ("JobsCode".Equals(columnItem.Name))
- {
- _ShowFlag = false; //BindJobsRowDataSource
- string JobsID = "";
- if (this.dgvJobs.Rows[e.RowIndex].Cells["JobsID"].Value != null)
- {
- JobsID = this.dgvJobs.Rows[e.RowIndex].Cells["JobsID"].Value.ToString();
- }
- DataTable dtDataSource = FormUtility.BindJobsRowDataSource(this.dgvJobs,
- e.RowIndex, columnItem.Name, _JobsCodeValue);
- int row = e.RowIndex;
- // 返回多少行,进而给每个单元格传值,为的以后多个工资方案进行筛选
- if (dtDataSource != null && dtDataSource.Rows.Count > 0)
- {
- for (int i = 0; i < dtDataSource.Rows.Count; i++)
- {
- //如果存在数据集中,此列标记删除
- this.dgvJobs.Rows[row].Cells["PayPlanID1"].Value = this._currentPayPlanID;
- if (dtAllData != null && JobsID != "")
- {
- DataRow[] drSel = dtAllData.Select(string.Format("PayPlanID={0} and JobsID={1}", this._currentPayPlanID, JobsID));
- if (drSel.Length > 0) //存在,需要更把此行删除
- {
- drSel[0].Delete();
- }
- }
- if (JobsID == "") //新增的时候,是否存在相同的工种编码
- {
- //DataRow[] drSel = dtAllData.Select(string.Format("PayPlanID={0} and JobsCode='{1}'", this._currentPayPlanID, dtDataSource.Rows[i]["JobsCode"]));
- //if (drSel.Length == 0) //不存在,把此行添加进来
- //{
- DataRow dr = this.dtAllData.NewRow();
- dr["JobsID"] = dtDataSource.Rows[i]["JobsID"];
- dr["JobsCode"] = dtDataSource.Rows[i]["JobsCode"];
- dr["JobsName"] = dtDataSource.Rows[i]["JobsName"];
- dr["PayPlanID"] = this._currentPayPlanID;
- dtAllData.Rows.Add(dr);
- row++;
- // }
- }
- else
- {
- DataRow dr = this.dtAllData.NewRow();
- dr["JobsID"] = dtDataSource.Rows[i]["JobsID"];
- dr["JobsCode"] = dtDataSource.Rows[i]["JobsCode"];
- dr["JobsName"] = dtDataSource.Rows[i]["JobsName"];
- dr["PayPlanID"] = this._currentPayPlanID;
- dtAllData.Rows.Add(dr);
- row++;
- }
- }
- this.dgvJobs.Rows[e.RowIndex].Selected = true;
- }
- // 设置可输入单元格的颜色
- this.dgvJobs.IsSetInputColumnsColor = true;
- }
- _ShowFlag = true;
- }
- catch (Exception ex)
- {
- _ShowFlag = true;
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 为实体绑定页面属性
- /// </summary>
- private bool BindEntity()
- {
- return false;
- }
- /// <summary>
- /// 绑定需要操作的实体信息
- /// </summary>
- private void BindPage()
- {
- try
- {
- DataTable dt_DataSource = new DataTable();
- dt_DataSource.Columns.Add("ProcedureID", typeof(int));
- dt_DataSource.Columns.Add("ProcedureCode", typeof(string));
- dt_DataSource.Columns.Add("ProcedureName", typeof(string));
- this.dgvPayPlan.DataSource = dt_DataSource;
- this.dgvJobs.DataSource = dt_DataSource.Copy();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 绑定工资方案数据源
- /// </summary>
- private void BindData()
- {
- try
- {
- DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PAMModuleProxy.Service.GetPayPlan();
- }));
- if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
- {
- if (this._formType == Constant.FormMode.Edit)
- {
- DataRow[] dr = dsResultAccount.Tables[0].Select("PayPlanID=" + this._entityId);
- if (dr.Length > 0)
- {
- this.dgvPayPlan.DataSource = dr.CopyToDataTable();
- }
- }
- else
- {
- this.dgvPayPlan.DataSource = dsResultAccount.Tables[0];
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 绑定工种工资方案数据源
- /// </summary>
- private void BindJobsData()
- {
- try
- {
- DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PAMModuleProxy.Service.GetJobsPayPlanInfo(Convert.ToInt32(this._entityId));
- }));
- if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
- {
- this.dgvJobs.DataSource = dsResultAccount.Tables[0];
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 与服务交互操作
- /// </summary>
- /// <returns></returns>
- private int EntityToServer()
- {
- int resultCount = Constant.INT_IS_ZERO;
- if (this._formType == Constant.FormMode.Add)
- {
- this._dsProcedure.Tables.Add(this.dgvPayPlan.GetDataTable());
- this._dsProcedure.Tables.Add(this.dgvJobs.GetDataTable());
- resultCount = (int)DoAsync(() =>
- {
- return SystemModuleProxy.Service.AddRptProcedure(this._rptProcedureEntity, this._dsProcedure);
- });
- }
- else if (this._formType == Constant.FormMode.Edit)
- {
- resultCount = (int)DoAsync(() =>
- {
- return SystemModuleProxy.Service.UpdateRptProcedure(this._rptProcedureEntity, this._dsProcedure);
- });
- }
- return resultCount;
- }
- #endregion
- private void dgvJobs_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- if (this.dgvJobs.Rows.Count <= 1)
- {
- return;
- }
- DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex];
- if ("JobsCode".Equals(columnItem.Name))
- {
- _JobsCodeValue = this.dgvJobs.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
- }
- }
- 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 dgvPayPlan_SelectionChanged(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvPayPlan.CurrentCell != null)
- {
- this._currentPayPlanID = Convert.ToInt32(this.dgvPayPlan.Rows[this.dgvPayPlan.CurrentCell.RowIndex].Cells["PayPlanID"].Value);
- //DataTable dtJobs = this.dgvJobs.DataSource as DataTable;
- //if (dtJobs != null && dtJobs.Rows.Count > 0)
- //{
- // DataRow[] dr = dtJobs.Select("PayPlanID=" + this._currentPayPlanID);
- // if (dr.Length > 0)
- // {
- // this.dgvJobs.DataSource = dr.CopyToDataTable();
- // }
- //}
- DataTable dtJobs = this.dtAllData;
- if (dtJobs != null)
- {
- DataView dv = dtJobs.DefaultView;
- dv.RowFilter = "PayPlanID=" + this._currentPayPlanID;
- this.dgvJobs.DataSource = dv.ToTable();
- }
- }
- }
- 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 btnSave_Click_1(object sender, EventArgs e)
- {
- try
- {
- DataTable dt = this.dtAllData;// this.dgvJobs.DataSource as DataTable;
- if (dt == null)
- {
- return;
- }
- dt.TableName = "Table1";
- int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
- {
- return PAMModuleProxy.Service.SaveJobsPayPlan(Convert.ToBoolean(this._entityId), dt);
- }));
- if (returnValue >= 0) //等于O,表示未修改数据,影响行为0
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- }
- else if (returnValue == -3)
- {
- // 提示信息
- MessageBox.Show("工种编码不能重复",
- 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
- {
- if (e.Row.Index != -1)
- {
- //ProductionDataID
- if (this.dgvJobs.CurrentCell != null)
- {
- string JobsID = this.dgvJobs.Rows[e.Row.Index].Cells["JobsID"].Value.ToString();
- DataRow[] drSel = dtAllData.Select(string.Format("PayPlanID={0} and JobsID={1}", this._currentPayPlanID, JobsID));
- if (drSel.Length > 0) //存在,需要更把此行删除
- {
- drSel[0].Delete();
- }
- }
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- }
- }
|