Check how the data fills in the form in the form

xiaoxiao2021-03-06  40

/ / Check the method (class) of the data in the form (class) to use each control tag property, determine the data type of this control, whether it allows empty (1 is 1 means can't be empty, the bit is 0) Empty, ten digits represent data type; see source code)

If you change to the use of regular expressions, it may be better. // Use: try {checkform controls.tcheckformControls.checkform_data (Object ParentControl);} catch (exception err) {messagebox.show (err.message);}

// Source Namespace CheckformControls {Public Enum Tkhyhdatattype: INT {UNKNOW = 0, Integer = 1, FLOAT = 2, String = 3, Date = 4, DateTime = 5, Time = 6, Number = 7 // It Only Use 0- 9 numbers, for example: 08688122784} ///

/// CheckFormControls /// public class TCheckFormControls {public const string sELECT_ITEM = "Please select a item in /" {0} /; "." Public const same = "{0} /" could not be empty, please check it. "; public const string error_in_convert =" '{0}' Couldn't Be Convert to {1}, please check your input in / "{2} /". "; Public const string error_input =" it Only can be infut {0}, please check your input in / "{1} /" "

private static bool ParseTypeValue (object tag, out TKhyhDataType ofDataType, out string sDataType, out bool bNeedData) {if (tag == null) {ofDataType = TKhyhDataType.Unknow; sDataType = ofDataType.ToString (); bNeedData = false; return false; } Int off {OFTYPEVALUE = Convert.Toint32 (tag.tostring ()); bneeddata = ((OfftyValue% 10) == 1); OffeValue = (OfftyValue- (OFTYPEVALUE% 10)) / 10;

ofDataType = (TKhyhDataType) System.Enum.Parse (typeof (TKhyhDataType), ofTypeValue.ToString ()); sDataType = ofDataType.ToString ();} catch {ofDataType = TKhyhDataType.Unknow; sDataType = ofDataType.ToString (); bNeedData = False; return false;} Return true;} ///

/// Checkform_Data /// /// /// 台 check control sort by control's TabIndex /// Data Type is by control's Tag /// Control's name is read from controls' AccessibleDescription public static void CheckForm_Data (Control parentSender) {Control obj, obj2; TKhyhDataType ofDataType; bool bNeedData; string objName; string sDataType; ArrayList arrList = new arraylist (); int idx; for (int i = 0; i

For (int i = 0; i

IF (! Parstypevalue (Obj.tag, Out OfDataType, Out SDATYPE, OUT BNEEDDATA) Continue;

IF (obj.tag == null) Continue;

//Messagebox.show (obj.name.tostring ()); //undinue;

IF (obj.accessibleDescription == null) objName = ""; else objName = obj.accessibleDescription.toString (); if (objName.length == 0) ObjName = obj.name;

if (obj is ListBox) {ListBox lstObj = obj as ListBox; if (bNeedData && lstObj.SelectedItems.Count == 0) {//lstObj.BackColor=Color.Red; throw new Exception (string.Format (SELECT_ITEM, objName) );}} else if (obj is ComboBox) {ComboBox lstObj = obj as ComboBox; if (bNeedData && lstObj.SelectedItem == null) {//lstObj.BackColor=Color.Red; throw new Exception (string.Format (sELECT_ITEM ,}}}}} else if (obj is textbox) {textbox textobj = obj as textbox; string v = textobj.text; if (v.Length == 0) {if (bneeddata) throw new exception (String.Format) (Could_not_empty, objName)); Else Continue;}

Switch (OFDATYPE) {CASE TKHYHDATYPE.INTEGER: try {convert.Toint32 (v);} catch {throw new exception (String.Format);} Break;

转载请注明原文地址:https://www.9cbs.com/read-82644.html

New Post(0)