//public DataGrid SaleListDataGrid { get; set; } //public DataGrid SaleDetailsDataGrid { get; set; } public bool Addsale(SalesCl sale) { try { if (Sales == null) { Sales = new List <SalesCl>(); } Sales.Add(sale); BindSale(); return(true); } catch (Exception) { return(false); } }
private void SalesSaveToList_Click(object sender, RoutedEventArgs e) { try { var sale = new SalesCl { CustomerName = myCustomerComboBox.Text, TransID = int.Parse(transID.Text), CategoryName = myCategoryComboBox.Text, ProductName = myProductComboBox.Text, Price = decimal.Parse(price.Text), Quantity = int.Parse(quantity.Text), TotalAmount = decimal.Parse(subTotal.Text), DateTime = DateTime.Parse(dateOfSales.Text) }; //db.Sales.Add(sale); //db.SaveChanges(); //dataGrid.ItemsSource = db.Sales.ToList(); saleListList.Addsale(sale); saleListList.BindSale(); var saleList = new SalesList { TransactionID = int.Parse(transID.Text), ProductName = myProductComboBox.Text, UnitPrice = decimal.Parse(price.Text), Quantity = int.Parse(quantity.Text), TotalAmount = decimal.Parse(subTotal.Text), }; db.SaleList.Add(saleList); db.SaveChanges(); // myCategoryComboBox.SelectedIndex = -1; //myProductComboBox.SelectedIndex = -1; price.Clear(); quantity.Clear(); subTotal.Clear(); //var salesSum = db.Sales; var salesSum = saleListList.Sales; amountDue.Text = salesSum.Sum(g => g.TotalAmount).ToString(); //Updating the new quantity value on the quantity page //var changeQuantity = db.Product.Where(b => b.Name == myProductComboBox.Text).ToList(); //foreach (var item in changeQuantity) //{ // int newQuatity = int.Parse(quantity.Text) - item.Quantity; // var chang = db.Product.Where(b => b.Name == myProductComboBox.Text).Select(b => b.Quantity).Single(); // chang = newQuatity; // //item.Equals(chang); //} //} } catch (Exception) { } }