ScbSearchBox.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664
  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. /// 查询文本框控件
  15. /// </summary>
  16. [ToolboxBitmap(typeof(ScbSearchBox), "ToolboxBitmap.SearchBox_00.bmp")]
  17. [DefaultEvent("SelectedItemChanged"), DefaultProperty("SearchText")]
  18. public partial class ScbSearchBox : UserControl, IDKControl,
  19. IDataVerifiable, IAsyncControl
  20. {
  21. #region 事件声明
  22. #region HasErrorChanged
  23. /// <summary>
  24. /// 当 HasError 属性的值更改时发生。
  25. /// </summary>
  26. private static readonly object EventHasErrorChanged = new object();
  27. /// <summary>
  28. /// 当 HasError 属性的值更改时发生。
  29. /// </summary>
  30. [Description("当 HasError 属性的值更改时发生。"), Category("CustomerEx")]
  31. public event EventHandler HasErrorChanged
  32. {
  33. add
  34. {
  35. base.Events.AddHandler(EventHasErrorChanged, value);
  36. }
  37. remove
  38. {
  39. base.Events.RemoveHandler(EventHasErrorChanged, value);
  40. }
  41. }
  42. /// <summary>
  43. /// 引发 HasErrorChanged 事件
  44. /// </summary>
  45. /// <param name="e">包含事件数据的 EventArgs</param>
  46. protected virtual void OnHasErrorChanged(EventArgs e)
  47. {
  48. EventHandler eventHandler = (EventHandler)base.Events[EventHasErrorChanged];
  49. if (eventHandler != null)
  50. {
  51. eventHandler(this, e);
  52. }
  53. }
  54. #endregion
  55. #region ReadOnlyChanged
  56. /// <summary>
  57. /// 当 ReadOnly 属性的值更改时发生。
  58. /// </summary>
  59. private static readonly object EventReadOnlyChanged = new object();
  60. /// <summary>
  61. /// 当 ReadOnly 属性的值更改时发生
  62. /// </summary>
  63. [Description("当 ReadOnly 属性的值更改时发生。"), Category("CustomerEx")]
  64. public event EventHandler ReadOnlyChanged
  65. {
  66. add
  67. {
  68. base.Events.AddHandler(EventReadOnlyChanged, value);
  69. }
  70. remove
  71. {
  72. base.Events.RemoveHandler(EventReadOnlyChanged, value);
  73. }
  74. }
  75. /// <summary>
  76. /// 引发 ReadOnlyChanged 事件
  77. /// </summary>
  78. /// <param name="e"></param>
  79. protected virtual void OnReadOnlyChanged(EventArgs e)
  80. {
  81. EventHandler eventHandler = base.Events[EventReadOnlyChanged] as EventHandler;
  82. if (eventHandler != null)
  83. {
  84. eventHandler(this, e);
  85. }
  86. }
  87. #endregion
  88. #region EditReadOnlyChanged
  89. /// <summary>
  90. /// 当 EditReadOnly 属性的值更改时发生。
  91. /// </summary>
  92. private static readonly object EventEditReadOnlyChanged = new object();
  93. /// <summary>
  94. /// 当 EditReadOnly 属性的值更改时发生
  95. /// </summary>
  96. [Description("当 EditReadOnly 属性的值更改时发生。"), Category("CustomerEx")]
  97. public event EventHandler EditReadOnlyChanged
  98. {
  99. add
  100. {
  101. base.Events.AddHandler(EventEditReadOnlyChanged, value);
  102. }
  103. remove
  104. {
  105. base.Events.RemoveHandler(EventEditReadOnlyChanged, value);
  106. }
  107. }
  108. /// <summary>
  109. /// 引发 EditReadOnlyChanged 事件
  110. /// </summary>
  111. /// <param name="e"></param>
  112. protected virtual void OnEditReadOnlyChanged(EventArgs e)
  113. {
  114. EventHandler eventHandler = base.Events[EventEditReadOnlyChanged] as EventHandler;
  115. if (eventHandler != null)
  116. {
  117. eventHandler(this, e);
  118. }
  119. }
  120. #endregion
  121. #region SearchedItemChanged
  122. /// <summary>
  123. /// 当 SelectedItem 属性的值更改时发生。
  124. /// </summary>
  125. private static readonly object EventSearchedItemChanged = new object();
  126. /// <summary>
  127. /// 当 SelectedItem 属性的值更改时发生
  128. /// </summary>
  129. [Description("当 SearchedItem 属性的值更改时发生。"), Category("CustomerEx")]
  130. public event EventHandler SearchedItemChanged
  131. {
  132. add
  133. {
  134. base.Events.AddHandler(EventSearchedItemChanged, value);
  135. }
  136. remove
  137. {
  138. base.Events.RemoveHandler(EventSearchedItemChanged, value);
  139. }
  140. }
  141. /// <summary>
  142. /// 引发 SelectedItem 事件
  143. /// </summary>
  144. /// <param name="e"></param>
  145. protected virtual void OnSearchedItemChanged(EventArgs e)
  146. {
  147. EventHandler eventHandler = base.Events[EventSearchedItemChanged] as EventHandler;
  148. if (eventHandler != null)
  149. {
  150. eventHandler(this, e);
  151. }
  152. }
  153. #endregion
  154. #region TextValueChanged
  155. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  156. public event TextBoxChangedHandle TextValueChanged;
  157. public class TextChangeEventArgs : EventArgs
  158. {
  159. public TextChangeEventArgs(string message)
  160. {
  161. }
  162. }
  163. private void txtCondition1_TextChanged(object sender, EventArgs e)
  164. {
  165. if (TextValueChanged != null)
  166. {
  167. TextValueChanged(this, new TextChangeEventArgs(this.txtCondition1.Text));
  168. }
  169. }
  170. #endregion
  171. #endregion
  172. #region 成员变量
  173. /// <summary>
  174. /// 查询窗体
  175. /// </summary>
  176. protected ISearchBoxForm _searchForm = null;
  177. /// <summary>
  178. /// 指示是否能够多项选择。
  179. /// </summary>
  180. private bool _multiSelect = false;
  181. /// <summary>
  182. /// 指示控件中的文本是否为只读
  183. /// </summary>
  184. private bool _editReadOnly = true;
  185. /// <summary>
  186. /// 指示控件中是否为只读
  187. /// </summary>
  188. private bool _readOnly = false;
  189. ///// <summary>
  190. ///// 为此控件显示的属性集合
  191. ///// </summary>
  192. //List<string> _displayMembers = new List<string>();
  193. ///// <summary>
  194. ///// 查询条件控件集合
  195. ///// </summary>
  196. //List<TxtTextBox> _queryConditions = new List<TxtTextBox>();
  197. ///// <summary>
  198. ///// 为此控件显示的属性
  199. ///// </summary>
  200. private string _displayMember = string.Empty;
  201. /// <summary>
  202. /// 用作此控件中的项的实际值
  203. /// </summary>
  204. private string _valueMember = string.Empty;
  205. /// <summary>
  206. /// 0:手动输入,1:SearchForm,2:初始化
  207. /// </summary>
  208. private SearchBoxValueFrom _valueFrom = SearchBoxValueFrom.UserInput;
  209. /// <summary>
  210. /// 查询的范围权限类型
  211. /// </summary>
  212. private PurviewType _purviewType = PurviewType.None;
  213. /// <summary>
  214. /// 初始化的文本
  215. /// </summary>
  216. private string _initText = null;
  217. /// <summary>
  218. /// 初始化的值
  219. /// </summary>
  220. private object _initValue = null;
  221. /// <summary>
  222. /// 选定的数据
  223. /// </summary>
  224. protected DataTable _checkedData = null;
  225. /// <summary>
  226. /// 选定后给文本框赋值时
  227. /// </summary>
  228. protected bool _resetText = false;
  229. /// <summary>
  230. /// 查询条件文本框的集合
  231. /// </summary>
  232. protected List<TextBox> _queryControls = new List<TextBox>();
  233. protected int _searchedPKMember;
  234. #endregion
  235. #region 构造函数
  236. /// <summary>
  237. /// 查询文本框控件
  238. /// </summary>
  239. public ScbSearchBox()
  240. :this(true)
  241. {
  242. }
  243. /// <summary>
  244. /// 查询文本框控件
  245. /// </summary>
  246. public ScbSearchBox(bool isInitControls = true)
  247. {
  248. this.InitializeComponent();
  249. CommonSetting.InitControls(this);
  250. if (isInitControls)
  251. {
  252. this.InitQueryControls();
  253. }
  254. this._searchForm = this.CreatSearchForm();
  255. if (this._searchForm != null)
  256. {
  257. //throw new NullReferenceException("SearchBoxForm");
  258. this._searchForm.FormClosed += this.SearchBoxForm_FormClosed;
  259. }
  260. this.txtCondition1.TextChanged += this.Condition_TextChanged;
  261. this.txtCondition1.KeyDown += this.Condition_KeyDown;
  262. }
  263. #endregion
  264. #region 属性
  265. /// <summary>
  266. /// 设置或获取选定的数据
  267. /// </summary>
  268. [DefaultValue("设置或获取选定的数据")]
  269. public virtual DataTable CheckedData
  270. {
  271. get
  272. {
  273. return _checkedData;
  274. }
  275. set
  276. {
  277. this._checkedData = value;
  278. }
  279. }
  280. /// <summary>
  281. /// 窗体标题
  282. /// </summary>
  283. [DefaultValue("")]
  284. public virtual string FormText
  285. {
  286. get
  287. {
  288. if (this._searchForm == null)
  289. {
  290. return string.Empty;
  291. }
  292. return this._searchForm.Text;
  293. }
  294. set
  295. {
  296. if (this._searchForm == null)
  297. {
  298. return;
  299. }
  300. this._searchForm.Text = value;
  301. }
  302. }
  303. /// <summary>
  304. /// 获取或设置查询条件(多选时,不能设置)。
  305. /// </summary>
  306. [Description("获取或设置查询条件(多选时,不能设置)。"), Category("CustomerEx")]
  307. [DefaultValue("")]
  308. [Browsable(true)]
  309. //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  310. //[EditorBrowsable(EditorBrowsableState.Advanced)]
  311. public override string Text
  312. {
  313. get
  314. {
  315. return this.txtCondition1.Text;
  316. }
  317. set
  318. {
  319. if (!this.MultiSelect /*&& !this.EditReadOnly && !this.ReadOnly*/)
  320. {
  321. this.txtCondition1.Text = value;
  322. }
  323. //base.Text = value;
  324. }
  325. }
  326. /// <summary>
  327. ///
  328. /// </summary>
  329. public TextBox Condition
  330. {
  331. get
  332. {
  333. return this.txtCondition1;
  334. }
  335. }
  336. /// <summary>
  337. /// 获取或设置一个值,该值指示文本框中的文本是否为只读。
  338. /// </summary>
  339. [Description("获取或设置一个值,该值指示文本框中的文本是否为只读。"), Category("CustomerEx")]
  340. [DefaultValue(false)]
  341. public virtual bool ReadOnly
  342. {
  343. get
  344. {
  345. return this._readOnly;
  346. }
  347. set
  348. {
  349. if (this._readOnly != value)
  350. {
  351. this._readOnly = value;
  352. this.SetReadOnly();
  353. this.OnReadOnlyChanged(EventArgs.Empty);
  354. }
  355. }
  356. }
  357. /// <summary>
  358. /// 获取或设置一个值,该值指示文本框中的文本是否为只读。
  359. /// </summary>
  360. [Description("获取或设置一个值,该值指示文本框中的文本是否为只读。"), Category("CustomerEx")]
  361. [DefaultValue(true)]
  362. public virtual bool EditReadOnly
  363. {
  364. get
  365. {
  366. if (this.MultiSelect)
  367. {
  368. this._editReadOnly = true;
  369. }
  370. return this._editReadOnly;
  371. }
  372. set
  373. {
  374. if (this.MultiSelect)
  375. {
  376. value = true;
  377. }
  378. if (this._editReadOnly != value)
  379. {
  380. this._editReadOnly = value;
  381. this.SetEditReadOnly();
  382. this.OnEditReadOnlyChanged(EventArgs.Empty);
  383. }
  384. }
  385. }
  386. /// <summary>
  387. /// 获取或设置控件的显示的属性
  388. /// </summary>
  389. [Description("获取或设置控件的显示的属性。"), Category("CustomerEx")]
  390. [DefaultValue("")]
  391. public virtual string DisplayMember
  392. {
  393. get
  394. {
  395. //if (this._displayMembers.Count == 0)
  396. //{
  397. // return string.Empty;
  398. //}
  399. //return this._displayMembers[0];
  400. return this._displayMember;
  401. }
  402. set
  403. {
  404. if (value == null)
  405. {
  406. value = string.Empty;
  407. }
  408. if (this._displayMember != value)
  409. {
  410. this._displayMember = value;
  411. this.ResetDisplayText();
  412. }
  413. //if (this.DisplayMember != value)
  414. //{
  415. // if (this._displayMembers.Count == 0)
  416. // {
  417. // this._displayMembers.Add(value);
  418. // }
  419. // else
  420. // {
  421. // this._displayMembers[0] = value;
  422. // }
  423. // this.ResetDisplayText();
  424. //}
  425. }
  426. }
  427. /// <summary>
  428. /// 获取或设置一个属性,该属性将用作控件中的项的实际值。
  429. /// </summary>
  430. [Description("获取或设置一个属性,该属性将用作控件中的项的实际值。"), Category("CustomerEx")]
  431. [DefaultValue("")]
  432. public virtual string ValueMember
  433. {
  434. get
  435. {
  436. return this._valueMember;
  437. }
  438. set
  439. {
  440. this._valueMember = value;
  441. }
  442. }
  443. /// <summary>
  444. /// 获取或设置一个值,该值指示查询结果数据集中的主键。
  445. /// </summary>
  446. [Description("获取或设置一个值,该值指示查询结果数据集中的主键。"), Category("CustomerEx")]
  447. [DefaultValue("")]
  448. public virtual string PKMember
  449. {
  450. get
  451. {
  452. if (this._searchForm != null)
  453. {
  454. return this._searchForm.PKMember;
  455. }
  456. return null;
  457. }
  458. protected set
  459. {
  460. if (this._searchForm != null)
  461. {
  462. this._searchForm.PKMember = value;
  463. }
  464. }
  465. }
  466. /// <summary>
  467. /// 获取或设置一个值,该值指示是否能够多项选择。
  468. /// </summary>
  469. [Description("获取或设置一个值,该值指示是否能够多项选择。"), Category("CustomerEx")]
  470. [DefaultValue(false)]
  471. public virtual bool MultiSelect
  472. {
  473. get
  474. {
  475. if (this._searchForm != null)
  476. {
  477. this._multiSelect = this._searchForm.MultiSelect;
  478. }
  479. return this._multiSelect;
  480. }
  481. set
  482. {
  483. if (this._multiSelect != value)
  484. {
  485. this._multiSelect = value;
  486. if (this._searchForm != null)
  487. {
  488. this._searchForm.MultiSelect = value;
  489. }
  490. if (value)
  491. {
  492. this.EditReadOnly = value;
  493. }
  494. }
  495. }
  496. }
  497. /// <summary>
  498. /// 获取或设置限制查询的范围权限类型。
  499. /// </summary>
  500. [Description("获取或设置限制查询的范围权限类型。"), Category("CustomerEx")]
  501. [DefaultValue(typeof(PurviewType), "None")]
  502. public virtual PurviewType PurviewType
  503. {
  504. get
  505. {
  506. return this._purviewType;
  507. }
  508. set
  509. {
  510. if (!Enum.IsDefined(typeof(PurviewType), value))
  511. {
  512. return;
  513. }
  514. if (this._purviewType != value)
  515. {
  516. this._purviewType = value;
  517. if (this._searchForm != null)
  518. {
  519. this._searchForm.PurviewType = value;
  520. }
  521. }
  522. }
  523. }
  524. /// <summary>
  525. /// 获取查询窗体
  526. /// </summary>
  527. [Browsable(false)]
  528. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  529. [EditorBrowsable(EditorBrowsableState.Advanced)]
  530. public ISearchBoxForm SearchForm
  531. {
  532. get
  533. {
  534. return this._searchForm;
  535. }
  536. }
  537. /// <summary>
  538. /// 获取数据来源。
  539. /// </summary>
  540. [Description("获取数据来源。"), Category("CustomerEx")]
  541. [Browsable(false)]
  542. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  543. [EditorBrowsable(EditorBrowsableState.Advanced)]
  544. public SearchBoxValueFrom ValueFrom
  545. {
  546. get
  547. {
  548. return this._valueFrom;
  549. }
  550. }
  551. /// <summary>
  552. /// 获取选择的项目
  553. /// </summary>
  554. [Description("获取选择的项目。"), Category("CustomerEx")]
  555. [Browsable(false)]
  556. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  557. [EditorBrowsable(EditorBrowsableState.Advanced)]
  558. public DataRow SearchedItem
  559. {
  560. get
  561. {
  562. //if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  563. //{
  564. // return null;
  565. //}
  566. if (this._checkedData == null ||
  567. this._checkedData.Rows.Count == 0)
  568. {
  569. return null;
  570. }
  571. return this._checkedData.Rows[0];
  572. }
  573. }
  574. public object[] InitItems
  575. {
  576. get;
  577. private set;
  578. }
  579. /// <summary>
  580. /// 获取选择的项目的值。
  581. /// </summary>
  582. [Description("获取选择的项目的ID值。"), Category("CustomerEx")]
  583. [Browsable(false)]
  584. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  585. [EditorBrowsable(EditorBrowsableState.Advanced)]
  586. public int SearchedPKMember
  587. {
  588. set
  589. {
  590. _searchedPKMember = value;
  591. }
  592. get
  593. {
  594. //if (this._valueFrom == SearchBoxValueFrom.InitValue)
  595. //{
  596. // return this._initValue;
  597. //}
  598. //if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  599. //{
  600. // return null;
  601. //}
  602. if (this._checkedData == null ||
  603. this._checkedData.Rows.Count == 0 ||
  604. !this._checkedData.Columns.Contains(this.PKMember))
  605. {
  606. return _searchedPKMember;
  607. }
  608. int.TryParse(this._checkedData.Rows[0][this.PKMember] + "", out _searchedPKMember);
  609. return _searchedPKMember;
  610. }
  611. }
  612. /// <summary>
  613. /// 获取选择的项目的值。
  614. /// </summary>
  615. [Description("获取选择的项目的值。"), Category("CustomerEx")]
  616. [Browsable(false)]
  617. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  618. [EditorBrowsable(EditorBrowsableState.Advanced)]
  619. public object SearchedValue
  620. {
  621. get
  622. {
  623. //if (this._valueFrom == SearchBoxValueFrom.InitValue)
  624. //{
  625. // return this._initValue;
  626. //}
  627. //if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  628. //{
  629. // return null;
  630. //}
  631. if (this._checkedData == null ||
  632. this._checkedData.Rows.Count == 0 ||
  633. !this._checkedData.Columns.Contains(this._valueMember))
  634. {
  635. return this._initValue;
  636. }
  637. return this._checkedData.Rows[0][this._valueMember];
  638. }
  639. }
  640. /// <summary>
  641. /// 获取选择的项目的文本表示形式。
  642. /// </summary>
  643. [Description("获取选择的项目的文本表示形式。"), Category("CustomerEx")]
  644. [Browsable(false)]
  645. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  646. [EditorBrowsable(EditorBrowsableState.Advanced)]
  647. public string SearchedText
  648. {
  649. get
  650. {
  651. if (this._valueFrom == SearchBoxValueFrom.InitValue)
  652. {
  653. return this._initText;
  654. }
  655. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  656. {
  657. return null;
  658. }
  659. if (this._checkedData == null ||
  660. this._checkedData.Rows.Count == 0 ||
  661. !this._checkedData.Columns.Contains(this._displayMember))
  662. {
  663. return null;
  664. }
  665. return this.FormatDisplay(this._checkedData.Rows[0][this._displayMember]);
  666. }
  667. }
  668. /// <summary>
  669. /// 获取选定的项目
  670. /// </summary>
  671. [Description("获取选择的项目。"), Category("CustomerEx")]
  672. [Browsable(false)]
  673. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  674. [EditorBrowsable(EditorBrowsableState.Advanced)]
  675. public DataTable CheckedItems
  676. {
  677. get
  678. {
  679. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  680. {
  681. return null;
  682. }
  683. return this._checkedData;
  684. }
  685. }
  686. /// <summary>
  687. /// 获取选定的项目的值。
  688. /// </summary>
  689. [Description("获取选定的项目的值。"), Category("CustomerEx")]
  690. [Browsable(false)]
  691. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  692. [EditorBrowsable(EditorBrowsableState.Advanced)]
  693. public object[] CheckedValues
  694. {
  695. get
  696. {
  697. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  698. {
  699. return null;
  700. }
  701. if (this._checkedData == null ||
  702. this._checkedData.Rows.Count == 0 ||
  703. !this._checkedData.Columns.Contains(this._valueMember))
  704. {
  705. return null;
  706. }
  707. object[] values = new object[this._checkedData.Rows.Count];
  708. for (int i = 0; i < this._checkedData.Rows.Count; i++)
  709. {
  710. values[i] = this._checkedData.Rows[i][this._valueMember];
  711. }
  712. return values;
  713. }
  714. }
  715. /// <summary>
  716. /// 获取选定的项目的值,用【,】隔开。
  717. /// </summary>
  718. [Description("获取选定的项目的值,用【,】隔开。"), Category("CustomerEx")]
  719. //[Browsable(false)]
  720. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  721. [EditorBrowsable(EditorBrowsableState.Advanced)]
  722. public string CheckedValue
  723. {
  724. get
  725. {
  726. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  727. {
  728. return null;
  729. }
  730. object[] values = this.CheckedValues;
  731. if (values == null)
  732. {
  733. return string.Empty;
  734. }
  735. string value =
  736. string.Join(Constant.MULTIPLE_VALUE_SEPARATOR,
  737. values);
  738. return value;
  739. }
  740. }
  741. /// <summary>
  742. /// 获取选定的项目的ID。
  743. /// </summary>
  744. [Description("获取选定的项目的ID。"), Category("CustomerEx")]
  745. [Browsable(false)]
  746. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  747. [EditorBrowsable(EditorBrowsableState.Advanced)]
  748. public object[] CheckedPKMembers
  749. {
  750. get
  751. {
  752. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  753. {
  754. return null;
  755. }
  756. if (this._checkedData == null ||
  757. this._checkedData.Rows.Count == 0 ||
  758. !this._checkedData.Columns.Contains(this._valueMember))
  759. {
  760. return null;
  761. }
  762. object[] values = new object[this._checkedData.Rows.Count];
  763. for (int i = 0; i < this._checkedData.Rows.Count; i++)
  764. {
  765. values[i] = this._checkedData.Rows[i][PKMember];
  766. }
  767. return values;
  768. }
  769. }
  770. /// <summary>
  771. /// 获取选定的项目的ID,用【,】隔开。
  772. /// </summary>
  773. [Description("获取选定的项目的ID,用【,】隔开。"), Category("CustomerEx")]
  774. //[Browsable(false)]
  775. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  776. [EditorBrowsable(EditorBrowsableState.Advanced)]
  777. public string CheckedPKMember
  778. {
  779. get
  780. {
  781. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  782. {
  783. return null;
  784. }
  785. object[] values = this.CheckedPKMembers;
  786. if (values == null)
  787. {
  788. return string.Empty;
  789. }
  790. string value =
  791. string.Join(Constant.MULTIPLE_VALUE_SEPARATOR,
  792. values);
  793. return value;
  794. }
  795. }
  796. /// <summary>
  797. /// 获取选定的项目的文本表示形式。
  798. /// </summary>
  799. [Description("获取选定的项目的文本表示形式。"), Category("CustomerEx")]
  800. [Browsable(false)]
  801. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  802. [EditorBrowsable(EditorBrowsableState.Advanced)]
  803. public string[] CheckedTexts
  804. {
  805. get
  806. {
  807. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  808. {
  809. return null;
  810. }
  811. if (this._checkedData == null ||
  812. this._checkedData.Rows.Count == 0 ||
  813. !this._checkedData.Columns.Contains(this._displayMember))
  814. {
  815. return null;
  816. }
  817. string[] values = new string[this._checkedData.Rows.Count];
  818. for (int i = 0; i < this._checkedData.Rows.Count; i++)
  819. {
  820. values[i] = this.FormatDisplay(this._checkedData.Rows[i][this._displayMember]);
  821. }
  822. return values;
  823. }
  824. }
  825. /// <summary>
  826. /// 获取选定的项目的文本表示形式,用【,】隔开。
  827. /// </summary>
  828. [Description("获取选定的项目的文本表示形式,用【,】隔开。"), Category("CustomerEx")]
  829. [Browsable(false)]
  830. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  831. [EditorBrowsable(EditorBrowsableState.Advanced)]
  832. public string CheckedText
  833. {
  834. get
  835. {
  836. if (this._valueFrom != SearchBoxValueFrom.SearchForm)
  837. {
  838. return null;
  839. }
  840. string[] values = this.CheckedTexts;
  841. if (values == null)
  842. {
  843. return string.Empty;
  844. }
  845. string value =
  846. string.Join(Constant.MULTIPLE_TEXT_SEPARATOR,
  847. values);
  848. return value;
  849. }
  850. }
  851. /// <summary>
  852. /// 获取或设置其他自定义属性。
  853. /// </summary>
  854. [Description("获取或设置其他自定义属性。"), Category("CustomerEx")]
  855. [Browsable(false)]
  856. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  857. [EditorBrowsable(EditorBrowsableState.Advanced)]
  858. public ExtendedProperties Properties
  859. {
  860. get
  861. {
  862. if (this._searchForm == null)
  863. {
  864. return null;
  865. }
  866. return this._searchForm.Properties;
  867. }
  868. }
  869. #endregion
  870. #region 重写属性
  871. /// <summary>
  872. /// 获取或设置控件四周绘制的边框的类型
  873. /// </summary>
  874. [Description("获取或设置控件四周绘制的边框的类型。"), Category("CustomerEx")]
  875. [DefaultValue(typeof(BorderStyle), "None")]
  876. [Browsable(false)]
  877. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  878. [EditorBrowsable(EditorBrowsableState.Advanced)]
  879. public new BorderStyle BorderStyle
  880. {
  881. get
  882. {
  883. return base.BorderStyle;
  884. }
  885. set
  886. {
  887. base.BorderStyle = value;
  888. }
  889. }
  890. /// <summary>
  891. /// 获取或设置控件的背景色
  892. /// </summary>
  893. [DefaultValue(typeof(Color), "Transparent")]
  894. public override Color BackColor
  895. {
  896. get
  897. {
  898. return base.BackColor;
  899. }
  900. set
  901. {
  902. base.BackColor = value;
  903. }
  904. }
  905. #endregion
  906. #region 事件处理
  907. /// <summary>
  908. /// 键盘按下
  909. /// </summary>
  910. /// <param name="sender"></param>
  911. /// <param name="e"></param>
  912. protected void Condition_KeyDown(object sender, KeyEventArgs e)
  913. {
  914. if (this.EditReadOnly && !this._readOnly)
  915. {
  916. if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
  917. {
  918. this.ClearValue();
  919. }
  920. }
  921. }
  922. /// <summary>
  923. /// 文本改变
  924. /// </summary>
  925. /// <param name="sender"></param>
  926. /// <param name="e"></param>
  927. protected void Condition_TextChanged(object sender, EventArgs e)
  928. {
  929. if (this._resetText)
  930. {
  931. return;
  932. }
  933. this._valueFrom = SearchBoxValueFrom.UserInput;
  934. }
  935. /// <summary>
  936. /// 关闭查询窗体
  937. /// </summary>
  938. /// <param name="sender"></param>
  939. /// <param name="e"></param>
  940. protected void SearchBoxForm_FormClosed(object sender, FormClosedEventArgs e)
  941. {
  942. this.OnSearchFormClosed(e);
  943. }
  944. /// <summary>
  945. /// 点击查询按钮
  946. /// </summary>
  947. /// <param name="sender"></param>
  948. /// <param name="e"></param>
  949. private void btnSearch_Click(object sender, EventArgs e)
  950. {
  951. this.ShowSearchForm();
  952. }
  953. #endregion
  954. #region 公有方法
  955. /// <summary>
  956. /// 打开查询窗体
  957. /// </summary>
  958. public virtual void ShowSearchForm()
  959. {
  960. if (this._searchForm == null)
  961. {
  962. return;
  963. }
  964. //if (!this.MultiSelect)
  965. //{
  966. // this._searchForm.SetConditions(this.txtCondition1.Text);
  967. //}
  968. if (this.ValueFrom == SearchBoxValueFrom.UserInput)
  969. {
  970. string display = this.DisplayMember.ToUpper();
  971. if (display.EndsWith("CODE"))
  972. {
  973. this.SearchForm.SetConditions(this.txtCondition1.Text, "");
  974. }
  975. else
  976. {
  977. this.SearchForm.SetConditions(this.txtCondition1.Text);
  978. }
  979. }
  980. this._searchForm.Show();
  981. }
  982. /// <summary>
  983. /// 初始化显示的值
  984. /// </summary>
  985. /// <param name="text"></param>
  986. /// <param name="value"></param>
  987. public virtual void InitValue(string text, object value, params object[] items)
  988. {
  989. this._initText = text;
  990. this._initValue = value;
  991. this.txtCondition1.Text = text;
  992. this._valueFrom = SearchBoxValueFrom.InitValue;
  993. InitItems = items;
  994. }
  995. ///// <summary>
  996. ///// 关闭查询窗体
  997. ///// </summary>
  998. //public virtual void CloseSearchForm()
  999. //{
  1000. // this._searchForm.CloseSearchForm();
  1001. //}
  1002. ///// <summary>
  1003. ///// 清除查询条件
  1004. ///// </summary>
  1005. //public virtual void ClearConditions()
  1006. //{
  1007. // this._searchForm.ClearConditions();
  1008. //}
  1009. ///// <summary>
  1010. ///// 清除查询结果
  1011. ///// </summary>
  1012. //public virtual void ClearQueryResults()
  1013. //{
  1014. // this._searchForm.ClearQueryResults();
  1015. //}
  1016. #endregion
  1017. #region 保护方法
  1018. /// <summary>
  1019. /// 初始化查询文本框集合
  1020. /// </summary>
  1021. protected virtual void InitQueryControls()
  1022. {
  1023. this._queryControls.Add(this.txtCondition1);
  1024. }
  1025. /// <summary>
  1026. /// 创建查询窗体。
  1027. /// </summary>
  1028. protected virtual ISearchBoxForm CreatSearchForm()
  1029. {
  1030. //SearchBoxForm form = FormFactory.CreatForm<SearchBoxForm>();
  1031. //return form;
  1032. return null;
  1033. }
  1034. /// <summary>
  1035. /// 当查询窗体关闭时。
  1036. /// </summary>
  1037. /// <param name="e"></param>
  1038. protected virtual void OnSearchFormClosed(FormClosedEventArgs e)
  1039. {
  1040. if (this._searchForm == null)
  1041. {
  1042. return;
  1043. }
  1044. this._searchForm.RefreshData();
  1045. DialogResult dialogResult = this._searchForm.DialogResult;
  1046. if (dialogResult == DialogResult.OK)
  1047. {
  1048. this._checkedData = this._searchForm.CheckedData;
  1049. if (this._checkedData == null || this._checkedData.Rows.Count == 0)
  1050. {
  1051. this.ClearValue();
  1052. }
  1053. else
  1054. {
  1055. this._valueFrom = SearchBoxValueFrom.SearchForm;
  1056. this.ResetDisplayText();
  1057. this._valueFrom = SearchBoxValueFrom.SearchForm;
  1058. this.OnSearchedItemChanged(EventArgs.Empty);
  1059. }
  1060. }
  1061. }
  1062. /// <summary>
  1063. /// 选择窗体关闭时,设置显示文本。
  1064. /// </summary>
  1065. protected virtual void ResetDisplayText()
  1066. {
  1067. this._resetText = true;
  1068. this.txtCondition1.Text = this.CheckedText;
  1069. this._resetText = false;
  1070. }
  1071. /// <summary>
  1072. /// 格式化显示文本。
  1073. /// </summary>
  1074. /// <param name="value">选定的值</param>
  1075. /// <returns>格式化显示的文本</returns>
  1076. protected virtual string FormatDisplay(object value)
  1077. {
  1078. // TODO
  1079. return value.ToString();
  1080. }
  1081. /// <summary>
  1082. /// 设置文本框只读
  1083. /// </summary>
  1084. protected virtual void SetEditReadOnly()
  1085. {
  1086. //foreach (TxtTextBox item in this._queryConditions)
  1087. //{
  1088. // item.ReadOnly = this._editReadOnly;
  1089. //}
  1090. this.txtCondition1.ReadOnly = this.EditReadOnly || this._readOnly;
  1091. }
  1092. #endregion
  1093. #region 私有方法
  1094. /// <summary>
  1095. /// 设置控件只读
  1096. /// </summary>
  1097. private void SetReadOnly()
  1098. {
  1099. this.SetEditReadOnly();
  1100. this.btnSearch.Enabled = !this._readOnly;
  1101. }
  1102. #endregion
  1103. #region IDataVerifiable 成员
  1104. #region 成员变量
  1105. /// <summary>
  1106. /// 显示边框颜色
  1107. /// </summary>
  1108. private bool _showBorderColor = true;
  1109. /// <summary>
  1110. /// 控件的项目名
  1111. /// </summary>
  1112. private string _itemName = null;
  1113. /// <summary>
  1114. /// 控件是否是必须输入项目
  1115. /// </summary>
  1116. private bool _mustInput = false;
  1117. /// <summary>
  1118. /// 控件在验证输入错误时,如何提示
  1119. /// </summary>
  1120. private InputErrorAlert _errorAlert = InputErrorAlert.Validated;
  1121. /// <summary>
  1122. /// 是否显示必须输入项目的提示
  1123. /// </summary>
  1124. private bool _showMustInputAlert = true;
  1125. /// <summary>
  1126. /// 验证不通过时,焦点能否离开
  1127. /// </summary>
  1128. private bool _canLostFocusOnError = true;
  1129. /// <summary>
  1130. /// 验证是否有错误
  1131. /// </summary>
  1132. private bool _hasError = false;
  1133. /// <summary>
  1134. /// 是否自定义错误
  1135. /// </summary>
  1136. private bool _hasCustomerError = false;
  1137. /// <summary>
  1138. /// 错误编码
  1139. /// </summary>
  1140. private ControlErrorCode _errorCode = ControlErrorCode.DKC_0000;
  1141. /// <summary>
  1142. /// 错误消息
  1143. /// </summary>
  1144. private string _errorMessage = null;
  1145. /// <summary>
  1146. /// 自定义错误消息
  1147. /// </summary>
  1148. private string _customerErrorMessage = null;
  1149. #endregion
  1150. #region 属性
  1151. /// <summary>
  1152. /// 获取或设置控件是否显示边框颜色。
  1153. /// </summary>
  1154. [Description("获取或设置控件是否显示边框颜色。"), Category("IDataVerifiable")]
  1155. [DefaultValue(true)]
  1156. public bool ShowBorderColor
  1157. {
  1158. get
  1159. {
  1160. return this._showBorderColor;
  1161. }
  1162. set
  1163. {
  1164. if (this._showBorderColor != value)
  1165. {
  1166. this._showBorderColor = value;
  1167. foreach (TextBox item in this._queryControls)
  1168. {
  1169. if (item is IDataVerifiable)
  1170. {
  1171. IDataVerifiable dvItem = item as IDataVerifiable;
  1172. dvItem.ShowBorderColor = value;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. }
  1178. /// <summary>
  1179. /// 获取或设置控件的项目名
  1180. /// </summary>
  1181. [Description("获取或设置控件的项目名。"), Category("IDataVerifiable")]
  1182. [DefaultValue(null)]
  1183. public string CDItemName
  1184. {
  1185. get
  1186. {
  1187. return this._itemName;
  1188. }
  1189. set
  1190. {
  1191. this._itemName = value;
  1192. foreach (TextBox item in this._queryControls)
  1193. {
  1194. if (item is IDataVerifiable)
  1195. {
  1196. IDataVerifiable dvItem = item as IDataVerifiable;
  1197. dvItem.CDItemName = value;
  1198. }
  1199. }
  1200. }
  1201. }
  1202. /// <summary>
  1203. /// 获取或设置控件是否必须选中项目。
  1204. /// </summary>
  1205. [Description("获取或设置控件是否必须选中项目。"), Category("IDataVerifiable")]
  1206. [DefaultValue(false)]
  1207. public bool MustInput
  1208. {
  1209. get
  1210. {
  1211. return this._mustInput;
  1212. }
  1213. set
  1214. {
  1215. if (this._mustInput != value)
  1216. {
  1217. this._mustInput = value;
  1218. foreach (TextBox item in this._queryControls)
  1219. {
  1220. if (item is IDataVerifiable)
  1221. {
  1222. IDataVerifiable dvItem = item as IDataVerifiable;
  1223. dvItem.MustInput = value;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. /// <summary>
  1230. /// 获取或设置控件是否必须选中项目。
  1231. /// </summary>
  1232. [Description("获取或设置控件在验证输入错误时,如何提示。"), Category("IDataVerifiable")]
  1233. [DefaultValue(typeof(InputErrorAlert), "Validated")]
  1234. public InputErrorAlert InputErrorAlert
  1235. {
  1236. get
  1237. {
  1238. return this._errorAlert;
  1239. }
  1240. set
  1241. {
  1242. if (this._errorAlert != value)
  1243. {
  1244. this._errorAlert = value;
  1245. foreach (TextBox item in this._queryControls)
  1246. {
  1247. if (item is IDataVerifiable)
  1248. {
  1249. IDataVerifiable dvItem = item as IDataVerifiable;
  1250. dvItem.InputErrorAlert = value;
  1251. }
  1252. }
  1253. }
  1254. }
  1255. }
  1256. /// <summary>
  1257. /// 获取或设置控件是否显示必须输入项目提示
  1258. /// </summary>
  1259. [Description("获取或设置控件是否显示必须输入项目提示。"), Category("IDataVerifiable")]
  1260. [DefaultValue(true)]
  1261. public bool ShowMustInputAlert
  1262. {
  1263. get
  1264. {
  1265. return this._showMustInputAlert;
  1266. }
  1267. set
  1268. {
  1269. if (this._showMustInputAlert != value)
  1270. {
  1271. this._showMustInputAlert = value;
  1272. foreach (TextBox item in this._queryControls)
  1273. {
  1274. if (item is IDataVerifiable)
  1275. {
  1276. IDataVerifiable dvItem = item as IDataVerifiable;
  1277. dvItem.ShowMustInputAlert = value;
  1278. }
  1279. }
  1280. }
  1281. }
  1282. }
  1283. /// <summary>
  1284. /// 获取或设置当验证不通过时,控件是否可以失去焦点
  1285. /// </summary>
  1286. [Description("获取或设置当验证不通过时,控件是否可以失去焦点。"), Category("IDataVerifiable")]
  1287. [DefaultValue(true)]
  1288. public bool CanLostFocusOnError
  1289. {
  1290. get
  1291. {
  1292. return this._canLostFocusOnError;
  1293. }
  1294. set
  1295. {
  1296. if (this._canLostFocusOnError != value)
  1297. {
  1298. this._canLostFocusOnError = value;
  1299. foreach (TextBox item in this._queryControls)
  1300. {
  1301. if (item is IDataVerifiable)
  1302. {
  1303. IDataVerifiable dvItem = item as IDataVerifiable;
  1304. dvItem.CanLostFocusOnError = value;
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }
  1310. /// <summary>
  1311. /// 获取控件校验时是否有错误
  1312. /// </summary>
  1313. [Description("获取控件校验时是否有错误。"), Category("IDataVerifiable")]
  1314. [DefaultValue(false)]
  1315. public bool HasError
  1316. {
  1317. get
  1318. {
  1319. //return this._hasCustomerError || this._hasError;
  1320. if (this._hasCustomerError)
  1321. {
  1322. return this._hasCustomerError;
  1323. }
  1324. foreach (TextBox item in this._queryControls)
  1325. {
  1326. if (item is IDataVerifiable)
  1327. {
  1328. IDataVerifiable dvItem = item as IDataVerifiable;
  1329. if (dvItem.HasError)
  1330. {
  1331. return true;
  1332. }
  1333. }
  1334. }
  1335. return false;
  1336. }
  1337. }
  1338. /// <summary>
  1339. /// 获取控件校验时的错误编码
  1340. /// </summary>
  1341. [Description("获取控件校验时的错误编码。"), Category("IDataVerifiable")]
  1342. [DefaultValue(typeof(ControlErrorCode), "DKC_0000")]
  1343. public ControlErrorCode ErrorCode
  1344. {
  1345. get
  1346. {
  1347. //return this._hasCustomerError ? ControlErrorCode.DKC_C001 : this._errorCode;
  1348. if (this._hasCustomerError)
  1349. {
  1350. return ControlErrorCode.DKC_C001;
  1351. }
  1352. foreach (TextBox item in this._queryControls)
  1353. {
  1354. if (item is IDataVerifiable)
  1355. {
  1356. IDataVerifiable dvItem = item as IDataVerifiable;
  1357. if (dvItem.HasError)
  1358. {
  1359. return dvItem.ErrorCode;
  1360. }
  1361. }
  1362. }
  1363. return this._errorCode;
  1364. }
  1365. }
  1366. /// <summary>
  1367. /// 获取控件校验时的错误消息
  1368. /// </summary>
  1369. [Description("获取控件校验时的错误编码。"), Category("IDataVerifiable")]
  1370. [DefaultValue(null)]
  1371. public string ErrorMessage
  1372. {
  1373. get
  1374. {
  1375. //return this._hasCustomerError ? this._customerErrorMessage : this._errorMessage;
  1376. if (this._hasCustomerError)
  1377. {
  1378. return this._customerErrorMessage;
  1379. }
  1380. foreach (TextBox item in this._queryControls)
  1381. {
  1382. if (item is IDataVerifiable)
  1383. {
  1384. IDataVerifiable dvItem = item as IDataVerifiable;
  1385. if (dvItem.HasError)
  1386. {
  1387. return dvItem.ErrorMessage;
  1388. }
  1389. }
  1390. }
  1391. return this._errorMessage;
  1392. }
  1393. }
  1394. #endregion
  1395. #region 公有方法
  1396. /// <summary>
  1397. /// 设置自定义错误
  1398. /// </summary>
  1399. /// <param name="hasError">输入是否有错误</param>
  1400. /// <param name="errorMessage">错误消息</param>
  1401. public virtual void SetCustomerError(bool hasError, string errorMessage)
  1402. {
  1403. if (this._hasCustomerError != hasError ||
  1404. this._customerErrorMessage != errorMessage)
  1405. {
  1406. this._hasCustomerError = hasError;
  1407. this._customerErrorMessage = errorMessage;
  1408. this.OnHasErrorChanged(EventArgs.Empty);
  1409. this.InvalidateBorder();
  1410. }
  1411. }
  1412. /// <summary>
  1413. /// 清除自定义错误
  1414. /// </summary>
  1415. public virtual void ClearCustomerError()
  1416. {
  1417. this.SetCustomerError(false, null);
  1418. }
  1419. /// <summary>
  1420. /// 验证输入内容
  1421. /// </summary>
  1422. /// <returns>验证结果</returns>
  1423. public virtual bool ValidateData()
  1424. {
  1425. //string text = base.Text;
  1426. //if (this._mustInput && text.Length == 0)
  1427. //{
  1428. // this.SetError(true, ControlErrorCode.DKC_0001, this._itemName);
  1429. // return false;
  1430. //}
  1431. //this.ClearError();
  1432. //return true;
  1433. bool result = true;
  1434. foreach (TextBox item in this._queryControls)
  1435. {
  1436. if (item is IDataVerifiable)
  1437. {
  1438. IDataVerifiable dvItem = item as IDataVerifiable;
  1439. result = result && dvItem.ValidateData();
  1440. }
  1441. }
  1442. return result;
  1443. }
  1444. /// <summary>
  1445. /// 清除输入项
  1446. /// </summary>
  1447. public virtual void ClearValue()
  1448. {
  1449. foreach (TextBox item in this._queryControls)
  1450. {
  1451. if (item is IDataVerifiable)
  1452. {
  1453. IDataVerifiable dvItem = item as IDataVerifiable;
  1454. dvItem.ClearValue();
  1455. }
  1456. }
  1457. if (this._checkedData != null && this._checkedData.Rows.Count > 0)
  1458. {
  1459. this._checkedData.Clear();
  1460. this.OnSearchedItemChanged(EventArgs.Empty);
  1461. }
  1462. SearchedPKMember = 0;
  1463. }
  1464. #endregion
  1465. #region 保护方法
  1466. /// <summary>
  1467. /// 设置验证不通过错误
  1468. /// </summary>
  1469. /// <param name="hasError">是否有错误</param>
  1470. /// <param name="code">错误编码</param>
  1471. /// <param name="args">设置格式的对象</param>
  1472. protected void SetError(bool hasError, ControlErrorCode code, params object[] args)
  1473. {
  1474. if (this._hasError != hasError ||
  1475. this._errorCode != code)
  1476. {
  1477. this._hasError = hasError;
  1478. this._errorCode = code;
  1479. if (args != null && args.Length > 0)
  1480. {
  1481. this._errorMessage = string.Format(code.GetDescription(), args);
  1482. }
  1483. else
  1484. {
  1485. this._errorMessage = code.GetDescription();
  1486. }
  1487. this.OnHasErrorChanged(EventArgs.Empty);
  1488. this.InvalidateBorder();
  1489. }
  1490. }
  1491. /// <summary>
  1492. /// 清除验证不通过错误
  1493. /// </summary>
  1494. protected void ClearError()
  1495. {
  1496. this.SetError(false, ControlErrorCode.DKC_0000);
  1497. }
  1498. #endregion
  1499. #region 私有方法
  1500. /// <summary>
  1501. /// 使父控件的指定区域无效(将其添加到控件的更新区域,下次绘制操作时将重新绘制更新区域),并向父控件发送绘制消息。
  1502. /// </summary>
  1503. private void InvalidateBorder()
  1504. {
  1505. //Color? borderColor = BorderColorPaint.GetBorderColor(this as IDataVerifiable, this._entered, this._mouseOver);
  1506. //if (borderColor != this._borderColor)
  1507. //{
  1508. // this._borderColor = borderColor;
  1509. // if (this.Parent == null)
  1510. // {
  1511. // this.Invalidate();
  1512. // }
  1513. // else
  1514. // {
  1515. // this.Parent.Invalidate(this.Bounds, true);
  1516. // }
  1517. //}
  1518. }
  1519. #endregion
  1520. #endregion
  1521. #region IAsyncControl 成员
  1522. #region 成员变量
  1523. /// <summary>
  1524. /// 异步处理开始时,控件状态
  1525. /// </summary>
  1526. private bool _asyncBeginStatus = false;
  1527. private bool _asyncBeginFocused = false;
  1528. private Control _activeControl = null;
  1529. #endregion
  1530. #region 公有方法
  1531. /// <summary>
  1532. /// 开始异步处理
  1533. /// </summary>
  1534. /// <param name="doFocus">是否处理焦点</param>
  1535. public virtual void BeginAsync(ref bool doFocus)
  1536. {
  1537. this._asyncBeginFocused = false;
  1538. //if (doFocus && this.Focused)
  1539. if (doFocus && this.ActiveControl != null)
  1540. {
  1541. this._asyncBeginFocused = true;
  1542. this._activeControl = this.ActiveControl;
  1543. doFocus = false;
  1544. }
  1545. this._asyncBeginStatus = this.ReadOnly;
  1546. this.ReadOnly = true;
  1547. }
  1548. /// <summary>
  1549. /// 结束异步处理
  1550. /// </summary>
  1551. public virtual void EndAsync()
  1552. {
  1553. this.ReadOnly = this._asyncBeginStatus;
  1554. if (this._asyncBeginFocused)
  1555. {
  1556. //this.Focus();
  1557. this.ActiveControl = this._activeControl;
  1558. this._activeControl = null;
  1559. }
  1560. }
  1561. #endregion
  1562. #endregion
  1563. }
  1564. }