Esempio n. 1
0
    /// <summary>
    /// Page load.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!StopProcessing)
        {
            if (AuthenticationHelper.IsAuthenticated())
            {
                // Get site id of credits main currency
                int creditSiteId = ECommerceHelper.GetSiteID(SiteContext.CurrentSiteID, ECommerceSettings.USE_GLOBAL_CREDIT);

                gridCreditEvents.HideControlForZeroRows = true;
                gridCreditEvents.IsLiveSite             = IsLiveSite;
                gridCreditEvents.OnExternalDataBound   += gridCreditEvents_OnExternalDataBound;
                gridCreditEvents.OrderBy        = "EventDate DESC, EventName ASC";
                gridCreditEvents.WhereCondition = "EventCustomerID = " + CustomerId + " AND ISNULL(EventSiteID, 0) = " + creditSiteId;

                // Get total credit value
                decimal credit = (decimal)CreditEventInfoProvider.GetTotalCredit(CustomerId, SiteContext.CurrentSiteID);

                if (Currency != null)
                {
                    // Convert credit to current currency when using one
                    CurrencyConverter.TryGetExchangeRate(creditSiteId == 0, Currency.CurrencyCode, SiteContext.CurrentSiteID, ref rate);
                    credit = CurrencyConverter.ApplyExchangeRate(credit, rate);
                }

                lblCreditValue.Text = CurrencyInfoProvider.GetFormattedPrice((double)credit, Currency);
            }
            else
            {
                // Hide if user is not authenticated
                Visible = false;
            }
        }
    }
    protected object gridCreditEvents_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        // Show only date part from date-time value
        switch (sourceName.ToLowerInvariant())
        {
        case "eventdate":
            var date = ValidationHelper.GetDateTime(parameter, DateTimeHelper.ZERO_TIME);
            if (date != DateTimeHelper.ZERO_TIME)
            {
                return(TimeZoneHelper.ConvertToUserTimeZone(date, true, MembershipContext.AuthenticatedUser, SiteContext.CurrentSite));
            }

            return(String.Empty);

        case "eventcreditchange":
            var credit = CurrencyConverter.ApplyExchangeRate(ValidationHelper.GetDecimal(parameter, 0m), rate);
            return(CurrencyInfoProvider.GetFormattedPrice(credit, Currency));
        }

        return(parameter);
    }
Esempio n. 3
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Check if order item modification is allowed
        if (!Order.CheckPermissions(PermissionsEnum.Modify, CurrentSiteName, CurrentUser))
        {
            RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyOrders");
        }

        // Reset auto added units (already auto added units in the shopping cart will not removed)
        ShoppingCartItem.CartItemAutoAddedUnits = 0;

        // Get new price
        var rate     = (SKU.IsGlobal) ? ShoppingCart.ExchangeRateForGlobalItems : ShoppingCart.ExchangeRate;
        var newPrice = (double)CurrencyConverter.ApplyExchangeRate(ValidationHelper.GetDecimal(EditForm.FieldControls["CartItemUnitPrice"].Value, 0m), (decimal)(1 / rate));

        // Update direct price (donation or product with attribute or text options)
        if (!Double.IsNaN(ShoppingCartItem.CartItemPrice))
        {
            if (ShoppingCartItem.ProductOptions.Count > 0)
            {
                // Set price without product options to SKU
                ShoppingCartItem.SKU.SKUPrice += newPrice - ShoppingCartItem.CartItemPrice;
            }

            ShoppingCartItem.CartItemPrice = newPrice;
        }
        else
        {
            SKU.SKUPrice = newPrice;
        }

        // Update SKUName
        SKU.SKUName = ValidationHelper.GetString(EditForm.FieldControls["CartItemName"].Value, "");

        // Update units
        ShoppingCartItem.CartItemUnits = ValidationHelper.GetInteger(EditForm.FieldControls["SKUUnits"].Value, 0);

        // Update is private information
        if (SKU.SKUProductType == SKUProductTypeEnum.Donation)
        {
            ShoppingCartItem.CartItemIsPrivate = ValidationHelper.GetBoolean(EditForm.FieldControls["CartItemIsPrivate"].Value, false);
        }

        // Update product text
        if (SKU.IsTextAttribute)
        {
            var controlName = (SKU.SKUOptionCategory.CategorySelectionType == OptionCategorySelectionTypeEnum.TextArea) ? "CartItemTextArea" : "CartItemTextBox";
            ShoppingCartItem.CartItemText = ValidationHelper.GetString(EditForm.FieldControls[controlName].Value, String.Empty);
        }

        // Update units of the product options
        int skuUnits = ValidationHelper.GetInteger(EditForm.FieldControls["SKUUnits"].Value, 0);

        foreach (var option in ShoppingCartItem.ProductOptions)
        {
            option.CartItemUnits = skuUnits;
        }

        // Evaluate shopping cart content
        ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCart);

        // Close dialog window and refresh parent window
        CloseDialogWindow();

        // Do not save ShoppingCartItem to the database
        EditForm.StopProcessing = true;
    }