using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; using System.Xml; using System.Data; using System.IO; using ICSharpCode.Core; using Mesnac.Basic; using Mesnac.Equips; using Mesnac.Codd.Session; using Mesnac.Action.Base; namespace Mesnac.Action.Default { /// /// 默认Action /// public class DefaultAction : DatabaseAction { #region 操作日志 /// /// 数据库日志记录 /// /// 班次Id /// 班次 /// 班组Id /// 班组 /// 用户GUID /// 用户名 /// 窗体GUID /// 窗体文本 /// 功能GUID /// 功能文本 /// 执行结果 /// 操作类型 /// 操作描述 /// 备注 public void DBLog(int shiftId, string shiftName, int classId, string className, string userGUId, string userName, string formGUID, string formText, string functionGUID, string functionText, string performResult, string worktype, string operdest, string remark) { try { DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.Error("获取本地数据连接失败..."); return; } dbHelper.ClearParameter(); dbHelper.CommandType = CommandType.Text; string sqlstr = @"INSERT INTO SysLog(GUID,ShiftID,ShiftName,ClassID,ClassName,UserGUID,UserName,FormGUID,FormText,FunctionGUID,FunctionText,PerformResult,WorkType,OperDest,Remark,RecordTime,IsUpFlag) VALUES(@GUID,@ShiftID,@ShiftName,@ClassID,@ClassName,@UserGUID,@UserName,@FormGUID,@FormText,@FunctionGUID,@FunctionText,@PerformResult,@WorkType,@OperDest,@Remark,@RecordTime,@IsUpFlag)"; dbHelper.CommandText = sqlstr; dbHelper.AddParameter("@GUID", Guid.NewGuid().ToString().ToUpper()); dbHelper.AddParameter("@ShiftName", shiftName); dbHelper.AddParameter("@ShiftID", shiftId); dbHelper.AddParameter("@ClassID", classId); dbHelper.AddParameter("@ClassName", className); dbHelper.AddParameter("@UserGUID", userGUId); dbHelper.AddParameter("@UserName", userName); dbHelper.AddParameter("@FormGUID", formGUID); dbHelper.AddParameter("@FormText", formText); dbHelper.AddParameter("@FunctionGUID", functionGUID); dbHelper.AddParameter("@FunctionText", functionText); dbHelper.AddParameter("@PerformResult", performResult); dbHelper.AddParameter("@WorkType", worktype); dbHelper.AddParameter("@OperDest", operdest); dbHelper.AddParameter("@Remark", remark); dbHelper.AddParameter("@RecordTime", DateTime.Now); dbHelper.AddParameter("@IsUpFlag", 0); dbHelper.ExecuteNonQuery(); } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("数据库日志记录异常:" + ex.Message, ex); } } /// /// 数据库日志记录 /// /// 班次Id /// 班次 /// 班组Id /// 班组 /// 窗体GUID /// 窗体文本 /// 功能GUID /// 功能文本 /// 执行结果 /// 操作类型 /// 操作描述 /// 备注 public void DBLog(int shiftId, string shiftName, int classId, string className, string formGUID, string formText, string functionGUID, string functionText, string performResult, string worktype, string operdest, string remark) { DBLog(shiftId, shiftName, classId, className, Mesnac.Basic.UserInfo.Instance.UserGUID, Mesnac.Basic.UserInfo.Instance.UserName, formGUID, formText, functionGUID, functionText, performResult, worktype, operdest, remark); } /// /// 数据库日志记录 /// /// 班次Id /// 班次 /// 班组Id /// 班组 /// 窗体GUID /// 窗体文本 /// 功能GUID /// 功能文本 /// 执行结果 public void DBLog(int shiftId, string shiftName, int classId, string className, string formGUID, string formText, string functionGUID, string functionText, string performResult) { DBLog(shiftId, shiftName, classId, className, Mesnac.Basic.UserInfo.Instance.UserGUID, Mesnac.Basic.UserInfo.Instance.UserName, formGUID, formText, functionGUID, functionText, performResult, formText, functionText, String.Empty); } /// /// 数据库日志记录 /// /// 窗体GUID /// 窗体文本 /// 功能GUID /// 功能文本 /// 执行结果 /// 操作类型 /// 操作描述 /// 备注 public void DBLog(string formGUID, string formText, string functionGUID, string functionText, string performResult, string worktype, string operdest, string remark) { int shiftId = GetSysValue("PlanLog.CurrentShiftID", 0); //获取当前班次 string shiftName = GetSysValue("PlanLog.CurrentShiftName", String.Empty); //获取当前班次名称 int classId = Mesnac.Basic.UserInfo.Instance.ClassID; //获取当前班组 string className = GetSysValue("PlanLog.CurrentClassName", String.Empty); //获取当前班组名称 DBLog(shiftId, shiftName, classId, className, Mesnac.Basic.UserInfo.Instance.UserGUID, Mesnac.Basic.UserInfo.Instance.UserName, formGUID, formText, functionGUID, functionText, performResult, worktype, operdest, remark); } /// /// 数据库日志记录 /// /// 窗体GUID /// 窗体文本 /// 功能GUID /// 功能文本 /// 执行结果 /// 操作类型 public void DBLog(string formGUID, string formText, string functionGUID, string functionText, string performResult, string worktype) { DBLog(formGUID, formText, functionGUID, functionText, performResult, worktype, formText, functionText); } /// /// 数据库日志记录 /// /// 窗体GUID /// 窗体文本 /// 功能GUID /// 功能文本 public void DBLog(string formGUID, string formText, string functionGUID, string functionText) { DBLog(formGUID, formText, functionGUID, functionText, formText, functionText); } /// /// 数据库日志记录 /// /// 操作类别 /// 日志标题 /// 日志内容 public void DBLog(string operateType, string caption, string content) { DBLog(this.FormGUID, this.FormText, this.FunctionGUID, this.FunctionText, String.Empty, operateType, caption, content); } /// /// 数据库日志记录 /// /// 日志内容 public void DBLog(string content) { DBLog(this.FormGUID, this.FormText, this.FunctionGUID, this.FunctionText, String.Empty, this.FormText, this.FunctionText, content); } #endregion #region 字典获取 #region 字典判断 /// /// 判断SysKeyValue中是否存在对应key的记录 /// /// 要检索的key /// 存在返回true,否则返回false public bool ExistsKey(string key) { try { DbHelper localHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(DataSourceFactory.MCDbType.Local); if (localHelper == null) { ICSharpCode.Core.LoggingService.Error("获取SysKeyValue表中对应键的值失败:获取本地数据连接失败!"); return false; } localHelper.CommandType = CommandType.Text; localHelper.ClearParameter(); string strSql = "select count(1) from SysKeyValue where ssKey = @ssKey"; localHelper.CommandText = strSql; localHelper.AddParameter("@ssKey", key); object result = localHelper.ToScalar(); if (result == null || result == System.DBNull.Value || Convert.ToInt32(result) <= 0) { return false; } else { return true; } } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("获取SysKeyValue表中对应键的值失败:" + ex.Message, ex); return false; } } #endregion #region 获取值 /// /// 获取本地库SysKeyValue表中对应键的值 /// /// 要查找的键 /// 返回对应键的值,获取失败返回String.Empty public string GetSysValue(string key) { try { DbHelper localHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(DataSourceFactory.MCDbType.Local); if (localHelper == null) { ICSharpCode.Core.LoggingService.Error("获取SysKeyValue表中对应键的值失败:获取本地数据连接失败!"); return String.Empty; } localHelper.CommandType = CommandType.Text; localHelper.ClearParameter(); string strSql = "select top 1 ssValue from SysKeyValue where ssKey = @ssKey"; localHelper.CommandText = strSql; localHelper.AddParameter("@ssKey", key); object result = localHelper.ToScalar(); if (result == null || result == System.DBNull.Value) { return String.Empty; } else { return result.ToString(); } } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("获取SysKeyValue表中对应键的值失败:" + ex.Message, ex); return String.Empty; } } /// /// 字典获取string重载 /// /// /// /// public string GetSysValue(string key, string defaultValue) { if (ExistsKey(key)) { string value = GetSysValue(key); if (String.IsNullOrEmpty(value)) { return defaultValue; } else { return value; } } else { return defaultValue; } } /// /// 字典获取int重载 /// /// /// /// public int GetSysValue(string key, int defaultValue) { if (ExistsKey(key)) { string strValue = GetSysValue(key); int intValue = defaultValue; if (int.TryParse(strValue, out intValue)) { return intValue; } else { return defaultValue; } } else { return defaultValue; } } /// /// 字典获取bool重载 /// /// /// /// public bool GetSysValue(string key, bool defaultValue) { if (ExistsKey(key)) { string strValue = GetSysValue(key); bool boolValue = defaultValue; if (bool.TryParse(strValue, out boolValue)) { return boolValue; } else { return defaultValue; } } else { return defaultValue; } } /// /// 字典获取float重载 /// /// /// /// public float GetSysValue(string key, float defaultValue) { if (ExistsKey(key)) { string strValue = GetSysValue(key); float floatValue = defaultValue; if (float.TryParse(strValue, out floatValue)) { return floatValue; } else { return defaultValue; } } else { return defaultValue; } } /// /// 字典获取double重载 /// /// /// /// public double GetSysValue(string key, double defaultValue) { if (ExistsKey(key)) { string strValue = GetSysValue(key); double doubleValue = defaultValue; if (double.TryParse(strValue, out doubleValue)) { return doubleValue; } else { return defaultValue; } } else { return defaultValue; } } #endregion #endregion } }