Пример #1
0
        /// <summary>
        /// Расчитывает тек. кол-во комплектующего, и его необходимый запас на заданном складу
        /// </summary>
        /// <param name="component">записи о неснижаемом запасе"></param>
        /// <param name="store">Задает склад, на котором надо проверить данные о неснижаемых запасах</param>
        public void CalculateStock(Entities.General.Accessory.Component component, Store store)
        {
            component.Current         = 0;
            component.ShouldBeOnStock = 0;

            var allShouldBe = new List <StockComponentInfo>(_newLoader.GetObjectListAll <StockComponentInfoDTO, StockComponentInfo>(new List <Filter>()
            {
                new Filter("StoreID", store.ItemId),
                new Filter("ComponentClass", component.GoodsClass.ItemId),
                new Filter("PartNumber", component.PartNumber.Replace(" ", ""))
            }, true));

            foreach (var stock in allShouldBe)
            {
                component.ShouldBeOnStock += stock.ShouldBeOnStock;
            }

            var allStorescomponents = new List <Entities.General.Accessory.Component>();

            allStorescomponents.AddRange(_componentCore.GetStoreBaseComponents(store.ItemId));
            allStorescomponents.AddRange(_componentCore.GetStoreComponents(store).ToArray());

            component.Current =
                allStorescomponents.Count(t => t.GoodsClass == component.GoodsClass &&
                                          t.PartNumber.Replace(" ", "").ToLower() ==
                                          component.PartNumber.Replace(" ", "").ToLower());
        }
Пример #2
0
 private void Check(Entities.General.Accessory.Component component, TransferRecord transferRecord)
 {
     if (transferRecord.ItemId > 0)
     {
         if (transferRecord.TransferDate > component.ActualStateRecords[0].RecordDate.Date)
         {
             throw new Exception("953: You can not change the date on TransferRecord bigger than the first ActualState");
         }
     }
 }
Пример #3
0
        public void SmartCoreFileTest_Detail()
        {
            var enviroment = GetEnviroment();

            var detail = new Entities.General.Accessory.Component
            {
                FaaFormFile = new AttachedFile {
                    FileName = "FaaFormFile.test"
                },
            };

            enviroment.NewKeeper.Save(detail);

            Assert.IsTrue(detail.ItemId > 0, "ItemId должен быть больше 0");

            var forCheck = enviroment.NewLoader.GetObject <ComponentDTO, Entities.General.Accessory.Component>(new Filter("ItemId", detail.ItemId), true);

            enviroment.NewKeeper.Delete(detail);

            Assert.IsTrue(forCheck != null, "значение не должно быть null");
            Assert.AreEqual(forCheck.Files.Count, 1, "Кол-во файлов должно быть 1");
            Assert.IsTrue(forCheck.FaaFormFile != null);
            Assert.AreEqual(forCheck.FaaFormFile.FileName, "FaaFormFile.test");
        }
