Exemplo n.º 1
0
    /// <summary>
    /// Bind data to the fields 
    /// </summary>
    protected void BindData()
    {
        ShippingAdmin shipAdmin = new ShippingAdmin();
        Shipping shippingOption = shipAdmin.GetShippingOptionById(ShippingId);

        //Set Title
        lblTitle.Text = lblTitle.Text + shippingOption.Description;

        //Get shipping rule types
        foreach (ShippingRuleType ruleType in shipAdmin.GetShippingRuleTypes())
        {
            if (ruleType.ShippingRuleTypeID == 3 || ruleType.ShippingRuleTypeID == 4)
            { // Nothing to do here
            }
            else
            {
                ListItem li = new ListItem(ruleType.Description, ruleType.ShippingRuleTypeID.ToString());
                lstShippingRuleType.Items.Add(li);
            }
        }
        lstShippingRuleType.SelectedIndex = 0;

        if (ItemId > 0)
        {
            ShippingRule shippingRule = shipAdmin.GetShippingRule(ItemId);

            lstShippingRuleType.SelectedValue = shippingRule.ShippingRuleTypeID.ToString();

            SetShippingTypeOptions(shippingRule.ShippingRuleTypeID);

            if (shippingRule.BaseCost != 0)
            {
                txtBaseCost.Text = shippingRule.BaseCost.ToString("N2");
            }
            else
            {
                txtBaseCost.Text = "0";
            }

            if (shippingRule.PerItemCost != 0)
            {
                txtPerItemCost.Text = shippingRule.PerItemCost.ToString("N2");
            }
            else
            {
                txtPerItemCost.Text = "0";
            }

            if (shippingRule.LowerLimit != null)
            {
                txtLowerLimit.Text = shippingRule.LowerLimit.ToString();
            }
            else
            {
                txtLowerLimit.Text = "0";
            }

            if (shippingRule.UpperLimit != null)
            {
                txtUpperLimit.Text = shippingRule.UpperLimit.ToString();
            }
            else
            {
                txtUpperLimit.Text = "0";
            }

        }
        else
        {
            pnlNonFlat.Visible = false;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Submit button click event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ShippingAdmin shipAdmin = new ShippingAdmin();
        ShippingRule shipRule = new ShippingRule();

        //set shipping id for this rule
        shipRule.ShippingID = ShippingId;

        //If edit mode then retrieve data first
        if (ItemId > 0)
        {
            shipRule = shipAdmin.GetShippingRule(ItemId);
        }

        //set values
        shipRule.ShippingRuleTypeID = int.Parse(lstShippingRuleType.SelectedValue);
        shipRule.BaseCost = decimal.Parse(txtBaseCost.Text);

        // "PerItemCost" field is not saving for Quantity and Weight based Rules
        //So i have commented this out.
        //if (int.Parse(lstShippingRuleType.SelectedValue) == 0)
        //{
            shipRule.PerItemCost = decimal.Parse(txtPerItemCost.Text);
        //}

        if (int.Parse(lstShippingRuleType.SelectedValue) > 0)
        {
            shipRule.LowerLimit = decimal.Parse(txtLowerLimit.Text);
            shipRule.UpperLimit = decimal.Parse(txtUpperLimit.Text);
        }
        else
        {
            shipRule.LowerLimit = null;
            shipRule.UpperLimit = null;
        }

        //Update or Add
        bool retval = false;

        if (ItemId > 0)
        {
            retval = shipAdmin.UpdateShippingRule(shipRule);
        }
        else
        {
            retval = shipAdmin.AddShippingRule(shipRule);
        }

        if (retval)
        {
            //redirect to main page
            Response.Redirect("~/admin/secure/settings/shipping/view.aspx?itemid=" + ShippingId.ToString() );
        }
        else
        {
            //display error message
            lblMsg.Text = "An error occurred while updating. Please try again.";
        }
    }