dkSemiCheckDefectPositionSearchBox.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. /*******************************************************************************
  2. * Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:dkSemiCheckDefectPositionSearchBox.cs
  5. * 2.功能描述:半检缺陷位置选择控件
  6. * 编辑履历:工种
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2016/07/12 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 dkSemiCheckDefectPositionSearchBox : UserControl
  21. {
  22. #region 成员变量
  23. private string _defectPositionIDS; //id集
  24. private string _defectPositionCode; // 工序Code
  25. private string _defectPositionName; // 工序Name
  26. private int? _defectPositionID; // 工序ID
  27. /// <summary>
  28. /// 数据选择窗体
  29. /// </summary>
  30. private S_CMN_026 _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 dkSemiCheckDefectPositionSearchBox()
  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 DefectPositionIDS
  153. {
  154. get
  155. {
  156. return _defectPositionIDS;
  157. }
  158. set
  159. {
  160. _defectPositionIDS = 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. /// 获取或者设定控件的缺陷扣罚Code
  211. /// </summary>
  212. [Description("获取或者设定控件的缺陷扣罚Code。")]
  213. public string DefectFineCode
  214. {
  215. get
  216. {
  217. return _DefectFineCodeCode;
  218. }
  219. set
  220. {
  221. _DefectFineCodeCode = value;
  222. }
  223. }
  224. /// <summary>
  225. /// 获取或者设定控件是否可用。
  226. /// </summary>
  227. [System.ComponentModel.DefaultValue(null)]
  228. [Description("获取或者设定控件是否可用。")]
  229. public new bool Enabled
  230. {
  231. get
  232. {
  233. return _isEnabled;
  234. }
  235. set
  236. {
  237. _isEnabled = value;
  238. this.txtJobs.Enabled = _isEnabled;
  239. this.TabStop = _isEnabled;
  240. }
  241. }
  242. /// <summary>
  243. /// 获取或者设定控件是否只读。
  244. /// </summary>
  245. [System.ComponentModel.DefaultValue(null)]
  246. [Description("获取或者设定控件是否只读。")]
  247. public bool ReadOnly
  248. {
  249. set
  250. {
  251. this.txtJobs.ReadOnly = value;
  252. }
  253. }
  254. /// <summary>
  255. /// 范围权限
  256. /// </summary>
  257. public byte PurviewType
  258. {
  259. get;
  260. set;
  261. }
  262. #endregion
  263. #region 定义委托事件
  264. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  265. public event TextBoxChangedHandle UserValueChanged;
  266. #endregion
  267. #region 控件事件
  268. public class TextChangeEventArgs : EventArgs
  269. {
  270. public TextChangeEventArgs(string message)
  271. {
  272. }
  273. }
  274. /// <summary>
  275. /// 控件尺寸大小改变事件
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void dkJobsSearchBox_SizeChanged(object sender, EventArgs e)
  280. {
  281. AdjustControl();
  282. }
  283. /// <summary>
  284. /// 查询按钮按下事件
  285. /// </summary>
  286. /// <param name="sender"></param>
  287. /// <param name="e"></param>
  288. private void btnSearch_Click(object sender, EventArgs e)
  289. {
  290. // 如果属性是不可用,是不能进行点击事件的
  291. if (!Enabled)
  292. {
  293. return;
  294. }
  295. // 当数据源为null时,查询数据源
  296. if (DataSource == null)
  297. {
  298. // 查询数据源
  299. DataSource = GetAllScdefectPosition();
  300. }
  301. // 释放窗体资源
  302. if (null != _frmDefectFine)
  303. {
  304. _frmDefectFine.Dispose();
  305. _frmDefectFine = null;
  306. }
  307. // 打开查询窗体
  308. if (this.SelectMore)
  309. {
  310. _frmDefectFine = new S_CMN_026(1);
  311. }
  312. else
  313. {
  314. _frmDefectFine = new S_CMN_026(0);
  315. }
  316. _frmDefectFine.DataSource = this.DataSource;
  317. DialogResult dialogResult = _frmDefectFine.ShowDialog();
  318. // 查询窗体返回值给控件赋值
  319. if (dialogResult.Equals(DialogResult.OK))
  320. {
  321. if (this.SelectMore)
  322. {
  323. _defectPositionCode = string.Empty;
  324. _defectPositionName = string.Empty;
  325. _defectPositionIDS = string.Empty;
  326. if (_frmDefectFine.ProductionLineRow != null || _frmDefectFine.dataDT.Rows.Count > 0)
  327. {
  328. for (int i = 0; i < _frmDefectFine.dataDT.Rows.Count; i++)
  329. {
  330. if (_frmDefectFine.dataDT.Rows[i]["Sel"].ToString().Equals("1"))
  331. {
  332. if (string.IsNullOrEmpty(_defectPositionCode))
  333. {
  334. _defectPositionCode = "," + _frmDefectFine.dataDT.Rows[i]["defectPositionCode"].ToString() + "->" + _frmDefectFine.dataDT.Rows[i]["defectPositionName"].ToString();
  335. //_procedureName = _frmDefectFine.dataDT.Rows[i]["procedureName"].ToString();
  336. _defectPositionIDS = _frmDefectFine.dataDT.Rows[i]["defectPositionID"].ToString();
  337. }
  338. else
  339. {
  340. _defectPositionCode += "," + _frmDefectFine.dataDT.Rows[i]["defectPositionCode"].ToString() + "->" + _frmDefectFine.dataDT.Rows[i]["defectPositionName"].ToString();
  341. //_procedureName += "," + _frmDefectFine.dataDT.Rows[i]["procedureName"].ToString();
  342. _defectPositionIDS += "," + _frmDefectFine.dataDT.Rows[i]["defectPositionID"].ToString();
  343. }
  344. }
  345. }
  346. this.Text = _defectPositionCode.Trim(',');
  347. }
  348. }
  349. else
  350. {
  351. if (_frmDefectFine.ProductionLineRow != null)
  352. {
  353. _defectPositionID = Convert.ToInt32(_frmDefectFine.ProductionLineRow["defectPositionID"]);
  354. _defectPositionCode = _frmDefectFine.ProductionLineRow["defectPositionCode"].ToString() + "->" + _frmDefectFine.ProductionLineRow["defectPositionName"].ToString();
  355. //_procedureName = _frmDefectFine.ProductionLineRow["procedureName"].ToString();
  356. this.Text = _frmDefectFine.ProductionLineRow["defectPositionCode"].ToString();
  357. }
  358. }
  359. }
  360. }
  361. /// <summary>
  362. /// 清除控件的值
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. private void txtJobs_KeyDown(object sender, KeyEventArgs e)
  367. {
  368. this.txtJobs.Text = "";
  369. this._DefectFineID = null;
  370. this._DefectFineCodeCode = string.Empty;
  371. }
  372. /// <summary>
  373. /// 文本框文本改变事件
  374. /// </summary>
  375. /// <param name="sender"></param>
  376. /// <param name="e"></param>
  377. private void txtJobs_TextChanged(object sender, EventArgs e)
  378. {
  379. if (UserValueChanged != null)
  380. {
  381. UserValueChanged(this, new TextChangeEventArgs(this.txtJobs.Text));
  382. }
  383. }
  384. #endregion
  385. #region 私有方法
  386. /// <summary>
  387. /// 设置控件的样式
  388. /// </summary>
  389. protected void AdjustControl()
  390. {
  391. // 取得按钮控件的宽度和高度
  392. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  393. this.Height = this.btnSearch.Height;
  394. // 设置控件的尺寸和位置。
  395. this.txtJobs.Location = new System.Drawing.Point(this.lblPost.Width +
  396. ControlsConst.CONTROLSPACE, (this.Height - this.txtJobs.Height) / 2);
  397. this.txtJobs.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  398. (this.lblPost.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  399. this.btnSearch.Location =
  400. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  401. (this.Height - this.btnSearch.Height) / 2);
  402. // 设置标签的尺寸和位置。
  403. this.lblPost.Location =
  404. new System.Drawing.Point(0, (this.Height - this.lblPost.Height) / 2);
  405. this.lblPost.Size = new System.Drawing.Size(this.lblPost.Width, this.lblPost.Height);
  406. }
  407. /// <summary>
  408. /// 过滤数据源
  409. /// </summary>
  410. /// <param name="dataSource"></param>
  411. /// <returns></returns>
  412. protected DataTable SetFilter(DataTable dataSource)
  413. {
  414. return dataSource;
  415. }
  416. /// <summary>
  417. /// 调用服务方法获取用户信息
  418. /// </summary>
  419. /// <returns></returns>
  420. private DataTable GetAllScdefectPosition()
  421. {
  422. DataSet userDataSet = SystemModuleProxy.Service.GetAllScdefectPosition();
  423. if (userDataSet == null)
  424. {
  425. return new DataTable();
  426. }
  427. if (userDataSet.Tables.Count <= 0)
  428. {
  429. return new DataTable();
  430. }
  431. if (!userDataSet.Tables[0].Columns.Contains("Sel"))
  432. {
  433. userDataSet.Tables[0].Columns.Add("Sel", typeof(int));
  434. }
  435. DataView dv = userDataSet.Tables[0].DefaultView;
  436. dv.RowFilter = "ValueFlag='1'";
  437. return dv.ToTable();
  438. }
  439. #endregion
  440. /// <summary>
  441. /// 清空控件的值
  442. /// </summary>
  443. /// <param name="dataSource"></param>
  444. /// <returns></returns>
  445. public void ClearControl()
  446. {
  447. this.txtJobs.Text = string.Empty;
  448. this._defectPositionID = null;
  449. this._defectPositionName = string.Empty;
  450. this._defectPositionCode = string.Empty;
  451. this._defectPositionIDS = string.Empty;
  452. }
  453. }
  454. }