RoadFlow2.1 临时演示

Log.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace RoadFlow.Platform
  5. {
  6. public class Log
  7. {
  8. private RoadFlow.Data.Interface.ILog dataLog;
  9. private static RoadFlow.Data.Interface.ILog dataLog1 = Data.Factory.Factory.GetLog();
  10. private delegate void dgWriteLog(RoadFlow.Data.Model.Log log);
  11. public Log()
  12. {
  13. this.dataLog = dataLog1;
  14. }
  15. /// <summary>
  16. /// 更新
  17. /// </summary>
  18. public int Update(RoadFlow.Data.Model.Log model)
  19. {
  20. return dataLog.Update(model);
  21. }
  22. /// <summary>
  23. /// 查询所有记录
  24. /// </summary>
  25. public List<RoadFlow.Data.Model.Log> GetAll()
  26. {
  27. return dataLog.GetAll();
  28. }
  29. /// <summary>
  30. /// 查询单条记录
  31. /// </summary>
  32. public RoadFlow.Data.Model.Log Get(Guid id)
  33. {
  34. return dataLog.Get(id);
  35. }
  36. /// <summary>
  37. /// 删除
  38. /// </summary>
  39. public int Delete(Guid id)
  40. {
  41. return dataLog.Delete(id);
  42. }
  43. /// <summary>
  44. /// 查询记录条数
  45. /// </summary>
  46. public long GetCount()
  47. {
  48. return dataLog.GetCount();
  49. }
  50. public enum Types
  51. {
  52. 组织机构,
  53. 用户登录,
  54. 角色应用,
  55. 数据字典,
  56. 流程相关,
  57. 系统错误,
  58. 其它分类
  59. }
  60. /// <summary>
  61. /// 新增
  62. /// </summary>
  63. private static void add(RoadFlow.Data.Model.Log model)
  64. {
  65. dataLog1.Add(model);
  66. }
  67. /// <summary>
  68. /// 新增
  69. /// </summary>
  70. public static void Add(RoadFlow.Data.Model.Log model)
  71. {
  72. dgWriteLog wl = new dgWriteLog(add);
  73. wl.BeginInvoke(model, null, null);
  74. }
  75. /// <summary>
  76. /// 记录日志
  77. /// </summary>
  78. /// <param name="err"></param>
  79. public static void Add(string title, string contents, Types type = Types.其它分类, string oldXML = "", string newXML = "", RoadFlow.Data.Model.Users user = null)
  80. {
  81. if (user == null)
  82. {
  83. user = Platform.Users.CurrentUser;
  84. }
  85. RoadFlow.Data.Model.Log log = new RoadFlow.Data.Model.Log();
  86. log.Contents = contents;
  87. log.ID = Guid.NewGuid();
  88. log.IPAddress = RoadFlow.Utility.Tools.GetIPAddress();
  89. log.Others = string.Format("操作系统:{0} 浏览器:{1}", RoadFlow.Utility.Tools.GetOSName(), RoadFlow.Utility.Tools.GetBrowse());
  90. log.Title = title;
  91. log.OldXml = oldXML.IsNullOrEmpty() ? null : oldXML;
  92. log.NewXml = newXML.IsNullOrEmpty() ? null : newXML;
  93. log.Type = type.ToString();
  94. log.URL = System.Web.HttpContext.Current.Request.Url.ToString();
  95. if (user != null)
  96. {
  97. log.UserID = user.ID;
  98. log.UserName = user.Name;
  99. }
  100. log.WriteTime = RoadFlow.Utility.DateTimeNew.Now;
  101. Add(log);
  102. }
  103. public static void Add(Exception err)
  104. {
  105. Add(err.Message, string.Concat(err.Source, err.StackTrace), Types.系统错误);
  106. }
  107. /// <summary>
  108. /// 得到类别下接选择
  109. /// </summary>
  110. /// <returns></returns>
  111. public string GetTypeOptions(string value = "")
  112. {
  113. StringBuilder options = new StringBuilder();
  114. var array = Enum.GetValues(typeof(Types));
  115. foreach (var arr in array)
  116. {
  117. options.AppendFormat("<option value=\"{0}\" {1}>{0}</option>", arr, arr.ToString() == value ? "selected=\"selected\"" : "");
  118. }
  119. return options.ToString();
  120. }
  121. /// <summary>
  122. /// 得到一页日志数据
  123. /// </summary>
  124. /// <param name="pager"></param>
  125. /// <param name="query"></param>
  126. /// <param name="order"></param>
  127. /// <param name="size"></param>
  128. /// <param name="number"></param>
  129. /// <param name="title"></param>
  130. /// <param name="type"></param>
  131. /// <param name="date1"></param>
  132. /// <param name="date2"></param>
  133. /// <param name="userID"></param>
  134. /// <returns></returns>
  135. public System.Data.DataTable GetPagerData(out string pager, string query = "", string title = "", string type = "", string date1 = "", string date2 = "", string userID = "")
  136. {
  137. return dataLog.GetPagerData(out pager, query, RoadFlow.Utility.Tools.GetPageSize(), RoadFlow.Utility.Tools.GetPageNumber(),
  138. title, type, date1, date2, Users.RemovePrefix(userID));
  139. }
  140. }
  141. }