//buttons implemntaion private void AddNewRowButton_Click(object sender, RoutedEventArgs e) { if (quantityTextbox.Text == "0" || unitsDropdownList.SelectedItem == null) { MessageBox.Show("please complete all fields "); return; } ItemCalculationHelper calculationHelper = new ItemCalculationHelper { Quantity = double.Parse(quantityTextbox.Text), Price = double.Parse(priceTextbox.Text), Discount = double.Parse(discountTextbox.Text) }; calculationHelper.Total = calculationHelper.Quantity * calculationHelper.Price; calculationHelper.Net = calculationHelper.Total - calculationHelper.Discount; DataItemRow dataItemRow = new DataItemRow { Item = itemsDropdownList.Text, Unit = unitsDropdownList.Text, Price = priceTextbox.Text, Quantity = calculationHelper.Quantity.ToString(), Total = calculationHelper.Total.ToString(), Discount = calculationHelper.Discount.ToString(), Net = calculationHelper.Net.ToString() }; dataGridview.Items.Add(dataItemRow); invoiceItems.Add(new InvoiceItems { ItemName = dataItemRow.Item, ItemUnit = dataItemRow.Unit, ItemPrice = double.Parse(dataItemRow.Price), ItemQuantity = long.Parse(dataItemRow.Quantity), ItemTotal = double.Parse(dataItemRow.Total), ItemDiscount = double.Parse(dataItemRow.Discount), ItemNet = double.Parse(dataItemRow.Net) }); UpdateInvoiceTotal(calculationHelper.Net); ClearAllFields(); storesDropdownList.IsEnabled = false; }
//text Fields Change private void quantityTextbox_TextChanged(object sender, TextChangedEventArgs e) { if (quantityTextbox.Text == "") { quantityTextbox.Text = "0"; } if (priceTextbox.Text == "") { priceTextbox.Text = "0"; } ItemCalculationHelper calculationHelper = new ItemCalculationHelper { Quantity = double.Parse(quantityTextbox.Text), Price = double.Parse(priceTextbox.Text) }; calculationHelper.Total = calculationHelper.Quantity * calculationHelper.Price; calculationHelper.Net = calculationHelper.Total - calculationHelper.Discount; totalTextbox.Text = calculationHelper.Total.ToString(); }