Ejemplo n.º 1
0
 protected void rptOptions_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
     {
         OptionTypesInProduct obj = e.Item.DataItem as OptionTypesInProduct;
         if (obj.ProductOptionsList != null && obj.ProductOptionsList.Count > 0)
         {
             if (obj.IsMultiSelect)
             {
                 CheckBoxList chklist = e.Item.FindControl("CheckBoxList") as CheckBoxList;
                 if (obj.IsSamePrice)
                 {
                     chklist.AutoPostBack = false;
                 }
                 chklist.DataSource = obj.ProductOptionsList;
                 chklist.DataBind();
             }
             else
             {
                 RadioButtonList radiolist = e.Item.FindControl("RadioButtonList") as RadioButtonList;
                 if (obj.IsSamePrice)
                 {
                     radiolist.AutoPostBack = false;
                 }
                 else
                 {
                     radiolist.SelectedIndexChanged += new EventHandler(radiolist_SelectedIndexChanged);
                 }
                 radiolist.DataSource = obj.ProductOptionsList;
                 radiolist.DataBind();
                 if (obj.ProductOptionsList != null && obj.ProductOptionsList.Count == 1)
                 {
                     radiolist.Items[0].Selected = true;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
    public OrderDetailSubProduct GetOrderDetailSubProduct()
    {
        Double productPrice = 0, toppingPrice = 0;
        bool   CalculateAdonPrice = false;

        #region Order Detail Sub Product

        OrderDetailSubProduct orderDetailSubProduct = new OrderDetailSubProduct();
        orderDetailSubProduct.ProductId     = ProductObject.ProductID;
        orderDetailSubProduct.Quantity      = 1;
        orderDetailSubProduct.ProductName   = ProductObject.Name;
        orderDetailSubProduct.RecipientName = txtRecipientName.Text.Trim();
        orderDetailSubProduct.Comments      = txtInstruction.Text;
        orderDetailSubProduct.OrderDetailSubProductAdons   = new List <OrderDetailSubProductAdon>();
        orderDetailSubProduct.OrderDetailSubProductOptions = new List <OrderDetailSubProductOption>();

        if (ProductObject.CategoryID == PizzaCategoryId)
        {
            orderDetailSubProduct.CrustType = (rblThinCrust.SelectedValue.ConvertToBool()) ? "Thin Crust" : "Regular";
        }


        #endregion

        foreach (RepeaterItem optionItem in rptOptions.Items)
        {
            #region Order Detail Sub Product Option

            #endregion
            HiddenField          OptionTypeID        = optionItem.FindControl("hdOptionTypeId") as HiddenField;
            OptionTypesInProduct optionTypeInProduct = ProductObject.OptionTypesInProductList.Where(ot => ot.OptionTypeID == Convert.ToInt16(OptionTypeID.Value)).FirstOrDefault();
            if (optionTypeInProduct.IsMultiSelect)
            {
                CheckBoxList chklist = optionItem.FindControl("CheckBoxList") as CheckBoxList;
                if (chklist != null)
                {
                    bool changePrice = true;
                    foreach (ListItem checkBox in chklist.Items)
                    {
                        if (checkBox.Selected)
                        {
                            ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(checkBox.Value)).First();
                            if (optionTypeInProduct.IsSamePrice && optionTypeInProduct.IsProductPriceChangeType)
                            {
                                if (changePrice)
                                {
                                    if (productPrice == 0)
                                    {
                                        productPrice = productOption.Price;
                                    }
                                    else
                                    {
                                        productPrice += productOption.Price;
                                    }
                                    changePrice = false;
                                }
                            }
                            else if (!optionTypeInProduct.IsSamePrice && optionTypeInProduct.IsProductPriceChangeType)
                            {
                                productPrice += productOption.Price;
                            }
                            else if (optionTypeInProduct.IsSamePrice)
                            {
                                productPrice += productOption.Price;
                            }
                            OrderDetailSubProductOption orderDetailSubProductOption = new OrderDetailSubProductOption();
                            orderDetailSubProductOption.ProductOptionId       = productOption.OptionID;
                            orderDetailSubProductOption.ProductOptionName     = productOption.OptionName;
                            orderDetailSubProductOption.Price                 = productOption.Price;
                            orderDetailSubProductOption.ProductOptionTypeName = optionTypeInProduct.OptionTypeName;
                            orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderDetailSubProductOption);
                        }
                    }
                }
            }
            else
            {
                RadioButtonList radiolist = optionItem.FindControl("RadioButtonList") as RadioButtonList;
                if (radiolist != null && !String.IsNullOrEmpty(radiolist.SelectedValue))
                {
                    OrderDetailSubProductOption orderDetailSubProductOption = new OrderDetailSubProductOption();
                    if (optionTypeInProduct.IsSamePrice)
                    {
                        ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(radiolist.SelectedValue)).FirstOrDefault();
                        productPrice = optionTypeInProduct.ProductOptionsList[0].Price;
                        orderDetailSubProductOption.ProductOptionName     = productOption.OptionName;
                        orderDetailSubProductOption.ProductOptionTypeName = optionTypeInProduct.OptionTypeName;
                        CalculateAdonPrice = optionTypeInProduct.IsAdonPriceVary;
                    }
                    else
                    {
                        ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(radiolist.SelectedValue)).FirstOrDefault();

                        orderDetailSubProductOption.ProductOptionId       = productOption.OptionID;
                        orderDetailSubProductOption.ProductOptionName     = productOption.OptionName;
                        orderDetailSubProductOption.Price                 = productOption.Price;
                        orderDetailSubProductOption.Price                 = optionTypeInProduct.ProductOptionsList[0].Price;
                        orderDetailSubProductOption.ProductOptionTypeName = optionTypeInProduct.OptionTypeName;
                        CalculateAdonPrice = optionTypeInProduct.IsAdonPriceVary;
                    }
                    orderDetailSubProduct.OrderDetailSubProductOptions.Add(orderDetailSubProductOption);
                }
                else
                {
                    productPrice = ProductObject.UnitPrice;
                }
            }
            if (CalculateAdonPrice)
            {
                Int16 freeToppingCount = 0;
                foreach (RepeaterItem adonTypeItem in rptAdonsType.Items)
                {
                    HiddenField       hdAdonTypeId = adonTypeItem.FindControl("hdAdonTypeId") as HiddenField;
                    AdOnTypeInProduct adonType     = ProductObject.AdOnTypeInProductList.Where(at => at.AdonTypeID == Convert.ToInt16(hdAdonTypeId.Value)).FirstOrDefault();

                    Repeater rptAdons = adonTypeItem.FindControl("rptAdons") as Repeater;
                    foreach (RepeaterItem adonItem in rptAdons.Items)
                    {
                        Double      adonPrice = 0;
                        HiddenField hdAdonId  = adonItem.FindControl("hdAdonId") as HiddenField;
                        Adon        adon      = adonType.Adons.Where(a => a.AdOnID == Convert.ToInt32(hdAdonId.Value)).FirstOrDefault();

                        HiddenField SelectedSize   = adonItem.FindControl("SelectedSize") as HiddenField;
                        short       selectedoption = short.Parse(SelectedSize.Value);

                        CheckBox txtDouble = adonItem.FindControl("txtDouble") as CheckBox;

                        OrderDetailSubProductAdon orderDetailSubAdon = new OrderDetailSubProductAdon();
                        orderDetailSubAdon.AdOnId             = adon.AdOnID;
                        orderDetailSubAdon.AdonName           = adon.AdOnName;
                        orderDetailSubAdon.AdonTypeName       = adonType.AdOnTypeName;
                        orderDetailSubAdon.SelectedAdonOption = selectedoption;
                        orderDetailSubAdon.IsDoubleSelected   = txtDouble.Checked;
                        if (adon.DefaultSelected == 0 && (selectedoption == 1 || selectedoption == 2 || selectedoption == 3))
                        {       // When None was default selected and user has changed default selected option
                            if (!adonType.IsFreeAdonType)
                            {
                                if (txtDouble.Checked)
                                {
                                    if (freeToppingCount == ProductObject.NumberOfFreeTopping)
                                    {
                                        if (toppingPrice > 0)
                                        {
                                            adonPrice += 2 * toppingPrice;
                                        }
                                        else
                                        {
                                            adonPrice += (2 * Convert.ToDouble(adonType.Price));
                                        }
                                    }
                                    else
                                    {
                                        if (toppingPrice > 0)
                                        {
                                            productPrice += toppingPrice;
                                        }
                                        else
                                        {
                                            productPrice += Convert.ToDouble(adonType.Price);
                                        }
                                        freeToppingCount++;
                                    }
                                }
                                else
                                {
                                    if (freeToppingCount == ProductObject.NumberOfFreeTopping)
                                    {
                                        if (toppingPrice > 0)
                                        {
                                            productPrice            += toppingPrice;
                                            orderDetailSubAdon.Price = toppingPrice;
                                        }
                                        else
                                        {
                                            productPrice            += Convert.ToDouble(adonType.Price);
                                            orderDetailSubAdon.Price = Convert.ToDouble(adonType.Price);
                                        }
                                    }
                                    else
                                    {
                                        freeToppingCount++;
                                    }
                                }
                            }
                            orderDetailSubProduct.OrderDetailSubProductAdons.Add(orderDetailSubAdon);
                        }
                        else  // When other than None is pre selected and user has also selected Double check box
                        {
                            if (txtDouble.Checked && selectedoption != 0)
                            {
                                if (toppingPrice > 0)
                                {
                                    adonPrice += toppingPrice;
                                }
                                else
                                {
                                    adonPrice += Convert.ToDouble(adonType.Price);
                                }
                                orderDetailSubAdon.Price = adonPrice;
                                orderDetailSubProduct.OrderDetailSubProductAdons.Add(orderDetailSubAdon);
                            }
                            else
                            {
                                txtDouble.Checked = false;
                            }
                        }

                        productPrice += adonPrice;
                    }
                }
            } // CalculateAdonPrice
        }     // rptOptions

        orderDetailSubProduct.Price = productPrice;


        return(orderDetailSubProduct);
    }
