| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678 |
-
- 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>
- /// <param name="text"></param>
- /// <param name="value"></param>
- public virtual void InitValue(string text, object value)
- {
- 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
- }
- }
|