Пример #4
0
        public IEnumerable <TransferRecord> GetTransferRecord()
        {
            var records = _newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("ReplaceComponentId", FilterType.Grather, 0));

            foreach (var transferRecord in records)
            {
                transferRecord.ReplaceComponent =
                    _componentCore.GetBaseComponentById(transferRecord.ReplaceComponentId) ??
                    _componentCore.GetComponentById(transferRecord.ReplaceComponentId);

                foreach (var record in transferRecord.ReplaceComponent.TransferRecords)
                {
                    #region Откуда перемещен

                    if (record.FromAircraftId > 0)
                    {
                        var a = _aircraftsCore.GetAircraftById(record.FromAircraftId) ??
                                new Aircraft
                        {
                            ItemId             = record.FromAircraftId,
                            IsDeleted          = true,
                            RegistrationNumber = "Can't Find Aircraft with id = " + record.FromAircraftId
                        };
                        record.FromAircraft = a;
                    }


                    if (record.FromBaseComponentId > 0)
                    {
                        var bd = _componentCore.GetBaseComponentById(record.FromBaseComponentId) ??
                                 new BaseComponent
                        {
                            ItemId       = record.FromBaseComponentId,
                            IsDeleted    = true,
                            Description  = "Can't Find Base Component with id = " + record.FromBaseComponentId,
                            PartNumber   = "Unknown",
                            SerialNumber = "Unknown"
                        };

                        var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                        if (a != null)
                        {
                            bd.Aircraft = a.ToString();
                        }

                        record.FromBaseComponent = bd;
                    }

                    if (record.FromStoreId > 0)
                    {
                        var store = _storeCore.GetStoreById(record.FromStoreId) ??
                                    new Store
                        {
                            ItemId    = record.FromStoreId,
                            IsDeleted = true,
                            Name      = "Can't Find Store with id = " + record.FromStoreId,
                        };

                        record.FromStore = store;
                    }

                    #endregion

                    #region Куда перемещен
                    if (record.DestinationObjectType == SmartCoreType.Store)
                    {
                        var store = _storeCore.GetStoreById(record.DestinationObjectId) ??
                                    new Store
                        {
                            ItemId    = record.DestinationObjectId,
                            IsDeleted = true,
                            Name      = "Can't Find Store with id = " + record.DestinationObjectId,
                        };

                        record.DestinationObject = store;
                    }

                    if (record.DestinationObjectType == SmartCoreType.BaseComponent)
                    {
                        var bd = _componentCore.GetBaseComponentById(record.DestinationObjectId) ??
                                 new BaseComponent
                        {
                            ItemId       = record.DestinationObjectId,
                            IsDeleted    = true,
                            Description  = "Can't Find Base Component with id = " + record.DestinationObjectId,
                            PartNumber   = "Unknown",
                            SerialNumber = "Unknown"
                        };

                        var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                        if (a != null)
                        {
                            bd.Aircraft = a.ToString();
                        }

                        record.DestinationObject = bd;
                    }
                    if (record.DestinationObjectType == SmartCoreType.Aircraft)
                    {
                        var a = _aircraftsCore.GetAircraftById(record.DestinationObjectId) ??
                                new Aircraft
                        {
                            ItemId             = record.DestinationObjectId,
                            IsDeleted          = true,
                            RegistrationNumber = "Can't Find Aircraft with id = " + record.DestinationObjectId
                        };
                        record.DestinationObject = a;
                    }
                    #endregion
                }

                #region  одительский объект

                if (transferRecord.ParentType == SmartCoreType.BaseComponent)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.ParentId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.ParentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    transferRecord.ParentComponent = bd;
                }
                else if (transferRecord.ParentType == SmartCoreType.Component)
                {
                    var d = _componentCore.GetComponentById(transferRecord.ParentId) ??
                            new Entities.General.Accessory.Component
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Component with id = " + transferRecord.ParentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };
                    transferRecord.ParentComponent = d;
                }
                else
                {
                    var d = new Entities.General.Accessory.Component
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find object with type = " + transferRecord.ParentType,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };
                    transferRecord.ParentComponent = d;
                }

                #endregion

                #region Откуда перемещен

                if (transferRecord.FromAircraftId > 0)
                {
                    var a = _aircraftsCore.GetAircraftById(transferRecord.FromAircraftId) ??
                            new Aircraft
                    {
                        ItemId             = transferRecord.FromAircraftId,
                        IsDeleted          = true,
                        RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.FromAircraftId
                    };
                    transferRecord.FromAircraft = a;
                }

                if (transferRecord.FromBaseComponentId > 0)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.FromBaseComponentId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.FromBaseComponentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.FromBaseComponentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                    if (a != null)
                    {
                        bd.Aircraft = a.ToString();
                    }

                    transferRecord.FromBaseComponent = bd;
                }

                if (transferRecord.FromStoreId > 0)
                {
                    var store = _storeCore.GetStoreById(transferRecord.FromStoreId) ??
                                new Store
                    {
                        ItemId    = transferRecord.FromStoreId,
                        IsDeleted = true,
                        Name      = "Can't Find Store with id = " + transferRecord.FromStoreId,
                    };

                    transferRecord.FromStore = store;
                }

                #endregion

                #region Куда перемещен
                if (transferRecord.DestinationObjectType == SmartCoreType.Store)
                {
                    var store = _storeCore.GetStoreById(transferRecord.DestinationObjectId) ??
                                new Store
                    {
                        ItemId    = transferRecord.DestinationObjectId,
                        IsDeleted = true,
                        Name      = "Can't Find Store with id = " + transferRecord.DestinationObjectId,
                    };

                    transferRecord.DestinationObject = store;
                }

                if (transferRecord.DestinationObjectType == SmartCoreType.BaseComponent)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.DestinationObjectId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.DestinationObjectId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.DestinationObjectId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                    if (a != null)
                    {
                        bd.Aircraft = a.ToString();
                    }

                    transferRecord.DestinationObject = bd;
                }
                if (transferRecord.DestinationObjectType == SmartCoreType.Aircraft)
                {
                    var a = _aircraftsCore.GetAircraftById(transferRecord.DestinationObjectId) ??
                            new Aircraft
                    {
                        ItemId             = transferRecord.DestinationObjectId,
                        IsDeleted          = true,
                        RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.DestinationObjectId
                    };
                    transferRecord.DestinationObject = a;
                }
                #endregion
            }

            return(records);
        }
