Пример #1
0
        /// <summary>
        /// Processes the sale prices table events.
        /// </summary>
        /// <param name="dto">The dto.</param>
        private void ProcessSalePricesTableEvents(CatalogEntryDto dto)
        {
            if (dto != null)
            {
                foreach (GridItem item in _removedItems)
                {
                    int id = 0;
                    if (item[_SalePriceIdString] != null && Int32.TryParse(item[_SalePriceIdString].ToString(), out id))
                    {
                        // find the existing one
                        CatalogEntryDto.SalePriceRow row = dto.SalePrice.FindBySalePriceId(id);
                        if (row != null && row.RowState != DataRowState.Deleted)
                        {
                            row.Delete();
                        }
                    }
                }
            }

            _removedItems.Clear();
        }
Пример #2
0
        /// <summary>
        /// Creates the system row.
        /// </summary>
        /// <param name="Mode">The mode.</param>
        /// <param name="RowIndex">Index of the row.</param>
        /// <param name="Item">The item.</param>
        /// <returns></returns>
        protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item)
        {
            int    i = 0;
            object objSysRowAction = Item[i++];
            object objCode         = Item[i++];
            //SaleType
            object objSaleType    = Item[i++];
            object objSaleCode    = Item[i++];
            object objUnitPrice   = Item[i++];
            object objCurrency    = Item[i++];
            object objMinQuantity = Item[i++];
            object objStartDate   = Item[i++];
            object objEndDate     = Item[i++];

            int salePriceId = 0;

            CatalogEntryDto.SalePriceRow newSalePriceRow = null;

            try
            {
                RowAction sysRowAction = RowAction.Default;

                if (objSysRowAction != null)
                {
                    sysRowAction = GetRowActionEnum((string)objSysRowAction);
                }

                string Code;
                if (objCode != null)
                {
                    Code = (string)objCode;
                }
                else
                {
                    throw new AbsentValue("Code");
                }

                bool            bSalePriceIsNew = false;
                CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(Code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0];
                    if (entry.ClassTypeId.Equals(EntryType.Variation, StringComparison.OrdinalIgnoreCase) ||
                        entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase))
                    {
                        if (catalogEntryDto.SalePrice.Count == 0)
                        {
                            if (sysRowAction == RowAction.Update)
                            {
                                throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                            }

                            if (sysRowAction == RowAction.Delete)
                            {
                                throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                            }

                            bSalePriceIsNew = true;
                        }

                        newSalePriceRow             = catalogEntryDto.SalePrice.NewSalePriceRow();
                        newSalePriceRow.ItemCode    = entry.Code;
                        newSalePriceRow.SaleType    = 0;
                        newSalePriceRow.SaleCode    = String.Empty;
                        newSalePriceRow.UnitPrice   = 0;
                        newSalePriceRow.Currency    = GetCatalogDefaultCurrency();
                        newSalePriceRow.MinQuantity = 0;
                        newSalePriceRow.StartDate   = DateTime.UtcNow;
                        newSalePriceRow.EndDate     = DateTime.UtcNow.AddMonths(1);
                    }
                    else
                    {
                        throw new MDPImportException(String.Format("The Entry with code '{0}' has wrong type ('{1}') for Variation/Inventory import.", Code, entry.ClassTypeId));
                    }
                }
                else
                {
                    throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", Code));
                }

                //SalePrice
                if (objSaleType != null)
                {
                    newSalePriceRow.SaleType = (int)GetSaleTypeId((string)objSaleType);
                }

                if (objSaleCode != null)
                {
                    newSalePriceRow.SaleCode = (string)objSaleCode;
                }

                if (objUnitPrice != null)
                {
                    newSalePriceRow.UnitPrice = (decimal)objUnitPrice;
                }

                if (objCurrency != null)
                {
                    newSalePriceRow.Currency = GetCurrencyCode((string)objCurrency);
                }

                if (objMinQuantity != null)
                {
                    newSalePriceRow.MinQuantity = (decimal)objMinQuantity;
                }

                if (objStartDate != null)
                {
                    newSalePriceRow.StartDate = ((DateTime)objStartDate).ToUniversalTime();
                }

                if (objEndDate != null)
                {
                    newSalePriceRow.EndDate = ((DateTime)objEndDate).ToUniversalTime();
                }

                if (bSalePriceIsNew)
                {
                    catalogEntryDto.SalePrice.AddSalePriceRow(newSalePriceRow);
                }
                else
                {
                    IEnumerable <int> result = from SalePriceTable in catalogEntryDto.SalePrice
                                               where SalePriceTable.SaleType == newSalePriceRow.SaleType &&
                                               SalePriceTable.SaleCode == newSalePriceRow.SaleCode &&
                                               SalePriceTable.Currency == newSalePriceRow.Currency &&
                                               SalePriceTable.StartDate == newSalePriceRow.StartDate &&
                                               SalePriceTable.EndDate == newSalePriceRow.EndDate
                                               select SalePriceTable.SalePriceId;

                    if (result.Count() == 0)
                    {
                        if (sysRowAction == RowAction.Update)
                        {
                            throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                        }

                        if (sysRowAction == RowAction.Delete)
                        {
                            throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code));
                        }

                        catalogEntryDto.SalePrice.AddSalePriceRow(newSalePriceRow);
                    }
                    else
                    {
                        if (sysRowAction == RowAction.Insert)
                        {
                            throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' already exists.", Code));
                        }

                        CatalogEntryDto.SalePriceRow salePriceRow = catalogEntryDto.SalePrice.FindBySalePriceId(result.First());

                        if (sysRowAction == RowAction.Delete)
                        {
                            salePriceRow.Delete();
                        }

                        if (sysRowAction == RowAction.Update)
                        {
                            salePriceId              = salePriceRow.SalePriceId;
                            salePriceRow.UnitPrice   = newSalePriceRow.UnitPrice;
                            salePriceRow.MinQuantity = newSalePriceRow.MinQuantity;
                        }
                    }
                }

                using (TransactionScope tx = new TransactionScope())
                {
                    // Save modifications
                    if (catalogEntryDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                    }

                    tx.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item);
            }

            return(salePriceId);
        }