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
{
///
/// 操作审计记录处理类
///
public class LogAduitHelper
{
#region 判断两个实例,找出不同的属性,添加到哈希表结果集中---利用反射
///
/// 判断两个实例,找出不同的属性,添加到哈希表结果集中---利用反射
///
/// 旧对象实例
/// 新对象实例
/// 不同的实例属性哈希表集合
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 newLabwareWellInfo = (ObservableCollection)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 耗材审计记录控制
///
/// 构建新加的数据hash
///
/// 新加的对象
///
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;
}
///
/// 构建删除的耗材数据hash
///
/// 已删除的耗材对象
///
public Hashtable LabwareDelObj(Labware delObj)
{
Hashtable diffMap = new Hashtable();
diffMap.Add("耗材Id", "删除 值为 " + delObj.labware_id);
return diffMap;
}
#endregion
#region 液体审计记录控制
///
/// 构建删除的耗材数据hash
///
/// 已删除的耗材对象
///
public Hashtable LiquidDelObj(Liquid delObj)
{
Hashtable diffMap = new Hashtable();
diffMap.Add("液体Id", "删除 值为 " + delObj.liquid_id);
return diffMap;
}
#endregion
}
}