Interaction between ext.net data and form values (directly encapsulate the code, read comments, and not much explanation)
Public class ModelHander
{///
/// Dynamic filling of object classes through forms //////
///
///
///
Public static int SetModelToForm (ref T t, NameValueCollection form, Page page) {int va = 0; Type = t. getType (); // obtain the PropertyInfo [] pi = type. getProperties (); // obtain the attribute set Type fieldType; string ControlType; foreach (PropertyInfo p in pi) {// if (form [p. name]! = Null & form [p. Name]! = "") // Affects RadioGroup {try {fieldType = p. PropertyType; ControlType = page. FindControl (p. Name). GetType (). Name; if (fieldType! = Null & fieldType. name = "Nullable '1") // determines whether it is null. {fieldType = Nullable. getUnderlyingType (p. propertyType);} if (ControlType = "ComboBox") // ComBox independently obtains the Value {p. setValue (t, Convert. changeType (ComboBox) page. findControl (p. name )). selectedItem. value, fieldType), null);} else if (ControlType = "RadioGroup") {RadioGroup radioGroup = page. findControl (p. name) as RadioGroup; // not executed here for (int I = 0; I <radioGroup. items. count; I ++) {if (radioGroup. items [I]. checked = true) {p. setValue (t, Convert. changeType (radioGroup. items [I]. inputValue, fieldType), null); break ;}} else if (ControlType = "Checkbox") {if (Checkbox) page. findControl (p. name )). checked) {p. setValue (t, Convert. changeType ("1", fieldType), null);} else {p. setValue (t, Convert. changeType ("0", fieldType), null) ;}} else if (ControlType = "Label") // ComBox independently obtains the Value {p. setValue (t, Convert. changeType (Label) page. findControl (p. name )). text, fieldType), null);} else if (ControlType = "HtmlEditor") // ComBox independently obtains the Value {p. setValue (t, Convert. changeType (HtmlEditor) page. findControl (p. name )). text, fieldType), null);} else if (ControlType = "DateField") // obtain the Value {p. setValue (t, Convert. changeType (DateField) page. findControl (p. name )). text, fieldType), null);} else {p. setValue (t, Convert. changeType (form [p. name], fieldType), null); // assign values to the attribute and convert the type of the key value to the type of the attribute} va ++; // record the number of successfully Assigned attributes} catch {}} return va ;}///
/// Set the Control value // Control: TextField, TextArea, Label, DateField, MultiCombo, ComboBox, Radio, Checkbox, NumberField //////
///
///
On the current page, find the control ///
Action Type (EDIT, QUERY) public static void SetDataOfControl (T t, 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 textField = (TextField) page. findControl (p. name); if (obj! = Null) {textField. setValue (obj);} if (actType = "QUERY") // The controller is grayed out during QUERY, 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") {// textArea. 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") // The controller is grayed out during QUERY, 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. selectItem (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") // The controller is grayed out during QUERY, 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") // The controller is grayed out during QUERY, 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") // The controller is grayed out during QUERY, read-only {// textField. enabled = false; triggerField. readOnly = true;} break; case "HtmlEditor": HtmlEditor = (HtmlEditor) page. findControl (p. name); if (obj! = Null) {HtmlEditor. text = obj. toString ();} if (actType = "QUERY") // The controller is grayed out during QUERY, 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") // The controller is grayed out during QUERY, read-only // {// GridPanelHelper. setColumnsEditable (gridPanel. columnModel, false); // else // {// GridPanelHelper. setColumnsEditable (gridPanel. columnModel, true); // break; default: break; }}catch {}}// end foreach // sets the 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 join ug_User_Group "+" on u_user.UId = ug_User_Group.uId "+" left join g_group on g_group.GId = regular "+" where u_user.UId = '"+ userid + "'"; dataTable dt = Sunway. DBUtility. dbHelperSQL. executeDataSet (CommandType. text, SQL, null ). tables [0]; return dt ;}///
/// Create a GridPanel column and Store ///Public static void CreateGrdStore (T t) {Type type = t. GetType (); PropertyInfo [] pi = type. GetProperties (); string ControlType ;}}
Assign values to corresponding page controls
ModelHander
.SetDataOfControl(model, this.Page, "QUERY");
Obtain the mode value.
ModelHander
.SetModelToForm(ref model, Request.Form, this.Page);