public EditProduct(ShopProduct EditProduct) { InitializeComponent(); cmbCategory.ItemsSource = publicData.myCategory; _editProduct = EditProduct; cmbCategory.SelectedItem = _editProduct.Category; txtName.Text = _editProduct.Name; txtPrice.Text = string.Format("{0:N2}", _editProduct.Price); txtTax.Text = string.Format("{0:N2}", _editProduct.Tax); txtDesc.Text = _editProduct.Description; }
private void Button_Click(object sender, RoutedEventArgs e) { ShopProduct curProd = (ShopProduct)((Button)sender).Tag; if (selectedProducts.Contains(curProd))//Check if product is already in cart { cartNotification.Text = "Already in Cart"; cartNotificationBG.Color = Colors.Cyan; } else { //Add to Cart cartItem newItem = new cartItem(); newItem.Product = curProd; newItem.Qty = 1; selectedProducts.Add(curProd); myCart.Add(newItem); cartNotification.Text = "Added to Cart"; cartNotificationBG.Color = Colors.Yellow; btnCheckout.IsEnabled = true; btnClearCart.IsEnabled = true; cartHeader.Visibility = Visibility.Visible; //Update Cart Amount totalAmount = 0; totalTax = 0; for (int i = 0; i < myCart.Count; i++) { totalAmount += myCart[i].Rate; totalTax += myCart[i].Tax; } lbltax.Text = string.Format("${0:N2}", totalTax); lblsubAmount.Text = string.Format("${0:N2}", totalAmount); lbltotal.Text = string.Format("${0:N2}", totalAmount + totalTax); } cartPopupNotify.IsOpen = true;//Notify dtClockTime.Stop(); dtClockTime.Start(); }
private void btnSave_Click(object sender, RoutedEventArgs e) { ShopCategory ct = (ShopCategory)cmbCategory.SelectedItem; //Check Data if (Convert.ToDouble(txtPrice.Text) == 0) { MessageBox.Show("Price cannot be Zero"); txtPrice.Focus(); return; } if (txtName.Text == "") { MessageBox.Show("Please enter Name"); txtName.Focus(); return; } if (_editProduct == null)//New Product { _editProduct = new ShopProduct(); _editProduct.Category = ct; _editProduct.Name = txtName.Text; _editProduct.Price = Convert.ToDouble(txtPrice.Text); _editProduct.Tax = Convert.ToDouble(txtTax.Text); _editProduct.Description = txtDesc.Text; publicData.myProducts.Add(_editProduct); } else //Edit Product { _editProduct.Category = ct; _editProduct.Name = txtName.Text; _editProduct.Price = Convert.ToDouble(txtPrice.Text); _editProduct.Tax = Convert.ToDouble(txtTax.Text); _editProduct.Description = txtDesc.Text; } this.NavigationService.GoBack(); }