/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_TAT_0301.cs
* 2.功能描述:基本工资策略明细
* 编辑履历:
* 作者 日期 版本 修改内容
* 任海 2014/12/12 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
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.Client.Controls;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
using Dongke.IBOSS.PRD.WCF.Proxys.TATModuleService;
using Dongke.IBOSS.PRD.WCF.DataModels;
namespace Dongke.IBOSS.PRD.Client.TATModule
{
///
/// 基本工资策略明细
///
public partial class F_TAT_0302 : FormBase
{
#region 成员变量
// 窗体模式ID
private Constant.FormMode _formType;
// 操作实体ID
private int? _entityId;
// 操作实体名称
private string _entityname;
// 操作实体
private BasicSalaryEntity _basicSalaryEntity = new BasicSalaryEntity();
// 选择窗体弹出标识
private bool _showFlag = true;
// 数据源
private DataSet _dsSourse;
// 窗体加载完毕标识
private bool _pageLoadOK = false;
#endregion
#region 构造函数
///
/// 窗体构造
///
/// 窗体开启模式
/// 操作实体ID
public F_TAT_0302(Constant.FormMode formType, int entityId, string entityname)
{
InitializeComponent();
this._formType = formType;
this._entityId = entityId;
this._entityname = entityname;
}
#endregion
#region 事件处理
///
/// 窗体加载
///
///
///
private void F_TAT_0302_Load(object sender, EventArgs e)
{
try
{
this.lblBasicSalaryDetail.Text = "当前选择的策略名称:" + _entityname;
this.dgvBasicSalaryDetail.AutoGenerateColumns = false;
//绑定工种信息
this.BindJobs();
this.dgvBasicSalaryDetail.IsSetInputColumnsColor = true;
//页面加载完毕
this._pageLoadOK = true;
//如果是审核及观看模式
if (this._formType == Constant.FormMode.Display)
{
//列表设置为只读
this.dgvBasicSalaryDetail.ReadOnly = true;
this.dgvBasicSalaryDetail.IsSetInputColumnsColor = false;
this.dgvBasicSalaryDetail.AllowUserToDeleteRows = false;
//控件除关闭外全部不可用
this.btnSave.Enabled = false;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 提交操作
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
int results = Conservation();
if (results == Constant.INT_IS_ONE)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工种编码"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.btnSave.Enabled = false;
return;
}
if (results == Constant.INT_IS_TWO)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "基本工资"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.btnSave.Enabled = false;
return;
}
if (results == Constant.INT_IS_THREE)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "补贴"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.btnSave.Enabled = false;
return;
}
if (results == Constant.INT_IS_FOUR)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "保底工资"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.btnSave.Enabled = false;
return;
}
//提交操作
ServiceResultEntity srEntity =
(ServiceResultEntity)DoAsync(() =>
{
return TATModuleProxy.Service.EditBasicSalaryDetail(Convert.ToInt32(this._entityId), _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 dgvBasicSalaryDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
//变更后重新加载
this._pageLoadOK = false;
if (this.dgvBasicSalaryDetail.Rows.Count <= 1 || !this._showFlag)
{
return;
}
DataGridViewRow rowItem = this.dgvBasicSalaryDetail.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvBasicSalaryDetail.Columns[e.ColumnIndex];
if (columnItem.Name == "JobsCode")
{
//打开多选页面进行值绑定
this._showFlag = false;
FormUtility.BindJobsRowDataSource(this.dgvBasicSalaryDetail,
e.RowIndex, columnItem.Name, string.Empty);
this._showFlag = true;
}
//加载OK
this._pageLoadOK = true;
// 设置可输入单元格的颜色
this.dgvBasicSalaryDetail.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 行校验
///
///
///
private void dgvBasicSalaryDetail_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
// 按Esc键时不校验
if (!dgvBasicSalaryDetail.IsCurrentRowDirty)
{
this.dgvBasicSalaryDetail.IsSetInputColumnsColor = true;
return;
}
if (this.ActiveControl != null && "btnClose".Equals(this.ActiveControl.Name))
{
// 清除单元格的错误消息
this.dgvBasicSalaryDetail.CurrentRow.ErrorText = string.Empty;
return;
}
DataGridViewRow row = dgvBasicSalaryDetail.CurrentRow;
if (!row.IsNewRow)
{
// 判断工种编码能为空
if (row.Cells["JobsCode"].Value == null
|| string.IsNullOrEmpty(row.Cells["JobsCode"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvBasicSalaryDetail.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "工种编码");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 判断基本工资不能为空
if (row.Cells["BasicSalary"].Value == null
|| string.IsNullOrEmpty(row.Cells["BasicSalary"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvBasicSalaryDetail.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "基本工资");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 判断补贴不能为空
if (row.Cells["Subsidy"].Value == null
|| string.IsNullOrEmpty(row.Cells["Subsidy"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvBasicSalaryDetail.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "补贴");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 判断保底工资不能为空
if (row.Cells["MinimumSalary"].Value == null
|| string.IsNullOrEmpty(row.Cells["MinimumSalary"].Value + string.Empty))
{
// 单元格的错误消息
this.dgvBasicSalaryDetail.CurrentRow.ErrorText = string.Format(Messages.MSG_CMN_W005, "保底工资");
e.Cancel = true;
this.btnSave.Enabled = false;
return;
}
// 清除单元格的错误消息
this.dgvBasicSalaryDetail.CurrentRow.ErrorText = string.Empty;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 根据数据是否变化,设置保存按钮的可用状态
///
///
///
private void dgvBasicSalaryDetail_RowValidated(object sender, DataGridViewCellEventArgs e)
{
try
{
this.SetSaveBtnStatus();
}
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();
}
#endregion
#region 私有方法/函数
///
/// 绑定对应工种明细
///
private void BindJobs()
{
try
{
//获取对应工种明细
ServiceResultEntity srEntityDetail
= TATModuleProxy.Service.GetBasicSalaryDetailById(Convert.ToInt32(this._entityId));
if (srEntityDetail.Data != null && srEntityDetail.Data.Tables.Count != 0)
{
this._dsSourse = srEntityDetail.Data;
this.dgvBasicSalaryDetail.DataSource = srEntityDetail.Data.Tables[0];
this.dgvBasicSalaryDetail.IsSetInputColumnsColor = true;
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 保存时单元格必输项不能为空
///
private int Conservation()
{
int isConservation = Constant.INT_IS_ZERO;
DataTable datatBasicSalaryDetail = (DataTable)this.dgvBasicSalaryDetail.DataSource;
foreach (DataRow drproductionData in datatBasicSalaryDetail.Rows)
{
if (drproductionData.RowState == DataRowState.Added || drproductionData.RowState == DataRowState.Modified)
{
if (drproductionData["JobsCode"].ToString() == "")
{
isConservation = Constant.INT_IS_ONE;
break;
}
if (drproductionData["BasicSalary"].ToString() == "")
{
isConservation = Constant.INT_IS_TWO;
break;
}
if (drproductionData["Subsidy"].ToString() == "")
{
isConservation = Constant.INT_IS_THREE;
break;
}
if (drproductionData["MinimumSalary"].ToString() == "")
{
isConservation = Constant.INT_IS_FOUR;
break;
}
}
}
return isConservation;
}
///
/// 设置保存按钮的可用状态
///
private void SetSaveBtnStatus()
{
if (DataJudge.IsChange((DataTable)this.dgvBasicSalaryDetail.DataSource))
{
this.btnSave.Enabled = true;
}
else
{
this.btnSave.Enabled = false;
}
}
#endregion
}
}