dkGoodsTypeSearchBox.cs 20 KB

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