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
|
}
|
}
|