WebLibs.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Web;
  5. using System.Web.UI.WebControls;
  6. using SysBaseLibs;
  7. namespace SysDataLibs
  8. {
  9. public class WebLibs
  10. {
  11. /// <summary>
  12. /// 将不能在HTML中正常显示的ASCII字符串进行Html语法的翻译
  13. /// </summary>
  14. /// <param name="pcStr">需要进行Html语法翻译的ASCII字符串</param>
  15. public static void AreaToHtml(ref string pcStr)
  16. {
  17. if (pcStr != null)
  18. {
  19. pcStr = pcStr.Replace(" ", "&nbsp;");
  20. pcStr = pcStr.Replace("\r", "<br>");
  21. }
  22. }
  23. /// <summary>
  24. /// 替换Url地址信息里的 换行符号
  25. /// </summary>
  26. /// <param name="pcURLMsg"></param>
  27. /// <returns></returns>
  28. public static string ConvertURLMsg(string pcURLMsg)
  29. {
  30. pcURLMsg = pcURLMsg.Replace("\n\r", " ");
  31. pcURLMsg = pcURLMsg.Replace("\r\n", " ");
  32. pcURLMsg = pcURLMsg.Replace("\r", " ");
  33. pcURLMsg = pcURLMsg.Replace("\n", " ");
  34. return pcURLMsg;
  35. }
  36. //public static void WebShowMessage(string pcMsg)
  37. //{
  38. // WebShowMessage(pcMsg, ErrActType.Return);
  39. //}
  40. //public static void WebShowMessage(string pcMsg, ErrActType poErrActType)
  41. //{
  42. // pcMsg = ConvertURLMsg(pcMsg);
  43. // HttpContext.Current.Response.Redirect("../Pub/WebShowMsg.aspx?pc_ErrorMsg=" + pcMsg + "&pc_ActionType=" + poErrActType.ToString());
  44. //}
  45. public static Unit IntToUnit(int piPixels)
  46. {
  47. return Unit.Parse(piPixels.ToString() + "px");
  48. }
  49. public static string ColorToHex(System.Drawing.Color poColor)
  50. {
  51. string lcRetVal = poColor.ToArgb().ToString("X");
  52. lcRetVal = "#" + lcRetVal.Substring(2, 6);
  53. return lcRetVal;
  54. }
  55. public static string CurPageName
  56. {
  57. get
  58. {
  59. string lcRetVal = "";
  60. string[] arrayurl = HttpContext.Current.Request.Url.PathAndQuery.Split('?');
  61. if (arrayurl != null && arrayurl.Length > 0)
  62. {
  63. string file = arrayurl[0];
  64. string[] arr2 = file.Split('/');
  65. if (arr2 != null && arr2.Length > 0)
  66. {
  67. if (arr2.Length == 1)
  68. lcRetVal = arr2[0];
  69. else
  70. lcRetVal = arr2[arr2.Length - 2] + "_" + arr2[arr2.Length - 1];
  71. }
  72. }
  73. return lcRetVal;
  74. }
  75. }
  76. public static UserSession GetUserSession()
  77. {
  78. UserSession loRetVal = null;
  79. try
  80. {
  81. if (HttpContext.Current.Session != null && HttpContext.Current.Session[Contants.UserInfoId] != null)
  82. {
  83. loRetVal = (UserSession)HttpContext.Current.Session[Contants.UserInfoId];
  84. }
  85. }
  86. catch
  87. {
  88. }
  89. return loRetVal;
  90. }
  91. public static UserSession CheckLogin()
  92. {
  93. UserSession loRetVal = null;
  94. loRetVal = GetUserSession();
  95. if (loRetVal == null)
  96. {
  97. //../ Login / Index
  98. //System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>alert('对不起! 您还没有登录或超时'); Form2.submit();</script>");
  99. System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='/Login/Index' target='_top' ></form><script>alert('对不起! 您还没有登录或超时'); Form2.submit();</script>");
  100. System.Web.HttpContext.Current.Response.End();
  101. }
  102. return loRetVal;
  103. }
  104. public static string GetCookieValue(string pcCookieKey)
  105. {
  106. return GetCookieValue(pcCookieKey, Contants.ShenYangSysCookieName);
  107. }
  108. public static string GetCookieValue(string pcCookieKey, string pcCookieName)
  109. {
  110. string lcRetVal = "";
  111. if (HttpContext.Current.Request.Browser.Cookies)
  112. {
  113. HttpCookie loCookie = HttpContext.Current.Request.Cookies[pcCookieName];
  114. if (loCookie != null)
  115. {
  116. string lcTempValue = loCookie[pcCookieKey];
  117. if (lcTempValue != null)
  118. lcRetVal = lcTempValue;
  119. }
  120. }
  121. return lcRetVal;
  122. }
  123. public static void SetCookieValue(string pcCookieKey, string pcCookieValue)
  124. {
  125. SetCookieValue(pcCookieKey, pcCookieValue, Contants.ShenYangSysCookieName);
  126. }
  127. public static void SetCookieValue(string pcCookieKey, string pcCookieValue, string pcCookieName)
  128. {
  129. if (HttpContext.Current.Request.Browser.Cookies)
  130. {
  131. HttpCookie loCookie = HttpContext.Current.Request.Cookies[pcCookieName];
  132. if (loCookie == null)
  133. loCookie = new HttpCookie(pcCookieName);
  134. loCookie.Values.Remove(pcCookieKey);
  135. loCookie.Values.Add(pcCookieKey, pcCookieValue);
  136. loCookie.Expires = DateTime.Now.AddMonths(6);
  137. HttpContext.Current.Response.SetCookie(loCookie);
  138. }
  139. }
  140. public static string CvStrByType(ref string pcStr, CovType TypeUse)
  141. {
  142. pcStr = pcStr.Trim();
  143. switch (((int)TypeUse))
  144. {
  145. case 1:
  146. pcStr = pcStr.Replace(@"\", @"\\");
  147. pcStr = pcStr.Replace("\r\n", @"\n");
  148. pcStr = pcStr.Replace("\r", "");
  149. pcStr = pcStr.Replace("\n", "");
  150. pcStr = pcStr.Replace("'", @"\'");
  151. break;
  152. case 2:
  153. pcStr = pcStr.Replace("&", "&amp;");
  154. pcStr = pcStr.Replace("<", "&lt;");
  155. pcStr = pcStr.Replace(">", "&gt;");
  156. pcStr = pcStr.Replace(" ", "&nbsp;");
  157. pcStr = pcStr.Replace("'", "\u2019");
  158. pcStr = pcStr.Replace("\r\n", "<br>");
  159. pcStr = pcStr.Replace("\r", "<br>");
  160. pcStr = pcStr.Replace("\n", "<br>");
  161. break;
  162. case 3:
  163. pcStr = pcStr.Replace("<br>", "\r\n");
  164. pcStr = pcStr.Replace("<BR>", "\r\n");
  165. pcStr = pcStr.Replace("<Br>", "\r\n");
  166. pcStr = pcStr.Replace("<bR>", "\r\n");
  167. break;
  168. case 4:
  169. pcStr = pcStr.Replace("\r\n", "<br>");
  170. pcStr = pcStr.Replace(" ", "&nbsp;");
  171. pcStr = pcStr.Replace("'", "\u2019");
  172. pcStr = pcStr.Replace("\r", "<br>");
  173. pcStr = pcStr.Replace("\n", "<br>");
  174. pcStr = pcStr.Replace("<", "&lt;");
  175. pcStr = pcStr.Replace(">", "&gt;");
  176. pcStr = pcStr.Replace("&", "\uff06");
  177. break;
  178. default:
  179. pcStr = pcStr.Replace("'", "''");
  180. break;
  181. }
  182. return (pcStr + "");
  183. }
  184. #region //===============================错误处理======================
  185. /// <summary>
  186. /// 权限检查错误转向页面
  187. /// </summary>
  188. /// <param name="as_PowerType">1,没有浏览权;2,没有添加权 ; 3 没有修改权 4;没有删除权;
  189. /// 5,没有打印权; 7 页面权限编号信息错误</param>
  190. public static void NotPower(int as_PowerType)
  191. {
  192. NotPower(as_PowerType, "N");
  193. }
  194. public static void NotPower(PowerType poType)
  195. {
  196. string lcRetval = "您的权限低,无法操作!";
  197. switch (poType)
  198. {
  199. case PowerType.IsBrowse:
  200. lcRetval = "您没有【访问该页面】的权限,如有问题,请联系管理员!";
  201. break;
  202. case PowerType.IsAdd:
  203. lcRetval = "您没有【添加功能】的权限,如有问题,请联系管理员!";
  204. break;
  205. case PowerType.IsUpdate:
  206. lcRetval = "您没有【修改功能】的权限,如有问题,请联系管理员!";
  207. break;
  208. case PowerType.IsDelete:
  209. lcRetval = "您没有【删除功能】的权限,如有问题,请联系管理员!";
  210. break;
  211. case PowerType.IsAudit:
  212. lcRetval = "您没有【审核功能】的权限,如有问题,请联系管理员!";
  213. break;
  214. case PowerType.IsPrint:
  215. lcRetval = "您没有【打印功能】的权限,如有问题,请联系管理员!";
  216. break;
  217. }
  218. HttpContext.Current.Response.Write("$(function() {layer.alert('" + lcRetval + "', { title: '提示信息' })});");
  219. }
  220. /// <summary>
  221. /// 权限检查错误转向页面
  222. /// </summary>
  223. /// <param name="as_PowerType"> 1,没有浏览权;2,没有添加权 ; 3 没有修改权 4;没有删除权;
  224. /// 5,没有打印权; 7 页面权限编号信息错误</param>
  225. /// <param name="as_ReturnType">参数 C 关闭;R 重定向 ;P 上一页; U 指定页面 ;N 不显示</param>
  226. public static void NotPower(int as_PowerType, string as_ReturnType)
  227. {
  228. if (as_PowerType == 1) { ErrRedirect(-30000001, as_ReturnType); } //浏览
  229. if (as_PowerType == 2) { ErrRedirect(-30000002, as_ReturnType); } //添加
  230. if (as_PowerType == 3) { ErrRedirect(-30000003, as_ReturnType); } //修改
  231. if (as_PowerType == 4) { ErrRedirect(-30000004, as_ReturnType); } //删除
  232. if (as_PowerType == 5) { ErrRedirect(-30000005, as_ReturnType); } //打印
  233. if (as_PowerType == 5) { ErrRedirect(-30000006, as_ReturnType); } //审核
  234. if (as_PowerType == 6) { ErrRedirect(-311271, as_ReturnType); } //检查是否有浏览新增删除修改的权限
  235. if (as_PowerType == 7) { ErrRedirect(-30000008, as_ReturnType); } //页面权限编号信息错误
  236. if (as_PowerType == 8) { ErrRedirect(-30000007, as_ReturnType); } //页面权限编号信息错误
  237. }
  238. /// <summary>
  239. /// 操作错误 提示页面
  240. /// </summary>
  241. /// <param name="as_OperationType">1,为删除的行为空 ;2 编号为空 ;3 参数传递错误 </param>
  242. public static void OperationErr(int as_PowerType)
  243. {
  244. OperationErr(as_PowerType, "");
  245. }
  246. /// <summary>
  247. /// 操作错误 提示页面
  248. /// </summary>
  249. /// <param name="as_OperationType">1,为删除的行为空 ;2 编号为空 ;3 参数传递错误 </param>
  250. /// <param name="as_ReturnType"></param>
  251. public static void OperationErr(int as_OperationType, string as_ReturnType)
  252. {
  253. if (as_OperationType == 1) { ErrRedirect(-10000101, as_ReturnType); }
  254. if (as_OperationType == 2) { ErrRedirect(-10000102, as_ReturnType); }
  255. if (as_OperationType == 3) { ErrRedirect(-10000103, as_ReturnType); }
  256. }
  257. public static void ErrRedirect(int as_ErrorCode, string as_ReturnType)
  258. {
  259. string returnType;
  260. if (as_ReturnType.Trim().Length == 0)
  261. returnType = "C";
  262. else
  263. returnType = as_ReturnType;
  264. PageRedirect(as_ErrorCode, returnType);
  265. }
  266. public static void PageRedirect(int ErrorCode, string ReturnType)
  267. {
  268. HttpContext.Current.Response.Redirect("../Pub/PubShowMessage.aspx?al_ErrCode=" + ErrorCode.ToString() + "&as_ReturnType=" + ReturnType);
  269. }
  270. public static void PageAlert(int ErrorCode, string ReturnType)
  271. {
  272. HttpContext.Current.Response.Redirect("../Pub/PubShowMessage.aspx?al_ErrCode=" + ErrorCode.ToString() + "&as_ReturnType=" + ReturnType);
  273. }
  274. public static void LoginOut()
  275. {
  276. HttpContext.Current.Session.RemoveAll();
  277. System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>Form2.submit();</script>");
  278. System.Web.HttpContext.Current.Response.End();
  279. }
  280. #endregion
  281. }
  282. }