ScbSearch2Box.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Design;
  8. using System.Reflection;
  9. using System.Windows.Forms;
  10. using Dongke.WinForm.Utilities;
  11. namespace Dongke.WinForm.Controls
  12. {
  13. /// <summary>
  14. /// 查询文本框控件(2个文本框)
  15. /// </summary>
  16. [ToolboxBitmap(typeof(ScbSearchBox), "ToolboxBitmap.SearchBox_00.bmp")]
  17. [DefaultEvent("SelectedItemChanged"), DefaultProperty("SearchText")]
  18. public partial class ScbSearch2Box : ScbSearchBox
  19. {
  20. #region 事件声明
  21. #endregion
  22. #region 成员变量
  23. ///// <summary>
  24. ///// 为此控件显示的属性
  25. ///// </summary>
  26. private string _displayMember2 = string.Empty;
  27. /// <summary>
  28. /// 初始化的文本
  29. /// </summary>
  30. private string _initText2 = null;
  31. /// <summary>
  32. /// 初始化的值
  33. /// </summary>
  34. private object _initValue2 = null;
  35. #endregion
  36. #region 构造函数
  37. /// <summary>
  38. /// 查询文本框控件
  39. /// </summary>
  40. private ScbSearch2Box(bool isInitControls = true)
  41. :base(false)
  42. {
  43. InitializeComponent();
  44. if (isInitControls)
  45. {
  46. this.InitQueryControls();
  47. }
  48. this.txtCondition2.TextChanged += this.Condition_TextChanged;
  49. this.txtCondition2.KeyDown += this.Condition_KeyDown;
  50. }
  51. #endregion
  52. #region 属性
  53. /// <summary>
  54. /// 获取或设置查询条件2(多选时,不能设置)。
  55. /// </summary>
  56. [Description("获取或设置查询条件2(多选时,不能设置)。"), Category("CustomerEx")]
  57. [DefaultValue("")]
  58. public string Text2
  59. {
  60. get
  61. {
  62. return this.txtCondition2.Text;
  63. }
  64. set
  65. {
  66. if (!this.MultiSelect)
  67. {
  68. this.txtCondition2.Text = value;
  69. }
  70. }
  71. }
  72. /// <summary>
  73. /// 获取或设置控件的显示的属性
  74. /// </summary>
  75. [Description("获取或设置控件的显示的属性。"), Category("CustomerEx")]
  76. [DefaultValue("")]
  77. public virtual string DisplayMember2
  78. {
  79. get
  80. {
  81. return this._displayMember2;
  82. }
  83. set
  84. {
  85. if (value == null)
  86. {
  87. value = string.Empty;
  88. }
  89. if (this._displayMember2 != value)
  90. {
  91. this._displayMember2 = value;
  92. this.ResetDisplayText();
  93. }
  94. }
  95. }
  96. /// <summary>
  97. /// 获取选择的项目的文本表示形式。
  98. /// </summary>
  99. [Description("获取选择的项目的文本表示形式。"), Category("CustomerEx")]
  100. [Browsable(false)]
  101. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  102. [EditorBrowsable(EditorBrowsableState.Advanced)]
  103. public string SearchedText2
  104. {
  105. get
  106. {
  107. if (this.ValueFrom == SearchBoxValueFrom.InitValue)
  108. {
  109. return this._initText2;
  110. }
  111. if (this.ValueFrom != SearchBoxValueFrom.SearchForm)
  112. {
  113. return null;
  114. }
  115. if (this._checkedData == null ||
  116. this._checkedData.Rows.Count == 0 ||
  117. !this._checkedData.Columns.Contains(this._displayMember2))
  118. {
  119. return null;
  120. }
  121. return this.FormatDisplay(this._checkedData.Rows[0][this._displayMember2]);
  122. }
  123. }
  124. /// <summary>
  125. /// 获取选定的项目的文本表示形式。
  126. /// </summary>
  127. [Description("获取选定的项目的文本表示形式。"), Category("CustomerEx")]
  128. [Browsable(false)]
  129. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  130. [EditorBrowsable(EditorBrowsableState.Advanced)]
  131. public string[] CheckedTexts2
  132. {
  133. get
  134. {
  135. if (this.ValueFrom != SearchBoxValueFrom.SearchForm)
  136. {
  137. return null;
  138. }
  139. if (this._checkedData == null ||
  140. this._checkedData.Rows.Count == 0 ||
  141. !this._checkedData.Columns.Contains(this._displayMember2))
  142. {
  143. return null;
  144. }
  145. string[] values = new string[this._checkedData.Rows.Count];
  146. for (int i = 0; i < this._checkedData.Rows.Count; i++)
  147. {
  148. values[i] = this.FormatDisplay(this._checkedData.Rows[i][this._displayMember2]);
  149. }
  150. return values;
  151. }
  152. }
  153. /// <summary>
  154. /// 获取选定的项目的文本表示形式,用【,】隔开。
  155. /// </summary>
  156. [Description("获取选定的项目的文本表示形式,用【,】隔开。"), Category("CustomerEx")]
  157. [Browsable(false)]
  158. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  159. [EditorBrowsable(EditorBrowsableState.Advanced)]
  160. public string CheckedText2
  161. {
  162. get
  163. {
  164. if (this.ValueFrom != SearchBoxValueFrom.SearchForm)
  165. {
  166. return null;
  167. }
  168. string[] values = this.CheckedTexts2;
  169. if (values == null)
  170. {
  171. return string.Empty;
  172. }
  173. string value =
  174. string.Join(Constant.MULTIPLE_TEXT_SEPARATOR,
  175. values);
  176. return value;
  177. }
  178. }
  179. #endregion
  180. #region 重写属性
  181. #endregion
  182. #region 事件处理
  183. #endregion
  184. #region 公有方法
  185. /// <summary>
  186. /// 打开查询窗体
  187. /// </summary>
  188. public override void ShowSearchForm()
  189. {
  190. if (!this.MultiSelect)
  191. {
  192. this.SearchForm.SetConditions(this.txtCondition1.Text, this.txtCondition2.Text);
  193. }
  194. this.SearchForm.Show();
  195. }
  196. /// <summary>
  197. /// 初始化显示的值
  198. /// </summary>
  199. /// <param name="text"></param>
  200. /// <param name="value"></param>
  201. /// <param name="text2"></param>
  202. /// <param name="value2"></param>
  203. public virtual void InitValue(string text, object value, string text2, object value2)
  204. {
  205. this._initText2 = text2;
  206. this._initValue2 = value2;
  207. this.txtCondition2.Text = text2;
  208. base.InitValue(text, value);
  209. }
  210. #endregion
  211. #region 保护方法
  212. /// <summary>
  213. /// 初始化查询文本框集合
  214. /// </summary>
  215. protected override void InitQueryControls()
  216. {
  217. //base.InitQueryControls();
  218. this._queryControls.Add(this.txtCondition1);
  219. this._queryControls.Add(this.txtCondition2);
  220. }
  221. /// <summary>
  222. /// 选择窗体关闭时,设置显示文本。
  223. /// </summary>
  224. protected override void ResetDisplayText()
  225. {
  226. this._resetText = true;
  227. this.txtCondition2.Text = this.CheckedText2;
  228. base.ResetDisplayText();
  229. }
  230. /// <summary>
  231. /// 设置文本框只读
  232. /// </summary>
  233. protected override void SetEditReadOnly()
  234. {
  235. base.SetEditReadOnly();
  236. this.txtCondition2.ReadOnly = this.txtCondition1.ReadOnly;
  237. }
  238. #endregion
  239. #region 私有方法
  240. #endregion
  241. #region IDataVerifiable 成员
  242. /// <summary>
  243. /// 清除输入项
  244. /// </summary>
  245. public override void ClearValue()
  246. {
  247. //this.txtCondition2.ClearValue();
  248. base.ClearValue();
  249. }
  250. #endregion
  251. }
  252. }