123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Web;
- using System.Web.UI.WebControls;
- using SysBaseLibs;
- namespace SysDataLibs
- {
- public class WebLibs
- {
- /// <summary>
- /// 将不能在HTML中正常显示的ASCII字符串进行Html语法的翻译
- /// </summary>
- /// <param name="pcStr">需要进行Html语法翻译的ASCII字符串</param>
- public static void AreaToHtml(ref string pcStr)
- {
- if (pcStr != null)
- {
- pcStr = pcStr.Replace(" ", " ");
- pcStr = pcStr.Replace("\r", "<br>");
- }
- }
- /// <summary>
- /// 替换Url地址信息里的 换行符号
- /// </summary>
- /// <param name="pcURLMsg"></param>
- /// <returns></returns>
- public static string ConvertURLMsg(string pcURLMsg)
- {
- pcURLMsg = pcURLMsg.Replace("\n\r", " ");
- pcURLMsg = pcURLMsg.Replace("\r\n", " ");
- pcURLMsg = pcURLMsg.Replace("\r", " ");
- pcURLMsg = pcURLMsg.Replace("\n", " ");
- return pcURLMsg;
- }
- //public static void WebShowMessage(string pcMsg)
- //{
- // WebShowMessage(pcMsg, ErrActType.Return);
- //}
- //public static void WebShowMessage(string pcMsg, ErrActType poErrActType)
- //{
- // pcMsg = ConvertURLMsg(pcMsg);
- // HttpContext.Current.Response.Redirect("../Pub/WebShowMsg.aspx?pc_ErrorMsg=" + pcMsg + "&pc_ActionType=" + poErrActType.ToString());
- //}
- public static Unit IntToUnit(int piPixels)
- {
- return Unit.Parse(piPixels.ToString() + "px");
- }
- public static string ColorToHex(System.Drawing.Color poColor)
- {
- string lcRetVal = poColor.ToArgb().ToString("X");
- lcRetVal = "#" + lcRetVal.Substring(2, 6);
- return lcRetVal;
- }
- public static string CurPageName
- {
- get
- {
- string lcRetVal = "";
- string[] arrayurl = HttpContext.Current.Request.Url.PathAndQuery.Split('?');
- if (arrayurl != null && arrayurl.Length > 0)
- {
- string file = arrayurl[0];
- string[] arr2 = file.Split('/');
- if (arr2 != null && arr2.Length > 0)
- {
- if (arr2.Length == 1)
- lcRetVal = arr2[0];
- else
- lcRetVal = arr2[arr2.Length - 2] + "_" + arr2[arr2.Length - 1];
- }
- }
- return lcRetVal;
- }
- }
- public static UserSession GetUserSession()
- {
- UserSession loRetVal = null;
- try
- {
- if (HttpContext.Current.Session != null && HttpContext.Current.Session[Contants.UserInfoId] != null)
- {
- loRetVal = (UserSession)HttpContext.Current.Session[Contants.UserInfoId];
- }
- }
- catch
- {
- }
- return loRetVal;
- }
- public static UserSession CheckLogin()
- {
- UserSession loRetVal = null;
- loRetVal = GetUserSession();
- if (loRetVal == null)
- {
- //../ Login / Index
- //System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>alert('对不起! 您还没有登录或超时'); Form2.submit();</script>");
- System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='/Login/Index' target='_top' ></form><script>alert('对不起! 您还没有登录或超时'); Form2.submit();</script>");
- System.Web.HttpContext.Current.Response.End();
- }
- return loRetVal;
- }
- public static string GetCookieValue(string pcCookieKey)
- {
- return GetCookieValue(pcCookieKey, Contants.ShenYangSysCookieName);
- }
- public static string GetCookieValue(string pcCookieKey, string pcCookieName)
- {
- string lcRetVal = "";
- if (HttpContext.Current.Request.Browser.Cookies)
- {
- HttpCookie loCookie = HttpContext.Current.Request.Cookies[pcCookieName];
- if (loCookie != null)
- {
- string lcTempValue = loCookie[pcCookieKey];
- if (lcTempValue != null)
- lcRetVal = lcTempValue;
- }
- }
- return lcRetVal;
- }
- public static void SetCookieValue(string pcCookieKey, string pcCookieValue)
- {
- SetCookieValue(pcCookieKey, pcCookieValue, Contants.ShenYangSysCookieName);
- }
- public static void SetCookieValue(string pcCookieKey, string pcCookieValue, string pcCookieName)
- {
- if (HttpContext.Current.Request.Browser.Cookies)
- {
- HttpCookie loCookie = HttpContext.Current.Request.Cookies[pcCookieName];
- if (loCookie == null)
- loCookie = new HttpCookie(pcCookieName);
- loCookie.Values.Remove(pcCookieKey);
- loCookie.Values.Add(pcCookieKey, pcCookieValue);
- loCookie.Expires = DateTime.Now.AddMonths(6);
- HttpContext.Current.Response.SetCookie(loCookie);
- }
- }
- public static string CvStrByType(ref string pcStr, CovType TypeUse)
- {
- pcStr = pcStr.Trim();
- switch (((int)TypeUse))
- {
- case 1:
- pcStr = pcStr.Replace(@"\", @"\\");
- pcStr = pcStr.Replace("\r\n", @"\n");
- pcStr = pcStr.Replace("\r", "");
- pcStr = pcStr.Replace("\n", "");
- pcStr = pcStr.Replace("'", @"\'");
- break;
- case 2:
- pcStr = pcStr.Replace("&", "&");
- pcStr = pcStr.Replace("<", "<");
- pcStr = pcStr.Replace(">", ">");
- pcStr = pcStr.Replace(" ", " ");
- pcStr = pcStr.Replace("'", "\u2019");
- pcStr = pcStr.Replace("\r\n", "<br>");
- pcStr = pcStr.Replace("\r", "<br>");
- pcStr = pcStr.Replace("\n", "<br>");
- break;
- case 3:
- pcStr = pcStr.Replace("<br>", "\r\n");
- pcStr = pcStr.Replace("<BR>", "\r\n");
- pcStr = pcStr.Replace("<Br>", "\r\n");
- pcStr = pcStr.Replace("<bR>", "\r\n");
- break;
- case 4:
- pcStr = pcStr.Replace("\r\n", "<br>");
- pcStr = pcStr.Replace(" ", " ");
- pcStr = pcStr.Replace("'", "\u2019");
- pcStr = pcStr.Replace("\r", "<br>");
- pcStr = pcStr.Replace("\n", "<br>");
- pcStr = pcStr.Replace("<", "<");
- pcStr = pcStr.Replace(">", ">");
- pcStr = pcStr.Replace("&", "\uff06");
- break;
- default:
- pcStr = pcStr.Replace("'", "''");
- break;
- }
- return (pcStr + "");
- }
- #region //===============================错误处理======================
- /// <summary>
- /// 权限检查错误转向页面
- /// </summary>
- /// <param name="as_PowerType">1,没有浏览权;2,没有添加权 ; 3 没有修改权 4;没有删除权;
- /// 5,没有打印权; 7 页面权限编号信息错误</param>
- public static void NotPower(int as_PowerType)
- {
- NotPower(as_PowerType, "N");
- }
- public static void NotPower(PowerType poType)
- {
- string lcRetval = "您的权限低,无法操作!";
- switch (poType)
- {
- case PowerType.IsBrowse:
- lcRetval = "您没有【访问该页面】的权限,如有问题,请联系管理员!";
- break;
- case PowerType.IsAdd:
- lcRetval = "您没有【添加功能】的权限,如有问题,请联系管理员!";
- break;
- case PowerType.IsUpdate:
- lcRetval = "您没有【修改功能】的权限,如有问题,请联系管理员!";
- break;
- case PowerType.IsDelete:
- lcRetval = "您没有【删除功能】的权限,如有问题,请联系管理员!";
- break;
- case PowerType.IsAudit:
- lcRetval = "您没有【审核功能】的权限,如有问题,请联系管理员!";
- break;
- case PowerType.IsPrint:
- lcRetval = "您没有【打印功能】的权限,如有问题,请联系管理员!";
- break;
- }
- HttpContext.Current.Response.Write("$(function() {layer.alert('" + lcRetval + "', { title: '提示信息' })});");
- }
- /// <summary>
- /// 权限检查错误转向页面
- /// </summary>
- /// <param name="as_PowerType"> 1,没有浏览权;2,没有添加权 ; 3 没有修改权 4;没有删除权;
- /// 5,没有打印权; 7 页面权限编号信息错误</param>
- /// <param name="as_ReturnType">参数 C 关闭;R 重定向 ;P 上一页; U 指定页面 ;N 不显示</param>
- public static void NotPower(int as_PowerType, string as_ReturnType)
- {
- if (as_PowerType == 1) { ErrRedirect(-30000001, as_ReturnType); } //浏览
- if (as_PowerType == 2) { ErrRedirect(-30000002, as_ReturnType); } //添加
- if (as_PowerType == 3) { ErrRedirect(-30000003, as_ReturnType); } //修改
- if (as_PowerType == 4) { ErrRedirect(-30000004, as_ReturnType); } //删除
- if (as_PowerType == 5) { ErrRedirect(-30000005, as_ReturnType); } //打印
- if (as_PowerType == 5) { ErrRedirect(-30000006, as_ReturnType); } //审核
- if (as_PowerType == 6) { ErrRedirect(-311271, as_ReturnType); } //检查是否有浏览新增删除修改的权限
- if (as_PowerType == 7) { ErrRedirect(-30000008, as_ReturnType); } //页面权限编号信息错误
- if (as_PowerType == 8) { ErrRedirect(-30000007, as_ReturnType); } //页面权限编号信息错误
- }
- /// <summary>
- /// 操作错误 提示页面
- /// </summary>
- /// <param name="as_OperationType">1,为删除的行为空 ;2 编号为空 ;3 参数传递错误 </param>
- public static void OperationErr(int as_PowerType)
- {
- OperationErr(as_PowerType, "");
- }
- /// <summary>
- /// 操作错误 提示页面
- /// </summary>
- /// <param name="as_OperationType">1,为删除的行为空 ;2 编号为空 ;3 参数传递错误 </param>
- /// <param name="as_ReturnType"></param>
- public static void OperationErr(int as_OperationType, string as_ReturnType)
- {
- if (as_OperationType == 1) { ErrRedirect(-10000101, as_ReturnType); }
- if (as_OperationType == 2) { ErrRedirect(-10000102, as_ReturnType); }
- if (as_OperationType == 3) { ErrRedirect(-10000103, as_ReturnType); }
- }
- public static void ErrRedirect(int as_ErrorCode, string as_ReturnType)
- {
- string returnType;
- if (as_ReturnType.Trim().Length == 0)
- returnType = "C";
- else
- returnType = as_ReturnType;
- PageRedirect(as_ErrorCode, returnType);
- }
- public static void PageRedirect(int ErrorCode, string ReturnType)
- {
- HttpContext.Current.Response.Redirect("../Pub/PubShowMessage.aspx?al_ErrCode=" + ErrorCode.ToString() + "&as_ReturnType=" + ReturnType);
- }
- public static void PageAlert(int ErrorCode, string ReturnType)
- {
- HttpContext.Current.Response.Redirect("../Pub/PubShowMessage.aspx?al_ErrCode=" + ErrorCode.ToString() + "&as_ReturnType=" + ReturnType);
- }
- public static void LoginOut()
- {
- HttpContext.Current.Session.RemoveAll();
- System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>Form2.submit();</script>");
- System.Web.HttpContext.Current.Response.End();
- }
- #endregion
- }
- }
|