123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.DataCenter;
- using OpenSEMI.ClientBase;
- namespace VirgoUI.Client.Models.DataLog.Event
- {
- public class SystemLogItem
- {
-
-
-
- public string Time { get; set; }
-
-
-
- public object Icon { get; set; }
-
-
-
- public string LogType { get; set; }
-
-
-
- public string TargetChamber { get; set; }
-
-
-
- public string Initiator { get; set; }
-
-
-
- public string Detail { get; set; }
- }
-
- public class EventViewModel : BaseModel
- {
- private int MenuPermission;
- public EventViewModel()
- {
- MenuPermission = ClientApp.Instance.GetPermission("EventLog");
- this.DisplayName = "Event";
-
- this.QueryDBEventFunc = (sql) => QueryDataClient.Instance.Service.QueryDBEvent(sql);
-
- this.QueryEventList = () =>
- {
- List<string> result = new List<string>();
- foreach (var eventName in Enum.GetNames(typeof(EventEnum)))
- result.Add(eventName);
- return result;
- };
- var now = DateTime.Today;
- SearchBeginTime = now;
- SearchEndTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
- SelectedUser = "All";
- SearchKeyWords = string.Empty;
- SearchAlarmEvent = true;
- SearchWarningEvent = true;
- SearchInfoEvent = true;
- SearchOpeLog = false;
- SearchPMA = false;
- SearchPMB = false;
- SearchPMC = false;
- SearchPMD = false;
-
- SearchTM = false;
- SearchLL = false;
-
- SearchSystem = false;
- }
- protected override void OnInitialize()
- {
- base.OnInitialize();
- }
- protected override void OnViewLoaded(object _view)
- {
- base.OnViewLoaded(_view);
- this.view = (EventView)_view;
- this.view.wfTimeFrom.Value = this.SearchBeginTime;
- this.view.wfTimeTo.Value = this.SearchEndTime;
- this.Preload();
- }
- public bool SearchAlarmEvent { get; set; }
- public bool SearchWarningEvent { get; set; }
- public bool SearchInfoEvent { get; set; }
- public bool SearchOpeLog { get; set; }
- public bool SearchPMA { get; set; }
- public bool SearchPMB { get; set; }
- public bool SearchPMC { get; set; }
- public bool SearchPMD { get; set; }
-
- public bool SearchTM { get; set; }
- public bool SearchLL { get; set; }
-
- public bool SearchSystem { get; set; }
- public string SearchKeyWords { get; set; }
-
- public DateTime SearchBeginTime { get; set; }
- public DateTime SearchEndTime { get; set; }
- public string Keywords { get; set; }
- public ObservableCollection<string> EventList { get; set; }
- public string SelectedEvent { get; set; }
- public ObservableCollection<string> UserList { get; set; }
- public string SelectedUser { get; set; }
- public ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem> SearchedResult { get; set; }
- public Func<string, List<EventItem>> QueryDBEventFunc { get; set; }
- public Func<List<string>> QueryEventList { get; set; }
-
-
-
-
- public void Preload()
- {
-
- EventList = new ObservableCollection<string>();
- EventList.Add("All");
- if (QueryEventList != null)
- {
- List<string> evList = QueryEventList();
- foreach (string ev in evList)
- EventList.Add(ev);
- }
- SelectedEvent = "All";
-
-
-
-
-
- if (SearchedResult == null)
- Search();
- }
-
-
-
-
- public void Export()
- {
- if (MenuPermission != 3) return;
- try
- {
- Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
- dlg.DefaultExt = ".xls";
- dlg.Filter = "Excel数据表格文件(*.xls)|*.xls";
- Nullable<bool> result = dlg.ShowDialog();
- if (result == true)
- {
- System.Data.DataSet ds = new System.Data.DataSet();
- ds.Tables.Add(new System.Data.DataTable("系统运行日志"));
- ds.Tables[0].Columns.Add("类型");
- ds.Tables[0].Columns.Add("时间");
- ds.Tables[0].Columns.Add("腔体");
- ds.Tables[0].Columns.Add("发起源");
- ds.Tables[0].Columns.Add("内容描述");
- foreach (var item in SearchedResult)
- {
- var row = ds.Tables[0].NewRow();
- row[0] = item.LogType;
- row[1] = item.Time;
- row[2] = item.TargetChamber;
- row[3] = item.Initiator;
- row[4] = item.Detail;
- ds.Tables[0].Rows.Add(row);
- }
- ds.WriteXml(dlg.FileName);
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- MessageBox.Show("导出系统日志发生错误", "导出失败", MessageBoxButton.OK, MessageBoxImage.Warning);
- }
- }
- private string GetSourceWhere()
- {
-
-
-
-
-
-
-
-
- return "";
- }
-
-
-
-
-
- public void Search()
- {
- if (MenuPermission != 3) return;
- Task.Factory.StartNew(() =>
- {
- try
- {
- this.SearchBeginTime = this.view.wfTimeFrom.Value;
- this.SearchEndTime = this.view.wfTimeTo.Value;
- string sqlEvent = "";
- string sqlOperationLog = "";
- string sql = "";
- if (SearchAlarmEvent || SearchWarningEvent || SearchInfoEvent)
- {
- sqlEvent = string.Format("SELECT \"event_id\", \"event_enum\", \"type\", \"occur_time\", \"level\",\"source\" , \"description\" FROM \"event_data\" where \"occur_time\" >='{0}' and \"occur_time\" <='{1}' ", SearchBeginTime.ToString("yyyyMMdd HHmmss"), SearchEndTime.ToString("yyyyMMdd HHmmss"));
- sqlEvent += GetSourceWhere();
- sqlEvent += " and (FALSE ";
- if (SearchAlarmEvent) sqlEvent += " OR \"level\"='Alarm' ";
- if (SearchWarningEvent) sqlEvent += " OR \"level\"='Warning' ";
- if (SearchInfoEvent) sqlEvent += " OR \"level\"='Information' ";
- sqlEvent += " ) ";
- if (!string.IsNullOrWhiteSpace(SelectedEvent) && SelectedEvent != "All") sqlEvent += string.Format(" and lower(\"event_enum\")='{0}' ", SelectedEvent.ToLower());
-
- if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlEvent += string.Format(" and lower(\"description\") like '%{0}%' or lower(\"type\") like '%{1}%'", SearchKeyWords.ToLower(), SearchKeyWords.ToLower());
- }
- if (SearchOpeLog)
- {
-
-
-
-
-
-
-
-
-
-
-
- }
- sql = sqlEvent;
- if (!string.IsNullOrEmpty(sqlOperationLog))
- {
- if (string.IsNullOrEmpty(sql))
- {
- sql = sqlOperationLog;
- }
- else
- {
- sql += " UNION ALL " + sqlOperationLog;
- }
- }
- if (!string.IsNullOrEmpty(sql) && QueryDBEventFunc != null)
- {
- sql += " order by \"occur_time\" DESC limit 2000;";
- List<EventItem> lstEvent = QueryDBEventFunc(sql);
- if (lstEvent == null)
- return;
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
- string logTypeStr;
- foreach (EventItem ev in lstEvent)
- {
- switch (ev.Level)
- {
- case EventLevel.Information: logTypeStr = "Info"; break;
- case EventLevel.Warning: logTypeStr = "Warning"; break;
- case EventLevel.Alarm: logTypeStr = "Alarm"; break;
- default: logTypeStr = "Undefine"; break;
- }
- SearchedResult.Add(new Aitex.Core.UI.View.Common.SystemLogItem()
- {
- Time = ((DateTime)ev.OccuringTime).ToString("yyyy/MM/dd HH:mm:ss.fff"),
- LogType = logTypeStr,
- Detail = ev.Description,
- TargetChamber = ev.Source,
- Initiator = "",
- Icon = new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/SystemLog/{0}.png", ev.Level.ToString()), UriKind.Absolute))
- });
- }
- NotifyOfPropertyChange("SearchedResult");
- if (SearchedResult.Count >= 2000)
- {
-
- }
- }));
- }
- else
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
- NotifyOfPropertyChange("SearchedResult");
- }));
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- });
- }
- private EventView view;
- }
- }
|