| | |
| | | |
| | | public bool DeleteAndMoveIntoHty(TEntity entity, OperateType operateType) |
| | | { |
| | | Type type = entity.GetType(); |
| | | Assembly assembly = type.Assembly; |
| | | Type? htyType = assembly.GetType(type.FullName + "_Hty"); |
| | | if (htyType != null) |
| | | try |
| | | { |
| | | object? obj = Activator.CreateInstance(htyType); |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateType)); |
| | | PropertyInfo? sourceIdPro = htyType.GetProperty("SourceId"); |
| | | if (obj != null && keyPro != null && operateTypePro != null && sourceIdPro != null) |
| | | Type type = entity.GetType(); |
| | | Assembly assembly = type.Assembly; |
| | | Type? htyType = assembly.GetType(type.FullName + "_Hty"); |
| | | if (htyType != null) |
| | | { |
| | | operateTypePro.SetValue(obj, operateType.ToString()); |
| | | sourceIdPro.SetValue(obj, keyPro.GetValue(entity)); |
| | | |
| | | List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList(); |
| | | |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | object? obj = Activator.CreateInstance(htyType); |
| | | PropertyInfo keyPro = typeof(TEntity).GetKeyProperty(); |
| | | PropertyInfo? operateTypePro = htyType.GetProperty(nameof(OperateType)); |
| | | PropertyInfo? sourceIdPro = htyType.GetProperty("SourceId"); |
| | | if (obj != null && keyPro != null && operateTypePro != null && sourceIdPro != null) |
| | | { |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | PropertyInfo? property = type.GetProperty(propertyInfo.Name); |
| | | operateTypePro.SetValue(obj, operateType.ToString()); |
| | | sourceIdPro.SetValue(obj, keyPro.GetValue(entity)); |
| | | |
| | | if (property != null) |
| | | List<PropertyInfo> propertyInfos = htyType.GetProperties().Where(x => x.Name != operateTypePro.Name && x.Name != sourceIdPro.Name && x.Name != keyPro.Name).ToList(); |
| | | |
| | | for (int i = 0; i < propertyInfos.Count; i++) |
| | | { |
| | | if (propertyInfo.Name == nameof(BaseEntity.Modifier)) |
| | | PropertyInfo propertyInfo = propertyInfos[i]; |
| | | PropertyInfo? property = type.GetProperty(propertyInfo.Name); |
| | | |
| | | if (property != null) |
| | | { |
| | | propertyInfo.SetValue(obj, App.User.UserId > 0 ? App.User.UserName : App.User.UserId.ToString()); |
| | | } |
| | | else if (propertyInfo.Name == nameof(BaseEntity.ModifyDate)) |
| | | { |
| | | propertyInfo.SetValue(obj, DateTime.Now); |
| | | } |
| | | else |
| | | { |
| | | propertyInfo.SetValue(obj, property.GetValue(entity)); |
| | | if (propertyInfo.Name == nameof(BaseEntity.Modifier)) |
| | | { |
| | | propertyInfo.SetValue(obj, App.User.UserId > 0 ? App.User.UserName : App.User.UserId.ToString()); |
| | | } |
| | | else if (propertyInfo.Name == nameof(BaseEntity.ModifyDate)) |
| | | { |
| | | propertyInfo.SetValue(obj, DateTime.Now); |
| | | } |
| | | else |
| | | { |
| | | propertyInfo.SetValue(obj, property.GetValue(entity)); |
| | | } |
| | | } |
| | | } |
| | | _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | } |
| | | _db.InsertableByObject(obj).AS(type.Name + "_Hty").ExecuteCommand(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | throw; |
| | | } |
| | | return DeleteData(entity); |
| | | } |
| | | |