/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0210.cs
* 2.功能描述:员工关联
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2014/09/12 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
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.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 员工关联
///
public partial class F_MST_0210 : DockPanelBase
{
#region 成员变量
// 单例模式
private static F_MST_0210 _instance;
// 最后选择行
private int _selecedRow;
// 用户管理实体类
private SUserEntity _userInfo;
#endregion
#region 构造函数
public F_MST_0210()
{
InitializeComponent();
this.Text = FormTitles.F_MST_0210;
this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
this.btnSearch.Text = ButtonText.BTN_SEARCH;
this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
}
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_MST_0210 Instance
{
get
{
if (_instance == null)
{
_instance = new F_MST_0210();
}
return _instance;
}
}
#endregion
#region 事件
///
/// 搜索按钮事件
///
///
///
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
// 根据页面设定用户实体值
this.GetUserEntityFromLayout();
// 记录当前选中行
int selectRowIndex = this._selecedRow;
// 异步处理
this.btnSearch.Enabled = false;
this.btnClearCondition.Enabled = false;
DataSet userDataSet = (DataSet)DoAsync(new AsyncMethod(this.SearchUserData));
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
this.scbOrganization.EditReadOnly = true;
if (userDataSet != null)
{
base.DataSource = (DataSet)userDataSet;
if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
{
this.dgvUser.DataSource = this.DataSource.Tables[0];
if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
{
dgvStaff.DataSource = null;
// 提示未查找到数据
MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (selectRowIndex >= Constant.INT_IS_ZERO)
{
if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
{
this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Selected = true;
this.dgvUser.CurrentCell = this.dgvUser.Rows[this.dgvUser.Rows.Count - 1].Cells["UserCode"];
}
else
{
this.dgvUser.Rows[selectRowIndex].Selected = true;
this.dgvUser.CurrentCell = this.dgvUser.Rows[selectRowIndex].Cells["UserCode"];
}
}
}
}
}
}
catch (Exception ex)
{
this.btnSearch.Enabled = true;
this.btnClearCondition.Enabled = true;
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 清空按钮事件
///
///
///
private void btnClearCondition_Click(object sender, EventArgs e)
{
this.txtUserCode.Clear();
this.txtUserName.Clear();
this.txtRemarks.Clear();
this.scbOrganization.ClearValue();
this.chkIsWorker.Checked = false;
}
///
/// 单元格鼠标事件
///
///
///
private void dgvUser_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex != -1)
{
int UserId = Convert.ToInt32(this.dgvUser.Rows[e.RowIndex].Cells["UserID"].Value.ToString());
DataSet dsStaff = SystemModuleProxy.Service.GetUserStaffByUserId(UserId);
this.dgvStaff.AutoGenerateColumns = false;
this.dgvStaff.DataSource = dsStaff.Tables[0];
}
}
///
/// 选定项改变事件
///
///
///
private void dgvUser_SelectionChanged(object sender, EventArgs e)
{
try
{
if (dgvUser.CurrentCell != null)
{
int UserId = Convert.ToInt32(this.dgvUser.Rows[dgvUser.CurrentCell.RowIndex].Cells["UserID"].Value.ToString());
DataSet dsStaff = SystemModuleProxy.Service.GetUserStaffByUserId(UserId);
this.dgvStaff.AutoGenerateColumns = false;
this.dgvStaff.DataSource = dsStaff.Tables[0];
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 新增按钮事件
///
///
///
private void tsbtnAddUser_Click(object sender, EventArgs e)
{
try
{
F_MST_0211 frmFMST0211 = new F_MST_0211(null, null);
DialogResult dialogresult = frmFMST0211.ShowDialog();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 单元格双击事件
///
///
///
private void dgvUser_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
if (e.RowIndex != -Constant.INT_IS_ONE)
{
string userId = this.dgvUser.Rows[e.RowIndex].Cells["userId"].Value.ToString();
string userCode = this.dgvUser.Rows[e.RowIndex].Cells["userCode"].Value.ToString();
F_MST_0211 frmFMST0207 = new F_MST_0211(Convert.ToInt32(userId), userCode);
DialogResult dialogresult = frmFMST0207.ShowDialog();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 编辑按钮事件
///
///
///
private void tsbtnEditUser_Click(object sender, EventArgs e)
{
try
{
if (this.dgvUser.SelectedRows.Count != 0)
{
string userId = this.dgvUser.SelectedRows[0].Cells["userId"].Value.ToString();
string userCode = this.dgvUser.SelectedRows[0].Cells["userCode"].Value.ToString();
F_MST_0211 frmFMST0211 = new F_MST_0211(Convert.ToInt32(userId), userCode);
DialogResult dialogresult = frmFMST0211.ShowDialog();
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 窗体加载事件
///
///
///
private void F_MST_0210_Load(object sender, EventArgs e)
{
// 加载权限
FormPermissionManager.FormPermissionControl(this.Name, this,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
}
///
/// 自适应列宽
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvUser.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
///
/// 关闭按钮事件
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 释放窗体
///
///
///
private void F_MST_0210_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
#endregion
#region 私有方法
///
/// 获取输入的用户信息
///
///
private SUserEntity GetUserEntityFromLayout()
{
this._userInfo = new SUserEntity();
// 用户编码
this._userInfo.UserCode = this.txtUserCode.Text.Trim();
// 用户姓名
this._userInfo.UserName = this.txtUserName.Text.Trim();
// 所属部门
this._userInfo.OrganizationCode = scbOrganization.SearchedValue + "";
// 所属部门
this._userInfo.OrganizationID = scbOrganization.SearchedPKMember;
// 备注
this._userInfo.Remarks = this.txtRemarks.Text.Trim();
if (this.chkIsWorker.Checked == true)
{
_userInfo.IsWorker = 1;
}
else
{
_userInfo.IsWorker = 0;
}
return _userInfo;
}
///
/// 获取用户列表
///
///
private DataSet SearchUserData()
{
try
{
return SystemModuleProxy.Service.SearchUserData(this._userInfo);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}