dkProcedureSearchBox.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:dkProcedureSearchBox.cs
  5. * 2.功能描述:工序选择控件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/11/29 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.WCF.Proxys;
  17. using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
  18. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  19. using Dongke.IBOSS.PRD.Basics.BaseResources;
  20. using Dongke.IBOSS.PRD.WCF.DataModels;
  21. namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox
  22. {
  23. /// <summary>
  24. /// 工序选择控件
  25. /// </summary>
  26. public partial class dkProcedureSearchBox : UserControl
  27. {
  28. #region 成员变量
  29. private S_CMN_016 _frmProcedure;
  30. private bool _isEnabled = true; // 控件是否可用
  31. private DataTable _dataSource = null; // 数据源
  32. private int? _procedureID; // 工序ID
  33. private string _procedureIDS; //id集
  34. private string _procedureCode; // 工序Code
  35. private string _procedureName; // 工序Name
  36. private bool _isMustInput; // 控件是否是必须输入项目
  37. private bool _IsOnlyShowValid = true; // 是否只显示有效数据
  38. private string _purview; // 是否有权限
  39. private string _modelType; //id集
  40. #endregion
  41. #region 构造函数
  42. public dkProcedureSearchBox()
  43. {
  44. InitializeComponent();
  45. this.ReadOnly = true;
  46. }
  47. #endregion
  48. #region 属性
  49. /// <summary>
  50. /// 是否只显示有效数据
  51. /// </summary>
  52. [Description("设置控件是否只显示有效数据。")]
  53. [DefaultValue(true)]
  54. public bool IsOnlyShowValid
  55. {
  56. get
  57. {
  58. return _IsOnlyShowValid;
  59. }
  60. set
  61. {
  62. _IsOnlyShowValid = value;
  63. }
  64. }
  65. /// <summary>
  66. /// 获取或者设定控件是否是必须输入项目
  67. /// </summary>
  68. [DefaultValue("False")]
  69. [Description("获取或者设定控件是否是必须输入项目。")]
  70. public bool IsMustInput
  71. {
  72. get
  73. {
  74. return _isMustInput;
  75. }
  76. set
  77. {
  78. _isMustInput = value;
  79. // 项目为必须输入项时,需要修改字体颜色
  80. if (_isMustInput)
  81. {
  82. this.lblProcedureName.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
  83. }
  84. else
  85. {
  86. this.lblProcedureName.ForeColor = System.Drawing.SystemColors.ControlText;
  87. }
  88. }
  89. }
  90. [DefaultValue("产品类别")]
  91. [Description("获取或者设定Lable标签字符。")]
  92. public string Title
  93. {
  94. get
  95. {
  96. return this.lblProcedureName.Text;
  97. }
  98. set
  99. {
  100. this.lblProcedureName.Text = value;
  101. AdjustControl();
  102. }
  103. }
  104. [DefaultValue(false)]
  105. public bool IsDeleteSelf
  106. {
  107. get;
  108. set;
  109. }
  110. /// <summary>
  111. /// 获取或者设定控件的数据源。
  112. /// </summary>
  113. [Description("获取或者设定控件的数据源。")]
  114. public DataTable DataSource
  115. {
  116. get
  117. {
  118. return _dataSource;
  119. }
  120. set
  121. {
  122. _dataSource = value;
  123. }
  124. }
  125. /// <summary>
  126. /// 获取或者设定控件的尺寸大小。
  127. /// </summary>
  128. [Description("获取或者设定控件的尺寸大小。")]
  129. public new Size Size
  130. {
  131. get
  132. {
  133. return base.Size;
  134. }
  135. set
  136. {
  137. base.Size = value;
  138. AdjustControl();
  139. }
  140. }
  141. /// <summary>
  142. /// 获取或者设定控件的文本框的文本字符串。
  143. /// </summary>
  144. [Description("获取或者设定控件的文本框的文本字符串。")]
  145. public override string Text
  146. {
  147. get
  148. {
  149. return this.txtProcedureName.Text;
  150. }
  151. set
  152. {
  153. this.txtProcedureName.Text = value;
  154. }
  155. }
  156. /// <summary>
  157. /// 获取或者设定控件的文本框的背景颜色。
  158. /// </summary>
  159. [Description("获取或者设定控件的文本框的背景颜色。")]
  160. public Color TxtGoodsTypeBackColor
  161. {
  162. get
  163. {
  164. return this.txtProcedureName.BackColor;
  165. }
  166. set
  167. {
  168. this.txtProcedureName.BackColor = value;
  169. }
  170. }
  171. /// <summary>
  172. /// 获取或者设定控件的工序id集
  173. /// </summary>
  174. [Description("获取或者设定控件的工序id集。")]
  175. public string ProcedureIDS
  176. {
  177. get
  178. {
  179. return _procedureIDS;
  180. }
  181. set
  182. {
  183. _procedureIDS = value;
  184. }
  185. }
  186. /// <summary>
  187. /// 获取或者设定控件的工序Code
  188. /// </summary>
  189. [Description("获取或者设定控件的工序Code。")]
  190. public string ProcedureCode
  191. {
  192. get
  193. {
  194. return _procedureCode;
  195. }
  196. set
  197. {
  198. _procedureCode = value;
  199. }
  200. }
  201. /// <summary>
  202. /// 获取或者设定控件的工序Name
  203. /// </summary>
  204. [Description("获取或者设定控件的工序Name。")]
  205. public string ProcedureName
  206. {
  207. get
  208. {
  209. return _procedureName;
  210. }
  211. set
  212. {
  213. _procedureName = value;
  214. }
  215. }
  216. /// <summary>
  217. /// 获取或者设定控件的工序ID。
  218. /// </summary>
  219. [Description("获取或者设定控件的工序ID。")]
  220. public int? ProcedureID
  221. {
  222. get
  223. {
  224. return _procedureID;
  225. }
  226. set
  227. {
  228. _procedureID = value;
  229. if (_procedureID != null && _procedureID != 0 && this.DataSource != null)
  230. {
  231. DataTable productionLineTable = this.DataSource.Copy();
  232. DataRow[] dataRows = productionLineTable.Select("procedureID = " + this._procedureID);
  233. if (dataRows.Length == 1)
  234. {
  235. this.Text = dataRows[0]["ProcedureCode"] as string;
  236. this.ProcedureName = dataRows[0]["ProcedureName"] as string;
  237. }
  238. }
  239. if (_procedureID == null)
  240. {
  241. this.Text = string.Empty;
  242. ProcedureCode = string.Empty;
  243. ProcedureName = string.Empty;
  244. }
  245. }
  246. }
  247. /// <summary>
  248. /// 获取或者设定控件是否可用。
  249. /// </summary>
  250. [System.ComponentModel.DefaultValue(null)]
  251. [Description("获取或者设定控件是否可用。")]
  252. public new bool Enabled
  253. {
  254. get
  255. {
  256. return _isEnabled;
  257. }
  258. set
  259. {
  260. _isEnabled = value;
  261. this.txtProcedureName.Enabled = _isEnabled;
  262. //this.btnSearch.Enabled = _isEnabled;
  263. this.TabStop = _isEnabled;
  264. }
  265. }
  266. /// <summary>
  267. /// 获取或者设定控件是否只读。
  268. /// </summary>
  269. [System.ComponentModel.DefaultValue(null)]
  270. [Description("获取或者设定控件是否只读。")]
  271. public bool ReadOnly
  272. {
  273. set
  274. {
  275. this.txtProcedureName.ReadOnly = value;
  276. }
  277. }
  278. /// <summary>
  279. /// 范围权限
  280. /// </summary>
  281. [Description("判断是否有权限")]
  282. public string Purview
  283. {
  284. get
  285. {
  286. return _purview;
  287. }
  288. set
  289. {
  290. _purview = value;
  291. }
  292. }
  293. /// <summary>
  294. /// 查看权限属性
  295. /// </summary>
  296. [System.ComponentModel.DefaultValue(false)]
  297. [Description("查看权限属性")]
  298. public bool Ispurview
  299. {
  300. get;
  301. set;
  302. }
  303. /// <summary>
  304. /// 范围权限
  305. /// </summary>
  306. public byte PurviewType
  307. {
  308. get;
  309. set;
  310. }
  311. /// <summary>
  312. /// 多选。
  313. /// </summary>
  314. [System.ComponentModel.DefaultValue(false)]
  315. [Description("多选。")]
  316. public bool SelectMore
  317. {
  318. get;
  319. set;
  320. }
  321. /// <summary>
  322. /// 是否启用权限功能
  323. /// </summary>
  324. [System.ComponentModel.DefaultValue(true)]
  325. [Description("是否启用权限功能")]
  326. public bool IsEnablePurview
  327. {
  328. get;
  329. set;
  330. }
  331. /// <summary>
  332. /// 获取或者工序类别
  333. /// </summary>
  334. [Description("获取或者设定控件的工序类别。")]
  335. public string ModelType
  336. {
  337. get
  338. {
  339. return _modelType;
  340. }
  341. set
  342. {
  343. _modelType = value;
  344. }
  345. }
  346. #endregion
  347. #region 事件
  348. [Description("控件光标点击按钮事件。")]
  349. public new event EventHandler Click
  350. {
  351. add
  352. {
  353. this.btnSearch.Click += value;
  354. }
  355. remove
  356. {
  357. this.btnSearch.Click -= value;
  358. }
  359. }
  360. /// <summary>
  361. /// 控件尺寸大小改变事件
  362. /// </summary>
  363. /// <param name="sender"></param>
  364. /// <param name="e"></param>
  365. private void dkProcedureSearchBox_SizeChanged(object sender, EventArgs e)
  366. {
  367. AdjustControl();
  368. }
  369. /// <summary>
  370. /// 清除控件的值
  371. /// </summary>
  372. /// <param name="sender"></param>
  373. /// <param name="e"></param>
  374. private void txtProcedureName_KeyDown(object sender, KeyEventArgs e)
  375. {
  376. if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
  377. {
  378. ClearControl();
  379. }
  380. }
  381. /// <summary>
  382. /// 查询按钮按下事件
  383. /// </summary>
  384. /// <param name="sender"></param>
  385. /// <param name="e"></param>
  386. private void btnSearch_Click(object sender, EventArgs e)
  387. {
  388. // 如果属性是不可用,是不能进行点击事件的
  389. if (!Enabled)
  390. {
  391. return;
  392. }
  393. // 当数据源为null时,查询数据源
  394. if (DataSource == null)
  395. {
  396. SearchProductionLineEntity line = new SearchProductionLineEntity();
  397. if (IsEnablePurview)
  398. {
  399. if (_purview == null)
  400. {
  401. if (this.Ispurview)
  402. {
  403. MessageBox.Show(Messages.MSG_CMN_W028,
  404. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  405. return;
  406. }
  407. else
  408. {
  409. MessageBox.Show(Messages.MSG_CMN_W027,
  410. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  411. return;
  412. }
  413. }
  414. line.ProcuteLineIDS = _purview;
  415. }
  416. // 查询数据源
  417. DataSource = SystemModuleProxy.Service.GetProdureList(line).Tables[0];
  418. // add wangx 2016/01/07
  419. if (!string.IsNullOrEmpty(this.ModelType))
  420. {
  421. DataView dv = DataSource.DefaultView;
  422. dv.RowFilter = "ModelType in (" + this.ModelType + ")";
  423. DataSource = dv.ToTable();
  424. }
  425. }
  426. // 释放窗体资源
  427. if (null != _frmProcedure)
  428. {
  429. _frmProcedure.Dispose();
  430. _frmProcedure = null;
  431. }
  432. // 打开查询窗体
  433. if (this.SelectMore)
  434. {
  435. _frmProcedure = new S_CMN_016(1);
  436. }
  437. else
  438. {
  439. _frmProcedure = new S_CMN_016(0);
  440. }
  441. _frmProcedure.DataSource = this.DataSource;
  442. DialogResult dialogResult = _frmProcedure.ShowDialog();
  443. // 查询窗体返回值给控件赋值
  444. if (dialogResult.Equals(DialogResult.OK))
  445. {
  446. if (this.SelectMore)
  447. {
  448. _procedureCode = string.Empty;
  449. _procedureName = string.Empty;
  450. _procedureIDS = string.Empty;
  451. if (_frmProcedure.ProductionLineRow != null || _frmProcedure.dataDT.Rows.Count > 0)
  452. {
  453. for (int i = 0; i < _frmProcedure.dataDT.Rows.Count; i++)
  454. {
  455. if (_frmProcedure.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
  456. {
  457. if (string.IsNullOrEmpty(_procedureCode))
  458. {
  459. _procedureCode = _frmProcedure.dataDT.Rows[i]["procedureCode"].ToString();
  460. _procedureName = _frmProcedure.dataDT.Rows[i]["procedureName"].ToString();
  461. _procedureIDS = _frmProcedure.dataDT.Rows[i]["procedureID"].ToString();
  462. }
  463. else
  464. {
  465. _procedureCode += "," + _frmProcedure.dataDT.Rows[i]["procedureCode"].ToString();
  466. _procedureName += "," + _frmProcedure.dataDT.Rows[i]["procedureName"].ToString();
  467. _procedureIDS += "," + _frmProcedure.dataDT.Rows[i]["procedureID"].ToString();
  468. }
  469. }
  470. }
  471. this.Text = _procedureName;
  472. }
  473. }
  474. else
  475. {
  476. if (_frmProcedure.ProductionLineRow != null)
  477. {
  478. _procedureID = Convert.ToInt32(_frmProcedure.ProductionLineRow["procedureID"]);
  479. _procedureCode = _frmProcedure.ProductionLineRow["procedureCode"].ToString();
  480. _procedureName = _frmProcedure.ProductionLineRow["procedureName"].ToString();
  481. this.Text = _frmProcedure.ProductionLineRow["procedureName"].ToString();
  482. }
  483. }
  484. }
  485. }
  486. private void txtProductionLineName_TextChanged(object sender, EventArgs e)
  487. {
  488. if (ProcedureValueChanged != null)
  489. {
  490. ProcedureValueChanged(this, new TextChangeEventArgs(this.txtProcedureName.Text));
  491. }
  492. }
  493. public class TextChangeEventArgs : EventArgs
  494. {
  495. public TextChangeEventArgs(string message)
  496. {
  497. }
  498. }
  499. #endregion
  500. #region 定义委托事件
  501. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  502. public event TextBoxChangedHandle ProcedureValueChanged;
  503. #endregion
  504. #region 私有方法
  505. /// <summary>
  506. /// 根据控件的尺寸变化,改变控件内部控件的尺寸大小
  507. /// </summary>
  508. protected void AdjustControl()
  509. {
  510. // 取得按钮控件的宽度和高度
  511. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  512. this.Height = this.btnSearch.Height;
  513. // 设置控件的尺寸和位置。
  514. this.txtProcedureName.Location = new System.Drawing.Point(this.lblProcedureName.Width +
  515. ControlsConst.CONTROLSPACE, (this.Height - this.txtProcedureName.Height) / 2);
  516. this.txtProcedureName.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  517. (this.lblProcedureName.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  518. this.btnSearch.Location =
  519. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  520. (this.Height - this.btnSearch.Height) / 2);
  521. // 设置标签的尺寸和位置。
  522. this.lblProcedureName.Location =
  523. new System.Drawing.Point(0, (this.Height - this.lblProcedureName.Height) / 2);
  524. this.lblProcedureName.Size = new System.Drawing.Size(this.lblProcedureName.Width, this.lblProcedureName.Height);
  525. }
  526. /// <summary>
  527. /// 清空控件的值
  528. /// </summary>
  529. /// <param name="dataSource"></param>
  530. /// <returns></returns>
  531. public void ClearControl()
  532. {
  533. this.txtProcedureName.Text = string.Empty;
  534. this._procedureID = null;
  535. this._procedureName = string.Empty;
  536. this._procedureCode = string.Empty;
  537. this._procedureIDS = string.Empty;
  538. }
  539. #endregion
  540. private void txtProcedureName_TextChanged(object sender, EventArgs e)
  541. {
  542. this.OnTextChanged(e);
  543. }
  544. }
  545. }