SiteBasePage.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web;
  5. using System.Web.UI.WebControls;
  6. using Utils;
  7. namespace SiteCore
  8. {
  9. public class SiteBasePage : BasePage
  10. {
  11. public static string tmpImgPath = webConfig.tmpImgPath;
  12. public static string instImgPath = webConfig.instPath;
  13. public static string wsPath = webConfig.wsPath;
  14. public static string expertImgPath = webConfig.expertPath;
  15. #region ShowKeyWord
  16. public const string SiteKey = " - 校园交易网";
  17. public void ShowKeyWord(string key, string des)
  18. {
  19. StringBuilder str = new StringBuilder();
  20. str.AppendFormat("\n<meta content=\"{0}\" name=\"keywords\" />\n", key);
  21. str.AppendFormat("<meta content=\"{0}\" name=\"description\" />", des);
  22. Literal lit = new Literal();
  23. lit.Text = str.ToString();
  24. Page.Header.Controls.AddAt(3, lit);
  25. }
  26. public void ShowTitle(string title)
  27. {
  28. Title = "校园交易网 - " + title;
  29. }
  30. #endregion
  31. public bool CheckLogin()
  32. {
  33. if (CurrentUser == null) { Response.Write("您尚未登录!"); return false; }
  34. return true;
  35. }
  36. public bool CheckUser()
  37. {
  38. if (CurrentUser == null) { return false; }
  39. return true;
  40. }
  41. public string GetDottedStyle(int index)
  42. {
  43. if (index == 0) return "wraptxt";
  44. return "wraptxt top_dot";
  45. }
  46. public string GetOrderNum(int index)
  47. {
  48. if (index > 3) return "<li class='cut_order' style='width:30px'>" + index + "</li>";
  49. return "<li class='top_order' style='width:30px'>" + index + "</li>";
  50. }
  51. public string GetSelfID(string sId)
  52. {
  53. return CommonHelper.GetNoneZero(sId);
  54. }
  55. public string GetSelfHref(string prev, object sId)
  56. {
  57. string gId = sId.ToString();//.Substring(1);
  58. return prev + "/" + gId.PadLeft(5, '0');
  59. }
  60. public double GetGroupSecond(object pTime, object day)
  61. {
  62. if (pTime.Equals(DBNull.Value) || day.Equals(DBNull.Value)) return 0;
  63. DateTime endTime = Convert.ToDateTime(pTime).AddDays(Convert.ToInt32(day));
  64. DateTime nowTime = DateTime.Now;
  65. double second = endTime.Subtract(nowTime).TotalSeconds;
  66. if (second > 0) return second;
  67. return 0;
  68. }
  69. #region 网站过滤
  70. /// <summary>
  71. /// 记录是分开的
  72. /// </summary>
  73. public bool IsSplit { get; set; }
  74. public bool IsIndustry { get; set; }
  75. public string GetFilterString(IList<DicItem> list, params string[] pArr)
  76. {
  77. return GetFilterString(list, pArr.Length, pArr);
  78. }
  79. public string GetFilterString(IList<DicItem> list, int showIdx, params string[] pArr)
  80. {
  81. //if (list == null || list.Count<1) return "";
  82. StringBuilder filterStr = new StringBuilder();
  83. int len = pArr.Length;
  84. int idx = GetDeepIndex(pArr);
  85. //参数级别
  86. if (idx > showIdx) idx = showIdx;
  87. if (idx == 1 && len == 1)
  88. { //只有一级
  89. GetOneLevelUL(list, pArr[0], ref filterStr);
  90. }
  91. else if (idx == 0)
  92. { //初始
  93. GetContentUL(list, ref filterStr, idx, pArr);
  94. }
  95. else
  96. {
  97. string sName = null;
  98. if (IsSplit) sName = GetHttpDecodeString(pArr[idx - 1] + "cn");
  99. else
  100. {
  101. if (list.Count > 0) sName = list[0].Name;
  102. else sName = "未知";
  103. }
  104. GetItemUL(ref filterStr, sName, idx, pArr);//获取item项
  105. filterStr.Append("<div class=\"part_info clearfix\">");
  106. filterStr.Append(" <div class=\"content\">");
  107. GetContentUL(list, ref filterStr, idx, pArr);//获取内容项
  108. filterStr.Append("</div></div>");
  109. }
  110. return filterStr.ToString();
  111. }
  112. //获取ITEM项
  113. public void GetItemUL(ref StringBuilder filterStr, string sName, int idx, params string[] pArr)
  114. {
  115. if (pArr.Length == 0) return;
  116. filterStr.Append("<ul class=\"clearfix\">");
  117. filterStr.AppendFormat("<li><a href=\"{0}\">全部</a> </li>", RemoveUrlParamHasCN(pArr));
  118. if (pArr.Length > 0)
  119. {
  120. if (idx % 2 == 0)
  121. {
  122. filterStr.AppendFormat("<li><a href=\"{1}\">{0}</a> </li>", HttpUtility.UrlDecode(sName), RemoveUrlParamHasCN(pArr[idx - 1]));
  123. }
  124. else
  125. {
  126. filterStr.AppendFormat("<li><b>{0}</b> </li>", HttpUtility.UrlDecode(sName));
  127. }
  128. }
  129. filterStr.Append("</ul>");
  130. }
  131. //获取内容项
  132. public void GetContentUL(IList<DicItem> list, ref StringBuilder filterStr, int idx, params string[] pArr)
  133. {
  134. //filterStr.Append("<ul class=\"clearfix\">");
  135. if (list.Count - idx > 0)
  136. {
  137. //int pi = idx - 1 < 0 ? 0 : idx - 1;
  138. string tmpParam = null;
  139. if (IsSplit) tmpParam = pArr[idx] + "={0}&" + pArr[idx] + "cn={1}&pg=1";
  140. else tmpParam = pArr[idx] + "={0}&pg=1";
  141. string url = "";
  142. string itemName = "";
  143. int i = 0;
  144. int pLen = GetDeepIndex(pArr);
  145. int cId = 0;
  146. if (pLen > 0) cId = Convert.ToInt32(GetDeepString(pArr));
  147. if (pLen < pArr.Length)
  148. filterStr.AppendFormat("<span>{0}</span>", "全部");
  149. else
  150. filterStr.AppendFormat("<span><a href=\"{0}\">全部</a></span>", RemoveUrlParamHasCN(pArr[idx]));
  151. url = CommonHelper.GetCurUrl(tmpParam);
  152. foreach (DicItem item in list)
  153. {
  154. if (!IsSplit && i < idx) { i++; continue; }//父节点的记录不显示
  155. if (IsIndustry) itemName = item.Name + "(" + item.Mcount + ")";//行业分类显示数量
  156. else itemName = item.Name;
  157. if (idx > 0 && item.ID == cId)//相同则不显示超链接
  158. {
  159. filterStr.AppendFormat("<span><b>{0}</b></span>", HttpUtility.UrlDecode(itemName));
  160. }
  161. else
  162. {
  163. if (IsSplit) filterStr.AppendFormat("<span><a href=\"{0}\">{1}</a></span>", string.Format(url, item.ID, HttpUtility.UrlEncode(itemName)), itemName);
  164. else filterStr.AppendFormat("<span><a href=\"{0}\">{1}</a></span>", string.Format(url, item.ID), itemName);
  165. }
  166. i++;
  167. }
  168. }
  169. else
  170. {
  171. if (IsSplit) filterStr.AppendFormat("<span><b>{0}</b></span>", GetHttpDecodeString(pArr[idx - 1] + "cn"));
  172. else if (list.Count > idx - 1)
  173. filterStr.AppendFormat("<span><b>{0}</b></span>", HttpUtility.UrlDecode(list[idx - 1].Name));
  174. }
  175. //filterStr.Append("</ul>");
  176. }
  177. public void GetOneLevelUL(IList<DicItem> list, string param, ref StringBuilder filterStr)
  178. {
  179. string tmpParam = null;
  180. if (IsSplit) tmpParam = param + "={0}&" + param + "cn={1}&pg=1";
  181. else tmpParam = param + "={0}&pg=1";
  182. string itemName = string.Empty;
  183. string url = string.Empty;
  184. int pId = GetInt(param);
  185. url = CommonHelper.GetCurUrl(tmpParam);
  186. filterStr.Append("<ul class=\"clearfix\">");
  187. filterStr.AppendFormat("<li><a href=\"{0}\">全部</a> </li>", RemoveUrlParamHasCN(param));
  188. foreach (DicItem item in list)
  189. {
  190. if (pId == item.ID) continue;
  191. if (IsIndustry) itemName = item.Name + "(" + item.Mcount + ")";
  192. else itemName = item.Name;
  193. if (item.Name == list[0].Name)
  194. {
  195. filterStr.AppendFormat("<li><b>{0}</b></li>", itemName);
  196. }
  197. else
  198. {
  199. if (IsSplit) filterStr.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", string.Format(url, item.ID, itemName), item.Name);
  200. filterStr.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", string.Format(url, item.ID), item.Name);
  201. }
  202. }
  203. filterStr.Append("</ul>");
  204. }
  205. /// <summary>
  206. /// 删除URL参数有带CN,即ind,indcn两个
  207. /// </summary>
  208. /// <param name="param"></param>
  209. /// <returns></returns>
  210. private string RemoveUrlParamHasCN(params string[] param)
  211. {
  212. int len = param.Length * 2;
  213. string[] sArr = new string[len];
  214. for (int i = 0; i < param.Length; i++)
  215. {
  216. sArr[2 * i] = param[i];
  217. sArr[2 * i + 1] = param[i] + "cn";
  218. }
  219. return CommonHelper.GetCurPageUrlRemoveParm(sArr);
  220. }
  221. #endregion
  222. #region URL参数
  223. //获取raw参数
  224. private string getRawQuery()
  225. {
  226. string rUrl = "";
  227. rUrl = Page.Request.RawUrl;
  228. if (rUrl.IndexOf("?") != -1)
  229. rUrl = rUrl.Substring(rUrl.IndexOf("?") + 1);
  230. else
  231. rUrl = "";
  232. return rUrl.ToLower();
  233. }
  234. /// <summary>
  235. /// 获取当前参数
  236. /// </summary>
  237. /// <param name="parm"></param>
  238. /// <param name="isDel"></param>
  239. /// <returns></returns>
  240. public string GetCurParms(string parm, bool isDel)
  241. {
  242. string raw = getRawQuery();
  243. if (isDel)
  244. return "?" + raw.Replace(parm.ToLower(), "").Replace("&&", "&").TrimStart('&');
  245. return "?" + (raw == "" ? "" : raw + "&") + parm;
  246. }
  247. /// <summary>
  248. /// 给当前页面添加参数
  249. /// </summary>
  250. /// <param name="parm"></param>
  251. /// <param name="df">默认地址</param>
  252. /// <returns></returns>
  253. public string GetCurAddParms(string parm, string df)
  254. {
  255. string sArr = GetCurRemoveParms(parm, df, false);
  256. string[] pArr = parm.Split('&');
  257. string[] tmp;
  258. for (int i = pArr.Length - 1; i >= 0; i--)
  259. {
  260. tmp = pArr[i].Split('=');
  261. if (tmp[1] == "") pArr = CommonHelper.DelArrayString(pArr, tmp[0] + "=");
  262. }
  263. string url = "";
  264. if (sArr.Length > 0)
  265. url = sArr + (pArr.Length > 0 ? "&" + string.Join("&", pArr) : "");
  266. else if (pArr.Length > 0)
  267. url = string.Join("&", pArr);
  268. if (url.Length > 0) return "?" + url;
  269. return df;
  270. }
  271. public string GetCurRemoveParms(string parm, string df, bool isReturn)
  272. {
  273. string raw = getRawQuery();
  274. if (raw == "") return "";
  275. string[] sArr = raw.Split('&');
  276. string[] pArr = parm.Split('&');
  277. IList<int> rList = new List<int>();
  278. for (int i = 0; i < pArr.Length; i++)
  279. {
  280. sArr = CommonHelper.DelArrayString(sArr, pArr[i].Split('=')[0] + "=");
  281. }
  282. if (isReturn)
  283. {
  284. return sArr.Length > 0 ? "?" + string.Join("&", sArr) : df;
  285. }
  286. return string.Join("&", sArr);
  287. }
  288. #endregion
  289. }
  290. }