dkGoodsTypeCodeSearchBox.cs 20 KB

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