//botao cancelar
        private void button1_Click(object sender, EventArgs e)
        {
            Encomendas encomendas = new Encomendas();

            this.Hide();
            encomendas.Show();
        }
Example #2
0
        public ActionResult Create([Bind(Include = "ID,Local_entrega,Preco,Estado,ClienteFK")] Encomendas encomendas)
        {
            if (Session["ac"] != "Encomendas/Create")
            {
                return(RedirectToAction("Index", "Encomendas"));
            }
            IList <Clientes> clienteslist = db.Clientes.ToList();

            foreach (Clientes c in clienteslist)
            {
                if (c.Username == User.Identity.Name)
                {
                    encomendas.ClienteFK = c.ID;
                }
            }

            if (ModelState.IsValid)
            {
                db.Encomendas.Add(encomendas);
                db.SaveChanges();
                return(RedirectToAction("Index", "Compras", new { id = encomendas.ID }));
            }

            ViewBag.ClienteFK = new SelectList(db.Clientes, "ID", "Nome", encomendas.ClienteFK);
            return(View(encomendas));
        }
        //Adicionar Encomenda
        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Encomenda adicionada com sucesso");
            Encomendas enc = new Encomendas();

            this.Hide();
            enc.Show();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Encomendas encomendas = db.Encomenda.Find(id);

            db.Encomenda.Remove(encomendas);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //botao adicionar artigos
        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Artigos adicionados com sucesso!");
            Encomendas encomendas = new Encomendas();

            this.Hide();
            encomendas.Show();
        }
