dkproductionLineSearchBox.cs 18 KB

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