Пример #5
0
        /// <summary>
        /// Возвращает все записи о перемешении агрегатов на переданное ВС
        /// </summary>
        /// <returns></returns>
        public IEnumerable <TransferRecord> GetTransferRecordsFromAndTo(Aircraft aircraft, Store s)
        {
            if (aircraft == null && s == null)
            {
                return(null);
            }
            string baseStatement = "";

            var collection = new List <TransferRecord>();

            if (aircraft != null)
            {
                var parentIds = _newLoader.GetSelectColumnOnly <TransferRecordDTO>(new List <Filter>()
                {
                    new Filter("DestinationObjectID", aircraft.ItemId),
                    new Filter("DestinationObjectType", aircraft.SmartCoreObjectType.ItemId),
                }, "ParentID");

                collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>()
                {
                    new Filter("FromAircraftID", aircraft.ItemId),
                    new Filter("FromStoreID", 0),
                }, true).OrderByDescending(t => t.TransferDate));

                collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>()
                {
                    new Filter("DestinationObjectID", aircraft.ItemId),
                    new Filter("DestinationObjectType", aircraft.SmartCoreObjectType.ItemId),
                }, true).OrderByDescending(t => t.TransferDate));

                if (parentIds != null)
                {
                    collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("DestinationObjectID", parentIds), true).OrderByDescending(t => t.TransferDate));
                }
            }
            else
            {
                var parentIds = _newLoader.GetSelectColumnOnly <TransferRecordDTO>(new List <Filter>()
                {
                    new Filter("DestinationObjectID", s.ItemId),
                    new Filter("DestinationObjectType", s.SmartCoreObjectType.ItemId),
                }, "ParentID");

                collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("FromStoreID", s.ItemId), true).OrderByDescending(t => t.TransferDate));

                collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>()
                {
                    new Filter("DestinationObjectID", s.ItemId),
                    new Filter("DestinationObjectType", s.SmartCoreObjectType.ItemId),
                }, true).OrderByDescending(t => t.TransferDate));


                if (parentIds != null)
                {
                    collection.AddRange(_newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new Filter("DestinationObjectID", parentIds), true).OrderByDescending(t => t.TransferDate));
                }
            }


            var ids        = collection.Select(a => a.ParentId);
            var components = _newLoader.GetObjectListAll <ComponentDTO, Entities.General.Accessory.Component>(new List <Filter>()
            {
                new Filter("IsBaseComponent", false),
                new Filter("ItemId", ids)
            }, true, true);

            var transferRecordIds = collection.Select(t => t.ItemId).ToList();
            var filesDict         = _filesDataAccess.GetItemFileLinks(transferRecordIds, SmartCoreType.TransferRecord.ItemId).ToDictionary(d => d.ParentId);

            var suppliersIds = collection.Select(t => t.FromSupplierId).ToList();

            suppliersIds.AddRange(collection.Where(t => t.DestinationObjectType == SmartCoreType.Supplier).Select(t => t.DestinationObjectId).ToArray());
            var suppliers = _newLoader.GetObjectListAll <SupplierDTO, Supplier>(new Filter("ItemId", suppliersIds));

            var specialistIds = new List <int>();

            specialistIds.AddRange(collection.Where(t => t.DestinationObjectType == SmartCoreType.Employee).Select(t => t.DestinationObjectId));
            specialistIds.AddRange(collection.Select(t => t.FromSpecialistId));
            var specialists = _newLoader.GetObjectListAll <SpecialistDTO, Specialist>(new Filter("ItemId", specialistIds));

            foreach (var transferRecord in collection)
            {
                if (filesDict.ContainsKey(transferRecord.ItemId))
                {
                    transferRecord.Files.Add(filesDict[transferRecord.ItemId]);
                }


                #region  одительский объект

                if (transferRecord.ParentType == SmartCoreType.BaseComponent)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.ParentId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.ParentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    transferRecord.ParentComponent = bd;
                }
                else if (transferRecord.ParentType == SmartCoreType.Component)
                {
                    var d = components.GetItemById(transferRecord.ParentId) ??
                            new Entities.General.Accessory.Component
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Component with id = " + transferRecord.ParentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };
                    transferRecord.ParentComponent = d;
                }
                else
                {
                    var d = new Entities.General.Accessory.Component
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find object with type = " + transferRecord.ParentType,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };
                    transferRecord.ParentComponent = d;
                }

                #endregion

                #region Откуда перемещен

                if (transferRecord.FromAircraftId > 0)
                {
                    var a = _aircraftsCore.GetAircraftById(transferRecord.FromAircraftId) ??
                            new Aircraft
                    {
                        ItemId             = transferRecord.FromAircraftId,
                        IsDeleted          = true,
                        RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.FromAircraftId
                    };
                    transferRecord.FromAircraft = a;
                }

                if (transferRecord.FromBaseComponentId > 0)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.FromBaseComponentId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.FromBaseComponentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.FromBaseComponentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                    if (a != null)
                    {
                        bd.Aircraft = a.ToString();
                    }

                    transferRecord.FromBaseComponent = bd;
                }

                if (transferRecord.FromStoreId > 0)
                {
                    var store = _storeCore.GetStoreById(transferRecord.FromStoreId) ??
                                new Store
                    {
                        ItemId    = transferRecord.FromStoreId,
                        IsDeleted = true,
                        Name      = "Can't Find Store with id = " + transferRecord.FromStoreId,
                    };

                    transferRecord.FromStore = store;
                }

                if (transferRecord.FromSupplierId > 0)
                {
                    var supplier = suppliers.FirstOrDefault(x => x.ItemId == transferRecord.FromSupplierId) ??
                                   new Supplier
                    {
                        ItemId    = transferRecord.FromSupplierId,
                        IsDeleted = true,
                        Name      = "Can't Find Supplier with id = " + transferRecord.FromSupplierId
                    };

                    transferRecord.FromSupplier = supplier;
                }

                if (transferRecord.FromSpecialistId > 0)
                {
                    var specialist = specialists.FirstOrDefault(x => x.ItemId == transferRecord.FromSpecialistId) ??
                                     new Specialist
                    {
                        ItemId    = transferRecord.FromSpecialistId,
                        IsDeleted = true,
                        FirstName = "Can't Find Specialist with id = " + transferRecord.FromSpecialistId
                    };

                    transferRecord.FromSpecialist = specialist;
                }

                #endregion

                #region Куда перемещен
                if (transferRecord.DestinationObjectType == SmartCoreType.Store)
                {
                    var store = _storeCore.GetStoreById(transferRecord.DestinationObjectId) ??
                                new Store
                    {
                        ItemId    = transferRecord.DestinationObjectId,
                        IsDeleted = true,
                        Name      = "Can't Find Store with id = " + transferRecord.DestinationObjectId,
                    };

                    transferRecord.DestinationObject = store;
                }

                if (transferRecord.DestinationObjectType == SmartCoreType.BaseComponent)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.DestinationObjectId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.DestinationObjectId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.DestinationObjectId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                    if (a != null)
                    {
                        bd.Aircraft = a.ToString();
                    }

                    transferRecord.DestinationObject = bd;
                }
                if (transferRecord.DestinationObjectType == SmartCoreType.Aircraft)
                {
                    var a = _aircraftsCore.GetAircraftById(transferRecord.DestinationObjectId) ??
                            new Aircraft
                    {
                        ItemId             = transferRecord.DestinationObjectId,
                        IsDeleted          = true,
                        RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.DestinationObjectId
                    };
                    transferRecord.DestinationObject = a;
                }

                if (transferRecord.DestinationObjectType == SmartCoreType.Supplier)
                {
                    var supplier = suppliers.FirstOrDefault(x => x.ItemId == transferRecord.DestinationObjectId) ??
                                   new Supplier
                    {
                        ItemId    = transferRecord.FromSupplierId,
                        IsDeleted = true,
                        Name      = "Can't Find Supplier with id = " + transferRecord.DestinationObjectId
                    };

                    transferRecord.DestinationObject = supplier;
                }

                if (transferRecord.DestinationObjectType == SmartCoreType.Employee)
                {
                    var specialist = specialists.FirstOrDefault(x => x.ItemId == transferRecord.DestinationObjectId) ??
                                     new Specialist
                    {
                        ItemId    = transferRecord.FromSpecialistId,
                        IsDeleted = true,
                        FirstName = "Can't Find Specialist with id = " + transferRecord.DestinationObjectId
                    };

                    transferRecord.DestinationObject = specialist;
                }
                #endregion
            }
            // возвращаем результат
            //SetParents(collection);
            return(collection);
        }
