dkLogoSearchBox.cs 17 KB

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