| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664 |
-
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Design;
- using System.Reflection;
- using System.Windows.Forms;
- using Dongke.WinForm.Utilities;
- namespace Dongke.WinForm.Controls
- {
- /// <summary>
- /// 查询文本框控件
- /// </summary>
- [ToolboxBitmap(typeof(ScbSearchBox), "ToolboxBitmap.SearchBox_00.bmp")]
- [DefaultEvent("SelectedItemChanged"), DefaultProperty("SearchText")]
- public partial class ScbSearchBox : UserControl, IDKControl,
- IDataVerifiable, IAsyncControl
- {
- #region 事件声明
- #region HasErrorChanged
- /// <summary>
- /// 当 HasError 属性的值更改时发生。
- /// </summary>
- private static readonly object EventHasErrorChanged = new object();
- /// <summary>
- /// 当 HasError 属性的值更改时发生。
- /// </summary>
- [Description("当 HasError 属性的值更改时发生。"), Category("CustomerEx")]
- public event EventHandler HasErrorChanged
- {
- add
- {
- base.Events.AddHandler(EventHasErrorChanged, value);
- }
- remove
- {
- base.Events.RemoveHandler(EventHasErrorChanged, value);
- }
- }
- /// <summary>
- /// 引发 HasErrorChanged 事件
- /// </summary>
- /// <param name="e">包含事件数据的 EventArgs</param>
- protected virtual void OnHasErrorChanged(EventArgs e)
- {
- EventHandler eventHandler = (EventHandler)base.Events[EventHasErrorChanged];
- if (eventHandler != null)
- {
- eventHandler(this, e);
- }
- }
- #endregion
- #region ReadOnlyChanged
- /// <summary>
- /// 当 ReadOnly 属性的值更改时发生。
- /// </summary>
- private static readonly object EventReadOnlyChanged = new object();
- /// <summary>
- /// 当 ReadOnly 属性的值更改时发生
- /// </summary>
- [Description("当 ReadOnly 属性的值更改时发生。"), Category("CustomerEx")]
- public event EventHandler ReadOnlyChanged
- {
- add
- {
- base.Events.AddHandler(EventReadOnlyChanged, value);
- }
- remove
- {
- base.Events.RemoveHandler(EventReadOnlyChanged, value);
- }
- }
- /// <summary>
- /// 引发 ReadOnlyChanged 事件
- /// </summary>
- /// <param name="e"></param>
- protected virtual void OnReadOnlyChanged(EventArgs e)
- {
- EventHandler eventHandler = base.Events[EventReadOnlyChanged] as EventHandler;
- if (eventHandler != null)
- {
- eventHandler(this, e);
- }
- }
- #endregion
- #region EditReadOnlyChanged
- /// <summary>
- /// 当 EditReadOnly 属性的值更改时发生。
- /// </summary>
- private static readonly object EventEditReadOnlyChanged = new object();
- /// <summary>
- /// 当 EditReadOnly 属性的值更改时发生
- /// </summary>
- [Description("当 EditReadOnly 属性的值更改时发生。"), Category("CustomerEx")]
- public event EventHandler EditReadOnlyChanged
- {
- add
- {
- base.Events.AddHandler(EventEditReadOnlyChanged, value);
- }
- remove
- {
- base.Events.RemoveHandler(EventEditReadOnlyChanged, value);
- }
- }
- /// <summary>
- /// 引发 EditReadOnlyChanged 事件
- /// </summary>
- /// <param name="e"></param>
- protected virtual void OnEditReadOnlyChanged(EventArgs e)
- {
- EventHandler eventHandler = base.Events[EventEditReadOnlyChanged] as EventHandler;
- if (eventHandler != null)
- {
- eventHandler(this, e);
- }
- }
- #endregion
- #region SearchedItemChanged
- /// <summary>
- /// 当 SelectedItem 属性的值更改时发生。
- /// </summary>
- private static readonly object EventSearchedItemChanged = new object();
- /// <summary>
- /// 当 SelectedItem 属性的值更改时发生
- /// </summary>
- [Description("当 SearchedItem 属性的值更改时发生。"), Category("CustomerEx")]
- public event EventHandler SearchedItemChanged
- {
- add
- {
- base.Events.AddHandler(EventSearchedItemChanged, value);
- }
- remove
- {
- base.Events.RemoveHandler(EventSearchedItemChanged, value);
- }
- }
- /// <summary>
- /// 引发 SelectedItem 事件
- /// </summary>
- /// <param name="e"></param>
- protected virtual void OnSearchedItemChanged(EventArgs e)
- {
- EventHandler eventHandler = base.Events[EventSearchedItemChanged] as EventHandler;
- if (eventHandler != null)
- {
- eventHandler(this, e);
- }
- }
- #endregion
- #region TextValueChanged
- public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
- public event TextBoxChangedHandle TextValueChanged;
- public class TextChangeEventArgs : EventArgs
- {
- public TextChangeEventArgs(string message)
- {
- }
- }
- private void txtCondition1_TextChanged(object sender, EventArgs e)
- {
- if (TextValueChanged != null)
- {
- TextValueChanged(this, new TextChangeEventArgs(this.txtCondition1.Text));
- }
- }
- #endregion
- #endregion
- #region 成员变量
- /// <summary>
- /// 查询窗体
- /// </summary>
- protected ISearchBoxForm _searchForm = null;
- /// <summary>
- /// 指示是否能够多项选择。
- /// </summary>
- private bool _multiSelect = false;
- /// <summary>
- /// 指示控件中的文本是否为只读
- /// </summary>
- private bool _editReadOnly = true;
- /// <summary>
- /// 指示控件中是否为只读
- /// </summary>
- private bool _readOnly = false;
- ///// <summary>
- ///// 为此控件显示的属性集合
- ///// </summary>
- //List<string> _displayMembers = new List<string>();
- ///// <summary>
- ///// 查询条件控件集合
- ///// </summary>
- //List<TxtTextBox> _queryConditions = new List<TxtTextBox>();
- ///// <summary>
- ///// 为此控件显示的属性
- ///// </summary>
- private string _displayMember = string.Empty;
- /// <summary>
- /// 用作此控件中的项的实际值
- /// </summary>
- private string _valueMember = string.Empty;
- /// <summary>
- /// 0:手动输入,1:SearchForm,2:初始化
- /// </summary>
- private SearchBoxValueFrom _valueFrom = SearchBoxValueFrom.UserInput;
- /// <summary>
- /// 查询的范围权限类型
- /// </summary>
- private PurviewType _purviewType = PurviewType.None;
- /// <summary>
- /// 初始化的文本
- /// </summary>
- private string _initText = null;
- /// <summary>
- /// 初始化的值
- /// </summary>
- private object _initValue = null;
- /// <summary>
- /// 选定的数据
- /// </summary>
- protected DataTable _checkedData = null;
- /// <summary>
- /// 选定后给文本框赋值时
- /// </summary>
- protected bool _resetText = false;
- /// <summary>
- /// 查询条件文本框的集合
- /// </summary>
- protected List<TextBox> _queryControls = new List<TextBox>();
- protected int _searchedPKMember;
- #endregion
- #region 构造函数
- /// <summary>
- /// 查询文本框控件
- /// </summary>
- public ScbSearchBox()
- :this(true)
- {
- }
- /// <summary>
- /// 查询文本框控件
- /// </summary>
- public ScbSearchBox(bool isInitControls = true)
- {
- this.InitializeComponent();
- CommonSetting.InitControls(this);
- if (isInitControls)
- {
- this.InitQueryControls();
- }
- this._searchForm = this.CreatSearchForm();
- if (this._searchForm != null)
- {
- //throw new NullReferenceException("SearchBoxForm");
- this._searchForm.FormClosed += this.SearchBoxForm_FormClosed;
- }
- this.txtCondition1.TextChanged += this.Condition_TextChanged;
- this.txtCondition1.KeyDown += this.Condition_KeyDown;
- }
- #endregion
- #region 属性
- /// <summary>
- /// 设置或获取选定的数据
- /// </summary>
- [DefaultValue("设置或获取选定的数据")]
- public virtual DataTable CheckedData
- {
- get
- {
- return _checkedData;
- }
- set
- {
- this._checkedData = value;
- }
- }
- /// <summary>
- /// 窗体标题
- /// </summary>
- [DefaultValue("")]
- public virtual string FormText
- {
- get
- {
- if (this._searchForm == null)
- {
- return string.Empty;
- }
- return this._searchForm.Text;
- }
- set
- {
- if (this._searchForm == null)
- {
- return;
- }
- this._searchForm.Text = value;
- }
- }
- /// <summary>
- /// 获取或设置查询条件(多选时,不能设置)。
- /// </summary>
- [Description("获取或设置查询条件(多选时,不能设置)。"), Category("CustomerEx")]
- [DefaultValue("")]
- [Browsable(true)]
- //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- //[EditorBrowsable(EditorBrowsableState.Advanced)]
- public override string Text
- {
- get
- {
- return this.txtCondition1.Text;
- }
- set
- {
- if (!this.MultiSelect /*&& !this.EditReadOnly && !this.ReadOnly*/)
- {
- this.txtCondition1.Text = value;
- }
- //base.Text = value;
- }
- }
- /// <summary>
- ///
- /// </summary>
- public TextBox Condition
- {
- get
- {
- return this.txtCondition1;
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示文本框中的文本是否为只读。
- /// </summary>
- [Description("获取或设置一个值,该值指示文本框中的文本是否为只读。"), Category("CustomerEx")]
- [DefaultValue(false)]
- public virtual bool ReadOnly
- {
- get
- {
- return this._readOnly;
- }
- set
- {
- if (this._readOnly != value)
- {
- this._readOnly = value;
- this.SetReadOnly();
- this.OnReadOnlyChanged(EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示文本框中的文本是否为只读。
- /// </summary>
- [Description("获取或设置一个值,该值指示文本框中的文本是否为只读。"), Category("CustomerEx")]
- [DefaultValue(true)]
- public virtual bool EditReadOnly
- {
- get
- {
- if (this.MultiSelect)
- {
- this._editReadOnly = true;
- }
- return this._editReadOnly;
- }
- set
- {
- if (this.MultiSelect)
- {
- value = true;
- }
- if (this._editReadOnly != value)
- {
- this._editReadOnly = value;
- this.SetEditReadOnly();
- this.OnEditReadOnlyChanged(EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 获取或设置控件的显示的属性
- /// </summary>
- [Description("获取或设置控件的显示的属性。"), Category("CustomerEx")]
- [DefaultValue("")]
- public virtual string DisplayMember
- {
- get
- {
- //if (this._displayMembers.Count == 0)
- //{
- // return string.Empty;
- //}
- //return this._displayMembers[0];
- return this._displayMember;
- }
- set
- {
- if (value == null)
- {
- value = string.Empty;
- }
- if (this._displayMember != value)
- {
- this._displayMember = value;
- this.ResetDisplayText();
- }
- //if (this.DisplayMember != value)
- //{
- // if (this._displayMembers.Count == 0)
- // {
- // this._displayMembers.Add(value);
- // }
- // else
- // {
- // this._displayMembers[0] = value;
- // }
- // this.ResetDisplayText();
- //}
- }
- }
- /// <summary>
- /// 获取或设置一个属性,该属性将用作控件中的项的实际值。
- /// </summary>
- [Description("获取或设置一个属性,该属性将用作控件中的项的实际值。"), Category("CustomerEx")]
- [DefaultValue("")]
- public virtual string ValueMember
- {
- get
- {
- return this._valueMember;
- }
- set
- {
- this._valueMember = value;
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示查询结果数据集中的主键。
- /// </summary>
- [Description("获取或设置一个值,该值指示查询结果数据集中的主键。"), Category("CustomerEx")]
- [DefaultValue("")]
- public virtual string PKMember
- {
- get
- {
- if (this._searchForm != null)
- {
- return this._searchForm.PKMember;
- }
- return null;
- }
- protected set
- {
- if (this._searchForm != null)
- {
- this._searchForm.PKMember = value;
- }
- }
- }
- /// <summary>
- /// 获取或设置一个值,该值指示是否能够多项选择。
- /// </summary>
- [Description("获取或设置一个值,该值指示是否能够多项选择。"), Category("CustomerEx")]
- [DefaultValue(false)]
- public virtual bool MultiSelect
- {
- get
- {
- if (this._searchForm != null)
- {
- this._multiSelect = this._searchForm.MultiSelect;
- }
- return this._multiSelect;
- }
- set
- {
- if (this._multiSelect != value)
- {
- this._multiSelect = value;
- if (this._searchForm != null)
- {
- this._searchForm.MultiSelect = value;
- }
- if (value)
- {
- this.EditReadOnly = value;
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置限制查询的范围权限类型。
- /// </summary>
- [Description("获取或设置限制查询的范围权限类型。"), Category("CustomerEx")]
- [DefaultValue(typeof(PurviewType), "None")]
- public virtual PurviewType PurviewType
- {
- get
- {
- return this._purviewType;
- }
- set
- {
- if (!Enum.IsDefined(typeof(PurviewType), value))
- {
- return;
- }
- if (this._purviewType != value)
- {
- this._purviewType = value;
- if (this._searchForm != null)
- {
- this._searchForm.PurviewType = value;
- }
- }
- }
- }
- /// <summary>
- /// 获取查询窗体
- /// </summary>
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public ISearchBoxForm SearchForm
- {
- get
- {
- return this._searchForm;
- }
- }
- /// <summary>
- /// 获取数据来源。
- /// </summary>
- [Description("获取数据来源。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public SearchBoxValueFrom ValueFrom
- {
- get
- {
- return this._valueFrom;
- }
- }
- /// <summary>
- /// 获取选择的项目
- /// </summary>
- [Description("获取选择的项目。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public DataRow SearchedItem
- {
- get
- {
- //if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- //{
- // return null;
- //}
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0)
- {
- return null;
- }
- return this._checkedData.Rows[0];
- }
- }
- public object[] InitItems
- {
- get;
- private set;
- }
- /// <summary>
- /// 获取选择的项目的值。
- /// </summary>
- [Description("获取选择的项目的ID值。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public int SearchedPKMember
- {
- set
- {
- _searchedPKMember = value;
- }
- get
- {
- //if (this._valueFrom == SearchBoxValueFrom.InitValue)
- //{
- // return this._initValue;
- //}
- //if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- //{
- // return null;
- //}
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0 ||
- !this._checkedData.Columns.Contains(this.PKMember))
- {
- return _searchedPKMember;
- }
- int.TryParse(this._checkedData.Rows[0][this.PKMember] + "", out _searchedPKMember);
- return _searchedPKMember;
- }
- }
- /// <summary>
- /// 获取选择的项目的值。
- /// </summary>
- [Description("获取选择的项目的值。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public object SearchedValue
- {
- get
- {
- //if (this._valueFrom == SearchBoxValueFrom.InitValue)
- //{
- // return this._initValue;
- //}
- //if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- //{
- // return null;
- //}
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0 ||
- !this._checkedData.Columns.Contains(this._valueMember))
- {
- return this._initValue;
- }
- return this._checkedData.Rows[0][this._valueMember];
- }
- }
- /// <summary>
- /// 获取选择的项目的文本表示形式。
- /// </summary>
- [Description("获取选择的项目的文本表示形式。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public string SearchedText
- {
- get
- {
- if (this._valueFrom == SearchBoxValueFrom.InitValue)
- {
- return this._initText;
- }
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0 ||
- !this._checkedData.Columns.Contains(this._displayMember))
- {
- return null;
- }
- return this.FormatDisplay(this._checkedData.Rows[0][this._displayMember]);
- }
- }
- /// <summary>
- /// 获取选定的项目
- /// </summary>
- [Description("获取选择的项目。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public DataTable CheckedItems
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- return this._checkedData;
- }
- }
- /// <summary>
- /// 获取选定的项目的值。
- /// </summary>
- [Description("获取选定的项目的值。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public object[] CheckedValues
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0 ||
- !this._checkedData.Columns.Contains(this._valueMember))
- {
- return null;
- }
- object[] values = new object[this._checkedData.Rows.Count];
- for (int i = 0; i < this._checkedData.Rows.Count; i++)
- {
- values[i] = this._checkedData.Rows[i][this._valueMember];
- }
- return values;
- }
- }
- /// <summary>
- /// 获取选定的项目的值,用【,】隔开。
- /// </summary>
- [Description("获取选定的项目的值,用【,】隔开。"), Category("CustomerEx")]
- //[Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public string CheckedValue
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- object[] values = this.CheckedValues;
- if (values == null)
- {
- return string.Empty;
- }
- string value =
- string.Join(Constant.MULTIPLE_VALUE_SEPARATOR,
- values);
- return value;
- }
- }
- /// <summary>
- /// 获取选定的项目的ID。
- /// </summary>
- [Description("获取选定的项目的ID。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public object[] CheckedPKMembers
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0 ||
- !this._checkedData.Columns.Contains(this._valueMember))
- {
- return null;
- }
- object[] values = new object[this._checkedData.Rows.Count];
- for (int i = 0; i < this._checkedData.Rows.Count; i++)
- {
- values[i] = this._checkedData.Rows[i][PKMember];
- }
- return values;
- }
- }
- /// <summary>
- /// 获取选定的项目的ID,用【,】隔开。
- /// </summary>
- [Description("获取选定的项目的ID,用【,】隔开。"), Category("CustomerEx")]
- //[Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public string CheckedPKMember
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- object[] values = this.CheckedPKMembers;
- if (values == null)
- {
- return string.Empty;
- }
- string value =
- string.Join(Constant.MULTIPLE_VALUE_SEPARATOR,
- values);
- return value;
- }
- }
- /// <summary>
- /// 获取选定的项目的文本表示形式。
- /// </summary>
- [Description("获取选定的项目的文本表示形式。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public string[] CheckedTexts
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- if (this._checkedData == null ||
- this._checkedData.Rows.Count == 0 ||
- !this._checkedData.Columns.Contains(this._displayMember))
- {
- return null;
- }
- string[] values = new string[this._checkedData.Rows.Count];
- for (int i = 0; i < this._checkedData.Rows.Count; i++)
- {
- values[i] = this.FormatDisplay(this._checkedData.Rows[i][this._displayMember]);
- }
- return values;
- }
- }
- /// <summary>
- /// 获取选定的项目的文本表示形式,用【,】隔开。
- /// </summary>
- [Description("获取选定的项目的文本表示形式,用【,】隔开。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public string CheckedText
- {
- get
- {
- if (this._valueFrom != SearchBoxValueFrom.SearchForm)
- {
- return null;
- }
- string[] values = this.CheckedTexts;
- if (values == null)
- {
- return string.Empty;
- }
- string value =
- string.Join(Constant.MULTIPLE_TEXT_SEPARATOR,
- values);
- return value;
- }
- }
- /// <summary>
- /// 获取或设置其他自定义属性。
- /// </summary>
- [Description("获取或设置其他自定义属性。"), Category("CustomerEx")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public ExtendedProperties Properties
- {
- get
- {
- if (this._searchForm == null)
- {
- return null;
- }
- return this._searchForm.Properties;
- }
- }
- #endregion
- #region 重写属性
- /// <summary>
- /// 获取或设置控件四周绘制的边框的类型
- /// </summary>
- [Description("获取或设置控件四周绘制的边框的类型。"), Category("CustomerEx")]
- [DefaultValue(typeof(BorderStyle), "None")]
- [Browsable(false)]
- [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- [EditorBrowsable(EditorBrowsableState.Advanced)]
- public new BorderStyle BorderStyle
- {
- get
- {
- return base.BorderStyle;
- }
- set
- {
- base.BorderStyle = value;
- }
- }
- /// <summary>
- /// 获取或设置控件的背景色
- /// </summary>
- [DefaultValue(typeof(Color), "Transparent")]
- public override Color BackColor
- {
- get
- {
- return base.BackColor;
- }
- set
- {
- base.BackColor = value;
- }
- }
- #endregion
- #region 事件处理
- /// <summary>
- /// 键盘按下
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void Condition_KeyDown(object sender, KeyEventArgs e)
- {
- if (this.EditReadOnly && !this._readOnly)
- {
- if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
- {
- this.ClearValue();
- }
- }
- }
- /// <summary>
- /// 文本改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void Condition_TextChanged(object sender, EventArgs e)
- {
- if (this._resetText)
- {
- return;
- }
- this._valueFrom = SearchBoxValueFrom.UserInput;
- }
- /// <summary>
- /// 关闭查询窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void SearchBoxForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- this.OnSearchFormClosed(e);
- }
- /// <summary>
- /// 点击查询按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSearch_Click(object sender, EventArgs e)
- {
- this.ShowSearchForm();
- }
- #endregion
- #region 公有方法
- /// <summary>
- /// 打开查询窗体
- /// </summary>
- public virtual void ShowSearchForm()
- {
- if (this._searchForm == null)
- {
- return;
- }
- //if (!this.MultiSelect)
- //{
- // this._searchForm.SetConditions(this.txtCondition1.Text);
- //}
- if (this.ValueFrom == SearchBoxValueFrom.UserInput)
- {
- string display = this.DisplayMember.ToUpper();
- if (display.EndsWith("CODE"))
- {
- this.SearchForm.SetConditions(this.txtCondition1.Text, "");
- }
- else
- {
- this.SearchForm.SetConditions(this.txtCondition1.Text);
- }
- }
- this._searchForm.Show();
- }
- /// <summary>
- /// 初始化显示的值
- /// </summary>
- /// <param name="text"></param>
- /// <param name="value"></param>
- public virtual void InitValue(string text, object value, params object[] items)
- {
- this._initText = text;
- this._initValue = value;
- this.txtCondition1.Text = text;
- this._valueFrom = SearchBoxValueFrom.InitValue;
- InitItems = items;
- }
- ///// <summary>
- ///// 关闭查询窗体
- ///// </summary>
- //public virtual void CloseSearchForm()
- //{
- // this._searchForm.CloseSearchForm();
- //}
- ///// <summary>
- ///// 清除查询条件
- ///// </summary>
- //public virtual void ClearConditions()
- //{
- // this._searchForm.ClearConditions();
- //}
- ///// <summary>
- ///// 清除查询结果
- ///// </summary>
- //public virtual void ClearQueryResults()
- //{
- // this._searchForm.ClearQueryResults();
- //}
- #endregion
- #region 保护方法
- /// <summary>
- /// 初始化查询文本框集合
- /// </summary>
- protected virtual void InitQueryControls()
- {
- this._queryControls.Add(this.txtCondition1);
- }
- /// <summary>
- /// 创建查询窗体。
- /// </summary>
- protected virtual ISearchBoxForm CreatSearchForm()
- {
- //SearchBoxForm form = FormFactory.CreatForm<SearchBoxForm>();
- //return form;
- return null;
- }
- /// <summary>
- /// 当查询窗体关闭时。
- /// </summary>
- /// <param name="e"></param>
- protected virtual void OnSearchFormClosed(FormClosedEventArgs e)
- {
- if (this._searchForm == null)
- {
- return;
- }
- this._searchForm.RefreshData();
- DialogResult dialogResult = this._searchForm.DialogResult;
- if (dialogResult == DialogResult.OK)
- {
- this._checkedData = this._searchForm.CheckedData;
- if (this._checkedData == null || this._checkedData.Rows.Count == 0)
- {
- this.ClearValue();
- }
- else
- {
- this._valueFrom = SearchBoxValueFrom.SearchForm;
- this.ResetDisplayText();
- this._valueFrom = SearchBoxValueFrom.SearchForm;
- this.OnSearchedItemChanged(EventArgs.Empty);
- }
- }
- }
- /// <summary>
- /// 选择窗体关闭时,设置显示文本。
- /// </summary>
- protected virtual void ResetDisplayText()
- {
- this._resetText = true;
- this.txtCondition1.Text = this.CheckedText;
- this._resetText = false;
- }
- /// <summary>
- /// 格式化显示文本。
- /// </summary>
- /// <param name="value">选定的值</param>
- /// <returns>格式化显示的文本</returns>
- protected virtual string FormatDisplay(object value)
- {
- // TODO
- return value.ToString();
- }
- /// <summary>
- /// 设置文本框只读
- /// </summary>
- protected virtual void SetEditReadOnly()
- {
- //foreach (TxtTextBox item in this._queryConditions)
- //{
- // item.ReadOnly = this._editReadOnly;
- //}
- this.txtCondition1.ReadOnly = this.EditReadOnly || this._readOnly;
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 设置控件只读
- /// </summary>
- private void SetReadOnly()
- {
- this.SetEditReadOnly();
- this.btnSearch.Enabled = !this._readOnly;
- }
- #endregion
- #region IDataVerifiable 成员
- #region 成员变量
- /// <summary>
- /// 显示边框颜色
- /// </summary>
- private bool _showBorderColor = true;
- /// <summary>
- /// 控件的项目名
- /// </summary>
- private string _itemName = null;
- /// <summary>
- /// 控件是否是必须输入项目
- /// </summary>
- private bool _mustInput = false;
- /// <summary>
- /// 控件在验证输入错误时,如何提示
- /// </summary>
- private InputErrorAlert _errorAlert = InputErrorAlert.Validated;
- /// <summary>
- /// 是否显示必须输入项目的提示
- /// </summary>
- private bool _showMustInputAlert = true;
- /// <summary>
- /// 验证不通过时,焦点能否离开
- /// </summary>
- private bool _canLostFocusOnError = true;
- /// <summary>
- /// 验证是否有错误
- /// </summary>
- private bool _hasError = false;
- /// <summary>
- /// 是否自定义错误
- /// </summary>
- private bool _hasCustomerError = false;
- /// <summary>
- /// 错误编码
- /// </summary>
- private ControlErrorCode _errorCode = ControlErrorCode.DKC_0000;
- /// <summary>
- /// 错误消息
- /// </summary>
- private string _errorMessage = null;
- /// <summary>
- /// 自定义错误消息
- /// </summary>
- private string _customerErrorMessage = null;
- #endregion
- #region 属性
- /// <summary>
- /// 获取或设置控件是否显示边框颜色。
- /// </summary>
- [Description("获取或设置控件是否显示边框颜色。"), Category("IDataVerifiable")]
- [DefaultValue(true)]
- public bool ShowBorderColor
- {
- get
- {
- return this._showBorderColor;
- }
- set
- {
- if (this._showBorderColor != value)
- {
- this._showBorderColor = value;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.ShowBorderColor = value;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置控件的项目名
- /// </summary>
- [Description("获取或设置控件的项目名。"), Category("IDataVerifiable")]
- [DefaultValue(null)]
- public string CDItemName
- {
- get
- {
- return this._itemName;
- }
- set
- {
- this._itemName = value;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.CDItemName = value;
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置控件是否必须选中项目。
- /// </summary>
- [Description("获取或设置控件是否必须选中项目。"), Category("IDataVerifiable")]
- [DefaultValue(false)]
- public bool MustInput
- {
- get
- {
- return this._mustInput;
- }
- set
- {
- if (this._mustInput != value)
- {
- this._mustInput = value;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.MustInput = value;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置控件是否必须选中项目。
- /// </summary>
- [Description("获取或设置控件在验证输入错误时,如何提示。"), Category("IDataVerifiable")]
- [DefaultValue(typeof(InputErrorAlert), "Validated")]
- public InputErrorAlert InputErrorAlert
- {
- get
- {
- return this._errorAlert;
- }
- set
- {
- if (this._errorAlert != value)
- {
- this._errorAlert = value;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.InputErrorAlert = value;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置控件是否显示必须输入项目提示
- /// </summary>
- [Description("获取或设置控件是否显示必须输入项目提示。"), Category("IDataVerifiable")]
- [DefaultValue(true)]
- public bool ShowMustInputAlert
- {
- get
- {
- return this._showMustInputAlert;
- }
- set
- {
- if (this._showMustInputAlert != value)
- {
- this._showMustInputAlert = value;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.ShowMustInputAlert = value;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或设置当验证不通过时,控件是否可以失去焦点
- /// </summary>
- [Description("获取或设置当验证不通过时,控件是否可以失去焦点。"), Category("IDataVerifiable")]
- [DefaultValue(true)]
- public bool CanLostFocusOnError
- {
- get
- {
- return this._canLostFocusOnError;
- }
- set
- {
- if (this._canLostFocusOnError != value)
- {
- this._canLostFocusOnError = value;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.CanLostFocusOnError = value;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取控件校验时是否有错误
- /// </summary>
- [Description("获取控件校验时是否有错误。"), Category("IDataVerifiable")]
- [DefaultValue(false)]
- public bool HasError
- {
- get
- {
- //return this._hasCustomerError || this._hasError;
- if (this._hasCustomerError)
- {
- return this._hasCustomerError;
- }
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- if (dvItem.HasError)
- {
- return true;
- }
- }
- }
- return false;
- }
- }
- /// <summary>
- /// 获取控件校验时的错误编码
- /// </summary>
- [Description("获取控件校验时的错误编码。"), Category("IDataVerifiable")]
- [DefaultValue(typeof(ControlErrorCode), "DKC_0000")]
- public ControlErrorCode ErrorCode
- {
- get
- {
- //return this._hasCustomerError ? ControlErrorCode.DKC_C001 : this._errorCode;
- if (this._hasCustomerError)
- {
- return ControlErrorCode.DKC_C001;
- }
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- if (dvItem.HasError)
- {
- return dvItem.ErrorCode;
- }
- }
- }
- return this._errorCode;
- }
- }
- /// <summary>
- /// 获取控件校验时的错误消息
- /// </summary>
- [Description("获取控件校验时的错误编码。"), Category("IDataVerifiable")]
- [DefaultValue(null)]
- public string ErrorMessage
- {
- get
- {
- //return this._hasCustomerError ? this._customerErrorMessage : this._errorMessage;
- if (this._hasCustomerError)
- {
- return this._customerErrorMessage;
- }
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- if (dvItem.HasError)
- {
- return dvItem.ErrorMessage;
- }
- }
- }
- return this._errorMessage;
- }
- }
- #endregion
- #region 公有方法
- /// <summary>
- /// 设置自定义错误
- /// </summary>
- /// <param name="hasError">输入是否有错误</param>
- /// <param name="errorMessage">错误消息</param>
- public virtual void SetCustomerError(bool hasError, string errorMessage)
- {
- if (this._hasCustomerError != hasError ||
- this._customerErrorMessage != errorMessage)
- {
- this._hasCustomerError = hasError;
- this._customerErrorMessage = errorMessage;
- this.OnHasErrorChanged(EventArgs.Empty);
- this.InvalidateBorder();
- }
- }
- /// <summary>
- /// 清除自定义错误
- /// </summary>
- public virtual void ClearCustomerError()
- {
- this.SetCustomerError(false, null);
- }
- /// <summary>
- /// 验证输入内容
- /// </summary>
- /// <returns>验证结果</returns>
- public virtual bool ValidateData()
- {
- //string text = base.Text;
- //if (this._mustInput && text.Length == 0)
- //{
- // this.SetError(true, ControlErrorCode.DKC_0001, this._itemName);
- // return false;
- //}
- //this.ClearError();
- //return true;
- bool result = true;
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- result = result && dvItem.ValidateData();
- }
- }
- return result;
- }
- /// <summary>
- /// 清除输入项
- /// </summary>
- public virtual void ClearValue()
- {
- foreach (TextBox item in this._queryControls)
- {
- if (item is IDataVerifiable)
- {
- IDataVerifiable dvItem = item as IDataVerifiable;
- dvItem.ClearValue();
- }
- }
- if (this._checkedData != null && this._checkedData.Rows.Count > 0)
- {
- this._checkedData.Clear();
- this.OnSearchedItemChanged(EventArgs.Empty);
- }
- SearchedPKMember = 0;
- }
- #endregion
- #region 保护方法
- /// <summary>
- /// 设置验证不通过错误
- /// </summary>
- /// <param name="hasError">是否有错误</param>
- /// <param name="code">错误编码</param>
- /// <param name="args">设置格式的对象</param>
- protected void SetError(bool hasError, ControlErrorCode code, params object[] args)
- {
- if (this._hasError != hasError ||
- this._errorCode != code)
- {
- this._hasError = hasError;
- this._errorCode = code;
- if (args != null && args.Length > 0)
- {
- this._errorMessage = string.Format(code.GetDescription(), args);
- }
- else
- {
- this._errorMessage = code.GetDescription();
- }
- this.OnHasErrorChanged(EventArgs.Empty);
- this.InvalidateBorder();
- }
- }
- /// <summary>
- /// 清除验证不通过错误
- /// </summary>
- protected void ClearError()
- {
- this.SetError(false, ControlErrorCode.DKC_0000);
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 使父控件的指定区域无效(将其添加到控件的更新区域,下次绘制操作时将重新绘制更新区域),并向父控件发送绘制消息。
- /// </summary>
- private void InvalidateBorder()
- {
- //Color? borderColor = BorderColorPaint.GetBorderColor(this as IDataVerifiable, this._entered, this._mouseOver);
- //if (borderColor != this._borderColor)
- //{
- // this._borderColor = borderColor;
- // if (this.Parent == null)
- // {
- // this.Invalidate();
- // }
- // else
- // {
- // this.Parent.Invalidate(this.Bounds, true);
- // }
- //}
- }
- #endregion
- #endregion
- #region IAsyncControl 成员
- #region 成员变量
- /// <summary>
- /// 异步处理开始时,控件状态
- /// </summary>
- private bool _asyncBeginStatus = false;
- private bool _asyncBeginFocused = false;
- private Control _activeControl = null;
- #endregion
- #region 公有方法
- /// <summary>
- /// 开始异步处理
- /// </summary>
- /// <param name="doFocus">是否处理焦点</param>
- public virtual void BeginAsync(ref bool doFocus)
- {
- this._asyncBeginFocused = false;
- //if (doFocus && this.Focused)
- if (doFocus && this.ActiveControl != null)
- {
- this._asyncBeginFocused = true;
- this._activeControl = this.ActiveControl;
- doFocus = false;
- }
- this._asyncBeginStatus = this.ReadOnly;
- this.ReadOnly = true;
- }
- /// <summary>
- /// 结束异步处理
- /// </summary>
- public virtual void EndAsync()
- {
- this.ReadOnly = this._asyncBeginStatus;
- if (this._asyncBeginFocused)
- {
- //this.Focus();
- this.ActiveControl = this._activeControl;
- this._activeControl = null;
- }
- }
- #endregion
- #endregion
- }
- }
|