1.分頁數據模型:PagedDataModel.cs
用處:將分頁的數據,封裝到類中
public class PagedDataModel<T> { /// <summary> /// 總頁數 /// </summary> public int PageCount; /// <summary> /// 總行數 /// </summary> public int RowCount; /// <summary> /// 當前頁碼 /// </summary> public int PageIndex; /// <summary> /// 當前頁碼數據 /// </summary> public IList<T> PagedList; }
2.數據幫助類:DataHelper.cs
用處:對數據進行處理,以一定格式返回
public static class DataHelper { /// <summary> /// js序列化器 /// </summary> static JavaScriptSerializer jss=new JavaScriptSerializer(); /// <summary> /// 將對象轉換為json數組格式字符串 /// </summary> /// <param name="obj"></param> /// <returns></returns> public static string ObjToJson(object obj) { return jss.Serialize(obj); } /// <summary> /// 返回MD5加密字符串 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string MD5(string str) { return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, FormsAuthPasswordFormat.MD5.ToString()); } }
3.頁面幫助類:PageHelper.cs
用處:向前台展示js信息時
public class PageHelper { /// <summary> /// 讀取指定路徑的文件,並返回字符串格式 /// </summary> /// <param name="strPath">文件路徑-物理路徑 </param> /// <returns></returns> public static string ReadFile(string strPath) { return File.ReadAllText(strPath); } /// <summary> /// 獲取提示和跳轉js代碼字符串 /// </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> /// 跳轉js代碼字符串 /// </summary> /// <param name="strMsg"></param> public static void WriteJSMsg(string strMsg) { string strBack = "<script>alert(" + strMsg + ");</script>"; HttpContext.Current.Response.Write(strBack); } }
4.驗證幫助類:ValidateHelper.cs
用處:對數據進行驗證
public class ValidateHelper { static Regex regIsNum=new Regex("^[0-9]+$"); /// <summary> /// 驗證 參數是否為整型數值 /// </summary> /// <param name="strNum"></param> /// <returns></returns> public static bool IsNum(string strNum) { return regIsNum.IsMatch(strNum); } }
5.異步消息處理類AjaxMsgHelper.cs
用處:將需要返回的信息,以一定的內容形式返回
public static class AjaxMsgHelper { /// <summary> /// 以json的格式返回消息 /// </summary> /// <param name="statu">狀態碼</param> /// <param name="msg">狀態信息</param> /// <param name="data">返回數據</param> /// <param name="nextUrl">跳轉url</param> public static void AjaxMsg(string statu, string msg,string data,string nextUrl) { //{"statu":"err","msg":"出錯啦","data":[{},{}],"nextUrl":"Login.aspx"} string strMsg = "{\"statu\":\""+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); } }