152 lines
4.9 KiB
C#
152 lines
4.9 KiB
C#
using System.Collections;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web;
|
|
using WX.CRM.Common;
|
|
|
|
namespace WX.CRM.WebHelper
|
|
{
|
|
public class PageRequest
|
|
{
|
|
|
|
public static Pager GetGirdPager()
|
|
{
|
|
Pager pager = new Pager()
|
|
{
|
|
rows = PageRequest.GetQueryInt("rows"),
|
|
order = PageRequest.GetQueryString("order"),
|
|
page = PageRequest.GetQueryInt("page"),
|
|
sort = PageRequest.GetQueryString("sort"),
|
|
totalRows = PageRequest.GetQueryInt("totalRows")
|
|
};
|
|
|
|
return pager;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 从地址栏获取值
|
|
/// </summary>
|
|
/// <param name="page">页面</param>
|
|
/// <param name="para">参数</param>
|
|
/// <returns></returns>
|
|
public static string GetQueryString(string para)
|
|
{
|
|
string queryString = "";
|
|
if (System.Web.HttpContext.Current.Request.QueryString[para] != null)
|
|
{
|
|
queryString = System.Web.HttpContext.Current.Request.QueryString[para].ToString();
|
|
}
|
|
else
|
|
{
|
|
queryString = "";
|
|
}
|
|
return queryString.Trim();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从地址栏获取相关int值
|
|
/// </summary>
|
|
/// <param name="page">页面</param>
|
|
/// <param name="para">参数</param>
|
|
/// <returns></returns>
|
|
public static int GetQueryInt(string para)
|
|
{
|
|
int queryInt = 0;
|
|
string tempQueryString = GetQueryString(para);
|
|
if (ValidateHelper.IsNumber(tempQueryString))
|
|
{
|
|
queryInt = int.Parse(tempQueryString);
|
|
}
|
|
return queryInt;
|
|
}
|
|
public static long GetQueryLong(string para)
|
|
{
|
|
long queryInt = 0;
|
|
string tempQueryString = GetQueryString(para);
|
|
if (ValidateHelper.IsNumber(tempQueryString))
|
|
{
|
|
queryInt = long.Parse(tempQueryString);
|
|
}
|
|
return queryInt;
|
|
}
|
|
/// <summary>
|
|
/// 不同浏览器返回不同文件下载名称
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetDlownLoadName(string name)
|
|
{
|
|
string browser = System.Web.HttpContext.Current.Request.Browser.Browser;
|
|
if (browser.ToUpper().IndexOf("IE") > -1 || browser.IndexOf("InternetExplorer") > -1)
|
|
return HttpUtility.UrlEncode(name);
|
|
return name;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从参数中获取相关参数数组
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
public static Hashtable GetQueryPara()
|
|
{
|
|
int paraCount = System.Web.HttpContext.Current.Request.QueryString.Count;
|
|
string queryKey = "";
|
|
string queryValue = "";
|
|
Hashtable para = new Hashtable();
|
|
Regex regex = new Regex("^[a-zA-z]+[_][a-zA-z]{3}[_][a-zA-z][_][a-zA-Z0-9]+$");
|
|
for (int i = 0; i < paraCount; i++)
|
|
{
|
|
queryKey = System.Web.HttpContext.Current.Request.QueryString.Keys[i].ToString();
|
|
queryValue = System.Web.HttpContext.Current.Request.QueryString[i].ToString();
|
|
if (regex.IsMatch(queryKey) && !queryValue.Equals(""))
|
|
{
|
|
para.Add(queryKey, queryValue);
|
|
}
|
|
}
|
|
return para;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 从表单中获取相关参数数组
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
public static Hashtable GetFormPara()
|
|
{
|
|
int paraCount = System.Web.HttpContext.Current.Request.Form.Count;
|
|
string formKey = "";
|
|
string formValue = "";
|
|
Hashtable para = new Hashtable();
|
|
Regex regex = new Regex("^[a-zA-z]+[_][a-zA-z]{3}[_][a-zA-z][_][a-zA-Z0-9]+$");
|
|
for (int i = 0; i < paraCount; i++)
|
|
{
|
|
formKey = System.Web.HttpContext.Current.Request.Form.Keys[i].ToString();
|
|
formValue = System.Web.HttpContext.Current.Request.Form[i].ToString();
|
|
|
|
if (regex.IsMatch(formKey) && !formValue.Equals(""))
|
|
{
|
|
para.Add(formKey, formValue);
|
|
}
|
|
}
|
|
|
|
return para;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取参数数组
|
|
/// </summary>
|
|
/// <param name="page"></param>
|
|
/// <returns></returns>
|
|
public static Hashtable GetPara()
|
|
{
|
|
if (System.Web.HttpContext.Current.Request.RequestType.ToLower().Equals("get"))
|
|
{
|
|
return GetQueryPara();
|
|
}
|
|
else
|
|
{
|
|
return GetFormPara();
|
|
}
|
|
}
|
|
}
|
|
}
|