public static string GetAlertasProducao(string id, string DtInicio, string DtFim, string Offset)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Offset) || !Diversos.IsNumeric(Offset))
                {
                    Offset = "0";
                }

                Maquina maquina = VARS.Maquinas.First(x => x.Id == Convert.ToInt32(id));

                //Populating a DataTable from database.
                DataTable dt = new DataTable();

                StringBuilder strQuery = new StringBuilder();
                strQuery.Append("SELECT TOP 1000 TipoAlerta.Tipo as 'A', (Alertas.Diametro + @OFFSET) AS 'D', FORMAT(Alertas.DataHora, 'dd/MM/yyyy HH:mm:ss') AS 'T' FROM Alertas ");
                strQuery.Append("INNER JOIN TipoAlerta ON Alertas.IdAlerta = TipoAlerta.Id ");
                strQuery.Append("WHERE Alertas.IdMaquina = @IdMaquina AND Alertas.DataHora BETWEEN @DATA1 AND @DATA2 ");
                strQuery.Append("ORDER BY Alertas.Id");

                if (maquina == null)
                {
                    throw new Exception("máquina não encontrada!");
                }
                else
                {
                    using (SqlConnection sqlConn = new SqlConnection(VARS.ConnectionString))
                        using (SqlCommand sqlCmd = new SqlCommand(strQuery.ToString(), sqlConn))
                        {
                            sqlCmd.Parameters.Add("@IdMaquina", SqlDbType.TinyInt).Value = Convert.ToInt32(id);
                            sqlCmd.Parameters.AddWithValue("@OFFSET", Convert.ToDouble(Offset.Replace(".", ",")));

                            sqlCmd.Parameters.Add("@DATA1", SqlDbType.DateTime).Value = DateTime.Parse(DtInicio);
                            sqlCmd.Parameters.Add("@DATA2", SqlDbType.DateTime).Value = DateTime.Parse(DtFim);

                            using (SqlDataAdapter sda = new SqlDataAdapter(sqlCmd))
                                sda.Fill(dt);
                        }
                }

                return(VARS.ConvertDataTabletoString(dt));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetAlertasProducao(): " + ex.Message);

                return(string.Empty);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string query = Request.QueryString["ID"];

            if (!string.IsNullOrEmpty(query) && Diversos.IsNumeric(query))
            {
                ID = Convert.ToInt32(query);
            }

            if (!IsPostBack)
            {
                #region Preenche Infos

                try
                {
                    Maquina maquina = VARS.Maquinas.First(x => x.Id == ID);

                    if (maquina != null)
                    {
                        txtNomeMaquina.Value = maquina.Nome;

                        this.lblNomeMaquina.InnerText = this.Title = "Configurações Avançadas - " + maquina.Nome;

                        txtLimConformeMin.Value = maquina.Classe.Conforme.Min.ToString("0.000");
                        txtLimConformeMax.Value = maquina.Classe.Conforme.Max.ToString("0.000");

                        txtLimClasse2Min.Value    = maquina.Classe.Classe2.Min.ToString("0.000");
                        txtLimClasse2Max.Value    = maquina.Classe.Classe2.Max.ToString("0.000");
                        txtMaxPointsclasse2.Value = maquina.Classe.MaxPontosClasse2.ToString();

                        txtLimClasse3Min.Value    = maquina.Classe.Classe3.Min.ToString("0.000");
                        txtLimClasse3Max.Value    = maquina.Classe.Classe3.Max.ToString("0.000");
                        txtMaxPointsclasse3.Value = maquina.Classe.MaxPontosClasse3.ToString();

                        txtMaxPointsNC.Value        = maquina.Classe.MaxPontosNC.ToString();
                        txtSptempoMaxPointsNC.Value = Convert.ToInt32(maquina.Classe.SpTempoMaxPontosNC.TotalSeconds).ToString();
                    }
                    else
                    {
                        throw new Exception("sem dados lidos para a maquina " + ID);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                #endregion
            }
        }
        public static string GetGraph(string id, string DtInicio, string DtFim, string Offset)
        {
            //Populating a DataTable from database.
            DataTable dt = new DataTable();

            dt.Columns.Add("D", typeof(double));
            //dt.Columns.Add("C", typeof(int));
            dt.Columns.Add("T", typeof(string));

            int maxOfRecords = 1000;

            if (string.IsNullOrWhiteSpace(Offset) || !Diversos.IsNumeric(Offset))
            {
                Offset = "0";
            }

            try
            {
                Maquina maquina = VARS.Maquinas.First(x => x.Id == Convert.ToInt32(id));

                //   int lastSec = -1;

                if (maquina == null)
                {
                    throw new Exception("máquina não encontrada!");
                }
                else
                if (maquina.GraficoPontos.GetPoints(DateTime.Parse(DtInicio), DateTime.Parse(DtFim).AddMinutes(1).AddSeconds(-1), Convert.ToDouble(Offset.Replace(".", ","))))
                {
                    //get stats
                    LAST_SEARCH_STATS.Clear();
                    //get class
                    LAST_CLASS_TABLE.Clear();

                    LAST_CLASS = Classificacoes.Classificacao.Undefined;

                    long numPointsClasse2 = 0;
                    long numPointsClasse3 = 0;
                    long numPointsNC      = 0;

                    Classificacoes.Classificacao lastClass = Classificacoes.Classificacao.Undefined;

                    int increment = (int)Math.Ceiling((double)maquina.GraficoPontos.Pontos.Count / maxOfRecords);

                    for (int i = 0; i < maquina.GraficoPontos.Pontos.Count; i++)
                    {
                        if (i % increment == 0 || (maquina.GraficoPontos.Pontos[i].Classe != Classificacoes.Classificacao.Conforme && maquina.GraficoPontos.Pontos[i].Classe != lastClass))
                        {
                            // dt.Rows.Add(Math.Round(maquina.GraficoPontos.Pontos[i].Value, 3), (int)maquina.GraficoPontos.Pontos[i].Classe, maquina.GraficoPontos.Pontos[i].DataHora.ToString("dd/MM/yyyy HH:mm:ss"));
                            dt.Rows.Add(Math.Round(maquina.GraficoPontos.Pontos[i].Value, 3), maquina.GraficoPontos.Pontos[i].DataHora.ToString("dd/MM/yyyy HH:mm:ss"));
                        }

                        if (LAST_CLASS_TABLE.Count < 1000)
                        {
                            if (maquina.GraficoPontos.Pontos[i].Classe != Classificacoes.Classificacao.Conforme)
                            {
                                if (maquina.GraficoPontos.Pontos[i].Classe != lastClass)
                                {
                                    LAST_CLASS_TABLE.Add(maquina.GraficoPontos.Pontos[i]);
                                }
                            }
                        }
                        lastClass = maquina.GraficoPontos.Pontos[i].Classe;


                        if (maquina.GraficoPontos.Pontos[i].Classe == Classificacoes.Classificacao.Classe2)
                        {
                            numPointsClasse2++;
                        }
                        else if (maquina.GraficoPontos.Pontos[i].Classe == Classificacoes.Classificacao.Classe3)
                        {
                            numPointsClasse3++;
                        }
                        else if (maquina.GraficoPontos.Pontos[i].Classe == Classificacoes.Classificacao.NaoConforme)
                        {
                            numPointsNC++;
                        }
                    }

                    //analise a conformidade da bobine
                    if (numPointsNC > 0 || numPointsClasse3 > maquina.Classe.MaxPontosClasse3 || numPointsClasse2 > maquina.Classe.MaxPontosClasse2)
                    {
                        LAST_CLASS = Classificacoes.Classificacao.NaoConforme;
                    }
                    else if (numPointsClasse3 > 0)
                    {
                        LAST_CLASS = Classificacoes.Classificacao.Classe3;
                    }
                    else if (numPointsClasse2 > 0)
                    {
                        LAST_CLASS = Classificacoes.Classificacao.Classe2;
                    }
                    else
                    {
                        LAST_CLASS = Classificacoes.Classificacao.Conforme;
                    }

                    //get stats
                    double aux = Math.Round(maquina.GraficoPontos.Pontos.Select(x => x.Value).Average(), 3);
                    LAST_SEARCH_STATS.Add(new Maquina.PontosGraph.DataPoint(aux, DateTime.Now, maquina.Classe.GetClassificacao(aux)));
                    LAST_SEARCH_STATS.Add(maquina.GraficoPontos.Minimum);
                    LAST_SEARCH_STATS.Add(maquina.GraficoPontos.Maximum);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetGraph(): " + ex.Message);

                return(string.Empty);
            }

            return(VARS.ConvertDataTabletoString(dt));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Debug.WriteLine("ConsultarRegistos Page_Load");

            string id = Request.QueryString["ID"];

            if (!string.IsNullOrEmpty(id) && Diversos.IsNumeric(id))
            {
                ID = Convert.ToInt32(id);
            }

            if (this.Maquina == null || this.Maquina.Id != ID)
            {
                Response.Redirect("/notfound.html", true);
            }

            if (!IsPostBack)
            {
                this.Title = "Controlo de Produção - " + this.Maquina.Nome;
                this.lblNomeMaquina.InnerText = this.Maquina.Nome;

                //vai buscar as datas
                try
                {
                    string dtInicio = Request.QueryString["DtInicio"];
                    if (!string.IsNullOrEmpty(dtInicio))
                    {
                        if (!DateTime.TryParse(dtInicio, out dateTimes[0]))
                        {
                            throw new Exception("DtInicio parse error");
                        }
                    }

                    string dtFim = Request.QueryString["DtFim"];
                    if (!string.IsNullOrEmpty(dtFim))
                    {
                        if (!DateTime.TryParse(dtFim, out dateTimes[1]))
                        {
                            throw new Exception("DtFim parse error");
                        }
                    }

                    if (dateTimes[0] == DateTime.MinValue || dateTimes[1] == DateTime.MinValue)
                    {
                        throw new Exception("Datetime == MinValue");
                    }

                    if (dateTimes[0] >= dateTimes[1])
                    {
                        throw new Exception("DtInicio >= DtFim");
                    }

                    string textOfst = Request.QueryString["Offset"];
                    if (string.IsNullOrEmpty(textOfst))
                    {
                        textOfst = "0";
                    }

                    if (Diversos.IsNumeric(textOfst))
                    {
                        double value = Convert.ToDouble(textOfst.Replace(".", ","));

                        if (value != 0)
                        {
                            txtOffset.Value = Convert.ToDouble(textOfst.Replace(".", ",")).ToString("0.000");
                        }
                    }

                    if (Diversos.CheckForInternetConnection())
                    {
                        string dominio = Convert.ToString(SQLHelper.ExecuteScalar("SELECT Value FROM Settings WHERE Id = 1", VARS.ConnectionString));

                        idQrCode.Src = @"https://chart.googleapis.com/chart?chs=190x190&cht=qr&chl=" + dominio +
                                       "ConsultarRegistos.aspx?id=" + id + "%26DtInicio=" + dtInicio + "%26DtFim=" + dtFim + "%26Offset=" + textOfst + "%26key=" +
                                       new GetKeys().Encripta(dtFim + id.ToString() + textOfst.Replace(".", ",") + dtInicio).Replace("+", "X").Replace("=", "Y");;
                        idDisplayQrCode.Style.Add("display", "block");
                    }

                    if (!this.SessaoIniciada)
                    { //se nao tem sessao iniciada esconde o txt do offset e botao de refresh
                        txtOffset.Disabled = true;
                        txtOffset.Style.Add("display", "none");
                        btnRefresh.HRef = "#";
                        btnRefresh.Style.Add("display", "none");
                    }


                    this.OrdUpdateChart = true;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Erro ao obter datas: " + ex.Message);

                    dateTimes[0] = DateTime.Today;
                    dateTimes[1] = DateTime.Today.AddDays(1).AddSeconds(-1);
                    //   idQrCode.Style.Add("display", "none");
                }
            }
        }
Ejemplo n.º 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string query = Request.QueryString["ID"];

            if (!string.IsNullOrEmpty(query) && Diversos.IsNumeric(query))
            {
                ID = Convert.ToInt32(query);
            }
            else
            {
                Response.Redirect("/index.aspx?id=1");
            }



            #region Get Maquinas

            try
            {
                if (VARS.UserSession.SessaoIniciada)
                {
                    if (VARS.Maquinas.Count == 0)
                    {
                        Response.Redirect("/notfound.html");
                    }
                    else
                    if (VARS.Maquinas.Count == 1)
                    {
                        divSelectMaquinas.Style.Add("display", "none");
                    }
                    else
                    {
                        StringBuilder strRadios = new StringBuilder();

                        for (int i = 0; i < VARS.Maquinas.Count; i++)
                        {
                            strRadios.AppendLine("<div class=\"form-check\">");
                            strRadios.AppendLine("<label class=\"form-check-label\">");
                            strRadios.AppendLine("<input type=\"radio\" class=\"form-check-input\" name=\"choice\" value=\"" + VARS.Maquinas[i].Id.ToString() + "\" onclick=\"RadioClick();\"" + (VARS.Maquinas[i].Id == ID ? "checked" : "") + " > ");
                            strRadios.AppendLine(VARS.Maquinas[i].Nome);
                            strRadios.AppendLine("</label>");
                            strRadios.AppendLine("</div>");
                            strRadios.AppendLine("<div class=\"form-check\">");
                            strRadios.AppendLine("&nbsp  &nbsp  &nbsp");
                            strRadios.AppendLine("</div>");
                        }

                        divRadioButtons.InnerHtml = strRadios.ToString();
                    }

                    Maquina maq = VARS.Maquinas.Find(x => x.Id == ID);

                    if (maq != null)
                    {
                        ControloDiametro control = (ControloDiametro)LoadControl("/ControloDiametro.ascx");

                        control.IdLinha = ID;

                        pnlEspacoMaquinas.Controls.Add(control);
                    }
                    else
                    {
                        Response.Redirect("/index.aspx?id=1");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Page_Load(): " + ex.Message);
            }
            #endregion
        }