示例#1
0
        public ActionResult Edit(Coletor coletor)
        {
            //TODO: melhorar exceção quando algum dos campos obrigatórios não for preenchido

            if (ModelState.IsValid)
            {
                try
                {
                    var coletorAntigo = db.Coletores.Find(coletor.id);

                    coletorAntigo.nome = coletor.nome;

                    TryUpdateModel(coletorAntigo);

                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                }
            }

            return(View());
        }
示例#2
0
        public IHttpActionResult Put(int id, [FromBody] Coletor coletor)
        {
            try
            {
                var coletorDB = _repository.GetByID(id);

                if (coletorDB == null)
                {
                    return(NotFound());
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Verificar campos obrigatórios"));
                }

                coletorDB.Codigo      = coletor.Codigo;
                coletorDB.NumeroSerie = coletor.NumeroSerie;
                coletorDB.Marca       = coletor.Marca;
                coletorDB.Modelo      = coletor.Modelo;
                coletorDB.Nome        = coletor.Nome;

                _repository.Update(coletorDB);

                return(Ok(coletorDB));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#3
0
        //
        public JsonResult ExcluiMaquinaPost(int idmaquina)
        {
            string ret = string.Empty;

            try
            {
                Maquina maquina = db.Maquina.Where(a => a.ID == idmaquina).FirstOrDefault();
                db.Entry(maquina).State = EntityState.Deleted;
                Coletor oColetor = db.Coletor.Where(a => a.Id_Maquina == idmaquina).FirstOrDefault();
                //
                if (oColetor != null)
                {
                    oColetor.Id_Maquina      = null;
                    db.Entry(oColetor).State = EntityState.Modified;
                }
                //
                db.SaveChanges();
                ret = "ok";
            }
            catch (Exception exc)
            {
                ret = exc.Message;
            }

            return(Json(new { ret, results = 0, success = true }, JsonRequestBehavior.AllowGet));
        }
        public async void Dialog_AddRomaneio()
        {
            var view = new Dialog_AddRomaneio {
                DataContext = this
            };

            var result = await DialogHost.Show(view, "RootDialog", ClosingEventHandler);

            var path = @"F:\SOF\VDWIN\EXP\PEDIDOS.CSV";

            if (Environment.MachineName == "ATAIDE-PC")
            {
                path = @"C:\Users\krekm\Desktop\PEDIDOS.CSV";
            }

            using (var context = new ColinfoContext())
            {
                var NumRom = ToRomaneio();

                var rom = Coletor.GetRomaneio(path, NumRom);

                if (rom != null)
                {
                    Application.Current.Dispatcher.Invoke(delegate
                    {
                        Arquivos.Add(rom);
                    });
                    ConsultaCadastros(rom);
                }
            }
        }
        private void fswTXT_Created(object sender, FileSystemEventArgs e)
        {
            var       NumberOfRetries = 3000;
            const int DelayOnRetry    = 10;

            for (var i = 1; i <= NumberOfRetries; ++i)
            {
                try
                {
                    var vnd = Coletor.getArquivo(e.FullPath, e.Name);
                    File.Delete(e.FullPath);

                    if (vnd != null)
                    {
                        //AddArquivo(vnd);
                        Application.Current.Dispatcher.Invoke(delegate
                        {
                            Arquivos.Add(vnd);
                        });
                        ConsultaCadastros(vnd);
                    }
                    break;
                }
                catch (IOException)
                {
                    if (i == NumberOfRetries)
                    {
                        throw;
                    }

                    Thread.Sleep(DelayOnRetry);
                }
            }
        }
示例#6
0
        //
        public JsonResult PegaColetorMaquina(int idmaquina, int idempresa)
        {
            string  data     = string.Empty;
            int     id       = 0;
            string  desc     = string.Empty;
            Coletor oColetor = new Coletor();

            //
            try
            {
                if (idempresa > 0)
                {
                    oColetor = db.Coletor.Where(a => a.Maquina.Id_Empresa == idempresa && a.Id_Maquina == idmaquina).FirstOrDefault();
                    //
                    if (oColetor != null)
                    {
                        desc = oColetor.Descricao;
                        id   = oColetor.Id;
                    }
                    data = "ok";
                }
            }
            catch (Exception exc)
            {
                data = "nok";
            }
            //
            return(Json(new { data = data, desc = desc, id = id, results = 0, success = true }, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public static void Test()
        {
            var items = Coletor.GetPedidos(@"C:\Users\krekm\Desktop\PEDIDOS.CSV", DateTime.Now)
                        .Where(x => x.CodVendedor == 307)
                        .SelectMany(it => it.Items);

            var result = items
                         .GroupBy(l => l.Produto)
                         .Select(cl => new Item()
            {
                Produto    = cl.First().Produto,
                QntCX      = cl.Sum(c => c.QntCX),
                ValorTotal = cl.Sum(c => c.ValorTotal),
            })
                         .OrderByDescending(x => x.ValorTotal)
                         .ToList();

            var best2 = result.FindAll(Tools.FindItem);

            foreach (var v in result)
            {
                var res = $"{v.QntCX} | {v.Produto} | {v.ValorTotal}";
                Console.WriteLine(res);
            }

            Console.WriteLine($"Best 2: {best2.Count()}");

            foreach (var v in best2)
            {
                var res = $"{v.QntCX} | {v.Produto} | {v.ValorTotal}";
                Console.WriteLine(res);
            }
        }
示例#8
0
 public void Update(Coletor coletor)
 {
     using (var ctx = new Context.Context())
     {
         ctx.Entry(coletor).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
示例#9
0
        public void Insert(Coletor coletor)
        {
            using (var ctx = new Context.Context())
            {
                ctx.Coletores.Add(coletor);

                ctx.SaveChanges();
            }
        }
        public ActionResult LerArquivoDePostagens()
        {
            HttpPostedFileBase arquivo = Request.Files["MeuArquivo"];

            Coletor c = new Coletor();
            var     listaPostagens = c.LerPostagensDoArquivo(arquivo.InputStream);

            return(View("Index", listaPostagens));
        }
        //
        public void ValidaAlertas(Coletor coletor, string valorenviado)
        {
            List <ColetorAlerta> lista_alertas = coletor.ColetorAlerta.Where(x => x.Ativo.Value == 1).ToList();

            //
            foreach (ColetorAlerta alerta in lista_alertas)
            {
                int    iregra        = alerta.Regra.HasValue ? alerta.Regra.Value : 0;
                double dvalorenviado = Convert.ToDouble(valorenviado) / 10;
                //
                if (alerta.Valor.IndexOf(".") > -1)
                {
                    alerta.Valor = alerta.Valor.Replace(".", ",");
                }
                double dvalor_regra = Convert.ToDouble(alerta.Valor);
                //
                switch (iregra)
                {
                case 1:     // Maior
                    if (dvalorenviado > dvalor_regra)
                    {
                        CriaLogAlerta(coletor.Id, alerta.Id, (Convert.ToDouble(dvalor_regra)).ToString(), (Convert.ToDouble(dvalorenviado)).ToString());
                    }
                    break;

                case 2:     // Menor
                    if (dvalorenviado < dvalor_regra)
                    {
                        CriaLogAlerta(coletor.Id, alerta.Id, (Convert.ToDouble(dvalor_regra)).ToString(), (Convert.ToDouble(dvalorenviado)).ToString());
                    }
                    break;

                case 3:     // Igual
                    if (dvalorenviado == dvalor_regra)
                    {
                        CriaLogAlerta(coletor.Id, alerta.Id, (Convert.ToDouble(dvalor_regra)).ToString(), (Convert.ToDouble(dvalorenviado)).ToString());
                    }
                    break;

                case 4:     // Maior ou Igual
                    if (dvalorenviado >= dvalor_regra)
                    {
                        CriaLogAlerta(coletor.Id, alerta.Id, (Convert.ToDouble(dvalor_regra)).ToString(), (Convert.ToDouble(dvalorenviado)).ToString());
                    }
                    break;

                case 5:     // Menor ou Igual
                    if (dvalorenviado <= dvalor_regra)
                    {
                        CriaLogAlerta(coletor.Id, alerta.Id, (Convert.ToDouble(dvalor_regra)).ToString(), (Convert.ToDouble(dvalorenviado)).ToString());
                    }
                    break;
                }
            }
        }
示例#12
0
        public Coletor GetByID(int id)
        {
            Coletor coletor = null;

            using (var ctx = new Context.Context())
            {
                coletor = ctx.Coletores.Where(x => x.DataExclusao == null && x.ID == id).SingleOrDefault();
            }

            return(coletor);
        }
示例#13
0
        public void AtualizaProdutos()
        {
            var path = @"F:\SOF\VDWIN\EXP\PRODUTOS.CSV";

            if (Environment.MachineName == "ATAIDE-PC")
            {
                path = @"C:\Users\krekm\Desktop\PRODUTOS.CSV";
            }

            Coletor.GetProdutos(path);
        }
示例#14
0
        public ActionResult Create(Coletor coletor)
        {
            if (ModelState.IsValid)
            {
                db.Coletores.Add(coletor);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(coletor));
        }
示例#15
0
        public IHttpActionResult Post([FromBody] Coletor coletor)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Verificar campos obrigatórios"));
                }

                _repository.Insert(coletor);

                return(Ok(coletor));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#16
0
        public JsonResult RelatorioMaquina(int idempresa, string lista_ids, int periodo)
        {
            string  sreult       = string.Empty;
            string  sFileName    = string.Empty;
            Empresa empresaLista = null;
            //
            List <EmpresaRelatorioModel> lista_empresa_model       = new List <EmpresaRelatorioModel>();
            List <ColetorAlerta>         lista_coletoralerta_model = new List <ColetorAlerta>();
            List <ColetorAlertaLog>      lista_coletor_alerta_log  = new List <ColetorAlertaLog>();
            //
            List <ColetorAlertaModel>      lista_coletor_alerta_item_model  = new List <ColetorAlertaModel>();
            List <ColetorAlertaLogModel>   lista_coletor_alerta_log_model   = new List <ColetorAlertaLogModel>();
            List <MaquinaItensReportModel> lista_maquina_itens_report_model = new List <MaquinaItensReportModel>();

            //
            empresaLista = db.Empresa.Where(x => x.Id == idempresa).FirstOrDefault();
            //
            if (empresaLista != null)
            {
                EmpresaRelatorioModel tmp = new EmpresaRelatorioModel();
                //
                tmp.Id           = empresaLista.Id;
                tmp.Nome         = empresaLista.Nome;
                tmp.Numero       = empresaLista.Numero;
                tmp.Telefone     = empresaLista.Telefone;
                tmp.Site         = empresaLista.Site;
                tmp.EstadoSigla  = PegaEstadoSigla(empresaLista.Estado);
                tmp.Endereco     = empresaLista.Endereco;
                tmp.CEP          = empresaLista.CEP;
                tmp.Cidade       = empresaLista.Cidade;
                tmp.NomeFantasia = empresaLista.NomeFantasia;
                tmp.Email        = empresaLista.Email;
                tmp.Bairro       = empresaLista.Bairro;
                lista_empresa_model.Add(tmp);
            }
            //
            string[] lista_ids_maquinas = lista_ids.Split(',');
            for (int i = 0; i < lista_ids_maquinas.Length; i++)
            {
                int     idmaquina = Convert.ToInt32(lista_ids_maquinas[i]);
                Coletor coletor   = db.Coletor.Where(x => x.Maquina != null && x.Maquina.ID == idmaquina).FirstOrDefault();
                //
                if (coletor != null)
                {
                    MaquinaItensReportModel mirm = new MaquinaItensReportModel();
                    //
                    mirm.DescricaoColetor = coletor.Descricao;
                    mirm.DescricaoMaquina = coletor.Maquina.Descricao;
                    //
                    lista_maquina_itens_report_model.Add(mirm);
                    //
                    lista_coletoralerta_model = db.ColetorAlerta.Where(x => x.Id_Coletor == coletor.Id).ToList();
                    foreach (ColetorAlerta item in lista_coletoralerta_model)
                    {
                        ColetorAlertaModel cam = new ColetorAlertaModel();
                        //
                        cam.Id               = item.Id;
                        cam.Id_Empresa       = item.Id_Empresa;
                        cam.Id_Coletor       = item.Id_Coletor;
                        cam.Id_TipoAlerta    = item.Id_TipoAlerta;
                        cam.Prioridade       = item.Prioridade.HasValue ? item.Prioridade.Value : 0;
                        cam.DescricaoColetor = "";
                        cam.Descricao        = item.Descricao;
                        cam.Email            = item.Email;
                        switch (item.ColetorTipoAlerta.Tipo.Value)
                        {
                        case 1:
                            cam.DescricaoTipoAlerta = "Temperatura";
                            break;

                        case 2:
                            cam.DescricaoTipoAlerta = "Pressão";
                            break;

                        case 3:
                            cam.DescricaoTipoAlerta = "Produção";
                            break;
                        }
                        cam.AtivoDescricao = item.Ativo.Value == 1 ? "Sim" : "Não";
                        //
                        cam.Ativo          = item.Ativo.Value;
                        cam.Valor          = item.Valor;
                        cam.Regra          = item.Regra.Value;
                        cam.AtivoDescricao = "";
                        cam.Prioridade     = 0;
                        //
                        lista_coletor_alerta_item_model.Add(cam);
                    }
                    //
                }
            }
            //
            ReportDocument oRelatorioMaquina              = null;
            ReportDocument oRelatorioMaquinaItem          = null;
            ReportDocument oRelatorioMaquinaItemAlerta    = null;
            ReportDocument oRelatorioMaquinaItemLogAlerta = null;

            //
            try
            {
                oRelatorioMaquina              = new ReportDocument();
                oRelatorioMaquinaItem          = new ReportDocument();
                oRelatorioMaquinaItemAlerta    = new ReportDocument();
                oRelatorioMaquinaItemLogAlerta = new ReportDocument();
                oRelatorioMaquina              = new ReportDocument();
                //
                string local = AppDomain.CurrentDomain.BaseDirectory + "Temp";
                sFileName = "Relatório_Máquinas" + DateTime.Today.ToShortDateString() + "_" + DateTime.Now.ToLongTimeString() + "_.pdf";
                sFileName = sFileName.Replace("/", "-");
                sFileName = sFileName.Replace("\\", "-");
                sFileName = sFileName.Replace(":", "-");
                //
                oRelatorioMaquina.Load(System.Web.HttpContext.Current.Server.MapPath("~/Relatorio/") + "RelatorioMaquinaTemp.rpt");
                oRelatorioMaquina.SetDataSource(lista_empresa_model);
                oRelatorioMaquina.Database.Tables[0].SetDataSource(lista_empresa_model);
                //oRelatorioMaquina.Subreports["RelatorioMaquinaItem.rpt"].Database.Tables[0].SetDataSource(lista_maquina_itens_report_model);
                ////
                //oRelatorioMaquinaItemAlerta.Load(System.Web.HttpContext.Current.Server.MapPath("~/Relatorio/") + "RelatorioMaquinaItemAlerta.rpt");
                //oRelatorioMaquinaItemAlerta.SetDataSource(lista_coletor_alerta_item_model);
                //oRelatorioMaquinaItemAlerta.Database.Tables[0].SetDataSource(lista_coletor_alerta_item_model);
                //
                //oRelatorioMaquinaItem.Load(System.Web.HttpContext.Current.Server.MapPath("~/Relatorio/") + "RelatorioMaquinaItem.rpt");
                //oRelatorioMaquinaItem.SetDataSource(lista_maquina_itens_report_model);
                //oRelatorioMaquinaItem.Database.Tables[0].SetDataSource(lista_maquina_itens_report_model);
                //oRelatorioMaquinaItem.Subreports["RelatorioMaquinaItemAlerta.rpt"].Database.Tables[0].SetDataSource(lista_coletor_alerta_item_model);
                //

                //

                //

                //
                oRelatorioMaquina.ExportToDisk(ExportFormatType.PortableDocFormat, local + "\\" + sFileName);
                //
                oRelatorioMaquinaItemAlerta.Close();
                oRelatorioMaquina.Close();
                oRelatorioMaquinaItem.Close();
                //
                oRelatorioMaquinaItemAlerta.Dispose();
                oRelatorioMaquina.Dispose();
                oRelatorioMaquinaItem.Dispose();
                //
                System.GC.Collect();
                sreult = "ok";
            }
            catch (Exception exc)
            {
                //Utils.Utils.Log.GravaLogExc(exc);
                sFileName = "Erro: " + exc.Message;
                sreult    = "nok";
            }
            //
            return(Json(new
            {
                data = sFileName,
                sreult,
                results = lista_empresa_model.Count(),
                success = true,
                errors = String.Empty
            }, JsonRequestBehavior.AllowGet));
        }
示例#17
0
 public async Task Edit(Coletor coleteor)
 {
     _context.Update(coleteor);
     await _context.SaveChangesAsync();
 }
示例#18
0
        //
        public JsonResult MaquinaPost(string descricao, int id_coletor, int id_maquina, int id_empresa_nova, int id_empresa_ant)
        {
            string ret  = string.Empty;
            string erro = string.Empty;

            //
            try
            {
                Maquina mm = new Maquina();
                //
                if (id_maquina > 0)
                {
                    mm = db.Maquina.Where(a => a.Id_Empresa == id_empresa_ant && a.ID == id_maquina).FirstOrDefault();
                    //
                    if (mm != null)
                    {
                        mm.Id_Empresa      = id_empresa_nova;
                        mm.Descricao       = descricao;
                        db.Entry(mm).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        ret = "Máquina não encontrada: Empresa (" + id_empresa_ant + ") - Máquina (" + id_maquina + ")";
                    }
                }
                else
                {
                    mm.Descricao  = descricao;
                    mm.Id_Empresa = id_empresa_nova;
                    db.Maquina.Add(mm);
                    db.SaveChanges();
                    db.Entry(mm).Reload();
                }
                //
                try
                {
                    Coletor coletor_temp = db.Coletor.Where(a => a.Id_Maquina == mm.ID && a.Id_Empresa == id_empresa_ant).FirstOrDefault();
                    //
                    if (coletor_temp != null)
                    {
                        coletor_temp.Id_Maquina      = null;
                        db.Entry(coletor_temp).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    //
                    if (id_coletor > 0) // 0 = N/A não se aplica
                    {
                        Coletor oColetor = null;

                        if (id_empresa_nova == id_empresa_ant)
                        {
                            oColetor = db.Coletor.Where(a => a.Id == id_coletor && a.Id_Empresa == id_empresa_ant).FirstOrDefault();
                        }
                        else
                        {
                            oColetor = db.Coletor.Where(a => a.Id == id_coletor && a.Id_Empresa == id_empresa_nova).FirstOrDefault();
                        }
                        //
                        if (oColetor != null)
                        {
                            oColetor.Id_Maquina      = mm.ID;
                            db.Entry(oColetor).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                    //
                    ret = "ok";
                }
                catch (Exception exc3)
                {
                    erro = exc3.Message;
                    ret  = "nok";
                }
            }
            catch (Exception exc)
            {
                erro = exc.Message;
                ret  = "nok";
            }
            //
            return(Json(new { ret, results = 0, success = true, erro }, JsonRequestBehavior.AllowGet));
        }
示例#19
0
        //
        public JsonResult PegaLogAtividade(string list_emp, string lista_ids, bool chkmaq, bool chkpress, bool chktemp, bool chkprod, int totreg)
        {
            string ret  = string.Empty;
            string erro = string.Empty;
            List <LogAtividadeModel> lista_retorno = new List <LogAtividadeModel>();

            //
            try
            {
                string[] lista_maquina_id = lista_ids.Split(',');
                string[] lista_empresa_id = list_emp.Split(',');
                //
                for (int i = 0; i < lista_maquina_id.Length; i++)
                {
                    int idmaquina = Convert.ToInt32(lista_maquina_id[i]);
                    int idempresa = Convert.ToInt32(lista_empresa_id[i]);
                    //
                    Maquina maq = db.Maquina.Where(x => x.ID == idmaquina && x.Id_Empresa == idempresa).FirstOrDefault();
                    //
                    if (maq != null)
                    {
                        Coletor col = db.Coletor.Where(x => x.Id_Empresa == idempresa && x.Id_Maquina == idmaquina).FirstOrDefault();
                        //
                        if (col != null)
                        {
                            string iddispositivo = col.MAC;
                            //
                            if (chkmaq)
                            {
                                List <LogAtividade> lista_atividades = db.LogAtividade
                                                                       .Where(a => a.Id_Empresa == idempresa && a.Id_Dispositivo.ToLower() == iddispositivo.ToLower())
                                                                       .OrderByDescending(x => x.Id)
                                                                       .Take(totreg)
                                                                       .ToList();
                                Empresa emp = new Empresa();
                                //
                                if (lista_atividades.Count > 0)
                                {
                                    emp = db.Empresa.Where(x => x.Id == idempresa).FirstOrDefault();
                                }
                                //
                                foreach (LogAtividade item in lista_atividades)
                                {
                                    LogAtividadeModel lam = new LogAtividadeModel();
                                    //
                                    lam.Id             = item.Id;
                                    lam.Descricao      = item.Descricao;
                                    lam.Id_Dispositivo = item.Id_Dispositivo.ToUpper();
                                    lam.NomeColetor    = col.Descricao;
                                    lam.NomeEmpresa    = emp.Nome;
                                    lam.NomeMaquina    = maq.Descricao;
                                    lam.DataHora       = Convert.ToDateTime(item.DataHora);
                                    lam.DataHoraDesc   = FormataDataHoraTela(item.DataHora);

                                    //
                                    switch (item.Tipo)
                                    {
                                    case 1:
                                        lam.Descricao = "Incício Programa";
                                        lam.Imagem    = "<i class='fa fa-code'></i>";
                                        break;

                                    case 2:
                                        lam.Descricao = "Incício loop";
                                        lam.Imagem    = "<i class='fa fa-bell'></i>";
                                        break;

                                    case 3:
                                        lam.Descricao = "Fim loop";
                                        lam.Imagem    = "<i class='fa fa-bell-slash'></i>";
                                        break;

                                    case 4:
                                        lam.Descricao = "Fim Programa";
                                        lam.Imagem    = "<i class='fa fa-code'></i>";
                                        break;

                                    case 5: lam.Descricao = "Pega dados maquina"; break;
                                    }
                                    //
                                    lista_retorno.Add(lam);
                                }
                            }
                            //
                            if (chkpress)
                            {
                                List <ColetorPressaoHistorico> lista_colt_press_histo = db.ColetorPressaoHistorico
                                                                                        .Where(a => a.Id_Coletor == col.Id)
                                                                                        .OrderByDescending(x => x.DataHora)
                                                                                        .Take(totreg)
                                                                                        .ToList();
                                //
                                foreach (ColetorPressaoHistorico item in lista_colt_press_histo)
                                {
                                    LogAtividadeModel lam = new LogAtividadeModel();
                                    //
                                    lam.Id             = item.Id;
                                    lam.Descricao      = "Pressão: " + item.Pressao;
                                    lam.Id_Dispositivo = item.Coletor.MAC.ToUpper();
                                    lam.NomeColetor    = col.Descricao;
                                    lam.NomeEmpresa    = item.Coletor.Empresa.Nome;
                                    lam.NomeMaquina    = maq.Descricao;
                                    lam.DataHora       = Convert.ToDateTime(item.DataHora);
                                    lam.DataHoraDesc   = FormataDataHoraTela(item.DataHora);
                                    lam.Imagem         = "<i class='fa fa-tachometer-alt'></i>";
                                    //
                                    lista_retorno.Add(lam);
                                }
                            }
                            //
                            if (chktemp)
                            {
                                List <ColetorTemperaturaHistorico> lista_colt_temp_histo = db.ColetorTemperaturaHistorico
                                                                                           .Where(a => a.Id_Coletor == col.Id)
                                                                                           .OrderByDescending(x => x.DataHora)
                                                                                           .Take(totreg)
                                                                                           .ToList();
                                //
                                foreach (ColetorTemperaturaHistorico item in lista_colt_temp_histo)
                                {
                                    LogAtividadeModel lam = new LogAtividadeModel();
                                    //
                                    lam.Id             = item.Id;
                                    lam.Descricao      = "Temperatura: " + item.Temperatura;
                                    lam.Id_Dispositivo = item.Coletor.MAC.ToUpper();
                                    lam.NomeColetor    = col.Descricao;
                                    lam.NomeEmpresa    = item.Coletor.Empresa.Nome;
                                    lam.NomeMaquina    = maq.Descricao;
                                    lam.DataHora       = Convert.ToDateTime(item.DataHora);
                                    lam.DataHoraDesc   = FormataDataHoraTela(item.DataHora);
                                    lam.Imagem         = "<i class='fa fa-thermometer-half'></i>";
                                    //
                                    lista_retorno.Add(lam);
                                }
                            }
                            //
                            if (chkprod)
                            {
                                List <ColetorProducaoHistorico> lista_colt_prod_histo = db.ColetorProducaoHistorico
                                                                                        .Where(a => a.Id_Coletor == col.Id)
                                                                                        .OrderByDescending(x => x.DataHora)
                                                                                        .Take(totreg)
                                                                                        .ToList();
                                //
                                foreach (ColetorProducaoHistorico item in lista_colt_prod_histo)
                                {
                                    LogAtividadeModel lam = new LogAtividadeModel();
                                    //
                                    lam.Id             = item.Id;
                                    lam.Descricao      = "Ciclos: " + item.Valor;
                                    lam.Id_Dispositivo = item.Coletor.MAC.ToUpper();
                                    lam.NomeColetor    = col.Descricao;
                                    lam.NomeEmpresa    = item.Coletor.Empresa.Nome;
                                    lam.NomeMaquina    = maq.Descricao;
                                    lam.DataHora       = Convert.ToDateTime(item.DataHora);
                                    lam.DataHoraDesc   = FormataDataHoraTela(item.DataHora);
                                    lam.Imagem         = "<i class='fa fa-tasks'></i>";
                                    //
                                    lista_retorno.Add(lam);
                                }
                            }
                            //
                            ret = "ok";
                        }
                        else
                        {
                            ret = "col";
                        }
                    }
                    else
                    {
                        ret = "maq";
                    }
                }
            }
            catch (Exception exc)
            {
                erro = exc.Message;
                ret  = "nok";
            }
            //
            lista_retorno = lista_retorno.OrderByDescending(x => x.DataHora).ToList();
            //
            return(Json(new { ret, lista_retorno, results = 1, erro, success = true }, JsonRequestBehavior.AllowGet));
        }
示例#20
0
        public ActionResult Index()
        {
            ViewBag.FabricaAtivo        = "active";
            ViewBag.FabricaMaquinaAtivo = "active";
            ViewBag.FabricaShow         = "show";
            List <EmpresaModel>          lista_empresas        = new List <EmpresaModel>();
            List <Maquina>               lista_maquinas        = new List <Maquina>();
            List <Medidor_MaquinaModels> lista_maquinas_models = new List <Medidor_MaquinaModels>();
            List <Coletor>               lista_coletor         = new List <Coletor>();

            //
            if (Codigo_Empresa > 0)
            {
                lista_maquinas = db.Maquina.Where(a => a.Id_Empresa == Codigo_Empresa).ToList();
                //
                if (Tipo_Empresa == 1)
                {
                    ViewBag.ShowCrudIncluir = "inline";
                    ViewBag.ShowCrudEditar  = "inline";
                    ViewBag.ShowCrudExcluir = "inline";

                    Empresa empresa = db.Empresa.Where(x => x.Id == Codigo_Empresa).FirstOrDefault();
                    //
                    EmpresaModel empresa_model = new EmpresaModel();
                    empresa_model.Id   = empresa.Id;
                    empresa_model.Nome = empresa.Nome;
                    lista_empresas.Add(empresa_model);
                    //
                    string empresas = empresa.Empresas;
                    if (!string.IsNullOrEmpty(empresas))
                    {
                        string[] empresas_array     = empresas.Split(',');
                        int[]    ids                = Array.ConvertAll(empresas_array, s => int.Parse(s));
                        var      lista_sub_empresas = db.Empresa.Where(r => ids.Contains(r.Id));
                        if (lista_sub_empresas.Any())
                        {
                            List <Maquina> lista_sub_maquinas = new List <Maquina>();
                            foreach (Empresa sub_empresa in lista_sub_empresas)
                            {
                                empresa_model      = new EmpresaModel();
                                empresa_model.Id   = sub_empresa.Id;
                                empresa_model.Nome = sub_empresa.Nome;
                                lista_empresas.Add(empresa_model);

                                lista_sub_maquinas = db.Maquina.Where(x => x.Id_Empresa == sub_empresa.Id).ToList();
                                lista_maquinas.AddRange(lista_sub_maquinas);
                            }
                        }
                    }
                }
                else
                {
                    ViewBag.ShowCrudIncluir = "none";
                    ViewBag.ShowCrudEditar  = "none";
                    ViewBag.ShowCrudExcluir = "none";
                }
                //
                foreach (Maquina item in lista_maquinas)
                {
                    Medidor_MaquinaModels novo = new Medidor_MaquinaModels();
                    novo.ID               = item.ID;
                    novo.Id_Empresa       = item.Id_Empresa;
                    novo.Descricao        = item.Descricao;
                    novo.DescricaoEmpresa = item.Empresa.Nome;
                    //
                    Coletor oColetor = db.Coletor.Where(a => a.Maquina.Id_Empresa == item.Empresa.Id && a.Id_Maquina == item.ID).FirstOrDefault();
                    //
                    if (oColetor != null)
                    {
                        novo.DescricaoMedidor = oColetor.Descricao;
                        novo.Id_Coletor       = oColetor.Id;
                    }
                    //
                    lista_maquinas_models.Add(novo);
                }
                //
                lista_coletor = db.Coletor.Where(a => a.Id_Empresa == Codigo_Empresa && a.Id_Maquina == null).ToList();
                //
                Coletor coletor_vazio = new Coletor();
                coletor_vazio.Id        = 0;
                coletor_vazio.Descricao = "N/A";
                lista_coletor.Add(coletor_vazio);
                lista_coletor         = lista_coletor.OrderBy(a => a.Id).ToList();
                lista_maquinas_models = lista_maquinas_models.OrderBy(x => x.ID).ToList();
                //
                ViewBag.ListaEmpresas = lista_empresas;
                ViewBag.ListaMaquinas = lista_maquinas_models;
                ViewBag.ListaColetor  = lista_coletor;
            }
            //
            return(View());
        }
示例#21
0
        //
        public JsonResult CarregaDados()
        {
            string sret = string.Empty;
            List <Medidor_MaquinaModels> lista_retorno  = new List <Medidor_MaquinaModels>();
            List <EmpresaModel>          lista_empresas = new List <EmpresaModel>();
            List <Maquina> lista_maquinas = db.Maquina.Where(a => a.Id_Empresa == Codigo_Empresa).ToList();

            //
            try
            {
                if (Tipo_Empresa == 1)
                {
                    Empresa empresa = db.Empresa.Where(x => x.Id == Codigo_Empresa).FirstOrDefault();
                    //
                    EmpresaModel empresa_model = new EmpresaModel();
                    empresa_model.Id   = empresa.Id;
                    empresa_model.Nome = empresa.Nome;
                    lista_empresas.Add(empresa_model);
                    //
                    string empresas = empresa.Empresas;
                    if (!string.IsNullOrEmpty(empresas))
                    {
                        string[] empresas_array     = empresas.Split(',');
                        int[]    ids                = Array.ConvertAll(empresas_array, s => int.Parse(s));
                        var      lista_sub_empresas = db.Empresa.Where(r => ids.Contains(r.Id));
                        if (lista_sub_empresas.Any())
                        {
                            List <Maquina> lista_sub_maquinas = new List <Maquina>();
                            foreach (Empresa sub_empresa in lista_sub_empresas)
                            {
                                empresa_model      = new EmpresaModel();
                                empresa_model.Id   = sub_empresa.Id;
                                empresa_model.Nome = sub_empresa.Nome;
                                lista_empresas.Add(empresa_model);

                                lista_sub_maquinas = db.Maquina.Where(x => x.Id_Empresa == sub_empresa.Id).ToList();
                                lista_maquinas.AddRange(lista_sub_maquinas);
                            }
                        }
                    }
                }
                //
                foreach (Maquina item in lista_maquinas)
                {
                    Medidor_MaquinaModels novo = new Medidor_MaquinaModels();
                    novo.ID               = item.ID;
                    novo.Id_Empresa       = item.Id_Empresa;
                    novo.Descricao        = item.Descricao;
                    novo.DescricaoEmpresa = item.Empresa.Nome;
                    //
                    Coletor oColetor = db.Coletor.Where(a => a.Maquina.Id_Empresa == item.Empresa.Id && a.Id_Maquina == item.ID).FirstOrDefault();
                    //
                    if (oColetor != null)
                    {
                        novo.DescricaoMedidor = oColetor.Descricao;
                        novo.Id_Coletor       = oColetor.Id;
                    }
                    //
                    lista_retorno.Add(novo);
                }
                //
                sret = "ok";
            }
            catch (Exception exc)
            {
                sret = exc.Message;
            }
            //
            lista_retorno = lista_retorno.OrderBy(x => x.ID).ToList();
            //
            return(Json(new { data = sret, lista_retorno, results = 0, success = true }, JsonRequestBehavior.AllowGet));
        }
        //
        public JsonResult ColetorPost(string descricao, string mac, int idcoletor, int empresa_anterior, int empresa_nova, int alerta)
        {
            string sret = string.Empty;
            string erro = string.Empty;

            //
            try
            {
                Coletor oColetor = new Coletor();
                //
                if (idcoletor > 0)
                {
                    oColetor = db.Coletor.Where(a => a.Id_Empresa == empresa_anterior && a.Id == idcoletor).FirstOrDefault();
                    //
                    if (oColetor != null)
                    {
                        oColetor.Descricao = descricao;
                        oColetor.MAC       = mac;
                        //
                        if (oColetor.Id_Empresa != empresa_nova)
                        {
                            List <ColetorAlerta> lista_coletor_alerta = db.ColetorAlerta.Where(x => x.Id_Coletor == idcoletor && x.Id_Empresa == oColetor.Id_Empresa).ToList();
                            //
                            foreach (ColetorAlerta item in lista_coletor_alerta)
                            {
                                item.Id_Empresa      = empresa_nova;
                                db.Entry(item).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                        //
                        oColetor.Id_Empresa      = empresa_nova;
                        oColetor.Alerta          = alerta;
                        db.Entry(oColetor).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        sret = "Coletor não encontrado!";
                    }
                }
                else
                {
                    oColetor.Descricao  = descricao;
                    oColetor.MAC        = mac;
                    oColetor.Ativo      = true;
                    oColetor.Id_Empresa = empresa_nova;
                    //
                    db.Coletor.Add(oColetor);
                    db.SaveChanges();
                    db.Entry(oColetor).Reload();
                }
                //
                sret = "ok";
            }
            catch (Exception exc)
            {
                erro = exc.Message;
                sret = "erro";
            }
            //
            return(Json(new { data = sret, results = 0, success = true, erro }, JsonRequestBehavior.AllowGet));
        }
        //
        public JsonResult ExcluiColetorPost(int idcoletor, int idempresa)
        {
            string ret  = string.Empty;
            string erro = string.Empty;

            try
            {
                Coletor oColetor = db.Coletor.Where(a => a.Id == idcoletor && a.Id_Empresa == idempresa).FirstOrDefault();
                //
                if (oColetor != null)
                {
                    var historico_pressao = db.ColetorPressaoHistorico.Where(x => x.Id_Coletor == idcoletor).Any();
                    if (historico_pressao)
                    {
                        ret = "hpres";
                    }
                    var historico_temperatura = db.ColetorTemperaturaHistorico.Where(x => x.Id_Coletor == idcoletor).Any();
                    if (historico_temperatura)
                    {
                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = "htemp";
                        }
                        else
                        {
                            ret += ",htemp";
                        }
                    }
                    var historico_producao = db.ColetorProducaoHistorico.Where(x => x.Id_Coletor == idcoletor).Any();
                    if (historico_producao)
                    {
                        if (string.IsNullOrEmpty(ret))
                        {
                            ret = "hpro";
                        }
                        else
                        {
                            ret += ",hpro";
                        }
                    }
                    //
                    if (string.IsNullOrEmpty(ret))
                    {
                        List <ColetorAlerta> lista_coletor_alerta = db.ColetorAlerta.Where(x => x.Id_Coletor == idcoletor && x.Id_Empresa == oColetor.Id_Empresa).ToList();
                        //
                        foreach (ColetorAlerta item in lista_coletor_alerta)
                        {
                            db.Entry(item).State = EntityState.Deleted;
                            db.SaveChanges();
                        }
                        //
                        db.Entry(oColetor).State = EntityState.Deleted;
                        db.SaveChanges();
                        ret = "ok";
                    }
                }
                else
                {
                    ret = "nao_encontrada";
                }
            }
            catch (Exception exc)
            {
                ret  = "erro";
                erro = exc.Message;
            }

            return(Json(new { ret, results = 0, erro, success = true }, JsonRequestBehavior.AllowGet));
        }
        //
        public JsonResult ExcluiColetorPostHistorico(int idcoletor, int idempresa)
        {
            string ret        = string.Empty;
            string erro       = string.Empty;
            int    total_excl = 0;

            //
            try
            {
                Coletor oColetor = db.Coletor.Where(a => a.Id == idcoletor && a.Id_Empresa == idempresa).FirstOrDefault();
                //
                if (oColetor != null)
                {
                    var historico_pressao = db.ColetorPressaoHistorico.Where(x => x.Id_Coletor == idcoletor).Any();
                    if (historico_pressao)
                    {
                        string        sql           = "DELETE ColetorPressaoHistorico WHERE Id_Coletor = " + idcoletor;
                        SQLController sqlcontroller = new SQLController();
                        total_excl = sqlcontroller.ExecutaSQLNonQuery(sql, out erro);
                    }
                    var historico_temperatura = db.ColetorTemperaturaHistorico.Where(x => x.Id_Coletor == idcoletor).Any();
                    if (historico_temperatura)
                    {
                        string        sql           = "DELETE ColetorTemperaturaHistorico WHERE Id_Coletor = " + idcoletor;
                        SQLController sqlcontroller = new SQLController();
                        total_excl += sqlcontroller.ExecutaSQLNonQuery(sql, out erro);
                    }
                    var historico_producao = db.ColetorProducaoHistorico.Where(x => x.Id_Coletor == idcoletor).Any();
                    if (historico_producao)
                    {
                        string        sql           = "DELETE ColetorProducaoHistorico WHERE Id_Coletor = " + idcoletor;
                        SQLController sqlcontroller = new SQLController();
                        total_excl += sqlcontroller.ExecutaSQLNonQuery(sql, out erro);
                    }
                    //
                    if (string.IsNullOrEmpty(erro))
                    {
                        List <ColetorAlerta> lista_coletor_alerta = db.ColetorAlerta.Where(x => x.Id_Coletor == idcoletor && x.Id_Empresa == oColetor.Id_Empresa).ToList();
                        //
                        foreach (ColetorAlerta item in lista_coletor_alerta)
                        {
                            db.Entry(item).State = EntityState.Deleted;
                            db.SaveChanges();
                        }
                        //
                        db.Entry(oColetor).State = EntityState.Deleted;
                        db.SaveChanges();
                        ret = "ok";
                    }
                }
                else
                {
                    ret = "nao_encontrada";
                }
            }
            catch (Exception exc)
            {
                ret  = "erro";
                erro = exc.Message;
            }

            return(Json(new { ret, results = 0, total_excl, erro, success = true }, JsonRequestBehavior.AllowGet));
        }
示例#25
0
 public async Task Remove(Coletor coleteor)
 {
     _context.Remove(coleteor);
     await _context.SaveChangesAsync();
 }
示例#26
0
        public List <Coletor> getColetores()
        {
            //Create COM Objects. Create a COM object for everything that is referenced
            Excel.Application xlApp       = new Excel.Application();
            Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(@"C:\ELETROFRIO\ENGENHARIA SMR\PRODUTOS FINAIS ELETROFRIO\MECÂNICA\RACK PADRAO\col_sucao.xlsx");
            Excel._Worksheet  xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range       xlRange     = xlWorksheet.UsedRange;
            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;

            //iterate over the rows and columns and print to the console as it appears in the file
            //excel is not zero based!!
            int i = 0;

            for (i = 2; i <= rowCount; i++)
            {
                var c = new Coletor();
                c.CodigoColetor                    = xlRange.Cells[i, 1].Value2.ToString();
                c.DescricaoColetor                 = xlRange.Cells[i, 2].Value2.ToString();
                c.QuantidadeCompressor             = xlRange.Cells[i, 3].Value2.ToString();
                c.DiametroTuboAcoColetor           = xlRange.Cells[i, 4].Value2.ToString();
                c.CodigoTuboAcoColetor             = xlRange.Cells[i, 5].Value2.ToString();
                c.QuantidadeRamalRack              = xlRange.Cells[i, 6].Value2.ToString();
                c.DiametroSuccaoRack               = xlRange.Cells[i, 7].Value2.ToString();
                c.CodigoBolsaSoldaSuccaoRack       = xlRange.Cells[i, 8].Value2.ToString();
                c.DiametroEncaixeSuccaoRack        = xlRange.Cells[i, 9].Value2.ToString();
                c.DiametroSuccaoCompressor         = xlRange.Cells[i, 10].Value2.ToString();
                c.CodigoBolsaSoldaSuccaoCompressor = xlRange.Cells[i, 11].Value2.ToString();
                c.DiametroEncaixeSuccaoCompressor  = xlRange.Cells[i, 12].Value2.ToString();
                c.ArquivoTemplateDoColetor         = xlRange.Cells[i, 13].Value2.ToString();
                c.ArquivoTemplateTuboDoColetor     = xlRange.Cells[i, 14].Value2.ToString();

                AddColetor(c);
            }

            void AddColetor(Coletor c)
            {
                coletores.Add(c);
            }

            //string celulaAtual = xlRange.Cells[2, 3].Value2.ToString();

            //cleanup
            GC.Collect();
            GC.WaitForPendingFinalizers();

            //rule of thumb for releasing com objects:
            //  never use two dots, all COM objects must be referenced and released individually
            //  ex: [somthing].[something].[something] is bad

            //release com objects to fully kill excel process from running in the background
            Marshal.ReleaseComObject(xlRange);
            Marshal.ReleaseComObject(xlWorksheet);

            //close and release
            xlWorkbook.Close();
            Marshal.ReleaseComObject(xlWorkbook);

            //quit and release
            xlApp.Quit();
            Marshal.ReleaseComObject(xlApp);

            return(coletores);
        }
示例#27
0
        public JsonResult RelatorioTemperaturaGetDados(int idempresa, string lista_ids, string periodo, string horaini, string horafim)
        {
            List <Object> lista           = new List <Object>();
            DateTime      data_filtro_ini = new DateTime();
            DateTime      data_filtro_fim = new DateTime();

            string[] lista_ids_maquinas = lista_ids.Split(',');
            //
            string  maq          = string.Empty;
            string  sreult       = string.Empty;
            string  sFileName    = string.Empty;
            Empresa empresaLista = null;
            //
            List <EmpresaRelatorioModel> lista_empresa_model       = new List <EmpresaRelatorioModel>();
            List <ColetorAlerta>         lista_coletoralerta_model = new List <ColetorAlerta>();
            List <ColetorAlertaLog>      lista_coletor_alerta_log  = new List <ColetorAlertaLog>();
            //
            //List<ColetorAlertaModel> lista_coletor_alerta_item_model = new List<ColetorAlertaModel>();
            List <ColetorAlertaLogModel>   lista_coletor_alerta_log_model   = new List <ColetorAlertaLogModel>();
            List <MaquinaItensReportModel> lista_maquina_itens_report_model = new List <MaquinaItensReportModel>();

            //
            empresaLista = db.Empresa.Where(x => x.Id == idempresa).FirstOrDefault();
            //
            if (!string.IsNullOrEmpty(periodo))
            {
                string[] datas_filro = periodo.Split('-');
                string[] data_um     = datas_filro[0].ToString().Split('/');
                string[] data_dois   = datas_filro[1].ToString().Split('/');
                //
                if (!string.IsNullOrEmpty(horaini) && horaini.Contains(":"))
                {
                    data_filtro_ini = new DateTime(Convert.ToInt32(data_um[2]),
                                                   Convert.ToInt32(data_um[0]),
                                                   Convert.ToInt32(data_um[1]),
                                                   Convert.ToInt32(horaini.Split(':')[0]),
                                                   Convert.ToInt32(horaini.Split(':')[1]), 1);
                }
                else
                {
                    data_filtro_ini = new DateTime(Convert.ToInt32(data_um[2]), Convert.ToInt32(data_um[0]), Convert.ToInt32(data_um[1]), 0, 0, 1);
                }
                //
                if (!string.IsNullOrEmpty(horaini) && horafim.Contains(":"))
                {
                    data_filtro_fim = new DateTime(Convert.ToInt32(data_dois[2]),
                                                   Convert.ToInt32(data_dois[0]),
                                                   Convert.ToInt32(data_dois[1]),
                                                   Convert.ToInt32(horafim.Split(':')[0]),
                                                   Convert.ToInt32(horafim.Split(':')[1]), 59);
                }
                else
                {
                    data_filtro_fim = new DateTime(Convert.ToInt32(data_dois[2]), Convert.ToInt32(data_dois[0]), Convert.ToInt32(data_dois[1]), 23, 59, 59);
                }
            }
            //
            try
            {
                for (int i = 0; i < lista_ids_maquinas.Length; i++)
                {
                    int     idmaquina = Convert.ToInt32(lista_ids_maquinas[i]);
                    Coletor coletor   = db.Coletor.Where(x => x.Maquina != null && x.Maquina.ID == idmaquina).FirstOrDefault();
                    //
                    if (coletor != null)
                    {
                        MaquinaItensReportModel mirm = new MaquinaItensReportModel();
                        //
                        mirm.DescricaoColetor = coletor.Descricao;
                        mirm.DescricaoMaquina = coletor.Maquina.Descricao;
                        if (string.IsNullOrEmpty(maq))
                        {
                            maq = coletor.Maquina.Descricao;
                        }
                        else
                        {
                            maq = maq + " - " + coletor.Maquina.Descricao;
                        }
                        //
                        lista_maquina_itens_report_model.Add(mirm);
                        //
                        lista_coletoralerta_model = db.ColetorAlerta.Where(x => x.Id_Coletor == coletor.Id).ToList();
                        //
                        string teste    = @"
                                    SELECT Cast(datahora AS DATE)                   AS 'Data',
                                            DATENAME(weekday, Cast(datahora AS DATE)) AS 'DiaSemana',
                                            Datepart(month, datahora)                AS Mes, 
                                            Datepart(day, datahora)                  AS Dia, 
                                            Temperatura
                                        FROM   ColetorTemperaturaHistorico 
                                    WHERE Id_Coletor = 47
                                        AND DataHora >= '2019-12-15 14:40:01.000'
                                        AND DataHora <= '2019-12-31 14:40:01.000'
                                        AND Temperatura IS NOT NULL 

                                        ORDER  BY Datepart(month, datahora), 
                                                Datepart(day, datahora)
                                    ";
                        string sql_temp = @"SELECT Cast(datahora AS DATE)                   AS 'Data',
                                        DATENAME(weekday, Cast(datahora AS DATE)) AS 'DiaSemana',
                                        Datepart(month, datahora)                AS Mes, 
                                        Datepart(day, datahora)                  AS Dia, 
                                        ROUND((Avg(Cast(temperatura AS FLOAT)) / 10 ), 2) AS 'TemperaturaMedia' 
                                 FROM   ColetorTemperaturaHistorico 
                                WHERE Id_Coletor = " + coletor.Id + @"
                                    AND DataHora >= '" + data_filtro_ini.ToString("yyyy/MM/dd HH:mm:ss.fff", CultureInfo.InvariantCulture) + @"'
                                    AND DataHora <= '" + data_filtro_fim.ToString("yyyy/MM/dd HH:mm:ss.fff", CultureInfo.InvariantCulture) + @"'
                                    AND Temperatura IS NOT NULL 
                                 GROUP  BY Cast(datahora AS DATE), 
                                           Datepart(day, datahora), 
                                           Datepart(month, datahora) 
                                 ORDER  BY Datepart(month, datahora), 
                                           Datepart(day, datahora)";
                        //
                        SQLController sqlcontroller = new SQLController();
                        DataTable     data_temp     = sqlcontroller.ExecutaSQL(teste);
                        //
                        if (data_temp != null && data_temp.Rows.Count > 0)
                        {
                            double[] valoresY = new double[data_temp.Rows.Count];
                            string[] valoresX = new string[data_temp.Rows.Count];
                            //
                            for (int k = 0; k < data_temp.Rows.Count; k++)
                            {
                                valoresX[k] = Convert.ToString(data_temp.Rows[k]["Dia"]) + "/" + Convert.ToString(data_temp.Rows[k]["Mes"]);
                                valoresY[k] = Convert.ToDouble(data_temp.Rows[k]["Temperatura"]);
                            }
                            //
                            List <Object> lista_itens = new List <Object>();
                            lista_itens.Add(valoresX);
                            lista_itens.Add(valoresY);
                            lista_itens.Add(coletor.Maquina.Descricao);
                            //
                            lista.Add(lista_itens);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                sFileName = "Erro: " + exc.Message;
                sreult    = "nok";
            }
            //
            return(Json(new
            {
                data = "OK",
                results = 1,
                success = true,
                errors = 0,
                dados = lista,
                maquinas = maq,
                periodo = data_filtro_ini.ToShortDateString() + " " + data_filtro_ini.ToShortTimeString() + " - " + data_filtro_fim.ToShortDateString() + " " + data_filtro_fim.ToShortTimeString()
            }, JsonRequestBehavior.AllowGet));
        }
示例#28
0
        public void AtualizaPedidos(DateTime date)
        {
            var vendstands = new int[] { 301, 302, 303, 304, 305, 306,
                                         401, 402, 403, 404, 405, 406,
                                         601, 602, 603, 604 };
            var pc = Environment.MachineName;

            var path = @"F:\SOF\VDWIN\EXP\PEDIDOS.CSV";

            if (pc == "ATAIDE-PC")
            {
                path = @"C:\Users\krekm\Desktop\PEDIDOS.CSV";
            }
            if (pc == "KREKINHA-PC")
            {
                path = @"C:\Users\krekm\Desktop\PEDIDOS.CSV";
            }

            var peds = Coletor.GetPedidos(path, date);

            var vendas = new ObservableCollection <Venda>();

            if (Vendas == null)
            {
                Vendas = new ObservableCollection <Venda>();
            }

            if (Vendas.Count > 0)
            {
                Vendas.Clear();
            }

            foreach (var ped in peds)
            {
                var vnd = vendas.FirstOrDefault(vd => vd.CodVendedor == ped.CodVendedor);
                if (vnd == null && ped.CodVendedor != 900)
                {
                    vendas.Add(new Venda
                    {
                        CodVendedor = ped.CodVendedor,
                        DataColeta  = ped.DataPedido,
                        Pedidos     = new List <Pedido> {
                            ped
                        }
                    });
                }
                else
                {
                    if (ped.CodVendedor == 900)
                    {
                        continue;
                    }
                    vnd.Pedidos.Add(ped);
                }
            }

            var vends     = vendas.Select(x => x.CodVendedor).Distinct().ToArray();
            var vendfauls = vendstands.Except(vends).ToArray();

            if (vendfauls.Length > 0)
            {
                foreach (var item in vendfauls)
                {
                    vendas.Add(new Venda()
                    {
                        CodVendedor = item
                    });
                }
            }

            var vendas2 = CheckDuple(vendas).OrderBy(x => x.CodVendedor);

            foreach (var vd in vendas2)
            {
                Vendas.Add(vd);
            }
        }
示例#29
0
 public async Task Create(Coletor coleteor)
 {
     _context.Add(coleteor);
     await _context.SaveChangesAsync();
 }