Exemple #1
0
        public void FundsAddtoFunds(double amount, string location)
        {
            // Get old amount
            double oldAmount = 0;
            string sql       = "SELECT * FROM Funds";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand(sql, connection);

                connection.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    oldAmount = (double)rdr["Concessions"];
                }
            }
            // Get old amount

            // Get new amount
            double newAmount = oldAmount + amount;

            // Update new amount
            FundsModel funds = new FundsModel();

            funds.Concessions = newAmount;
            FundsUpdate(funds, location);
        }
Exemple #2
0
        public ActionResult FundsView()
        {
            string sql = "SELECT * FROM Funds";

            var model = new FundsModel();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand(sql, connection);

                connection.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    var item = new FundsModel();
                    item.id          = (int)rdr["Id"];
                    item.Concessions = (double)rdr["Concessions"];
                    item.BITS        = (double)rdr["BITS"];
                    item.Equipment   = (double)rdr["Equipment"];
                    item.Space       = (double)rdr["Space"];
                    model            = item;
                }
            }
            return(View(model));
        }
Exemple #3
0
        public ActionResult FundsUpdateSpaceView(double funds)
        {
            var model = new FundsModel();

            model.Space = funds;

            return(View(model));
        }
Exemple #4
0
        public ActionResult FundsUpdateEquipmentView(double funds)
        {
            var model = new FundsModel();

            model.Equipment = funds;

            return(View(model));
        }
Exemple #5
0
        public ActionResult FundsUpdateConcesssionsView(double funds)
        {
            var model = new FundsModel();

            model.Concessions = funds;

            return(View(model));
        }
            public async Task Returns_Created_With_Valid_Request(
                CreateDebitCommand command,
                FundsModel model,
                [Frozen] Mock <IMediator> mediator,
                AccountsController sut)
            {
                mediator.Setup(p => p.Send(It.IsAny <IRequest <FundsModel> >(), It.IsAny <CancellationToken>())).ReturnsAsync(model);

                var message = await sut.PostDebit(command) as OkObjectResult;

                Assert.True(message != null);
                Assert.True(message.StatusCode == 200);
                Assert.True((FundsModel)message.Value == model);
            }
Exemple #7
0
        public ActionResult Create([Bind(Include = "code,name,source,amount,balance,processId,info,state")] FundsModel funds)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "添加经费", "经费管理"))
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
            }
            SetSelect();
            if (ModelState.IsValid)
            {
                if (db.Funds.Where(x => x.f_code == funds.code).Count() > 0)
                {
                    ViewBag.msg = "该代码已被使用";
                    return(View(funds));
                }
                if (db.Funds.Where(x => x.f_name == funds.name).Count() > 0)
                {
                    ViewBag.msg = "该名称已被使用";
                    return(View(funds));
                }
                //if (funds.processId == null || funds.processId == 0)
                //{
                //    ViewBag.msg = "未选择批复流程。";
                //    return View(funds);
                //}
                if (funds.amount == 0)
                {
                    ViewBag.msg = "请设置经费总额。";
                    return(View(funds));
                }
                Funds model = new Funds();
                funds.toDBModel(model);
                model.f_manager = user;
                db.Funds.Add(model);
                db.SaveChanges();
                SysLog.WriteLog(user, string.Format("经费添加[{0}]", model.f_code), IpHelper.GetIP(), model.f_id.ToString(), 6, "", db);
                ViewBag.msg = "经费添加成功。";
            }

            return(View(funds));
        }
Exemple #8
0
        public IActionResult List(int pageSize = 0, int pageIndex = 0)
        {
            try
            {
                FundsModel model = new FundsModel();
                //pageSize = pageSize == 0 ? _configuration.GetValue<int>("PagingConfig:PageSize") : pageSize;
                //pageIndex = pageIndex == 0 ? 1 : pageIndex;

                ViewBag.SearchFundsModel = new SearchFund();

                model.Funds = _fundService.GetFunds(pageSize, pageIndex)?.ToList();

                return(View(model));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Exemple #9
0
        // GET: FundsManager/Edit/5
        public ActionResult Edit(int?id)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "添加经费", "经费管理"))
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
            }
            SetSelect();
            FundsModel funds = (from f in db.Funds
                                where f.f_id == (int)id
                                select new FundsModel
            {
                amount = f.f_amount,
                id = f.f_id,
                balance = f.f_balance,
                info = f.f_info,
                manager = f.f_manager,
                name = f.f_name,
                source = f.f_source,
                state = f.f_state,
                code = f.f_code
            }).FirstOrDefault();

            if (funds == null)
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有找到该经费。" }));
            }
            if (user != funds.manager && !RoleCheck.CheckHasAuthority(user, db, "经费管理"))
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有对该经费的管理权限。" }));
            }
            return(View(funds));
        }