Example #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Session["ac"] != "Encomendas/Delete" || (int)Session["id"] != id)
            {
                return(RedirectToAction("Index", "Encomendas"));
            }
            Encomendas encomendas = db.Encomendas.Find(id);

            db.Encomendas.Remove(encomendas);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "EncoId,Descricao,Status,Codigo,ApeId")] Encomendas encomendas)
 {
     if (ModelState.IsValid)
     {
         db.Entry(encomendas).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ApeId  = new SelectList(db.Apartamento, "ApeId", "NomeApe", encomendas.ApeId);
     ViewBag.Codigo = new SelectList(db.Usuarios, "Codigo", "Email", encomendas.Codigo);
     return(View(encomendas));
 }
 public ActionResult Edit([Bind(Include = "EncomendaID,LocalExpedicao,DataExpedicao,DonoFK,JornadaFK")] Encomendas encomendas)
 {
     if (ModelState.IsValid)
     {
         db.Entry(encomendas).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DonoFK    = new SelectList(db.Clientes, "ClienteID", "Nome", encomendas.DonoFK);
     ViewBag.JornadaFK = new SelectList(db.Jornadas, "JornadaID", "Descricao", encomendas.JornadaFK);
     return(View(encomendas));
 }
Example #9
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Encomendas encomendas = db.Encomendas.Find(id);

            if (encomendas == null)
            {
                return(HttpNotFound());
            }
            return(View(encomendas));
        }
Example #10
0
 public ActionResult Edit([Bind(Include = "ID,Local_entrega,Preco,Estado,ClienteFK")] Encomendas encomendas)
 {
     if (Session["ac"] != "Encomendas/Edit" || (int)Session["id"] != encomendas.ID)
     {
         return(RedirectToAction("Index", "Encomendas"));
     }
     if (ModelState.IsValid)
     {
         db.Entry(encomendas).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ClienteFK = new SelectList(db.Clientes, "ID", "Nome", encomendas.ClienteFK);
     return(View(encomendas));
 }
        public ActionResult SalvaEncomenda([Bind(Include = "EncoId,Descricao,Status,Codigo,ApeId,DataEntrega")] Encomendas encomendas, string data)
        {
            Porteiro usuario = AdminLar.Repositories.Funcoes.GetPorteiro();

            if (usuario != null)
            {
                encomendas.Status      = "Recebido";
                encomendas.ApeId       = usuario.ApeId;
                encomendas.DataEntrega = Convert.ToDateTime(data);
                db.Encomenda.Add(encomendas);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Encomendas"));
        }
        public ActionResult Cancela(string codigo)
        {
            Encomendas enc = db.Encomenda.Find(Convert.ToInt32(codigo));

            enc.Status = "Cancelado";

            db.Entry(enc).State = EntityState.Modified;


            if (db.SaveChanges() > 0)
            {
                return(Json(true));
            }

            return(Json(false));
        }
Example #13
0
        public ActionResult Delete(int?id)
        {
            Session["id"] = id;
            Session["ac"] = "Encomendas/Delete";
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Encomendas encomendas = db.Encomendas.Find(id);

            if (encomendas == null)
            {
                return(HttpNotFound());
            }
            return(View(encomendas));
        }
        // GET: Encomendas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Encomendas encomendas = db.Encomendas.Find(id);

            if (encomendas == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DonoFK    = new SelectList(db.Clientes, "ClienteID", "Nome", encomendas.DonoFK);
            ViewBag.JornadaFK = new SelectList(db.Jornadas, "JornadaID", "Descricao", encomendas.JornadaFK);
            return(View(encomendas));
        }
        // GET: Encomendas/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Encomendas encomendas = db.Encomenda.Find(id);

            if (encomendas == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ApeId  = new SelectList(db.Apartamento, "ApeId", "NomeApe", encomendas.ApeId);
            ViewBag.Codigo = new SelectList(db.Usuarios, "Codigo", "Email", encomendas.Codigo);
            return(View(encomendas));
        }
Example #16
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Encomendas encomendas = db.Encomendas.Find(id);

            if (encomendas == null)
            {
                return(HttpNotFound());
            }
            Session["id"]     = id;
            Session["ac"]     = "Encomendas/Edit";
            ViewBag.ClienteFK = new SelectList(db.Clientes, "ID", "Nome", encomendas.ClienteFK);
            return(View(encomendas));
        }
Example #17
0
        private void dgvEncomenda_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int EncomendaId = Convert.ToInt32(dgvEncomenda.Rows[e.RowIndex].Cells[indexColunaEncomendaId].Value);
            int ClienteId   = Convert.ToInt32(dgvEncomenda.Rows[e.RowIndex].Cells[indexColunaClienteId].Value);

            if (e.ColumnIndex == indexColunaEditar)
            {
                formEncomenda = new FormEncomenda(EncomendaId, ClienteId);
                formEncomenda.ShowDialog();
            }
            else if (e.ColumnIndex == indexColunaExcluir)
            {
                if (encomendaServico.Excluir(EncomendaId, ClienteId))
                {
                    MessageBox.Show("Encomenda excluída com sucesso.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Encomendas.RemoveAt(e.RowIndex);
                    AtualizarGridEncomendas();
                }
                else
                {
                    MessageBox.Show("Não foi possível excluir a encomenda.", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #18
0
        private void AtualizarGridEncomendas()
        {
            dgvEncomenda.DataSource = (from e in Encomendas
                                       select new
            {
                NomeCliente = cliente.Nome
                ,
                DataEntrega = e.DataEntregaPrevista
                ,
                Descricao = e.Descricao
                ,
                EncomendaId = e.Id
                ,
                ClienteId = cliente.Id
            }).ToList();

            if (Encomendas.Any())
            {
                dgvEncomenda.Columns["NomeCliente"].DisplayIndex     = 0;
                dgvEncomenda.Columns["DataEntregaPrev"].DisplayIndex = 1;
                dgvEncomenda.Columns["Descricao"].DisplayIndex       = 2;
                dgvEncomenda.Columns["Editar"].DisplayIndex          = 3;
            }
        }
        public async Task <IActionResult> Create([Bind("ID,MoradaEncomenda,MoradaFaturacao,")] Encomendas encomendas)
        {
            if (ModelState.IsValid)
            {
                var    funcionario = new Funcionarios();
                Random r           = new Random();
                do
                {
                    int id = r.Next(0, 100);
                    funcionario = await _context.Funcionarios
                                  .FirstOrDefaultAsync(m => m.ID == id);
                } while (funcionario == null);

                encomendas.GestorID = funcionario.ID;
                var Cliente = await _context.Clientes
                              .FirstOrDefaultAsync(m => m.UserId == _userManager.GetUserId(User));

                if (encomendas.MoradaEncomenda == null)
                {
                    encomendas.MoradaEncomenda = Cliente.Morada + " " + Cliente.CodigoPostal;
                }

                if (encomendas.MoradaFaturacao == null)
                {
                    encomendas.MoradaFaturacao = Cliente.Morada + " " + Cliente.CodigoPostal;
                }

                if (Cliente == null)
                {
                    return(NotFound());
                }
                try
                {
                    Guid     g    = Guid.NewGuid();
                    DateTime date = DateTime.Now;
                    var      week = date.DayOfWeek.ToString();
                    encomendas.ClientID        = Cliente.ID;
                    encomendas.TrackID         = g.ToString();
                    encomendas.EstadoEncomenda = "Em processamento";
                    encomendas.DataEncomenda   = date;
                    if (week == "Thursday" || week == "Friday")
                    {
                        encomendas.PrevisaoEntrega = date.AddDays(4);
                    }
                    else
                    {
                        encomendas.PrevisaoEntrega = date.AddDays(2);
                    }

                    _context.Add(encomendas);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Create", "DetalhesEncomendas"));
                }
                catch (Exception)
                {
                    return(View(encomendas));
                }
            }
            return(View());
        }