Exemplo n.º 1
0
        public void Save(BaseEntityObject value, bool saveAttachedFile = true, bool writeAudit = true)
        {
            if (_casEnvironment.IdentityUser.UserType == UsetType.ReadOnly)
            {
                return;
            }

            value.CorrectorId = _casEnvironment.IdentityUser.ItemId;
            value.Updated     = DateTime.Now;

            var type = AuditOperation.Created;

            if (value.ItemId > 0)
            {
                type = AuditOperation.Changed;
            }

            var blType = value.GetType();
            var dto    = (DtoAttribute)blType.GetCustomAttributes(typeof(DtoAttribute), false).FirstOrDefault();
            var method = typeof(INewKeeper).GetMethods().FirstOrDefault(i => i.Name == "SaveGeneric")?.MakeGenericMethod(blType, dto.Type);

            method.Invoke(this, new object[] { value, saveAttachedFile });

            if (writeAudit)
            {
                _auditRepository.WriteAsync(value, type, _casEnvironment.IdentityUser);
            }
        }
Exemplo n.º 2
0
        /*
         * Глобальные коллекции
         */

        #region public void Save(BaseSmartCoreObject saveObject)
        public void Save(BaseEntityObject saveObject)
        {
            if (saveObject == null)
            {
                return;
            }

            saveObject.CorrectorId = _casEnvironment.IdentityUser.ItemId;

            var type = AuditOperation.Created;

            if (saveObject.ItemId > 0)
            {
                type = AuditOperation.Changed;
            }

            CasEnvironment.Keeper.Save(saveObject);
            _auditRepository.WriteAsync(saveObject, type, _casEnvironment.IdentityUser);

            if (saveObject is AbstractDictionary)
            {
                IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType());

                if (col == null)
                {
                    return;
                }
                AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId);
                if (dict == null || saveObject.ItemId != dict.ItemId)
                {
                    col.Add(saveObject);
                }
                else
                {
                    dict.SetProperties((AbstractDictionary)saveObject);
                }
            }
            if (saveObject is Store)
            {
                Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.Stores.Add((Store)saveObject);
                }
            }
            if (saveObject is BaseComponent)
            {
                BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.BaseComponents.Add((BaseComponent)saveObject);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Новый метод для сохранения объектов
        /// </summary>
        /// <param name="saveObject">Сохраняемый объект</param>
        /// <param name="saveChild">Сохранять дочерние объекты</param>
        /// <param name="saveForced">Сохранять свойтсва, помеченные как "принудительные"</param>
        public void SaveAll(BaseEntityObject saveObject, bool saveChild = false, bool saveForced = false)
        {
            if (saveObject == null)
            {
                return;
            }

            CasEnvironment.Keeper.SaveAll(saveObject, saveChild, saveForced);

            if (saveObject is AbstractDictionary)
            {
                IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType());

                if (col == null)
                {
                    return;
                }
                AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId);
                if (dict == null || saveObject.ItemId != dict.ItemId)
                {
                    col.Add(saveObject);
                }
                else
                {
                    dict.SetProperties((AbstractDictionary)saveObject);
                }
            }
            if (saveObject is Store)
            {
                Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.Stores.Add((Store)saveObject);
                }
            }
            if (saveObject is BaseComponent)
            {
                BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.BaseComponents.Add((BaseComponent)saveObject);
                }
            }
        }
Exemplo n.º 4
0
        /*
         * Воздушное судно и склад
         */


        /*
         * Агрегаты
         */

        /*
         * Перемещение агрегатов
         */


        /*
         * Directive: Добавление в БД всех классов относящихся к директиве
         */

        /*
         * Удаление объектов
         */
        #region public void Delete(BaseSmartCoreObject deletedObject, bool isDeletedOnly = true)
        /// <summary>
        /// Удаляет объект из БД
        /// </summary>
        /// <param name="deletedObject">Объект, который нужно удалить</param>
        /// <param name="isDeletedOnly">Флаг - сделать запись недействительной (true)или физически удалить(false)</param>
        public void Delete(BaseEntityObject deletedObject, bool isDeletedOnly = true)
        {
            if (deletedObject == null)
            {
                return;
            }

            CasEnvironment.Keeper.Delete(deletedObject, isDeletedOnly);

            if (deletedObject is AbstractDictionary)
            {
                var col = CasEnvironment.GetDictionary(deletedObject.GetType());

                if (col == null)
                {
                    return;
                }
                col.Remove(deletedObject);
            }
            if (deletedObject is Store)
            {
                CasEnvironment.Stores.Remove((Store)deletedObject);
            }
            if (deletedObject is BaseComponent)
            {
                CasEnvironment.BaseComponents.Remove((BaseComponent)deletedObject);
            }
            if (deletedObject is ComponentWorkInRegimeParams &&
                ((ComponentWorkInRegimeParams)deletedObject).Engine != null)
            {
                ((ComponentWorkInRegimeParams)deletedObject).Engine.ComponentWorkParams.Remove((ComponentWorkInRegimeParams)deletedObject);
            }
            if (deletedObject is MaintenanceProgramChangeRecord)
            {
                var aircraft = _aircraftsCore.GetAircraftById(((MaintenanceProgramChangeRecord)deletedObject).ParentAircraftId);
                aircraft.MaintenanceProgramChangeRecords.Remove((MaintenanceProgramChangeRecord)deletedObject);
            }
        }
