123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Aitex.Core.RT.DBCore;
- using System.Data;
- using Aitex.Core.RT.Log;
- namespace Aitex.Core.RT.Event
- {
- class EventDBWriter
- {
- EventDB _db = new EventDB();
- public void Initialize()
- {
- Dictionary<string, Type> columns = new Dictionary<string,Type>();
- columns["ID"] = typeof(int);
- columns["EventEnum"] = typeof(string);
- columns["Type"] = typeof(string);
- columns["Source"] = typeof(string);
- columns["Description"] = typeof(string);
- columns["Level"] = typeof(string);
- columns["OccurTime"] = typeof(DateTime);
- DB.CreateTableIfNotExisted("EventManager", columns, true, "PID");
- }
- public void WriteEvent(EventItem ev)
- {
- string executeInsert = string.Format(
- @"Insert into ""EventManager""(""ID"",""EventEnum"",""Type"",""Source"",""Description"",""Level"",""OccurTime"") values({0},'{1}','{2}','{3}','{4}','{5}','{6}')",
- ev.Id, ev.EventEnum, ev.Type.ToString(), ev.Source, ev.Description.Replace("'", "''"), ev.Level.ToString(), ev.OccuringTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
- DB.Insert(executeInsert);
- }
- public List<EventItem> QueryDBEvent(string sql)
- {
- List<EventItem> result = new List<EventItem>();
- DataSet ds = DB.ExecuteDataset(sql);
- if (ds == null)
- return result;
- for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
- {
- EventItem ev = new EventItem();
- int id = 0;
- if (int.TryParse(ds.Tables[0].Rows[i]["ID"].ToString(), out id ))
- ev.Id = id;
- EventType type = EventType.EventUI_Notify;
- if (Enum.TryParse<EventType>(ds.Tables[0].Rows[i]["Type"].ToString(), out type))
- ev.Type = type;
- ev.Source = ds.Tables[0].Rows[i]["Source"].ToString();
- ev.EventEnum = ds.Tables[0].Rows[i]["EventEnum"].ToString();
- ev.Description = ds.Tables[0].Rows[i]["Description"].ToString();
- EventLevel level = EventLevel.Information;
- if (Enum.TryParse<EventLevel>(ds.Tables[0].Rows[i]["Level"].ToString(), out level))
- ev.Level = level;
- var row = ds.Tables[0].Rows[i]["OccurTime"];
- if (row != null && !row.Equals(DBNull.Value))
- ev.OccuringTime = ((DateTime)row);
- result.Add(ev);
- }
- return result;
- }
- }
- }
|