Ext.net the interaction of data and form values (directly on the encapsulated code, see comments, not many explanations)

Source: Internet
Author: User

public class modelhander<t>{//<summary>//////For dynamic filling of entity classes through forms///</summary>//<typeparam     Name= "T" ></typeparam>//<param name= "T" ></param>//<param name= "form" ></param>    <returns></returns> public static int setmodeltoform (ref t T, namevaluecollection form, page page)        {int va = 0; Type type = T.gettype ();//get type propertyinfo[] pi = type.        GetProperties ();//Gets the property collection Type FieldType;        String ControlType; foreach (PropertyInfo p in pi) {//if (form[p.name]! = NULL && form[p.name]! = "")//Impact Radiogrou                    p {try {fieldtype = P.propertytype; ControlType = page. FindControl (P.name). GetType ().                    Name; if (FieldType! = null && Fieldtype.name = = "Nullable ' 1")//Determines whether a nullable type {fi Eldtype = Nullable.                    Getunderlyingtype (P.propertytype); } if (ControlType = = "ComboBox")//combox processing to get the value {P.set Value (T, Convert.changetype ((ComboBox) page. FindControl (P.name)).                    Selecteditem.value, FieldType), NULL); } else if (ControlType = = "Radiogroup") {Radiogroup Radiogro Up = page.                         FindControl (P.name) as radiogroup;//is not executed here to be resolved for (int i = 0; i < RadioGroup.Items.Count; i++) {if (radiogroup.items[i]. Checked = = True) {P.setvalue (T, Convert.changetype (RADIOGROUP.I Tems[i].                                Inputvalue, FieldType), NULL);                            Break                    }}} and Else if (ControlType = = "checkbox")                 {       if ((Checkbox) page. FindControl (P.name)).                        Checked) {p.setvalue (T, Convert.changetype ("1", FieldType), NULL); } else {P.setvalue (T, conver                        T.changetype ("0", FieldType), NULL);                        }} else if (ControlType = = "Label")//combox processing Gets the value values separately { P.setvalue (T, Convert.changetype ((Label) page. FindControl (P.name)).                    Text, FieldType), NULL);                        } else if (ControlType = = "HtmlEditor")//combox processed separately to get the value values { P.setvalue (T, Convert.changetype ((HtmlEditor) page. FindControl (P.name)).                    Text, FieldType), NULL);                        } else if (ControlType = = "Datefield")//datefield processed separately to get the value values { P.setvalue (T, Convert.changetype((Datefield) page. FindControl (P.name)).                    Text, FieldType), NULL); } else {P.setvalue (T, Convert.changetype (Form[p.name], field                type), NULL),//Assign a value to the property, and convert the type of the key value to the type of the property} va++;//record the number of properties for which the assignment succeeded}    Catch {}}} return VA; }///<summary>//Set Control value//Control:textfield,textarea,label,datefield,multicombo,combobox,radio,checkbox , Numberfield///</summary>//<typeparam name= "T" ></typeparam>//<param name= "T" >< /param>//<param name= "page" > current page, looking for controls </param>//<param name= "Acttype" > Action type (EDIT, QUERY) &L            t;/param> public static void Setdataofcontrol (T T, page page, string acttype) {if (t==null) {        Return        } Type type = T.gettype (); propertyinfo[] pi = type. GetprOperties ();        String ControlType;        Object obj;        String[] Multiitems;            Acttype = Acttype.toupper ();//action type foreach (PropertyInfo p in pi) {if (P.name! = "ID")                    {try {obj = p.getvalue (t, NULL); ControlType = page. FindControl (P.name). GetType ().                    Name; Switch (controltype) {case "TextField": TextField te Xtfield = ((TextField) page.                            FindControl (P.name));                            if (obj! = null) {textfield.setvalue (obj);                                if (Acttype = = "Query")//when the control is grayed out, read-only {                                textfield.enabled = false;                                Textfield.readonly = true; Textfield.cls = "textdisabled";                               Textfield.disabled = true;                        } break; Case "TextArea": TextArea TextArea = ((TextArea) page.                            FindControl (P.name)); if (obj! = null) {Textarea.text = obj.                            ToString (); } if (Acttype = = "QUERY") {//textare                                a.enabled = false;                            Textarea.readonly = true;                        } break; Case "label": Label label = ((Label) page.                            FindControl (P.name)); if (obj! = null) {label. Text = obj.                            ToString ();                    } break;    Case "Datefield": Datefield Datefield = ((Datefield) page.                            FindControl (P.name)); if (obj! = null) {Datefield.text = obj.                            ToString ();                                if (Acttype = = "Query")//when the control is grayed out, read-only {                                datefield.enabled = false;                            Datefield.readonly = true;                        } break; Case "Multicombo": Multicombo Multicombo = ((Multicombo) page.                            FindControl (P.name)); if (obj! = null) {//multiitems=obj. ToString ().                                Split (', '); foreach (string item in Multiitems)//{//Multicombo.s     Electitem (item);                           Multicombo.value = obj.                                ToString ();                                }} if (Acttype = = "QUERY") {                                Multicombo.readonly = true;                            Multicombo.disabled = true;                        } break; Case "ComboBox": ComboBox ComboBox = (ComboBox) page.                            FindControl (P.name)); if (obj! = null) {ComboBox.SelectedItem.Value = obj.                            ToString (); } if (Acttype = = "QUERY") {ComboBox.                                ReadOnly = true;                            Combobox.disabled = true;                        } break;       Case "Radiogroup":                     Radiogroup radiogroup = page.                            FindControl (p.name) as Radiogroup;  for (int i = 0; i < RadioGroup.Items.Count; i++) {if (obj! = Null && radiogroup.items[i]. Inputvalue = = obj. ToString ()) {radiogroup.items[i].                                Checked = true;                                }} if (Acttype = = "QUERY") {                                radiogroup.enabled = false;                                Radiogroup.readonly = true;                            Radiogroup.disabled = true;                        } break; Case "checkbox": CheckBox checkbox = (checkbox) page.                            FindControl (P.name)); if (obj! = null && obj.        ToString () = = "1")                    {checkbox.                            Checked = true; } else {checkbox.                            Checked = false; } if (Acttype = = "QUERY") {checkbox.                                Enabled = false; CheckBox.                            ReadOnly = true;                        } break; Case "Hidden": Hidden Hidden = ((Hidden) page.                            FindControl (P.name)); if (obj! = null) {hidden. Text = obj.                            ToString ();                                if (Acttype = = "Query")//when the control is grayed out, read-only {                                textfield.enabled = false; Hidden. ReadOnly = true;                               Textfield.cls = "textdisabled";                            Textfield.disabled = true;                        } break; Case "Numberfield": Numberfield Numberfield = ((Numberfield) page.                            FindControl (P.name)); if (obj! = null) {Numberfield.text = obj.                            ToString ();                                if (Acttype = = "Query")//when the control is grayed out, read-only {                                textfield.enabled = false;                            Numberfield.readonly = true;                        } break; Case "Triggerfield": Triggerfield Triggerfield = ((Triggerfield) page.                            FindControl (P.name));                   if (obj! = null) {             Triggerfield.text = obj.                            ToString ();                                if (Acttype = = "Query")//when the control is grayed out, read-only {                                textfield.enabled = false;                            Triggerfield.readonly = true;                        } break; Case "HtmlEditor": HtmlEditor HtmlEditor = ((HtmlEditor) page.                            FindControl (P.name)); if (obj! = null) {Htmleditor.text = obj.                            ToString ();                                if (Acttype = = "Query")//when the control is grayed out, read-only {                                textfield.enabled = false;                                Htmleditor.readonly = true;                                Textfield.cls = "textdisabled";           Textfield.disabled = true;                 } break; Case "Gridpanel"://Gridpanel Gridpanel = ((gridpanel) page.                        FindControl (P.name)); if (obj! = null)////{////Gridpanel.text = obj.                        ToString ();                        }//if (Acttype = = "Query")//when the control is grayed out, read-only//{                        Gridpanelhelper.setcolumnseditable (Gridpanel.columnmodel, false); }//else//{//Gridpanelhelper.                        Setcolumnseditable (Gridpanel.columnmodel, true);                        }//break;                    Default:break;     }} catch {}}   }//end foreach//Gray Set Person button if (page. FindControl ("askmanbtn") = null && Acttype = = "QUERY") {button button = page.            FindControl ("Askmanbtn") as Button; button.        Disabled = true; } if (page. FindControl ("gridappfile") = null && Acttype = = "QUERY") {Fileuploadfield fileUpload = page.            FindControl ("F2") as Fileuploadfield;            Fileupload.disabled = true; Gridpanel Gridpanel = page.            FindControl ("Gridappfile") as Gridpanel; GRIDPANEL.COLUMNMODEL.COLUMNS[2].        Hidden = true; } if (page. FindControl ("btnadd") = null && Acttype = = "QUERY") {button btn = page.            FindControl ("Btnadd") as Button; Btn.        Disabled = true; } if (page. FindControl ("btndel") = null && Acttype = = "QUERY") {button btn = page.            FindControl ("Btndel") as Button; Btn.        Disabled = true; }} public static DataTable Getuserbyid (int userid) {String sql = "Select Uname,g_group. Gname as Uclass,uwork from U_user left joins Ug_user_group "+" on U_user. Uid=ug_user_group.uid "+" left join G_group on G_group. Gid=ug_user_group.gid "+" where u_user.        Uid= ' "+ userid +" ' "; DataTable dt = Sunway.DBUtility.DbHelperSQL.ExecuteDataSet (commandtype.text, SQL, NULL).        Tables[0];    return DT;         }///<summary>//Create Gridpanel columns and store///</summary> public static void Creategrdstore (T t) {        Type type = T.gettype (); propertyinfo[] pi = type.        GetProperties ();    String ControlType; }}
assigning values to the corresponding page control

   Modelhander<db_backapply>. Setdataofcontrol (model, this. Page, "QUERY");
Get its mode value

   Modelhander<db_backapply>. Setmodeltoform (ref model, Request.Form, this.) Page);



Ext.net the interaction of data and form values (directly on the encapsulated code, see comments, not many explanations)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.