public void GetItemsFromStore() { ConnectStoreDBDataContext obj = new ConnectStoreDBDataContext(); dgShowStore.ItemsSource = from store in obj.Stores select store; }
//Show sale Summary private void MenuItem_Click(object sender, RoutedEventArgs e) { Sale_Sum smObj = new Sale_Sum(); smObj.Show(); ConnectStoreDBDataContext db = new ConnectStoreDBDataContext(); var query = from sale in db.Sales group sale by new { sale.ID_Product } into dbom let SalePrice = dbom.Sum(s => s.Price_Sum) select new { ID = dbom.Key.ID_Product, SalePrice, SaleQnt = dbom.Sum(q => q.Sold_Qnt) }; smObj.dgSaleSum.ItemsSource = from gpS in query join store in db.Stores on gpS.ID equals store.ID select new { ID = gpS.ID, Name = store.Product, Sale_Price_Sum = gpS.SalePrice, Sale_Quantity = gpS.SaleQnt, Quantity = store.Quantity_Start - gpS.SaleQnt }; }
public Sale_History() { InitializeComponent(); //Show Sales ConnectStoreDBDataContext obj1 = new ConnectStoreDBDataContext(); dgShowSale.ItemsSource = from store in obj1.Stores join sale in obj1.Sales on store.ID equals sale.ID_Product select new { sale.ID, Name = store.Product, Store_ID = store.ID, sale.Sale_Price, sale.Sold_Qnt, sale.Price_Sum, sale.Sale_Date, sale.Note }; ////////////////////////////////////////////////////////////////////////// // in tab 2 show [Overall_Sale, Sold_Qnt, Overall_Qnt] /* * ConnectStoreDBDataContext db = new ConnectStoreDBDataContext(); * * var query = from sale in db.Sales * str in db.Stores * select new * { * ID = dbom.Key.ID_Product, * SalePrice, * SaleQnt = dbom.Sum(q => q.Sold_Qnt) * * }; * * * var query1 = from gpS in query * join store in db.Stores * on gpS.ID equals store.ID * select new * { * ID = gpS.ID, * Name = store.Product, * Sale_Price_Sum = gpS.SalePrice, * Sale_Quantity = gpS.SaleQnt, * Quantity = store.Quantity_Start - gpS.SaleQnt * }; * * * * ////////////////////////////////////////////////////////////////////////// */ }
public Income() { InitializeComponent(); ConnectStoreDBDataContext obj = new ConnectStoreDBDataContext(); //Cost for all items var allCst = obj.Stores.AsEnumerable().Sum(cost => cost.Real_Price_AMD * cost.Quantity_Start); tbCost.Text = allCst.ToString(); //Sale summary var sal = obj.Sales.AsEnumerable().Sum(income => income.Price_Sum); tbSale.Text = sal.ToString(); // var curCst = obj.Sales.AsEnumerable().Sum(cost => cost.Price_Sum); // tbcurrentCost.Text = curCst.ToString(); //Cost for sold items double?currentCst = (from cst in obj.Stores join sl in obj.Sales on cst.ID equals sl.ID_Product select cst.Real_Price_AMD).Sum(); tbcurrentCost.Text = currentCst.ToString(); //Current Income tbCurIncome.Text = (sal - currentCst).ToString(); //Overall Income tbOverallIncome.Text = (sal - allCst).ToString(); /* var query = obj.Stores.Join(sal, * (cst => cst.ID), * () * ); */ /* * var query = from clients in db.Clients * join orders in db.Orders on clients.Id equals orders.ClientId * select new { Clients = clients, Orders = orders }; * * * var query = db.Clients.Join( orders, // Target table * ( cl => cl.Id ), // ID of clients column * ( or => or.ClientID), // Corresponding ID for orders to join on * ( ( cl, or ) => new { Clients = cl, Orders = or } )); * * */ }
private void okBtn_Click(object sender, RoutedEventArgs e) { try { Qnt = int.Parse(saleQuantity.Text); if (Qnt == 0) { MessageBox.Show("Please enter value greater than 0"); return; } ConnectStoreDBDataContext obj = new ConnectStoreDBDataContext(); Store str = obj.Stores.Single(s => s.ID == MainView.CurrentID); if (str.Quantity_Now >= Qnt) { str.Quantity_Now = str.Quantity_Now - Qnt; obj.SubmitChanges(); } else { string errorString = "Available quantity is: " + str.Quantity_Now; MessageBox.Show(errorString); return; } Note = saleNote.Text; } catch (Exception) { MessageBox.Show("Please enter valid values for Quantity and/or Price"); return; } ConnectStoreDBDataContext db = new ConnectStoreDBDataContext(); if (salePrice.Text == "") { Price = (from store in db.Stores where store.ID == MainView.CurrentID select store.Sale_Price_AMD).Sum(); } else { Price = int.Parse(salePrice.Text); } Price_Sum = (double)Price * Qnt; Sale sl = new Sale(); sl.ID_Product = MainView.CurrentID; sl.Sold_Qnt = Qnt; sl.Sale_Price = (double)Price; sl.Price_Sum = Price_Sum; sl.Note = Note; sl.Sale_Date = DateTime.Now; db.Sales.InsertOnSubmit(sl); db.SubmitChanges(); MainView.CurrentID = 0; this.Close(); }