示例#1
0
        public ActionResult CreateSave(BudgetCenter model, string returnUrl = "Index")
        {
            ViewBag.Path1 = "参数设置";
            if (ModelState.IsValid)
            {
                try
                {
                    db.BudgetCenter.Add(model);
                    db.PPSave();
                    Common.RMOk(this, "记录:'" + model.Name + "'新建成功!");
                    return(Redirect(Url.Content(returnUrl)));
                }
                catch (Exception e)
                {
                    if (e.InnerException.Message.Contains("Cannot insert duplicate key row"))
                    {
                        ModelState.AddModelError(string.Empty, "相同名称的记录已存在,保存失败!");
                    }
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            ViewBag.ReturnUrl = returnUrl;
            return(View("Create", model));
        }
示例#2
0
        public ActionResult EditSave(BudgetCenter model, string returnUrl = "Index")
        {
            ViewBag.Path1 = "参数设置";
            //检查记录在权限范围内
            var result = Common.GetHRAdminBudgetCenterQuery(db, WebSecurity.CurrentUserId).Where(a => a.Id == model.Id).SingleOrDefault();

            if (result == null)
            {
                Common.RMError(this);
                return(Redirect(Url.Content(returnUrl)));
            }
            //end

            if (ModelState.IsValid)
            {
                try
                {
                    result.Name = model.Name;
                    db.PPSave();
                    Common.RMOk(this, "记录:" + model + "保存成功!");
                    return(Redirect(Url.Content(returnUrl)));
                }
                catch (Exception e)
                {
                    if (e.InnerException.Message.Contains("Cannot insert duplicate key row"))
                    {
                        ModelState.AddModelError(string.Empty, "相同名称的记录已存在,保存失败!");
                    }
                }
            }
            ViewBag.ReturnUrl = returnUrl;

            return(View("Edit", model));
        }
示例#3
0
        public ActionResult RestoreSave(BudgetCenter record, string returnUrl = "Index")
        {
            ViewBag.Path1 = "参数设置";
            //检查记录在权限范围内
            var result = Common.GetHRAdminBudgetCenterQuery(db, WebSecurity.CurrentUserId, true).Where(a => a.IsDeleted == true).Where(a => a.Id == record.Id).SingleOrDefault();

            if (result == null)
            {
                Common.RMError(this);
                return(Redirect(Url.Content(returnUrl)));
            }
            //end

            try
            {
                result.IsDeleted = false;
                db.PPSave();
                Common.RMOk(this, "记录:" + result + "恢复成功!");
                return(Redirect(Url.Content(returnUrl)));
            }
            catch (Exception e)
            {
                Common.RMOk(this, "记录" + result + "恢复失败!" + e.ToString());
            }
            return(Redirect(Url.Content(returnUrl)));
        }
示例#4
0
        public ActionResult Index(int selectedMonth = 0, int selectedYear = 0)
        {
            BudgetCenter budgetCenter = new BudgetCenter();

            ViewBag.Months = new SelectList(Enumerable.Range(1, 12).Select(x => new SelectListItem()
            {
                Text  = CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedMonthNames[x - 1] + "(" + x + ")",
                Value = x.ToString()
            }), "Value", "Text");
            ViewBag.Years = new SelectList(Enumerable.Range(General.GetFirstTransactionYear(),
                                                            General.YearsToDisplay()).Select(x => new SelectListItem()
            {
                Text  = x.ToString(),
                Value = x.ToString()
            }), "Value", "Text");
            budgetCenter.SelectedMonth = selectedMonth == 0 ? DateTime.Now.Month :  selectedMonth;
            budgetCenter.SelectedYear  = selectedYear == 0 ? DateTime.Now.Year : selectedYear;
            budgetCenter.BudgetRows    = BuildRows(budgetCenter.SelectedMonth);

            //TODO figure out month int versus current date issue, use recurance day when applicable
            return(View(budgetCenter));
        }