Ejemplo n.º 3
0
    public Double GetPrice()
    {
        Double productPrice = ProductObject.UnitPrice, toppingPrice = 0;
        bool   CalculateAdonPrice = false;

        if (rptOptions.Items.Count > 0)
        {
            foreach (RepeaterItem optionItem in rptOptions.Items)
            {
                HiddenField          OptionTypeID        = optionItem.FindControl("hdOptionTypeId") as HiddenField;
                OptionTypesInProduct optionTypeInProduct = ProductObject.OptionTypesInProductList.Where(ot => ot.OptionTypeID == Convert.ToInt16(OptionTypeID.Value)).FirstOrDefault();
                if (optionTypeInProduct.IsMultiSelect)
                {
                    CheckBoxList chklist = optionItem.FindControl("CheckBoxList") as CheckBoxList;
                    if (chklist != null)
                    {
                        bool changePrice = true;
                        foreach (ListItem checkBox in chklist.Items)
                        {
                            if (checkBox.Selected)
                            {
                                ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(checkBox.Value)).First();
                                if (optionTypeInProduct.IsSamePrice && optionTypeInProduct.IsProductPriceChangeType)
                                {
                                    if (changePrice)
                                    {
                                        if (productPrice == 0)
                                        {
                                            productPrice = productOption.Price;
                                        }
                                        else
                                        {
                                            productPrice += productOption.Price;
                                        }
                                        changePrice = false;
                                    }
                                }
                                else if (!optionTypeInProduct.IsSamePrice && optionTypeInProduct.IsProductPriceChangeType)
                                {
                                    productPrice += productOption.Price;
                                }
                                else if (optionTypeInProduct.IsSamePrice)
                                {
                                    productPrice = productOption.Price;
                                }
                            }
                        }
                    }
                }
                else
                {
                    RadioButtonList radiolist = optionItem.FindControl("RadioButtonList") as RadioButtonList;
                    if (radiolist != null && !String.IsNullOrEmpty(radiolist.SelectedValue))
                    {
                        CalculateAdonPrice = true;
                        if (optionTypeInProduct.IsSamePrice)
                        {
                            ProductOptions productOption = optionTypeInProduct.ProductOptionsList[0];
                            productPrice = productOption.Price;
                        }
                        else
                        {
                            ProductOptions productOption = optionTypeInProduct.ProductOptionsList.Where(po => po.OptionID == Convert.ToInt32(radiolist.SelectedValue)).FirstOrDefault();
                            productPrice = productOption.Price;
                            toppingPrice = productOption.ToppingPrice;
                        }
                    }
                    else
                    {
                        productPrice = ProductObject.UnitPrice;
                    }
                }
                if (CalculateAdonPrice)
                {
                    productPrice = CalculateToppingPrice(productPrice, toppingPrice);
                }
            }
        }
        else
        {
            productPrice = CalculateToppingPrice();
        }
        return(productPrice);
    }
