dkJobsSearchBox.cs 14 KB

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