Exemple #1
0
        public DataMark GetInfo(DataMark info)
        {
            DataTable columnDt = new DataTable();
            object    oldInfo  = null;
            object    newInfo  = null;
            Type      entityType;

            try
            {
                //获取数据
                info = new DataChangeManageDAL().GetInfo(info, ref columnDt);

                //获取实体类型
                entityType = this.GetEntityTypeByTable(info.DATAKIND);

                info.DATAKIND = info.DATAKINDDES;

                //json格式数据转换为实体
                if (string.IsNullOrEmpty(info.ORIGINALDATA) == false)
                {
                    oldInfo = JsonConvertHelper.GetDeserialize(entityType, info.ORIGINALDATA);
                }

                if (string.IsNullOrEmpty(info.CHANGEDDATA) == false)
                {
                    newInfo = JsonConvertHelper.GetDeserialize(entityType, info.CHANGEDDATA);
                }

                //生成字段明细数据
                PropertyInfo[] pArray = entityType.GetProperties();

                info.Details = new List <DataMarkDetail>();
                //获取字段信息
                foreach (var item in pArray)
                {
                    object[] attrs = item.GetCustomAttributes(typeof(DBColumnAttribute), true);
                    if (attrs.Count() == 0)
                    {
                        continue;
                    }

                    DBColumnAttribute ca = (DBColumnAttribute)attrs[0];//字段属性

                    DataMarkDetail detail = new DataMarkDetail();

                    //原值
                    object oldValue = null;
                    if (oldInfo != null)
                    {
                        oldValue = BindHelper.GetPropertyValue(oldInfo, item.Name);
                    }

                    detail.OldValue = oldValue == null?"":oldValue.ToString();

                    //变更后值
                    object newValue = null;
                    if (newInfo != null)
                    {
                        newValue = BindHelper.GetPropertyValue(newInfo, item.Name);
                    }

                    detail.NewValue = newValue == null ? "" : newValue.ToString();

                    DataRow[] rows = columnDt.Select("COLUMNNAME='" + ca.ColumnName + "'");
                    if (rows.Length > 0)
                    {
                        detail.ColumnDes = rows[0]["COLUMNDES"].ToString();
                    }

                    if (string.IsNullOrEmpty(detail.ColumnDes) == true)
                    {
                        continue;
                    }

                    info.Details.Add(detail);
                }

                return(info);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }