/*******************************************************************************
* Copyright(c) 2014 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PC_0402.cs
* 2.功能描述:班次配置新建\编辑
* 编辑履历:
* 作者 日期 版本 修改内容
* 冯雪 2014/09/22 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.ConfigModule;
using Dongke.IBOSS.PRD.WCF.DataModels.PCModule;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.PCModuleService;
namespace Dongke.IBOSS.PRD.Client.PCModule
{
///
/// 班次配置新建\编辑窗体
///
public partial class F_PC_0402 : FormBase
{
#region 成员变量
// 班次配置ID
private int _classesSettingID;
// 窗体状态的枚举 新建/编辑
private Constant.FormMode _editStatus;
// 选中的员工编码
private string _staffCode;
// 工号ID
private int _userId;
// 工号名称
private string _userName;
// 工号编号
private string _userCode;
// 备注
private string _remark;
//保存影响行
private int _returnRow = Constant.INT_IS_ZERO;
// 打开选择窗体的标识
private bool _showFromFlag = true;
// 当前工号的工种集合
private DataTable _userJobsTable = new DataTable();
#endregion
#region 属性
///
/// 备注
///
public string Remark
{
get { return _remark; }
set { _remark = value; }
}
///
/// 工号名称
///
public string UserName1
{
get { return _userName; }
set { _userName = value; }
}
///
/// 班次配置ID
///
public int ClassesSettingID
{
get { return _classesSettingID; }
set { _classesSettingID = value; }
}
///
/// 工号ID
///
public int UserId
{
get { return _userId; }
set { _userId = value; }
}
///
/// 工号编号
///
public string UserCode
{
get { return _userCode; }
set { _userCode = value; }
}
///
/// 编辑时账务日期
///
public DateTime? AccountDate
{
get;
set;
}
#endregion
#region 构造函数
///
/// 构造函数
///
/// 新建/编辑
/// 要编辑的员工编号
public F_PC_0402(Constant.FormMode editStatus)
{
InitializeComponent();
this._editStatus = editStatus;
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CANCEL;
if (this._editStatus == Constant.FormMode.Add)
{
this.Text = FormTitles.F_PC_0402_ADD;
}
else
{
this.Text = FormTitles.F_PC_0402_EDIT;
// wangx 2016-06-20
this.dkUserInfo.Enabled = false;
this.dtpAccountDate.Enabled = false;
this.txtRemarks.Enabled = false;
// wangx 2016-06-20 end
}
}
#endregion
#region 事件
///
/// 页面加载事件
///
///
///
private void F_PC_0402_Load(object sender, EventArgs e)
{
try
{
if (this._editStatus == Constant.FormMode.Edit)
{
this.dkUserInfo.UserID = this._userId;
this.dkUserInfo.UserName = this._userName;
this.dkUserInfo.UserCode = this._userCode;
BindUserJobs();
if (this.AccountDate.HasValue)
{
this.dtpAccountDate.Value = this.AccountDate.Value;
}
DataSet result = (DataSet)DoAsync(() =>
{
return PCModuleProxy.Service.SearchClassesDetail(this._classesSettingID);
});
this.dgvClassesDetail.AutoGenerateColumns = false;
this.dgvClassesDetail.IsSetInputColumnsColor = true;
// 绑定明细数据
this.dgvClassesDetail.DataSource = result.Tables[0];
// 允许编辑行
this.dgvClassesDetail.AllowUserToAddRows = true;
this.dgvClassesDetail.IsSetInputColumnsColor = true;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 自动适应列宽
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvClassesDetail.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
///
/// 关闭按钮事件
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 工号ValueChanged事件
///
///
///
private void dkUserInfo_UserValueChanged(object sender, Controls.SearchTextBox.dkUserInfoSearchBox.TextChangeEventArgs e)
{
try
{
int userId = this.dkUserInfo.UserID.Value;
BindUserJobs();
DataSet result = (DataSet)DoAsync(() =>
{
return HRModuleProxy.Service.SearchHrStaffInfo(userId);
});
this.dgvClassesDetail.AutoGenerateColumns = false;
// 绑定明细数据
this.dgvClassesDetail.DataSource = result.Tables[0];
// 允许编辑行
this.dgvClassesDetail.AllowUserToAddRows = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 员工编号值改变事件
///
///
///
private void dgvClassesDetail_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvClassesDetail.Rows.Count <= Constant.INT_IS_ONE || !_showFromFlag)
{
return;
}
DataGridViewRow rowItem = this.dgvClassesDetail.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvClassesDetail.Columns[e.ColumnIndex];
// 用编号获取员工信息
if ("StaffCode".Equals(columnItem.Name)
&& !string.IsNullOrEmpty(this.dgvClassesDetail.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""))
{
this._showFromFlag = false;
FormUtility.BindStaffRowDataSource(this.dgvClassesDetail,
e.RowIndex, columnItem.Name, this._staffCode, this.dkUserInfo.UserID.Value, true);
this._showFromFlag = true;
// 设置可输入单元格的颜色
this.dgvClassesDetail.IsSetInputColumnsColor = true;
// 不可出现重复的人员
//for (int i = 0; i < this.dgvClassesDetail.Rows.Count; i++)
//{
// if (i != e.RowIndex)
// {
// if (this.dgvClassesDetail.Rows[i].IsNewRow == true)
// {
// return;
// }
// String NowStaffID = this.dgvClassesDetail.Rows[e.RowIndex].Cells["StaffID"].Value.ToString();
// if (NowStaffID == string.Empty)
// {
// this.dgvClassesDetail.Rows.RemoveAt(e.RowIndex);
// return;
// }
// String ForStaffID = "";
// if (this.dgvClassesDetail.Rows[i].Cells["StaffID"].Value != null)
// {
// ForStaffID = this.dgvClassesDetail.Rows[i].Cells["StaffID"].Value.ToString();
// }
// if (NowStaffID == ForStaffID)
// {
// ((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex].Delete();
// //仅限当前页面,工号间的待修改
// MessageBox.Show("员工信息不可重复配置!", this.Text,
// MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
// }
// }
//}
}
if (columnItem.Name == "UJobsId")
{
string JobsId = this.dgvClassesDetail.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (JobsId == string.Empty)
{
if (((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex]["UJobsId", DataRowVersion.Original] != null)
{
string OValue = ((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex]["UJobsId", DataRowVersion.Original].ToString();
((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex]["UJobsId"] = OValue;
}
else
{
((DataTable)this.dgvClassesDetail.DataSource).Rows[e.RowIndex].Delete();
}
}
}
}
catch (Exception ex)
{
this._showFromFlag = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 单元格编辑时
///
///
///
private void dgvClassesDetail_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
try
{
if (this.dgvClassesDetail.Rows.Count <= Constant.INT_IS_ONE)
{
return;
}
DataGridViewColumn columnItem = this.dgvClassesDetail.Columns[e.ColumnIndex];
if ("StaffCode".Equals(columnItem.Name))
{
this._staffCode = this.dgvClassesDetail.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存按钮事件
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
// 至少有一条明细信息
if (isWhiteTable() == true)
{
MessageBox.Show("至少要有一条班次配置明细信息!",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
return;
}
// 验证界面必录项的录入;
if (!this.CheckInputValidity())
{
return;
}
// 不可更改帐务日期之前的班次配置
DateTime accountDate = CommonModuleProxy.Service.GetAccountDate();
if (Convert.ToDateTime(this.dtpAccountDate.Text) < accountDate)
{
SearchClassesSettingEntity scsEntity = new SearchClassesSettingEntity();
scsEntity.UserCode = this.dkUserInfo.UserCode;
scsEntity.UserID = this.dkUserInfo.UserID;
scsEntity.StartAccountDate = Convert.ToDateTime(Convert.ToDateTime(this.dtpAccountDate.Text).ToString("yyyy-MM-dd"));
scsEntity.EndAccountDate = Convert.ToDateTime(scsEntity.StartAccountDate).AddHours(23)
.AddMinutes(59).AddSeconds(59);
//查询
DataSet dsResult = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return WCF.Proxys.PCModuleProxy.Service.SearchClassesSetting(scsEntity);
}));
if (dsResult.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
MessageBox.Show("选择日期已存在班次配置,不可再次补录!",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
return;
}
}
// 保存
ClassesSettingEntity setEntity = new ClassesSettingEntity();
setEntity.UserID = this.dkUserInfo.UserID.Value;
setEntity.UserCode = this.dkUserInfo.UserCode;
setEntity.UserName = this.dkUserInfo.UserName;
setEntity.AccountDate = Convert.ToDateTime(this.dtpAccountDate.Text);
setEntity.ClassesSettingID = this._classesSettingID;
DataTable dTable = (DataTable)this.dgvClassesDetail.DataSource;
dTable.AcceptChanges();
// 修改table中的工号为当前配置的工号
foreach (DataRow row in dTable.Rows)
{
row["UserID"] = this.dkUserInfo.UserID.Value;
row["UserCode"] = this.dkUserInfo.UserCode;
if (row["UJobsId"].ToString() == string.Empty && row["StaffCode"].ToString() == string.Empty)
{
continue;
}
if (row["UJobsId"].ToString() == string.Empty)
{
MessageBox.Show("请为所有员工配置工种!",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
return;
}
if (row["StaffCode"].ToString() == "")
{
MessageBox.Show("请为已选择工种配置员工!",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
return;
}
}
this._returnRow = (int)DoAsync(new BaseAsyncMethod(() =>
{
return PCModuleProxy.Service.SaveClassesSetting(setEntity, dTable);
}));
if (this._returnRow > Constant.INT_IS_ZERO)
{
// 保存成功提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "班次配置", "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.InitializationForm();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 取消按钮
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
if (this._returnRow > Constant.INT_IS_ZERO)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
}
#endregion
#region 私有方法
///
/// 验证输入格式是否正确
///
///
private bool CheckInputValidity()
{
// 验证员工信息是否录入;
if (string.IsNullOrEmpty(this.dkUserInfo.Text.Trim()))
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工号"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
this.dkUserInfo.Focus();
return false;
}
if (this.dgvClassesDetail.RowCount <= Constant.INT_IS_ONE)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "员工信息"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
this.dgvClassesDetail.Focus();
return false;
}
return true;
}
///
/// 清空输入项
///
private void InitializationForm()
{
if (this._editStatus == Constant.FormMode.Add)
{
this.dkUserInfo.Text = "";
this.txtRemarks.Clear();
this.dgvClassesDetail.DataSource = null;
}
else
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
///
/// 绑定用户工种
///
private void BindUserJobs()
{
try
{
//获取可选择的工种数据源
DataSet userJobsData = (DataSet)DoAsync(new BaseAsyncMethod(GetUserRowData));
this.UJobsId.DisplayMember = "UserJobsName";
this.UJobsId.ValueMember = "UserJobsId";
this.UJobsId.DataSource = userJobsData.Tables[0];
this._userJobsTable = userJobsData.Tables[0];
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据工号ID获取该工号的工种关联
///
///
private DataSet GetUserRowData()
{
try
{
return SystemModuleProxy.Service.GetJobByUserId(Convert.ToInt32(this.dkUserInfo.UserID));
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 是否空表
///
///
private bool isWhiteTable()
{
foreach (DataGridViewRow gvrFor in this.dgvClassesDetail.Rows)
{
if ((gvrFor.Cells["UJobsId"].Value != null && gvrFor.Cells["UJobsId"].Value.ToString() != "")
|| (gvrFor.Cells["StaffCode"].Value != null && gvrFor.Cells["StaffCode"].Value.ToString() != ""))
{
return false;
}
}
return true;
}
#endregion
}
}