dkDefectFineSearchBox.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. public partial class dkDefectFineSearchBox : UserControl
  21. {
  22. #region 成员变量
  23. private string _procedureIDS; //id集
  24. private string _procedureCode; // 工序Code
  25. private string _procedureName; // 工序Name
  26. private int? _procedureID; // 工序ID
  27. /// <summary>
  28. /// 数据选择窗体
  29. /// </summary>
  30. private S_CMN_024 _frmDefectFine;
  31. /// <summary>
  32. /// 控件是否可用
  33. /// </summary>
  34. private bool _isEnabled = true;
  35. /// <summary>
  36. /// 数据源
  37. /// </summary>
  38. private DataTable _dataSource = null;
  39. /// <summary>
  40. /// 缺陷扣罚ID
  41. /// </summary>
  42. private int? _DefectFineID;
  43. /// <summary>
  44. /// 缺陷扣罚编码
  45. /// </summary>
  46. private string _DefectFineCodeCode;
  47. /// <summary>
  48. /// 控件是否是必须输入项目
  49. /// </summary>
  50. private bool _isMustInput;
  51. /// <summary>
  52. /// 是否只显示有效数据
  53. /// </summary>
  54. private bool _IsOnlyShowValid = true;
  55. #endregion
  56. #region 构造函数
  57. public dkDefectFineSearchBox()
  58. {
  59. InitializeComponent();
  60. this.ReadOnly = true;
  61. }
  62. #endregion
  63. #region 属性
  64. /// <summary>
  65. /// 是否只显示有效数据
  66. /// </summary>
  67. [Description("设置控件是否只显示有效数据。")]
  68. [DefaultValue(true)]
  69. public bool IsOnlyShowValid
  70. {
  71. get
  72. {
  73. return _IsOnlyShowValid;
  74. }
  75. set
  76. {
  77. _IsOnlyShowValid = value;
  78. }
  79. }
  80. /// <summary>
  81. /// 多选。
  82. /// </summary>
  83. [System.ComponentModel.DefaultValue(false)]
  84. [Description("多选。")]
  85. public bool SelectMore
  86. {
  87. get;
  88. set;
  89. }
  90. /// <summary>
  91. /// 获取或者设定控件是否是必须输入项目
  92. /// </summary>
  93. [DefaultValue("False")]
  94. [Description("获取或者设定控件是否是必须输入项目。")]
  95. public bool IsMustInput
  96. {
  97. get
  98. {
  99. return _isMustInput;
  100. }
  101. set
  102. {
  103. _isMustInput = value;
  104. // 项目为必须输入项时,需要修改字体颜色
  105. if (_isMustInput)
  106. {
  107. this.lblPost.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
  108. }
  109. else
  110. {
  111. this.lblPost.ForeColor = System.Drawing.SystemColors.ControlText;
  112. }
  113. }
  114. }
  115. /// <summary>
  116. /// Lable标签文本
  117. /// </summary>
  118. [DefaultValue("工种名称")]
  119. [Description("获取或者设定Lable标签字符。")]
  120. public string Title
  121. {
  122. get
  123. {
  124. return this.lblPost.Text;
  125. }
  126. set
  127. {
  128. this.lblPost.Text = value;
  129. AdjustControl();
  130. }
  131. }
  132. /// <summary>
  133. /// 获取或者设定控件的数据源。
  134. /// </summary>
  135. [Description("获取或者设定控件的数据源。")]
  136. public DataTable DataSource
  137. {
  138. get
  139. {
  140. return _dataSource;
  141. }
  142. set
  143. {
  144. DataTable dataSource = SetFilter(value);
  145. _dataSource = dataSource;
  146. }
  147. }
  148. /// <summary>
  149. /// 获取或者设定控件的尺寸大小。
  150. /// </summary>
  151. [Description("获取或者设定控件的尺寸大小。")]
  152. public new Size Size
  153. {
  154. get
  155. {
  156. return base.Size;
  157. }
  158. set
  159. {
  160. base.Size = value;
  161. AdjustControl();
  162. }
  163. }
  164. /// <summary>
  165. /// 获取或者设定控件的文本框的文本字符串。
  166. /// </summary>
  167. [Description("获取或者设定控件的文本框的文本字符串。")]
  168. public override string Text
  169. {
  170. get
  171. {
  172. return this.txtJobs.Text;
  173. }
  174. set
  175. {
  176. this.txtJobs.Text = value;
  177. }
  178. }
  179. /// <summary>
  180. /// 获取或者设定控件的文本框的背景颜色。
  181. /// </summary>
  182. [Description("获取或者设定控件的文本框的背景颜色。")]
  183. public Color TxtUserBackColor
  184. {
  185. get
  186. {
  187. return this.txtJobs.BackColor;
  188. }
  189. set
  190. {
  191. this.txtJobs.BackColor = value;
  192. }
  193. }
  194. /// <summary>
  195. /// 获取或者设定控件的缺陷扣罚ID。
  196. /// </summary>
  197. [Description("获取或者设定控件的缺陷扣罚ID。")]
  198. [DefaultValue(null)]
  199. public int? DefectFineID
  200. {
  201. get
  202. {
  203. return _DefectFineID;
  204. }
  205. set
  206. {
  207. this._DefectFineID = null;
  208. this._DefectFineCodeCode = string.Empty;
  209. this.Text = string.Empty;
  210. if (value != null)
  211. {
  212. // 当数据源为null时,查询数据源
  213. if (DataSource == null)
  214. {
  215. // 查询数据源
  216. DataSource = GetDefectFineInfo();
  217. }
  218. if (value != null && value != 0 && this.DataSource != null)
  219. {
  220. DataTable userTable = this.DataSource.Copy();
  221. DataRow[] dataRows = userTable.Select("DefectFineID = " + value);
  222. if (dataRows.Length == 1)
  223. {
  224. this._DefectFineID = value;
  225. this._DefectFineCodeCode = dataRows[0]["DefectFineCode"] as string;
  226. this.Text = dataRows[0]["DefectFineCode"] as string;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. /// <summary>
  233. /// 获取或者设定控件的工序id集
  234. /// </summary>
  235. [Description("获取或者设定控件的工序id集。")]
  236. public string DefectFineIDS
  237. {
  238. get
  239. {
  240. return _procedureIDS;
  241. }
  242. set
  243. {
  244. _procedureIDS = value;
  245. }
  246. }
  247. /// <summary>
  248. /// 获取或者设定控件的缺陷扣罚Code
  249. /// </summary>
  250. [Description("获取或者设定控件的缺陷扣罚Code。")]
  251. public string DefectFineCode
  252. {
  253. get
  254. {
  255. return _DefectFineCodeCode;
  256. }
  257. set
  258. {
  259. _DefectFineCodeCode = value;
  260. }
  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.txtJobs.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.txtJobs.ReadOnly = value;
  290. }
  291. }
  292. /// <summary>
  293. /// 范围权限
  294. /// </summary>
  295. public byte PurviewType
  296. {
  297. get;
  298. set;
  299. }
  300. #endregion
  301. #region 定义委托事件
  302. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  303. public event TextBoxChangedHandle UserValueChanged;
  304. #endregion
  305. #region 控件事件
  306. public class TextChangeEventArgs : EventArgs
  307. {
  308. public TextChangeEventArgs(string message)
  309. {
  310. }
  311. }
  312. /// <summary>
  313. /// 控件尺寸大小改变事件
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void dkJobsSearchBox_SizeChanged(object sender, EventArgs e)
  318. {
  319. AdjustControl();
  320. }
  321. /// <summary>
  322. /// 查询按钮按下事件
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void btnSearch_Click(object sender, EventArgs e)
  327. {
  328. // 如果属性是不可用,是不能进行点击事件的
  329. if (!Enabled)
  330. {
  331. return;
  332. }
  333. // 当数据源为null时,查询数据源
  334. if (DataSource == null)
  335. {
  336. // 查询数据源
  337. DataSource = GetDefectFineInfo();
  338. }
  339. // 释放窗体资源
  340. if (null != _frmDefectFine)
  341. {
  342. _frmDefectFine.Dispose();
  343. _frmDefectFine = null;
  344. }
  345. //// 打开查询窗体
  346. //_frmDefectFine = new S_CMN_024(this.txtJobs.Text);
  347. //_frmDefectFine.DataSource = this.DataSource;
  348. //DialogResult dialogResult = _frmDefectFine.ShowDialog();
  349. //// 查询窗体返回值给控件赋值
  350. //if (dialogResult.Equals(DialogResult.OK))
  351. //{
  352. // if (_frmDefectFine.JobsRow != null)
  353. // {
  354. // _DefectFineID = Convert.ToInt32(_frmDefectFine.JobsRow["DefectFineID"]);
  355. // _DefectFineCodeCode = _frmDefectFine.JobsRow["DefectFineCode"].ToString();
  356. // this.Text = _frmDefectFine.JobsRow["DefectFineCode"].ToString();
  357. // }
  358. //}
  359. // 打开查询窗体
  360. if (this.SelectMore)
  361. {
  362. _frmDefectFine = new S_CMN_024(1);
  363. }
  364. else
  365. {
  366. _frmDefectFine = new S_CMN_024(0);
  367. }
  368. _frmDefectFine.DataSource = this.DataSource;
  369. DialogResult dialogResult = _frmDefectFine.ShowDialog();
  370. // 查询窗体返回值给控件赋值
  371. if (dialogResult.Equals(DialogResult.OK))
  372. {
  373. if (this.SelectMore)
  374. {
  375. _procedureCode = string.Empty;
  376. _procedureName = string.Empty;
  377. _procedureIDS = string.Empty;
  378. if (_frmDefectFine.ProductionLineRow != null || _frmDefectFine.dataDT.Rows.Count > 0)
  379. {
  380. for (int i = 0; i < _frmDefectFine.dataDT.Rows.Count; i++)
  381. {
  382. if (_frmDefectFine.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
  383. {
  384. if (string.IsNullOrEmpty(_procedureCode))
  385. {
  386. _procedureCode = _frmDefectFine.dataDT.Rows[i]["DefectFineCode"].ToString();
  387. //_procedureName = _frmDefectFine.dataDT.Rows[i]["procedureName"].ToString();
  388. _procedureIDS = _frmDefectFine.dataDT.Rows[i]["DefectFineID"].ToString();
  389. }
  390. else
  391. {
  392. _procedureCode += "," + _frmDefectFine.dataDT.Rows[i]["DefectFineCode"].ToString();
  393. //_procedureName += "," + _frmDefectFine.dataDT.Rows[i]["procedureName"].ToString();
  394. _procedureIDS += "," + _frmDefectFine.dataDT.Rows[i]["DefectFineID"].ToString();
  395. }
  396. }
  397. }
  398. this.Text = _procedureCode;
  399. }
  400. }
  401. else
  402. {
  403. if (_frmDefectFine.ProductionLineRow != null)
  404. {
  405. _procedureID = Convert.ToInt32(_frmDefectFine.ProductionLineRow["DefectFineID"]);
  406. _procedureCode = _frmDefectFine.ProductionLineRow["DefectFineCode"].ToString();
  407. //_procedureName = _frmDefectFine.ProductionLineRow["procedureName"].ToString();
  408. this.Text = _frmDefectFine.ProductionLineRow["DefectFineCode"].ToString();
  409. }
  410. }
  411. }
  412. }
  413. /// <summary>
  414. /// 清除控件的值
  415. /// </summary>
  416. /// <param name="sender"></param>
  417. /// <param name="e"></param>
  418. private void txtJobs_KeyDown(object sender, KeyEventArgs e)
  419. {
  420. this.txtJobs.Text = "";
  421. this._DefectFineID = null;
  422. this._DefectFineCodeCode = string.Empty;
  423. }
  424. /// <summary>
  425. /// 文本框文本改变事件
  426. /// </summary>
  427. /// <param name="sender"></param>
  428. /// <param name="e"></param>
  429. private void txtJobs_TextChanged(object sender, EventArgs e)
  430. {
  431. if (UserValueChanged != null)
  432. {
  433. UserValueChanged(this, new TextChangeEventArgs(this.txtJobs.Text));
  434. }
  435. }
  436. #endregion
  437. #region 私有方法
  438. /// <summary>
  439. /// 设置控件的样式
  440. /// </summary>
  441. protected void AdjustControl()
  442. {
  443. // 取得按钮控件的宽度和高度
  444. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  445. this.Height = this.btnSearch.Height;
  446. // 设置控件的尺寸和位置。
  447. this.txtJobs.Location = new System.Drawing.Point(this.lblPost.Width +
  448. ControlsConst.CONTROLSPACE, (this.Height - this.txtJobs.Height) / 2);
  449. this.txtJobs.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  450. (this.lblPost.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  451. this.btnSearch.Location =
  452. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  453. (this.Height - this.btnSearch.Height) / 2);
  454. // 设置标签的尺寸和位置。
  455. this.lblPost.Location =
  456. new System.Drawing.Point(0, (this.Height - this.lblPost.Height) / 2);
  457. this.lblPost.Size = new System.Drawing.Size(this.lblPost.Width, this.lblPost.Height);
  458. }
  459. /// <summary>
  460. /// 过滤数据源
  461. /// </summary>
  462. /// <param name="dataSource"></param>
  463. /// <returns></returns>
  464. protected DataTable SetFilter(DataTable dataSource)
  465. {
  466. return dataSource;
  467. }
  468. /// <summary>
  469. /// 调用服务方法获取用户信息
  470. /// </summary>
  471. /// <returns></returns>
  472. private DataTable GetDefectFineInfo()
  473. {
  474. DataSet userDataSet = SystemModuleProxy.Service.GetAllDefectFine();
  475. if (userDataSet == null)
  476. {
  477. return new DataTable();
  478. }
  479. if (userDataSet.Tables.Count <= 0)
  480. {
  481. return new DataTable();
  482. }
  483. return userDataSet.Tables[0];
  484. }
  485. #endregion
  486. /// <summary>
  487. /// 清空控件的值
  488. /// </summary>
  489. /// <param name="dataSource"></param>
  490. /// <returns></returns>
  491. public void ClearControl()
  492. {
  493. this.txtJobs.Text = string.Empty;
  494. this._procedureID = null;
  495. this._procedureName = string.Empty;
  496. this._procedureCode = string.Empty;
  497. this._procedureIDS = string.Empty;
  498. }
  499. }
  500. }