/// <summary> /// 将DataRedar转换为List /// </summary> private List <Data.Model.Log> DataReaderToList(SqlDataReader dataReader) { List <Data.Model.Log> List = new List <Data.Model.Log>(); Data.Model.Log model = null; while (dataReader.Read()) { model = new Data.Model.Log(); model.ID = dataReader.GetGuid(0); model.Title = dataReader.GetString(1); model.Type = dataReader.GetString(2); model.WriteTime = dataReader.GetDateTime(3); if (!dataReader.IsDBNull(4)) { model.UserID = dataReader.GetGuid(4); } if (!dataReader.IsDBNull(5)) { model.UserName = dataReader.GetString(5); } if (!dataReader.IsDBNull(6)) { model.IPAddress = dataReader.GetString(6); } if (!dataReader.IsDBNull(7)) { model.URL = dataReader.GetString(7); } if (!dataReader.IsDBNull(8)) { model.Contents = dataReader.GetString(8); } if (!dataReader.IsDBNull(9)) { model.Others = dataReader.GetString(9); } if (!dataReader.IsDBNull(10)) { model.OldXml = dataReader.GetString(10); } if (!dataReader.IsDBNull(11)) { model.NewXml = dataReader.GetString(11); } List.Add(model); } return(List); }
/// <summary> /// 记录日志 /// </summary> /// <param name="err"></param> public static void Add(string title, string contents, Types type = Types.其它分类, Data.Model.Users user = null) { if (user == null) { user = Platform.Users.CurrentUser; } Data.Model.Log log = new Data.Model.Log(); log.Contents = contents; log.ID = Guid.NewGuid(); log.IPAddress = Utility.Tools.GetIPAddress(); log.Others = string.Format("操作系统:{0} 浏览器:{1}", Utility.Tools.GetOSName(), Utility.Tools.GetBrowse()); log.Title = title; log.Type = type.ToString(); log.URL = System.Web.HttpContext.Current.Request.Url.ToString(); if (user != null) { log.UserID = user.ID; log.UserName = user.Name; } log.WriteTime = Utility.Tools.DateTime; Add(log); }
/// <summary> /// 添加记录 /// </summary> /// <param name="model">Data.Model.Log实体类</param> /// <returns>操作所影响的行数</returns> public int Add(Data.Model.Log model) { string sql = @"INSERT INTO Log (ID,Title,Type,WriteTime,UserID,UserName,IPAddress,URL,Contents,Others,OldXml,NewXml) VALUES(@ID,@Title,@Type,@WriteTime,@UserID,@UserName,@IPAddress,@URL,@Contents,@Others,@OldXml,@NewXml)" ; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.UniqueIdentifier, -1) { Value = model.ID }, new SqlParameter("@Title", SqlDbType.NVarChar, -1) { Value = model.Title }, new SqlParameter("@Type", SqlDbType.NVarChar, 100) { Value = model.Type }, new SqlParameter("@WriteTime", SqlDbType.DateTime, 8) { Value = model.WriteTime }, model.UserID == null ? new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, -1) { Value = DBNull.Value } : new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, -1) { Value = model.UserID }, model.UserName == null ? new SqlParameter("@UserName", SqlDbType.NVarChar, 100) { Value = DBNull.Value } : new SqlParameter("@UserName", SqlDbType.NVarChar, 100) { Value = model.UserName }, model.IPAddress == null ? new SqlParameter("@IPAddress", SqlDbType.VarChar, 50) { Value = DBNull.Value } : new SqlParameter("@IPAddress", SqlDbType.VarChar, 50) { Value = model.IPAddress }, model.URL == null ? new SqlParameter("@URL", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@URL", SqlDbType.VarChar, -1) { Value = model.URL }, model.Contents == null ? new SqlParameter("@Contents", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@Contents", SqlDbType.VarChar, -1) { Value = model.Contents }, model.Others == null ? new SqlParameter("@Others", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@Others", SqlDbType.VarChar, -1) { Value = model.Others }, model.OldXml == null ? new SqlParameter("@OldXml", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@OldXml", SqlDbType.VarChar, -1) { Value = model.OldXml }, model.NewXml == null ? new SqlParameter("@NewXml", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@NewXml", SqlDbType.VarChar, -1) { Value = model.NewXml } }; return(dbHelper.Execute(sql, parameters)); }
/// <summary> /// 更新记录 /// </summary> /// <param name="model">Data.Model.Log实体类</param> public int Update(Data.Model.Log model) { string sql = @"UPDATE Log SET Title=@Title,Type=@Type,WriteTime=@WriteTime,UserID=@UserID,UserName=@UserName,IPAddress=@IPAddress,URL=@URL,Contents=@Contents,Others=@Others,OldXml=@OldXml,NewXml=@NewXml WHERE ID=@ID" ; SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Title", SqlDbType.NVarChar, -1) { Value = model.Title }, new SqlParameter("@Type", SqlDbType.NVarChar, 100) { Value = model.Type }, new SqlParameter("@WriteTime", SqlDbType.DateTime, 8) { Value = model.WriteTime }, model.UserID == null ? new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, -1) { Value = DBNull.Value } : new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, -1) { Value = model.UserID }, model.UserName == null ? new SqlParameter("@UserName", SqlDbType.NVarChar, 100) { Value = DBNull.Value } : new SqlParameter("@UserName", SqlDbType.NVarChar, 100) { Value = model.UserName }, model.IPAddress == null ? new SqlParameter("@IPAddress", SqlDbType.VarChar, 50) { Value = DBNull.Value } : new SqlParameter("@IPAddress", SqlDbType.VarChar, 50) { Value = model.IPAddress }, model.URL == null ? new SqlParameter("@URL", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@URL", SqlDbType.VarChar, -1) { Value = model.URL }, model.Contents == null ? new SqlParameter("@Contents", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@Contents", SqlDbType.VarChar, -1) { Value = model.Contents }, model.Others == null ? new SqlParameter("@Others", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@Others", SqlDbType.VarChar, -1) { Value = model.Others }, model.OldXml == null ? new SqlParameter("@OldXml", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@OldXml", SqlDbType.VarChar, -1) { Value = model.OldXml }, model.NewXml == null ? new SqlParameter("@NewXml", SqlDbType.VarChar, -1) { Value = DBNull.Value } : new SqlParameter("@NewXml", SqlDbType.VarChar, -1) { Value = model.NewXml }, new SqlParameter("@ID", SqlDbType.UniqueIdentifier, -1) { Value = model.ID } }; return(dbHelper.Execute(sql, parameters)); }
/// <summary> /// 新增 /// </summary> public static void Add(Data.Model.Log model) { dgWriteLog wl = new dgWriteLog(add); wl.BeginInvoke(model, null, null); }
/// <summary> /// 新增 /// </summary> private static void add(Data.Model.Log model) { dataLog1.Add(model); }
/// <summary> /// 更新 /// </summary> public int Update(Data.Model.Log model) { return(dataLog.Update(model)); }