Пример #6
0
        /// <summary>
        /// Удаление TransferRecord
        /// </summary>
        /// <param name="transferRecord"></param>
        public void Delete(TransferRecord transferRecord)
        {
            // Ограничение - если у агрегата только одна transfer record - мы не можем ее удалить ...
            // Добавление & удаление transfer record влияет на математический аппарат
            // Обнуляем математический аппарат
            if (transferRecord.ParentComponent != null)
            {
                if (transferRecord.ParentComponent.TransferRecords.Count == 1)
                {
                    throw new Exception("1153: Can not delete single transfer record");
                }

                if (transferRecord.ConsumableId > 0)
                {
                    //Поиск комплектующего, часть которого была перемещена данной записью
                    Entities.General.Accessory.Component fromConsumable = _componentCore.GetBaseComponentById(transferRecord.ConsumableId)
                                                                          ?? _componentCore.GetComponentById(transferRecord.ConsumableId);
                    if (fromConsumable != null)
                    {
                        //комплектующее найдено
                        //Проверка, находится ли то комплектующее, часть которого была перемещена
                        //на той же локации, с которой была перемещена данная часть
                        TransferRecord consumLocation = fromConsumable.TransferRecords.GetLast();
                        if (consumLocation != null &&
                            ((consumLocation.DestinationObjectType == SmartCoreType.BaseComponent &&
                              consumLocation.DestinationObjectId == transferRecord.FromBaseComponentId) ||
                             (consumLocation.DestinationObjectType == SmartCoreType.Aircraft &&
                              consumLocation.DestinationObjectId == transferRecord.FromAircraftId) ||
                             (consumLocation.DestinationObjectType == SmartCoreType.Store &&
                              consumLocation.DestinationObjectId == transferRecord.FromStoreId)))
                        {
                            //Если последняя точка назначения исходного комплектующего
                            //совпадает с отправной точкой данной части исходного комплектующего
                            //то необходимо удалить данную часть комплектующуго, а кол-во
                            //перемещенных единиц добавить к исходному комплектующему
                            transferRecord.ParentComponent.IsDeleted = true;
                            _newKeeper.Delete(transferRecord.ParentComponent, true, false);

                            fromConsumable.Quantity += transferRecord.ParentComponent.Quantity > 0
                                                                                                                   ? transferRecord.ParentComponent.Quantity
                                                                                                                   : 1;
                            _componentCore.Save(fromConsumable);
                        }
                        else
                        {
                            // Иначе, если не найдена последняя запись о перемещении
                            // исходного расходника или
                            // если исходный расходник был перемещен с отправной точки данной части
                            // то нужно произвести простой откат данной записи о перемещении

                            // Сохраняем запись
                            transferRecord.IsDeleted = true;
                            _newKeeper.Save(transferRecord);
                            transferRecord.ParentComponent.TransferRecords.Remove(transferRecord);

                            // Обновляем состояние объекта
                            _componentCore.SetDestinations(transferRecord.ParentComponent);

                            if (transferRecord.ParentComponent is BaseComponent)
                            {
                                _calculator.ResetMath((BaseComponent)transferRecord.ParentComponent);
                            }
                        }
                    }
                    else
                    {
                        // если исходный расходник не найден
                        // то нужно произвести простой откат данной записи о перемещении

                        // Сохраняем запись
                        transferRecord.IsDeleted = true;
                        _newKeeper.Save(transferRecord);
                        transferRecord.ParentComponent.TransferRecords.Remove(transferRecord);

                        // Обновляем состояние объекта
                        _componentCore.SetDestinations(transferRecord.ParentComponent);

                        if (transferRecord.ParentComponent is BaseComponent)
                        {
                            _calculator.ResetMath((BaseComponent)transferRecord.ParentComponent);
                        }
                    }
                }
                else
                {
                    // Сохраняем запись
                    transferRecord.IsDeleted = true;
                    _newKeeper.Save(transferRecord);
                    transferRecord.ParentComponent.TransferRecords.Remove(transferRecord);

                    // Обновляем состояние объекта
                    _componentCore.SetDestinations(transferRecord.ParentComponent);

                    if (transferRecord.ParentComponent is BaseComponent)
                    {
                        _calculator.ResetMath((BaseComponent)transferRecord.ParentComponent);
                    }
                }
            }
            else
            {
                throw new Exception("1000: Failed to specify tranfer record parent type");
            }
        }
