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";
            }
        }
Exemplo n.º 2
0
 //establecer valor
 private void buttonDisplay_Click(object sender, EventArgs e)
 {
     if (richTextBox1.Text != "" && comboBoxEstacion.Text.Contains("Estacion"))
     {
         try
         {
             Estacion.Estacion estacion = obtenerEstacion();
             string            variable;
             string            operacion = "";
             Int32.TryParse(DecodeAndDecrypt(estacion.getId()), out int id);
             try
             {
                 if (comboBoxEstablecer.Text != "" && comboBoxEstacion.Text.Contains("Estacion"))
                 {
                     if (Int32.TryParse(textBoxDisplay.Text, out int x))
                     {
                         if (comboBoxEstablecer.Text.Contains("Humedad"))
                         {
                             operacion = "setHum";
                             variable  = textBoxDisplay.Text;
                             estacion.setHum(EncryptAndEncode(variable));
                         }
                         if (comboBoxEstablecer.Text.Contains("Temperatura"))
                         {
                             operacion = "setTemp";
                             variable  = textBoxDisplay.Text;
                             estacion.setTemp(EncryptAndEncode(variable));
                         }
                         if (comboBoxEstablecer.Text.Contains("Luminosidad"))
                         {
                             operacion = "setLum";
                             variable  = textBoxDisplay.Text;
                             estacion.setLum(EncryptAndEncode(variable));
                         }
                         labelError2.Visible = false;
                         label3.Visible      = true;
                     }
                     else
                     {
                         labelError2.Visible = true;
                         label3.Visible      = false;
                     }
                     if (comboBoxEstablecer.Text.Contains("Pantalla"))
                     {
                         operacion = "setPantalla";
                         estacion.setLCD(EncryptAndEncode(textBoxDisplay.Text));
                         labelError2.Visible = false;
                         label3.Visible      = true;
                     }
                     if (operacion.Contains("set"))
                     {
                         operacion += " estacion" + id;
                         string logLine = escribirLog(operacion);
                         estacion.setLog(logLine);
                         string path = "C:\\Users\\Public\\log.txt";;
                         using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, true))
                         {
                             file.WriteLine(logLine);
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 labelError2.Visible = true;
                 label3.Visible      = false;
             }
         }catch (Exception ex)
         {
             textBoxDisplay.Text = "ESTACIÓN NO DISPONIBLE";
             comboBoxEstacion.Items.Remove(comboBoxEstacion.Text);
         }
     }
 }