Following the previous article WinForm program on the interface controls unified control of "one" (Assignment \ Empty \ Validation ...), this article will implement a similar function of the component (components).
Look at the implementation of the component first, as follows:
Code A
public partial class Ctrlvalidation:component
{
Public Ctrlvalidation ()
{
InitializeComponent ();
Typecache = new Typecache ();
}
Public ctrlvalidation (IContainer container)
{
Container. ADD (this);
InitializeComponent ();
Typecache = new Typecache ();
}
Typecache Typecache;
list<realsailing.ui.utils.setcontrol> ctrlcollect = new list<realsailing.ui.utils.setcontrol> ();
[Description ("Control Collection")]
[Editor (typeof (Dropeditor), typeof (UITypeEditor))]
[DesignerSerializationVisibility (Designerserializationvisibility.content)]
Public list<realsailing.ui.utils.setcontrol> Ctrlcollect
{
Get
{
return ctrlcollect;
}
Set
{
Ctrlcollect = value;
}
}
Private Object DataSource;
[Category ("Catdata"), DefaultValue ((string) null), Refreshproperties (Refreshproperties.repaint),
Description ("Datagriddatasourcedescr"), Attributeprovider (typeof (IListSource))]
public Object DataSource
{
Get
{
return this.datasource;
}
Set
{
if ((value!= null) &&! ( Value is IList) &&! (value is IListSource))
{
throw new ArgumentException ("baddatasourceforcomplexbinding");
}
if ((This.datasource = null) | | !this.datasource.equals (value))
{
if (((value = = null) | | (value = = Convert.dbnull)) && (this. DataMember!= null) && (this. Datamember.length!= 0))
{
This.datasource = null;
This. DataMember = "";
}
Else
{
if (value!= null)
{
This.datasource = value;
}
}
}
}
}
private string DataMember;
[DefaultValue ((string) null), Description ("DATAGRIDDATAMEMBERDESCR"),
Category ("Catdata"),
Editor ("System.Windows.Forms.Design.DataMemberListEditor, System.Design, version=2.0.0.0, Culture=neutral, Publickeytoken=b03f5f7f11d50a3a ", typeof (UITypeEditor))]
public string DataMember
{
Get
{
return this.datamember;
}
Set
{
if ((This.datamember = null) | | !this.datamember.equals (value))
{
This.datamember = value;
}
}
}
#region provides methods
<summary>
Whether the required item is empty, true to be null, FALSE to NULL
</summary>
<returns></returns>
public bool Checkisnull ()
{
foreach (RealSailing.UI.Utils.SetControl ctrl in Ctrlcollect)
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
BOOL Editnull = _process. Checknull ();
if (!editnull)
return editnull;
}
return true;
}
<summary>
The input box is in the correct format, true is correct, false indicates incorrect
</summary>
<returns></returns>
public bool Checkisformate ()
{
foreach (RealSailing.UI.Utils.SetControl ctrl in Ctrlcollect)
{
if (ctrl. Controlname.gettype (). Equals (typeof (DevExpress.XtraEditors.TextEdit)))
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
BOOL Editformate = _process. Checkformate ();
if (!editformate)
return editformate;
}
}
return true;
}
<summary>
Clear the screen.
</summary>
public void Setctrlclear ()
{
Ctrlcollect.foreach (Ctrl =>
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
_process. Setctrlclear ();
});
}
<summary>
To set the available state of a control
</summary>
<param name= "Enable" ></param>
public void setctrlenable (bool enable)
{
Ctrlcollect.foreach (Ctrl =>
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
_process. Setctrlenable (enable);
});
}
<summary>
To set the default value for a control
</summary>
public void Setctrldefault ()
{
Ctrlcollect.foreach (Ctrl =>
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
_process. Setctrldefault ();
});
}
<summary>
Clear error message
</summary>
public void Clearerrtext ()
{
Ctrlcollect.foreach (Ctrl =>
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
_process. Clearerrtext ();
});
}
<summary>
Map the value of a data row to a text edit box
</summary>
<param name= "Row" ></param>
public void Loadeditrowtotext (DataRow row)
{
if (row!= null)
{
Ctrlcollect.foreach (Ctrl =>
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
_process. Loadtotext (row);
});
}
}
<summary>
Assign data in an edit box to a data row
</summary>
<param name= "Row" ></param>
public void Setctrltexttoeditrow (DataRow row)
{
if (row!= null)
{
Ctrlcollect.foreach (Ctrl =>
{
object[] obj = new object[] {CTRL};
Typeprocess _process = Typefactory.createtype (ctrl. Controlname.gettype (). Name, obj, ctrl. ToString (), Typecache);
_process. Settexttorow (row);
});
}
}
#endregion
}