private void Button_Click_DelPro(object sender, RoutedEventArgs e) { db = new managementdbEntities(); if (selectedPro == null) { return; } if (selectedPro.BARCODE == null) { return; } PRODUCT delPro = db.PRODUCTs.Where(x => x.BARCODE == selectedPro.BARCODE).Select(x => x).SingleOrDefault(); string message = "Do you surely want to delete this product? "; string caption = "Delete Product"; var result = MessageBox.Show(message, caption, MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { delPro.PSTATUS = 0; db.SaveChanges(); MessageBox.Show("Deleted category"); this.Page_Loaded(sender, e); } else { } db.SaveChanges(); this.Page_Loaded(sender, e); selectedPro = null; }
// Add new category private void Button_Click_Add(object sender, RoutedEventArgs e) { addform = new CAdd(); addform.DatabaseChanged += addform_DatabaseChanged; addform.ShowDialog(); if (newCate == null) { return; } db = new managementdbEntities(); CATEGORY newCategory = db.CATEGORies.Where(x => x.CNAME == newCate).Select(x => x).FirstOrDefault(); if (newCategory == null) { newCategory = new CATEGORY(); newCategory.CNAME = newCate; newCategory.CSTATUS = 1; db.CATEGORies.Add(newCategory); } else { newCategory.CSTATUS = 1; } db.SaveChanges(); this.Page_Loaded(sender, e); newCate = null; }
public PAdd() { InitializeComponent(); db = new managementdbEntities(); db.Configuration.ProxyCreationEnabled = false; db.CATEGORies.ToList(); var filteredCate = db.CATEGORies.Local .Where(x => x.CSTATUS == 1); cbCatagory.ItemsSource = filteredCate.ToList(); }
public PUpdate(PRODUCT selProduct) { InitializeComponent(); db = new managementdbEntities(); cbCatagory.ItemsSource = db.CATEGORies.ToList(); txtBarcode.Text = selProduct.BARCODE; txtPName.Text = selProduct.PNAME; txtPrice.Text = selProduct.PRICE.ToString(); txtQty.Text = selProduct.QTY.ToString(); cbCatagory.SelectedItem = db.CATEGORies.Where(x => x.CNAME == selProduct.CATE).Select(x => x).SingleOrDefault(); selectProduct = selProduct; }
private void Button_Click_AddOrder(object sender, RoutedEventArgs e) { oaddform = new OAdd(); oaddform.DatabaseChanged += oadddform_DatabaseChanged; oaddform.ShowDialog(); if (newOrd == null) { return; } var result = newOrd.ToString(); var tokens = newOrd.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(token => token.Trim()) .ToArray(); // BARCODE, QUANTITY, DATE, TOTAL, COUPON db = new managementdbEntities(); // add to transaction data ORDER newOrder = new ORDER(); newOrder.BARCODE = tokens[0]; newOrder.QTY = int.Parse(tokens[1]); newOrder.DATE = DateTime.Parse(tokens[2]); newOrder.TOTAL = int.Parse(tokens[3]); db.ORDERs.Add(newOrder); // modify master data PRODUCT updProduct = db.PRODUCTs.Where(x => x.BARCODE == newOrder.BARCODE).Select(x => x).SingleOrDefault(); if (updProduct != null) { updProduct.QTY = updProduct.QTY - newOrder.QTY; } //db.SaveChanges(); // modify coupon date string couponCode = tokens[4].ToString(); COUPON updCoupon = db.COUPONs.Where(x => x.CODE == couponCode).Select(x => x).SingleOrDefault(); if (updCoupon != null) { updCoupon.AVAILABLE = updCoupon.AVAILABLE - 1; } //db.SaveChanges(); db.SaveChanges(); this.Page_Loaded(sender, e); }
private void Button_Click_AddPro(object sender, RoutedEventArgs e) { paddform = new PAdd(); paddform.DatabaseChanged += paddform_DatabaseChanged; paddform.ShowDialog(); db = new managementdbEntities(); if (newPro == null) { return; } //MessageBox.Show(newPro.ToString()); var result = newPro.ToString(); var tokens = newPro.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(token => token.Trim()) .ToArray(); string barcode = tokens[0].ToString(); PRODUCT newProduct = db.PRODUCTs.Where(x => x.BARCODE == barcode).Select(x => x).FirstOrDefault(); if (newProduct == null) { newProduct = new PRODUCT(); newProduct.BARCODE = tokens[0]; newProduct.PNAME = tokens[1]; newProduct.PRICE = int.Parse(tokens[2]); newProduct.QTY = int.Parse(tokens[3]); newProduct.CATE = tokens[4]; newProduct.PSTATUS = 1; db.PRODUCTs.Add(newProduct); } else if (newProduct.PSTATUS == 0) { newProduct.PNAME = tokens[1]; newProduct.PRICE = int.Parse(tokens[2]); newProduct.QTY = int.Parse(tokens[3]); newProduct.CATE = tokens[4]; newProduct.PSTATUS = 1; } db.SaveChanges(); this.Page_Loaded(sender, e); newPro = null; }
private void BtnCoupon_Click(object sender, RoutedEventArgs e) { db = new managementdbEntities(); string coupon = txtCoupon.Text; validCoupon = db.COUPONs.Where(x => x.CODE == coupon && x.AVAILABLE > 0).Select(x => x).SingleOrDefault(); if (validCoupon == null) { lblCouponError.Content = "This coupon is not valid."; } else { lblCouponError.Content = "Coupon applied, " + validCoupon.VALUE + "% discount."; total -= (int)validCoupon.VALUE / 100.0 * total; lblTotal.Content = total.ToString(); } }
private void Button_Click_Delete(object sender, RoutedEventArgs e) { db = new managementdbEntities(); if (selectedCate == null) { return; } if (selectedCate.CNAME == null) { return; } CATEGORY delEntry = db.CATEGORies.Where(x => x.CNAME == selectedCate.CNAME).Select(x => x).FirstOrDefault(); bool productOfCate = db.PRODUCTs.Where(x => x.CATE == selectedCate.CNAME).Any(); if (productOfCate) { string message = selectedCate.CNAME + " has already contained product(s). Do you still want to delete this category? "; string caption = "Delete Category"; var result = MessageBox.Show(message, caption, MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { delEntry.CSTATUS = 0; db.SaveChanges(); MessageBox.Show("Deleted product"); this.Page_Loaded(sender, e); } else { } } else { delEntry.CSTATUS = 0; db.SaveChanges(); MessageBox.Show("Deleted product"); this.Page_Loaded(sender, e); } selectedCate = null; }
public Stats() { InitializeComponent(); db = new managementdbEntities(); List <PRODUCT> SaleItems = new List <PRODUCT>(); List <ORDER> SaleQty = new List <ORDER>(); productList = db.PRODUCTs.ToList(); orderList = db.ORDERs.ToList(); PRODUCT Item = new PRODUCT(); resultQry = new List <Data>(); salesInPeriod = new List <Data>(); var innerJoinQuery = from order in orderList join prod in productList on order.BARCODE equals prod.BARCODE select new { Item = prod.PNAME, SaleQty = order.QTY }; //this.DataContext = innerJoinQuery; //lvSaleProduct.ItemsSource = innerJoinQuery.ToList(); ///////////////////////////////////////////////////////// //var groupJoinQuery = from prod in productList // join order in orderList on prod.BARCODE equals order.BARCODE into prodGroup // select prodGroup; var groupJoinQuery = from order in orderList join prod in productList on order.BARCODE equals prod.BARCODE group order by order.BARCODE into g select new { Item = g.First().PRODUCT.PNAME, SaleQty = g.Sum(x => x.QTY) }; ////////////////////////////////////////////////////////// this.DataContext = groupJoinQuery; lvSaleProduct.ItemsSource = groupJoinQuery.ToList(); }
private void Page_Loaded(object sender, RoutedEventArgs e) { // Category List db = new managementdbEntities(); db.Configuration.ProxyCreationEnabled = false; db.CATEGORies.ToList(); var filteredCate = db.CATEGORies.Local .Where(x => x.CSTATUS == 1); List <CATEGORY> cATEGORies = filteredCate.ToList(); lvCategory.ItemsSource = cATEGORies; // Product List = status == 1 && cstatus == 1 db.Configuration.ProxyCreationEnabled = false; db.PRODUCTs.ToList(); var filteredProduct = db.PRODUCTs.Local .Where(x => x.PSTATUS == 1); // pstatus = 1 PRODUCT newProduct = new PRODUCT(); List <PRODUCT> pRODUCTs = filteredProduct.ToList(); filteredProduct = from product in pRODUCTs join category in cATEGORies on product.CATE equals category.CNAME select product; lvProduct.ItemsSource = filteredProduct.ToList(); // Order list db.Configuration.ProxyCreationEnabled = false; lvOrder.ItemsSource = db.ORDERs.ToList(); // Category in combobox cbCatagory.ItemsSource = db.CATEGORies.Where(x => x.CSTATUS == 1).ToList(); }
public CAdd() { InitializeComponent(); db = new managementdbEntities(); }
public OAdd() { InitializeComponent(); db = new managementdbEntities(); cbProduct.ItemsSource = db.PRODUCTs.Where(x => x.PSTATUS == 1).ToList(); }