And the code-behind to:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI.WebControls;
using Litium;
using Litium.Foundation.Modules.ECommerce.Plugins.Campaigns;
using Litium.Foundation.Modules.ExtensionMethods;
using Litium.Foundation.Modules.ProductCatalog;
using Litium.Products;
using Litium.Studio.KC.Samples.Campaigns;
using Litium.Studio.UI.Common;
using Litium.Studio.UI.Common.Carriers;
using Litium.Studio.UI.ECommerce.Common;
using Litium.Studio.UI.ECommerce.Common.Constants;
using Litium.Web.Administration.FieldFramework;
using Telerik.Web.UI;
using SystemStringConstants = Litium.Foundation.GUI.Constants.SystemStringConstants;
namespace Web.Site.ECommerce.Campaigns.KC
{
public partial class ReducePriceByAmountActionControl : UserBaseControl, IUIExtensionPanel
{
#region Control State
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Page.RegisterRequiresControlState(this);
Controls.Add(LoadControl("~/Litium/ECommerce/WebUserControls/ProductCatalogDialog.ascx")); //
}
protected override object SaveControlState()
{
return _data;
}
protected override void LoadControlState(object state)
{
if (state != null)
{
_data = state as ReducePriceByAmountAction.Data;
}
}
#endregion Control State
#region Constants
protected static class DialogType
{
public const string SELECT_ARTICLE = "7";
public const string SELECT_ASSORTMENT = "3";
public const string SELECT_PRODUCT_GROUP = "4";
public const string SELECT_PRODUCT_SET = "5";
}
/// <summary>
/// DataField name of display name column.
/// </summary>
private const string DISPLAY_NAME_COLUMN = "DisplayName";
/// <summary>
/// DataField name of article number column.
/// </summary>
private const string ARTICLE_NUMBER_COLUMN = "ArticleNumber";
/// <summary>
/// DataField name of location column.
/// </summary>
private const string LOCATION_COLUMN = "Location";
/// <summary>
/// DataField name of assortment column.
/// </summary>
private const string ASSORTMENT_COLUMN = "Assortment";
private readonly Guid PROPERTY_ID = new Guid("61B3AB55-3B97-4B48-820C-E69C981ACB54");
private CategoryService _categoryService = IoC.Resolve<CategoryService>();
private AssortmentService _assortmentService = IoC.Resolve<AssortmentService>();
#endregion
#region Property
ReducePriceByAmountAction.Data Data {
set {
_data = value;
}
get {
if (_data == null)
return _data = new ReducePriceByAmountAction.Data { SelectedIDs = new List<Guid>(), SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.Articles, MaxDiscountsPerItemInOrder = -1 };
return _data;
}
}
private ReducePriceByAmountAction.Data _data;
private Hashtable SelectedItemIds {
set {
Session[ProductCatalogItemCarrier.SESSION_KEY_SELECTED_ITEMS] = value;
Session[ProductCatalogItemCarrier.SESSION_KEY_SELECTED_EXTRA_ITEMS] = value;
}
}
private string CampaignSelectedWebSite {
get {
string result = string.Empty;
if (Session[SessionConstants.ECOM_CAMPAIGNS_SELECTED_WEBSITE] != null)
{
result = Session[SessionConstants.ECOM_CAMPAIGNS_SELECTED_WEBSITE] as string;
}
return result;
}
}
#endregion Property
#region Private Metods
/// <summary>
/// Initializes the validation on page.
/// </summary>
private void InitializeValidation()
{
c_percentageRegexValidator.CssClass = ParameterConstants.VALIDATOR_STYLE_NAME;
c_percentageRegexValidator.Text = String.Format("{0} {1}", ParameterConstants.VALIDATOR_IMAGE,
SystemStrings.GetValue(SystemStringConstants.VALIDATION_MESSAGE_INVALID_INPUT,
FoundationContext.LanguageID, true));
string requiredMessage = String.Format("{0} {1}", ParameterConstants.VALIDATOR_IMAGE,
SystemStrings.GetValue(SystemStringConstants.VALIDATION_MESSAGE_REQUIRED_FIELD,
FoundationContext.LanguageID, true));
c_percentageRequiredValidator.CssClass = ParameterConstants.VALIDATOR_STYLE_NAME;
c_percentageRequiredValidator.Text = requiredMessage;
}
/// <summary>
/// Initialize description of the action.
/// </summary>
private void InitializeDescription()
{
string description = CurrentModule.Strings.GetValue("ReducePriceByAmountActionDescriptionGeneral",
FoundationContext.LanguageID, true);
string selectedType = string.Empty;
switch (Data.SelectedIdType)
{
case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
selectedType = CurrentModule.Strings.GetValue("CampaignAssortments", FoundationContext.LanguageID, true).Replace(" ", " ");
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
selectedType = CurrentModule.Strings.GetValue("CampaignProductGroups", FoundationContext.LanguageID, true).Replace(" ", " ");
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
selectedType = CurrentModule.Strings.GetValue("CampaignProductSets", FoundationContext.LanguageID, true).Replace(" ", " ");
break;
default:
selectedType = CurrentModule.Strings.GetValue("CampaignProducts", FoundationContext.LanguageID, true).Replace(" ", " ");
break;
}
c_labelDescription.Text = string.Format(description, selectedType);
}
/// <summary>
/// Initializes the grids columns.
/// </summary>
private void InitializeGridsColumns()
{
ModuleProductCatalog pcModule = ModuleProductCatalog.Instance;
string columnName = FoundationContext.SystemStrings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_articlesGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;
columnName = pcModule.Strings.GetValue("ArticleNumber", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_articlesGrid.MasterTableView.Columns.FindByDataField(ARTICLE_NUMBER_COLUMN).HeaderText = columnName;
columnName = pcModule.Strings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_productGroupsGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;
columnName = pcModule.Strings.GetValue("Location", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_productGroupsGrid.MasterTableView.Columns.FindByDataField(LOCATION_COLUMN).HeaderText = columnName;
columnName = pcModule.Strings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_assortmentGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;
columnName = pcModule.Strings.GetValue("Name", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_productSetsGrid.MasterTableView.Columns.FindByDataField(DISPLAY_NAME_COLUMN).HeaderText = columnName;
columnName = pcModule.Strings.GetValue("Location", FoundationContext.LanguageID, true).Replace(" ", " ");
if (!string.IsNullOrEmpty(columnName))
c_productSetsGrid.MasterTableView.Columns.FindByDataField(ASSORTMENT_COLUMN).HeaderText = columnName;
}
/// <summary>
/// Initializes the popup window dialog.
/// </summary>
private void InitializePopupWindowsDialog()
{
HideGrids();
String gridClientId = ConfigureGrids();
if (ModuleProductCatalog.ExistsInstance)
{
c_buttonAdd.Attributes.Add(ParameterConstants.JAVASCRIPT_ON_CLICK,
String.Format("OpenSelectFromProductCatalogGridResult('', '{0}', '', '{1}', '1', '0', '', '', '{2}','','{3}','{4}'); return false;",
c_hiddenFieldIDs.ClientID, c_selectionRadiobuttonlist.SelectedValue, gridClientId, PROPERTY_ID, CampaignSelectedWebSite));
}
else
{
c_buttonAdd.Visible = false;
}
}
/// <summary>
/// Initializes the radio button list control.
/// </summary>
private void InitializeRadioButtonListControl()
{
c_selectionRadiobuttonlist.Items.Clear();
var item = new ListItem();
item.Value = DialogType.SELECT_ARTICLE;
item.Text = CurrentModule.Strings.GetValue("CampaignProducts", FoundationContext.LanguageID, true).Replace(" ", " ");
c_selectionRadiobuttonlist.Items.Add(item);
item = new ListItem();
item.Value = DialogType.SELECT_PRODUCT_GROUP;
item.Text = CurrentModule.Strings.GetValue("CampaignProductGroups", FoundationContext.LanguageID, true).Replace(" ", " ");
c_selectionRadiobuttonlist.Items.Add(item);
item = new ListItem();
item.Value = DialogType.SELECT_ASSORTMENT;
item.Text = CurrentModule.Strings.GetValue("CampaignAssortments", FoundationContext.LanguageID, true).Replace(" ", " ");
c_selectionRadiobuttonlist.Items.Add(item);
item = new ListItem();
item.Value = DialogType.SELECT_PRODUCT_SET;
item.Text = CurrentModule.Strings.GetValue("CampaignProductSets", FoundationContext.LanguageID, true).Replace(" ", " ");
c_selectionRadiobuttonlist.Items.Add(item);
switch (Data.SelectedIdType)
{
case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_ASSORTMENT).Selected = true;
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_PRODUCT_GROUP).Selected = true;
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_PRODUCT_SET).Selected = true;
break;
default:
c_selectionRadiobuttonlist.Items.FindByValue(DialogType.SELECT_ARTICLE).Selected = true;
break;
}
}
/// <summary>
/// Configures the grids on page.
/// </summary>
/// <param name="selectedIdType">Type of the selection criteria.</param>
/// <returns>Grid client ID and popup dialog type</returns>
private string ConfigureGrids()
{
switch (c_selectionRadiobuttonlist.SelectedValue)
{
case DialogType.SELECT_PRODUCT_SET:
{
Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets;
c_productSetDiv.Attributes.CssStyle.Add("display", "block");
return c_productSetsGrid.ClientID;
}
case DialogType.SELECT_ASSORTMENT:
{
Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.Assortments;
c_assortmentDiv.Attributes.CssStyle.Add("display", "block");
return c_assortmentGrid.ClientID;
}
case DialogType.SELECT_PRODUCT_GROUP:
{
Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups;
c_productGroupDiv.Attributes.CssStyle.Add("display", "block");
return c_productGroupsGrid.ClientID;
}
default:
{
Data.SelectedIdType = ReducePriceByAmountAction.Data.SelectionCriteria.Articles;
c_articlesDiv.Attributes.CssStyle.Add("display", "block");
return c_articlesGrid.ClientID;
}
}
}
/// <summary>
/// Hides the grids div.
/// </summary>
private void HideGrids()
{
c_articlesDiv.Attributes.CssStyle.Add("display", "none");
c_productGroupDiv.Attributes.CssStyle.Add("display", "none");
c_assortmentDiv.Attributes.CssStyle.Add("display", "none");
c_productSetDiv.Attributes.CssStyle.Add("display", "none");
}
/// <summary>
/// Rebinds (clearing) the grids when Selection type is changed.
/// </summary>
private void RebindGrids()
{
Data.SelectedIDs.Clear();
if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_ASSORTMENT)
c_assortmentGrid.Rebind();
if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_PRODUCT_GROUP)
c_productGroupsGrid.Rebind();
if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_PRODUCT_SET)
c_productSetsGrid.Rebind();
if (c_selectionRadiobuttonlist.SelectedValue == DialogType.SELECT_ARTICLE)
c_articlesGrid.Rebind();
}
/// <summary>
/// Processing the hidden field.
/// Retrieve data from hidden field and setting them to Data object.
/// </summary>
private void ProcessingHiddenField()
{
var selectedIDs = new List<Guid>(GetGuidValueList(c_hiddenFieldIDs.Value));
if (selectedIDs.Count != 0)
{
Data.SelectedIDs.Clear();
Data.SelectedIDs.AddRange(selectedIDs.Distinct().ToList());
var hashtable = new Hashtable { { PROPERTY_ID, selectedIDs } };
SelectedItemIds = hashtable;
}
else
{
SelectedItemIds = null;
}
}
/// <summary>
/// Sorting ProductsSet collection.
/// </summary>
/// <param name="productSets">The product sets.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>Sorted collection.</returns>
private List<ProductList> ProductSetSorting(List<ProductList> productSets, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
switch (sortexpressions[0].FieldName)
{
case DISPLAY_NAME_COLUMN:
productSets.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
break;
}
if (sortexpressions[0].SortDirection == SortDirection.Descending)
productSets.Reverse();
return productSets;
}
/// <summary>
/// Sorting Assortment collection.
/// </summary>
/// <param name="assortments">The assortment collection.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns> Sorted collection. </returns>
private List<Assortment> AssortmenSorting(List<Assortment> assortments, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
switch (sortexpressions[0].FieldName)
{
case DISPLAY_NAME_COLUMN:
assortments.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
break;
}
if (sortexpressions[0].SortDirection == SortDirection.Descending)
assortments.Reverse();
return assortments;
}
/// <summary>
/// Sorting for ProductGroup collection.
/// </summary>
/// <param name="productGroups">The product groups.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>Sorted collection.</returns>
private List<Category> ProductGroupSorting(List<Category> productGroups, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
switch (sortexpressions[0].FieldName)
{
case DISPLAY_NAME_COLUMN:
productGroups.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
break;
case ASSORTMENT_COLUMN:
productGroups.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
break;
}
if (sortexpressions[0].SortDirection == SortDirection.Descending)
productGroups.Reverse();
return productGroups;
}
/// <summary>
/// Sorting Articles collection.
/// </summary>
/// <param name="articles">The articles.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>Sorted collection.</returns>
private List<Variant> ArticleSorting(List<Variant> articles, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
switch (sortexpressions[0].FieldName)
{
case DISPLAY_NAME_COLUMN:
articles.Sort((a, b) => string.Compare(a.GetEntityName(), b.GetEntityName()));
break;
case ARTICLE_NUMBER_COLUMN:
articles.Sort((a, b) => a.Id.CompareTo(b.Id));
break;
}
if (sortexpressions[0].SortDirection == SortDirection.Descending)
articles.Reverse();
return articles;
}
#endregion Private Metods
#region Protected Methods
protected override void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitializePageControls();
}
}
/// <summary>
/// Initializes the page controls.
/// </summary>
private void InitializePageControls()
{
InitializeRadioButtonListControl();
InitializeValidation();
InitializeGridsColumns();
InitializePopupWindowsDialog();
InitializeDescription();
}
/// <summary>
/// Articles the RAD grid getting data.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="startrowindex">The start row index.</param>
/// <param name="pagesize">The page size.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>PageResult object.</returns>
protected PagedResult ArticleRadGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
ProcessingHiddenField();
var articlesCollection = new List<Variant>();
if (Data.SelectedIDs.Count > 0)
{
var variantService = IoC.Resolve<VariantService>();
foreach (Guid articleID in Data.SelectedIDs)
{
var article = variantService.Get(articleID);
if (article != null)
{
articlesCollection.Add(article);
}
}
}
if (sortexpressions != null && sortexpressions.Count > 0)
articlesCollection = ArticleSorting(articlesCollection, sortexpressions);
return new PagedResult
{
Count = articlesCollection.Count,
Data = articlesCollection.Select(x => new { ID = x.SystemId, DisplayName = x.GetEntityName(), ArticleNumber = x.Id }).ToList(),
Reset = pagesize > startrowindex
};
}
/// <summary>
/// Products groups grid get data.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="startrowindex">The start row index.</param>
/// <param name="pagesize">The page size.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>PageResult object.</returns>
protected PagedResult ProductGroupsGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
ProcessingHiddenField();
var productGroups = new List<Category>();
if (Data.SelectedIDs.Count > 0)
{
foreach (Guid id in Data.SelectedIDs)
{
var item = _categoryService.Get(id);
if (item != null)
productGroups.Add(item);
}
}
if (sortexpressions != null && sortexpressions.Count > 0)
productGroups = ProductGroupSorting(productGroups, sortexpressions);
var pageResult = new PagedResult
{
Count = productGroups.Count,
Reset = pagesize > startrowindex
};
pageResult.Data = productGroups.Select(x =>
new {
ID = x.SystemId,
DisplayName = x.GetEntityName(),
Assortment = x.GetCategoryPath()
}).ToList();
return pageResult;
}
/// <summary>
/// Assortment grid get data.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="startrowindex">The start row index.</param>
/// <param name="pagesize">The page size.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>PageResult object.</returns>
protected PagedResult AssortmentGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
ProcessingHiddenField();
var assortments = new List<Assortment>();
if (Data.SelectedIDs.Count > 0)
{
foreach (Guid id in Data.SelectedIDs)
{
var item = _assortmentService.Get(id);
if (item != null)
assortments.Add(item);
}
}
if (sortexpressions != null && sortexpressions.Count > 0)
assortments = AssortmenSorting(assortments, sortexpressions);
return new PagedResult
{
Count = assortments.Count,
Reset = pagesize > startrowindex,
Data = assortments.Select(x => new ReducePriceByPercentageResult { ID = x.SystemId, DisplayName = x.GetEntityName() }).ToList()
};
}
/// <summary>
/// ProductSet grid get data.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="startrowindex">The start row index.</param>
/// <param name="pagesize">The page size.</param>
/// <param name="sortexpressions">The sort expressions.</param>
/// <returns>PageResult object.</returns>
protected PagedResult ProductSetsGridGetData(object sender, int startrowindex, int pagesize, List<Litium.Studio.UI.Common.SortExpression> sortexpressions)
{
ProcessingHiddenField();
var productSets = new List<ProductList>();
if (Data.SelectedIDs.Count > 0)
{
var productSetService = IoC.Resolve<ProductListService>();
foreach (Guid id in Data.SelectedIDs)
{
var productSet = productSetService.Get<ProductList>(id);
if (productSet != null)
productSets.Add(productSet);
}
}
if (sortexpressions != null && sortexpressions.Count > 0)
productSets = ProductSetSorting(productSets, sortexpressions);
return new PagedResult
{
Count = productSets.Count,
Reset = pagesize > startrowindex,
Data = productSets.Select(x => new
{
ID = x.SystemId,
DisplayName = x.GetEntityName()
}).ToList()
};
}
/// <summary>
/// Called when GridItemCommand event raised.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="e">The <see cref="Telerik.Web.UI.GridCommandEventArgs"/> instance containing the event data.</param>
protected void GridItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "RebindGrid")
{
return;
}
if (e.CommandName == "Delete")
{
Guid deletableItemID = Guid.Empty;
switch (Data.SelectedIdType)
{
case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
deletableItemID = (Guid)c_assortmentGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
deletableItemID = (Guid)c_productGroupsGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
deletableItemID = (Guid)c_productSetsGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
break;
default:
deletableItemID = (Guid)c_articlesGrid.MasterTableView.DataKeyValues[e.Item.ItemIndex]["ID"];
break;
}
if (deletableItemID != Guid.Empty)
Data.SelectedIDs.Remove(deletableItemID);
}
c_hiddenFieldIDs.Value = string.Join(",", Data.SelectedIDs.ToList().ConvertAll(x => x.ToString()).ToArray());
}
/// <summary>
/// Gets the GUID value list.
/// </summary>
/// <param name="originalValue">The comma separated Guid-string value.</param>
/// <returns>IEnumerable Guid collection.</returns>
private static IEnumerable<Guid> GetGuidValueList(string originalValue)
{
string[] values = originalValue.Split(ParameterConstants.VALUE_SEPERATOR_COMMA);
return (values.Where(value => !string.IsNullOrEmpty(value)).Select(value => new Guid(value))).ToList();
}
/// <summary>
/// Called when [select type checked changed] event raised.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected void OnDialogSelectionSelectedIndexChanged(object sender, EventArgs e)
{
c_hiddenFieldIDs.Value = String.Empty;
RebindGrids();
InitializePopupWindowsDialog();
InitializeDescription();
SelectedItemIds = null;
}
protected void GridPageIndexChanged(object source, GridPageChangedEventArgs e)
{
c_hiddenFieldIDs.Value = string.Join(",", Data.SelectedIDs.ToList().ConvertAll(x => x.ToString()).ToArray());
}
[Serializable]
internal sealed class ReducePriceByPercentageResult
{
public Guid ID { get; set; }
public string DisplayName { get; set; }
public string ArticleNumber { get; set; }
}
#endregion Protected Methods
#region Implementation of IUIExtensionPanel
/// <summary>
/// Gets the panel data.
/// </summary>
/// <returns>Return an object with the panel data.</returns>
object IUIExtensionPanel.GetPanelData()
{
decimal amount;
Data.ApplyOnCampaignPriceCumulatively = c_applyOnCampaignCheckbox.Checked;
decimal.TryParse(c_textboxAmount.Text, out amount);
Data.DiscountAmountWithVAT = amount;
int maxDiscountsPerItemInOrder;
if (int.TryParse(c_textboxMaxDiscountsPerItemInOrder.Text, out maxDiscountsPerItemInOrder))
Data.MaxDiscountsPerItemInOrder = maxDiscountsPerItemInOrder;
else
Data.MaxDiscountsPerItemInOrder = -1;
return Data;
}
/// <summary>
/// Sets the panel data.
/// </summary>
/// <param name="data">The data.</param>
void IUIExtensionPanel.SetPanelData(object data)
{
if (data is ReducePriceByAmountAction.Data)
Data = (ReducePriceByAmountAction.Data)data;
InitializePageControls();
if (data is ReducePriceByAmountAction.Data)
{
c_applyOnCampaignCheckbox.Checked = Data.ApplyOnCampaignPriceCumulatively;
c_textboxAmount.Text = Data.DiscountAmountWithVAT.ToString();
c_textboxMaxDiscountsPerItemInOrder.Text = (Data.MaxDiscountsPerItemInOrder > 0) ? Data.MaxDiscountsPerItemInOrder.ToString() : string.Empty;
switch (Data.SelectedIdType)
{
case ReducePriceByAmountAction.Data.SelectionCriteria.Assortments:
c_assortmentGrid.Rebind();
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductGroups:
c_productGroupsGrid.Rebind();
break;
case ReducePriceByAmountAction.Data.SelectionCriteria.ProductSets:
c_productSetsGrid.Rebind();
break;
default:
c_articlesGrid.Rebind();
break;
}
}
}
#endregion
}
}```