dkDefectSearchBox.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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 dkDefectSearchBox : 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_025 _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 dkDefectSearchBox()
  58. {
  59. InitializeComponent();
  60. this.ReadOnly = true;
  61. }
  62. #endregion
  63. #region 属性
  64. /// <summary>
  65. /// 多选。
  66. /// </summary>
  67. [System.ComponentModel.DefaultValue(false)]
  68. [Description("多选。")]
  69. public bool SelectMore
  70. {
  71. get;
  72. set;
  73. }
  74. /// <summary>
  75. /// 是否只显示有效数据
  76. /// </summary>
  77. [Description("设置控件是否只显示有效数据。")]
  78. [DefaultValue(true)]
  79. public bool IsOnlyShowValid
  80. {
  81. get
  82. {
  83. return _IsOnlyShowValid;
  84. }
  85. set
  86. {
  87. _IsOnlyShowValid = value;
  88. }
  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. /// 获取或者设定控件的工序id集
  150. /// </summary>
  151. [Description("获取或者设定控件的工序id集。")]
  152. public string DefectIDS
  153. {
  154. get
  155. {
  156. return _procedureIDS;
  157. }
  158. set
  159. {
  160. _procedureIDS = value;
  161. }
  162. }
  163. /// <summary>
  164. /// 获取或者设定控件的尺寸大小。
  165. /// </summary>
  166. [Description("获取或者设定控件的尺寸大小。")]
  167. public new Size Size
  168. {
  169. get
  170. {
  171. return base.Size;
  172. }
  173. set
  174. {
  175. base.Size = value;
  176. AdjustControl();
  177. }
  178. }
  179. /// <summary>
  180. /// 获取或者设定控件的文本框的文本字符串。
  181. /// </summary>
  182. [Description("获取或者设定控件的文本框的文本字符串。")]
  183. public override string Text
  184. {
  185. get
  186. {
  187. return this.txtJobs.Text;
  188. }
  189. set
  190. {
  191. this.txtJobs.Text = value;
  192. }
  193. }
  194. /// <summary>
  195. /// 获取或者设定控件的文本框的背景颜色。
  196. /// </summary>
  197. [Description("获取或者设定控件的文本框的背景颜色。")]
  198. public Color TxtUserBackColor
  199. {
  200. get
  201. {
  202. return this.txtJobs.BackColor;
  203. }
  204. set
  205. {
  206. this.txtJobs.BackColor = value;
  207. }
  208. }
  209. /// <summary>
  210. /// 获取或者设定控件的缺陷扣罚ID。
  211. /// </summary>
  212. [Description("获取或者设定控件的缺陷扣罚ID。")]
  213. [DefaultValue(null)]
  214. public int? DefectFineID
  215. {
  216. get
  217. {
  218. return _DefectFineID;
  219. }
  220. set
  221. {
  222. this._DefectFineID = null;
  223. this._DefectFineCodeCode = string.Empty;
  224. this.Text = string.Empty;
  225. if (value != null)
  226. {
  227. // 当数据源为null时,查询数据源
  228. if (DataSource == null)
  229. {
  230. // 查询数据源
  231. DataSource = GetDefectFineInfo();
  232. }
  233. if (value != null && value != 0 && this.DataSource != null)
  234. {
  235. DataTable userTable = this.DataSource.Copy();
  236. DataRow[] dataRows = userTable.Select("DefectID = " + value);
  237. if (dataRows.Length == 1)
  238. {
  239. this._DefectFineID = value;
  240. this._DefectFineCodeCode = dataRows[0]["DefectCode"] as string;
  241. this.Text = dataRows[0]["DefectCode"] as string;
  242. }
  243. }
  244. }
  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. if (this.SelectMore)
  347. {
  348. _frmDefectFine = new S_CMN_025(1);
  349. }
  350. else
  351. {
  352. _frmDefectFine = new S_CMN_025(0);
  353. }
  354. _frmDefectFine.DataSource = this.DataSource;
  355. DialogResult dialogResult = _frmDefectFine.ShowDialog();
  356. // 查询窗体返回值给控件赋值
  357. if (dialogResult.Equals(DialogResult.OK))
  358. {
  359. if (this.SelectMore)
  360. {
  361. _procedureCode = string.Empty;
  362. _procedureName = string.Empty;
  363. _procedureIDS = string.Empty;
  364. if (_frmDefectFine.ProductionLineRow != null || _frmDefectFine.dataDT.Rows.Count > 0)
  365. {
  366. for (int i = 0; i < _frmDefectFine.dataDT.Rows.Count; i++)
  367. {
  368. if (_frmDefectFine.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
  369. {
  370. if (string.IsNullOrEmpty(_procedureCode))
  371. {
  372. _procedureCode = "," + _frmDefectFine.dataDT.Rows[i]["DefectCode"].ToString() + "->" + _frmDefectFine.dataDT.Rows[i]["DefectName"].ToString();
  373. //_procedureName = _frmDefectFine.dataDT.Rows[i]["procedureName"].ToString();
  374. _procedureIDS = _frmDefectFine.dataDT.Rows[i]["DefectID"].ToString();
  375. }
  376. else
  377. {
  378. _procedureCode += "," + _frmDefectFine.dataDT.Rows[i]["DefectCode"].ToString() + "->" + _frmDefectFine.dataDT.Rows[i]["DefectName"].ToString();
  379. //_procedureName += "," + _frmDefectFine.dataDT.Rows[i]["procedureName"].ToString();
  380. _procedureIDS += "," + _frmDefectFine.dataDT.Rows[i]["DefectID"].ToString();
  381. }
  382. }
  383. }
  384. this.Text = _procedureCode.Trim(',');
  385. }
  386. }
  387. else
  388. {
  389. if (_frmDefectFine.ProductionLineRow != null)
  390. {
  391. _procedureID = Convert.ToInt32(_frmDefectFine.ProductionLineRow["DefectID"]);
  392. _procedureCode = _frmDefectFine.ProductionLineRow["DefectCode"].ToString() + "->" + _frmDefectFine.ProductionLineRow["DefectName"].ToString();
  393. //_procedureName = _frmDefectFine.ProductionLineRow["procedureName"].ToString();
  394. this.Text = _frmDefectFine.ProductionLineRow["DefectCode"].ToString();
  395. }
  396. }
  397. }
  398. }
  399. /// <summary>
  400. /// 清除控件的值
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void txtJobs_KeyDown(object sender, KeyEventArgs e)
  405. {
  406. this.txtJobs.Text = "";
  407. this._DefectFineID = null;
  408. this._DefectFineCodeCode = string.Empty;
  409. }
  410. /// <summary>
  411. /// 文本框文本改变事件
  412. /// </summary>
  413. /// <param name="sender"></param>
  414. /// <param name="e"></param>
  415. private void txtJobs_TextChanged(object sender, EventArgs e)
  416. {
  417. if (UserValueChanged != null)
  418. {
  419. UserValueChanged(this, new TextChangeEventArgs(this.txtJobs.Text));
  420. }
  421. }
  422. #endregion
  423. #region 私有方法
  424. /// <summary>
  425. /// 设置控件的样式
  426. /// </summary>
  427. protected void AdjustControl()
  428. {
  429. // 取得按钮控件的宽度和高度
  430. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  431. this.Height = this.btnSearch.Height;
  432. // 设置控件的尺寸和位置。
  433. this.txtJobs.Location = new System.Drawing.Point(this.lblPost.Width +
  434. ControlsConst.CONTROLSPACE, (this.Height - this.txtJobs.Height) / 2);
  435. this.txtJobs.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  436. (this.lblPost.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  437. this.btnSearch.Location =
  438. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  439. (this.Height - this.btnSearch.Height) / 2);
  440. // 设置标签的尺寸和位置。
  441. this.lblPost.Location =
  442. new System.Drawing.Point(0, (this.Height - this.lblPost.Height) / 2);
  443. this.lblPost.Size = new System.Drawing.Size(this.lblPost.Width, this.lblPost.Height);
  444. }
  445. /// <summary>
  446. /// 过滤数据源
  447. /// </summary>
  448. /// <param name="dataSource"></param>
  449. /// <returns></returns>
  450. protected DataTable SetFilter(DataTable dataSource)
  451. {
  452. return dataSource;
  453. }
  454. /// <summary>
  455. /// 调用服务方法获取用户信息
  456. /// </summary>
  457. /// <returns></returns>
  458. private DataTable GetDefectFineInfo()
  459. {
  460. DataSet userDataSet = SystemModuleProxy.Service.GetDefectData(1);
  461. if (userDataSet == null)
  462. {
  463. return new DataTable();
  464. }
  465. if (userDataSet.Tables.Count <= 0)
  466. {
  467. return new DataTable();
  468. }
  469. return userDataSet.Tables[0];
  470. }
  471. #endregion
  472. /// <summary>
  473. /// 清空控件的值
  474. /// </summary>
  475. /// <param name="dataSource"></param>
  476. /// <returns></returns>
  477. public void ClearControl()
  478. {
  479. this.txtJobs.Text = string.Empty;
  480. this._procedureID = null;
  481. this._procedureName = string.Empty;
  482. this._procedureCode = string.Empty;
  483. this._procedureIDS = string.Empty;
  484. }
  485. }
  486. }