Exemple #10
0
        public ActionResult Edit([Bind(Include = "id,code,name,expireDate,source,amount,balance,info,state")] FundsModel funds)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToRoute(new { controller = "Login", action = "LogOut" }));
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            if (!RoleCheck.CheckHasAuthority(user, db, "添加经费", "经费管理"))
            {
                return(RedirectToRoute(new { controller = "Error", action = "Index", err = "没有权限。" }));
            }
            SetSelect();
            if (ModelState.IsValid)
            {
                Funds model = db.Funds.Find(funds.id);
                if (funds == null)
                {
                    ViewBag.msg = "没有找到该经费。";
                    return(View(funds));
                }
                if (user != model.f_manager && !RoleCheck.CheckHasAuthority(user, db, "经费管理"))
                {
                    ViewBag.msg = "您不是该经费的管理员,没有更改权限。";
                    return(View(funds));
                }
                if (model.f_name != funds.name)
                {
                    if (db.Funds.Where(x => x.f_name == funds.name && x.f_id != funds.id).Count() > 0)
                    {
                        ViewBag.msg = "该名称已被使用";
                        return(View(funds));
                    }
                }
                if (model.f_code != funds.code)
                {
                    if (db.Funds.Where(x => x.f_code == funds.code && x.f_id != funds.id).Count() > 0)
                    {
                        ViewBag.msg = "该代码已被使用";
                        return(View(funds));
                    }
                }
                if (funds.amount == 0)
                {
                    ViewBag.msg = "请输入经费总额。";
                    return(View(funds));
                }
                if (funds.balance == null || funds.balance == 0)
                {
                    //自动设置余额
                    decimal usedfunds = (from fs in db.Funds
                                         join bill in db.Reimbursement
                                         on fs.f_id equals bill.r_funds_id
                                         join u in db.User_Info
                                         on fs.f_manager equals u.user_id into T1
                                         from t1 in T1.DefaultIfEmpty()
                                         where fs.f_id == funds.id && bill.r_add_user_id == user && bill.r_bill_state == 1
                                         select bill.r_fact_amount).DefaultIfEmpty(0).Sum();
                    if (usedfunds > 0)
                    {
                        funds.balance = funds.amount - usedfunds;
                    }
                    if (funds.balance < 0)
                    {
                        ViewBag.msg = "出错:当前设置的经费总额小于已使用的经费总额。";
                        return(View(funds));
                    }
                }
                funds.toDBModel(model);
                db.Entry(model).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                    SysLog.WriteLog(user, string.Format("经费修改[{0}]", model.f_code), IpHelper.GetIP(), model.f_id.ToString(), 6, "", db);
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder errors = new StringBuilder();
                    IEnumerable <DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
                    foreach (DbEntityValidationResult result in validationResult)
                    {
                        ICollection <DbValidationError> validationError = result.ValidationErrors;
                        foreach (DbValidationError err in validationError)
                        {
                            errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
                        }
                    }
                    ErrorUnit.WriteErrorLog(errors.ToString(), this.GetType().Name);
                    ViewBag.msg = " 经费信息更新失败。";
                    return(View(funds));
                }
                ViewBag.msg = "经费信息修改成功。";
            }
            return(View(funds));
        }
Exemple #11
0
        public ActionResult FundsUpdate(FundsModel funds, string location)
        {
            string queryString3 = "";
            string queryString2 = "";
            string queryString1 = "";
            bool   success      = true;
            double amount       = 0;

            if (location == "Concessions")
            {
                amount       = funds.Concessions;
                queryString2 = "UPDATE Funds SET Concessions = @Amount WHERE Id = 1";
            }

            else if (location == "Equipment")
            {
                amount       = funds.Equipment;
                queryString2 = "UPDATE Funds SET Equipment = @Amount WHERE Id = 1";
            }

            else if (location == "Space")
            {
                amount       = funds.Space;
                queryString2 = "UPDATE Funds SET Space = @Amount WHERE Id = 1";
            }

            //this is the SQL statement to update our item amount. @itemAmount and @itemName are replaced using the function following
            if (amount > 0)
            {
                queryString1 = "SELECT * FROM Funds";
                queryString3 = "UPDATE Funds SET BITS += @difference WHERE Id = 1";
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    //here is where we connect to the database and perform the SQL command
                    SqlCommand command = new SqlCommand(queryString1, connection);

                    //thesee statements replace the @itemName and @itemAmount in the queryString with their appropriate variables


                    //basically a test to make sure it worked, and catch exception
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = command.ExecuteReader();
                        reader.Read();
                        double current = (double)reader[location];
                        double difference;
                        difference = current - amount;
                        connection.Close();
                        connection.Open();
                        command.CommandText = queryString3;
                        command.Parameters.Add("@difference", System.Data.SqlDbType.Float).Value = difference;
                        command.ExecuteNonQuery();
                        connection.Close();
                        connection.Open();
                        command.CommandText = queryString2;
                        command.Parameters.Add("@Amount", System.Data.SqlDbType.Float).Value = amount;
                        command.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                success = true;
            }
            else
            {
                success = false;
            }

            FundsView();
            return(View("FundsView"));
        }