dkDefectTypeNameSearchBox.cs 17 KB

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