| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Reflection;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Utils;
- namespace SiteCore
- {
- public class BasePage:Page
- {
- public bool _checkRight = true;
- public bool _isLoadJs = true;
- public bool _addVisible = false;
- public int _selfAddVisible = 0;
- public bool _refreshVisible = true;
- public bool _selfCheckPermission = false;
- public bool _keyFilterVisible = false;
- public DateTime _filterDate;
- public string _searchFilter = "";
- public string _searchDate = "";
- public string gcTag = "";
- public SearchDateEnum _searchDateEnum = SearchDateEnum.Default;
- public List<string> _permissions = new List<string>();//权限
- public string PmTag = "";
- public string tag = "";
- public static string SiteVer = webConfig.SiteVer;
- public bool _isCheckLogin = true;
- private WebUser _currentUser;
- public static readonly string TmpFilePath = ConfigurationManager.AppSettings["TempPath"];
- public static readonly string AttachPath = ConfigurationManager.AppSettings["AttachPath"];
-
- //获取用户数据
- public WebUser CurrentUser
- {
- get
- {
- if (_currentUser == null)
- {
- _currentUser = WebUser.GetUser();
- }
- return _currentUser;
-
- }
- }
- public int UserID
- {
- get
- {
- if (Session["xyUserID"] == null) return 0;
- return Convert.ToInt32(Session["xyUserID"]);
- }
- }
- public StringBuilder _script = new StringBuilder();
- public void AppendScript(String str)
- {
- _script.Append(str);
- }
- /// <summary>
- /// 检测是否登录
- /// </summary>
- public bool CheckRights()
- {
- if (Session["xyUserID"] == null)
- {
- Session["xyUserID"] = "1";
- Session["xyUserName"] = "ljq";
- }
- if (!_isCheckLogin) return true;
- string sPath = CommonHelper.GetPrePath();
- if (Session["xyUserID"] == null)
- {
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "/Login.aspx" + "';</script>");
- Response.End();
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检测是否登录
- /// </summary>
- public bool CheckRightsWithBack()
- {
- if (!_isCheckLogin) return true;
- string sPath = CommonHelper.GetPrePath();
- string curUrl = HttpContext.Current.Request.RawUrl;
- if (CurrentUser == null)
- {
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "login.html?pv=" + curUrl + "';</script>");
- Response.End();
- return false;
- }
- return true;
- }
- /// <summary>
- /// 检测是否登录
- /// </summary>
- public bool CheckMobileRights()
- {
- if (!_isCheckLogin) return true;
- string sPath = CommonHelper.GetPrePath();
- string curUrl = HttpContext.Current.Request.Url.AbsolutePath;
- if (CurrentUser == null)
- {
- Response.Write("<script type=\"text/javascript\">window.top.location='m/" + sPath + "login.html?lt=" + GetString("lt") + "';</script>");
- Response.End();
- return false;
- }
- return true;
- }
- public void conSuccess(string msg)
- {
- Response.Write("{\"res\":1,\"msg\":\"" + msg + "\"}");
- }
- public void conSuccess(string msg, string ext)
- {
- Response.Write("{\"res\":1,\"ext\":[" + ext + "],\"msg\":\"" + msg + "\"}");
- }
- public void conError(string msg)
- {
- Response.Write("{\"res\":0,\"msg\":\"" + msg + "\"}");
- }
- public void conGridJson(object total, string json)
- {
- Response.Write("{" + string.Format("\"res\":1,\"total\":{0},\"data\":{1}", total, json) + "}");
- }
- public string GetImgUrl(object img)
- {
- return CommonHelper.GetPrePath() + "d/" + img;
- }
- public DataStruct GetStruct(int pi,int ps)
- {
- DataStruct dStruct = new DataStruct();
- dStruct.CurrentPage = pi + 1;
- dStruct.PageSize = (ps == 0 ? 20 : ps);
- return dStruct;
- }
- /// <summary>
- /// 查询时次要过滤条件
- /// </summary>
- public string SecondWhere
- {
- get
- {
- if (ViewState["secondWhere"] == null)
- return "";
- else
- return ViewState["secondWhere"].ToString();
- }
- set
- {
- ViewState["secondWhere"] = value;
- }
- }
- public void SelItemSelected(DropDownList ddl,object value)
- {
- ddl.ClearSelection();
- ListItem item=ddl.Items.FindByValue(value.ToString());
- if(item!=null)item.Selected=true;
- }
- public void SelRadioItemSelected(RadioButtonList rbl, object value)
- {
- rbl.ClearSelection();
- ListItem item = rbl.Items.FindByValue(value.ToString());
- if (item != null) item.Selected = true;
- }
-
- //显示错误页面
- public void ShowErrorPage()
- {
- Response.Redirect(CommonHelper.GetPrePath() + "ErrorPage.htm", true);
- }
- public void ShowErrorHtml(string url)
- {
- Response.Write("你访问的页面错误啦!<a href='" + url + "'>点击这里返回</a>");
- Response.End();
- }
- public void ShowErrorHtml(string txt,string url)
- {
- Response.Write(txt+"!<a href='" + url + "'>点击这里返回</a>");
- Response.End();
- }
- public void ShowError(string txt)
- {
- Response.Clear();
- Response.Write(txt);
- Response.End();
- }
- public object GetReflectionObject(string className)
- {
- if (string.IsNullOrEmpty(className)) return null;
- string tmpName = "BizCom." + className;
- return Assembly.Load("BizCom").CreateInstance(tmpName);
- }
- #region 格式化显示方式
- /// <summary>
- /// 返回是否过期
- /// </summary>
- /// <param name="endTime"></param>
- /// <returns></returns>
- public static bool CheckIsExpire(object endTime)
- {
- return DateTime.Now.Subtract(Convert.ToDateTime(endTime)).Days > 0;
- }
- /// <summary>
- /// 布尔值显示文字
- /// </summary>
- /// <param name="result"></param>
- /// <param name="tStr"></param>
- /// <param name="fStr"></param>
- /// <returns></returns>
- public string GetBoolenString(object result, string tStr, string fStr)
- {
- if (result.Equals(DBNull.Value)) return "";
- return Convert.ToBoolean(result) ? tStr : fStr;
- }
- /// <summary>
- /// 图片显示
- /// </summary>
- /// <param name="imgUrl"></param>
- /// <returns></returns>
- public string GetImgString(object imgUrl)
- {
- return GetImgString(imgUrl, "");
- }
- public string GetImgString(object imgUrl, string noPic)
- {
- string str = "<img alt='' class=\"g_img\" align=\"absmiddle\" src=\"{0}\" />";
- string img = noPic == "" ? "images/noImg.gif" : "images/" + noPic;
- if (imgUrl.ToString() != "") img = imgUrl.ToString().Replace("images/", "images/i2/");
- return string.Format(str, "../../" + img);
- }
- public string GetCouponImageString(object imgUrl,object type)
- {
- string str = "<img alt='' class=\"g_img\" align=\"absmiddle\" src=\"{0}\" />";
- string img = "images/nocImg.gif";
- if (type.ToString() == "1") img = "images/noeImg.gif";
- if (imgUrl.ToString() != "") img = "Documents/" + imgUrl;
- return string.Format(str, "../../" + img);
- }
- public string GetMerchantImgString(object imgUrl, string noPic)
- {
- string str = "<img alt='' class=\"g_img\" align=\"absmiddle\" src=\"{0}\" />";
- string img = noPic == "" ? "images/noImg.gif" : "images/" + noPic;
- if (imgUrl.ToString() != "") img = "Documents/" + imgUrl;
- return string.Format(str, "../../" + img);
- }
- public string GetSiteImgString(object imgUrl, object title)
- {
- string str = "<img alt=\"{1}\" title\"{1}\" class=\"g_img\" align=\"absmiddle\" src=\"{0}\" />";
- string img = "";
- if (imgUrl.ToString() != "") img = "Documents/" + imgUrl;
- return string.Format(str, "../../" + img,CommonHelper.FormatForXML(title));
- }
- public string GetCurrentImgString(object imgUrl, string noPic)
- {
- string img = noPic == "" ? "images/noImg.gif" : "images/" + noPic;
- if (imgUrl.ToString() != "") img = "Documents/" + imgUrl;
- return img;
- }
- /// <summary>
- /// 格式化日期
- /// </summary>
- /// <param name="date"></param>
- /// <returns></returns>
- public string GetFormatDate(object date)
- {
- return GetFormatDate(date, "无");
- }
- public string GetFormatDate(object date, string def)
- {
- if (date == null) return def;
- return date.ToString() == "" ? def : Convert.ToDateTime(date).ToString("yyyy-MM-dd");
- }
- /// <summary>
- /// 过期日期
- /// </summary>
- /// <param name="sDate"></param>
- /// <param name="eDate"></param>
- /// <returns></returns>
- public string GetFormatExpireDate(object sDate, object eDate)
- {
- return GetFormatExpireDate(sDate, eDate, "无");
- }
- public string GetFormatExpireDate(object sDate, object eDate, string defaultTxt)
- {
- if (sDate.ToString() == "" && eDate.ToString() == "")
- {
- return defaultTxt;
- }
- return "<span style=\"color:green\">" + GetFormatDate(sDate) + "<span> 至 <span style=\"color:blue\">" + GetFormatDate(eDate) + "</span>";
- }
- public string GetFormatapkDate(object sDate, object eDate, string defaultTxt)
- {
- if (sDate.ToString() == "" && eDate.ToString() == "")
- {
- return defaultTxt;
- }
- return "" + GetFormatDate(sDate) + "至" + GetFormatDate(eDate) + "";
- }
- /// <summary>
- /// 格式日期带时间
- /// </summary>
- /// <param name="date"></param>
- /// <returns></returns>
- public string GetFormatDateTime(object date)
- {
- if (date==null || date.Equals(DBNull.Value)) return "";
- return date.ToString() == "" ? "" : Convert.ToDateTime(date).ToString("yyyy-MM-dd HH:mm");
- }
- public string GetCurrentDateTime(object date)
- {
- if (date.Equals(DBNull.Value) || date.ToString() == "") return "";
- DateTime dt1 = DateTime.Now;
- DateTime dt2 = Convert.ToDateTime(date);
- TimeSpan span = dt1.Subtract(dt2);
- if (span.TotalDays > 5)
- {
- return dt2.ToString("yyyy-MM-dd HH:mm");
- }/*
- else if (span.TotalDays > 30)
- {
- return "1个月前";
- }
- else if (span.TotalDays > 14)
- {
- return "2周前";
- }
- else if (span.TotalDays > 7)
- {
- return "1周前";
- }*/
- else if (span.TotalDays > 1)
- {
- return string.Format("{0}天前", (int)Math.Floor(span.TotalDays));
- }
- else if (span.TotalHours > 1)
- {
- return string.Format("{0}小时前", (int)Math.Floor(span.TotalHours));
- }
- else if (span.TotalMinutes > 1)
- {
- return string.Format("{0}分钟前", (int)Math.Floor(span.TotalMinutes));
- }
- else if (span.TotalSeconds >= 1)
- {
- return string.Format("{0}秒前", (int)Math.Floor(span.TotalSeconds));
- }
- else
- {
- return "刚刚";
- }
- }
- /// <summary>
- /// 格式化时间
- /// </summary>
- /// <param name="sTime"></param>
- /// <param name="eTime"></param>
- /// <returns></returns>
- public string GetFormatTime(object sTime, object eTime)
- {
- string tmp = sTime.ToString();
- string firstTime = "", endTime = "";
- if (tmp == "" || tmp == "-1") return "全天";
- if (tmp == "0") firstTime = "00:00";
- else if (tmp == "30") firstTime = "00:30";
- else firstTime = tmp.Substring(0, tmp.Length - 2).PadLeft(2, '0') + ":" + tmp.Substring(tmp.Length - 2);
- tmp = eTime.ToString();
- if (tmp == "0") endTime = "00:00";
- else if (tmp == "30") endTime = "00:30";
- else endTime = tmp.Substring(0, tmp.Length - 2).PadLeft(2, '0') + ":" + tmp.Substring(tmp.Length - 2);
- return firstTime + " ~ " + endTime;
- }
- /// <summary>
- /// 获取精度数据
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public string GetDoubleString(object value)
- {
- if (string.IsNullOrEmpty(value.ToString())) return "";
- string db= Convert.ToDouble(value).ToString("F2");
- return db.Replace(".00", "");
- }
- public string GetDoubleString(object value,int num)
- {
- if (string.IsNullOrEmpty(value.ToString())) return "";
- return Convert.ToDouble(value).ToString("N"+num);
- }
- public string GetDoubleString(object value, string txt)
- {
- if (Convert.ToDouble(value) < 1) return txt;
- else return GetDoubleString(value);
- }
- //获取还剩几天
- public string GetDayByDate(object date)
- {
- DateTime curDt = DateTime.Now;
- if (date.ToString() == "") return "己过期";
- DateTime exDt = Convert.ToDateTime(date);
- TimeSpan tdays = exDt - curDt;
- if (tdays.Days < 0) return "己过期";
- else if (tdays.Days == 0) return "今天";
- return tdays.Days + "天";
- }
- /// <summary>
- /// 获取带有空值的字符串
- /// </summary>
- /// <param name="result">data</param>
- /// <param name="nullStr">为空时显示的内容</param>
- /// <returns></returns>
- public string GetWithEmptyString(object result, string nullStr)
- {
- if (result == null) return nullStr;
- return result.ToString().Length > 0 ? result.ToString() : nullStr;
- }
- /// <summary>
- /// 获取两个数字相差的数量
- /// </summary>
- /// <param name="aNum"></param>
- /// <param name="num"></param>
- /// <returns></returns>
- public object GetMinuteNum(object aNum, object num)
- {
- if (aNum.ToString() == "" || num.ToString() == "") return 0;
- return Convert.ToInt32(aNum) - Convert.ToInt32(num);
- }
- public object GetMinusMinuteNum(object aNum, object num)
- {
- if (aNum.ToString() == "" || num.ToString() == "") return 0;
- int tmp=Convert.ToInt32(aNum) - Convert.ToInt32(num);
- if(tmp<0)return 0;
- return tmp;
- }
- public double GetDoubleMinuteNum(object aNum,object num)
- {
- return Convert.ToDouble(aNum) - Convert.ToDouble(num);
- }
- public string GetDoubleMinuteString(object aNum, object num)
- {
- return GetDoubleString(Convert.ToDouble(aNum) - Convert.ToDouble(num));
- }
-
- #endregion
- #region 页面方法
- //设置过期
- public void SetPageExpires()
- {
- Response.Buffer = true;
- Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
- Response.Expires = 0;
- Response.AddHeader("pragma","no-cache");
- Response.AddHeader("cache-control", "private");
- Response.CacheControl = "no-cache";
- }
- #endregion
- #region URL参数
- /// <summary>
- /// 获取当前Url带完整参数
- /// </summary>
- /// <param name="url"></param>
- /// <param name="parm"></param>
- /// <param name="nshow">不加的参数</param>
- /// <returns></returns>
- public string GetCurrentUrl(string url, string parm, string nshow)
- {
- string query = HttpContext.Current.Request.Url.Query;
- StringBuilder qStr = new StringBuilder();
- qStr.Append(url + "?");
- if (query != "")
- {
- query = query.Substring(1);
- string key = parm.Split('=')[0];
- string[] qArr = query.Split('&');
- for (int i = 0; i < qArr.Length; i++)
- {
- if (qArr[i].Split('=')[0] != key && qArr[i].Split('=')[0] != nshow)
- qStr.Append(qArr[i] + "&");
- }
- }
- qStr.Append(parm);
- return qStr.ToString();
- }
- public string GetCurrentUrl(string parm, string nshow)
- {
- return GetCurrentUrl("", parm, nshow);
- }
- /// <summary>
- /// 获取当前Url带完整参数
- /// </summary>
- /// <param name="parm"></param>
- /// <returns></returns>
- public string GetCurrentUrl(string parm)
- {
- return GetCurrentUrl("", parm, "");
- }
- /// <summary>
- /// 检测URL参数是否存在
- /// </summary>
- /// <param name="parms"></param>
- /// <returns></returns>
- public bool UrlParmsCheck(string parms)
- {
- return CommonHelper.UrlParmsCheck(parms);
- }
- public static bool UrlPostParmsCheck(string parms)
- {
- return CommonHelper.UrlPostParmsCheck(parms);
- }
- public int GetInt(string param)
- {
- return CommonHelper.GetInt(param);
- }
- public int GetPostInt(string param)
- {
- return CommonHelper.GetPostInt(param);
- }
- public double GetDouble(string param)
- {
- string v = GetString(param);
- if (v == "") return 0;
- return Convert.ToDouble(v);
- }
- public double GetPostDouble(string param)
- {
- string v = GetPostString(param);
- if (v == "") return 0;
- return Convert.ToDouble(v);
- }
- public string GetString(string param)
- {
- return CommonHelper.GetString(param);
- }
- public string GetPostString(string param)
- {
- return CommonHelper.GetPostString(param);
- }
- public int GetDecodeInt(string param)
- {
- return GetDecodeInt(param, false);
- }
- public int GetDecodeInt(string param, bool isPost)
- {
- string value = null;
- if (isPost) value = GetPostString(param);
- else value = GetString(param);
- if (value.Length < 1) return 0;
- return CommonHelper.DecodeInt(value);
- }
- public string GetDecodeString(string param)
- {
- return GetDecodeString(param, false);
- }
- public string GetDecodeString(string param, bool isPost)
- {
- string value = null;
- if (isPost) value = GetPostString(param);
- else value = GetString(param);
- if (value.Length < 1) return "";
- return CommonHelper.DecodeString(value);
- }
- public string GetDeepString(params string[] parms)
- {
- return CommonHelper.GetDeepString(parms);
- }
- public string GetDeepIds(params string[] parms)
- {
- return CommonHelper.GetDeepIds(parms);
- }
- public string GetHttpDecodeString(string parm)
- {
- return HttpUtility.UrlDecode(GetString(parm));
- }
- public string GetHttpDecodeString(string parm, Encoding coding)
- {
- return HttpUtility.UrlDecode(GetString(parm),coding);
- }
- public int GetDeepIndex(params string[] parms)
- {
- return CommonHelper.GetDeepIndex(parms);
- }
- #endregion
- #region 显示Ajax消息
- /// <summary>
- /// 显示消息
- /// </summary>
- /// <param name="msg">信息内容</param>
- public void ShowAjaxMsg(string msg)
- {
- ShowAjaxMsg("提示", msg);
- }
- /// <summary>
- /// 显示消息
- /// </summary>
- /// <param name="title">提示</param>
- /// <param name="msg">信息内容</param>
- public void ShowAjaxMsg(string title, string msg)
- {
- ScriptManager.RegisterStartupScript(Page, GetType(), title, "<script>alert('" + msg + "');</script>", false);
- }
- /// <summary>
- /// 显示消息带JS函数
- /// </summary>
- /// <param name="func">方法名称</param>
- public void ShowAjaxHasFunc(string func)
- {
- ShowAjaxHasFunc("提示", func);
- }
- /// <summary>
- /// 显示消息带JS函数
- /// </summary>
- /// <param name="title">提示</param>
- /// <param name="func">方法名称</param>
- public void ShowAjaxHasFunc(string title, string func)
- {
- ScriptManager.RegisterStartupScript(Page, GetType(), title, "<script>" + func + "</script>", false);
- }
- #endregion
- #region 运行JS脚本显示
- public void ShowScript(string script)
- {
- Page.ClientScript.RegisterStartupScript(GetType(), "alt", "<script>" + script + "</script>");
- }
- /// <summary>
- /// 显示消息
- /// </summary>
- /// <param name="msg">信息内容</param>
- public void ShowMsg(string msg)
- {
- ShowMsg("提示", msg);
- }
- /// <summary>
- /// 显示消息
- /// </summary>
- /// <param name="title">提示</param>
- /// <param name="msg">信息内容</param>
- public void ShowMsg(string title, string msg)
- {
- ShowMsg(title, msg, "");
- }
- /// <summary>
- /// 显示消息
- /// </summary>
- /// <param name="title">提示</param>
- /// <param name="msg">信息内容</param>
- /// <param name="msg">方法</param>
- public void ShowMsg(string title, string msg, string func)
- {
- Page.ClientScript.RegisterStartupScript(GetType(), title, "<script>alert('" + msg + "');" + func + "</script>");
- }
- /// <summary>
- /// 弹出显示结果
- /// </summary>
- /// <param name="msg"></param>
- public void ShowResult(string msg)
- {
- ShowResult(msg, "");
- }
- /// <summary>
- /// 弹出显示结果
- /// </summary>
- /// <param name="msg"></param>
- /// <param name="func"></param>
- public void ShowResult(string msg, string func)
- {
- func = func.Replace("'", "\"");
- Page.ClientScript.RegisterStartupScript(GetType(), "result", "<script>$(document).ready( function(){ resultShow('" + msg + "','" + func + "');});</script>");
- }
- #endregion
-
- }
- public enum SearchDateEnum
- {
- Empty = 9,
- Default = 0,
- OneDay = 1,
- OneMonth = 2,
- OneYear = 3
- }
- }
|