BlLogOperation.cs 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Common;
  4. using System.Linq;
  5. using System.Management;
  6. using System.Net;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using ProjectBase.Data.BaseDAL;
  10. using SIMDP.DAL.IDALSQL;
  11. using SIMDP.Model;
  12. using SIMDP.Util;
  13. namespace SIMDP.BLL
  14. {
  15. public class BlLogOperation : BaseBLL<MoLogOperation>
  16. {
  17. private IDalLogOperation dalLogOperation;
  18. /// <summary>
  19. /// 构造函数
  20. /// </summary>
  21. public BlLogOperation() : base()
  22. {
  23. base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
  24. dalLogOperation = baseDal as IDalLogOperation;
  25. }
  26. /// <summary>
  27. /// 获取组织ID与组织名称的集合
  28. /// </summary>
  29. /// <returns></returns>
  30. public Dictionary<string, string> GetGroupName()
  31. {
  32. Dictionary<string, string> dic = new Dictionary<string, string>();
  33. //BlAuthoryGroup bl = new BlAuthoryGroup();
  34. List<MoAuthoryGroup> group = BLLFactory<BlAuthoryGroup>.Instance.GetAll();
  35. if (group.Count == 0 || group == null)
  36. {
  37. return null;
  38. }
  39. foreach (MoAuthoryGroup item in group)
  40. {
  41. dic.Add(item.GroupId, item.GroupName);
  42. }
  43. return dic;
  44. }
  45. /// <summary>
  46. /// 根据相关信息,写入用户的操作日志记录
  47. /// </summary>
  48. /// <param name="userId">操作用户</param>
  49. /// <param name="tableName">操作表名称</param>
  50. /// <param name="operationType">操作类型</param>
  51. /// <param name="note">操作详细表述,目前数据表不包含这个字段,赋值为空</param>
  52. /// <param name="trans">事务对象</param>
  53. /// <returns></returns>
  54. public static bool OnOperationLog(string userId, string tableName, string operationType,string note = null, DbTransaction trans = null)
  55. {
  56. //虽然实现了这个事件,但是我们还需要判断该表是否在配置表里面,如果不在,则不记录操作日志。
  57. //BlLogOperationSetting blSetting = new BlLogOperationSetting();
  58. MoLogOperationSetting settingInfo = BLLFactory<BlLogOperationSetting>.Instance.FindByTableName(tableName, trans);
  59. if (settingInfo != null)
  60. {
  61. bool insert = operationType == "增加" && settingInfo.InsertLog;
  62. bool update = operationType == "修改" && settingInfo.UpdateLog;
  63. bool delete = operationType == "删除" && settingInfo.DeleteLog;
  64. if (insert || update || delete)
  65. {
  66. MoLogOperation info = new MoLogOperation();
  67. info.TableName = tableName;
  68. info.Type = operationType;
  69. info.Time = DateTime.Now;
  70. if (!string.IsNullOrEmpty(userId))
  71. {
  72. //BlAuthoryUser blUser = new BlAuthoryUser();
  73. MoAuthoryUser userInfo = BLLFactory<BlAuthoryUser>.Instance.FindByID(userId, trans);
  74. if (userInfo != null)
  75. {
  76. info.Account = userId;
  77. info.Name = userInfo.UserName;
  78. info.GroupId = userInfo.GroupId;
  79. }
  80. }
  81. info.Ip = SysEnvironment.Ip;
  82. info.Mac = SysEnvironment.Mac;
  83. //BlLogOperation bl = new BlLogOperation();
  84. return BLLFactory<BlLogOperation>.Instance.Insert(info, trans);
  85. //return true;
  86. }
  87. }
  88. return false;
  89. }
  90. }
  91. }