Beispiel #1
0
        /// <summary>
        /// Сохранение Запросного ордера
        /// </summary>
        public RequestForQuotation AddQuotationOrder(IEnumerable <KeyValuePair <Product, double> > quotationList, BaseEntityObject parent, out string message)
        {
            if (parent == null)
            {
                message = "Not set parent." +
                          "\nFailed to create empty quotation order";
                return(null);
            }

            if (!(parent is Aircraft) && !(parent is Operator) && !(parent is Store))
            {
                message = "Parent must be Aircraft or Store or Operator." +
                          "\nFailed to create empty quotation order";
                return(null);
            }

            if (quotationList == null)
            {
                message = "Selected tasks not have a accessories." +
                          "\nFailed to create empty quotation order";
                return(null);
            }

            var rqst = new RequestForQuotation
            {
                Description    = "",
                Status         = WorkPackageStatus.Opened,
                Author         = _casEnvironment.Operators[0].Name,
                OpeningDate    = DateTime.Today,
                PublishingDate = new DateTime(1852, 01, 01),
                ClosingDate    = new DateTime(1852, 01, 01),
                Remarks        = "",
                ParentType     = parent.SmartCoreObjectType,
                ParentId       = parent.ItemId,
                Title          = parent + "-QO-" + DateTime.Now
            };

            _newKeeper.Save(rqst);

            #region Формирование записей рабочего пакета
            foreach (var item in quotationList)
            {
                Product product  = item.Key;
                double  quantity = item.Value;

                var record =
                    rqst.PackageRecords.FirstOrDefault(r => r.PackageItemType == product.SmartCoreObjectType &&
                                                       r.PackageItemId == product.ItemId);
                if (record != null)
                {
                    record.Quantity += item.Value;
                }
                else
                {
                    record = new RequestForQuotationRecord(rqst.ItemId, product, quantity);
                    rqst.PackageRecords.Add(record);
                }
            }
            #endregion

            #region Сохранение рабочего пакета и его записей

            foreach (var item in rqst.PackageRecords)
            {
                item.ParentPackageId = rqst.ItemId;
                _newKeeper.Save(item);
            }

            message = "Items added successfully";

            #endregion

            return(rqst);
        }
Beispiel #2
0
        /// <summary>
        /// Добавление элементов в существующий открытый или опубликованный рабочий пакет
        /// </summary>
        /// <param name="quotationItems">Элементы, которые необходимо добавить</param>
        /// <param name="quotationId">ID пакета, в который добавляютя элементы</param>
        /// <param name="message">Сообщение о статусе добавления-корректно или описание ошибки при добавлении</param>
        /// <return>true - если добавление прошло успешно или false в случае провала </return>
        public bool AddToQuotationOrder(List <KeyValuePair <Product, double> > quotationItems, int quotationId, out string message)
        {
            if (quotationItems == null || /*parentAircraft == null ||*/ quotationId <= 0)
            {
                throw new NullReferenceException("1504: NullReferenceException");
            }

            #region Проверка состояния рабочего пакета

            var addTo = _loader.GetObject <RequestForQuotation>(quotationId, true, loadDeleted: true);
            if (addTo == null)
            {
                message = "Quotation Order with id: " + quotationId + " does not exist." +
                          "\nFailed to add items to Quotation Order ";
                return(false);
            }

            if (addTo.IsDeleted)
            {
                message = "Quotation Order : " + addTo.Title + " is deleted." +
                          "\nFailed to add items to deleted Quotation Order ";
                return(false);
            }

            if (addTo.Status == WorkPackageStatus.Closed)
            {
                message = "Quotation Order : " + addTo.Title + " is Closed." +
                          "\nFailed to add items to closed Quotation Order ";
                return(false);
            }

            #endregion

            #region Проверка Переданных элементов для формирования рабочего пакета)

            if (!quotationItems.Any())
            {
                message = "Selected tasks not have a Items." +
                          "\nFailed to add items to Quotation Order";
                return(false);
            }

            #endregion

            #region Формирование записей рабочего пакета
            foreach (var item in quotationItems)
            {
                Product product  = item.Key;
                double  quantity = item.Value;

                var record =
                    addTo.PackageRecords.FirstOrDefault(r => r.PackageItemType == product.SmartCoreObjectType &&
                                                        r.PackageItemId == product.ItemId);
                if (record != null)
                {
                    record.Quantity += item.Value;
                }
                else
                {
                    record = new RequestForQuotationRecord(quotationId, product, quantity);
                    addTo.PackageRecords.Add(record);
                }
            }
            #endregion

            #region Сохранение рабочего пакета и его записей

            foreach (var item in addTo.PackageRecords)
            {
                item.ParentPackageId = addTo.ItemId;
                _newKeeper.Save(item);
            }

            message = "Items added successfully";

            #endregion

            return(true);
        }
Beispiel #3
0
 /// <summary>
 /// Создает запись  без дополнительной информации
 /// </summary>
 public IORQORRelation(InitialOrderRecord initialOrderRecord, RequestForQuotationRecord requestForQuotationRecord) : this()
 {
     _initialOrderRecord        = initialOrderRecord;
     _requestForQuotationRecord = requestForQuotationRecord;
 }