| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008 |
- using SiteCore.Redis;
- using System;
- using System.Collections.Generic;
- 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 string _t = "";
- public bool _checkRight = true;
- public int _pageSize = 30;
- public bool _addVisible = false;
- public int _selfAddVisible = 0;
- public bool _refreshVisible = true;
- public bool _choiceVisible = false;
- public bool _selfCheckPermission = false;
- public DateTime _filterDate;
- public string _searchFilter = "";
- public string _searchDate = "";
- public string _filterItem = "";
- public bool _filterDateBtn = true; //本日本周本月的按钮显示
- public string _b_sDate = "";
- public string _b_eDate = "";
- public bool _b_HavingTime = false;
- public bool _hasExport = false;
- public string gcTag = "";
- public string _repTitle = "";
- public SearchDateEnum _searchDateEnum = SearchDateEnum.Empty;
- public bool _noneDefaultTime = false;
- public bool onlyEndTime = false;
- public bool _keyFilterVisible = false;
- public bool _isCheckLogin = true;
- public static readonly string _btnStr = "<a class=\"mini-button\" iconCls=\"icon-{0}\" plain=\"true\" href=\"javascript:{0}_0\" >{1}</a>";
- public List<string> _permissions = new List<string>();//权限
- //public string _action=string.Empty;
- public static readonly string SiteVer = webConfig.SiteVer;
- public static readonly string SiteName = webConfig.SiteName;
- public static readonly string SiteDomain = webConfig.SiteDomain;
- public static readonly string CookieName = webConfig.CookieName;
- public static readonly string SiteUrl = webConfig.SiteUrl;
- public string dis_stime = "00:00:00";///webConfig.DisStartTime;
- public string dis_etime = "23:59:59";// webConfig.DisEndTime;
- #region 账户相关
- public string Round(double d, int n = 2)
- {
- return d.ToString("F" + n);
- }
- public string Round(decimal d, int n = 2)
- {
- return d.ToString("F" + n);
- }
- public decimal RoundDecimal(decimal d, int n = 2)
- {
- return Convert.ToDecimal(Round(d, n));
- }
- public double RoundDouble(double d, int n = 2)
- {
- return Convert.ToDouble(Round(d, n));
- }
- private WebUser _currentUser = null;
- //获取用户数据
- public WebUser CurrentUser
- {
- get
- {
- if (_currentUser == null)
- {
- _currentUser = WebUser.GetUser();
- }
- return _currentUser;
- }
- }
- public int UserID
- {
- get
- {
- if (CurrentUser == null) return 0;
- return Convert.ToInt32(CurrentUser.UserID);
- }
- }
- public string PKey
- {
- get
- {
- if (CurrentUser == null) return "";
- if (CurrentUser.User.State == 5) return "admin";
- return CurrentUser.UserPost.PostID.ToString();
- }
- }
- protected override void OnPreLoad(EventArgs e)
- {
- if (isLoginOut())
- {
- string sPath = CommonHelper.GetPrePath();
- Response.Write("<script type=\"text/javascript\">alert('会话超时过期,请重新登录。');window.top.location='" + sPath + "Login.aspx" + "';</script>");
- Response.End();
- return;
- }
- //_t = Session["_t"].ToString();
- base.OnPreLoad(e);
- }
- public bool isLoginOut()
- {
- //人员是否已登录
- //if (Session["userId"] == null || Session["userId"].ToString() == "")
- // return true;
- //传过来的Ticket是否有效
- HttpCookie lcCookie = HttpContext.Current.Request.Cookies[webConfig.CookieName];
- if (lcCookie == null)
- {
- return true;
- }
- string name = lcCookie.Values["User"];
- string ticket = lcCookie.Values["Ticket"];
- if (name == null || ticket == null || name == "" || ticket == "")
- {
- return true;
- }
- name = HttpUtility.UrlDecode(name);
- string dl_ticket = erpRedis.RedisHelper.StringGet("dl_" + name);
- //if (String.IsNullOrEmpty(dl_ticket))
- //{
- // erpRedis.RedisHelper.StringSet("dl_" + name, ticket);
- // return false;
- //}
- if (ticket != dl_ticket)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 检测是否登录
- /// </summary>
- public bool CheckRights()
- {
- //if (Session["xyUserID"] == null)
- //{
- // Session["xyUserID"] = "1";
- // Session["xyUserName"] = "ljq";
- //}
- if (!_isCheckLogin) return true;
- if (CurrentUser == null)
- {
- string sPath = CommonHelper.GetPrePath();
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "Login.aspx" + "';</script>");
- Response.End();
- return false;
- }
- return true;
- }
- public bool CheckRightSession()
- {
- if (Session["cur_user"] == null)
- {
- string sPath = CommonHelper.GetPrePath();
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "Login.aspx" + "';</script>");
- Response.End();
- return false;
- }
- return true;
- }
- //权限标签
- public string PmTag = "";
- public string GetPersonName(object pName)
- {
- if (pName.ToString() == "") return "";
- return pName.ToString();
- }
- public StringBuilder _script = new StringBuilder();
- public void AppendScript(String str)
- {
- _script.Append(str);
- }
- public object GetReflectionObject(string className)
- {
- if (string.IsNullOrEmpty(className)) return null;
- string tmpName = "BizCom." + className;
- return Assembly.Load("BizCom").CreateInstance(tmpName);
- }
- #endregion
- //显示错误页面
- 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.Write(txt);
- Response.End();
- }
- public int GetDecodeInt(string param)
- {
- string value = GetString(param);
- if (value.Length < 1) return 0;
- return CommonHelper.DecodeInt(value);
- }
- public string GetDecodeString(string param)
- {
- string value = GetString(param);
- if (value.Length < 1) return "";
- return CommonHelper.DecodeString(value);
- }
- public void SelItemSelected(DropDownList ddl, object value)
- {
- ddl.ClearSelection();
- System.Web.UI.WebControls.ListItem item = ddl.Items.FindByValue(value.ToString());
- if (item != null) item.Selected = true;
- }
- public void SelRadioItemSelected(RadioButtonList rbl, object value)
- {
- rbl.ClearSelection();
- System.Web.UI.WebControls.ListItem item = rbl.Items.FindByValue(value.ToString());
- if (item != null) item.Selected = true;
- }
- public string GDis_STime
- {
- get
- {
- string dm = DateTime.Now.ToString("yyyyMM");
- if (Convert.ToInt32(dm) >= 202009) return dis_stime;
- return "00:00:00";
- }
- }
- public string GDis_ETime
- {
- get
- {
- string dm = DateTime.Now.ToString("yyyyMM");
- if (Convert.ToInt32(dm) >= 202009) return dis_etime;
- return "23:59:59";
- }
- }
- public string getTodTime(DateTime sTime)
- {
- return getTodTime(sTime.ToString("yyyy-MM-dd"));
- }
- public string getTodTime(string stime)
- {
- DisTime dTime = redis.RedisHelper.HashGet<DisTime>("distime", stime);
- if (dTime != null && dTime.stime != "") return dTime.stime;
- return stime + " " + GDis_STime;
- //string st = redis.RedisHelper.StringGet("dis_" + stime);
- //if (string.IsNullOrEmpty(st)) return stime + " " + dis_stime;
- //return st;
- }
- public string getTormTime(DateTime eTime)
- {
- return getTormTime(eTime.ToString("yyyy-MM-dd"));
- }
- public string getTormTime(string etime)
- {
- DisTime dTime = redis.RedisHelper.HashGet<DisTime>("distime", etime);
- //string et = redis.RedisHelper.StringGet("die_" + etime);
- if (dTime == null || dTime.etime == "")
- {
- if (dis_etime.IndexOf("-") != -1)
- {
- string detime = dis_etime.Replace("-", "");
- DateTime _ctime = Convert.ToDateTime(etime);
- return _ctime.AddDays(1).ToString("yyyy-MM-dd") + " " + detime;
- }
- return etime + " " + GDis_ETime;
- }
- return dTime.etime;
- }
- public void getTTime(string stime, string etime, out string tstime, out string tetime)
- {
- DisTime sdTime = null;
- DisTime edTime = null;
- if (stime == etime)
- {
- sdTime = redis.RedisHelper.HashGet<DisTime>("distime", etime);
- edTime = sdTime;
- }
- else
- {
- sdTime = redis.RedisHelper.HashGet<DisTime>("distime", stime);
- edTime = redis.RedisHelper.HashGet<DisTime>("distime", etime);
- }
- if (sdTime == null)
- {
- tstime = stime + " " + GDis_STime;
- }
- else
- {
- if (sdTime.stime != "") tstime = sdTime.stime;
- else tstime = stime + " " + GDis_STime;
- }
- if (edTime == null)
- {
- if (dis_etime.IndexOf("-") != -1)
- {
- string detime = dis_etime.Replace("-", "");
- DateTime _ctime = Convert.ToDateTime(etime);
- tetime = _ctime.AddDays(1).ToString("yyyy-MM-dd") + " " + detime;
- }
- else
- {
- tetime = etime + " " + GDis_ETime;
- }
- }
- else
- {
- if (string.IsNullOrEmpty(edTime.etime))
- {
- if (dis_etime.IndexOf("-") != -1)
- {
- string detime = dis_etime.Replace("-", "");
- DateTime _ctime = Convert.ToDateTime(etime);
- tetime = _ctime.AddDays(1).ToString("yyyy-MM-dd") + " " + detime;
- }
- else
- {
- tetime = etime + " " + GDis_ETime;
- }
- }
- else tetime = edTime.etime;
- }
- }
- public string getDefDateWhere(string sdate, string edate)
- {
- string _stime = ""; //getTodTime(edate);
- string _etime = "";// getTormTime(edate);
- if (sdate == "" && edate != "")
- {
- getTTime(edate, edate, out _stime, out _etime);
- return "(datediff(d,'" + _stime + "',createtime)>=0 and datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0)";
- }
- if (sdate != "" && edate != "")
- {
- getTTime(sdate, edate, out _stime, out _etime);
- return "datediff(d,'" + _stime + "',createtime)>=0 and datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0)";
- }
- return "";
- }
- public string getDispatchDateWhere(string sdate, string edate)
- {
- string _stime = ""; //getTodTime(edate);
- string _etime = "";// getTormTime(edate);
- if (sdate == "" && edate != "")
- {
- getTTime(edate, edate, out _stime, out _etime);
- return "(datediff(d,'" + _stime + "',createtime)>=0 and datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0)";
- }
- if (sdate != "" && edate != "")
- {
- getTTime(sdate, edate, out _stime, out _etime);
- return "(datediff(d,'" + _stime + "',createtime)>=0 and datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0)";
- }
- return "";
- }
- public string getDispatchDateWhere(string field, string sdate, string edate)
- {
- string _stime = ""; //getTodTime(edate);
- string _etime = "";// getTormTime(edate);
- if (sdate == "" && edate != "")
- {
- getTTime(edate, edate, out _stime, out _etime);
- return "(datediff(d,'" + _stime + "'," + field + ")>=0 and datediff(s,'" + _stime + "'," + field + ")>=0 and datediff(s,'" + _etime + "'," + field + ")<=0)";
- }
- if (sdate != "" && edate != "")
- {
- getTTime(sdate, edate, out _stime, out _etime);
- return "(datediff(d,'" + _stime + "'," + field + ")>=0 and datediff(s,'" + _stime + "'," + field + ")>=0 and datediff(s,'" + _etime + "'," + field + ")<=0)";
- }
- return "";
- }
- public string getDispatchDateWhere(DateTime etime)
- {
- if (Convert.ToInt32(etime.ToString("HHmmss")) < 60000)
- {
- etime = etime.AddDays(-1);
- }
- string _stime = getTodTime(etime.ToString("yyyy-MM-dd"));
- string _etime = getTormTime(etime.ToString("yyyy-MM-dd"));
- return " datediff(d,'" + _stime + "',createtime)>=0 and datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0";
- }
- public string getDispatchDateNoTimeWhere(DateTime etime)
- {
- string _stime = getTodTime(etime);
- string _etime = getTormTime(etime);
- return " datediff(d,'" + _stime + "',createtime)>=0 and datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0";
- }
- public string getProductionTaskWhere(string stime, string etime)
- {
- return "productiontaskid in (select distinct productiontaskid from ce_erpdispatchtask where " + getSaleDispatchDateWhere(stime, etime) + " and ispatch=0 )";
- }
- public string getSaleDispatchDateWhere(string stime, string etime)
- {
- return getDispatchDateWhere(stime, etime);
- }
- //public string getSaleDispatchDateNoTimeWhere(DateTime etime)
- //{
- // string _stime = etime.ToString("yyyy-MM-dd") + " 00:00:00";
- // string _etime = etime.ToString("yyyy-MM-dd") + " 23:59:59";
- // return " datediff(s,'" + _stime + "',createtime)>=0 and datediff(s,'" + _etime + "',createtime)<=0";
- //}
- //private void setDisTimeRedis2(string sdate,string edate, out string _stime, out string _etime)
- //{
- // _stime = "";
- // _etime = "";
- // string dkey = Convert.ToDateTime(sdate).ToString("yyyy-MM-dd");
- // string dStr = redis.RedisHelper.StringGet("dis_" + dkey);
- // if (!String.IsNullOrEmpty(dStr))
- // {
- // string[] dArr = dStr.Split('|');
- // _stime = dArr[0];
- // }
- // else
- // {
- // _stime = getTodTime(sdate);
- // }
- // dkey = Convert.ToDateTime(edate).ToString("yyyy-MM-dd");
- // dStr = redis.RedisHelper.StringGet("dis_" + dkey);
- // if (!string.IsNullOrEmpty(dStr))
- // {
- // string[] dArr = dStr.Split('|');
- // _etime = dArr[1];
- // }
- // if (_etime == "") _etime = getTodTime(edate);
- //}
- //private void setDisTimeRedis(string date,out string _stime,out string _etime)
- //{
- // string dkey = Convert.ToDateTime(date).ToString("yyyy-MM-dd");
- // string dStr = redis.RedisHelper.StringGet("dis_" + dkey);
- // if (!String.IsNullOrEmpty(dStr))
- // {
- // string[] dArr = dStr.Split('|');
- // _stime = dArr[0];
- // _etime = dArr[1];
- // }
- // else
- // {
- // _stime = getTodTime(date);
- // _etime = getTormTime(date);
- // }
- //}
- #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 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, 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>";
- }
- /// <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;
- }
- public void SetDateWhere(string field, string start, string end, IList<string> where)
- {
- if (start != "" || end != "")
- {
- if (start != "" && end != "")
- where.Add(string.Format(" (DATEDIFF(d,'{0}',{2})>=0 and DATEDIFF(d,'{1}',{2})<=0 )", start, end, field));
- else if (start != "")
- where.Add(string.Format(" {1}>='{0}'", start, field));
- else
- where.Add(string.Format(" dateDiff(d,{1},'{0}')=0 ", end, field));
- }
- }
- public void SetDateWhereB(string field, string start, string end, IList<string> where)
- {
- if (start != "" || end != "")
- {
- if (start != "" && end != "")
- {
- if (start == end) where.Add(string.Format(" dateDiff(d,{1},'{0}')=0 ", end, field));
- else where.Add(string.Format(" (DATEDIFF(s,'{0}',{2})>=0 and DATEDIFF(s,'{1}',{2})<=0 )", start, end, field));//where.Add(string.Format(" ({2} Between '{0}' and '{1}' )", start, end, field));
- }
- else if (start != "")
- where.Add(string.Format(" {1}>='{0}'", start, field));
- else
- where.Add(string.Format(" dateDiff(d,{1},'{0}')=0 ", end, field));
- }
- }
- public string GetDateWhere(string field, string start, string end)
- {
- if (start != "" || end != "")
- {
- if (start != "" && end != "")
- return string.Format(" (DATEDIFF(d,'{0}',{2})>=0 and DATEDIFF(d,'{1}',{2})<=0 )", start, end, field);
- else if (start != "")
- return string.Format(" {1}>='{0}'", start, field);
- else
- return string.Format(" dateDiff(d,{1},'{0}')=0 ", end, field);
- }
- return "";
- }
- /// <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 "0";
- return Convert.ToDouble(value).ToString("N" + num);
- }
- public string GetDoubleString(object value, string txt)
- {
- if (string.IsNullOrEmpty(value.ToString())) return 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 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 bool UrlPostParmsCheck(string parms)
- {
- return CommonHelper.UrlPostParmsCheck(parms);
- }
- public int GetInt(string parm)
- {
- return CommonHelper.GetInt(parm);
- }
- 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 static String cleanHtml(String htmlText)
- {
- if (htmlText == null)
- return null;
- htmlText = htmlText.Trim();
- if (htmlText.Length == 0)
- return htmlText;
- string[] regex = { "expression\\((.*?)\\)", "eval\\((.*?)\\)", "<script[^>]*?>[\\s\\S]*?</script>", "<style[^>]*?>[\\s\\S]*?</style>",
- "<!--.*?-->", "<script[^>]*?>", "<!--", "javascript:", "vbscript:","onload(.*?)=" };
- for (int i = 0; i < regex.Length; i++)
- {
- htmlText = Regex.Replace(htmlText, regex[i], "", RegexOptions.IgnoreCase);
- }
- htmlText = htmlText.Replace("--", "- -").Replace("'", "'").Replace("/*", "/ *");//.Replace("(", "(").Replace(")", ")");
- return htmlText;
- }
- public string GetString(string param)
- {
- string text = CommonHelper.GetString(param);
- text = cleanHtml(text);
- return text;
- }
- public string GetPostString(string param)
- {
- string text = CommonHelper.GetPostString(param).Trim();
- text = cleanHtml(text);
- return text;
- }
- public string GetDeepString(params string[] parms)
- {
- string text = CommonHelper.GetDeepString(parms);
- text = cleanHtml(text);
- return text;
- }
- public string GetHttpDecodeString(string parm)
- {
- string text = HttpUtility.UrlDecode(GetString(parm));
- text = cleanHtml(text);
- return text;
- }
- public string GetHttpDecodeString(string parm, Encoding coding)
- {
- string text = HttpUtility.UrlDecode(GetString(parm), coding);
- text = cleanHtml(text);
- return text;
- }
- public int GetDeepIndex(params string[] parms)
- {
- return CommonHelper.GetDeepIndex(parms);
- }
- #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,
- DefaultTime = 5,
- OneDay = 1,
- OneMonth = 2,
- OneYear = 3,
- TwoMonth = 4
- }
- }
|