Exemplo n.º 5
0
        public void Delete(BaseEntityObject value, bool isDeletedOnly = false, bool saveAttachedFile = true)
        {
            if (_casEnvironment.IdentityUser.UserType == UserType.ReadOnly || _casEnvironment.IdentityUser.UserType == UserType.SaveOnly)
            {
                return;
            }

            value.CorrectorId = _casEnvironment.IdentityUser.ItemId;
            value.Updated     = DateTime.Now;

            var blType = value.GetType();
            var dto    = ((DtoAttribute)blType.GetCustomAttributes(typeof(DtoAttribute), false).FirstOrDefault())?.Type;

            if (_casEnvironment is CaaEnvironment)
            {
                dto = ((CAADtoAttribute)blType.GetCustomAttributes(typeof(CAADtoAttribute), false).FirstOrDefault())?.Type;
            }
            var method = typeof(INewKeeper).GetMethods().FirstOrDefault(i => i.Name == "DeleteGeneric")?.MakeGenericMethod(blType, dto);

            method.Invoke(this, new object[] { value, isDeletedOnly, saveAttachedFile });

            _auditRepository.WriteAsync(value, AuditOperation.Deleted, _casEnvironment.IdentityUser);
        }
Exemplo n.º 6
0
        ///<summary>
        /// Проверяется, подходит ли элемент под фильтр
        ///</summary>
        ///<param name="item">Проверяемый элемент</param>
        ///<returns>Результат - подходит ли элемент</returns>
        public bool Acceptable(BaseEntityObject item)
        {
            if (item == null || FilterProperty == null || Values.Length == 0)
            {
                return(true);
            }
            PropertyInfo typeProp;

            if ((typeProp = item.GetType().GetProperty(FilterProperty.Name)) == null ||
                !FilterProperty.PropertyType.Name.Equals(typeProp.PropertyType.Name))
            {
                return(true);
            }

            if (FilterProperty.PropertyType.Name.ToLower() != "string" &&
                FilterProperty.PropertyType.GetInterface(typeof(IEnumerable <>).Name) != null)
            {
                //Если свойство не string (string реализует интерфейс IEnumerable<>)
                //и реализует интерфейс IEnumerable<> то
                //производится поиск параметра универсального типа
                Type t = FilterProperty.PropertyType;

                while (t != null)
                {
                    if (t.IsGenericType)
                    {
                        t = t.GetGenericArguments().FirstOrDefault();
                        break;
                    }
                    t = t.BaseType;
                }
                if (t == null)
                {
                    return(false);
                }
                if (t.Name != typeof(T).Name)
                {
                    return(false);
                }
            }
            else if (FilterProperty.PropertyType.Name != typeof(T).Name)
            {
                return(false);
            }

            object propertyValue = FilterProperty.GetValue(item, null);

            if (propertyValue == null)
            {
                return(false);
            }

            //Тип свойства реалтзует интерфейс IEnumerable
            if (FilterProperty.PropertyType.Name.ToLower() != "string" &&
                FilterProperty.PropertyType.GetInterface(typeof(IEnumerable <>).Name) != null)
            {
                IEnumerable <T> convertedPropertyValue = ((IEnumerable <T>)propertyValue).ToArray();
                if (!convertedPropertyValue.Any())
                {
                    return(false);
                }
                switch (FilterType)
                {
                case FilterType.Equal:
                    return(convertedPropertyValue.Contains(Values[0]));

                case FilterType.NotEqual:
                    return(!convertedPropertyValue.Contains(Values[0]));

                case FilterType.In:
                    return(convertedPropertyValue.Any(cpv => Values.Contains(cpv)));

                //return Values.Any(v => convertedPropertyValue.Contains(v));
                default:
                    return(false);
                }
            }
            //Проверка, является ли переданный тип наследником BaseSmartCoreObject
            if (FilterProperty.PropertyType.IsSubclassOf(typeof(AbstractDictionary)) ||
                FilterProperty.PropertyType.IsSubclassOf(typeof(StaticDictionary)))
            {
                switch (FilterType)
                {
                case FilterType.Equal:
                    return(propertyValue.Equals(Values[0]));

                case FilterType.NotEqual:
                    return(!propertyValue.Equals(Values[0]));

                case FilterType.In:
                    return(Values.Any(v => propertyValue.Equals(v)));

                default:
                    return(false);
                }
            }
            if (FilterProperty.PropertyType.GetInterface(typeof(IBaseEntityObject).Name) != null)
            {
                switch (FilterType)
                {
                case FilterType.Equal:
                    return(propertyValue.Equals(Values[0]));

                case FilterType.NotEqual:
                    return(!propertyValue.Equals(Values[0]));

                case FilterType.In:
                    return(Values.Any(v => propertyValue.Equals(v)));

                default:
                    return(false);
                }
            }
            if (FilterProperty.PropertyType.Name == typeof(Lifelength).Name)
            {
                Lifelength convertedPropertyValue = (Lifelength)propertyValue;
                Lifelength convertedFilterValue   = Values[0] as Lifelength ?? Lifelength.Null;

                switch (FilterType)
                {
                case FilterType.Less:
                    return(convertedPropertyValue.IsLessIgnoreNulls(convertedFilterValue));

                case FilterType.LessOrEqual:
                    return(convertedPropertyValue.IsLessOrEqualByAnyParameter(convertedFilterValue));

                case FilterType.Equal:
                    return(convertedPropertyValue.Equals(convertedFilterValue));

                case FilterType.GratherOrEqual:
                    return(convertedPropertyValue.IsGreaterOrEqualByAllParameters(convertedFilterValue));

                case FilterType.Grather:
                    return(convertedPropertyValue.IsGratherIgnoreNulls(convertedFilterValue));

                case FilterType.NotEqual:
                    return(!convertedPropertyValue.Equals(convertedFilterValue));

                case FilterType.In:
                    return(Values.OfType <Lifelength>().Any(convertedPropertyValue.Equals));

                default:
                    return(false);
                }
            }
            if (FilterProperty.PropertyType.IsEnum)
            {
                switch (FilterType)
                {
                case FilterType.Equal:
                    return(Equals(propertyValue, Values[0]));

                case FilterType.NotEqual:
                    return(!Equals(propertyValue, Values[0]));

                case FilterType.In:
                {
                    return(Values.Any(value => Equals(value, propertyValue)));
                }

                default:
                    return(false);
                }
            }

            string typeName = FilterProperty.PropertyType.Name.ToLower();

            switch (typeName)
            {
            case "bool":
            case "boolean":
            {
                bool convertedPropertyValue = Convert.ToBoolean(propertyValue);
                bool convertedFilterValue   = Convert.ToBoolean(Values[0]);
                switch (FilterType)
                {
                case FilterType.Equal:
                    return(convertedPropertyValue == convertedFilterValue);

                case FilterType.NotEqual:
                    return(convertedPropertyValue != convertedFilterValue);

                case FilterType.In:
                    return(Values.Any(v => convertedFilterValue == Convert.ToBoolean(v)));

                default:
                    return(false);
                }
            }

            case "datetime":
            {
                DateTime convertedPropertyValue = Convert.ToDateTime(propertyValue);
                DateTime convertedFilterValue   = Convert.ToDateTime(Values[0]);
                switch (FilterType)
                {
                case FilterType.Less:
                    return(convertedPropertyValue < convertedFilterValue);

                case FilterType.LessOrEqual:
                    return(convertedPropertyValue <= convertedFilterValue);

                case FilterType.Equal:
                    return(convertedPropertyValue == convertedFilterValue);

                case FilterType.GratherOrEqual:
                    return(convertedPropertyValue >= convertedFilterValue);

                case FilterType.Grather:
                    return(convertedPropertyValue > convertedFilterValue);

                case FilterType.NotEqual:
                    return(convertedPropertyValue != convertedFilterValue);

                case FilterType.In:
                    return(Values.Any(v => convertedFilterValue == Convert.ToDateTime(v)));

                case FilterType.Between:
                    return(Convert.ToDateTime(Values[0]) <= convertedPropertyValue && convertedPropertyValue <= Convert.ToDateTime(Values[1]));

                default:
                    return(false);
                }
            }

            case "double":
            {
                double convertedPropertyValue = Convert.ToDouble(propertyValue);
                double convertedFilterValue   = Convert.ToDouble(Values[0]);
                switch (FilterType)
                {
                case FilterType.Less:
                    return(convertedPropertyValue < convertedFilterValue);

                case FilterType.LessOrEqual:
                    return(convertedPropertyValue <= convertedFilterValue);

                case FilterType.Equal:
                    return(convertedPropertyValue == convertedFilterValue);

                case FilterType.GratherOrEqual:
                    return(convertedPropertyValue >= convertedFilterValue);

                case FilterType.Grather:
                    return(convertedPropertyValue > convertedFilterValue);

                case FilterType.NotEqual:
                    return(convertedPropertyValue != convertedFilterValue);

                case FilterType.In:
                    return(Values.Any(v => convertedFilterValue == Convert.ToDouble(v)));

                default:
                    return(false);
                }
            }

            case "int16":
            {
                Int16 convertedPropertyValue = Convert.ToInt16(propertyValue);
                Int16 convertedFilterValue   = Convert.ToInt16(Values[0]);
                switch (FilterType)
                {
                case FilterType.Less:
                    return(convertedPropertyValue < convertedFilterValue);

                case FilterType.LessOrEqual:
                    return(convertedPropertyValue <= convertedFilterValue);

                case FilterType.Equal:
                    return(convertedPropertyValue == convertedFilterValue);

                case FilterType.GratherOrEqual:
                    return(convertedPropertyValue >= convertedFilterValue);

                case FilterType.Grather:
                    return(convertedPropertyValue > convertedFilterValue);

                case FilterType.NotEqual:
                    return(convertedPropertyValue != convertedFilterValue);

                case FilterType.In:
                    return(Values.Any(v => convertedFilterValue == Convert.ToInt16(v)));

                default:
                    return(false);
                }
            }

            case "int32":
            {
                Int32 convertedPropertyValue = Convert.ToInt32(propertyValue);
                Int32 convertedFilterValue   = Convert.ToInt32(Values[0]);
                switch (FilterType)
                {
                case FilterType.Less:
                    return(convertedPropertyValue < convertedFilterValue);

                case FilterType.LessOrEqual:
                    return(convertedPropertyValue <= convertedFilterValue);

                case FilterType.Equal:
                    return(convertedPropertyValue == convertedFilterValue);

                case FilterType.GratherOrEqual:
                    return(convertedPropertyValue >= convertedFilterValue);

                case FilterType.Grather:
                    return(convertedPropertyValue > convertedFilterValue);

                case FilterType.NotEqual:
                    return(convertedPropertyValue != convertedFilterValue);

                case FilterType.In:
                    return(Values.Any(v => convertedFilterValue == Convert.ToInt32(v)));

                default:
                    return(false);
                }
            }

            case "string":
            {
                string convertedPropertyValue = propertyValue.ToString().Trim().ToLower();
                //для строкового фильтра в FilterType.Equal и FilterType.NotEqual
                //проверяются все значения
                switch (FilterType)
                {
                case FilterType.Equal:
                    return(Values.Select(v => new Pattern(v.ToString().Trim().ToLower(), true, true)).All(p => p.IsMatch(convertedPropertyValue)));

                case FilterType.NotEqual:
                    return(!Values.Select(v => new Pattern(v.ToString().Trim().ToLower(), true, true)).Any(p => p.IsMatch(convertedPropertyValue)));

                case FilterType.In:
                    return(Values.Select(v => new Pattern(v.ToString().Trim().ToLower(), true, true)).Any(p => p.IsMatch(convertedPropertyValue)));

                default:
                    return(false);
                }
            }
            }
            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Сохраняет переданный объект со всеми его вложеными объектами в БД
        /// </summary>
        /// <param name="savingObject">Объект, который необходимо сохранить</param>
        /// <param name="saveChild">сохранять дочерние объекты для данного типа</param>
        /// <param name="saveForced">сохранять свойства помеченные принудительно</param>
        private void SaveAllInternal(BaseEntityObject savingObject,
                                     bool saveChild  = false,
                                     bool saveForced = false)
        {
            if (savingObject == null)
            {
                return;
            }
            if (!saveChild)
            {
                Save(savingObject);

                return;
            }

            // Определение конструкций для загрузки вложенных типов (помеченных атрибутом Child),
            // являющихся BaseSmartCoreObject
            Type type = savingObject.GetType();

            #region Сохранение вложенных объектов в отношении 1 к 1

            //определение своиств, имеющих атрибут "сохраняемое"
            //а так же являющихся вложенными типами
            //и имеющих отношение с данным типом 1 к 1
            List <PropertyInfo> properties;
            if (saveForced)
            {
                //определение своиств, имеющих атрибут "сохраняемое"
                //исключая своиства, которые только считывают информацию из БД
                properties =
                    type.GetProperties().Where(p => (p.GetCustomAttributes(typeof(TableColumnAttribute), false).Length != 0 &&
                                                     ((TableColumnAttribute)p.GetCustomAttributes(typeof(TableColumnAttribute), false).First()).AccessType != ColumnAccessType.WriteOnly) ||
                                               p.GetCustomAttributes(typeof(ChildAttribute), false).Length != 0).ToList();
            }
            else
            {
                //определение своиств, имеющих атрибут "сохраняемое"
                //исключая своиства, которые только записывают информацию в БД
                //и которые загружаются/сохраняются принудительно
                properties =
                    type.GetProperties().Where(p => (p.GetCustomAttributes(typeof(TableColumnAttribute), false).Length != 0 &&
                                                     ((TableColumnAttribute)p.GetCustomAttributes(typeof(TableColumnAttribute), false).First()).AccessType != ColumnAccessType.WriteOnly &&
                                                     ((TableColumnAttribute)p.GetCustomAttributes(typeof(TableColumnAttribute), false).First()).Forced == false) ||
                                               p.GetCustomAttributes(typeof(ChildAttribute), false).Length != 0).ToList();
            }
            foreach (PropertyInfo t in properties)
            {
                Type baseType = t.PropertyType;
                //Определение атрибута сохраняемой таблицы
                TableAttribute childTypeTable =
                    (TableAttribute)t.PropertyType.GetCustomAttributes(typeof(TableAttribute), true)
                    .FirstOrDefault();
                ChildAttribute child =
                    (ChildAttribute)t.GetCustomAttributes(typeof(ChildAttribute), true)
                    .FirstOrDefault();
                while (baseType != null)
                {
                    if (baseType.Name == typeof(BaseEntityObject).Name &&
                        childTypeTable != null && child != null)
                    {
                        SaveAllInternal(t.GetValue(savingObject, null) as BaseEntityObject, child.LoadChild, saveForced);
                        break;
                    }
                    baseType = baseType.BaseType;
                }
            }
            #endregion

            #region Сохранение текущего объекта

            Save(savingObject);

            #endregion

            #region Определение конструкций для загрузки вложенных типов при отношении 1 к *

            //Поиск своиств имеющих только атрибут Child
            //с пареметром RelationType = 1 ко многим
            properties = type.GetProperties().Where(p => p.GetCustomAttributes(typeof(TableColumnAttribute), false).Length == 0 &&
                                                    p.GetCustomAttributes(typeof(SubQueryAttribute), false).Length == 0 &&
                                                    p.GetCustomAttributes(typeof(ChildAttribute), false).Length != 0 &&
                                                    ((ChildAttribute)p.GetCustomAttributes(typeof(ChildAttribute), false).First()).RelationType == RelationType.OneToMany &&
                                                    ((ChildAttribute)p.GetCustomAttributes(typeof(ChildAttribute), false).First()).ColumnAccessType != ColumnAccessType.ReadOnly)
                         .ToList();

            foreach (PropertyInfo t in properties)
            {
                var currentChild = (ChildAttribute)t.GetCustomAttributes(typeof(ChildAttribute), true).First();
                var collection   = t.GetValue(savingObject, null) as ICommonCollection;
                if (collection == null || collection.Count == 0)
                {
                    continue;
                }

                var          genericArgumentType     = collection[0].GetType();
                PropertyInfo foreightKeyTypeProperty = null;
                PropertyInfo foreightKeyProperty     = null;

                //Поиск свойств в дочернем элементе, отвечающих за внешние ключи и обратные ссылки на родителя
                if (!string.IsNullOrEmpty(currentChild.ForeignKeyTypeColumn))
                {
                    foreightKeyTypeProperty = genericArgumentType.GetProperty(currentChild.ForeignKeyTypeColumn);
                }
                if (!string.IsNullOrEmpty(currentChild.ForeignKeyColumn))
                {
                    foreightKeyProperty = genericArgumentType.GetProperty(currentChild.ForeignKeyColumn);
                }

                foreach (BaseEntityObject o in collection)
                {
                    //Если свойства, указывающие на внешние ключи и обратные ссылки на родителя найдены,
                    //то этим свойствам проставляются данные из текущего родителя
                    foreightKeyProperty?.SetValue(o, savingObject.ItemId, null);
                    foreightKeyTypeProperty?.SetValue(o, savingObject.SmartCoreObjectType.ItemId, null);

                    SaveAllInternal(o, currentChild.LoadChild, saveForced);
                }
            }
            #endregion
        }
Exemplo n.º 8
0
        protected override ListViewItem.ListViewSubItem[] GetListViewSubItems(BaseEntityObject item)
        {
            List <ListViewItem.ListViewSubItem> subItems = new List <ListViewItem.ListViewSubItem>();

            //if(item.ItemId == 41043)
            //{

            //}
            if (item is NextPerformance)
            {
                NextPerformance np = (NextPerformance)item;

                double manHours = np.Parent is IEngineeringDirective ? ((IEngineeringDirective)np.Parent).ManHours : 0;
                double cost     = np.Parent is IEngineeringDirective ? ((IEngineeringDirective)np.Parent).Cost : 0;

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.ATAChapter.ToString(), Tag = np.ATAChapter
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.Title, Tag = np.Title
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.Description, Tag = np.Description
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.Type, Tag = np.Type
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.KitsToString, Tag = np.Kits.Count
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.PerformanceSource.ToString(), Tag = np.PerformanceSource
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.Parent.Threshold.RepeatInterval.ToString(), Tag = np.Parent.Threshold.RepeatInterval
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.Remains.ToString(), Tag = np.Remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.WorkType, Tag = np.WorkType
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = np.PerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)np.PerformanceDate), Tag = np.PerformanceDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = manHours.ToString(), Tag = manHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = cost.ToString(), Tag = cost
                });
            }
            else if (item is AbstractPerformanceRecord)
            {
                AbstractPerformanceRecord apr = (AbstractPerformanceRecord)item;
                Lifelength remains            = Lifelength.Null;

                double manHours = apr.Parent is IEngineeringDirective ? ((IEngineeringDirective)apr.Parent).ManHours : 0;
                double cost     = apr.Parent is IEngineeringDirective ? ((IEngineeringDirective)apr.Parent).Cost : 0;

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.ATAChapter.ToString(), Tag = apr.ATAChapter
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.Title, Tag = apr.Title
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.Description, Tag = apr.Description
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.KitsToString, Tag = apr.Kits.Count
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.OnLifelength.ToString(), Tag = apr.OnLifelength
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.Parent.Threshold.RepeatInterval.ToString(), Tag = apr.Parent.Threshold.RepeatInterval
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = remains.ToString(), Tag = remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = apr.WorkType, Tag = apr.WorkType
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = SmartCore.Auxiliary.Convert.GetDateFormat(apr.RecordDate), Tag = apr.RecordDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = manHours.ToString(), Tag = manHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = cost.ToString(), Tag = cost
                });
            }
            else if (item is Directive)
            {
                Directive     directive = (Directive)item;
                AtaChapter    ata       = directive.ATAChapter;
                DirectiveType pdType    = directive.DirectiveType;
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ata.ToString(), Tag = ata
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = directive.Title, Tag = directive.Title
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = directive.Description, Tag = directive.Description
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = pdType.ShortName, Tag = pdType.ShortName
                });

                #region Определение текста для колонки "КИТы"
                subItems.Add(new ListViewItem.ListViewSubItem
                {
                    Text = directive.Kits.Count > 0 ? directive.Kits.Count + " kits" : "",
                    Tag  = directive.Kits.Count
                });
                #endregion

                #region Определение текста для колонки "Первое выполнение"

                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem();
                if (directive.Threshold.FirstPerformanceSinceNew != null && !directive.Threshold.FirstPerformanceSinceNew.IsNullOrZero())
                {
                    subItem.Text = "s/n: " + directive.Threshold.FirstPerformanceSinceNew;
                    subItem.Tag  = directive.Threshold.FirstPerformanceSinceNew;
                }
                if (directive.Threshold.FirstPerformanceSinceEffectiveDate != null &&
                    !directive.Threshold.FirstPerformanceSinceEffectiveDate.IsNullOrZero())
                {
                    if (subItem.Text != "")
                    {
                        subItem.Text += " or ";
                    }
                    else
                    {
                        subItem.Text = "";
                        subItem.Tag  = directive.Threshold.FirstPerformanceSinceEffectiveDate;
                    }
                    subItem.Text += "s/e.d: " + directive.Threshold.FirstPerformanceSinceEffectiveDate;
                }

                subItems.Add(subItem);
                #endregion

                #region Определение текста для колонки "повторяющийся интервал"

                subItem = new ListViewItem.ListViewSubItem();
                if (!directive.Threshold.RepeatInterval.IsNullOrZero())
                {
                    subItem.Text = directive.Threshold.RepeatInterval.ToString();
                    subItem.Tag  = directive.Threshold.RepeatInterval;
                }
                else
                {
                    subItem.Text = "";
                    subItem.Tag  = Lifelength.Null;
                }
                subItems.Add(subItem);
                #endregion

                #region Определение текста для колонки "Остаток/Просрочено на сегодня"
                subItems.Add(new ListViewItem.ListViewSubItem
                {
                    Text = directive.Remains.ToString(),
                    Tag  = directive.Remains
                });
                #endregion

                #region Определение текста для колонки "Тип работ"

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = directive.WorkType.ToString(), Tag = directive.WorkType
                });
                #endregion

                #region Определение текста для колонки "Следующее выполнение"
                subItems.Add(new ListViewItem.ListViewSubItem
                {
                    Text = directive.NextPerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)directive.NextPerformanceDate),
                    Tag  = directive.NextPerformanceDate
                });
                #endregion

                #region Определение текста для колонки "Человек/Часы"

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = directive.ManHours.ToString(), Tag = directive.ManHours
                });
                #endregion

                #region Определение текста для колонки "Стоимость"

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = directive.Cost.ToString(), Tag = directive.Cost
                });
                #endregion
            }
            else if (item is BaseComponent)
            {
                BaseComponent bd  = (BaseComponent)item;
                AtaChapter    ata = bd.ATAChapter;

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ata.ToString(), Tag = ata
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.PartNumber, Tag = bd.PartNumber
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.Description, Tag = bd.Description
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.MaintenanceControlProcess.ShortName, Tag = bd.MaintenanceControlProcess.ShortName
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.Kits.Count > 0 ? bd.Kits.Count + " kits" : "", Tag = bd.Kits.Count
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.LifeLimit.ToString(), Tag = bd.LifeLimit
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = Lifelength.Null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.Remains.ToString(), Tag = bd.Remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ComponentRecordType.Remove.ToString(), Tag = ComponentRecordType.Remove
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.NextPerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)bd.NextPerformanceDate), Tag = bd.NextPerformanceDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.ManHours.ToString(), Tag = bd.ManHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = bd.Cost.ToString(), Tag = bd.Cost
                });
            }
            else if (item is Component)
            {
                Component  d   = (Component)item;
                AtaChapter ata = d.ATAChapter;

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ata.ToString(), Tag = ata
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.PartNumber, Tag = d.PartNumber
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.Description, Tag = d.Description
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.MaintenanceControlProcess.ShortName, Tag = d.MaintenanceControlProcess.ShortName
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.Kits.Count > 0 ? d.Kits.Count + " kits" : "", Tag = d.Kits.Count
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.LifeLimit != null ? d.LifeLimit.ToString() : "", Tag = d.LifeLimit
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = Lifelength.Null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.Remains != null ? d.Remains.ToString() : "", Tag = d.Remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ComponentRecordType.Remove.ToString(), Tag = ComponentRecordType.Remove
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.NextPerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)d.NextPerformanceDate), Tag = d.NextPerformanceDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.ManHours.ToString(), Tag = d.ManHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = d.Cost.ToString(), Tag = d.Cost
                });
            }
            else if (item is ComponentDirective)
            {
                ComponentDirective dd  = (ComponentDirective)item;
                AtaChapter         ata = dd.ParentComponent.ATAChapter;

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ata != null ? ata.ToString() : "", Tag = ata
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.Remarks, Tag = dd.Remarks
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.Kits.Count > 0 ? dd.Kits.Count + " kits" : "", Tag = dd.Kits.Count
                });
                #region Определение текста для колонки "Первое выполнение"

                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem();
                if (dd.Threshold.FirstPerformanceSinceNew != null && !dd.Threshold.FirstPerformanceSinceNew.IsNullOrZero())
                {
                    subItem.Text = "s/n: " + dd.Threshold.FirstPerformanceSinceNew;
                    subItem.Tag  = dd.Threshold.FirstPerformanceSinceNew;
                }
                subItems.Add(subItem);
                #endregion
                #region Определение текста для колонки "повторяющийся интервал"

                subItem = new ListViewItem.ListViewSubItem();
                if (!dd.Threshold.RepeatInterval.IsNullOrZero())
                {
                    subItem.Text = dd.Threshold.RepeatInterval.ToString();
                    subItem.Tag  = dd.Threshold.RepeatInterval;
                }
                else
                {
                    subItem.Text = "";
                    subItem.Tag  = Lifelength.Null;
                }
                subItems.Add(subItem);
                #endregion
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.Remains.ToString(), Tag = dd.Remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.DirectiveType.ToString(), Tag = dd.DirectiveType
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.NextPerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)dd.NextPerformanceDate), Tag = dd.NextPerformanceDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.ManHours.ToString(), Tag = dd.ManHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = dd.Cost.ToString(), Tag = dd.Cost
                });
            }
            else if (item is MaintenanceCheck)
            {
                MaintenanceCheck mc = (MaintenanceCheck)item;
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.Name + (mc.Schedule ? " Shedule" : " Unshedule"), Tag = mc.Name
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.Name, Tag = mc.Name
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.Kits.Count > 0 ? mc.Kits.Count + " kits" : "", Tag = mc.Kits.Count
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.Interval.ToString(), Tag = mc.Interval
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = Lifelength.Null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.Remains.ToString(), Tag = mc.Remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.NextPerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)mc.NextPerformanceDate), Tag = mc.NextPerformanceDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.ManHours.ToString(), Tag = mc.ManHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = mc.Cost.ToString(), Tag = mc.Cost
                });
            }
            else if (item is MaintenanceDirective)
            {
                MaintenanceDirective md  = (MaintenanceDirective)item;
                AtaChapter           ata = md.ATAChapter;
                string type = md.MaintenanceCheck != null ? md.MaintenanceCheck.Name : "MPD";

                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ata != null ? ata.ToString() : "", Tag = ata
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.TaskNumberCheck, Tag = md.TaskNumberCheck
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.Description, Tag = md.Description,
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = type, Tag = type,
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.Kits.Count > 0 ? md.Kits.Count + " kits" : "", Tag = md.Kits.Count
                });
                #region Определение текста для колонки "Первое выполнение"

                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem();
                if (md.Threshold.FirstPerformanceSinceNew != null && !md.Threshold.FirstPerformanceSinceNew.IsNullOrZero())
                {
                    subItem.Text = "s/n: " + md.Threshold.FirstPerformanceSinceNew;
                    subItem.Tag  = md.Threshold.FirstPerformanceSinceNew;
                }
                if (md.Threshold.FirstPerformanceSinceEffectiveDate != null &&
                    !md.Threshold.FirstPerformanceSinceEffectiveDate.IsNullOrZero())
                {
                    if (subItem.Text != "")
                    {
                        subItem.Text += " or ";
                    }
                    else
                    {
                        subItem.Text = "";
                        subItem.Tag  = md.Threshold.FirstPerformanceSinceEffectiveDate;
                    }
                    subItem.Text += "s/e.d: " + md.Threshold.FirstPerformanceSinceEffectiveDate;
                }

                subItems.Add(subItem);
                #endregion
                #region Определение текста для колонки "повторяющийся интервал"

                subItem = new ListViewItem.ListViewSubItem();
                if (!md.Threshold.RepeatInterval.IsNullOrZero())
                {
                    subItem.Text = md.Threshold.RepeatInterval.ToString();
                    subItem.Tag  = md.Threshold.RepeatInterval;
                }
                else
                {
                    subItem.Text = "";
                    subItem.Tag  = Lifelength.Null;
                }
                subItems.Add(subItem);
                #endregion
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.Remains.ToString(), Tag = md.Remains
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.MaintenanceCheck?.ToString(), Tag = md.MaintenanceCheck
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.WorkType.ToString(), Tag = md.WorkType
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.NextPerformanceDate == null ? "N/A" : SmartCore.Auxiliary.Convert.GetDateFormat((DateTime)md.NextPerformanceDate), Tag = md.NextPerformanceDate
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.ManHours.ToString(), Tag = md.ManHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = md.Cost.ToString(), Tag = md.Cost
                });
            }
            else if (item is NonRoutineJob)
            {
                NonRoutineJob job = (NonRoutineJob)item;
                AtaChapter    ata = job.ATAChapter;
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = ata != null ? ata.ToString() : "", Tag = ata
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = job.Description, Tag = job.Description
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "NRC", Tag = "NRC"
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = job.Kits.Count > 0 ? job.Kits.Count + " kits" : "", Tag = job.Kits.Count
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = Lifelength.Null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = Lifelength.Null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = Lifelength.Null
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = ""
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = "", Tag = DateTimeExtend.GetCASMinDateTime()
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = job.ManHours.ToString(), Tag = job.ManHours
                });
                subItems.Add(new ListViewItem.ListViewSubItem {
                    Text = job.Cost.ToString(), Tag = job.Cost
                });
            }
            else
            {
                throw new ArgumentOutOfRangeException($"1135: Takes an argument has no known type {item.GetType()}");
            }

            return(subItems.ToArray());
        }