//
        public JsonResult ExcluiColetorAlertaPost(int idalerta, int idcoletor, int idempresa)
        {
            string ret  = string.Empty;
            string erro = string.Empty;

            try
            {
                ColetorAlerta oColetorAlerta = db.ColetorAlerta.Where(x => x.Id == idalerta && x.Id_Coletor == idcoletor && x.Id_Empresa == idempresa).FirstOrDefault();
                //
                if (oColetorAlerta != null)
                {
                    string        sql           = "DELETE ColetorAlertaLog WHERE Id_Coletor = " + idcoletor + " AND Id_ColetorAlerta = " + oColetorAlerta.Id;
                    SQLController sqlcontroller = new SQLController();
                    sqlcontroller.ExecutaSQLNonQuery(sql, out erro);
                    //
                    db.Entry(oColetorAlerta).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 ExcluiUsuarioPost(int idempresa, int idusuario)
        {
            string ret = string.Empty;

            try
            {
                if (Codigo_Usuario == idusuario && idempresa == Codigo_Empresa)
                {
                    ret = "usu";
                }
                else
                {
                    Usuario oUsuarioModel = db.Usuario.Where(a => a.ID == idusuario && a.Id_Empresa == idempresa).FirstOrDefault();
                    //
                    if (oUsuarioModel != null)
                    {
                        string        erro          = string.Empty;
                        string        sql           = "DELETE UsuarioLogin WHERE Id_MedidorUsuario = " + idusuario;
                        SQLController sqlcontroller = new SQLController();
                        int           total_excl    = sqlcontroller.ExecutaSQLNonQuery(sql, out erro);
                        //
                        db.Entry(oUsuarioModel).State = EntityState.Deleted;
                        db.SaveChanges();
                        ret = "ok";
                    }
                    else
                    {
                        ret = "nok";
                    }
                }
            }
            catch (Exception exc)
            {
                ret = exc.Message;
            }

            return(Json(new { ret, results = 0, 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));
        }