/// <summary>
 /// Load data of editing creditEvent.
 /// </summary>
 /// <param name="creditEventObj">CreditEvent object</param>
 protected void LoadData(CreditEventInfo creditEventObj)
 {
     txtEventName.Text                  = creditEventObj.EventName;
     txtEventDescription.Text           = creditEventObj.EventDescription;
     txtEventCreditChange.Price         = creditEventObj.EventCreditChange;
     dtPickerEventDate.SelectedDateTime = creditEventObj.EventDate;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        creditSiteId = ECommerceHelper.GetSiteID(SiteContext.CurrentSiteID, ECommerceSettings.USE_GLOBAL_CREDIT);

        CreditEventInfo creditEvent = EditedObject as CreditEventInfo;

        // Check site of credit event
        if ((creditEvent != null) && (creditEvent.EventID > 0) && (creditEvent.EventSiteID != creditSiteId))
        {
            EditedObject = null;
        }

        creditEvent = EditForm.Data as CreditEventInfo;
        if ((creditEvent != null) && (creditEvent.EventID == 0))
        {
            creditEvent.EventSiteID = creditSiteId;
        }

        CustomerInfo customer = EditedObjectParent as CustomerInfo;

        // Check if customer belongs to current site
        if (!CheckCustomerSiteID(customer))
        {
            EditedObject = null;
        }

        // Check presence of main currency
        CheckMainCurrency(creditSiteId);

        // Register check permissions
        EditForm.OnCheckPermissions += (s, args) => CheckPermissions();
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (customer == null)
        {
            return;
        }

        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        // Check if using global credit
        if (creditSiteId <= 0)
        {
            // Check Ecommerce global modify permission
            if (!ECommerceContext.IsUserAuthorizedForPermission("EcommerceGlobalModify"))
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
            }
        }

        // Validate values
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            CreditEventInfo creditEventObj = CreditEventInfoProvider.GetCreditEventInfo(eventid);

            // if creditEvent doesnt already exist, create new one
            if (creditEventObj == null)
            {
                creditEventObj = new CreditEventInfo();
                creditEventObj.EventCustomerID = customerId;
                creditEventObj.EventSiteID     = creditSiteId;
            }

            creditEventObj.EventName         = txtEventName.Text.Trim();
            creditEventObj.EventDescription  = txtEventDescription.Text.Trim();
            creditEventObj.EventCreditChange = txtEventCreditChange.Value;
            creditEventObj.EventDate         = dtPickerEventDate.SelectedDateTime;

            CreditEventInfoProvider.SetCreditEventInfo(creditEventObj);

            URLHelper.Redirect("Customer_Edit_Credit_Edit.aspx?customerid=" + customerId + "&eventid=" + Convert.ToString(creditEventObj.EventID) + "&saved=1&siteId=" + SiteID);
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (customer == null)
        {
            return;
        }

        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        // Check if using global credit
        if (creditSiteId <= 0)
        {
            // Check Ecommerce global modify permission
            if (!ECommerceContext.IsUserAuthorizedForPermission("EcommerceGlobalModify"))
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
            }
        }

        // Validate values
        string errorMessage = ValidateForm();

        if (errorMessage == "")
        {
            CreditEventInfo creditEventObj = CreditEventInfoProvider.GetCreditEventInfo(eventid);

            // if creditEvent doesnt already exist, create new one
            if (creditEventObj == null)
            {
                creditEventObj = new CreditEventInfo();
                creditEventObj.EventCustomerID = customerId;
                creditEventObj.EventSiteID = creditSiteId;
            }

            creditEventObj.EventName = txtEventName.Text.Trim();
            creditEventObj.EventDescription = txtEventDescription.Text.Trim();
            creditEventObj.EventCreditChange = txtEventCreditChange.Value;
            creditEventObj.EventDate = dtPickerEventDate.SelectedDateTime;

            CreditEventInfoProvider.SetCreditEventInfo(creditEventObj);

            URLHelper.Redirect("Customer_Edit_Credit_Edit.aspx?customerid=" + customerId + "&eventid=" + Convert.ToString(creditEventObj.EventID) + "&saved=1&siteId=" + SiteID);
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = errorMessage;
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            URLHelper.Redirect(UrlResolver.ResolveUrl("Customer_Edit_Credit_Edit.aspx?customerid=" + customerId + "&eventid=" + Convert.ToString(actionArgument) + "&siteId=" + SiteID));
        }
        else if (actionName == "delete")
        {
            // Check customer modification permission
            if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
            {
                RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyCustomers");
            }

            // Check if using global credit
            if (ECommerceSettings.UseGlobalCredit(SiteContext.CurrentSiteName))
            {
                // Check Ecommerce global modify permission
                if (!ECommerceContext.IsUserAuthorizedForPermission(EcommercePermissions.ECOMMERCE_MODIFYGLOBAL))
                {
                    RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL);
                }
            }

            // Get event info object
            int             eventId   = Convert.ToInt32(actionArgument);
            CreditEventInfo eventInfo = CreditEventInfoProvider.GetCreditEventInfo(eventId);

            // Check if deleted event exists and whether it belongs to edited customer
            if ((eventInfo != null) && (eventInfo.EventCustomerID == customerId))
            {
                // Delete CreditEventInfo object from database
                CreditEventInfoProvider.DeleteCreditEventInfo(eventInfo);
                UniGrid.ReloadData();
                // Display customer total credit
                headTotalCredit.Text = string.Format(GetString("CreditEvent_List.TotalCredit"), GetFormattedTotalCredit());
            }
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void uniGrid_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "edit")
        {
            URLHelper.Redirect("Customer_Edit_Credit_Edit.aspx?customerid=" + customerId + "&eventid=" + Convert.ToString(actionArgument) + "&siteId=" + SiteID);
        }
        else if (actionName == "delete")
        {
            // Check customer modification permission
            if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
            }

            // Check if using global credit
            if (ECommerceSettings.UseGlobalCredit(CMSContext.CurrentSiteName))
            {
                // Check Ecommerce global modify permission
                if (!ECommerceContext.IsUserAuthorizedForPermission("EcommerceGlobalModify"))
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
                }
            }

            // Get event info object
            int             eventId   = Convert.ToInt32(actionArgument);
            CreditEventInfo eventInfo = CreditEventInfoProvider.GetCreditEventInfo(eventId);

            // Check if deleted event exists and whether it belongs to edited customer
            if ((eventInfo != null) && (eventInfo.EventCustomerID == customerId))
            {
                // Delete CreditEventInfo object from database
                CreditEventInfoProvider.DeleteCreditEventInfo(eventInfo);
                UniGrid.ReloadData();
                lblCreditValue.Text = GetFormatedTotalCredit();
            }
        }
    }
    /// <summary>
    /// Gets and updates credit event. Called when the "Get and update event" button is pressed.
    /// Expects the CreateCreditEvent method to be run first.
    /// </summary>
    private bool GetAndUpdateCreditEvent()
    {
        // Prepare the parameters
        string where = "EventName LIKE 'My New%'";

        // Get the credit event
        DataSet credits = CreditEventInfoProvider.GetCreditEvents(where, null);
        if (!DataHelper.DataSourceIsEmpty(credits))
        {
            // Create object from DataRow
            CreditEventInfo updateCredit = new CreditEventInfo(credits.Tables[0].Rows[0]);

            // Update the properties
            updateCredit.EventName = updateCredit.EventName.ToLowerCSafe();

            // Update the credit event
            CreditEventInfoProvider.SetCreditEventInfo(updateCredit);

            return true;
        }

        return false;
    }
    /// <summary>
    /// Gets and bulk updates credit events. Called when the "Get and bulk update events" button is pressed.
    /// Expects the CreateCreditEvent method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateCreditEvents()
    {
        // Prepare the parameters
        string where = "EventName LIKE 'My New%'";

        // Get the data
        DataSet credits = CreditEventInfoProvider.GetCreditEvents(where, null);
        if (!DataHelper.DataSourceIsEmpty(credits))
        {
            // Loop through the individual items
            foreach (DataRow creditDr in credits.Tables[0].Rows)
            {
                // Create object from DataRow
                CreditEventInfo updateCredit = new CreditEventInfo(creditDr);

                // Update the properties
                updateCredit.EventName = updateCredit.EventName.ToUpper();

                // Update the credit event
                CreditEventInfoProvider.SetCreditEventInfo(updateCredit);
            }

            return true;
        }

        return false;
    }
    /// <summary>
    /// Deletes credit event. Called when the "Delete event" button is pressed.
    /// Expects the CreateCreditEvent method to be run first.
    /// </summary>
    private bool DeleteCreditEvent()
    {
        // Prepare the parameters
        string where = "EventName LIKE 'My New%'";

        // Get the credit event
        DataSet credits = CreditEventInfoProvider.GetCreditEvents(where, null);
        if (!DataHelper.DataSourceIsEmpty(credits))
        {
            // Create object from DataRow
            CreditEventInfo deleteCredit = new CreditEventInfo(credits.Tables[0].Rows[0]);

            // Delete credit event
            CreditEventInfoProvider.DeleteCreditEventInfo(deleteCredit);

            return (deleteCredit != null);
        }

        return false;
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Creates credit event. Called when the "Create event" button is pressed.
    /// Expects the CreateRegisteredCustomer method to be run first.
    /// </summary>
    private bool CreateCreditEvent()
    {
        // Prepare the parameters
        string where = "CustomerLastName LIKE N'My New Registered%'";
        CustomerInfo customer = null;

        // Get the customer
        DataSet customers = CustomerInfoProvider.GetCustomers(where, null);
        if (!DataHelper.DataSourceIsEmpty(customers))
        {
            // Create object from DataRow
            customer = new CustomerInfo(customers.Tables[0].Rows[0]);
        }

        if (customer != null)
        {
            // Create new credit event object
            CreditEventInfo newEvent = new CreditEventInfo();

            // Set the properties
            newEvent.EventName = "My new event";
            newEvent.EventCreditChange = 500;
            newEvent.EventDate = DateTime.Now;
            newEvent.EventDescription = "Credit event description.";
            newEvent.EventCustomerID = customer.CustomerID;

            // Create the credit event
            CreditEventInfoProvider.SetCreditEventInfo(newEvent);

            return true;
        }

        return false;
    }
    /// <summary>
    /// Creates credit event. Called when the "Create event" button is pressed.
    /// Expects the CreateRegisteredCustomer method to be run first.
    /// </summary>
    private bool CreateCreditEvent()
    {
        // Get the customer
        CustomerInfo customer = CustomerInfoProvider.GetCustomers().WhereStartsWith("CustomerLastName", "My New Registered").FirstOrDefault();

        if (customer != null)
        {
            // Create new credit event object
            CreditEventInfo newEvent = new CreditEventInfo
                                       {
                                           EventName = "My new event",
                                           EventCreditChange = 500,
                                           EventDate = DateTime.Now,
                                           EventDescription = "Credit event description.",
                                           EventCustomerID = customer.CustomerID,
                                           EventSiteID = SiteContext.CurrentSiteID
                                       };

            // Create the credit event
            CreditEventInfoProvider.SetCreditEventInfo(newEvent);

            return true;
        }

        return false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get site id of credits main currency
        creditSiteId = ECommerceHelper.GetSiteID(CMSContext.CurrentSiteID, ECommerceSettings.USE_GLOBAL_CREDIT);

        string currentCreditEvent = "";
        string eventImage         = "";
        string title = "";

        // Required field validator error messages initialization
        rfvEventName.ErrorMessage = GetString("Ecommerce.Customer.CreditEventNameEmpty");
        txtEventCreditChange.EmptyErrorMessage      = GetString("Ecommerce.Customer.CreditChangeFormat");
        txtEventCreditChange.ValidationErrorMessage = txtEventCreditChange.EmptyErrorMessage;
        txtEventCreditChange.CurrencySiteID         = creditSiteId;
        txtEventCreditChange.AllowZero = false;

        // Control initializations
        lblEventName.Text               = GetString("CreditEvent_Edit.EventNameLabel");
        lblEventDescription.Text        = GetString("CreditEvent_Edit.EventDescriptionLabel");
        lblEventDate.Text               = GetString("CreditEvent_Edit.EventDateLabel");
        lblEventCreditChange.Text       = GetString("CreditEvent_Edit.EventCreditChangeLabel");
        dtPickerEventDate.SupportFolder = "~/CMSAdminControls/Calendar";

        // Get event ID
        eventid = QueryHelper.GetInteger("eventid", 0);

        CreditEventInfo creditEventObj = null;

        // Edit existing credit event
        if (eventid > 0)
        {
            creditEventObj = CreditEventInfoProvider.GetCreditEventInfo(eventid);
            EditedObject   = creditEventObj;

            if (creditEventObj != null)
            {
                // Credit from another site
                if (creditEventObj.EventSiteID != creditSiteId)
                {
                    EditedObject = null;
                }

                currentCreditEvent = creditEventObj.EventName;
                customerId         = creditEventObj.EventCustomerID;
            }

            eventImage = "creditevent.png";
            title      = GetString("CreditEvent_Edit.HeaderCaption");
        }
        // Create new credit event
        else
        {
            currentCreditEvent = GetString("CreditEvent_Edit.NewItemCaption");
            if (!RequestHelper.IsPostBack())
            {
                dtPickerEventDate.SelectedDateTime = DateTime.Now;
            }
            eventImage = "newcreditevent.png";
            title      = GetString("CreditEvent_Edit.NewItemCaption");

            // Get customer id from querystring
            customerId = QueryHelper.GetInteger("customerid", 0);
        }

        customer = CustomerInfoProvider.GetCustomerInfo(customerId);
        // Check if customer belongs to current site
        if (!CheckCustomerSiteID(customer))
        {
            customer = null;
        }

        // Fill editing form
        if ((customer != null) && (creditEventObj != null) && !RequestHelper.IsPostBack())
        {
            LoadData(creditEventObj);

            // Show that the creditEvent was created or updated successfully
            if (QueryHelper.GetString("saved", "") == "1")
            {
                ShowChangesSaved();
            }
        }

        // Initializes page title control
        InitializeMasterPage(title, eventImage, currentCreditEvent);

        // Check presence of main currency
        string currencyWarning = CheckMainCurrency(creditSiteId);

        if (!string.IsNullOrEmpty(currencyWarning))
        {
            ShowWarning(currencyWarning, null, null);
        }
    }
 /// <summary>
 /// Load data of editing creditEvent.
 /// </summary>
 /// <param name="creditEventObj">CreditEvent object</param>
 protected void LoadData(CreditEventInfo creditEventObj)
 {
     txtEventName.Text = creditEventObj.EventName;
     txtEventDescription.Text = creditEventObj.EventDescription;
     txtEventCreditChange.Price = creditEventObj.EventCreditChange;
     dtPickerEventDate.SelectedDateTime = creditEventObj.EventDate;
 }