dkInChecked.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:dkInChecked.cs
  5. * 2.功能描述:盘点选择控件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/09/15 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.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. namespace Dongke.IBOSS.PRD.Client.Controls.SearchTextBox
  20. {
  21. public partial class dkInChecked : UserControl
  22. {
  23. #region 成员变量
  24. /// <summary>
  25. /// 数据选择窗体
  26. /// </summary>
  27. private S_CMN_021 _frmInChecked;
  28. /// <summary>
  29. /// 控件是否可用
  30. /// </summary>
  31. private bool _isEnabled = true;
  32. /// <summary>
  33. /// 数据源
  34. /// </summary>
  35. private DataTable _dataSource = null;
  36. /// <summary>
  37. /// 盘点单ID
  38. /// </summary>
  39. private int? _inCheckedID;
  40. /// <summary>
  41. /// 盘点单号
  42. /// </summary>
  43. private string _inCheckedNo;
  44. /// <summary>
  45. /// 控件是否是必须输入项目
  46. /// </summary>
  47. private bool _isMustInput;
  48. /// <summary>
  49. /// 是否只显示有效数据
  50. /// </summary>
  51. private bool _IsOnlyShowValid = true;
  52. #endregion
  53. #region 构造函数
  54. public dkInChecked()
  55. {
  56. InitializeComponent();
  57. this.ReadOnly = true;
  58. }
  59. #endregion
  60. #region 属性
  61. /// <summary>
  62. /// 是否只显示有效数据
  63. /// </summary>
  64. [Description("设置控件是否只显示有效数据。")]
  65. [DefaultValue(true)]
  66. public bool IsOnlyShowValid
  67. {
  68. get
  69. {
  70. return _IsOnlyShowValid;
  71. }
  72. set
  73. {
  74. _IsOnlyShowValid = value;
  75. }
  76. }
  77. /// <summary>
  78. /// 获取或者设定控件是否是必须输入项目
  79. /// </summary>
  80. [DefaultValue("False")]
  81. [Description("获取或者设定控件是否是必须输入项目。")]
  82. public bool IsMustInput
  83. {
  84. get
  85. {
  86. return _isMustInput;
  87. }
  88. set
  89. {
  90. _isMustInput = value;
  91. // 项目为必须输入项时,需要修改字体颜色
  92. if (_isMustInput)
  93. {
  94. this.lblPost.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
  95. }
  96. else
  97. {
  98. this.lblPost.ForeColor = System.Drawing.SystemColors.ControlText;
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// Lable标签文本
  104. /// </summary>
  105. [DefaultValue("工种名称")]
  106. [Description("获取或者设定Lable标签字符。")]
  107. public string Title
  108. {
  109. get
  110. {
  111. return this.lblPost.Text;
  112. }
  113. set
  114. {
  115. this.lblPost.Text = value;
  116. AdjustControl();
  117. }
  118. }
  119. /// <summary>
  120. /// 获取或者设定控件的数据源。
  121. /// </summary>
  122. [Description("获取或者设定控件的数据源。")]
  123. public DataTable DataSource
  124. {
  125. get
  126. {
  127. return _dataSource;
  128. }
  129. set
  130. {
  131. DataTable dataSource = SetFilter(value);
  132. _dataSource = dataSource;
  133. }
  134. }
  135. /// <summary>
  136. /// 获取或者设定控件的尺寸大小。
  137. /// </summary>
  138. [Description("获取或者设定控件的尺寸大小。")]
  139. public new Size Size
  140. {
  141. get
  142. {
  143. return base.Size;
  144. }
  145. set
  146. {
  147. base.Size = value;
  148. AdjustControl();
  149. }
  150. }
  151. /// <summary>
  152. /// 获取或者设定控件的文本框的文本字符串。
  153. /// </summary>
  154. [Description("获取或者设定控件的文本框的文本字符串。")]
  155. public override string Text
  156. {
  157. get
  158. {
  159. return this.txtJobs.Text;
  160. }
  161. set
  162. {
  163. this.txtJobs.Text = value;
  164. }
  165. }
  166. /// <summary>
  167. /// 获取或者设定控件的文本框的背景颜色。
  168. /// </summary>
  169. [Description("获取或者设定控件的文本框的背景颜色。")]
  170. public Color TxtUserBackColor
  171. {
  172. get
  173. {
  174. return this.txtJobs.BackColor;
  175. }
  176. set
  177. {
  178. this.txtJobs.BackColor = value;
  179. }
  180. }
  181. /// <summary>
  182. /// 获取或者设定控件的职务ID。
  183. /// </summary>
  184. [Description("获取或者设定控件的职务ID。")]
  185. [DefaultValue(null)]
  186. public int? InCheckedID
  187. {
  188. get
  189. {
  190. return _inCheckedID;
  191. }
  192. set
  193. {
  194. this._inCheckedID = null;
  195. this._inCheckedNo = string.Empty;
  196. this.Text = string.Empty;
  197. if (value != null)
  198. {
  199. // 当数据源为null时,查询数据源
  200. if (DataSource == null)
  201. {
  202. // 查询数据源
  203. DataSource = GetInChecked();
  204. }
  205. if (value != null && value != 0 && this.DataSource != null)
  206. {
  207. DataTable userTable = this.DataSource.Copy();
  208. DataRow[] dataRows = userTable.Select("InCheckedID = " + value);
  209. if (dataRows.Length == 1)
  210. {
  211. this._inCheckedID = value;
  212. this._inCheckedNo = dataRows[0]["InCheckedNo"] as string;
  213. this.Text = dataRows[0]["InCheckedNo"] as string;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. /// <summary>
  220. /// 获取或者设定控件的盘点单号
  221. /// </summary>
  222. [Description("获取或者设定控件的盘点单号。")]
  223. public string InCheckedNo
  224. {
  225. get
  226. {
  227. return _inCheckedNo;
  228. }
  229. set
  230. {
  231. _inCheckedNo = value;
  232. }
  233. }
  234. /// <summary>
  235. /// 获取或者设定控件是否可用。
  236. /// </summary>
  237. [System.ComponentModel.DefaultValue(null)]
  238. [Description("获取或者设定控件是否可用。")]
  239. public new bool Enabled
  240. {
  241. get
  242. {
  243. return _isEnabled;
  244. }
  245. set
  246. {
  247. _isEnabled = value;
  248. this.txtJobs.Enabled = _isEnabled;
  249. this.TabStop = _isEnabled;
  250. }
  251. }
  252. /// <summary>
  253. /// 获取或者设定控件是否只读。
  254. /// </summary>
  255. [System.ComponentModel.DefaultValue(null)]
  256. [Description("获取或者设定控件是否只读。")]
  257. public bool ReadOnly
  258. {
  259. set
  260. {
  261. this.txtJobs.ReadOnly = value;
  262. }
  263. }
  264. /// <summary>
  265. /// 范围权限
  266. /// </summary>
  267. public byte PurviewType
  268. {
  269. get;
  270. set;
  271. }
  272. /// <summary>
  273. /// 盘点类型 0:在产盘点 1:注浆盘点 2:模具盘点
  274. /// </summary>
  275. [System.ComponentModel.DefaultValue(0)]
  276. public int CheckType
  277. {
  278. get;
  279. set;
  280. }
  281. #endregion
  282. #region 定义委托事件
  283. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  284. public event TextBoxChangedHandle UserValueChanged;
  285. #endregion
  286. #region 控件事件
  287. public class TextChangeEventArgs : EventArgs
  288. {
  289. public TextChangeEventArgs(string message)
  290. {
  291. }
  292. }
  293. /// <summary>
  294. /// 控件尺寸大小改变事件
  295. /// </summary>
  296. /// <param name="sender"></param>
  297. /// <param name="e"></param>
  298. private void dkJobsSearchBox_SizeChanged(object sender, EventArgs e)
  299. {
  300. AdjustControl();
  301. }
  302. /// <summary>
  303. /// 查询按钮按下事件
  304. /// </summary>
  305. /// <param name="sender"></param>
  306. /// <param name="e"></param>
  307. private void btnSearch_Click(object sender, EventArgs e)
  308. {
  309. // 如果属性是不可用,是不能进行点击事件的
  310. if (!Enabled)
  311. {
  312. return;
  313. }
  314. // 当数据源为null时,查询数据源
  315. if (DataSource == null)
  316. {
  317. // 查询数据源
  318. DataSource = GetInChecked();
  319. }
  320. // 释放窗体资源
  321. if (null != _frmInChecked)
  322. {
  323. _frmInChecked.Dispose();
  324. _frmInChecked = null;
  325. }
  326. // 打开查询窗体
  327. _frmInChecked = new S_CMN_021();
  328. _frmInChecked.DataSource = this.DataSource;
  329. DialogResult dialogResult = _frmInChecked.ShowDialog();
  330. // 查询窗体返回值给控件赋值
  331. if (dialogResult.Equals(DialogResult.OK))
  332. {
  333. if (_frmInChecked.DataRow != null)
  334. {
  335. _inCheckedID = Convert.ToInt32(_frmInChecked.DataRow["InCheckedID"]);
  336. _inCheckedNo = _frmInChecked.DataRow["InCheckedNo"].ToString();
  337. this.Text = _frmInChecked.DataRow["InCheckedNo"].ToString();
  338. }
  339. }
  340. }
  341. /// <summary>
  342. /// 清除控件的值
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. private void txtJobs_KeyDown(object sender, KeyEventArgs e)
  347. {
  348. this.txtJobs.Text = "";
  349. this._inCheckedID = null;
  350. this._inCheckedNo = string.Empty;
  351. }
  352. /// <summary>
  353. /// 文本框文本改变事件
  354. /// </summary>
  355. /// <param name="sender"></param>
  356. /// <param name="e"></param>
  357. private void txtJobs_TextChanged(object sender, EventArgs e)
  358. {
  359. if (UserValueChanged != null)
  360. {
  361. UserValueChanged(this, new TextChangeEventArgs(this.txtJobs.Text));
  362. }
  363. }
  364. #endregion
  365. #region 私有方法
  366. /// <summary>
  367. /// 设置控件的样式
  368. /// </summary>
  369. protected void AdjustControl()
  370. {
  371. // 取得按钮控件的宽度和高度
  372. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  373. this.Height = this.btnSearch.Height;
  374. // 设置控件的尺寸和位置。
  375. this.txtJobs.Location = new System.Drawing.Point(this.lblPost.Width +
  376. ControlsConst.CONTROLSPACE, (this.Height - this.txtJobs.Height) / 2);
  377. this.txtJobs.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  378. (this.lblPost.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  379. this.btnSearch.Location =
  380. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  381. (this.Height - this.btnSearch.Height) / 2);
  382. // 设置标签的尺寸和位置。
  383. this.lblPost.Location =
  384. new System.Drawing.Point(0, (this.Height - this.lblPost.Height) / 2);
  385. this.lblPost.Size = new System.Drawing.Size(this.lblPost.Width, this.lblPost.Height);
  386. }
  387. /// <summary>
  388. /// 过滤数据源
  389. /// </summary>
  390. /// <param name="dataSource"></param>
  391. /// <returns></returns>
  392. protected DataTable SetFilter(DataTable dataSource)
  393. {
  394. return dataSource;
  395. }
  396. /// <summary>
  397. /// 调用服务方法获取用户信息
  398. /// </summary>
  399. /// <returns></returns>
  400. private DataTable GetInChecked()
  401. {
  402. DataSet userDataSet = null;
  403. if (CheckType == 0)
  404. {
  405. userDataSet = PMModuleProxy.Service.GetInCheckedList();
  406. }
  407. else if (CheckType == 1)
  408. {
  409. ClientRequestEntity cre = new ClientRequestEntity();
  410. cre.NameSpace = "GBChecked";
  411. cre.Name = "seachbox_GetList";
  412. ServiceResultEntity sre = PMModuleProxyNew.Service.HandleRequest(cre);
  413. if (sre.Status == Basics.BaseResources.Constant.ServiceResultStatus.Success)
  414. {
  415. userDataSet = sre.Data;
  416. }
  417. }
  418. else if (CheckType == 2)
  419. {
  420. ClientRequestEntity cre = new ClientRequestEntity();
  421. cre.NameSpace = "FPC1101";
  422. cre.Name = "seachbox_GetList";
  423. ServiceResultEntity sre = PCModuleProxyNew.Service.HandleRequest(cre);
  424. if (sre.Status == Basics.BaseResources.Constant.ServiceResultStatus.Success)
  425. {
  426. userDataSet = sre.Data;
  427. }
  428. }
  429. if (userDataSet == null)
  430. {
  431. return new DataTable();
  432. }
  433. if (userDataSet.Tables.Count <= 0)
  434. {
  435. return new DataTable();
  436. }
  437. return userDataSet.Tables[0];
  438. }
  439. #endregion
  440. }
  441. }