Link to home
Create AccountLog in
Avatar of Tammu
Tammu

asked on

Check asp.net textbox value against multiple if conditions

I am currently using this code to check the textbox value against multiple if conditions. It works great. here is the code I am using

 protected void btUpdate_Click(object sender, EventArgs e)
    {

        Order currentOrder = Basket.Order;

        string tbcodeValue = this.tbpromo.Text.Trim().ToUpper();

        string[] validCodes = new string[] { "ABCD", "EFGH", "MNOP" };
        if (!((IList<string>)validCodes).Contains(tbcodeValue))
        {
            lbmessage.Text = "Invalid Promo code. Please enter again";
        }
        else
        {
            currentOrder.Shipping.Cost = 0;
            this.lShipping.Text = currentOrder.Shipping.Cost.ToString("c");
            this.lSubtotal.Text = currentOrder.Subtotal.ToString("c");
            this.lTotal.Text = currentOrder.TotalCost.ToString("c");
            currentOrder.PromotionCode = tbcodeValue;
            lbmessage.Text = "Free Standard Shipping on All Orders";

        }

Open in new window


I would like to extend this code in such way that say for example if the promo code is equal to DEFG, i would like to charge a different shipping cost from 0 to 2.95

and  keep the rest the of the promo codes to be at 0.

any advice is appreciated.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi,
If I'll have to implement this, I'll move the parts that are subject of changes to different classes, in this case Shipping (maybe you already have it). Here, you'll have to have a mechanism for retrieving the cost amout based on certain criteria like promo codes, shipping company, taxes etc. every criteria will add a certain amout (+, -) to the overall cost.
Avatar of Tammu
Tammu

ASKER

Thanks xusersx2000,

Here is my updated code. I will definitely keep in mind about the SQL as this is a just a one time offering to the customer for the next 5 days. I think I can use this. Please tell me if this looks good

   protected void btUpdate_Click(object sender, EventArgs e)
    {

        Order currentOrder = Basket.Order;

        string tbcodeValue = this.tbpromo.Text.Trim().ToUpper();

        string[] validCodes = new string[] { "ABCD", "DEFG", "A7F", "B13F", "E25F", "N19F" };
        if (!((IList<string>)validCodes).Contains(tbcodeValue))
        {
            lbmessage.Text = "Invalid Promo code. Please enter again";
            this.lShipping.Text = currentOrder.Shipping.Cost.ToString("c");
            this.lSubtotal.Text = currentOrder.Subtotal.ToString("c");
            this.lTotal.Text = currentOrder.TotalCost.ToString("c");
        }
        else 
        {
            switch (tbcodeValue)
            {
                case "S495":
                    currentOrder.Shipping.Cost = 2.95;
                    lbmessage.Text = "$2.95 Standard Shipping on All Orders";
                    break;
                default:
                    currentOrder.Shipping.Cost = 0;
                    lbmessage.Text = "Free Standard Shipping on All Orders";
                    break;
            }
            this.lShipping.Text = currentOrder.Shipping.Cost.ToString("c");
            this.lSubtotal.Text = currentOrder.Subtotal.ToString("c");
            this.lTotal.Text = currentOrder.TotalCost.ToString("c");
            currentOrder.PromotionCode = tbcodeValue;
        }

    }

Open in new window


Thanks and appreciate it
Avatar of Tammu

ASKER

Thanks