dkStaffSearchBox.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:dkUserSearchBox.cs
  5. * 2.功能描述:系统员工选择控件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/09/12 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Client.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.DataModels.HRModule;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
  20. namespace Dongke.IBOSS.PRD.Client.Controls
  21. {
  22. /// <summary>
  23. /// 系统员工选择控件
  24. /// </summary>
  25. public partial class dkStaffSearchBox : UserControl
  26. {
  27. #region 成员变量
  28. private S_CMN_003 _frmUser; // 数据选择窗体
  29. private bool _isEnabled = true; // 控件是否可用
  30. private DataTable _dataSource = null; // 数据源
  31. private int? _userID; // 组织机构ID
  32. private string _userCode; // 组织机构Code
  33. private string _userName; // 组织机构名称
  34. private bool _isMustInput; // 控件是否是必须输入项目
  35. private bool _IsOnlyShowValid = true; // 是否只显示有效数据
  36. private DataRow _userRow; // 返回用户的DataRow
  37. private string _whereCondition = "StaffStatus = 2 And ValueFlag = 1"; // 查询条件
  38. private DKStaffEntity _staffEntity = new DKStaffEntity(); // 员工档案实体
  39. #endregion
  40. #region 构造函数
  41. /// <summary>
  42. /// 构造函数
  43. /// </summary>
  44. public dkStaffSearchBox()
  45. {
  46. InitializeComponent();
  47. this.ReadOnly = true;
  48. }
  49. #endregion
  50. #region 属性
  51. /// <summary>
  52. /// 是否只显示有效数据
  53. /// </summary>
  54. [Description("设置控件是否只显示有效数据。")]
  55. [DefaultValue(true)]
  56. public bool IsOnlyShowValid
  57. {
  58. get
  59. {
  60. return _IsOnlyShowValid;
  61. }
  62. set
  63. {
  64. _IsOnlyShowValid = value;
  65. }
  66. }
  67. /// <summary>
  68. /// 获取或者设定控件是否是必须输入项目
  69. /// </summary>
  70. [DefaultValue("False")]
  71. [Description("获取或者设定控件是否是必须输入项目。")]
  72. public bool IsMustInput
  73. {
  74. get
  75. {
  76. return _isMustInput;
  77. }
  78. set
  79. {
  80. _isMustInput = value;
  81. // 项目为必须输入项时,需要修改字体颜色
  82. if (_isMustInput)
  83. {
  84. this.lblUser.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
  85. }
  86. else
  87. {
  88. this.lblUser.ForeColor = System.Drawing.SystemColors.ControlText;
  89. }
  90. }
  91. }
  92. /// <summary>
  93. /// Lable标签文本
  94. /// </summary>
  95. [DefaultValue("员工姓名")]
  96. [Description("获取或者设定Lable标签字符。")]
  97. public string Title
  98. {
  99. get
  100. {
  101. return this.lblUser.Text;
  102. }
  103. set
  104. {
  105. this.lblUser.Text = value;
  106. AdjustControl();
  107. }
  108. }
  109. /// <summary>
  110. /// 获取或者设定控件的数据源。
  111. /// </summary>
  112. [Description("获取或者设定控件的数据源。")]
  113. public DataTable DataSource
  114. {
  115. get
  116. {
  117. return _dataSource;
  118. }
  119. set
  120. {
  121. DataTable dataSource = SetFilter(value);
  122. _dataSource = dataSource;
  123. }
  124. }
  125. [Description("获取或者设定控件StaffEntity。")]
  126. public DKStaffEntity StaffEntity
  127. {
  128. get
  129. {
  130. return _staffEntity;
  131. }
  132. set
  133. {
  134. _staffEntity = value;
  135. }
  136. }
  137. /// <summary>
  138. /// 获取或者设定控件的尺寸大小。
  139. /// </summary>
  140. [Description("获取或者设定控件的尺寸大小。")]
  141. public new Size Size
  142. {
  143. get
  144. {
  145. return base.Size;
  146. }
  147. set
  148. {
  149. base.Size = value;
  150. AdjustControl();
  151. }
  152. }
  153. /// <summary>
  154. /// 获取或者设定控件的文本框的文本字符串。
  155. /// </summary>
  156. [Description("获取或者设定控件的文本框的文本字符串。")]
  157. public override string Text
  158. {
  159. get
  160. {
  161. return this.txtUser.Text;
  162. }
  163. set
  164. {
  165. this.txtUser.Text = value;
  166. }
  167. }
  168. /// <summary>
  169. /// 获取或者设定控件的文本框的背景颜色。
  170. /// </summary>
  171. [Description("获取或者设定控件的文本框的背景颜色。")]
  172. public Color TxtUserBackColor
  173. {
  174. get
  175. {
  176. return this.txtUser.BackColor;
  177. }
  178. set
  179. {
  180. this.txtUser.BackColor = value;
  181. }
  182. }
  183. /// <summary>
  184. /// 获取或者设定控件的员工ID。
  185. /// </summary>
  186. [Description("获取或者设定控件的用户ID。")]
  187. [DefaultValue(null)]
  188. public int? UserID
  189. {
  190. get
  191. {
  192. return _userID;
  193. }
  194. set
  195. {
  196. this._userID = null;
  197. this._userCode = string.Empty;
  198. this._userName = string.Empty;
  199. this.Text = string.Empty;
  200. if (value != null)
  201. {
  202. // 当数据源为null时,查询数据源
  203. if (DataSource == null)
  204. {
  205. // 查询数据源
  206. DataSource = GetUserInfo();
  207. }
  208. if (value != null && value != 0 && this.DataSource != null)
  209. {
  210. DataTable userTable = this.DataSource.Copy();
  211. DataRow[] dataRows = userTable.Select("StaffID = " + value);
  212. if (dataRows.Length == 1)
  213. {
  214. this._userID = value;
  215. this._userCode = dataRows[0]["StaffCode"] as string;
  216. this._userName = dataRows[0]["StaffName"] as string;
  217. this.Text = dataRows[0]["StaffName"] as string;
  218. }
  219. }
  220. }
  221. }
  222. }
  223. /// <summary>
  224. /// 获取或者设定控件的员工Code
  225. /// </summary>
  226. [Description("获取或者设定控件的用户Code。")]
  227. public string UserCode
  228. {
  229. get
  230. {
  231. return _userCode;
  232. }
  233. set
  234. {
  235. _userCode = value;
  236. }
  237. }
  238. /// <summary>
  239. /// 获取或者设定控件的员工名称
  240. /// </summary>
  241. [Description("获取或者设定控件的用户名称。")]
  242. public string UserName
  243. {
  244. get
  245. {
  246. return _userName;
  247. }
  248. set
  249. {
  250. _userName = value;
  251. }
  252. }
  253. /// <summary>
  254. /// 获取或者设定控件用户信息
  255. /// </summary>
  256. [Description("获取或者设定控件的用户信息。")]
  257. public DataRow UserRow
  258. {
  259. get { return _userRow; }
  260. set { _userRow = value; }
  261. }
  262. /// <summary>
  263. /// 获取或者设定控件是否可用。
  264. /// </summary>
  265. [System.ComponentModel.DefaultValue(null)]
  266. [Description("获取或者设定控件是否可用。")]
  267. public new bool Enabled
  268. {
  269. get
  270. {
  271. return _isEnabled;
  272. }
  273. set
  274. {
  275. _isEnabled = value;
  276. this.txtUser.Enabled = _isEnabled;
  277. this.TabStop = _isEnabled;
  278. }
  279. }
  280. /// <summary>
  281. /// 获取或者设定控件是否只读。
  282. /// </summary>
  283. [System.ComponentModel.DefaultValue(null)]
  284. [Description("获取或者设定控件是否只读。")]
  285. public bool ReadOnly
  286. {
  287. set
  288. {
  289. this.txtUser.ReadOnly = value;
  290. }
  291. }
  292. /// <summary>
  293. /// 范围权限
  294. /// </summary>
  295. public byte PurviewType
  296. {
  297. get;
  298. set;
  299. }
  300. /// <summary>
  301. /// 获取或者设定控件的员工Code
  302. /// </summary>
  303. [Description("获取或者设定控件的查询条件。")]
  304. public string WhereCondition
  305. {
  306. get
  307. {
  308. return _whereCondition;
  309. }
  310. set
  311. {
  312. _whereCondition = value;
  313. }
  314. }
  315. #endregion
  316. #region 定义委托事件
  317. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  318. public event TextBoxChangedHandle UserValueChanged;
  319. #endregion
  320. #region 控件事件
  321. /// <summary>
  322. /// 控件尺寸大小改变事件
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void dkUserSearchBox_SizeChanged(object sender, System.EventArgs e)
  327. {
  328. AdjustControl();
  329. }
  330. /// <summary>
  331. /// 查询按钮按下事件
  332. /// </summary>
  333. /// <param name="sender"></param>
  334. /// <param name="e"></param>
  335. private void btnSearch_Click(object sender, System.EventArgs e)
  336. {
  337. // 如果属性是不可用,是不能进行点击事件的
  338. if (!Enabled)
  339. {
  340. return;
  341. }
  342. // 当数据源为null时,查询数据源
  343. if (DataSource == null)
  344. {
  345. // 查询数据源
  346. DataSource = GetUserInfo();
  347. }
  348. // 释放窗体资源
  349. if (null != _frmUser)
  350. {
  351. _frmUser.Dispose();
  352. _frmUser = null;
  353. }
  354. // 打开查询窗体
  355. _frmUser = new S_CMN_003(this.txtUser.Text, this.WhereCondition);
  356. _frmUser.DataSource = this.DataSource;
  357. DialogResult dialogResult = _frmUser.ShowDialog();
  358. // 查询窗体返回值给控件赋值
  359. if (dialogResult.Equals(DialogResult.OK))
  360. {
  361. if (_frmUser.UserRow != null)
  362. {
  363. _userRow = _frmUser.UserRow;
  364. //_userID = Convert.ToInt32(_frmUser.UserRow["StaffID"]);
  365. //_userCode = _frmUser.UserRow["StaffCode"].ToString();
  366. //_userName = _frmUser.UserRow["StaffName"].ToString();
  367. this._staffEntity = _frmUser.StaffEntity;
  368. _userID = _frmUser.StaffEntity.StaffID;
  369. _userCode = _frmUser.StaffEntity.StaffCode;
  370. _userName = _frmUser.StaffEntity.StaffName;
  371. this.Text = _frmUser.StaffEntity.StaffName;
  372. }
  373. }
  374. }
  375. /// <summary>
  376. /// 清除控件的值
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void txtUser_KeyDown(object sender, KeyEventArgs e)
  381. {
  382. if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
  383. {
  384. this.txtUser.Text = "";
  385. this._userID = null;
  386. this._userCode = string.Empty;
  387. this._userName = string.Empty;
  388. this._userRow = null;
  389. }
  390. }
  391. /// <summary>
  392. /// 文本框文本改变事件
  393. /// </summary>
  394. /// <param name="sender"></param>
  395. /// <param name="e"></param>
  396. private void txtUser_TextChanged(object sender, EventArgs e)
  397. {
  398. if (UserValueChanged != null)
  399. {
  400. UserValueChanged(this, new TextChangeEventArgs(this.txtUser.Text));
  401. }
  402. }
  403. public class TextChangeEventArgs : EventArgs
  404. {
  405. public TextChangeEventArgs(string message)
  406. {
  407. }
  408. }
  409. #endregion
  410. #region 私有方法
  411. /// <summary>
  412. /// 设置控件的样式
  413. /// </summary>
  414. protected void AdjustControl()
  415. {
  416. // 取得按钮控件的宽度和高度
  417. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  418. this.Height = this.btnSearch.Height;
  419. // 设置控件的尺寸和位置。
  420. this.txtUser.Location = new System.Drawing.Point(this.lblUser.Width +
  421. ControlsConst.CONTROLSPACE, (this.Height - this.txtUser.Height) / 2);
  422. this.txtUser.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  423. (this.lblUser.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  424. this.btnSearch.Location =
  425. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  426. (this.Height - this.btnSearch.Height) / 2);
  427. // 设置标签的尺寸和位置。
  428. this.lblUser.Location =
  429. new System.Drawing.Point(0, (this.Height - this.lblUser.Height) / 2);
  430. this.lblUser.Size = new System.Drawing.Size(this.lblUser.Width, this.lblUser.Height);
  431. }
  432. /// <summary>
  433. /// 过滤数据源
  434. /// </summary>
  435. /// <param name="dataSource"></param>
  436. /// <returns></returns>
  437. protected DataTable SetFilter(DataTable dataSource)
  438. {
  439. return dataSource;
  440. }
  441. /// <summary>
  442. /// 调用服务方法获取用户信息
  443. /// </summary>
  444. /// <returns></returns>
  445. private DataTable GetUserInfo()
  446. {
  447. SearchStaffEntity pSearchStaff = new SearchStaffEntity();
  448. pSearchStaff.ValueFlag = true;
  449. DataSet userDataSet = HRModuleProxy.Service.SearchHrStaff(pSearchStaff);
  450. if (userDataSet == null)
  451. {
  452. return new DataTable();
  453. }
  454. if (userDataSet.Tables.Count <= 0)
  455. {
  456. return new DataTable();
  457. }
  458. return userDataSet.Tables[0];
  459. }
  460. #endregion
  461. }
  462. }