Exemplo n.º 1
0
        //consulta
        private void buttonConsultar_Click(object sender, EventArgs e)
        {
            if (richTextBox1.Text != "" && comboBoxEstacion.Text.Contains("Estacion"))
            {
                try
                {
                    Estacion.Estacion estacion = obtenerEstacion();
                    int    variable;
                    string operacion = ""; //qué -> coger estacion a la que fue y su operacion hecha
                    Int32.TryParse(DecodeAndDecrypt(estacion.getId()), out int id);
                    if (comboBoxVariable.Text.Contains("Humedad"))
                    {
                        operacion          = "getHum";
                        variable           = Int32.Parse(DecodeAndDecrypt(estacion.getHum()));
                        richTextBox2.Text += "La humedad de la estacion " + id + " es de: " + variable.ToString() + "\n";
                    }
                    if (comboBoxVariable.Text.Contains("Temperatura"))
                    {
                        operacion          = "getTemp";
                        variable           = Int32.Parse(DecodeAndDecrypt(estacion.getTemp()));
                        richTextBox2.Text += "La temperatura de la estacion " + id + " es de: " + variable.ToString() + "\n";
                    }
                    if (comboBoxVariable.Text.Contains("Luminosidad"))
                    {
                        operacion          = "getLum";
                        variable           = Int32.Parse(DecodeAndDecrypt(estacion.getLum()));
                        richTextBox2.Text += "La luminosidad de la estacion " + id + " es de: " + variable.ToString() + "\n";
                    }
                    if (comboBoxVariable.Text.Contains("Pantalla"))
                    {
                        operacion = "getPantalla";
                        string s = DecodeAndDecrypt(estacion.getLCD());
                        richTextBox2.Text += "La pantalla de la estacion " + id + " tiene el valor " + s + "\n";
                    }

                    operacion += " estacion" + id;
                    string textoLog = escribirLog(operacion);
                    estacion.setLog(textoLog);
                    string path = "C:\\Users\\Public\\log.txt";
                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, true))
                    {
                        file.WriteLine(textoLog);
                    }
                }catch (Exception ex)
                {
                    richTextBox2.Text += "ESTACIÓN NO DISPONIBLE \n";
                    comboBoxEstacion.Items.Remove(comboBoxEstacion.Text);
                }
            }
            else
            {
                richTextBox2.Text += "Hay campos sin rellenar \n";
            }
        }