Exemplo n.º 1
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);
         }
     }
 }