Пример #1
0
        /// <summary>
        /// Загружает все элементы рабочего пакета
        /// </summary>
        /// <param name="package"></param>
        public void LoadDirectivePackageItems <T, TV>(T package)
            where T : AbstractDirectivePackage <TV>, new()
            where TV : BaseDirectivePackageRecord, new()
        {
            package.CanPublish         = package.CanClose = true;
            package.BlockPublishReason = "";
            package.MinClosingDate     = null;
            package.MaxClosingDate     = null;
            // Компоненты
            package.PackageRecords.Clear();
            package.PackageRecords.AddRange(_loader.GetObjectListAll <TV>(BaseDirectivePackageRecord.ParentIdProperty, package.ItemId));
            foreach (TV record in package.PackageRecords)
            {
                record.ParentPackage = package;
            }

            IEnumerable <IGrouping <SmartCoreType, TV> > groupedRecordsByTaskType =
                package.PackageRecords.GroupBy(pr => pr.PackageItemType);

            foreach (IGrouping <SmartCoreType, TV> groupedRecords in groupedRecordsByTaskType)
            {
                #region загрузка Базовых деталей
                if (groupedRecords.Key == SmartCoreType.BaseComponent)
                {
                    foreach (TV adWpr in groupedRecords)
                    {
                        IDirective d = _componentCore.GetBaseComponentById(adWpr.DirectiveId);
                        if (d != null)
                        {
                            adWpr.Task = d;
                        }
                        else
                        {
                            package.PackageRecords.RemoveById(adWpr.ItemId);
                        }
                    }
                    continue;
                }
                #endregion

                if (groupedRecords.Key.ObjectType == null)
                {
                    continue;
                }

                Type objectType = groupedRecords.Key.ObjectType;

                ICommonFilter filter =
                    new CommonFilter <int>(BaseEntityObject.ItemIdProperty,
                                           FilterType.In,
                                           groupedRecords.Select(wpr => wpr.DirectiveId).ToArray());

                ICommonCollection directiveCollection = _loader.GetObjectCollection(objectType, new[] { filter }, true, true);

                if (directiveCollection.Count > 0)
                {
                    foreach (TV adWpr in groupedRecords)
                    {
                        IDirective d = directiveCollection.GetItemById(adWpr.DirectiveId) as IDirective;
                        if (d != null)
                        {
                            adWpr.Task = d;
                        }
                        else
                        {
                            package.PackageRecords.RemoveById(adWpr.ItemId);
                        }
                    }
                }
            }
            // ставим флаг о том, что все элементы рабочего пакета считаны
            package.PackageItemsLoaded = true;
        }