dkThermometerSearchBox.cs 18 KB

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