/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:dkUserSearchBox.cs * 2.功能描述:系统员工选择控件 * 编辑履历: * 作者 日期 版本 修改内容 * 张国印 2014/09/12 1.00 新建 *******************************************************************************/ using System; using System.ComponentModel; using System.Data; using System.Drawing; using System.Windows.Forms; using Dongke.IBOSS.PRD.Basics.BaseControls; 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 { /// /// 系统员工选择控件 /// public partial class dkStaffSearchBox : UserControl { #region 成员变量 private S_CMN_003 _frmUser; // 数据选择窗体 private bool _isEnabled = true; // 控件是否可用 private DataTable _dataSource = null; // 数据源 private int? _userID; // 组织机构ID private string _userCode; // 组织机构Code private string _userName; // 组织机构名称 private bool _isMustInput; // 控件是否是必须输入项目 private bool _IsOnlyShowValid = true; // 是否只显示有效数据 private DataRow _userRow; // 返回用户的DataRow private string _whereCondition = "StaffStatus = 2 And ValueFlag = 1"; // 查询条件 private DKStaffEntity _staffEntity = new DKStaffEntity(); // 员工档案实体 #endregion #region 构造函数 /// /// 构造函数 /// public dkStaffSearchBox() { InitializeComponent(); this.ReadOnly = true; } #endregion #region 属性 /// /// 是否只显示有效数据 /// [Description("设置控件是否只显示有效数据。")] [DefaultValue(true)] public bool IsOnlyShowValid { get { return _IsOnlyShowValid; } set { _IsOnlyShowValid = value; } } /// /// 获取或者设定控件是否是必须输入项目 /// [DefaultValue("False")] [Description("获取或者设定控件是否是必须输入项目。")] public bool IsMustInput { get { return _isMustInput; } set { _isMustInput = value; // 项目为必须输入项时,需要修改字体颜色 if (_isMustInput) { this.lblUser.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39))))); } else { this.lblUser.ForeColor = System.Drawing.SystemColors.ControlText; } } } /// /// Lable标签文本 /// [DefaultValue("员工姓名")] [Description("获取或者设定Lable标签字符。")] public string Title { get { return this.lblUser.Text; } set { this.lblUser.Text = value; AdjustControl(); } } /// /// 获取或者设定控件的数据源。 /// [Description("获取或者设定控件的数据源。")] public DataTable DataSource { get { return _dataSource; } set { DataTable dataSource = SetFilter(value); _dataSource = dataSource; } } [Description("获取或者设定控件StaffEntity。")] public DKStaffEntity StaffEntity { get { return _staffEntity; } set { _staffEntity = value; } } /// /// 获取或者设定控件的尺寸大小。 /// [Description("获取或者设定控件的尺寸大小。")] public new Size Size { get { return base.Size; } set { base.Size = value; AdjustControl(); } } /// /// 获取或者设定控件的文本框的文本字符串。 /// [Description("获取或者设定控件的文本框的文本字符串。")] public override string Text { get { return this.txtUser.Text; } set { this.txtUser.Text = value; } } /// /// 获取或者设定控件的文本框的背景颜色。 /// [Description("获取或者设定控件的文本框的背景颜色。")] public Color TxtUserBackColor { get { return this.txtUser.BackColor; } set { this.txtUser.BackColor = value; } } /// /// 获取或者设定控件的员工ID。 /// [Description("获取或者设定控件的用户ID。")] [DefaultValue(null)] public int? UserID { get { return _userID; } set { this._userID = null; this._userCode = string.Empty; this._userName = string.Empty; this.Text = string.Empty; if (value != null) { // 当数据源为null时,查询数据源 if (DataSource == null) { // 查询数据源 DataSource = GetUserInfo(); } if (value != null && value != 0 && this.DataSource != null) { DataTable userTable = this.DataSource.Copy(); DataRow[] dataRows = userTable.Select("StaffID = " + value); if (dataRows.Length == 1) { this._userID = value; this._userCode = dataRows[0]["StaffCode"] as string; this._userName = dataRows[0]["StaffName"] as string; this.Text = dataRows[0]["StaffName"] as string; } } } } } /// /// 获取或者设定控件的员工Code /// [Description("获取或者设定控件的用户Code。")] public string UserCode { get { return _userCode; } set { _userCode = value; } } /// /// 获取或者设定控件的员工名称 /// [Description("获取或者设定控件的用户名称。")] public string UserName { get { return _userName; } set { _userName = value; } } /// /// 获取或者设定控件用户信息 /// [Description("获取或者设定控件的用户信息。")] public DataRow UserRow { get { return _userRow; } set { _userRow = value; } } /// /// 获取或者设定控件是否可用。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否可用。")] public new bool Enabled { get { return _isEnabled; } set { _isEnabled = value; this.txtUser.Enabled = _isEnabled; this.TabStop = _isEnabled; } } /// /// 获取或者设定控件是否只读。 /// [System.ComponentModel.DefaultValue(null)] [Description("获取或者设定控件是否只读。")] public bool ReadOnly { set { this.txtUser.ReadOnly = value; } } /// /// 范围权限 /// public byte PurviewType { get; set; } /// /// 获取或者设定控件的员工Code /// [Description("获取或者设定控件的查询条件。")] public string WhereCondition { get { return _whereCondition; } set { _whereCondition = value; } } #endregion #region 定义委托事件 public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e); public event TextBoxChangedHandle UserValueChanged; #endregion #region 控件事件 /// /// 控件尺寸大小改变事件 /// /// /// private void dkUserSearchBox_SizeChanged(object sender, System.EventArgs e) { AdjustControl(); } /// /// 查询按钮按下事件 /// /// /// private void btnSearch_Click(object sender, System.EventArgs e) { // 如果属性是不可用,是不能进行点击事件的 if (!Enabled) { return; } // 当数据源为null时,查询数据源 if (DataSource == null) { // 查询数据源 DataSource = GetUserInfo(); } // 释放窗体资源 if (null != _frmUser) { _frmUser.Dispose(); _frmUser = null; } // 打开查询窗体 _frmUser = new S_CMN_003(this.txtUser.Text, this.WhereCondition); _frmUser.DataSource = this.DataSource; DialogResult dialogResult = _frmUser.ShowDialog(); // 查询窗体返回值给控件赋值 if (dialogResult.Equals(DialogResult.OK)) { if (_frmUser.UserRow != null) { _userRow = _frmUser.UserRow; //_userID = Convert.ToInt32(_frmUser.UserRow["StaffID"]); //_userCode = _frmUser.UserRow["StaffCode"].ToString(); //_userName = _frmUser.UserRow["StaffName"].ToString(); this._staffEntity = _frmUser.StaffEntity; _userID = _frmUser.StaffEntity.StaffID; _userCode = _frmUser.StaffEntity.StaffCode; _userName = _frmUser.StaffEntity.StaffName; this.Text = _frmUser.StaffEntity.StaffName; } } } /// /// 清除控件的值 /// /// /// private void txtUser_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete) { this.txtUser.Text = ""; this._userID = null; this._userCode = string.Empty; this._userName = string.Empty; this._userRow = null; } } /// /// 文本框文本改变事件 /// /// /// private void txtUser_TextChanged(object sender, EventArgs e) { if (UserValueChanged != null) { UserValueChanged(this, new TextChangeEventArgs(this.txtUser.Text)); } } public class TextChangeEventArgs : EventArgs { public TextChangeEventArgs(string message) { } } #endregion #region 私有方法 /// /// 设置控件的样式 /// protected void AdjustControl() { // 取得按钮控件的宽度和高度 int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0; this.Height = this.btnSearch.Height; // 设置控件的尺寸和位置。 this.txtUser.Location = new System.Drawing.Point(this.lblUser.Width + ControlsConst.CONTROLSPACE, (this.Height - this.txtUser.Height) / 2); this.txtUser.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width - (this.lblUser.Width + ControlsConst.CONTROLSPACE * 2), this.Height); this.btnSearch.Location = new System.Drawing.Point(this.Width - this.btnSearch.Width, (this.Height - this.btnSearch.Height) / 2); // 设置标签的尺寸和位置。 this.lblUser.Location = new System.Drawing.Point(0, (this.Height - this.lblUser.Height) / 2); this.lblUser.Size = new System.Drawing.Size(this.lblUser.Width, this.lblUser.Height); } /// /// 过滤数据源 /// /// /// protected DataTable SetFilter(DataTable dataSource) { return dataSource; } /// /// 调用服务方法获取用户信息 /// /// private DataTable GetUserInfo() { SearchStaffEntity pSearchStaff = new SearchStaffEntity(); pSearchStaff.ValueFlag = true; DataSet userDataSet = HRModuleProxy.Service.SearchHrStaff(pSearchStaff); if (userDataSet == null) { return new DataTable(); } if (userDataSet.Tables.Count <= 0) { return new DataTable(); } return userDataSet.Tables[0]; } #endregion } }