Пример #7
0
        public void ImportComponentStore()
        {
            var env              = GetEnviroment();
            var aircraftCore     = new AircraftsCore(env.Loader, env.NewKeeper, env.NewLoader);
            var itemRelationCore = new ItemsRelationsDataAccess(env);
            var componentCore    = new ComponentCore(env, env.Loader, env.NewLoader, env.NewKeeper, aircraftCore, itemRelationCore);

            var store  = env.Loader.GetObject <Store>(new CommonFilter <int>(BaseEntityObject.ItemIdProperty, 11));
            var models = env.Loader.GetObjectList <ComponentModel>();

            var storeComponent = componentCore.GetStoreComponents(store);

            var ds = ExcelToDataTableUsingExcelDataReader(@"D:\CRJ200 NEW  Compon 1.xlsx");

            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    if (string.IsNullOrEmpty(row[0].ToString()) && string.IsNullOrEmpty(row[1].ToString()) &&
                        string.IsNullOrEmpty(row[2].ToString()))
                    {
                        continue;
                    }

                    var comp = new Entities.General.Accessory.Component();

                    var goodClass = row[0].ToString().Replace('−', '-');
                    comp.GoodsClass = GoodsClass.Items.FirstOrDefault(i => goodClass.ToLower().Equals(i.FullName.ToLower()));
                    if (comp.GoodsClass == null || comp.GoodsClass == GoodsClass.Unknown)
                    {
                        comp.GoodsClass = GoodsClass.Items.FirstOrDefault(i => goodClass.ToLower().Contains(i.FullName.ToLower()));
                    }
                    if (comp.GoodsClass == null || comp.GoodsClass == GoodsClass.Unknown)
                    {
                        comp.GoodsClass = GoodsClass.Items.FirstOrDefault(i => goodClass.ToLower().Contains(i.ShortName.ToLower()));
                    }


                    comp.PartNumber    = row[3].ToString();
                    comp.ALTPartNumber = row[4].ToString();
                    comp.SerialNumber  = row[5].ToString();
                    comp.BatchNumber   = row[6].ToString();
                    comp.Remarks       = $"{DateTime.Today} CIT Comp";

                    Double.TryParse(row[7].ToString().Replace('.', ','), out double quantityIn);
                    Double.TryParse(row[8].ToString().Replace('.', ','), out double current);

                    comp.QuantityIn = quantityIn;
                    comp.Quantity   = current;

                    #region E&M

                    //comp.Product = models.FirstOrDefault(i =>i.PartNumber == comp.PartNumber);
                    //comp.Measure = Measure.Unit;

                    #endregion

                    comp.Model   = models.FirstOrDefault(i => i.PartNumber == comp.PartNumber);
                    comp.Measure = Measure.Unknown;

                    //comp.GoodsClass = GoodsClass.MaintenanceMaterials;
                    DateTime.TryParse(row[1].ToString(), out var date);
                    if (date.Year < DateTimeExtend.GetCASMinDateTime().Year)
                    {
                        date = DateTimeExtend.GetCASMinDateTime();
                    }
                    comp.ManufactureDate = date;


                    var find = storeComponent.FirstOrDefault(i => i.PartNumber == comp.PartNumber &&
                                                             i.SerialNumber == comp.SerialNumber &&
                                                             i.BatchNumber == comp.BatchNumber);
                    if (find != null)
                    {
                        continue;
                    }

                    componentCore.AddComponent(comp, store, date, "", ComponentStorePosition.Serviceable, destinationResponsible: true);


                    Double.TryParse(row[10].ToString().Replace('.', ','), out double unitPrice);
                    Double.TryParse(row[11].ToString().Replace('.', ','), out double totalPrice);

                    comp.ProductCosts = new CommonCollection <ProductCost>()
                    {
                        new ProductCost
                        {
                            Currency     = Сurrency.USD,
                            UnitPrice    = unitPrice,
                            TotalPrice   = totalPrice,
                            ParentId     = comp.ItemId,
                            ParentTypeId = comp.SmartCoreType.ItemId
                        }
                    };
                    foreach (var compProductCost in comp.ProductCosts)
                    {
                        env.Keeper.Save(compProductCost);
                    }
                }
            }
        }
