private bool checkValues() { if (string.IsNullOrEmpty(txtCbBranch.SelectedValue)) { txtError.Text = "No branch is available. First Add Branch from Branch Managment."; return(false); } if (string.IsNullOrEmpty(txtCbProduct.SelectedValue)) { txtError.Text = "No product available for branch. First Add Product in branch from Branch Managment."; return(false); } if (string.IsNullOrEmpty(txtCbAdonType.SelectedValue)) { txtError.Text = "No Adon Type available. First Add Adon type and Adon from Product Managment."; return(false); } else { short id = short.Parse(txtCbAdonType.SelectedValue); AdonType adontype = (from at in entities.AdonTypes where at.AdOnTypeId == id select at).FirstOrDefault(); if (!adontype.IsFreeAdonType) { if (txtPrice.Value == null) { txtError.Text = "Enter default adon price."; return(false); } } } return(true); }
public Int16 AddAdonType(AdonType adonType) { #region Parameters IParameter[] parameters = new Parameter[] { new Parameter("@AdOnTypeName", adonType.AdOnTypeName), new Parameter("@IsFreeAdonType", adonType.IsFreeAdonType), new Parameter("@ImageName", adonType.ImageName) }; #endregion object result = DBHandler.ExecuteScalar(System.Data.CommandType.StoredProcedure, "[AdonType_AddAdonType]", parameters); return(Convert.ToInt16(result.ToString())); }
protected void txtCbAdonType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) { short id = short.Parse(txtCbAdonType.SelectedValue); AdonType adontype = (from at in entities.AdonTypes where at.AdOnTypeId == id select at).FirstOrDefault(); Set_AdonTypeInProducts_LocalObject(); if (adontype.IsFreeAdonType) { txtPrice.Value = null; txtPrice.Enabled = false; } else { txtPrice.Enabled = true; CheckAvailbilityOfOptionsofProducts(); } BindAdons(); }
protected void grdProductAdonType_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == RadGrid.PerformInsertCommandName) { GridEditableItem editedItem = e.Item as GridEditableItem; if (editedItem != null) { RadTextBox name = editedItem.FindControl("txtAdOnTypeName") as RadTextBox; CheckBox chk = editedItem.FindControl("txtFree") as CheckBox; FileUpload txtImage = editedItem.FindControl("txtImage") as FileUpload; Label error = editedItem.FindControl("error") as Label; if (!string.IsNullOrEmpty(name.Text)) { try { AdonType adOnType = new AdonType(); adOnType.AdOnTypeName = name.Text; adOnType.IsFreeAdonType = chk.Checked; string filename = string.Empty; if (txtImage.HasFile) { filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName); } adOnType.ImageName = filename; Int16 result = _adonTypeManager.AddAdonType(adOnType); if (result > 0) { if (txtImage.HasFile) { String path = Server.MapPath("~/Products/AdonTypeImage/"); txtImage.SaveAs(path + filename); ThumbImage(path + filename, path + filename, 60, 60); } name.Text = string.Empty; } } catch (Exception ex) { // RadAjaxManager1.Alert("Error occured while Adding new Record. Error Detail ->" + ex.Message); } } } } else if (e.CommandName == RadGrid.UpdateCommandName) { GridEditableItem editedItem = e.Item as GridEditableItem; if (editedItem != null) { RadTextBox name = editedItem.FindControl("txtAdOnTypeName") as RadTextBox; CheckBox chk = editedItem.FindControl("txtFree") as CheckBox; FileUpload txtImage = editedItem.FindControl("txtImage") as FileUpload; Label error = editedItem.FindControl("error") as Label; if (!string.IsNullOrEmpty(name.Text)) { try { Telerik.Web.UI.DataKey key = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]; short id = (short)key["AdOnTypeId"]; AdonType adOnType = new AdonType(); adOnType.AdOnTypeId = id; adOnType.AdOnTypeName = name.Text; adOnType.IsFreeAdonType = chk.Checked; string filename = string.Empty; if (txtImage.HasFile) { filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName); } adOnType.ImageName = filename; Int32 result = _adonTypeManager.UpdateAdonType(adOnType); if (result > 0) { if (txtImage.HasFile) { String path = Server.MapPath("~/Products/AdonTypeImage/"); txtImage.SaveAs(path + filename); ThumbImage(path + filename, path + filename, 60, 60); } name.Text = string.Empty; } } catch (Exception ex) { //RadAjaxManager1.Alert("Error occured while updating Record. Error Detail ->" + ex.Message); } } else { error.Text = "Enter required valid values."; e.Canceled = true; } BindData(); } } }
protected void Button1_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridEditFormItem editedItem = (GridEditFormItem)btn.NamingContainer;// access the EditFormItem if (btn.CommandName == RadGrid.PerformInsertCommandName) { if (editedItem != null) { RadTextBox name = editedItem.FindControl("txtAdOnTypeName") as RadTextBox; CheckBox chk = editedItem.FindControl("txtFree") as CheckBox; FileUpload txtImage = editedItem.FindControl("txtImage") as FileUpload; Label error = editedItem.FindControl("error") as Label; if (!string.IsNullOrEmpty(name.Text)) { try { AdonType adOnType = new AdonType(); adOnType.AdOnTypeName = name.Text; adOnType.IsFreeAdonType = chk.Checked; string filename = string.Empty; if (txtImage.HasFile) { filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName); } adOnType.ImageName = filename; Int16 result = _adonTypeManager.AddAdonType(adOnType); if (result > 0) { if (txtImage.HasFile) { String path = Server.MapPath("~/Products/AdonTypeImage/"); txtImage.SaveAs(path + filename); ThumbImage(path + filename, path + filename, 60, 60); } name.Text = string.Empty; } } catch (Exception ex) { // RadAjaxManager1.Alert("Error occured while Adding new Record. Error Detail ->" + ex.Message); } } } } else if (btn.CommandName == RadGrid.UpdateCommandName) { if (editedItem != null) { RadTextBox name = editedItem.FindControl("txtAdOnTypeName") as RadTextBox; CheckBox chk = editedItem.FindControl("txtFree") as CheckBox; FileUpload txtImage = editedItem.FindControl("txtImage") as FileUpload; HiddenField hdAdonTypeId = editedItem.FindControl("hdAdonTypeId") as HiddenField; Label error = editedItem.FindControl("error") as Label; if (!string.IsNullOrEmpty(name.Text)) { try { Int16 adonTypeId = 0; Int16.TryParse(hdAdonTypeId.Value, out adonTypeId); AdonType adOnType = new AdonType(); adOnType.AdOnTypeId = adonTypeId; adOnType.AdOnTypeName = name.Text; adOnType.IsFreeAdonType = chk.Checked; string filename = string.Empty; if (txtImage.HasFile) { filename = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(txtImage.FileName); } adOnType.ImageName = filename; Int32 result = _adonTypeManager.UpdateAdonType(adOnType); if (result > 0) { if (txtImage.HasFile) { String path = Server.MapPath("~/Products/AdonTypeImage/"); txtImage.SaveAs(path + filename); ThumbImage(path + filename, path + filename, 60, 60); } name.Text = string.Empty; } } catch (Exception ex) { //RadAjaxManager1.Alert("Error occured while updating Record. Error Detail ->" + ex.Message); } } else { error.Text = "Enter required valid values."; } BindData(); } } }
private void GetPrice() { Double productPrice = 0; Products product = (Products)lbProducts.SelectedItem; if (_optionPrice == 0) { productPrice = product.DefaultBranchProductPrice; } else { productPrice = _optionPrice; } for (int i = 0; i < lbOptions.Items.Count; i++) { DependencyObject obj = lbOptions.ItemContainerGenerator.ContainerFromIndex(i); ContentPresenter adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj); OptionType optionType = (OptionType)adonTypeContentPresenter.Content; ListBox Options = FindVisualChild <ListBox>(obj); if (!optionType.IsMultiSelect && optionType.IsSamePrice) { } } for (int i = 0; i < lbToppings.Items.Count; i++) { DependencyObject obj = lbToppings.ItemContainerGenerator.ContainerFromIndex(i); ContentPresenter adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj); AdonType adonType = (AdonType)adonTypeContentPresenter.Content; ListBox AdonList = FindVisualChild <ListBox>(obj); for (int j = 0; j < AdonList.Items.Count; j++) { DependencyObject obj1 = AdonList.ItemContainerGenerator.ContainerFromIndex(j); // Getting the ContentPresenter of myListBoxItem ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1); // Finding textBlock from the DataTemplate that is set on that ContentPresenter DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; Int16 SelectedTopping = Convert.ToInt16(((TextBlock)myDataTemplate.FindName("SelectedTopping", myContentPresenter)).Text); if (SelectedTopping != 0) { if (!adonType.IsFreeAdonType) { Adon adon = (Adon)myContentPresenter.Content; if (adon.DefaultSelected != SelectedTopping) { if (_defaultAdonPrice > 0) { productPrice += _defaultAdonPrice; } else { productPrice += (Double)adonType.Price; } } } } } } Price.Content = productPrice.ToString("C", CultureInfo.CurrentCulture); }
private void OrderNowButton_Click(object sender, RoutedEventArgs e) { Double productPrice = 0; Products product = (Products)lbProducts.SelectedItem; List <OrderDetailAdOns> orderDetailAdonList = new List <OrderDetailAdOns>(); List <OrderDetailOptions> orderDetailOptionsList = new List <OrderDetailOptions>(); if (UserOrder == null) { UserOrder = new Orders(); } if (_optionPrice == 0) { productPrice = product.DefaultBranchProductPrice; } else { productPrice = _optionPrice; } if (UserOrder.OrderDetailsList == null) { UserOrder.OrderDetailsList = new List <BusinessEntities.OrderDetails>(); //SessionOrderAdonList = new List<List<BusinessEntities.OrderDetailAdOns>>(); //SessionOrderDetailOptionList = new List<List<BusinessEntities.OrderDetailOptions>>(); UserOrder.OrderStatusID = BusinessEntities.OrderStatus.NewOrder; } BusinessEntities.OrderDetails orderdetail = new BusinessEntities.OrderDetails(); if (!product.IsSpecial) { if (_optionPrice > 0) { orderdetail.Price = _optionPrice; } else { orderdetail.Price = Convert.ToDouble(product.DefaultBranchProductPrice); } } orderdetail.CategoryName = _category.Name; orderdetail.ProductName = product.Name; orderdetail.ProductID = product.ProductID; orderdetail.ProductImage = product.Image; orderdetail.Quantity = 1; if (product.IsSpecial) { MultiPorductControl control = (MultiPorductControl)MultiProductPanel.Children[0]; orderdetail.Price = control.GetPrice(); orderdetail.OrderDetailSubProducts = control.GetOrderDetailSubProducts(); orderdetail.IsGroupProduct = true; } else { #region Get Selected Option for (int i = 0; i < lbOptions.Items.Count; i++) { DependencyObject obj = lbOptions.ItemContainerGenerator.ContainerFromIndex(i); ContentPresenter optionTypeContentPresenter = FindVisualChild <ContentPresenter>(obj); OptionType optionType = (OptionType)optionTypeContentPresenter.Content; ListBox OptionList = FindVisualChild <ListBox>(obj); if (optionType.IsSamePrice && !optionType.IsMultiSelect) { for (int j = 0; j < OptionList.Items.Count; j++) { DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(j); // Getting the ContentPresenter of myListBoxItem ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1); // Finding textBlock from the DataTemplate that is set on that ContentPresenter DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; RadioButton selectedOption = (RadioButton)myDataTemplate.FindName("SelectedOption", myContentPresenter); if (selectedOption.IsChecked.Value) { ProductOptions productOptions = (ProductOptions)myContentPresenter.Content; OrderDetailOptions orderdetailoption = new OrderDetailOptions(); orderdetailoption.ProductOptionId = productOptions.OptionID; orderdetailoption.ProductOptionName = productOptions.OptionName; orderdetailoption.Price = Convert.ToDouble(productOptions.Price); orderDetailOptionsList.Add(orderdetailoption); orderdetail.Price = productOptions.Price; } } } else if (!optionType.IsSamePrice && !optionType.IsMultiSelect) { for (int j = 0; j < OptionList.Items.Count; j++) { DependencyObject obj1 = OptionList.ItemContainerGenerator.ContainerFromIndex(j); // Getting the ContentPresenter of myListBoxItem ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1); // Finding textBlock from the DataTemplate that is set on that ContentPresenter DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; RadioButton selectedOption = (RadioButton)myDataTemplate.FindName("SelectedOption", myContentPresenter); if (selectedOption.IsChecked.Value) { ProductOptions productOptions = (ProductOptions)myContentPresenter.Content; OrderDetailOptions orderdetailoption = new OrderDetailOptions(); orderdetailoption.ProductOptionId = productOptions.OptionID; orderdetailoption.ProductOptionName = productOptions.OptionName; orderdetailoption.Price = productOptions.Price; orderDetailOptionsList.Add(orderdetailoption); orderdetail.Price = productOptions.Price; } } } } #endregion #region Get Selected Toppings for (int i = 0; i < lbToppings.Items.Count; i++) { DependencyObject obj = lbToppings.ItemContainerGenerator.ContainerFromIndex(i); ContentPresenter adonTypeContentPresenter = FindVisualChild <ContentPresenter>(obj); AdonType adonType = (AdonType)adonTypeContentPresenter.Content; ListBox AdonList = FindVisualChild <ListBox>(obj); for (int j = 0; j < AdonList.Items.Count; j++) { DependencyObject obj1 = AdonList.ItemContainerGenerator.ContainerFromIndex(j); // Getting the ContentPresenter of myListBoxItem ContentPresenter myContentPresenter = FindVisualChild <ContentPresenter>(obj1); // Finding textBlock from the DataTemplate that is set on that ContentPresenter DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; Int16 SelectedTopping = Convert.ToInt16(((TextBlock)myDataTemplate.FindName("SelectedTopping", myContentPresenter)).Text); if (SelectedTopping != 0) { if (!adonType.IsFreeAdonType) { Adon adon = (Adon)myContentPresenter.Content; OrderDetailAdOns orderdetailadon = new OrderDetailAdOns(); orderdetailadon.AdOnId = adon.AdOnID; orderdetailadon.AdonName = adon.AdOnName; orderdetailadon.AdonTypeName = adon.AdOnTypeName; orderdetailadon.SelectedAdonOption = (SelectedOption)SelectedTopping; orderDetailAdonList.Add(orderdetailadon); if (adon.DefaultSelected != SelectedTopping) { if (_defaultAdonPrice > 0) { productPrice += _defaultAdonPrice; } else { productPrice += (Double)adonType.Price; } } } } } } #endregion } double discountPrice = 0; Double.TryParse(txtDiscount.Text, out discountPrice); if (discountPrice > 0) { orderdetail.Price = discountPrice; } else if (orderdetail.Price == 0) { orderdetail.Price = productPrice; } UserOrder.OrderDetailsList.Add(orderdetail); UserOrder.OrderTotal += orderdetail.Price; OrderDetailOptionList.Add(orderDetailOptionsList); OrderDetailAdonList.Add(orderDetailAdonList); lbOptions.ItemsSource = null; lbToppings.ItemsSource = null; _defaultAdonPrice = 0; _optionPrice = 0; SelectedAdons.Text = string.Empty; txtDiscount.Text = String.Empty; Price.Content = String.Empty; lbProducts.UnselectAll(); this.Close(); }