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 columns = new Dictionary(); columns["event_id"] = typeof(int); columns["event_enum"] = typeof(string); columns["type"] = typeof(string); columns["source"] = typeof(string); columns["description"] = typeof(string); columns["level"] = typeof(string); columns["occur_time"] = typeof(DateTime); DB.CreateTableIfNotExisted("event_data", columns, true, "gid"); } public void WriteEvent(EventItem ev) { string executeInsert = string.Format( @"Insert into ""event_data""(""event_id"",""event_enum"",""type"",""source"",""description"",""level"",""occur_time"") 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 int GetCount(string cmdText) { return DB.GetCount(cmdText); } public List QueryDBEvent(string sql) { List result = new List(); DataSet ds = DB.ExecuteDataset(sql); if (ds == null) return result; try { 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]["event_id"].ToString(), out id)) ev.Id = id; EventType type = EventType.EventUI_Notify; if (Enum.TryParse(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]["event_enum"].ToString(); ev.Description = ds.Tables[0].Rows[i]["description"].ToString(); EventLevel level = EventLevel.Information; if (Enum.TryParse(ds.Tables[0].Rows[i]["level"].ToString(), out level)) ev.Level = level; if (!ds.Tables[0].Rows[i]["occur_time"].Equals(DBNull.Value)) ev.OccuringTime = ((DateTime)ds.Tables[0].Rows[i]["occur_time"]) ; //DateTime dt = (DateTime)ds.Tables[0].Rows[i]["occur_time"]; //if (DateTime.TryParse(ds.Tables[0].Rows[i]["occur_time"].ToString(), out dt )) //ev. = dt; result.Add(ev); } } catch (Exception ex) { LOG.Write(ex); } return result; } } }