Example #1
0
        public ActionResult Edit([Bind(Include = "OrdemProducaoRefugoId,Produto,Data,UsuarioId,ProdIncio,ProdFim,Obs")] OrdemProducaoRefugo ordemProducaoRefugo)
        {
            var a = Request.Form["Material"];
            var b = Request.Form["Cor"];
            var c = Request.Form["EspecificacaoRefugo.Peso"];


            var e = Request.Form["ParadaRefugo.HoraParada"];
            var f = Request.Form["ParadaRefugo.HoraRetorno"];
            var g = Request.Form["Motivo"];
            var h = Request.Form["ParadaRefugo.Observacoes"];

            if (ModelState.IsValid)
            {
                var qtdOp       = 0;
                var mesAnterior = 0;
                if (db.OrdemProducaoRefugoes.Count() > 0)
                {
                    qtdOp       = db.OrdemProducaoRefugoes.ToList().Last().OPnoMes;
                    mesAnterior = db.OrdemProducaoRefugoes.ToList().Last().Data.Month;
                }
                else
                {
                    qtdOp       = 0;
                    mesAnterior = 0;
                }
                if (mesAnterior != ordemProducaoRefugo.Data.Month)
                {
                    ordemProducaoRefugo.OPnoMes = 1;
                }
                else
                {
                    ordemProducaoRefugo.OPnoMes = qtdOp + 1;
                }

                ordemProducaoRefugo.GerarCodigo();

                if (a != null)
                {
                    var           material = a.Split(',');
                    var           cor      = b.Split(',');
                    var           peso     = c.Split(',').Select(Double.Parse).ToArray();
                    List <string> d        = new List <string>(Request.Form.GetValues("EspecificacaoRefugo.Limpeza"));
                    d = ordemProducaoRefugo.RemoveExtraFalseFromCheckbox(d);
                    bool[] limpeza = d.Select(Boolean.Parse).ToArray();
                    for (int x = 0; x < material.Count(); x++)
                    {
                        EspecificacaoRefugo e1 = new EspecificacaoRefugo();
                        e1.Material = material[x];
                        e1.Cor      = cor[x];
                        e1.Peso     = peso[x];
                        e1.Limpeza  = limpeza[x];
                        e1.OrdemProducaoRefugoId = ordemProducaoRefugo.OrdemProducaoRefugoId;
                        db.EspecificacaoRefugoes.Add(e1);
                        db.SaveChanges();
                    }
                }

                if (e != null)
                {
                    var hrP = e.Split(',');
                    var hrR = f.Split(',');
                    var mot = g.Split(',');
                    var obs = h.Split(',');
                    for (int y = 0; y < hrP.Count(); y++)
                    {
                        ParadaRefugo p = new ParadaRefugo();
                        p.HoraParada            = hrP[y];
                        p.HoraRetorno           = hrR[y];
                        p.Motivo                = mot[y];
                        p.Observacoes           = obs[y];
                        p.OrdemProducaoRefugoId = ordemProducaoRefugo.OrdemProducaoRefugoId;
                        db.ParadaRefugoes.Add(p);
                        db.SaveChanges();
                    }
                }


                db.Entry(ordemProducaoRefugo).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.UsuarioId = new SelectList(db.Usuarios, "UsuarioId", "NomeUsuario", ordemProducaoRefugo.UsuarioId);
            return(View(ordemProducaoRefugo));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "OrdemProducaoRefugoId,Produto,Data,UsuarioId,ProdIncio,ProdFim,Obs")] OrdemProducaoRefugo ordemProducaoRefugo, bool Status)
        {
            var a = Request.Form["Material"];
            var b = Request.Form["Cor"];
            var c = Request.Form["EspecificacaoRefugo.Peso"];


            var e = Request.Form["ParadaRefugo.HoraParada"];
            var f = Request.Form["ParadaRefugo.HoraRetorno"];
            var g = Request.Form["Motivo"];
            var h = Request.Form["ParadaRefugo.Observacoes"];

            if (ModelState.IsValid)
            {
                if (a != null)
                {
                    var           material = a.Split(',');
                    var           cor      = b.Split(',');
                    var           peso     = c.Split(',').Select(Double.Parse).ToArray();
                    List <string> d        = new List <string>(Request.Form.GetValues("EspecificacaoRefugo.Limpeza"));
                    d = ordemProducaoRefugo.RemoveExtraFalseFromCheckbox(d);
                    bool[] limpeza = d.Select(Boolean.Parse).ToArray();
                    List <EspecificacaoRefugo> esp = new List <EspecificacaoRefugo>();
                    for (int x = 0; x < material.Count(); x++)
                    {
                        EspecificacaoRefugo e1 = new EspecificacaoRefugo();
                        e1.Material = material[x];
                        e1.Cor      = cor[x];
                        e1.Peso     = peso[x];
                        e1.Limpeza  = limpeza[x];
                        e1.OrdemProducaoRefugoId = ordemProducaoRefugo.OrdemProducaoRefugoId;
                        esp.Add(e1);
                    }
                    ordemProducaoRefugo.EspecificacoesRefugo = esp;
                }

                if (e != null)
                {
                    var hrP = e.Split(',');
                    var hrR = f.Split(',');
                    var mot = g.Split(',');
                    var obs = h.Split(',');
                    List <ParadaRefugo> parada = new List <ParadaRefugo>();
                    for (int y = 0; y < hrP.Count(); y++)
                    {
                        ParadaRefugo p = new ParadaRefugo();
                        p.HoraParada            = hrP[y];
                        p.HoraRetorno           = hrR[y];
                        p.Motivo                = mot[y];
                        p.Observacoes           = obs[y];
                        p.OrdemProducaoRefugoId = ordemProducaoRefugo.OrdemProducaoRefugoId;
                        parada.Add(p);
                    }
                    ordemProducaoRefugo.ParadasRefugo = parada;
                }

                db.OrdemProducaoRefugoes.Add(ordemProducaoRefugo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UsuarioId = new SelectList(db.Usuarios, "UsuarioId", "NomeUsuario", ordemProducaoRefugo.UsuarioId);
            return(View(ordemProducaoRefugo));
        }
        public ActionResult Create([Bind(Include = "OrdemProducaoRefugoId,Produto,Data,UsuarioId,ProdIncio,ProdFim,Obs")] OrdemProducaoRefugo ordemProducaoRefugo, bool Status)
        {
            ordemProducaoRefugo.Status = Status;
            var a = Request.Form["Material"];
            var b = Request.Form["Cor"];

            var e = Request.Form["ParadaRefugo.HoraParada"];
            var f = Request.Form["ParadaRefugo.HoraRetorno"];
            var g = Request.Form["Motivo"];
            var h = Request.Form["ParadaRefugo.Observacoes"];

            if (b == "")
            {
                ViewBag.C = "Preencha este campo!";
            }
            else
            {
                //if (ModelState.IsValid)
                //{

                var qtdOp       = 0;
                var mesAnterior = 0;
                if (db.OrdemProducaoRefugoes.Count() > 0)
                {
                    var qtdOps = db.OrdemProducaoRefugoes.Where(o => o.Data.Month == ordemProducaoRefugo.Data.Month && o.Data.Year == ordemProducaoRefugo.Data.Year).OrderBy(o => o.OPnoMes).ToList();
                    if (qtdOps.Count() > 0)
                    {
                        qtdOp = qtdOps.Last().OPnoMes;
                    }
                    else
                    {
                        qtdOp = 0;
                    }
                    mesAnterior = db.OrdemProducaoRefugoes.ToList().Last().Data.Month;
                }
                else
                {
                    qtdOp       = 0;
                    mesAnterior = 0;
                }

                /*if (mesAnterior != ordemProducaoRefugo.Data.Month)
                 * {
                 * ordemProducaoRefugo.OPnoMes = 1;
                 * }
                 * else*/
                ordemProducaoRefugo.OPnoMes = qtdOp + 1;

                ordemProducaoRefugo.GerarCodigo();
                if (a != null)
                {
                    var material = a.Split(',');
                    var cor      = b.Split(',').Select(Int32.Parse).ToArray();

                    List <string> c    = new List <string>(Request.Form.GetValues("EspecificacaoRefugo.Peso"));
                    var           peso = c.Select(Double.Parse).ToList();

                    List <string> d = new List <string>(Request.Form.GetValues("EspecificacaoRefugo.Limpeza"));
                    d = ordemProducaoRefugo.RemoveExtraFalseFromCheckbox(d);
                    bool[] limpeza = d.Select(Boolean.Parse).ToArray();
                    List <EspecificacaoRefugo> esp = new List <EspecificacaoRefugo>();
                    for (int x = 0; x < material.Count(); x++)
                    {
                        EspecificacaoRefugo e1 = new EspecificacaoRefugo();
                        e1.Material              = material[x];
                        e1.CorPecaId             = cor[x];
                        e1.Peso                  = peso[x];
                        e1.Limpeza               = limpeza[x];
                        e1.OrdemProducaoRefugoId = ordemProducaoRefugo.OrdemProducaoRefugoId;
                        esp.Add(e1);
                    }
                    ordemProducaoRefugo.EspecificacoesRefugo = esp;
                }

                if (e != null)
                {
                    var hrP = e.Split(',');
                    var hrR = f.Split(',');
                    var mot = g.Split(',');
                    var obs = h.Split(',');
                    List <ParadaRefugo> parada = new List <ParadaRefugo>();
                    for (int y = 0; y < hrP.Count(); y++)
                    {
                        ParadaRefugo p = new ParadaRefugo();
                        p.HoraParada            = hrP[y];
                        p.HoraRetorno           = hrR[y];
                        p.Motivo                = mot[y];
                        p.Observacoes           = obs[y];
                        p.OrdemProducaoRefugoId = ordemProducaoRefugo.OrdemProducaoRefugoId;
                        parada.Add(p);
                    }
                    ordemProducaoRefugo.ParadasRefugo = parada;
                }

                db.OrdemProducaoRefugoes.Add(ordemProducaoRefugo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
                //}
            }
            ViewBag.CorPecaId = db.CorPecas.ToList();
            ViewBag.UsuarioId = new SelectList(db.Usuarios, "UsuarioId", "NomeUsuario", ordemProducaoRefugo.UsuarioId);
            return(View(ordemProducaoRefugo));
        }