private void AddComponentAndDirectiveToBindedItemsCollections(Component component, ComponentDirective componentDirective, ICommonCollection <BaseEntityObject> itemsToInsert, ICommonCollection <BaseEntityObject> allbindedItems, Dictionary <Component, List <ComponentDirective> > newBindedItems) { itemsToInsert.Add(componentDirective); // Добавление задачи по компоненту из коллекции содержащих все связаные задачи allbindedItems.Add(componentDirective); //если в коллекции содержащей все связные задачи нет родительского компонента от задачи по компоненту //требуется добавить компонент в коллекцию содержащую все связные задачи if (allbindedItems.OfType <Component>().All(i => i.ItemId != component.ItemId)) { itemsToInsert.Add(component); allbindedItems.Add(component); } if (newBindedItems.ContainsKey(component)) { newBindedItems[component].Add(componentDirective); } else { newBindedItems.Add(component, new List <ComponentDirective> { componentDirective }); } }
/// <summary> /// Добавляет массив агрегатов в коллекцию /// </summary> /// <param name="objects"></param> public void AddRange(ICommonCollection objects) { foreach (T o in objects) { o.PropertyChanged += OnItemPropertyChanged; Items.Add(o); } Items.Sort(); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, objects.OfType <IBaseEntityObject>().ToList())); }
protected override void AnimatedThreadWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { return; } DirectivesViewer.SetItemsArray(ResultDirectiveArray.OfType <BaseEntityObject>()); headerControl.PrintButtonEnabled = DirectivesViewer.ItemsCount != 0; buttonDeleteSelected.Enabled = DirectivesViewer.SelectedItem != null; if (ViewedType.IsSubclassOf(typeof(StaticDictionary))) { buttonAddNew.Enabled = false; buttonDeleteSelected.Enabled = false; } }
private Control GetControl(ICommonFilter commonFilter) { #region ЭУ для базовых типов if (commonFilter is CommonFilter <bool> ) { var boolFilter = commonFilter as CommonFilter <bool>; var boolFilterControl = new CommonBoolFilterControl(boolFilter) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(boolFilterControl); } if (commonFilter is CommonFilter <int> ) { var stringFilter = commonFilter as CommonFilter <int>; var intFilterControl = new CommonIntFilterControl(stringFilter) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(intFilterControl); } if (commonFilter is CommonFilter <string> ) { var stringFilter = commonFilter as CommonFilter <string>; var stringFilterControl = new CommonStringFilterControl(stringFilter) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(stringFilterControl); } if (commonFilter is CommonFilter <DateTime> ) { var dateFilter = commonFilter as CommonFilter <DateTime>; DateTime minDate = DateTimeExtend.GetCASMinDateTime(); DateTime maxDate = DateTime.Today; if (_items != null && _items.Count > 0 && commonFilter.FilterProperty.PropertyType.Name == nameof(DateTime)) { var p = commonFilter.FilterProperty; var preCollection = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .OfType <DateTime>() .OrderBy(time => time) .ToList(); var preMaxDate = preCollection[preCollection.Count - 1]; var preMinDate = preCollection[0]; if (preMinDate > minDate) { minDate = preMinDate; } if (preMaxDate > maxDate) { maxDate = preMaxDate; } } var dateFilterControl = new CommonDateTimePeriodFilterControl(dateFilter, minDate, maxDate) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(dateFilterControl); } #endregion #region ЭУ для ENUM, IDictionaryItem, IBaseEntityObject Type filterType = commonFilter.GetType(); if (filterType.IsGenericType) { Type genericArgumentType = filterType.GetGenericArguments().First(); if (genericArgumentType.IsEnum) { try { var enumFilterControl = new CommonEnumFilterControl(commonFilter) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(enumFilterControl); } catch (Exception) { return(null); } } if (genericArgumentType.GetInterface(nameof(IDictionaryItem)) != null) { try { var dictionaryFilter = (ICommonFilter <IDictionaryItem>)commonFilter; IDictionaryItem[] values = null; if (commonFilter.FilterProperty.PropertyType.GetInterface(typeof(IEnumerable <>).Name) != null) { Type t = commonFilter.FilterProperty.PropertyType; if (t != null) { Type filterPropertyGenericArgument = t.GetGenericArguments().FirstOrDefault(); if (filterPropertyGenericArgument != null && filterPropertyGenericArgument.GetInterface(nameof(IDictionaryItem)) != null) { PropertyInfo p = commonFilter.FilterProperty; values = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .Where(o => o != null) .Cast <IEnumerable>() .SelectMany(enumerable => enumerable.OfType <IDictionaryItem>()) .Select(o => o) .ToArray(); } } } else { PropertyInfo p = commonFilter.FilterProperty; values = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .OfType <IDictionaryItem>() .Distinct() .ToArray(); } var dictionaryFilterControl = new CommonDictionaryFilterControl(dictionaryFilter, values) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(dictionaryFilterControl); } catch (Exception) { return(null); } } if (genericArgumentType.GetInterface(nameof(IBaseEntityObject)) != null) { try { var entitiesFilter = commonFilter as ICommonFilter <IBaseEntityObject>; BaseEntityObject[] values = null; if (_items != null && _items.Count > 0) { if (commonFilter.FilterProperty.PropertyType.GetInterface(typeof(IEnumerable <>).Name) != null) { //Свойство типа является универсальным типом, типом аргумента которого является //является тип аргумента данного фильтра Type t = commonFilter.FilterProperty.PropertyType; while (t != null) { if (t.IsGenericType) { break; } t = t.BaseType; } if (t != null) { Type filterPropertyGenericArgument = t.GetGenericArguments().FirstOrDefault(); if (filterPropertyGenericArgument != null && filterPropertyGenericArgument.GetInterface(nameof(IBaseEntityObject)) != null) { PropertyInfo p = commonFilter.FilterProperty; values = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .Where(o => o != null) .Cast <IEnumerable>() .SelectMany(enumerable => enumerable.OfType <BaseEntityObject>()) .Select(o => o) .ToArray(); } } } if (commonFilter.FilterProperty.PropertyType.GetInterface(nameof(IBaseEntityObject)) != null) { PropertyInfo p = commonFilter.FilterProperty; values = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .OfType <BaseEntityObject>() .ToArray(); } } var baseEntityObjectFilterControl = new CommonBaseEntityObjectFilterControl(entitiesFilter, values) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(baseEntityObjectFilterControl); } catch (Exception) { return(null); } } } #endregion #region ЭУ для CommonFilter<Lifelength> if (commonFilter is CommonFilter <Lifelength> ) { var lifelengthFilter = commonFilter as CommonFilter <Lifelength>; Lifelength[] values = null; if (_items != null && _items.Count > 0 && commonFilter.FilterProperty.PropertyType.Name == nameof(Lifelength)) { PropertyInfo p = commonFilter.FilterProperty; values = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .OfType <Lifelength>() .ToArray(); } var stringFilterControl = new CommonLifelengthFilterControl(lifelengthFilter, values) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(stringFilterControl); } #endregion #region ЭУ для CommonFilter<BaseEntityObject> if (commonFilter is CommonFilter <IBaseEntityObject> ) { var lifelengthFilter = commonFilter as CommonFilter <IBaseEntityObject>; BaseEntityObject[] values = null; if (_items != null && _items.Count > 0 && commonFilter.FilterProperty.PropertyType.Name == nameof(Lifelength)) { PropertyInfo p = commonFilter.FilterProperty; values = _items.OfType <BaseEntityObject>() .Select(o => p.GetValue(o, null)) .OfType <BaseEntityObject>() .ToArray(); } var baseEntityObjectFilterControl = new CommonBaseEntityObjectFilterControl(lifelengthFilter, values) { AutoSize = true, MinimumSize = new Size(20, 17), Tag = commonFilter.FilterProperty, }; return(baseEntityObjectFilterControl); } #endregion return(null); }
protected override void AnimatedThreadWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { return; } if (_currentAircraft != null) { aircraftHeaderControl1.Aircraft = _currentAircraft; } if (CurrentAircraft != null) { labelTitle.Text = "Date as of: " + SmartCore.Auxiliary.Convert.GetDateFormat(DateTime.Today) + " Aircraft TSN/CSN: " + GlobalObjects.CasEnvironment.Calculator.GetCurrentFlightLifelength(CurrentAircraft); } if (_currentBaseComponent != null) { var parentAircraft = GlobalObjects.AircraftsCore.GetAircraftById(_currentBaseComponent.ParentAircraftId); var parentStore = GlobalObjects.StoreCore.GetStoreById(_currentBaseComponent.ParentStoreId); if (parentAircraft != null) { aircraftHeaderControl1.Aircraft = parentAircraft; } if (parentStore != null) { aircraftHeaderControl1.Store = parentStore; } } if (_currentStore != null) { aircraftHeaderControl1.Store = _currentStore; } DirectivesViewer.SetItemsArray(ResultDirectiveArray.OfType <BaseEntityObject>()); headerControl.PrintButtonEnabled = DirectivesViewer.ItemsCount != 0; buttonDeleteSelected.Enabled = DirectivesViewer.SelectedItem != null; if (ViewedType.IsSubclassOf(typeof(StaticDictionary))) { buttonAddNew.Enabled = false; buttonDeleteSelected.Enabled = false; } if (_toolStripMenuItemsWorkPackages != null) { foreach (var item in _toolStripMenuItemsWorkPackages.Items) { item.Click -= AddToWorkPackageItemClick; } _toolStripMenuItemsWorkPackages.Items.Clear(); foreach (WorkPackage workPackage in _openPubWorkPackages) { var item = new RadMenuItem(workPackage.Title); item.Click += AddToWorkPackageItemClick; item.Tag = workPackage; _toolStripMenuItemsWorkPackages.Items.Add(item); } } }