ScbSearchBox.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678
  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. /// <param name="text"></param>
  999. /// <param name="value"></param>
  1000. public virtual void InitValue(string text, object value)
  1001. {
  1002. this._initText = text;
  1003. this._initValue = value;
  1004. this.txtCondition1.Text = text;
  1005. this._valueFrom = SearchBoxValueFrom.InitValue;
  1006. //InitItems = items;
  1007. }
  1008. ///// <summary>
  1009. ///// 关闭查询窗体
  1010. ///// </summary>
  1011. //public virtual void CloseSearchForm()
  1012. //{
  1013. // this._searchForm.CloseSearchForm();
  1014. //}
  1015. ///// <summary>
  1016. ///// 清除查询条件
  1017. ///// </summary>
  1018. //public virtual void ClearConditions()
  1019. //{
  1020. // this._searchForm.ClearConditions();
  1021. //}
  1022. ///// <summary>
  1023. ///// 清除查询结果
  1024. ///// </summary>
  1025. //public virtual void ClearQueryResults()
  1026. //{
  1027. // this._searchForm.ClearQueryResults();
  1028. //}
  1029. #endregion
  1030. #region 保护方法
  1031. /// <summary>
  1032. /// 初始化查询文本框集合
  1033. /// </summary>
  1034. protected virtual void InitQueryControls()
  1035. {
  1036. this._queryControls.Add(this.txtCondition1);
  1037. }
  1038. /// <summary>
  1039. /// 创建查询窗体。
  1040. /// </summary>
  1041. protected virtual ISearchBoxForm CreatSearchForm()
  1042. {
  1043. //SearchBoxForm form = FormFactory.CreatForm<SearchBoxForm>();
  1044. //return form;
  1045. return null;
  1046. }
  1047. /// <summary>
  1048. /// 当查询窗体关闭时。
  1049. /// </summary>
  1050. /// <param name="e"></param>
  1051. protected virtual void OnSearchFormClosed(FormClosedEventArgs e)
  1052. {
  1053. if (this._searchForm == null)
  1054. {
  1055. return;
  1056. }
  1057. this._searchForm.RefreshData();
  1058. DialogResult dialogResult = this._searchForm.DialogResult;
  1059. if (dialogResult == DialogResult.OK)
  1060. {
  1061. this._checkedData = this._searchForm.CheckedData;
  1062. if (this._checkedData == null || this._checkedData.Rows.Count == 0)
  1063. {
  1064. this.ClearValue();
  1065. }
  1066. else
  1067. {
  1068. this._valueFrom = SearchBoxValueFrom.SearchForm;
  1069. this.ResetDisplayText();
  1070. this._valueFrom = SearchBoxValueFrom.SearchForm;
  1071. this.OnSearchedItemChanged(EventArgs.Empty);
  1072. }
  1073. }
  1074. }
  1075. /// <summary>
  1076. /// 选择窗体关闭时,设置显示文本。
  1077. /// </summary>
  1078. protected virtual void ResetDisplayText()
  1079. {
  1080. this._resetText = true;
  1081. this.txtCondition1.Text = this.CheckedText;
  1082. this._resetText = false;
  1083. }
  1084. /// <summary>
  1085. /// 格式化显示文本。
  1086. /// </summary>
  1087. /// <param name="value">选定的值</param>
  1088. /// <returns>格式化显示的文本</returns>
  1089. protected virtual string FormatDisplay(object value)
  1090. {
  1091. // TODO
  1092. return value.ToString();
  1093. }
  1094. /// <summary>
  1095. /// 设置文本框只读
  1096. /// </summary>
  1097. protected virtual void SetEditReadOnly()
  1098. {
  1099. //foreach (TxtTextBox item in this._queryConditions)
  1100. //{
  1101. // item.ReadOnly = this._editReadOnly;
  1102. //}
  1103. this.txtCondition1.ReadOnly = this.EditReadOnly || this._readOnly;
  1104. }
  1105. #endregion
  1106. #region 私有方法
  1107. /// <summary>
  1108. /// 设置控件只读
  1109. /// </summary>
  1110. private void SetReadOnly()
  1111. {
  1112. this.SetEditReadOnly();
  1113. this.btnSearch.Enabled = !this._readOnly;
  1114. }
  1115. #endregion
  1116. #region IDataVerifiable 成员
  1117. #region 成员变量
  1118. /// <summary>
  1119. /// 显示边框颜色
  1120. /// </summary>
  1121. private bool _showBorderColor = true;
  1122. /// <summary>
  1123. /// 控件的项目名
  1124. /// </summary>
  1125. private string _itemName = null;
  1126. /// <summary>
  1127. /// 控件是否是必须输入项目
  1128. /// </summary>
  1129. private bool _mustInput = false;
  1130. /// <summary>
  1131. /// 控件在验证输入错误时,如何提示
  1132. /// </summary>
  1133. private InputErrorAlert _errorAlert = InputErrorAlert.Validated;
  1134. /// <summary>
  1135. /// 是否显示必须输入项目的提示
  1136. /// </summary>
  1137. private bool _showMustInputAlert = true;
  1138. /// <summary>
  1139. /// 验证不通过时,焦点能否离开
  1140. /// </summary>
  1141. private bool _canLostFocusOnError = true;
  1142. /// <summary>
  1143. /// 验证是否有错误
  1144. /// </summary>
  1145. private bool _hasError = false;
  1146. /// <summary>
  1147. /// 是否自定义错误
  1148. /// </summary>
  1149. private bool _hasCustomerError = false;
  1150. /// <summary>
  1151. /// 错误编码
  1152. /// </summary>
  1153. private ControlErrorCode _errorCode = ControlErrorCode.DKC_0000;
  1154. /// <summary>
  1155. /// 错误消息
  1156. /// </summary>
  1157. private string _errorMessage = null;
  1158. /// <summary>
  1159. /// 自定义错误消息
  1160. /// </summary>
  1161. private string _customerErrorMessage = null;
  1162. #endregion
  1163. #region 属性
  1164. /// <summary>
  1165. /// 获取或设置控件是否显示边框颜色。
  1166. /// </summary>
  1167. [Description("获取或设置控件是否显示边框颜色。"), Category("IDataVerifiable")]
  1168. [DefaultValue(true)]
  1169. public bool ShowBorderColor
  1170. {
  1171. get
  1172. {
  1173. return this._showBorderColor;
  1174. }
  1175. set
  1176. {
  1177. if (this._showBorderColor != value)
  1178. {
  1179. this._showBorderColor = value;
  1180. foreach (TextBox item in this._queryControls)
  1181. {
  1182. if (item is IDataVerifiable)
  1183. {
  1184. IDataVerifiable dvItem = item as IDataVerifiable;
  1185. dvItem.ShowBorderColor = value;
  1186. }
  1187. }
  1188. }
  1189. }
  1190. }
  1191. /// <summary>
  1192. /// 获取或设置控件的项目名
  1193. /// </summary>
  1194. [Description("获取或设置控件的项目名。"), Category("IDataVerifiable")]
  1195. [DefaultValue(null)]
  1196. public string CDItemName
  1197. {
  1198. get
  1199. {
  1200. return this._itemName;
  1201. }
  1202. set
  1203. {
  1204. this._itemName = value;
  1205. foreach (TextBox item in this._queryControls)
  1206. {
  1207. if (item is IDataVerifiable)
  1208. {
  1209. IDataVerifiable dvItem = item as IDataVerifiable;
  1210. dvItem.CDItemName = value;
  1211. }
  1212. }
  1213. }
  1214. }
  1215. /// <summary>
  1216. /// 获取或设置控件是否必须选中项目。
  1217. /// </summary>
  1218. [Description("获取或设置控件是否必须选中项目。"), Category("IDataVerifiable")]
  1219. [DefaultValue(false)]
  1220. public bool MustInput
  1221. {
  1222. get
  1223. {
  1224. return this._mustInput;
  1225. }
  1226. set
  1227. {
  1228. if (this._mustInput != value)
  1229. {
  1230. this._mustInput = value;
  1231. foreach (TextBox item in this._queryControls)
  1232. {
  1233. if (item is IDataVerifiable)
  1234. {
  1235. IDataVerifiable dvItem = item as IDataVerifiable;
  1236. dvItem.MustInput = value;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. }
  1242. /// <summary>
  1243. /// 获取或设置控件是否必须选中项目。
  1244. /// </summary>
  1245. [Description("获取或设置控件在验证输入错误时,如何提示。"), Category("IDataVerifiable")]
  1246. [DefaultValue(typeof(InputErrorAlert), "Validated")]
  1247. public InputErrorAlert InputErrorAlert
  1248. {
  1249. get
  1250. {
  1251. return this._errorAlert;
  1252. }
  1253. set
  1254. {
  1255. if (this._errorAlert != value)
  1256. {
  1257. this._errorAlert = value;
  1258. foreach (TextBox item in this._queryControls)
  1259. {
  1260. if (item is IDataVerifiable)
  1261. {
  1262. IDataVerifiable dvItem = item as IDataVerifiable;
  1263. dvItem.InputErrorAlert = value;
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. /// <summary>
  1270. /// 获取或设置控件是否显示必须输入项目提示
  1271. /// </summary>
  1272. [Description("获取或设置控件是否显示必须输入项目提示。"), Category("IDataVerifiable")]
  1273. [DefaultValue(true)]
  1274. public bool ShowMustInputAlert
  1275. {
  1276. get
  1277. {
  1278. return this._showMustInputAlert;
  1279. }
  1280. set
  1281. {
  1282. if (this._showMustInputAlert != value)
  1283. {
  1284. this._showMustInputAlert = value;
  1285. foreach (TextBox item in this._queryControls)
  1286. {
  1287. if (item is IDataVerifiable)
  1288. {
  1289. IDataVerifiable dvItem = item as IDataVerifiable;
  1290. dvItem.ShowMustInputAlert = value;
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }
  1296. /// <summary>
  1297. /// 获取或设置当验证不通过时,控件是否可以失去焦点
  1298. /// </summary>
  1299. [Description("获取或设置当验证不通过时,控件是否可以失去焦点。"), Category("IDataVerifiable")]
  1300. [DefaultValue(true)]
  1301. public bool CanLostFocusOnError
  1302. {
  1303. get
  1304. {
  1305. return this._canLostFocusOnError;
  1306. }
  1307. set
  1308. {
  1309. if (this._canLostFocusOnError != value)
  1310. {
  1311. this._canLostFocusOnError = value;
  1312. foreach (TextBox item in this._queryControls)
  1313. {
  1314. if (item is IDataVerifiable)
  1315. {
  1316. IDataVerifiable dvItem = item as IDataVerifiable;
  1317. dvItem.CanLostFocusOnError = value;
  1318. }
  1319. }
  1320. }
  1321. }
  1322. }
  1323. /// <summary>
  1324. /// 获取控件校验时是否有错误
  1325. /// </summary>
  1326. [Description("获取控件校验时是否有错误。"), Category("IDataVerifiable")]
  1327. [DefaultValue(false)]
  1328. public bool HasError
  1329. {
  1330. get
  1331. {
  1332. //return this._hasCustomerError || this._hasError;
  1333. if (this._hasCustomerError)
  1334. {
  1335. return this._hasCustomerError;
  1336. }
  1337. foreach (TextBox item in this._queryControls)
  1338. {
  1339. if (item is IDataVerifiable)
  1340. {
  1341. IDataVerifiable dvItem = item as IDataVerifiable;
  1342. if (dvItem.HasError)
  1343. {
  1344. return true;
  1345. }
  1346. }
  1347. }
  1348. return false;
  1349. }
  1350. }
  1351. /// <summary>
  1352. /// 获取控件校验时的错误编码
  1353. /// </summary>
  1354. [Description("获取控件校验时的错误编码。"), Category("IDataVerifiable")]
  1355. [DefaultValue(typeof(ControlErrorCode), "DKC_0000")]
  1356. public ControlErrorCode ErrorCode
  1357. {
  1358. get
  1359. {
  1360. //return this._hasCustomerError ? ControlErrorCode.DKC_C001 : this._errorCode;
  1361. if (this._hasCustomerError)
  1362. {
  1363. return ControlErrorCode.DKC_C001;
  1364. }
  1365. foreach (TextBox item in this._queryControls)
  1366. {
  1367. if (item is IDataVerifiable)
  1368. {
  1369. IDataVerifiable dvItem = item as IDataVerifiable;
  1370. if (dvItem.HasError)
  1371. {
  1372. return dvItem.ErrorCode;
  1373. }
  1374. }
  1375. }
  1376. return this._errorCode;
  1377. }
  1378. }
  1379. /// <summary>
  1380. /// 获取控件校验时的错误消息
  1381. /// </summary>
  1382. [Description("获取控件校验时的错误编码。"), Category("IDataVerifiable")]
  1383. [DefaultValue(null)]
  1384. public string ErrorMessage
  1385. {
  1386. get
  1387. {
  1388. //return this._hasCustomerError ? this._customerErrorMessage : this._errorMessage;
  1389. if (this._hasCustomerError)
  1390. {
  1391. return this._customerErrorMessage;
  1392. }
  1393. foreach (TextBox item in this._queryControls)
  1394. {
  1395. if (item is IDataVerifiable)
  1396. {
  1397. IDataVerifiable dvItem = item as IDataVerifiable;
  1398. if (dvItem.HasError)
  1399. {
  1400. return dvItem.ErrorMessage;
  1401. }
  1402. }
  1403. }
  1404. return this._errorMessage;
  1405. }
  1406. }
  1407. #endregion
  1408. #region 公有方法
  1409. /// <summary>
  1410. /// 设置自定义错误
  1411. /// </summary>
  1412. /// <param name="hasError">输入是否有错误</param>
  1413. /// <param name="errorMessage">错误消息</param>
  1414. public virtual void SetCustomerError(bool hasError, string errorMessage)
  1415. {
  1416. if (this._hasCustomerError != hasError ||
  1417. this._customerErrorMessage != errorMessage)
  1418. {
  1419. this._hasCustomerError = hasError;
  1420. this._customerErrorMessage = errorMessage;
  1421. this.OnHasErrorChanged(EventArgs.Empty);
  1422. this.InvalidateBorder();
  1423. }
  1424. }
  1425. /// <summary>
  1426. /// 清除自定义错误
  1427. /// </summary>
  1428. public virtual void ClearCustomerError()
  1429. {
  1430. this.SetCustomerError(false, null);
  1431. }
  1432. /// <summary>
  1433. /// 验证输入内容
  1434. /// </summary>
  1435. /// <returns>验证结果</returns>
  1436. public virtual bool ValidateData()
  1437. {
  1438. //string text = base.Text;
  1439. //if (this._mustInput && text.Length == 0)
  1440. //{
  1441. // this.SetError(true, ControlErrorCode.DKC_0001, this._itemName);
  1442. // return false;
  1443. //}
  1444. //this.ClearError();
  1445. //return true;
  1446. bool result = true;
  1447. foreach (TextBox item in this._queryControls)
  1448. {
  1449. if (item is IDataVerifiable)
  1450. {
  1451. IDataVerifiable dvItem = item as IDataVerifiable;
  1452. result = result && dvItem.ValidateData();
  1453. }
  1454. }
  1455. return result;
  1456. }
  1457. /// <summary>
  1458. /// 清除输入项
  1459. /// </summary>
  1460. public virtual void ClearValue()
  1461. {
  1462. foreach (TextBox item in this._queryControls)
  1463. {
  1464. if (item is IDataVerifiable)
  1465. {
  1466. IDataVerifiable dvItem = item as IDataVerifiable;
  1467. dvItem.ClearValue();
  1468. }
  1469. }
  1470. if (this._checkedData != null && this._checkedData.Rows.Count > 0)
  1471. {
  1472. this._checkedData.Clear();
  1473. this.OnSearchedItemChanged(EventArgs.Empty);
  1474. }
  1475. SearchedPKMember = 0;
  1476. }
  1477. #endregion
  1478. #region 保护方法
  1479. /// <summary>
  1480. /// 设置验证不通过错误
  1481. /// </summary>
  1482. /// <param name="hasError">是否有错误</param>
  1483. /// <param name="code">错误编码</param>
  1484. /// <param name="args">设置格式的对象</param>
  1485. protected void SetError(bool hasError, ControlErrorCode code, params object[] args)
  1486. {
  1487. if (this._hasError != hasError ||
  1488. this._errorCode != code)
  1489. {
  1490. this._hasError = hasError;
  1491. this._errorCode = code;
  1492. if (args != null && args.Length > 0)
  1493. {
  1494. this._errorMessage = string.Format(code.GetDescription(), args);
  1495. }
  1496. else
  1497. {
  1498. this._errorMessage = code.GetDescription();
  1499. }
  1500. this.OnHasErrorChanged(EventArgs.Empty);
  1501. this.InvalidateBorder();
  1502. }
  1503. }
  1504. /// <summary>
  1505. /// 清除验证不通过错误
  1506. /// </summary>
  1507. protected void ClearError()
  1508. {
  1509. this.SetError(false, ControlErrorCode.DKC_0000);
  1510. }
  1511. #endregion
  1512. #region 私有方法
  1513. /// <summary>
  1514. /// 使父控件的指定区域无效(将其添加到控件的更新区域,下次绘制操作时将重新绘制更新区域),并向父控件发送绘制消息。
  1515. /// </summary>
  1516. private void InvalidateBorder()
  1517. {
  1518. //Color? borderColor = BorderColorPaint.GetBorderColor(this as IDataVerifiable, this._entered, this._mouseOver);
  1519. //if (borderColor != this._borderColor)
  1520. //{
  1521. // this._borderColor = borderColor;
  1522. // if (this.Parent == null)
  1523. // {
  1524. // this.Invalidate();
  1525. // }
  1526. // else
  1527. // {
  1528. // this.Parent.Invalidate(this.Bounds, true);
  1529. // }
  1530. //}
  1531. }
  1532. #endregion
  1533. #endregion
  1534. #region IAsyncControl 成员
  1535. #region 成员变量
  1536. /// <summary>
  1537. /// 异步处理开始时,控件状态
  1538. /// </summary>
  1539. private bool _asyncBeginStatus = false;
  1540. private bool _asyncBeginFocused = false;
  1541. private Control _activeControl = null;
  1542. #endregion
  1543. #region 公有方法
  1544. /// <summary>
  1545. /// 开始异步处理
  1546. /// </summary>
  1547. /// <param name="doFocus">是否处理焦点</param>
  1548. public virtual void BeginAsync(ref bool doFocus)
  1549. {
  1550. this._asyncBeginFocused = false;
  1551. //if (doFocus && this.Focused)
  1552. if (doFocus && this.ActiveControl != null)
  1553. {
  1554. this._asyncBeginFocused = true;
  1555. this._activeControl = this.ActiveControl;
  1556. doFocus = false;
  1557. }
  1558. this._asyncBeginStatus = this.ReadOnly;
  1559. this.ReadOnly = true;
  1560. }
  1561. /// <summary>
  1562. /// 结束异步处理
  1563. /// </summary>
  1564. public virtual void EndAsync()
  1565. {
  1566. this.ReadOnly = this._asyncBeginStatus;
  1567. if (this._asyncBeginFocused)
  1568. {
  1569. //this.Focus();
  1570. this.ActiveControl = this._activeControl;
  1571. this._activeControl = null;
  1572. }
  1573. }
  1574. #endregion
  1575. #endregion
  1576. }
  1577. }