using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI.WebControls; using Utils; namespace SiteCore { public class SiteBasePage : BasePage { public static string tmpImgPath = webConfig.tmpImgPath; public static string instImgPath = webConfig.instPath; public static string wsPath = webConfig.wsPath; public static string expertImgPath = webConfig.expertPath; #region ShowKeyWord public const string SiteKey = " - 校园交易网"; public void ShowKeyWord(string key, string des) { StringBuilder str = new StringBuilder(); str.AppendFormat("\n\n", key); str.AppendFormat("", des); Literal lit = new Literal(); lit.Text = str.ToString(); Page.Header.Controls.AddAt(3, lit); } public void ShowTitle(string title) { Title = "校园交易网 - " + title; } #endregion public bool CheckLogin() { if (CurrentUser == null) { Response.Write("您尚未登录!"); return false; } return true; } public bool CheckUser() { if (CurrentUser == null) { return false; } return true; } public string GetDottedStyle(int index) { if (index == 0) return "wraptxt"; return "wraptxt top_dot"; } public string GetOrderNum(int index) { if (index > 3) return "
  • " + index + "
  • "; return "
  • " + index + "
  • "; } public string GetSelfID(string sId) { return CommonHelper.GetNoneZero(sId); } public string GetSelfHref(string prev, object sId) { string gId = sId.ToString();//.Substring(1); return prev + "/" + gId.PadLeft(5, '0'); } public double GetGroupSecond(object pTime, object day) { if (pTime.Equals(DBNull.Value) || day.Equals(DBNull.Value)) return 0; DateTime endTime = Convert.ToDateTime(pTime).AddDays(Convert.ToInt32(day)); DateTime nowTime = DateTime.Now; double second = endTime.Subtract(nowTime).TotalSeconds; if (second > 0) return second; return 0; } #region 网站过滤 /// /// 记录是分开的 /// public bool IsSplit { get; set; } public bool IsIndustry { get; set; } public string GetFilterString(IList list, params string[] pArr) { return GetFilterString(list, pArr.Length, pArr); } public string GetFilterString(IList list, int showIdx, params string[] pArr) { //if (list == null || list.Count<1) return ""; StringBuilder filterStr = new StringBuilder(); int len = pArr.Length; int idx = GetDeepIndex(pArr); //参数级别 if (idx > showIdx) idx = showIdx; if (idx == 1 && len == 1) { //只有一级 GetOneLevelUL(list, pArr[0], ref filterStr); } else if (idx == 0) { //初始 GetContentUL(list, ref filterStr, idx, pArr); } else { string sName = null; if (IsSplit) sName = GetHttpDecodeString(pArr[idx - 1] + "cn"); else { if (list.Count > 0) sName = list[0].Name; else sName = "未知"; } GetItemUL(ref filterStr, sName, idx, pArr);//获取item项 filterStr.Append("
    "); filterStr.Append("
    "); GetContentUL(list, ref filterStr, idx, pArr);//获取内容项 filterStr.Append("
    "); } return filterStr.ToString(); } //获取ITEM项 public void GetItemUL(ref StringBuilder filterStr, string sName, int idx, params string[] pArr) { if (pArr.Length == 0) return; filterStr.Append(""); } //获取内容项 public void GetContentUL(IList list, ref StringBuilder filterStr, int idx, params string[] pArr) { //filterStr.Append("
      "); if (list.Count - idx > 0) { //int pi = idx - 1 < 0 ? 0 : idx - 1; string tmpParam = null; if (IsSplit) tmpParam = pArr[idx] + "={0}&" + pArr[idx] + "cn={1}&pg=1"; else tmpParam = pArr[idx] + "={0}&pg=1"; string url = ""; string itemName = ""; int i = 0; int pLen = GetDeepIndex(pArr); int cId = 0; if (pLen > 0) cId = Convert.ToInt32(GetDeepString(pArr)); if (pLen < pArr.Length) filterStr.AppendFormat("{0}", "全部"); else filterStr.AppendFormat("全部", RemoveUrlParamHasCN(pArr[idx])); url = CommonHelper.GetCurUrl(tmpParam); foreach (DicItem item in list) { if (!IsSplit && i < idx) { i++; continue; }//父节点的记录不显示 if (IsIndustry) itemName = item.Name + "(" + item.Mcount + ")";//行业分类显示数量 else itemName = item.Name; if (idx > 0 && item.ID == cId)//相同则不显示超链接 { filterStr.AppendFormat("{0}", HttpUtility.UrlDecode(itemName)); } else { if (IsSplit) filterStr.AppendFormat("{1}", string.Format(url, item.ID, HttpUtility.UrlEncode(itemName)), itemName); else filterStr.AppendFormat("{1}", string.Format(url, item.ID), itemName); } i++; } } else { if (IsSplit) filterStr.AppendFormat("{0}", GetHttpDecodeString(pArr[idx - 1] + "cn")); else if (list.Count > idx - 1) filterStr.AppendFormat("{0}", HttpUtility.UrlDecode(list[idx - 1].Name)); } //filterStr.Append("
    "); } public void GetOneLevelUL(IList list, string param, ref StringBuilder filterStr) { string tmpParam = null; if (IsSplit) tmpParam = param + "={0}&" + param + "cn={1}&pg=1"; else tmpParam = param + "={0}&pg=1"; string itemName = string.Empty; string url = string.Empty; int pId = GetInt(param); url = CommonHelper.GetCurUrl(tmpParam); filterStr.Append("
      "); filterStr.AppendFormat("
    • 全部
    • ", RemoveUrlParamHasCN(param)); foreach (DicItem item in list) { if (pId == item.ID) continue; if (IsIndustry) itemName = item.Name + "(" + item.Mcount + ")"; else itemName = item.Name; if (item.Name == list[0].Name) { filterStr.AppendFormat("
    • {0}
    • ", itemName); } else { if (IsSplit) filterStr.AppendFormat("
    • {1}
    • ", string.Format(url, item.ID, itemName), item.Name); filterStr.AppendFormat("
    • {1}
    • ", string.Format(url, item.ID), item.Name); } } filterStr.Append("
    "); } /// /// 删除URL参数有带CN,即ind,indcn两个 /// /// /// private string RemoveUrlParamHasCN(params string[] param) { int len = param.Length * 2; string[] sArr = new string[len]; for (int i = 0; i < param.Length; i++) { sArr[2 * i] = param[i]; sArr[2 * i + 1] = param[i] + "cn"; } return CommonHelper.GetCurPageUrlRemoveParm(sArr); } #endregion #region URL参数 //获取raw参数 private string getRawQuery() { string rUrl = ""; rUrl = Page.Request.RawUrl; if (rUrl.IndexOf("?") != -1) rUrl = rUrl.Substring(rUrl.IndexOf("?") + 1); else rUrl = ""; return rUrl.ToLower(); } /// /// 获取当前参数 /// /// /// /// public string GetCurParms(string parm, bool isDel) { string raw = getRawQuery(); if (isDel) return "?" + raw.Replace(parm.ToLower(), "").Replace("&&", "&").TrimStart('&'); return "?" + (raw == "" ? "" : raw + "&") + parm; } /// /// 给当前页面添加参数 /// /// /// 默认地址 /// public string GetCurAddParms(string parm, string df) { string sArr = GetCurRemoveParms(parm, df, false); string[] pArr = parm.Split('&'); string[] tmp; for (int i = pArr.Length - 1; i >= 0; i--) { tmp = pArr[i].Split('='); if (tmp[1] == "") pArr = CommonHelper.DelArrayString(pArr, tmp[0] + "="); } string url = ""; if (sArr.Length > 0) url = sArr + (pArr.Length > 0 ? "&" + string.Join("&", pArr) : ""); else if (pArr.Length > 0) url = string.Join("&", pArr); if (url.Length > 0) return "?" + url; return df; } public string GetCurRemoveParms(string parm, string df, bool isReturn) { string raw = getRawQuery(); if (raw == "") return ""; string[] sArr = raw.Split('&'); string[] pArr = parm.Split('&'); IList rList = new List(); for (int i = 0; i < pArr.Length; i++) { sArr = CommonHelper.DelArrayString(sArr, pArr[i].Split('=')[0] + "="); } if (isReturn) { return sArr.Length > 0 ? "?" + string.Join("&", sArr) : df; } return string.Join("&", sArr); } #endregion } }