private double CalculateToppingPrice(Double productPrice, Double toppingPrice) { 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) { HiddenField hdAdonId = adonItem.FindControl("hdAdonId") as HiddenField; Adon adon = adonType.Adons.Where(a => a.AdOnID == Convert.ToInt32(hdAdonId.Value)).FirstOrDefault(); if (adonType.DisplayFormat == 1) { //RadioButtonList txtAdonOptions = adonItem.FindControl("AdonOptions") as RadioButtonList; CheckBox txtDouble = adonItem.FindControl("txtDouble") as CheckBox; //short selectedoption = short.Parse(txtAdonOptions.SelectedValue); HiddenField SelectedSize = adonItem.FindControl("SelectedSize") as HiddenField; short selectedoption = short.Parse(SelectedSize.Value); if (adon.DefaultSelected == 0 && selectedoption != 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) { productPrice += 2 * toppingPrice; } else { productPrice += (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; } else { productPrice += Convert.ToDouble(adonType.Price); } } else { freeToppingCount++; } } } } else // When other than None is pre selected and user has also selected Double check box { if (txtDouble.Checked && selectedoption != 0) { if (toppingPrice > 0) { productPrice += toppingPrice; } else { productPrice += Convert.ToDouble(adonType.Price); } } else { txtDouble.Checked = false; } } UnSelectOtherSize(adonItem, selectedoption); } else if (adonType.DisplayFormat == 2 || adonType.DisplayFormat == 3) { } else if (adonType.DisplayFormat == 4) { RadioButtonList NoneFullRadioButtonList = adonItem.FindControl("NoneFullRadioButtonList") as RadioButtonList; short selectedoption = short.Parse(NoneFullRadioButtonList.SelectedValue); if (!NoneFullRadioButtonList.SelectedValue.Equals("0")) { if (adon.DefaultSelected == 0 && selectedoption == 1) { if (!adonType.IsFreeAdonType) { if (toppingPrice > 0) { productPrice += toppingPrice; } else { productPrice += Convert.ToDouble(adonType.Price); } } } } UnSelectOtherSize(adonItem, selectedoption); } } } return(productPrice); }
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); }
protected void rptAdons_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item is RepeaterItem) { RepeaterItem item = e.Item; Adon obj = item.DataItem as Adon; if (obj != null) { Label adonname = item.FindControl("txtAdonName") as Label; adonname.Text = obj.AdOnName; if (obj.DisplayFormat == 1) { RadioButtonList adonoptions = item.FindControl("AdonOptions") as RadioButtonList; DefaultSelected(item, obj.DefaultSelected); } else if (obj.DisplayFormat == 2) { RadioButton AdonRadioButton = item.FindControl("AdonRadioButton") as RadioButton; AdonRadioButton.Visible = true; } else if (obj.DisplayFormat == 3) { CheckBox AdonCheckBox = item.FindControl("AdonCheckBox") as CheckBox; AdonCheckBox.Visible = true; } else if (obj.DisplayFormat == 4) { DefaultSelected(item, obj.DefaultSelected, false, false, false); } } } //Adon obj = e.Item.DataItem as Adon; //if (obj != null) //{ // Label adonname = e.Item.FindControl("txtAdonName") as Label; // adonname.Text = obj.AdOnName; // if (obj.DisplayFormat == 1) // { // RadioButtonList adonoptions = e.Item.FindControl("AdonOptions") as RadioButtonList; // adonoptions.Items[obj.DefaultSelected].Selected = true; // adonoptions.Visible = true; // if (obj.DefaultSelected != 0) // { // adonoptions.SelectedValue = obj.DefaultSelected.ToString(); // } // CheckBox txtDouble = e.Item.FindControl("txtDouble") as CheckBox; // txtDouble.Visible = true; // } // else if (obj.DisplayFormat == 2) // { // RadioButton AdonRadioButton = e.Item.FindControl("AdonRadioButton") as RadioButton; // AdonRadioButton.Visible = true; // } // else if (obj.DisplayFormat == 3) // { // CheckBox AdonCheckBox = e.Item.FindControl("AdonCheckBox") as CheckBox; // AdonCheckBox.Visible = true; // } // else if (obj.DisplayFormat == 4) // { // RadioButtonList adonoptions = e.Item.FindControl("NoneFullRadioButtonList") as RadioButtonList; // adonoptions.Items[obj.DefaultSelected].Selected = true; // adonoptions.Visible = true; // if (obj.DefaultSelected != 0) // { // adonoptions.SelectedValue = obj.DefaultSelected.ToString(); // } // } //} }