Ejemplo n.º 4
0
    protected void SaveBtn_Click(object sender, EventArgs e)
    {
        if (checkValues())
        {
            int              branchid      = int.Parse(txtCbBranch.SelectedValue);
            int              productid     = int.Parse(txtCbProduct.SelectedValue);
            short            optiontypeid  = short.Parse(txtCbOptionType.SelectedValue);
            ProductsInBranch productbranch = (from pb in entities.ProductsInBranches
                                              where pb.BranchID == branchid && pb.ProductID == productid
                                              select pb).FirstOrDefault();
            if (productbranch != null)
            {
                BusinessEntities.OptionTypesInProduct optiontypeproduct = new BusinessEntities.OptionTypesInProduct();
                ICollection <BusinessEntities.ProductOptionsInProducts> ProductOptionList = new List <BusinessEntities.ProductOptionsInProducts>();

                optiontypeproduct.BranchID     = branchid;
                optiontypeproduct.ProductID    = productid;
                optiontypeproduct.OptionTypeID = Convert.ToInt16(txtCbOptionType.SelectedValue);


                GridItemCollection collection = grdOptions.Items;
                bool flag = true;

                foreach (GridItem item in collection)
                {
                    CheckBox         chk          = item.FindControl("txtSelected") as CheckBox;
                    GridEditableItem editableItem = item as GridEditableItem;
                    int productoptionid           = (int)editableItem.GetDataKeyValue("OptionID");
                    if (chk.Checked)
                    {
                        BusinessEntities.ProductOptionsInProducts productoption = new BusinessEntities.ProductOptionsInProducts();
                        productoption.ProductOptionID = productoptionid;
                        CheckBox enable = item.FindControl("txtEnabled") as CheckBox;
                        productoption.Enabled = enable.Checked;
                        RadNumericTextBox txtDisplayOrder = item.FindControl("txtDisplayOrder") as RadNumericTextBox;
                        productoption.DisplayOrder = Convert.ToInt16(txtDisplayOrder.Value.ToString());

                        if (txtNo.Checked)
                        {
                            RadNumericTextBox price = item.FindControl("txtOptionPrice") as RadNumericTextBox;
                            if (price.Value != null)
                            {
                                productoption.Price = Convert.ToDecimal(price.Value);
                            }
                            else
                            {
                                ShowMessage("You have not entered option price in selected row of Available Options Table.", MessageType.Error);
                                item.Selected = true;
                                flag          = false;
                                break;
                            }
                        }
                        else if (txtYes.Checked)
                        {
                            productoption.Price = Convert.ToDecimal(txtPrice.Value);
                        }

                        if (txtAdonYes.Checked)
                        {
                            RadNumericTextBox price1 = item.FindControl("txtAdonPrice") as RadNumericTextBox;
                            if (price1.Value != null)
                            {
                                productoption.ToppingPrice = Convert.ToDecimal(price1.Value);
                            }
                            else
                            {
                                ShowMessage("You have not entered Adon price in selected row of Available Options Table.", MessageType.Error);
                                item.Selected = true;
                                flag          = false;
                                break;
                            }
                        }
                        else
                        {
                            productoption.ToppingPrice = new Nullable <decimal>();
                        }
                        ProductOptionList.Add(productoption);
                    }
                }

                if (flag && ProductOptionList.Count > 0)
                {
                    try
                    {
                        if (txtYes.Checked)
                        {
                            optiontypeproduct.IsSamePrice = true;
                        }
                        else
                        {
                            optiontypeproduct.IsSamePrice = false;
                        }
                        if (txtMultiYes.Checked)
                        {
                            optiontypeproduct.IsMultiSelect = true;
                        }
                        else
                        {
                            optiontypeproduct.IsMultiSelect = false;
                        }
                        if (txtAdonYes.Checked)
                        {
                            optiontypeproduct.IsAdonPriceVary = true;
                        }
                        else
                        {
                            optiontypeproduct.IsAdonPriceVary = false;
                        }
                        if (txtPriceChangeYes.Checked)
                        {
                            optiontypeproduct.IsProductPriceChangeType = true;
                        }
                        else
                        {
                            optiontypeproduct.IsProductPriceChangeType = false;
                        }
                        optiontypeproduct.ProductOptionsXml = Utility.CollectionXml <BusinessEntities.ProductOptionsInProducts>(ProductOptionList, "ProductOptionsInProductsDataSet", "ProductOptionsInProductsDataTable");
                        int result = productOptionManager.AddProductOption(optiontypeproduct);
                        if (result > 0)
                        {
                            ShowMessage("Options have been saved successfully.", MessageType.Success);
                        }
                    }
                    catch (Exception ex)
                    {
                        txtError.Text = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message;
                    }
                }
                else if (flag)
                {
                    ShowMessage("You have selected no option. You must select option to proceed.", MessageType.Error);
                }
            }
        }
    }