dkGoodsCodeSearchBox.cs 16 KB

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