Esempio n. 1
0
    /// <summary>
    /// Saves exchange rates.
    /// </summary>
    private void Save()
    {
        // Check permissions
        CheckConfigurationModification();

        string errorMessage = new Validator().NotEmpty(txtExchangeTableDisplayName.Text.Trim(), GetString("general.requiresdisplayname")).Result;

        if ((errorMessage == "") && (plcRateFromGlobal.Visible))
        {
            errorMessage = new Validator().NotEmpty(txtGlobalExchangeRate.Text.Trim(), GetString("ExchangeTable_Edit.DoubleFormatRequired")).Result;
        }

        if ((errorMessage == "") && (plcRateFromGlobal.Visible))
        {
            if (!ValidationHelper.IsPositiveNumber(txtGlobalExchangeRate.Text.Trim()) || (ValidationHelper.GetDouble(txtGlobalExchangeRate.Text.Trim(), 0) == 0))
            {
                errorMessage = GetString("ExchangeTable_Edit.errorRate");
            }
        }

        // From/to date validation
        if (errorMessage == "")
        {
            if ((!dtPickerExchangeTableValidFrom.IsValidRange()) || (!dtPickerExchangeTableValidTo.IsValidRange()))
            {
                errorMessage = GetString("general.errorinvaliddatetimerange");
            }

            if ((dtPickerExchangeTableValidFrom.SelectedDateTime != DateTime.MinValue) &&
                (dtPickerExchangeTableValidTo.SelectedDateTime != DateTime.MinValue) &&
                (dtPickerExchangeTableValidFrom.SelectedDateTime >= dtPickerExchangeTableValidTo.SelectedDateTime))
            {
                errorMessage = GetString("General.DateOverlaps");
            }
        }

        // Exchange rates validation
        if (errorMessage == String.Empty)
        {
            foreach (TextBox txt in mTextBoxes.Values)
            {
                string tmp = txt.Text.Trim();
                if (tmp != String.Empty)
                {
                    // Exchange rate mus be double
                    if (!ValidationHelper.IsDouble(tmp))
                    {
                        errorMessage = GetString("ExchangeTable_Edit.DoubleFormatRequired");
                        break;
                    }

                    // Exchange rate must be positive
                    double rate = ValidationHelper.GetDouble(tmp, 1);
                    if (rate <= 0)
                    {
                        errorMessage = GetString("ExchangeTable_Edit.errorRate");
                    }
                }
            }
        }

        // Save changes if no validation error
        if (errorMessage == "")
        {
            ExchangeTableInfo exchangeTableObj = ExchangeTableInfoProvider.GetExchangeTableInfo(txtExchangeTableDisplayName.Text.Trim(), SiteInfoProvider.GetSiteName(ConfiguredSiteID));

            // If exchangeTableName value is unique
            if ((exchangeTableObj == null) || (exchangeTableObj.ExchangeTableID == mExchangeTableId))
            {
                // Get ExchangeTableInfo object by primary key
                exchangeTableObj = ExchangeTableInfoProvider.GetExchangeTableInfo(mExchangeTableId);
                if (exchangeTableObj == null)
                {
                    // Create new item -> insert
                    exchangeTableObj = new ExchangeTableInfo();
                    exchangeTableObj.ExchangeTableSiteID = ConfiguredSiteID;
                }

                exchangeTableObj.ExchangeTableValidFrom              = dtPickerExchangeTableValidFrom.SelectedDateTime;
                exchangeTableObj.ExchangeTableDisplayName            = txtExchangeTableDisplayName.Text.Trim();
                exchangeTableObj.ExchangeTableValidTo                = dtPickerExchangeTableValidTo.SelectedDateTime;
                exchangeTableObj.ExchangeTableRateFromGlobalCurrency = 0;
                if (plcRateFromGlobal.Visible)
                {
                    exchangeTableObj.ExchangeTableRateFromGlobalCurrency = ValidationHelper.GetDouble(txtGlobalExchangeRate.Text.Trim(), 0);
                }

                // Save general exchange table information
                ExchangeTableInfoProvider.SetExchangeTableInfo(exchangeTableObj);

                // Save rates on edit
                if (mExchangeTableId > 0)
                {
                    foreach (TextBox txt in mTextBoxes.Values)
                    {
                        if (mData[txt.ClientID] != null)
                        {
                            int  rateCurrencyId = ValidationHelper.GetInteger(((DataRowView)mData[txt.ClientID])["CurrencyID"], 0);
                            bool rateExists     = mExchangeRates.ContainsKey(rateCurrencyId);

                            if (rateExists)
                            {
                                ExchangeRateInfo rate = new ExchangeRateInfo(mExchangeRates[rateCurrencyId]);

                                if (txt.Text.Trim() == String.Empty)
                                {
                                    // Remove exchange rate
                                    ExchangeRateInfoProvider.DeleteExchangeRateInfo(rate);
                                }
                                else
                                {
                                    rate.ExchangeRateValue = ValidationHelper.GetDouble(txt.Text.Trim(), 0);
                                    // Update rate
                                    ExchangeRateInfoProvider.SetExchangeRateInfo(rate);
                                }
                            }
                            else
                            {
                                if (txt.Text.Trim() != String.Empty)
                                {
                                    // Insert exchange rate
                                    ExchangeRateInfo rate = new ExchangeRateInfo();
                                    rate.ExchangeRateToCurrencyID = rateCurrencyId;
                                    rate.ExchangeRateValue        = ValidationHelper.GetDouble(txt.Text.Trim(), 0);
                                    rate.ExchangeTableID          = mExchangeTableId;

                                    ExchangeRateInfoProvider.SetExchangeRateInfo(rate);
                                }
                            }
                        }
                    }
                }

                URLHelper.Redirect("ExchangeTable_Edit.aspx?exchangeid=" + exchangeTableObj.ExchangeTableID + "&saved=1&siteId=" + SiteID);
            }
            else
            {
                // Show error message
                ShowError(GetString("ExchangeTable_Edit.CurrencyNameExists"));
            }
        }
        else
        {
            // Show error message
            ShowError(errorMessage);
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        editGrid.RowDataBound += new GridViewRowEventHandler(editGrid_RowDataBound);

        // Get main currency
        mMainCurrency = CurrencyInfoProvider.GetMainCurrency(this.ConfiguredSiteID);

        rfvDisplayName.ErrorMessage = GetString("general.requiresdisplayname");

        // Control initializations
        lblExchangeTableValidFrom.Text   = GetString("ExchangeTable_Edit.ExchangeTableValidFromLabel");
        lblExchangeTableDisplayName.Text = GetString("ExchangeTable_Edit.ExchangeTableDisplayNameLabel");
        lblExchangeTableValidTo.Text     = GetString("ExchangeTable_Edit.ExchangeTableValidToLabel");

        // Help image
        this.imgHelp.ImageUrl           = GetImageUrl("General/HelpSmall.png");
        this.imgHelp.ToolTip            = GetString("ExchangeTable_Edit.ExchangeRateHelp");
        this.imgHelpFromGlobal.ImageUrl = GetImageUrl("General/HelpSmall.png");
        this.imgHelpFromGlobal.ToolTip  = GetString("ExchangeTable_Edit.ExchangeRateHelp");

        lblRates.Text = GetString("ExchangeTable_Edit.ExchangeRates");

        btnOk.Text = GetString("General.OK");
        dtPickerExchangeTableValidFrom.SupportFolder = "~/CMSAdminControls/Calendar";
        dtPickerExchangeTableValidTo.SupportFolder   = "~/CMSAdminControls/Calendar";

        string currentTableTitle = GetString("ExchangeTable_Edit.NewItemCaption");

        // Get exchangeTable id from querystring
        mExchangeTableId = QueryHelper.GetInteger("exchangeid", 0);
        if (mExchangeTableId > 0)
        {
            exchangeTableObj = ExchangeTableInfoProvider.GetExchangeTableInfo(mExchangeTableId);
            EditedObject     = exchangeTableObj;

            if (exchangeTableObj != null)
            {
                // Check tables site id
                CheckEditedObjectSiteID(exchangeTableObj.ExchangeTableSiteID);
                // Set title
                currentTableTitle = exchangeTableObj.ExchangeTableDisplayName;

                LoadData(exchangeTableObj);

                // Fill editing form
                if (!RequestHelper.IsPostBack())
                {
                    // Show that the exchangeTable was created or updated successfully
                    if (QueryHelper.GetString("saved", "") == "1")
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text    = GetString("General.ChangesSaved");
                    }
                }
            }

            this.CurrentMaster.Title.TitleText  = GetString("ExchangeTable_Edit.HeaderCaption");
            this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_ExchangeTable/object.png");

            // Init Copy from global link
            InitCopyFromGlobalLink();
        }
        // Creating a new exchange table
        else
        {
            if (!RequestHelper.IsPostBack())
            {
                // Preset valid from date
                ExchangeTableInfo tableInfo = ExchangeTableInfoProvider.GetLastExchangeTableInfo(this.ConfiguredSiteID);
                if (tableInfo != null)
                {
                    dtPickerExchangeTableValidFrom.SelectedDateTime = tableInfo.ExchangeTableValidTo;
                }
            }
            // Grids are visible only in edit mode
            plcGrid.Visible = false;

            this.CurrentMaster.Title.TitleText  = GetString("ExchangeTable_New.HeaderCaption");
            this.CurrentMaster.Title.TitleImage = GetImageUrl("Objects/Ecommerce_ExchangeTable/new.png");
        }

        // Initializes page title breadcrumbs control
        string[,] breadcrumbs = new string[2, 3];
        breadcrumbs[0, 0]     = GetString("ExchangeTable_Edit.ItemListLink");
        breadcrumbs[0, 1]     = "~/CMSModules/Ecommerce/Pages/Tools/Configuration/ExchangeRates/ExchangeTable_List.aspx?siteId=" + SiteID;
        breadcrumbs[0, 2]     = "";
        breadcrumbs[1, 0]     = currentTableTitle;
        breadcrumbs[1, 1]     = "";
        breadcrumbs[1, 2]     = "";
        this.CurrentMaster.Title.Breadcrumbs = breadcrumbs;

        this.CurrentMaster.Title.HelpTopicName = "new_rateexchange_rate_edit";
        this.CurrentMaster.Title.HelpName      = "helpTopic";

        plcRateFromGlobal.Visible = IsFromGlobalRateNeeded();

        // Check presence of main currency
        string currencyErr = CheckMainCurrency(ConfiguredSiteID);

        if (!string.IsNullOrEmpty(currencyErr))
        {
            // Show message
            lblNoMainCurrency.Text    = currencyErr;
            plcNoMainCurrency.Visible = true;
            plcRates.Visible          = false;
        }
    }