| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Utils;
- namespace SiteCore
- {
- public class WebBasePage:BasePage
- {
- public int PkID; //int主键值
- protected string tmpId = "";
- protected bool tmpExpire;
- protected string tmpState = "";
- protected string fullScreen = "全屏查看";
- #region 防重复刷新
- private bool _refreshState;
- //是否是页面刷新
- private bool _isRefresh;
- public bool IsRefresh
- {
- get
- {
- return _isRefresh;
- }
- }
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- if (Context.Session["__ISREFRESH"] == null)
- Context.Session["__ISREFRESH"] = false;
- }
- protected override void LoadViewState(object savedState)
- {
- object[] allStates = (object[])savedState;
- base.LoadViewState(allStates[0]);
- _refreshState = (bool)allStates[1];
- _isRefresh = _refreshState == (bool)Session["__ISREFRESH"];
- }
- protected override object SaveViewState()
- {
- Session["__ISREFRESH"] = _refreshState;
- object[] allStates = new object[2];
- allStates[0] = base.SaveViewState();
- allStates[1] = !_refreshState;
- return allStates;
- }
- #endregion
- protected bool IsReport { get; set; }
- protected bool IsFullScreen { get; set; }
- #region 页面私有方法
- /// <summary>
- /// 检测是否登录
- /// </summary>
- public bool CheckRights()
- {
- string sPath=CommonHelper.GetPrePath();
- string curUrl = HttpContext.Current.Request.Url.AbsolutePath;
- if (CurrentUser == null)
- {
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "SiteTransfer.aspx" + "';</script>");
- Response.End();
- return false;
- }
- else if (CurrentUser.MerchantID < 1)//是会员登录状态
- {
- if (curUrl.IndexOf("/MerchantCenter", StringComparison.OrdinalIgnoreCase) != -1)//如果是会员访问商家页面则退出
- {
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "SiteTransfer.aspx" + "';</script>");
- Response.End();
- return false;
- }
- }
- else if (CurrentUser.MerchantID >0)//
- {
- if (curUrl.IndexOf("/UserCenter", StringComparison.OrdinalIgnoreCase) != -1)//如果是会员访问商家页面则退出
- {
- Response.Write("<script type=\"text/javascript\">window.top.location='" + sPath + "SiteTransfer.aspx" + "';</script>");
- Response.End();
- return false;
- }
- }
- else
- {
- ShowTabPage();
- }
- return true;
- }
- /// <summary>
- /// 显示通用错误
- /// </summary>
- public void ShowCustomError()
- {
- ShowMsg("提示", "系统繁忙或发生错误!");
- }
- /// <summary>
- /// 显示全屏查看
- /// </summary>
- /// <returns></returns>
- public bool ShowFullScreen()
- {
- if (!UrlParmsCheck("fs"))
- {
- string str = "<a href=\"javascript:openCurFullWin();\">(<span class=\"fullscreen\"></span>全屏查看)</a>";
- string script = string.Format("$(\"" + str.Replace("\"", "") + "\").appendTo($(\".title\"))");
- AddScript(script);
- return true;
- }
- else
- {
- IsFullScreen = true;
- return false;
- }
- }
- public void ShowTabPage()
- {
- if (UrlParmsCheck("it"))//如果是tab页中转的
- {
- string script = string.Format("$(\".title\").hide()");
- AddScript(script);
- }
- }
- #endregion
- #region 页面事件
- protected override void OnPreLoad(EventArgs e)
- {
- if (UrlParmsCheck("isReport"))IsReport = true;
- if (Page.IsPostBack)
- {
- if (EnableViewState)
- {
- if (ViewState["ID"] != null)
- PkID = Convert.ToInt32(ViewState["ID"]);
- }
- }
- base.OnPreLoad(e);
- }
- protected override void OnPreRender(EventArgs e)
- {
- if(EnableViewState)ViewState["ID"] = PkID;
- if (WaitShowScript.Count > 0)
- Page.ClientScript.RegisterStartupScript(GetType(), "alt", "<script>" + string.Join(";", WaitShowScript.ToArray()) + "</script>");
- base.OnPreRender(e);
- }
- private readonly List<string> _waitShowScript=new List<string>();
- public List<string> WaitShowScript
- {
- get { return _waitShowScript; }
- set { WaitShowScript = value;}
- }
- /// <summary>
- /// 添加运行脚本
- /// </summary>
- /// <param name="func"></param>
- public void AddScript(string func)
- {
- _waitShowScript.Add(func.TrimEnd(';'));
- //Page.ClientScript.RegisterStartupScript(GetType(), "alt", "<script>" + func + "</script>");
- }
- #endregion
- #region 设置查询条件
- protected void KeyWhere(string field,string value,IList<string> where)
- {
- value = value.Trim();
- if(value!="")
- {
- string[] sArr = field.Split(',');
- StringBuilder str=new StringBuilder();
- for (int i = 0; i < sArr.Length;i++ )
- {
- str.Append(string.Format(" {1} like '%{0}%' or", value, sArr[i]));
- }
- where.Add(" ("+str.ToString().TrimEnd("or".ToCharArray())+") ");
- }
- }
- protected void EqualsWhere(string field, string value, IList<string> where)
- {
- if(value!="")
- {
- where.Add(string.Format(" {1}={0}",value,field));
- }
- }
- protected void StartEndDateWhere(string s_field,string e_field,string start, string end, IList<string> where)
- {
- if (start != "" || end != "")
- {
- if (start != "" && end != "")
- where.Add(string.Format(" {2}>='{0}' and {3}<='{1}'", start, end, s_field,e_field));
- else if (start != "")
- where.Add(string.Format(" {1}>='{0}'", start, s_field));
- else
- where.Add(string.Format(" {1}<='{0}'", end, e_field));
- }
- }
- protected void BetweenStringWhere(string field,string start,string end,IList<string> where)
- {
- if (start != "" || end != "")
- {
- if (start != "" && end != "")
- 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(" {1}<='{0}'", end, field));
- }
- }
- protected void BetweenIntWhere(string field, string start, string end, IList<string> where)
- {
- if (start != "" || end != "")
- {
- if (start != "" && end != "")
- 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(" {1}<={0}", end, field));
- }
- }
- #endregion
- #region GridView数据处理
- /// <summary>
- /// 过期
- /// </summary>
- /// <param name="endTime"></param>
- /// <returns></returns>
- protected bool GetIsExpire(object endTime)
- {
- if (endTime != null && endTime.ToString() != "" && Convert.ToDateTime(endTime).AddDays(1) <= DateTime.Now)
- return true;
- return false;
- }
- /// <summary>
- /// 发布
- /// </summary>
- /// <param name="expire"></param>
- /// <param name="pubstate"></param>
- /// <param name="sId"></param>
- /// <param name="pType"></param>
- /// <returns></returns>
- protected string GetPublishString(bool expire, object pubstate, string sId,string pType)
- {
- if (expire)
- return "<span class=\"tip\">发布</span>";
- else
- {
- if (pubstate.ToString() == "1")
- return string.Format("<a href=\"javascript:mcAjaxFunc('{0}','{1}','下架','un');\" title=\"下架后将不会在网站上显示\">下架</a>", pType,sId);
- else
- return string.Format("<a href=\"javascript:showPublish('{0}','{1}');\" title=\"发布后将在网站显示\">发布</a>", pType, sId);
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="expire"></param>
- /// <param name="sId"></param>
- /// <param name="pType"></param>
- /// <returns></returns>
- protected string GetDelString(bool expire, string sId, string pType)
- {
- if (expire)//过期允许删除
- return "<a href=\"javascript:mcAjaxFunc('"+pType+"','"+sId+"','删除');\" >删除</a>";
- else
- return "<span class=\"tip\" title=\"未过期不允许删除\">删除</span>";
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="expire"></param>
- /// <param name="sId"></param>
- /// <returns></returns>
- protected string GetEditString(bool expire, string sId)
- {
- if (expire)
- return "<span class=\"tip\" >编辑</span>";
- else
- return "<a href=\"javascript:rectEdit('" + sId + "')\" title=\"修改\">编辑</a>";
- }
- protected string GetEditString(bool expire, string sId,string url)
- {
- if (expire)
- return "<span class=\"tip\" >编辑</span>";
- else
- return "<a href=\"javascript:rectEdit('" + sId + "','"+url+"')\" title=\"修改\">编辑</a>";
- }
- /// <summary>
- /// 转赠好友
- /// </summary>
- /// <param name="expire"></param>
- /// <param name="sId"></param>
- /// <param name="num"></param>
- /// <param name="usedNum"></param>
- /// <returns></returns>
- protected string GetUserGiveString(bool expire,string sId,object num,object usedNum)
- {
- if (expire || Convert.ToInt32(GetMinuteNum(num,usedNum))<1)
- return "<span class=\"tip\">转赠好友</span>";
- else
- return "<a href=\"javascript:giveToFriend('" + sId+ "');\" title=\"转赠好友\">转赠好友</a>";
- }
- /// <summary>
- /// 状态显示
- /// </summary>
- /// <param name="state"></param>
- /// <returns></returns>
- public string GetStateString(bool expire,object state)
- {
- if (state.ToString() == "") return "";
- if (expire)
- return "<span style='color:red'>己过期</span>";
-
- int si = Convert.ToInt32(state);
- switch (si)
- {
- case 1:return "<span style='color:blue'>己发布</span>";
- default:
- return "<span>未发布</span>";
- }
- }
- /// <summary>
- /// 获取分隔后数组中的某项
- /// </summary>
- /// <param name="result"></param>
- /// <param name="idx"></param>
- /// <returns></returns>
- public string GetSplitString(object result, int idx)
- {
- if (result.ToString() == "") return "";
- string[] arr = result.ToString().Split(',');
- if (arr.Length > idx)
- return arr[idx];
- return "";
- }
- #endregion
- #region GridView 绑定
- public void SetGridBind(string sqltable, GridView gridView, DataStruct dStruct)
- {
- DataTable dt = WebCache.GetData(sqltable, dStruct);
- GridViewBind(gridView, dt, dStruct.EmptyMessage);
- }
- public void SetReportGridBind(string sqltable, GridView gridView, DataStruct dStruct)
- {
- DataTable dt;
- if (IsReport)
- {
- string sWhere = SecurityHelper.UrlDecoding(GetString("sw"));
- if (sWhere != "")
- {
- dStruct.MainWhere = sWhere.Split('μ')[0];
- dStruct.SecondWhere = sWhere.Split('μ')[1];
- }
- dt = WebCache.GetFullData(sqltable,dStruct);
- }
- else
- {
- if (IsReport)
- {
- HiddenField hidden = new HiddenField();
- hidden.ID = "hReport";
- //加密条件放至隐藏控件
- hidden.Value = SecurityHelper.UrlEncoding(dStruct.MainWhere + "μ" + dStruct.SecondWhere);
- Page.Form.Controls.AddAt(0, hidden);
- }
- dt = WebCache.GetData(sqltable,dStruct);
- }
- GridViewBind(gridView, dt, dStruct.EmptyMessage);
- if (IsReport)
- {
- Page.EnableViewState = false;
- StringWriter oStringWriter = new StringWriter();
- HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
- Page.RenderControl(oHtmlTextWriter);
- WebHelper.ExportGridView(this.Title, oStringWriter.ToString());
- }
- }
- public void SetSimpleGridBind(string sqltable, GridView gridView, DataStruct dStruct)
- {
- dStruct.SecondWhere = SecondWhere;
- DataTable dt = WebCache.GetData(sqltable, dStruct);
- GridViewBind(gridView, dt, dStruct.EmptyMessage);
- }
- public void GridViewBind(GridView gridView,DataTable dt)
- {
- GridViewBind(gridView, dt, "当前没有记录");
- }
- public void GridViewBind(GridView gridView, DataTable dt, string emptyMsg)
- {
- if (dt!=null && dt.Rows.Count < 1)
- {
- dt.Rows.Add(dt.NewRow());
- gridView.DataSource = dt;
- gridView.DataBind();
- int columnCount = gridView.Rows[0].Cells.Count;
- gridView.Rows[0].Cells.Clear();
- gridView.Rows[0].Cells.Add(new TableCell());
- gridView.Rows[0].Cells[0].CssClass = "GridEmptyDataRowStyle";
- gridView.Rows[0].Cells[0].ColumnSpan = columnCount;
- gridView.Rows[0].Cells[0].Text = emptyMsg;
- gridView.RowStyle.HorizontalAlign = HorizontalAlign.Center;
- }
- else
- {
- gridView.DataSource = dt;
- gridView.DataBind();
- }
- }
- #endregion
- #region 获取编辑页面URL参数
- private string _lcPara;
- /// <summary>
- /// URL参数 lcPara=xx,1,yy,2
- /// </summary>
- private string GetLcPara(string key)
- {
- if (string.IsNullOrEmpty(_lcPara))
- {
- _lcPara = Request.QueryString[key];
- }
- return _lcPara;
- }
- /// <summary>
- /// 获取默认主键
- /// </summary>
- /// <returns></returns>
- public string GetPk()
- {
- return GetPara("LcID");
- }
- /// <summary>
- /// 获取自定义url参数
- /// </summary>
- /// <param name="key">参数名</param>
- /// <returns></returns>
- public string GetPara(string key)
- {
- //LCPara=PkID,1,sName,sk
- string lcPara = GetLcPara("LcPara");
- if (!string.IsNullOrEmpty(lcPara))
- {
- lcPara = lcPara.Replace("#", "");
- string[] sArr = lcPara.Split(',');
- for (int i = 0; i < sArr.Length; i++)
- {
- if (i % 2 != 0) continue;
- if (sArr[i].ToLower().Equals(key.ToLower()))
- return sArr[i + 1];
- }
- }
- return "";
- }
- #endregion
- }
- }
|