Using System; using System. collections. generic; using System. linq; using System. text; using log4net. core; using System. linq. expressions; using System. web. mvc; using System. web. script. serialization; using System. text. regularExpressions; namespace Model. common {// <summary> // The exception help class encapsulates the try catch operation and uniformly calls the add, delete, and modify method. // </summary> public class ExceptionHelper {static log4net. ILog log = null; static JavaScriptSerializer JsonSerializer = new JavaScriptSerializer (); // json conversion class public ExceptionHelper (string classname) {log = log4net. logManager. getLogger (classname );} /// <summary> /// method call without return values and parameters /// </summary> /// <param name = "action"> </param> public void invoke (Action action) {try {action ();} catch (Exception ex) {log. error (ex. message );}} /// <summary> /// call a method with a returned value and no parameters /// </summary> /// <typeparam name = "T"> </typeparam> // /<param name = "func"> </param> // <returns> </returns> public static T Invoke <T> (Func <T> func) {try {return func ();} catch (Exception ex) {log. error (ex. message); return default (T );}} /// <summary> /// public method for obtaining non-query execution results /// </summary> /// <param name = "op"> operation method </ param> /// <param name = "nu"> newuser object </param> /// <param name = "errormsg"> error message </param> /// <returns> json result </returns> public static string GetNoQueryJsonResult <T> (Func <T, int> op, T nu, string errormsg, bool isvalid) {EasyResult er = new EasyResult (); er. success = false; try {if (isvalid) {int I = op (nu); if (I> 0) {er. success = true;} else {er. errorMsg = errormsg;} else {er. errorMsg = "Verification Failed. Check the data";} catch (Exception ex) {er. errorMsg = ex. message; log. error (ex. message, ex);} return JsonSerializer. serialize (er );}} /// <summary> /// the generic exception help class encapsulates the try catch operation and uniformly calls the query method. /// </summary> /// <typeparam name = "ModelType"> </typeparam> public class ExceptionHelper <ModelType> {public delegate List <ModelType> FuncEx (int t1, int t2, Dictionary <string, string> t3, out int t4); static log4net. ILog log = null; static JavaScriptSerializer JsonSerializer = new JavaScriptSerializer (); // json conversion class public ExceptionHelper (string classname) {log = log4net. logManager. getLogger (classname);} // <summary> // public method for obtaining query execution results (pagination) /// </summary> /// <param name = "op"> operation method </param> /// <param name = "pageIndex"> page number </param> /// <param name = "pageSize"> Number of records per page </param> /// <param name = "dicCondition"> query condition </param> /// <param name = "totalcount"> total </param> // <returns> json data set </returns> public static string GetQueryJsonResult (FuncEx op, int pageIndex, int pageSize, Dictionary <string, string> dicCondition, out int totalcount) {totalcount = 0; try {List <ModelType> lsnu = op (pageIndex, pageSize, dicCondition, out totalcount); EasyDataGrid <ModelType> edg = new EasyDataGrid <ModelType> (); edg. total = totalcount; // total number of records edg. rows = lsnu; // string str = JsonSerializer. serialize (edg); str = Regex. replace (str, @ "\/Date \ (\ d +) \/", match => {DateTime dt = new DateTime (1970, 1, 1); dt = dt. addMilliseconds (long. parse (match. groups [1]. value); dt = dt. toLocalTime (); return dt. toString ("yyyy-MM-dd") ;}); return str ;}catch (Exception ex) {log. error (ex. message, ex) ;}return "";}}}
Easy ui help class
Using System; using System. collections. generic; using System. linq; using System. text; namespace Model. common {// <summary> // easyui tree json data class // </summary> public class EasyTreeNode {public EasyTreeNode () {attributes = new Dictionary <string, string> (); children = new List <EasyTreeNode> ();} /// <summary> /// tree id /// </summary> public int id {get; set ;} /// <summary> /// text displayed in the tree /// </summary> public string text {get; set ;} /// <summary> // other attributes <attribute name, attribute value> /// </summary> public Dictionary <string, string> attributes {get; set ;} /// <summary >/// subnode /// </summary> public List <EasyTreeNode> children {get; set ;}} /// <summary> // easyui datagrid json data class // </summary> public class EasyDataGrid <T> {public EasyDataGrid () {rows = new List <T> () ;}/// <summary> /// total number of records /// </summary> public int total {get; set ;} /// <summary> /// set of row data (<field name, field value>) /// </summary> public List <T> rows {get; set ;}//< summary> /// return information /// </summary> public class EasyResult {public string errorMsg {get; set ;} public bool success {get; set ;}}}
References related dll.