Common projects and projects

Source: Internet
Author: User

Common projects and projects

1. Paging Data Model: PagedDataModel. cs

Usage: encapsulate paging data into a class.

Public class PagedDataModel <T >{/// <summary> // total number of pages /// </summary> public int PageCount; /// <summary> /// total number of rows /// </summary> public int RowCount; /// <summary> /// current page number /// </summary> public int PageIndex; /// <summary> /// current page data /// </summary> public IList <T> PagedList ;}

2. Data help class: DataHelper. cs

Usage: process the data and return it in a certain format.

Public static class DataHelper {// <summary> // js serializer // </summary> static JavaScriptSerializer jss = new JavaScriptSerializer (); /// <summary> /// convert the object to a json array string // </summary> /// <param name = "obj"> </param>/ // <returns> </returns> public static string ObjToJson (object obj) {return jss. serialize (obj );} /// <summary> /// return the MD5 encrypted string /// </summary> /// <param name = "str"> </param> /// <returns> </returns> public static string MD5 (string str) {return System. web. security. formsAuthentication. hashPasswordForStoringInConfigFile (str, FormsAuthPasswordFormat. MD5.ToString ());}}

3. Page help class: PageHelper. cs

Usage: When displaying js information to the front-end

Public class PageHelper {/// <summary> /// read the file in the specified path, returns the string format /// </summary> /// <param name = "strPath"> file path-physical path </param> /// <returns> </returns> public static string ReadFile (string strPath) {return File. readAllText (strPath );} /// <summary> /// get the prompt and jump to the js Code string // </summary> /// <param name = "strMsg"> </param> // /<param name = "strBackUrl"> </param> public static void WriteJSMsg (string strMsg, string strBackUrl) {string strBack = "<script> alert (" + strMsg + "); window. location = '"+ strBackUrl +"'; </script> "; HttpContext. current. response. write (strBack );} /// <summary> /// jump to the js Code string /// </summary> /// <param name = "strMsg"> </param> public static void WriteJSMsg (string strMsg) {string strBack = "<script> alert (" + strMsg + "); </script>"; HttpContext. current. response. write (strBack );}}

4. Verify the help class: ValidateHelper. cs

Use: verify data

Public class ValidateHelper {static Regex regIsNum = new Regex ("^ [0-9] + $ "); /// <summary> /// check whether the parameter is an integer value. /// </summary> /// <param name = "strNum"> </param> /// <returns> </returns> public static bool IsNum (string strNum) {return regIsNum. isMatch (strNum );}}

5. asynchronous message processing class AjaxMsgHelper. cs

Usage: return the information to be returned in the form of certain content.

Public static class AjaxMsgHelper {// <summary> // return the message in json format /// </summary> /// <param name = "statu"> Status Code </param> /// <param name = "msg"> status information </param> /// <param name = "data"> return data </param> // /<param name = "nextUrl"> jump url </param> public static void AjaxMsg (string statu, string msg, string data, string nextUrl) {// {"statu": "err", "msg": "error", "data ":[{}, {}], "nextUrl": "Login. aspx "} string strMsg =" {\ "sta Tu \ ": \" "+ statu +" \ ", \" msg \ ": \" "+ msg +" \ ", \" data \": "+ (data = null? "Null": data) + ", \" nextUrl \ ": \" "+ nextUrl +" \ "}"; HttpContext. current. response. write (strMsg);} public static void AjaxMsg (string statu, string msg, string data) {AjaxMsg (statu, msg, data, "null ");} public static void AjaxMsg (string statu, string msg) {AjaxMsg (statu, msg, null, null );}}

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.