private void LoadDocuments(BaseComponentCollection baseComponents, CasEnvironment env) { var types = new[] { SmartCoreType.BaseComponent.ItemId, SmartCoreType.ComponentDirective.ItemId }; //Загрузка документов var documents = env.NewLoader.GetObjectListAll <DocumentDTO, Document>(new Filter("ParentTypeId", types), true); if (documents.Count > 0) { foreach (var _currentComponent in baseComponents) { var crs = env.GetDictionary <DocumentSubType>().GetByFullName("Component CRS Form") as DocumentSubType; var shipping = env.GetDictionary <DocumentSubType>().GetByFullName("Shipping document") as DocumentSubType; var docShipping = documents.FirstOrDefault(d => d.ParentId == _currentComponent.ItemId && d.ParentTypeId == SmartCoreType.BaseComponent.ItemId && d.DocumentSubType == shipping); if (docShipping != null) { _currentComponent.Document = docShipping; _currentComponent.Document.Parent = _currentComponent; } var docCrs = documents.FirstOrDefault(d => d.ParentId == _currentComponent.ItemId && d.ParentTypeId == SmartCoreType.Component.ItemId && d.DocumentSubType == crs); if (docCrs != null) { _currentComponent.DocumentCRS = docCrs; _currentComponent.DocumentCRS.Parent = _currentComponent; } if (_currentComponent.ComponentDirectives.Count > 0) { foreach (var directive in _currentComponent.ComponentDirectives) { var docCd = documents.FirstOrDefault(d => d.ParentId == directive.ItemId && d.ParentTypeId == SmartCoreType.ComponentDirective.ItemId); if (docCd != null) { directive.Document = docCd; directive.Document.Parent = directive; } } } } } }
/* * Директивы летной годности */ /* * Audits */ /* * */ /* * / KITs */ //TODO!!!! метод временный. Создан для обновления словарей в кэше. Подумать над новым подходом загрузки словарей #region public void ReloadDictionary(params Type[] types) public void ReloadDictionary(params Type[] types) { foreach (var type in types) { var reloadedDict = GetObjectList(type, loadChild: true); var dict = _casEnvironment.GetDictionary(type); dict.Clear(); foreach (AbstractDictionary dictionary in reloadedDict) { dict.Add(dictionary); } } }
//#region public static void SetValue(TableColumnAttribute tca, BaseEntityObject item, PropertyInfo currentProperty, object value) //public static void SetValue(TableColumnAttribute tca, BaseEntityObject item, PropertyInfo currentProperty, object value) //{ // object objectValue; // if (!(string.IsNullOrEmpty(tca.TypeBy))) // { // PropertyInfo typeProperty = item.GetType().GetProperties().Where(p => p.Name == tca.TypeBy).First(); // if (typeProperty != null) // { // SmartCoreType coreType = typeProperty.GetValue(item, null) as SmartCoreType; // if (coreType != null && coreType.ObjectType != null) // objectValue = GetValue(coreType.ObjectType, value); // else objectValue = GetValue(currentProperty.PropertyType, value); // } // else objectValue = GetValue(currentProperty.PropertyType, value); // } // else objectValue = GetValue(currentProperty.PropertyType, value); // currentProperty.SetValue(item, objectValue, null); //} //#endregion #region public static void Fill(Type type, object value) public static object GetValue(Type type, object value) { //Проверка, является ли переданный тип наследником BaseSmartCoreObject if (type.IsSubclassOf(typeof(AbstractDictionary))) { try { var typeDict = _casEnvironment.GetDictionary(type); return(typeDict == null ? null : typeDict.GetItemById(ToInt32(value))); } catch (Exception ex) { throw ex; } } if (type.IsSubclassOf(typeof(StaticDictionary))) { try { //поиск в типе своиства Items PropertyInfo itemsProp = type.GetProperty("Items"); //поиск у типа конструктора беза параметров ConstructorInfo ci = type.GetConstructor(new Type[0]); //создание экземпляра статического словаря //(при этом будут созданы все его статические элементы, //которые будут доступны через статическое своиство Items) StaticDictionary instance = (StaticDictionary)ci.Invoke(null); //Получение элементов статического своиства Items IEnumerable staticList = (IEnumerable)itemsProp.GetValue(instance, null); int id = ToInt32(value); StaticDictionary res = staticList.Cast <StaticDictionary>().FirstOrDefault(o => o.ItemId == id) ?? staticList.Cast <StaticDictionary>().FirstOrDefault(o => o.ItemId == -1); return(res); } catch (Exception) { return(null); } } if (type.IsEnum) { try { object o = Enum.Parse(type, value.ToString()); return(o); } catch (Exception) { return(null); } } if (type.Name == typeof(Aircraft).Name) { try { var aircraft = _aircraftsCore.GetAircraftById(ToInt32(value)); return(aircraft); } catch (Exception) { return(null); } } if (type.Name == typeof(BaseComponent).Name) { try { BaseComponent bd = _casEnvironment.BaseComponents.GetItemById(ToInt32(value));//TODO(Evgenii Babak): использовать ComponentCore return(bd); } catch (Exception) { return(null); } } if (type.Name == typeof(Hangar).Name) { try { Hangar hangar = _casEnvironment.Hangars.GetItemById(ToInt32(value)); return(hangar); } catch (Exception) { return(null); } } if (type.Name == typeof(Operator).Name) { try { Operator op = _casEnvironment.Operators.GetItemById(ToInt32(value)); return(op); } catch (Exception) { return(null); } } if (type.Name == typeof(Store).Name) { try { Store store = _casEnvironment.Stores.GetItemById(ToInt32(value)); return(store); } catch (Exception) { return(null); } } if (type.Name == typeof(WorkShop).Name) { try { WorkShop workShop = _casEnvironment.WorkShops.GetItemById(ToInt32(value)); return(workShop); } catch (Exception) { return(null); } } Type nullable = Nullable.GetUnderlyingType(type); if (nullable != null) { //TODO:(Evgenii Babak) использовать Nameof() вместо названия типа string typeName = nullable.Name.ToLower(); switch (typeName) { case "int32": return(ToInt32Nullable(value)); case "int16": return(ToInt16Nullable(value)); case "datetime": return(ToDateTimeNullable(value)); case "bool": return(ToBoolNullable(value)); case "boolean": return(ToBoolNullable(value)); case "double": return(ToDoubleNullable(value)); default: return(null); } } else { string typeName = type.Name.ToLower(); switch (typeName) { case "string": return(ToString(value)); case "int32": return(ToInt32(value)); case "int16": return(ToInt16(value)); case "datetime": return(ToDateTime(value)); case "bool": return(ToBool(value)); case "boolean": return(ToBool(value)); case "byte[]": return(ToBytes(value)); case "double": return(ToDouble(value)); case "adtype": return((ADType)ToInt16(value)); case "averageutilization": return(ToAverageUtilization(value)); case "avionicsinventorymarktype": //case "atachapter": // return _casEnvironment.Dictionaries[typeof(AtaChapter)].GetItemById(ToInt32(value)); case "componentdirectivethreshold": return(ToComponentDirectiveThreshold(value)); case "trainingthreshold": return(ToTrainingThreshold(value)); case "componenttype": return(BaseComponentType.GetComponentTypeById(ToInt32(value))); case "componentrecordtype": return(ComponentRecordType.GetItemById(ToInt32(value))); case "detectionphase": return((DetectionPhase)ToInt16(value)); case "directivethreshold": return(ToDirectiveThreshold(value)); case "directivetype": return(DirectiveWorkType.GetItemById(ToInt32(value))); case "highlight": return(Highlight.GetHighlightById(ToInt32(value))); case "componentstatus": return((ComponentStatus)ToInt16(value)); case "lifelength": return(ToLifelength(value)); case "landinggearmarktype": return((LandingGearMarkType)ToInt32(value)); case "maintenancedirectivethreshold": return(ToMaintenanceDirectiveThreshold(value)); case "maintenancecontrolprocess": return(MaintenanceControlProcess.GetItemById(ToInt32(value))); case "powerloss": return((PowerLoss)ToInt16(value)); case "runupcondition": return((RunUpCondition)ToInt16(value)); case "runuptype": return((RunUpType)ToInt16(value)); case "shutdowntype": return((ShutDownType)ToInt16(value)); case "thrustlever": return((ThrustLever)ToInt16(value)); case "timespan": return(ToTime(value)); case "weathercondition": return((WeatherCondition)ToInt16(value)); case "workpackagestatus": return((WorkPackageStatus)ToInt32(value)); default: return(null); } } }