Mvc3 easyui exception help class (encapsulate try catch operations and uniformly call add, delete, modify, and query methods) and easy ui help class

Source: Internet
Author: User
Tags log4net

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.

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.