private void ItemsDG_SelectionChanged(object sender, SelectionChangedEventArgs e) { //get reference to object selected ItemTbl selectedItem = ItemsDG.SelectedItem as ItemTbl; //check not null if (selectedItem != null) { //display tbxBName.Text = selectedItem.ItName; tbxprice.Text = selectedItem.ItPrice.ToString(); tbxqty.Text = selectedItem.ItQty.ToString(); } }
//Save btn private void btnsave_Click(object sender, RoutedEventArgs e) { ItemTbl t = new ItemTbl() //items tbl { ItName = tbxBName.Text, //Name enter by the user ItCat = cbxcatrgy.Text, //Catagery enter by the user ItType = cbxtypes.Text, //Type enter by the user ItPrice = int.Parse(tbxprice.Text), //Price enter by the user ItQty = int.Parse(tbxquantity.Text) //Quntity enter by the user }; db.ItemTbls.Add(t); db.SaveChanges(); ShowItems(ItemsDG); //show items enter by user in Product list box }
//add to bill btn private void btnaddbil_Click(object sender, RoutedEventArgs e) { //get details CustomerTbl selectedCustomer = CustomersDg.SelectedItem as CustomerTbl; ItemTbl selectedItem = ItemsDG.SelectedItem as ItemTbl; if (selectedCustomer != null && selectedItem != null) { if (currentBasket == null) { currentBasket = new Basket(); currentBasket.Customer = selectedCustomer; } //add to basket currentBasket.ItemsToPurchase.Add(selectedItem); //update text with total tbxtotal.Text = string.Format("{0:C}", currentBasket.GetTotalInBasket()); //update display BillDG.ItemsSource = null; BillDG.ItemsSource = currentBasket.ItemsToPurchase; } //add to basket //update display //update db //int Grdtotal = 0; //BillTbl b = new BillTbl()//billtbl //{ // CustId=int.Parse(tbxCID.Text), // CustName= tbxCName1.Text, // Amount=int.Parse(tbxprice.Text), // }; //db.BillTbls.Add(b); //Grdtotal = Grdtotal + b.Amount; //tbxtotal.Text = "£" + Grdtotal; //db.SaveChanges(); //ShowItems(BillDG); }