//获取DatabaseManager的实例 public static DataBaseManager GetDataBaseManager() { if (manager == null) // 对象未初始化 { manager = new DataBaseManager(); manager.Init(connectString); } return(manager); }
/// <summary> /// 初始化数据 /// </summary> /// <param name="canvas">绘图板实例</param> /// <param name="propertyGrid">属性面板实例</param> public void Init(Canvas canvas) { graphManager = new GraphManager(this, canvas); dataManager = new DataManager(this); dataBaseManager = DataBaseManager.GetDataBaseManager(); int i = path.IndexOf('\\'); mapName = path.Substring(0, i); flowChartInteractor = new FlowChartInteractor(); }
/// <summary> /// 重载数据 /// </summary> public void Reload() { string sqlString = string.Format("SELECT Top 25 * FROM DiagramLog ORDER BY OperateTime DESC"); DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager(); logTable = dataBaseManager.GetDataTable(sqlString); // 加载数据行 dataGridViewX1.Rows.Clear(); int index = 0; List <string> userList = new List <string>(); userList.Add("所有用户"); List <string> operationList = new List <string>(); operationList.Add("所有操作"); foreach (DataRow row in logTable.Rows) { dataGridViewX1.Rows.Add(1); DataGridViewRow newRow = dataGridViewX1.Rows[index]; string hostName = row["HostName"].ToString(); string operation = row["Operation"].ToString(); newRow.Cells["HostName"].Value = hostName; newRow.Cells["Operation"].Value = operation; newRow.Cells["OperateTime"].Value = row["OperateTime"].ToString(); newRow.Cells["Success"].Value = row["Success"].ToString(); newRow.Cells["Description"].Value = row["Description"].ToString(); if (!userList.Contains(hostName)) { userList.Add(hostName); } if (!operationList.Contains(operation)) { operationList.Add(operation); } index++; } // 添加下拉框内容 comboBoxEx1.Items.Clear(); comboBoxEx1.Items.AddRange(userList.ToArray()); comboBoxEx1.SelectedIndex = 0; comboBoxEx2.Items.Clear(); comboBoxEx2.Items.AddRange(operationList.ToArray()); comboBoxEx2.SelectedIndex = 0; dateTimeInput1.Value = DateTime.Now.AddDays(-1); dateTimeInput2.Value = DateTime.Now; }
/// <summary> /// 初始化子绘图数据表 /// </summary> private void InitGraphTable() { if (!string.IsNullOrEmpty(innerChartPath)) { DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager(); string fullPath = string.Format(@"子绘图\{0}", innerChartPath); Hashtable infoTable = dataBaseManager.GetDiagramDataByPath(fullPath, "AI图") as Hashtable; if (infoTable != null) { Hashtable logicData = infoTable["logicData"] as Hashtable; graphTable = logicData["graphTable"] as Hashtable; } } }
/// <summary> /// 保存日志 /// </summary> /// <param name="operation">当前操作</param> /// <param name="description">操作描述</param> /// <param name="success">是否操作成功</param> public void SaveLog(string operation, string description, bool success) { string hostName = Dns.GetHostName(); string strSuccess = "0"; if (success) { strSuccess = "1"; } string sqlString = string.Format("INSERT INTO {0} ([HostName], [Operation], [OperateTime], [Success], [Description]) VALUES ('{1}', '{2}', GetDate(), {3}, '{4}')", logTableName, hostName, operation, strSuccess, description); DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager(); dataBaseManager.ExecuteSqlCommand(sqlString); }
/// <summary> /// 过滤日志 /// </summary> /// <param name="sender">事件发送者</param> /// <param name="e">事件参数</param> private void buttonX1_Click(object sender, EventArgs e) { string hostName = comboBoxEx1.Text; string selectHostString = string.Format("HostName = '{0}'", hostName); if (hostName == "所有用户") { selectHostString = ""; } string operation = comboBoxEx2.Text; string selectOperationString = string.Format("Operation = '{0}'", operation); if (operation == "所有操作") { selectOperationString = ""; } DateTime startTime = dateTimeInput1.Value; startTime = startTime.AddHours(-dateTimeInput1.Value.Hour); startTime = startTime.AddMinutes(-dateTimeInput1.Value.Minute); startTime = startTime.AddSeconds(-dateTimeInput1.Value.Second); DateTime endTime = dateTimeInput2.Value; endTime = endTime.AddHours(23 - dateTimeInput2.Value.Hour); endTime = endTime.AddMinutes(59 - dateTimeInput2.Value.Minute); endTime = endTime.AddSeconds(59 - dateTimeInput2.Value.Second); string selectString = string.Format("SELECT * FROM DiagramLog WHERE OperateTime >= '{0}' AND OperateTime <= '{1}'", startTime, endTime); if (selectHostString != "") { selectString += string.Format(" AND {0}", selectHostString); } if (selectOperationString != "") { selectString += string.Format(" AND {0}", selectOperationString); } DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager(); logTable = dataBaseManager.GetDataTable(selectString); // 加载数据行 dataGridViewX1.Rows.Clear(); int index = 0; foreach (DataRow row in logTable.Rows) { dataGridViewX1.Rows.Add(1); DataGridViewRow newRow = dataGridViewX1.Rows[index]; newRow.Cells["HostName"].Value = row["HostName"].ToString(); newRow.Cells["Operation"].Value = row["Operation"].ToString(); newRow.Cells["OperateTime"].Value = row["OperateTime"].ToString(); newRow.Cells["Success"].Value = row["Success"].ToString(); newRow.Cells["Description"].Value = row["Description"].ToString(); index++; } }