public ActionResult Edit([Bind(Include = "nrprest,matricula,conta,chave,sequencia,valor,valorcalculado,dtvencimento,dtpagamento,situacao,formapagamento,obs,ass")] Prestacoes prestacoes, string sequencia)
        {
            try
            {
                RemoveMascara(prestacoes, sequencia);
                prestacoes.Ass = "Registro editado em " + DateTime.Now.ToString() + " por: " + User.Identity.Name;

                if (ModelState.IsValid)
                {
                    db.Entry(prestacoes).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["success"] = "Prestação editada com sucesso";
                    return(RedirectToAction("Index"));
                }
                Dropdown(prestacoes);
                return(View());
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        // GET: Prestacoes/Create
        public ActionResult Create()
        {
            Prestacoes prest = new Prestacoes();

            prest.Sequencia    = DateTime.Now.ToString("yyyyMM");
            prest.DtVencimento = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 5);
            Dropdown();
            ViewBag.NrPrest = new SelectList(db.Prestacoes).Count() + 1;
            return(View(prest));
        }
        // GET: Prestacoes/Details/5
        public ActionResult Details(int?nrPrest)
        {
            if (nrPrest == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Prestacoes prestacoes = db.Prestacoes.Find(nrPrest);

            if (prestacoes == null)
            {
                return(HttpNotFound());
            }
            return(View(prestacoes));
        }
        public ActionResult Create([Bind(Include = "nrprest,matricula,conta,chave,sequencia,valor,valorcalculado,dtvencimento,dtpagamento,situacao,formapagamento,obs,ass")] Prestacoes prest, string sequencia)
        {
            try
            {
                RemoveMascara(prest, sequencia);

                if (ModelState.IsValid)
                {
                    if (Functions.ValidaPrestacao(prest.Matricula, prest.Conta, prest.Chave, prest.DtVencimento))
                    {
                        prest.Ass = "Registro criado em " + DateTime.Now.ToString() + " por: " + User.Identity.Name;
                        db.Prestacoes.Add(prest);
                        db.SaveChanges();
                        TempData["success"] = "Prestação criada com sucesso";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["warning"] = "Prestação já cadastrada";
                    }
                }
                Dropdown(prest);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            return(View(prest));
        }
 private void Dropdown(Prestacoes prestacoes)
 {
     ViewBag.Matricula      = new SelectList(db.Membros.Where(c => c.Inativo == false), "Matricula", "Nome", prestacoes.Matricula);
     ViewBag.FormaPagamento = new SelectList(db.FormaPagamento, "Tipo", "Descricao", prestacoes.FormaPagamento);
     ViewBag.Chave          = new SelectList(db.Chaves.Where(c => c.Inativo == false).Where(c => c.GeraConta == true), "Chave", "Chave", prestacoes.Chave);
     ViewBag.Conta          = new SelectList(db.Contas.Where(c => c.Inativo == false), "Conta", "TipoChave", prestacoes.Conta);
     ViewBag.Faccao         = new SelectList(db.Faccoes.Where(f => f.Inativo == false), "Chave", "Chave");
     ViewBag.Situacao       = new List <SelectListItem>
     {
         new SelectListItem {
             Text = "Em aberto", Value = "A"
         },
         new SelectListItem {
             Text = "Vencido", Value = "V"
         },
         new SelectListItem {
             Text = "Pago", Value = "P"
         },
         new SelectListItem {
             Text = "Anulada", Value = "N"
         }
     };
 }
        public ActionResult Delete(int nrPrest, FormCollection collection)
        {
            try
            {
                Prestacoes prestacoes = db.Prestacoes.Find(nrPrest);
                if (prestacoes.Situacao == "P")
                {
                    TempData["info"] = "Não é possível excluir uma prestação paga";
                }
                else
                {
                    db.Prestacoes.Remove(prestacoes);
                    db.SaveChanges();
                    TempData["success"] = "Prestação excluída com sucesso";
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #7
0
        /// <summary>
        /// Grava as prestações no banco de dados de acordo com o escopo do método CalculaPeriodoEVencimento.
        /// </summary>
        /// <param name="Matricula"></param>
        /// <param name="Conta"></param>
        /// <param name="Chave"></param>
        /// <param name="Faccao"></param>
        /// <param name="VencimentoInicial"></param>
        /// <param name="f"></param>
        /// <param name="where"></param>
        private void GravaPrestacoes(int?Matricula, string Conta, string Chave, string Faccao, DateTime VencimentoInicial, int f, string where, bool PorGraduacao)
        {
            using
            (
                var connection = new SqlConnection(Functions.Conexao())
            )
            {
                connection.Open();
                try
                {
                    var membros = connection
                                  .Query <Membros>("SELECT Matricula, Graduacao FROM Membros(NOLOCK) WHERE " + where + ";",
                                                   new { Fac = Faccao, Mat = Matricula });

                    foreach (dynamic matricula in membros)
                    {
                        string ChavePrest = PorGraduacao? matricula.Graduacao : Chave;

                        for (int i = 0; i <= f; i++)
                        {
                            Prestacoes prest = new Prestacoes
                            {
                                Matricula    = matricula.Matricula,
                                Conta        = Conta,
                                Chave        = ChavePrest,
                                Sequencia    = VencimentoInicial.AddMonths(i).ToString("yyyyMM"),
                                DtVencimento = VencimentoInicial.AddMonths(i),
                                Situacao     = "A",
                                Ass          = "Criada pela geração de prestações em: " + DateTime.Now.ToString() + " por: " + User.Identity.Name
                            };

                            bool valido = Functions.ValidaPrestacao(matricula.Matricula, Conta, Chave, prest.DtVencimento);

                            if (valido)
                            {
                                db.Prestacoes.Add(prest);
                                db.SaveChanges();
                            }
                            else
                            {
                                var cts = new CancellationTokenSource();
                                cts.Dispose();
                            }
                        }
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var eve in ex.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }
        }
 private static void RemoveMascara(Prestacoes prestacoes, string sequencia)
 {
     prestacoes.Sequencia = sequencia.Replace("/", string.Empty);
 }