public DeviceViewModel() { try { Devices = BackClient.GetEntities <ObservableCollection <Device> >("json_devices.php"); TemplatesFirmwares = BackClient.GetEntities <List <TemplateFirmware> >("json_firmwares.php"); TemplateDevices = BackClient.GetEntities <List <TemplateDevice> >("json_template_device.php"); var sensorsOfDevices = BackClient.GetEntities <List <SensorsOfDevice> >("json_sensors_of_device.php"); foreach (var device in Devices) { device.TemplatesFirmwares = TemplatesFirmwares[device.IdTemplateFirmware - 1]; device.TemplateDevice = TemplateDevices[device.IdTemplateDevice - 1]; foreach (var sensor in sensorsOfDevices) { if (device.IdTemplateDevice == sensor.IdTemplateDevice && !device.SensorsOfDevices.Any(item => item.IdInDevice == sensor.IdInDevice)) { device.SensorsOfDevices.Add(sensor); } } } } catch (Exception ex) { MessageBox.Show("Ошибка! " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
public SensorViewModel() { try { Sensors = BackClient.GetEntities <ObservableCollection <Sensor> >("json_sensors.php"); SensorParameters = BackClient.GetEntities <List <SensorParameter> >("json_sensor_parameters.php"); ParameterTypes = BackClient.GetEntities <List <ParameterType> >("json_parameter_type.php"); Parameters = BackClient.GetEntities <List <Parameter> >("json_parameters.php"); foreach (var sensor in Sensors) { for (int i = 0; i < SensorParameters.Count; i++) { if (sensor.Id == SensorParameters[i].IdSensor) { sensor.SensorParameters.Add(SensorParameters[i]); } } } } catch (Exception ex) { MessageBox.Show("Ошибка! " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
public TemplateFirmwareViewModel() { try { TemplatesFirmware = BackClient.GetEntities <ObservableCollection <TemplateFirmware> >("json_firmwares.php"); } catch (Exception ex) { MessageBox.Show("Ошибка! " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
public TemplateDeviceViewModel() { try { TemplatesDevices = BackClient.GetEntities <ObservableCollection <TemplateDevice> >("json_template_device.php"); TemplatesFirmwares = BackClient.GetEntities <List <TemplateFirmware> >("json_firmwares.php"); Controllers = BackClient.GetEntities <List <Controller> >("json_controllers.php"); Sensors = BackClient.GetEntities <List <Sensor> >("json_sensors.php"); Parameters = BackClient.GetEntities <List <Parameter> >("json_parameters.php"); SensorParameters = BackClient.GetEntities <List <SensorParameter> >("json_sensor_parameters.php"); var sensorsOfDevices = BackClient.GetEntities <List <SensorsOfDevice> >("json_sensors_of_device.php"); foreach (var sensor in Sensors) { foreach (var sensorParameter in SensorParameters) { if (sensor.Id == sensorParameter.IdSensor) { sensor.SensorParameters.Add(sensorParameter); } } } foreach (var templateDevice in TemplatesDevices) { templateDevice.TemplatesFirmwares = TemplatesFirmwares[templateDevice.IdTemplateFirmware - 1]; templateDevice.Controllers = Controllers[templateDevice.IdControllers - 1]; foreach (var sensor in sensorsOfDevices) { if (templateDevice.Id == sensor.IdTemplateDevice) { templateDevice.SensorsOfDevices?.Add(sensor); } } } } catch (Exception ex) { MessageBox.Show("Ошибка! " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } }
public ParameterViewModel() { Parameters = BackClient.GetEntities <ObservableCollection <Parameter> >("json_parameters.php"); }
public MainViewModel() { //Создание графиков SeriesTemperature = new SeriesCollection { new LineSeries { Title = "Температура", Values = new ChartValues <double>() } }; SeriesHumidity = new SeriesCollection { new LineSeries { Title = "Влажность", Values = new ChartValues <double>() } }; SeriesPressure = new SeriesCollection { new LineSeries { Title = "Давление", Values = new ChartValues <double>() } }; try { //Получение значений показателей ValueTemperature = BackClient.GetEntities <List <ValueParameters> >("json_old_parameters_temp.php"); ValueHumidity = BackClient.GetEntities <List <ValueParameters> >("json_old_parameters_hum.php"); ValuePressure = BackClient.GetEntities <List <ValueParameters> >("json_old_parameters_pres.php"); //получение статуса реле var relaysStatus = BackClient.GetEntities <string>("get_rele_status.php"); FirstRelayStatus = relaysStatus[0] != '0'; SecondRelayStatus = relaysStatus[1] != '0'; } catch (WebException ex) { MessageBox.Show("Ошибка! " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } catch (Newtonsoft.Json.JsonException) { MessageBox.Show("Ошибка получения данных!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } //Запись температуры в массивы foreach (var values in ValueTemperature) { valueTemp.Add(values.Value); valueDate.Add(values.Date); } //Запись влажности в массивы foreach (var values in ValueHumidity) { valueHum.Add(values.Value); } //Запись давления в массивы foreach (var values in ValuePressure) { valuePres.Add(values.Value); } //Присваивание значение массивов графику for (int i = 0; i < valueTemp.Count; i++) { SeriesTemperature[0].Values.Add(valueTemp[i]); SeriesHumidity[0].Values.Add(valueHum[i]); SeriesPressure[0].Values.Add(valuePres[i]); Labels.Add(valueDate[i].ToString("dd.MM.yyyy HH:mm (МСК)")); } YFormatterTemperature = value => value.ToString("0.0°"); YFormatterHumidity = value => (value / 100).ToString("#%"); YFormatterPressure = value => value.ToString("0 мм рт столба"); _backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; _backgroundWorker.DoWork += (s, a) => { while (true) { RefreshTemperature(); if (_backgroundWorker.CancellationPending) { break; } Thread.Sleep(30000); } }; _backgroundWorker.RunWorkerAsync(); }
public void RefreshTemperature() { try { ValueTemperature = BackClient.GetEntities <List <ValueParameters> >("json_old_parameters_temp.php"); ValueHumidity = BackClient.GetEntities <List <ValueParameters> >("json_old_parameters_hum.php"); ValuePressure = BackClient.GetEntities <List <ValueParameters> >("json_old_parameters_pres.php"); //Запись температуры в массивы foreach (var values in ValueTemperature) { valueTemp.Add(values.Value); valueDate.Add(values.Date); } //Запись влажности в массивы foreach (var values in ValueHumidity) { valueHum.Add(values.Value); } //Запись давления в массивы foreach (var values in ValuePressure) { valuePres.Add(values.Value); } //Получение текущих значений var valueCurrentTemperature = BackClient.GetEntities <List <ValueParameters> >("json_current_parameters_temp.php"); var valueCurrentHumidity = BackClient.GetEntities <List <ValueParameters> >("json_current_parameters_hum.php"); var valueCurrentPressure = BackClient.GetEntities <List <ValueParameters> >("json_current_parameters_pres.php"); ValueCurrentTemperature = valueCurrentTemperature[0].Value.ToString("0°"); ValueCurrentHumidity = (valueCurrentHumidity[0].Value / 100).ToString("#%"); ValueCurrentPressure = valueCurrentPressure[0].Value.ToString("0 мм рт столба"); //Работа в трее if (Int32.Parse(valueCurrentTemperature[0].Value.ToString()) > 35) { ClosingBehavior.NotifyIcon.BalloonTipText = @"Температура превысила допустимы значения! Температура: " + valueCurrentTemperature[0].Value; ClosingBehavior.NotifyIcon.ShowBalloonTip(1000); } //Обновление графиков if (ValueTemperature.Count > 10) { SeriesTemperature[0].Values.Add(valueTemp.Last()); SeriesHumidity[0].Values.Add(valueHum.Last()); SeriesPressure[0].Values.Add(valuePres.Last()); Labels.Add(valueDate.Last().ToString("dd.MM.yyyy HH:mm (МСК)")); Labels.RemoveAt(0); SeriesTemperature[0].Values.RemoveAt(0); SeriesHumidity[0].Values.RemoveAt(0); SeriesPressure[0].Values.RemoveAt(0); BackClient.SendRequest("http://h92761ae.beget.tech/delete_old_parameter.php?"); } } catch (Exception ex) { MessageBox.Show("Ошибка! " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); _backgroundWorker.CancelAsync(); } }