Пример #1
0
 private void MostrarTexto(string texto)
 {
     if (Txtlog.Dispatcher.CheckAccess())
     {
         Txtlog.AppendText(texto);
         using (StreamWriter file = new StreamWriter(path, true))
         {
             file.WriteLine(string.Format(@"{0} {1}", texto, paci.Nombre));
         }
         try
         {
             double voltaje = 0d;
             string value   = texto;
             value = value.Replace(@".", @",").Trim();
             if (value.Length > 3)
             {
                 voltaje = double.TryParse(value.Substring(0, 4), out voltaje) ? double.Parse(value.Substring(0, 4)) : voltaje;
             }
             if (voltaje != 0)
             {
                 Dispatcher.Invoke(() =>
                 {
                     voltagePointCollection.Add(new VoltagePoint(voltaje, DateTime.Now));
                 });
             }
             textPort = string.Empty;
             //Modificación de resultados del paciente
             Resultado res = new Resultado();
             res.Fecha = DateTime.Now;
             res.Valor = texto;
             if (paci.LstSensor[0].LstResultado == null)
             {
                 paci.LstSensor[0].LstResultado = new List <Resultado>();
             }
             paci.LstSensor[0].LstResultado.Add(res);
             paci.StatusPaciente = StatusPaciente.Disponible;
             if (paci.LstSensor[0].LstResultado.Count >= Properties.Settings.Default.QuantityResult)
             {
                 App.Paciente = paci;
                 Close();
             }
         }
         catch (InvalidOperationException) { }
         catch (Exception)
         {
             //TxtMensaje.Text = ex.Message;
         }
     }
     else
     {
         MostrarTextoCallback d = new MostrarTextoCallback(MostrarTexto);
         Dispatcher.BeginInvoke(d, new object[] { texto });
     }
 }
        private void MostrarTexto(string texto)
        {
            if (this.Txtlog.Dispatcher.CheckAccess())
            {
                Paciente paciActive = null;
                switch (idSensorActivo)
                {
                case (int)SensorType.Electrocardiograma:
                    paciActive = lstPaciente.Find(x => x.Nombre == LblElectro.Text);
                    break;

                case (int)SensorType.Glucometro:
                    paciActive = lstPaciente.Find(x => x.Nombre == LblGlucometro.Text);
                    break;

                case (int)SensorType.Pulsiometro:
                    paciActive = lstPaciente.Find(x => x.Nombre == LblPulsiometro.Text);
                    break;

                case (int)SensorType.Medida:
                    LblMedida.Text = string.Empty;
                    break;
                }
                Txtlog.AppendText(texto);
                using (StreamWriter file = new StreamWriter(path, true))
                {
                    file.WriteLine(string.Format(@"{0} {1}", texto, paciActive.Nombre));
                }
                textPort = string.Empty;
                Resultado res = new Resultado();
                res.Fecha = DateTime.Now;
                res.Valor = texto;
                int sensIndex = paciActive.LstSensor.FindIndex(x => x.IdSensor.Equals(idSensorActivo));
                if (paciActive.LstSensor[sensIndex].LstResultado == null)
                {
                    paciActive.LstSensor[sensIndex].LstResultado = new List <Resultado>();
                }
                paciActive.LstSensor[sensIndex].LstResultado.Add(res);
                paciActive.StatusPaciente = StatusPaciente.Disponible;
                if (paciActive.LstSensor[sensIndex].LstResultado.Count >= Properties.Settings.Default.QuantityResult)
                {
                    switch (idSensorActivo)
                    {
                    case (int)SensorType.Electrocardiograma:
                        LblElectro.Text = string.Empty;
                        break;

                    case (int)SensorType.Glucometro:
                        LblGlucometro.Text = string.Empty;
                        break;

                    case (int)SensorType.Pulsiometro:
                        LblPulsiometro.Text = string.Empty;
                        break;

                    case (int)SensorType.Medida:
                        LblMedida.Text = string.Empty;
                        break;
                    }
                    if (puerto != null)
                    {
                        if (puerto.IsOpen)
                        {
                            puerto.Close();
                        }
                    }
                    ActivarBotones(true);
                    lstSensor[lstSensor.FindIndex(x => x.IdSensor.Equals(idSensorActivo))].StatusSensor = StatusSensor.Disponible;
                    NextPaciente();
                }
            }
            else
            {
                MostrarTextoCallback d = new MostrarTextoCallback(MostrarTexto);
                this.Dispatcher.BeginInvoke(d, new object[] { texto });
            }
        }