/*******************************************************************************
* Copyright(c) 2014 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:TAT_CMN_001.cs
* 2.功能描述:选择员工信息
* 编辑履历:
* 作者 日期 版本 修改内容
* 冯雪 2014/09/23 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.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels.HRModule;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
{
///
/// 选择员工信息
///
public partial class TAT_CMN_001 : FormBase
{
#region 成员变量
// 画面的数据源
//private DataTable _dataSource;
// 返回用户的DataRow
private DataRow _staffRow;
// 查询条件
private int _managerSalaryID;
// 员工编号
private string _staffCode;
// 员工档案实体
private DKStaffEntity _staffEntity = new DKStaffEntity();
// 是否单选
private bool _isSelectOne = false;
#endregion
#region 构造函数
///
/// 构造函数
///
public TAT_CMN_001()
{
InitializeComponent();
// 按钮
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnOK.Text = ButtonText.BTN_OK;
this.btnClose.Text = ButtonText.BTN_CANCEL;
this.Text = FormTitles.S_CMN_010;
}
#endregion
#region 属性
///
/// 返回选择的员工行
///
public DataRow StaffRow
{
get
{
return _staffRow;
}
set
{
_staffRow = value;
}
}
///
/// 返回选择的员工档案信息
///
public DKStaffEntity StaffEntity
{
get
{
return _staffEntity;
}
set
{
_staffEntity = value;
}
}
///
/// 工号
///
public int ManagerSalaryID
{
get { return _managerSalaryID; }
set { _managerSalaryID = value; }
}
public bool IsSelectOne
{
get
{
return _isSelectOne;
}
set
{
_isSelectOne = value;
}
}
///
/// 员工编号
///
public string StaffCode1
{
get { return _staffCode; }
set { _staffCode = value; }
}
///
/// 选择的数据
///
public DataTable SelTable { get; set; }
#endregion
#region 事件
///
/// 页面加载事件
///
///
///
private void S_CMN_010_Load(object sender, EventArgs e)
{
try
{
this.dgvStaff.AutoGenerateColumns = false;
this.txtStaffCode.Text = this._staffCode;
this.Search();
if (_isSelectOne == true)
{
this.chkChooseAll.Visible = false;
this.Sel.Visible = false;
this.dgvStaff.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查询按钮按下事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
this.Search();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 确定按钮按下事件
///
///
///
private void btnOK_Click(object sender, EventArgs e)
{
try
{
if (_isSelectOne == true)
{
isSelectOneOK();
}
else
{
Commit();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 关闭按钮按下事件
///
///
///
private void btnClose_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
///
/// 选择所有事件
///
///
///
private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < this.dgvStaff.Rows.Count; i++)
{
this.dgvStaff.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
}
}
///
/// 清空按钮事件
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.txtStaffCode.Clear();
this.txtStaffName.Clear();
this.dkTargetobs.JobsID = null;
this.dkTargetobs.Text = "";
}
#endregion
#region 方法
///
/// 查询方法
///
private void Search()
{
try
{
// 清空之前的查询结果
this.dgvStaff.DataSource = null;
// 为查询实体赋值
SearchStaffEntity searchStaffEntity = new SearchStaffEntity();
searchStaffEntity.ManagerSalaryID = this.ManagerSalaryID;
searchStaffEntity.StaffCode = this.txtStaffCode.Text.Trim();
searchStaffEntity.StaffName = this.txtStaffName.Text.Trim();
searchStaffEntity.Jobs = this.dkTargetobs.JobsID;
DataSet result = (DataSet)DoAsync(() =>
{
return HRModuleProxy.Service.SearchManagersOrMembers(searchStaffEntity);
});
// 绑定明细数据
this.dgvStaff.DataSource = result.Tables[0];
this.dgvStaff.Focus();
// 当没有查询结果时,提示无查询结构消息
if (this.dgvStaff.RowCount <= Constant.INT_IS_ZERO)
{
MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtStaffCode.Focus();
this.btnOK.Enabled = false;
return;
}
this.btnOK.Enabled = true;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 提交时给取得的行赋值
///
private void Commit()
{
try
{
DataTable invDt = (DataTable)this.dgvStaff.DataSource;
if (invDt == null || invDt.Rows.Count == 0)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
invDt.AcceptChanges();
invDt = invDt.Copy();
string filter = "Sel = 1";
invDt.DefaultView.RowFilter = filter;
invDt = invDt.DefaultView.ToTable();
// 如果选中了数据就关闭窗体,反之则不关
if (invDt.Rows.Count > 0)
{
SelTable = invDt;
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
throw ex;
}
}
protected void isSelectOneOK()
{
try
{
if (this.dgvStaff.SelectedRows.Count != 0)
{
String Staffid = this.dgvStaff.SelectedRows[0].Cells["Staffid"].Value.ToString();
DataTable invDt = (DataTable)this.dgvStaff.DataSource;
if (invDt == null || invDt.Rows.Count == 0)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
invDt.AcceptChanges();
invDt = invDt.Copy();
string filter = "Staffid = " + Staffid;
invDt.DefaultView.RowFilter = filter;
invDt = invDt.DefaultView.ToTable();
// 如果选中了数据就关闭窗体,反之则不关
if (invDt.Rows.Count > 0)
{
SelTable = invDt;
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
"没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}