/// <summary> /// Handles the Click event of the SaveChangesButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void SaveChangesButton_Click(object sender, EventArgs e) { CatalogEntryDto.SalePriceRow row = null; if (SalePriceId != 0) // find existing { row = _CatalogEntryDto.SalePrice.FindBySalePriceId(SalePriceId); } // if not found, create new if (row == null) { row = _CatalogEntryDto.SalePrice.NewSalePriceRow(); row.Currency = ""; //row.ItemCode = ""; } // update SalePrice fields if (row != null) { row.SaleCode = SaleCode.Text; decimal price = Decimal.Parse(UnitPrice.Text); row.UnitPrice = price; ListItem selectedItem = SaleTypeFilter.Items.FindByValue(SelectedSaleTypeField.Value); if (selectedItem != null) { row.SaleType = Int32.Parse(selectedItem.Value); ManagementHelper.SelectListItem(SaleTypeFilter, row.SaleType); } selectedItem = CurrencyFilter.Items.FindByValue(SelectedCurrencyField.Value); if (selectedItem != null) { row.Currency = selectedItem.Value; ManagementHelper.SelectListItem(CurrencyFilter, row.Currency); } row.MinQuantity = Decimal.Parse(MinQuantity.Text); row.StartDate = StartDate.Value.ToUniversalTime(); row.EndDate = EndDate.Value.ToUniversalTime(); if (row.RowState == DataRowState.Detached) { _CatalogEntryDto.SalePrice.Rows.Add(row); } } ScriptManager.RegisterStartupScript(MetaDataTab, typeof(SalePriceEditPopup), "DialogClose", "SalePriceEdit_CloseDialog();", true); }
/// <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(); }
/// <summary> /// Clones the node entry. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogEntryId">The catalog entry id.</param> /// <param name="targetCatalogId">The target catalog id.</param> /// <param name="targetCatalogNodeId">The target catalog node id.</param> private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { using (TransactionScope scope = new TransactionScope()) { CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { if (catalogId <= 0) { catalogId = catalogEntryDto.CatalogEntry[0].CatalogId; } if (targetCatalogId <= 0) { targetCatalogId = catalogId; } CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId); CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto(); newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]); newCatalogEntryDto.CatalogEntry[0].SetAdded(); newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString(); if (catalogEntryDto.CatalogItemSeo.Count > 0) { foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows) { newCatalogEntryDto.CatalogItemSeo.ImportRow(row); newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded(); newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx"; } } if (catalogEntryDto.Variation.Count > 0) { foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows) { newCatalogEntryDto.Variation.ImportRow(row); newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded(); } } if (catalogEntryDto.SalePrice.Count > 0) { foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows) { CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow(); newRow.ItemArray = row.ItemArray; newRow.ItemCode = newCatalogEntryDto.CatalogEntry[0].Code; newCatalogEntryDto.SalePrice.Rows.Add(newRow); //newCatalogEntryDto.SalePrice.ImportRow(row); //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code; //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded(); } } if (catalogEntryDto.Inventory.Count > 0) { foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows) { newCatalogEntryDto.Inventory.ImportRow(row); newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded(); newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code; } } if (newCatalogEntryDto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto); } if (newCatalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0]; int newCatalogEntryId = entry.CatalogEntryId; int metaClassId = entry.MetaClassId; // load list of MetaFields for MetaClass MetaClass metaClass = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId); MetaFieldCollection metaFields = metaClass.MetaFields; // cycle through each language and get meta objects CatalogContext.MetaDataContext.UseCurrentUICulture = false; string[] languages = GetCatalogLanguages(catalogId); if (languages != null) { foreach (string language in languages) { CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = language; MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId); MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName); foreach (MetaField metaField in metaFields) { // skip system MetaFields if (!metaField.IsUser) { continue; } switch (metaField.DataType) { case MetaDataType.File: case MetaDataType.Image: case MetaDataType.ImageFile: MetaFile metaFile = (MetaFile)metaObject[metaField]; if (metaFile != null) { newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer); } break; default: if (metaObject[metaField] != null) { newMetaObject[metaField] = metaObject[metaField]; } break; } } newMetaObject.AcceptChanges(CatalogContext.MetaDataContext); } } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto(); foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows) { if (row.ParentEntryId == catalogEntryId) { newCatalogRelationDto.CatalogEntryRelation.ImportRow(row); newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded(); newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId; } } if (targetCatalogNodeId > 0) { foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows) { if (row.CatalogEntryId == catalogEntryId) { newCatalogRelationDto.NodeEntryRelation.ImportRow(row); newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded(); newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId = targetCatalogId; newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId = targetCatalogNodeId; newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId; } } } if (newCatalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto); } CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto(); foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows) { newCatalogAssociationDto.CatalogAssociation.ImportRow(row); newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded(); newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId; } foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows) { newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row); newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded(); //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId; } if (newCatalogAssociationDto.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto); } } } scope.Complete(); } }
/// <summary> /// Binds the form. /// </summary> /// <param name="reset">if set to <c>true</c> [reset].</param> private void BindForm(bool reset) { if (SaleTypeFilter.Items.Count == 0) { BindSaleTypesList(); } if (CurrencyFilter.Items.Count == 0) { BindCurrenciesList(); // select default currency ManagementHelper.SelectListItemIgnoreCase(CurrencyFilter, _CatalogCurrency); } if (String.IsNullOrEmpty(SelectedSaleTypeField.Value)) { SelectedSaleTypeField.Value = SaleTypeFilter.SelectedValue; } if (String.IsNullOrEmpty(SelectedCurrencyField.Value)) { SelectedCurrencyField.Value = CurrencyFilter.SelectedValue; } CatalogEntryDto.SalePriceRow selectedSalePriceRow = null; if (SalePriceId != 0) { selectedSalePriceRow = _CatalogEntryDto.SalePrice.FindBySalePriceId(SalePriceId); } if (selectedSalePriceRow != null) { if (reset) { SetFormFieldsValues(selectedSalePriceRow.SaleCode, selectedSalePriceRow.UnitPrice, selectedSalePriceRow.MinQuantity, selectedSalePriceRow.StartDate, selectedSalePriceRow.EndDate, selectedSalePriceRow.SaleType, selectedSalePriceRow.Currency); } ManagementHelper.SelectListItem2(SaleTypeFilter, selectedSalePriceRow.SaleType); ManagementHelper.SelectListItem2(CurrencyFilter, selectedSalePriceRow.Currency); } else if (reset) { if (_CatalogEntryDto != null) { SetFormFieldsValues("", 0m, 0m, DateTime.UtcNow, DateTime.UtcNow.AddYears(1), -1, _CatalogCurrency); } else { SetFormFieldsValues("", 0m, 0m, DateTime.UtcNow, DateTime.UtcNow.AddYears(1), -1, _CatalogCurrency); } ManagementHelper.SelectListItem2(CurrencyFilter, _CatalogCurrency); } }
/// <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); }