Пример #8
0
        public void ImportComponent()
        {
            var env = GetEnviroment();

            var aircraftCore     = new AircraftsCore(env.Loader, env.NewKeeper, env.NewLoader);
            var itemRelationCore = new ItemsRelationsDataAccess(env);
            var componentCore    = new ComponentCore(env, env.Loader, env.NewLoader, env.NewKeeper, aircraftCore, itemRelationCore);

            var ds             = ExcelToDataTableUsingExcelDataReader(@"H:\Components3720.xlsx");
            var baseComponents = componentCore.GetAicraftBaseComponents(2348);
            var ata            = env.NewLoader.GetObjectListAll <ATAChapterDTO, AtaChapter>();

            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    BaseComponent baseComp;
                    var           description   = row[0].ToString();
                    var           remarks       = $"Used On: {row[1]}";
                    var           partNumber    = row[2].ToString();
                    var           serialNumber  = row[5].ToString();
                    var           position      = row[6].ToString();
                    var           ataNumber     = Convert.ToInt32(row[11].ToString());
                    var           hiddenRemarks = $"X Station : {row[7]} \n Y Buttockline : {row[8]} \n Z Waterline : {row[9]} \n ";
                    var           instDate      = new DateTime(2018, 3, 28);


                    var component = new Entities.General.Accessory.Component
                    {
                        PartNumber      = partNumber,
                        SerialNumber    = serialNumber,
                        Description     = description,
                        Remarks         = remarks,
                        HiddenRemarks   = hiddenRemarks,
                        ManufactureDate = instDate,
                        StartDate       = instDate,
                        DeliveryDate    = instDate
                    };

                    if (ataNumber == 49)
                    {
                        baseComp             = baseComponents.FirstOrDefault(i => i.BaseComponentType == BaseComponentType.Apu);
                        component.ATAChapter = ata.FirstOrDefault(i => i.ShortName.Equals(ataNumber.ToString()));
                        component.GoodsClass = GoodsClass.AircraftBaseComponentsApu;
                    }
                    else if (ataNumber == 32)
                    {
                        baseComp             = baseComponents.FirstOrDefault(i => i.BaseComponentType == BaseComponentType.LandingGear);
                        component.ATAChapter = ata.FirstOrDefault(i => i.ShortName.Equals(ataNumber.ToString()));
                        component.GoodsClass = GoodsClass.AircraftBaseComponentsLandingGear;
                    }
                    else if (ataNumber >= 70)
                    {
                        baseComp             = baseComponents.FirstOrDefault(i => i.BaseComponentType == BaseComponentType.Engine);
                        component.ATAChapter = ata.FirstOrDefault(i => i.ShortName.Equals(ataNumber.ToString()));
                        component.GoodsClass = GoodsClass.AircraftBaseComponentsEngine;
                    }
                    else
                    {
                        baseComp             = baseComponents.FirstOrDefault(i => i.BaseComponentType == BaseComponentType.Frame);
                        component.ATAChapter = ata.FirstOrDefault(i => i.ShortName.Equals(ataNumber.ToString()));
                        component.GoodsClass = GoodsClass.AircraftBaseComponents;
                    }

                    componentCore.AddComponent(component, baseComp, instDate, position, null, null, null, null, true);
                }
            }
        }
