/*******************************************************************************
* 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 构造函数
///
/// 窗体构造
///
/// 窗体打开模式
/// 操作实体ID
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 事件处理
///
/// 窗体加载
///
///
///
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);
}
}
///
/// 窗体关闭
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 窗体释放
///
///
///
private void F_MST_0702_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
}
///
/// 数据来源工序变更
///
///
///
private void dgvRptSProcedure_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 数据统计工序变更
///
///
///
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 私有方法
///
/// 为实体绑定页面属性
///
private bool BindEntity()
{
return false;
}
///
/// 绑定需要操作的实体信息
///
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;
}
}
///
/// 绑定工资方案数据源
///
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;
}
}
///
/// 绑定工种工资方案数据源
///
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;
}
}
///
/// 与服务交互操作
///
///
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);
}
}
///
/// 选定项发生改变事件
///
///
///
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);
}
}
///
/// 保存按钮事件
///
///
///
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);
}
}
///
/// 删除行时
///
///
///
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;
}
}
}
}