schangxiang@126.com
2025-11-04 ca398287db3f5ea01f03aac4a85edb13b28100a6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static NPOI.HSSF.UserModel.HeaderFooter;
using System.ComponentModel;
using System.Windows.Media.Animation;
using XImagingXhandler.XDAL;
using System.Collections.ObjectModel;
using Newtonsoft.Json;
 
namespace XHandler.Class
{
    /// <summary>
    /// 操作审计记录处理类
    /// </summary>
    public class LogAduitHelper
    {
        #region 判断两个实例,找出不同的属性,添加到哈希表结果集中---利用反射
        /// <summary>
        /// 判断两个实例,找出不同的属性,添加到哈希表结果集中---利用反射
        /// </summary>
        /// <param name="oldObj">旧对象实例</param>
        /// <param name="newObj">新对象实例</param>
        /// <returns>不同的实例属性哈希表集合</returns>
        public Hashtable diffObj(Object oldObj, Object newObj)
        {
            Hashtable diffMap = new Hashtable();
            try
            {
                var oldObjClazz = oldObj.GetType();
                var newObjClazz = newObj.GetType();
                if (oldObjClazz.Equals(newObjClazz))
                {
                    PropertyInfo[] fields = oldObjClazz.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                    foreach (PropertyInfo field in fields)
                    {
                        Object oldValue = field.GetValue(oldObj);
                        Object newValue = field.GetValue(newObj);
                        if ((oldValue == null && newValue != null) || oldValue != null && !oldValue.Equals(newValue))
                        {
                            DescriptionAttribute descriptionAttribute= field.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;
                            string keyName = descriptionAttribute?.Description ?? field.Name;
                            if(field.Name.Equals("labwareWellInfoList"))
                            {
                                ObservableCollection<LabwareWellInfo> newLabwareWellInfo = (ObservableCollection<LabwareWellInfo>)newValue;
                                string content = string.Empty;
                                foreach(LabwareWellInfo l in newLabwareWellInfo)
                                {
                                    content = content + JsonConvert.SerializeObject(l)+";";
                                }
                                newValue = content;
                            }
                            diffMap.Add(keyName, " 从 " + oldValue + " 修改为 " + newValue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
 
            }
            return diffMap;
        }
        #endregion
 
        #region 耗材审计记录控制
        /// <summary>
        /// 构建新加的数据hash
        /// </summary>
        /// <param name="newObj">新加的对象</param>
        /// <returns></returns>
        public Hashtable AddObj(Object newObj)
        {
            Hashtable diffMap = new Hashtable();
            try
            {
                var newObjClazz = newObj.GetType();
                PropertyInfo[] fields = newObjClazz.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (PropertyInfo field in fields)
                {
                    Object newValue = field.GetValue(newObj);
                    if (newValue != null) 
                    {
                        DescriptionAttribute descriptionAttribute = field.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute;
                        string keyName = descriptionAttribute?.Description ?? field.Name;
                        diffMap.Add(keyName, " 值为 " + newValue);
                    }
                }
            }
            catch (Exception ex)
            {
 
            }
            return diffMap;
        }
 
        /// <summary>
        /// 构建删除的耗材数据hash
        /// </summary>
        /// <param name="delObj">已删除的耗材对象</param>
        /// <returns></returns>
        public Hashtable LabwareDelObj(Labware delObj)
        {
            Hashtable diffMap = new Hashtable();
            diffMap.Add("耗材Id", "删除 值为 " + delObj.labware_id);
            return diffMap;
        }
        #endregion
 
        #region 液体审计记录控制
        /// <summary>
        /// 构建删除的耗材数据hash
        /// </summary>
        /// <param name="delObj">已删除的耗材对象</param>
        /// <returns></returns>
        public Hashtable LiquidDelObj(Liquid delObj)
        {
            Hashtable diffMap = new Hashtable();
            diffMap.Add("液体Id", "删除 值为 " + delObj.liquid_id);
            return diffMap;
        }
        #endregion
    }
}