Пример #9
0
 public Lifelength GetFlightLifelengthOnEndOfDay(Entities.General.Accessory.Component component, DateTime effectiveDate)
 {
     return(_provider.GetFlightLifelengthOnEndOfDayComponent(component.ItemId, effectiveDate));
 }
Пример #10
0
 public Lifelength GetCurrentFlightLifelength(Entities.General.Accessory.Component component)
 {
     return(_provider.GetCurrentFlightLifelengthComponent(component.ItemId));
 }
Пример #11
0
        ///<summary>
        /// Проставляет товар и стандарт для комплектующего
        ///</summary>
        ///<returns>true - если удалось определеить и проставить продукт и стандарт для комплектующего</returns>
        public bool SetStandartAndProduct(AbstractAccessory accessory,
                                          string standartName, string partialNumber, string description, string remarks, string manufacturer,
                                          GoodsClass goodsClass, Measure measure,
                                          double costNew, double costOverhaul, double costServiceable,
                                          IEnumerable <Supplier> suppliers)
        {
            if (accessory == null)
            {
                throw new ArgumentException("must be not null", "accessory");
            }

            if (accessory.Product != null && accessory.Product.ItemId > 0)
            {
                return(true);
            }

            string       standart            = standartName.Replace(" ", "").ToLower();
            string       partNumber          = partialNumber.Replace(" ", "").ToLower();
            bool         needToSaveAccessory = false;
            bool         result       = true;
            GoodStandart goodStandart = null;

            List <GoodStandart> goodStandarts = _loader.GetObjectList <GoodStandart>();
            List <Product>      products;

            if (accessory is Entities.General.Accessory.Component)
            {
                products = new List <Product>(_loader.GetObjectList <ComponentModel>(loadChild: true).ToArray());
            }
            else
            {
                products = _loader.GetObjectList <Product>(loadChild: true);
            }
            if (goodStandarts != null && !string.IsNullOrEmpty(standart))
            {
                goodStandart = goodStandarts
                               .FirstOrDefault(ad => ad.PartNumber.Replace(" ", "").ToLower() == partNumber &&
                                               ad.FullName.Replace(" ", "").ToLower() == standart);
                if (goodStandart == null)
                {
                    goodStandart = new GoodStandart
                    {
                        GoodsClass  = goodsClass,
                        PartNumber  = partialNumber,
                        Description = description,
                        FullName    = standartName,
                        //CostNew = costNew,
                        //CostServiceable = costServiceable,
                        //CostOverhaul = costOverhaul,
                        Remarks = remarks,
                        //Measure = measure
                    };

                    _newKeeper.Save(goodStandart);
                }
                accessory.Standart = goodStandart;

                needToSaveAccessory = true;
            }
            if ((manufacturer != "" || suppliers != null && suppliers.Any()) && products != null)
            {
                Product product = products
                                  .FirstOrDefault(p => p.PartNumber.Replace(" ", "").ToLower() == partNumber &&
                                                  p.Standart != null && p.Standart.FullName.Replace(" ", "").ToLower() == standart);
                if (product == null)
                {
                    if (accessory is Entities.General.Accessory.Component)
                    {
                        ComponentModel dm = new ComponentModel
                        {
                            BatchNumber     = "",
                            CostNew         = costNew,
                            CostOverhaul    = costOverhaul,
                            CostServiceable = costServiceable,
                            Description     = description,
                            GoodsClass      = goodsClass,
                            Manufacturer    = manufacturer,
                            Measure         = measure,
                            PartNumber      = partNumber,
                            Remarks         = remarks,
                        };
                        product = dm;
                    }
                    else
                    {
                        product = new Product
                        {
                            GoodsClass      = goodsClass,
                            PartNumber      = partialNumber,
                            Description     = description,
                            Manufacturer    = manufacturer,
                            Standart        = goodStandart,
                            CostNew         = costNew,
                            CostServiceable = costServiceable,
                            CostOverhaul    = costOverhaul,
                            Remarks         = remarks,
                            Measure         = measure
                        };
                    }

                    _newKeeper.Save(product);

                    if (goodStandart != null && goodStandart.DefaultProductId <= 0)
                    {
                        goodStandart.DefaultProductId = product.ItemId;
                        _newKeeper.Save(goodStandart);
                    }

                    product.SupplierRelations.Clear();
                    foreach (KitSuppliersRelation ksr in accessory.SupplierRelations)
                    {
                        if (ksr.SupplierId != 0)
                        {
                            product.SupplierRelations.Add(ksr);
                            ksr.KitId        = product.ItemId;
                            ksr.ParentTypeId = product.SmartCoreObjectType.ItemId;

                            _newKeeper.Save(ksr);
                        }
                    }
                }

                Entities.General.Accessory.Component component = accessory as Entities.General.Accessory.Component;
                if (component != null)
                {
                    component.Model = product as ComponentModel;
                }
                else
                {
                    accessory.Product = product;
                }

                needToSaveAccessory = true;
            }
            else
            {
                accessory.Product = null;
                result            = false;
            }

            if (needToSaveAccessory)
            {
                _newKeeper.Save(accessory);
            }

            return(result);
        }