Exemple #1
0
        public IList <Relation.ItemsRelation> GetRelations(int directiveId, int typeId)
        {
            //TODO:(Evgenii Babak) не использовать рукописные запросы
            var qr = BaseQueries.GetSelectQuery <Relation.ItemsRelation>(true) +
                     $" WHERE FirstItemId = {directiveId} AND FirtsItemTypeId = {typeId} OR SecondItemId = {directiveId} AND SecondItemTypeId = {typeId}";

            var ds = _casEnvironment.Execute(qr);

            return(BaseQueries.GetObjectList <Relation.ItemsRelation>(ds.Tables[0]));
        }
        public IList <Relation.ItemsRelation> GetCustomRelations(IEnumerable <int> directiveIds, params int[] type)
        {
            if (!directiveIds.Any())
            {
                return(new List <Relation.ItemsRelation>());
            }
            //TODO:(Evgenii Babak) не использовать рукописные запросы
            var qr = BaseQueries.GetSelectQuery <Relation.ItemsRelation>(true) +
                     $" WHERE (FirstItemId IN ({string.Join(",", directiveIds)}) or SecondItemId In ({string.Join(",", directiveIds)})) and (FirtsItemTypeId in ({string.Join(",", type)}) or SecondItemTypeId in ({string.Join(",", type)})) AND IsDeleted = 0";

            var ds = _casEnvironment.Execute(qr);

            return(BaseQueries.GetObjectList <Relation.ItemsRelation>(ds.Tables[0]));
        }
Exemple #3
0
        /// <summary>
        /// Возвращает все детали, которые должны быть на складе
        /// </summary>
        /// <returns></returns>
        public StockComponentInfo[] GetStockComponentInfosWithCalculation(Store store)
        {
            var qr = StockComponentInfoQueries.GetSelectQuery(store);
            var ds = _casEnvironment.Execute(qr);

            return(CalculateCurrents(StockComponentInfoQueries.GetStockComponentInfoList(ds.Tables[0]).ToArray(), store));
        }
Exemple #4
0
        public List <FlightTrackRecord> GetAllFlightScheduleRecordsForPeriod(DateTime from, DateTime to, bool loadChild = false)
        {
            var fl          = _newLoader.GetObjectList <FlightNumberDTO, FlightNumber>(new Filter("FlightType", FlightType.Schedule.ItemId));
            var flNumberIds = fl.Select(i => i.ItemId);

            var query = BaseQueries.GetSelectQueryColumnOnly <FlightNumberPeriod>(BaseEntityObject.ItemIdProperty);

            query = $"{query} and FlightNumberId in ({string.Join(",", flNumberIds)}) " +
                    $"and (DepartureDate <= {from.ToSqlDate()} or DepartureDate <= {to.ToSqlDate()}) " +
                    $"and (ArrivalDate >= {from.ToSqlDate()} or ArrivalDate >= {to.ToSqlDate()})";

            var res = _environment.Execute(query);
            var ids = new List <int>();

            foreach (DataRow row in res.Tables[0].Rows)
            {
                ids.Add(Convert.ToInt32(row[0].ToString()));
            }

            var tripRecords = _newLoader.GetObjectListAll <FlightTrackRecordDTO, FlightTrackRecord>(new Filter("FlightPeriodId", ids), loadChild).ToList();

            if (loadChild)
            {
                loadChildTrackRecords(tripRecords);
            }

            return(tripRecords);
        }
Exemple #5
0
        /// <summary>
        /// Возвращает все директивы базового агрегата, или самолета
        /// </summary>
        /// <returns></returns>
        public List <MaintenanceDirective> GetMaintenanceDirectives(BaseEntityObject parent, IEnumerable <ICommonFilter> filters = null)
        {
            if (parent == null || (!(parent is Aircraft) && !(parent is BaseComponent)))
            {
                throw new ArgumentNullException();
            }

            var qrs = parent is Aircraft
                                                                        ? MaintenanceDirectiveQueries.GetAircraftDirectivesSelectQuery(((Aircraft)parent).ItemId, filters, true)
                                                                        : MaintenanceDirectiveQueries.GetSelectQuery((BaseComponent)parent, filters, true);

            List <ExecutionResultArgs> resultArgses;
            var ds = _casEnvironment.Execute(qrs, out resultArgses);

            if (resultArgses.Count(r => r.Exception != null) > 0)
            {
                throw resultArgses.First(r => r.Exception != null).Exception;
            }
            var directives = BaseQueries.GetObjectList <MaintenanceDirective>(ds, true);

            if (directives.Count == 0)
            {
                return(directives);
            }

            var directiveIds = directives.Select(d => d.ItemId).ToList();

            //Загрузка задач по компонентам привязанных к задачам из MPD
            //Компонент, для которого привязаны задачи должен находится на том ВС что и задачи MPD
            var itemsRelations = _itemsRelationsDataAccess.GetRelations(directiveIds, SmartCoreType.MaintenanceDirective.ItemId);

            if (itemsRelations.Count > 0)
            {
                foreach (var mpd in directives)
                {
                    mpd.ItemRelations.AddRange(itemsRelations.Where(i => i.FirstItemId == mpd.ItemId || i.SecondItemId == mpd.ItemId));
                }
            }

            return(directives);
        }
        public void DeleteFromWorkPackage(int workPackageId, IEnumerable <IBaseEntityObject> recordsToDelete)
        {
            var recordsIds      = recordsToDelete.Select(r => r.ItemId).ToArray();
            var recordsTypesIds = recordsToDelete.Select(r => r.SmartCoreObjectType.ItemId).Distinct().ToArray();

            var query = BaseQueries.GetDeleteQuery <WorkPackageRecord>(new ICommonFilter[]
            {
                new CommonFilter <int>(WorkPackageRecord.DirectiveIdProperty, FilterType.In, recordsIds),
                new CommonFilter <int>(WorkPackageRecord.WorkPackageItemTypeProperty, FilterType.In, recordsTypesIds),
                new CommonFilter <int>(WorkPackageRecord.WorkPakageIdProperty, workPackageId)
            });

            _environment.Execute(query);
        }
Exemple #7
0
        public int SaveAttachedFile(ItemFileLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("ItemFileLink", "can not be null");
            }

            var dsAfterInsertLink = new DataSet();
            var existsFileId      = FindFileId(link.File);

            if (existsFileId > 0)
            {
                //Присваиваем fileId  файла, обновляем линк и возвращаем Id файла
                link.File.ItemId = existsFileId;

                dsAfterInsertLink = _environment.Execute(ItemFileLinksQueries.GetMergeQuery(), ItemFileLinksQueries.GetParameters(link));
                link.ItemId       = DbTypes.ToInt32(dsAfterInsertLink.Tables[0].Rows[0][0]);

                return(existsFileId);
            }
            //Запоминаем fileId старого файла
            var oldFileId = link.File.ItemId;

            var ds = _environment.Execute(AttachedFileQueries.GetInsertQuery(), AttachedFileQueries.GetParameters(link.File));
            //Запоминаем fileId нового файла
            var newFileId = DbTypes.ToInt32(ds.Tables[0].Rows[0][0]);

            link.File.ItemId = newFileId;

            dsAfterInsertLink = _environment.Execute(ItemFileLinksQueries.GetMergeQuery(), ItemFileLinksQueries.GetParameters(link));
            link.ItemId       = DbTypes.ToInt32(dsAfterInsertLink.Tables[0].Rows[0][0]);

            if (oldFileId > 0)
            {
                DeleteFileIfFileHasNoLinks(oldFileId);
            }

            return(newFileId);
        }