123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Data;
- using System.Linq;
- using System.Windows;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Client.ClientBase;
- using OpenSEMI.ClientBase;
- using SciChart.Core.Extensions;
- namespace EfemDualUI.Views.History.Statistics
- {
- public class StatsDataListItem : NotifiableItem
- {
- public string Name { get; set; }
- public string Value { get; set; }
- public string Description { get; set; }
- public string Total { get; set; }
- public string LastUpdateTime { get; set; }
- public string LastResetTime { get; set; }
- public string LastResetTotalTime { get; set; }
- public string WarningValue { get; set; }
- public string WarningValueSetPoint { get; set; }
- public bool WarningEnable { get; set; }
- public string AlarmValue { get; set; }
- public string AlarmValueSetPoint { get; set; }
- public bool AlarmEnable { get; set; }
- public bool AlarmTextSaved { get; set; }
- public bool WarningTextSaved { get; set; }
- public bool IsVisible { get; set; }
- }
- public class StatsDataListItemRFAndPump : NotifiableItem
- {
- public string Name { get; set; }
- public string Description { get; set; }
- public string LastPMTime { get; set; }
- public string fromLastPM { get; set; }
- public string Total { get; set; }
- public string PMInterval { get; set; }
- public string PMIntervalSetPoint { get; set; }
- public bool AlarmEnable { get; set; }
- public bool PMIntervalTextSaved { get; set; }
- }
- public class StatisticsViewModel : UiViewModelBase
- {
- private int MenuPermission;
- public ObservableCollection<StatsDataListItem> StatData
- {
- get;
- set;
- }
- public ObservableCollection<StatsDataListItemRFAndPump> StatDataRFAndPump
- {
- get;
- set;
- }
- protected override void OnInitialize()
- {
- StatData = new ObservableCollection<StatsDataListItem>();
- StatDataRFAndPump = new ObservableCollection<StatsDataListItemRFAndPump>();
- base.OnInitialize();
- }
- protected override void OnActivate()
- {
- base.OnActivate();
- }
- protected override void OnDeactivate(bool close)
- {
- base.OnDeactivate(close);
- }
- protected override void Poll()
- {
- try
- {
- MenuPermission = ClientApp.Instance.GetPermission("Statistics");
- string sql = $"SELECT * FROM \"stats_data\" order by \"name\" ASC;";
- DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- if (dbData == null || dbData.Rows.Count == 0)
- return;
- string[] clearedNameList = Array.ConvertAll<StatsDataListItem, string>(StatData.ToArray(), x => x.Name);
- List<string> removableList = new List<string>();
- if (clearedNameList.Length > 0)
- removableList = clearedNameList.ToList();
- for (int i = 0; i < dbData.Rows.Count; i++)
- {
- if (!dbData.Rows[i]["is_visible"].Equals(DBNull.Value) && !Convert.ToBoolean(dbData.Rows[i]["is_visible"].ToString()))
- continue;
- string name = dbData.Rows[i]["name"].ToString();
- removableList.RemoveIfContains(name);
- StatsDataListItem item = StatData.FirstOrDefault(x => x.Name == name);
- if (item == null)
- {
- item = new StatsDataListItem();
- item.Name = dbData.Rows[i]["name"].ToString();
- item.AlarmEnable = false;
- item.WarningEnable = false;
- item.IsVisible = true;
- item.AlarmTextSaved = true;
- item.WarningTextSaved = true;
- item.AlarmValueSetPoint = dbData.Rows[i]["alarm_value"].ToString();
- item.WarningValueSetPoint = dbData.Rows[i]["warning_value"].ToString();
- StatData.Add(item);
- }
-
- item.Description = dbData.Rows[i]["description"].ToString();
- item.Value = dbData.Rows[i]["value"].ToString();
- item.Total = dbData.Rows[i]["total"].ToString();
- if (!dbData.Rows[i]["enable_warning"].Equals(DBNull.Value))
- item.WarningEnable = Convert.ToBoolean(dbData.Rows[i]["enable_warning"].ToString());
- item.WarningValue = dbData.Rows[i]["warning_value"].ToString();
- if (!dbData.Rows[i]["enable_alarm"].Equals(DBNull.Value))
- item.AlarmEnable = Convert.ToBoolean(dbData.Rows[i]["enable_alarm"].ToString());
- item.AlarmValue = dbData.Rows[i]["alarm_value"].ToString();
- if (!dbData.Rows[i]["last_update_time"].Equals(DBNull.Value))
- item.LastUpdateTime = ((DateTime)dbData.Rows[i]["last_update_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
- if (!dbData.Rows[i]["last_reset_time"].Equals(DBNull.Value))
- item.LastResetTime = ((DateTime)dbData.Rows[i]["last_reset_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
- if (!dbData.Rows[i]["last_total_reset_time"].Equals(DBNull.Value))
- item.LastResetTotalTime = ((DateTime)dbData.Rows[i]["last_total_reset_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
- item.InvokePropertyChanged(nameof(item.AlarmValue));
- item.InvokePropertyChanged(nameof(item.WarningValue));
- item.InvokePropertyChanged(nameof(item.Value));
- item.InvokePropertyChanged(nameof(item.Total));
- item.InvokePropertyChanged(nameof(item.LastUpdateTime));
- item.InvokePropertyChanged(nameof(item.LastResetTime));
- item.InvokePropertyChanged(nameof(item.LastResetTotalTime));
- }
- foreach (var name in removableList)
- {
- StatsDataListItem item = StatData.FirstOrDefault(x => x.Name == name);
- if (item != null)
- StatData.Remove(item);
- }
- }));
- string sqlrfpump = $"SELECT * FROM \"stats_data_rf_pump\" order by \"name\" ASC;";
- DataTable dbDataRFPump = QueryDataClient.Instance.Service.QueryData(sqlrfpump);
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- if (dbDataRFPump == null || dbDataRFPump.Rows.Count == 0)
- return;
- string[] clearedNameList = Array.ConvertAll<StatsDataListItemRFAndPump, string>(StatDataRFAndPump.ToArray(), x => x.Name);
- List<string> removableList = new List<string>();
- if (clearedNameList.Length > 0)
- removableList = clearedNameList.ToList();
- for (int i = 0; i < dbDataRFPump.Rows.Count; i++)
- {
- string name = dbDataRFPump.Rows[i]["name"].ToString();
- removableList.RemoveIfContains(name);
- StatsDataListItemRFAndPump item = StatDataRFAndPump.FirstOrDefault(x => x.Name == name);
- if (item == null)
- {
- item = new StatsDataListItemRFAndPump();
- item.Name = dbDataRFPump.Rows[i]["name"].ToString();
- item.AlarmEnable = false;
- item.PMIntervalTextSaved = true;
- item.PMIntervalSetPoint = dbDataRFPump.Rows[i]["pm_interval"].ToString();
- StatDataRFAndPump.Add(item);
- }
- item.Description = dbDataRFPump.Rows[i]["description"].ToString();
- if (!dbDataRFPump.Rows[i]["enable_alarm"].Equals(DBNull.Value))
- item.AlarmEnable = Convert.ToBoolean(dbDataRFPump.Rows[i]["enable_alarm"].ToString());
- item.fromLastPM = dbDataRFPump.Rows[i]["from_last_pm"].ToString();
- item.PMInterval = dbDataRFPump.Rows[i]["pm_interval"].ToString();
- item.Total = dbDataRFPump.Rows[i]["total"].ToString();
- if (!dbDataRFPump.Rows[i]["last_pm_time"].Equals(DBNull.Value))
- item.LastPMTime = ((DateTime)dbDataRFPump.Rows[i]["last_pm_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
- item.InvokePropertyChanged(nameof(item.Name));
- item.InvokePropertyChanged(nameof(item.AlarmEnable));
- item.InvokePropertyChanged(nameof(item.Description));
- item.InvokePropertyChanged(nameof(item.Total));
- item.InvokePropertyChanged(nameof(item.fromLastPM));
- item.InvokePropertyChanged(nameof(item.PMInterval));
- item.InvokePropertyChanged(nameof(item.LastPMTime));
- }
- foreach (var name in removableList)
- {
- StatsDataListItemRFAndPump item = StatDataRFAndPump.FirstOrDefault(x => x.Name == name);
- if (item != null)
- StatDataRFAndPump.Remove(item);
- }
- }));
- }
- catch (Exception e)
- {
- LOG.Write(e);
- }
- }
- public void ResetValue(StatsDataListItem item)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.Stats.ResetValue", item.Name);
- }
- public void ResetEnableAlarm(StatsDataListItem item)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.Stats.EnableAlarm", item.Name, item.AlarmEnable);
- }
- public void ResetEnableWarning(StatsDataListItem item)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.Stats.EnableWarning", item.Name, item.WarningEnable);
- }
- public void SetAlarmValue(StatsDataListItem item)
- {
- if (MenuPermission != 3) return;
- if (string.IsNullOrEmpty(item.AlarmValueSetPoint) ||
- !int.TryParse(item.AlarmValueSetPoint, out int setValue))
- {
- DialogBox.ShowWarning("Alarm value not valid");
- return;
- }
- InvokeClient.Instance.Service.DoOperation("System.Stats.SetAlarmValue", item.Name, setValue);
- item.AlarmTextSaved = true;
- item.InvokePropertyChanged(nameof(item.AlarmTextSaved));
- }
- public void SetWarningValue(StatsDataListItem item)
- {
- if (MenuPermission != 3) return;
- if (string.IsNullOrEmpty(item.WarningValueSetPoint) ||
- !int.TryParse(item.WarningValueSetPoint, out int setValue))
- {
- DialogBox.ShowWarning("Warning value not valid");
- return;
- }
- InvokeClient.Instance.Service.DoOperation("System.Stats.SetWarningValue", item.Name, setValue);
- item.WarningTextSaved = true;
- item.InvokePropertyChanged(nameof(item.WarningTextSaved));
- }
-
- public void ResetTotalValue(StatsDataListItem item)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.Stats.ResetTotalValue", item.Name);
- }
- public void ResetTimeValue(StatsDataListItemRFAndPump item)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.StatsRFAndPump.ResetValue", item.Name);
- }
- public void ResetRFEnableAlarm(StatsDataListItemRFAndPump item)
- {
- if (MenuPermission != 3) return;
- InvokeClient.Instance.Service.DoOperation("System.StatsRFAndPump.EnableAlarm", item.Name, item.AlarmEnable);
- }
- public void SetPMIntervalValue(StatsDataListItemRFAndPump item)
- {
- if (MenuPermission != 3) return;
- if (string.IsNullOrEmpty(item.PMIntervalSetPoint) ||
- !int.TryParse(item.PMIntervalSetPoint, out int setValue))
- {
- DialogBox.ShowWarning("PM Interval value not valid");
- return;
- }
- InvokeClient.Instance.Service.DoOperation("System.StatsRFAndPump.SetPMIntervalValue", item.Name, setValue);
- item.PMIntervalTextSaved = true;
- item.InvokePropertyChanged(nameof(item.PMIntervalTextSaved));
- }
- }
- }
|