ASP.NET MVC 增强Convert用法+【分页2】
2015-04-22 16:03
295 查看
【分页2】
public dynamic PageQuery() {
int pageIndex = Request.Params["page"] == null ? 1 : int.Parse(Request.Params["page"]);//Request["page"] 需要显示第几页 EasyUI datagrid自传
int pageSize = Request.Params["rows"] == null ? 10 : int.Parse(Request.Params["rows"]);//每页大小 EasyUI datagrid自传
try {
BackUserInfoPageCondition condition = new BackUserInfoPageCondition
{
pageIndex=pageIndex,
pageSize=pageSize,
UserCode = Request.Params["search_UserCode"],
UserName = Request.Params["search_UserName"],
IDNO = Request.Params["search_IDNO"],
Phone = Request.Params["search_Phone"],
DepartId = Request.Params["search_Depart"].Trim().ConvertTo<int>(),//默认-1请选择
DutyId = Request.Params["search_Duty"].Trim().ConvertTo<int>() ,
StatusFlag = Request.Params["search_StatusFlag"].Trim().ConvertTo<short?>(),
DimissionFlag = Request.Params["search_DimissionFlag"].Trim().ConvertTo<short?>(),
DisableFlag = Request.Params["search_DisableFlag"].Trim().ConvertTo<short?>(),
LockFlag = Request.Params["search_LockFlag"].Trim().ConvertTo<short?>()
};
var data = _IBackUserInfoService.PageQuery(condition);//根据条件query查询
var o = new { total = condition.total, rows = data };//EasyUI datagrid需要
return Json(o);
}
catch (Exception e)
{
//写日志
return Content("ERROR");
}
}
using System;using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace Common
{
public static class Utils
{
/// <summary>
/// MD5加密
/// https://social.msdn.microsoft.com/Forums/zh-CN/590bd6a8-57d7-4041-81da-80fe8b832b77/md5 /// http://blog.163.com/m13864039250_1/blog/static/21386524820150231533602/ /// </summary>
public static string GetMD5Hash(string input){
//MD5 md5Hash = MD5.Create();
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] data=md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));//字符串格式控制符 x 为十六进制 2每次两位数
}//0xA、0x1A,这样看起来不整齐,为了好看,可以指定"X2",这样显示出来就是:0x0A、0x1A。
return sBuilder.ToString();
}
/// <summary>
/// 任意类型之间的转换
/// 来源:http://www.cnblogs.com/artech/archive/2011/03/17/NullableType.html
/// 用法:
/// Utils.ConvertTo<short?>(Request.Params["LockFlag"])
/// Request.Params["LockFlag"].ConvertTo<short?>()
/// int intValue1 = "123".ConvertTo<int>();
/// int? intValue2 = "123".ConvertTo<int?>();
/// DateTime dateTimeValue1 = "1981-08-24".ConvertTo<DateTime>();
/// DateTime? dateTimeValue2 = "1981-08-24".ConvertTo<DateTime?>();
/// </summary>
public static T ConvertTo<T>(this IConvertible convertibleValue)
{
if (null == convertibleValue)
{
return default(T);
}
if (!typeof(T).IsGenericType)
{
return (T)Convert.ChangeType(convertibleValue, typeof(T));
}
else
{
Type genericTypeDefinition = typeof(T).GetGenericTypeDefinition();
if (genericTypeDefinition == typeof(Nullable<>))
{
return (T)Convert.ChangeType(convertibleValue, Nullable.GetUnderlyingType(typeof(T)));
}
}
throw new InvalidCastException(string.Format("Invalid cast from type \"{0}\" to type \"{1}\".", convertibleValue.GetType().FullName, typeof(T).FullName));
}
}
}
public dynamic PageQuery() {
int pageIndex = Request.Params["page"] == null ? 1 : int.Parse(Request.Params["page"]);//Request["page"] 需要显示第几页 EasyUI datagrid自传
int pageSize = Request.Params["rows"] == null ? 10 : int.Parse(Request.Params["rows"]);//每页大小 EasyUI datagrid自传
try {
BackUserInfoPageCondition condition = new BackUserInfoPageCondition
{
pageIndex=pageIndex,
pageSize=pageSize,
UserCode = Request.Params["search_UserCode"],
UserName = Request.Params["search_UserName"],
IDNO = Request.Params["search_IDNO"],
Phone = Request.Params["search_Phone"],
DepartId = Request.Params["search_Depart"].Trim().ConvertTo<int>(),//默认-1请选择
DutyId = Request.Params["search_Duty"].Trim().ConvertTo<int>() ,
StatusFlag = Request.Params["search_StatusFlag"].Trim().ConvertTo<short?>(),
DimissionFlag = Request.Params["search_DimissionFlag"].Trim().ConvertTo<short?>(),
DisableFlag = Request.Params["search_DisableFlag"].Trim().ConvertTo<short?>(),
LockFlag = Request.Params["search_LockFlag"].Trim().ConvertTo<short?>()
};
var data = _IBackUserInfoService.PageQuery(condition);//根据条件query查询
var o = new { total = condition.total, rows = data };//EasyUI datagrid需要
return Json(o);
}
catch (Exception e)
{
//写日志
return Content("ERROR");
}
}
using System;using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
namespace Common
{
public static class Utils
{
/// <summary>
/// MD5加密
/// https://social.msdn.microsoft.com/Forums/zh-CN/590bd6a8-57d7-4041-81da-80fe8b832b77/md5 /// http://blog.163.com/m13864039250_1/blog/static/21386524820150231533602/ /// </summary>
public static string GetMD5Hash(string input){
//MD5 md5Hash = MD5.Create();
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
byte[] data=md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));//字符串格式控制符 x 为十六进制 2每次两位数
}//0xA、0x1A,这样看起来不整齐,为了好看,可以指定"X2",这样显示出来就是:0x0A、0x1A。
return sBuilder.ToString();
}
/// <summary>
/// 任意类型之间的转换
/// 来源:http://www.cnblogs.com/artech/archive/2011/03/17/NullableType.html
/// 用法:
/// Utils.ConvertTo<short?>(Request.Params["LockFlag"])
/// Request.Params["LockFlag"].ConvertTo<short?>()
/// int intValue1 = "123".ConvertTo<int>();
/// int? intValue2 = "123".ConvertTo<int?>();
/// DateTime dateTimeValue1 = "1981-08-24".ConvertTo<DateTime>();
/// DateTime? dateTimeValue2 = "1981-08-24".ConvertTo<DateTime?>();
/// </summary>
public static T ConvertTo<T>(this IConvertible convertibleValue)
{
if (null == convertibleValue)
{
return default(T);
}
if (!typeof(T).IsGenericType)
{
return (T)Convert.ChangeType(convertibleValue, typeof(T));
}
else
{
Type genericTypeDefinition = typeof(T).GetGenericTypeDefinition();
if (genericTypeDefinition == typeof(Nullable<>))
{
return (T)Convert.ChangeType(convertibleValue, Nullable.GetUnderlyingType(typeof(T)));
}
}
throw new InvalidCastException(string.Format("Invalid cast from type \"{0}\" to type \"{1}\".", convertibleValue.GetType().FullName, typeof(T).FullName));
}
}
}
相关文章推荐
- 主攻ASP.NET.4.5.1 MVC5.0之重生:创建UIHelper通用自定义分页和选择开关与PagesHelper和IsSelect简单用法
- ASP.NET MVC Bundles 用法和说明(打包javascript和css)
- ASP.NET MVC DropDownList 用法
- Html.DropDownList()的用法 ( Asp.Net MVC)
- Asp.net Mvc Dwz 分页
- ASP.NET MVC分页实现
- Asp.net Mvc分页方法介绍
- ASP.NET MVC 中出现的 方法 中的 this 关键字 用法 (this HtmlHelper helper)
- ASP.NET MVC Html.BeginForm用法1
- Asp.net MVC中Html.Partial, RenderPartial, Action,RenderAction 区别和用法
- Asp.Net MVC中DropDownListFor的用法(转)
- ASP.NET MVC分页的实现
- ASP.NET MVC分页、ASP.NET MVC Ajax分页组件1.0发布!
- ASP.NET MVC URL分页控件
- ASP.NET MVC HtmlHelper用法大全
- ASP.NET MVC中Area的另一种用法
- Asp.net MVC中Html.Partial, RenderPartial, Action,RenderAction 区别和用法
- ASP.NET MVC实现(查询+分页)
- ASP.NET MVC分页控件MvcPager 1.5版发布
- ASP.NET MVC HtmlHelper用法大全