Esempio n. 1
0
 /// <summary>
 /// 验证权限(action执行前会先执行这里)
 /// </summary>
 /// <param name="filterContext"></param>
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     //如果存在身份信息
     if (!HttpContext.Current.User.Identity.IsAuthenticated)
     {
         ContentResult Content = new ContentResult();
         //Content.Content = string.Format("<script type='text/javascript'>alert('请先登录!');window.location.href='{0}';</script>", FormsAuthentication.LoginUrl);
         filterContext.Result = new RedirectResult("/");
     }
     else
     {
         string[] Role = new string[] { "member", "admin", "developer" }; //获取所有角色
         if (!Role.Contains(Code) || Code != GetUser())                   //验证权限
         {
             //验证不通过
             ContentResult Content = new ContentResult();
             DTError       error   = new DTError {
                 Message = "对不起,您没有权限访问该页面", Url = filterContext.HttpContext.Request.RawUrl
             };
             //filterContext.HttpContext.ExceptionHandled = true;
             filterContext.HttpContext.Session["error"] = error;
             filterContext.HttpContext.Session.Timeout  = 20;
             filterContext.Result = new RedirectResult("/Error/Show");
         }
         else
         {
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 异常
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnException(ExceptionContext filterContext)
        {
            //获取异常信息,入库保存
            Exception Error   = filterContext.Exception;
            string    Message = Error.Message;                      //错误信息
            string    Url     = HttpContext.Current.Request.RawUrl; //错误发生地址
            DTError   error   = new DTError {
                Message = Message, Url = Url
            };

            filterContext.ExceptionHandled             = true;
            filterContext.HttpContext.Session["error"] = error;
            filterContext.HttpContext.Session.Timeout  = 20;
            filterContext.Result = new RedirectResult("/Error/Show/");//跳转至错误提示页面
        }
        //
        // GET: /Error/

        public ActionResult Show()
        {
            DTError error = new DTError();

            if (Session["error"] != null)
            {
                error = (DTError)Session["error"];
            }
            else
            {
                error.Message = "未找到网页";
                error.Url     = "";
            }

            return(View(error));
        }
Esempio n. 4
0
        private void F_資料確認(IRow row, int i, int 起始欄)
        {
            string  StrError    = "";
            DataRow D_dataRow   = DTImportData.NewRow();
            DataRow D_erroraRow = DTError.NewRow();

            #region 基礎資料
            //D_dataRow[0] = str頁簽名稱;

            #endregion
            for (int j = 起始欄 - 1; j < DTDefine.Rows.Count; j++)
            {
                if (DTDefine.Rows[j]["IsUsing"].ToString() == "0")
                {
                    continue;
                }

                Boolean B是否為必要欄位;

                if (!Boolean.TryParse(DTDefine.Rows[j]["是否為必要欄位"].ToString(), out B是否為必要欄位))
                {
                    B是否為必要欄位 = false;
                }
                string Str資料格式 = "";
                Str資料格式 = DTDefine.Rows[j]["資料格式"].ToString();
                //必填沒有資料
                if (row.GetCell(j) == null)
                {
                    if (B是否為必要欄位)
                    {
                        StrError += FConvertError(DTDefine.Rows[j]["欄位名稱"].ToString(), i, StrError, j, "No Define");
                    }
                    else
                    {
                        D_dataRow[j] = "";
                    }
                }
                else
                {
                    switch (Str資料格式)
                    {
                    case "Varchar":
                    case "Nvarchar":
                        try
                        {
                            if (!string.IsNullOrEmpty(row.GetCell(j).ToString()))
                            {
                                D_dataRow[j] = row.GetCell(j).ToString().Trim();
                            }
                            else
                            {
                                if (B是否為必要欄位)
                                {
                                    StrError += FConvertError(DTDefine.Rows[j]["欄位名稱"].ToString(), i, StrError, j, "No Data");
                                }
                                else
                                {
                                    D_dataRow[j] = "";
                                }
                            }
                        }
                        catch (Exception)
                        {
                            StrError += FConvertError(DTDefine.Rows[j]["欄位名稱"].ToString(), i, StrError, j, "ImportError");
                        }
                        break;

                    case "Int":
                    case "Float":
                        try
                        {
                            if (row.GetCell(j).CellType == CellType.Numeric)
                            {
                                D_dataRow[j] = row.GetCell(j).NumericCellValue.ToString();
                            }
                            else if (row.GetCell(j).CellType == CellType.Formula)
                            {
                                D_dataRow[j] = row.GetCell(j).NumericCellValue.ToString();
                            }
                        }
                        catch (Exception)
                        {
                            if (B是否為必要欄位)
                            {
                                StrError += FConvertError(DTDefine.Rows[j]["欄位名稱"].ToString(), i, StrError, j, "int Error1");
                            }
                            else
                            {
                                D_dataRow[j] = "0";
                            }
                        }
                        break;

                    case "Datetime":
                        try
                        {
                            D_dataRow[j] = row.GetCell(j).DateCellValue.ToString("yyyy-MM-dd");
                        }
                        catch (Exception)
                        {
                            if (B是否為必要欄位)
                            {
                                StrError = FConvertError(DTDefine.Rows[j]["欄位名稱"].ToString(), i, StrError, j, "DateformatError");
                            }
                            else
                            {
                                D_dataRow[j] = "";
                            }
                        }
                        break;

                    default:
                        StrError += FConvertError(DTDefine.Rows[j]["欄位名稱"].ToString(), i, StrError, j, "No Define");
                        break;
                    }
                }
            }

            if (StrError.Length > 0)
            {
                D_erroraRow[0] = "Row " + i.ToString() + " " + StrError;
                DTError.Rows.Add(D_erroraRow);
            }
            else
            {
                DTImportData.Rows.Add(D_dataRow);
            }
        }