private void tb_Search_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Down) { int index = lv_SearchFoodItem.SelectedIndex + 1; lv_SearchFoodItem.SelectedIndex = index; return; } if (e.Key == Key.Up) { int index = lv_SearchFoodItem.SelectedIndex - 1; lv_SearchFoodItem.SelectedIndex = index; return; } if (e.Key == Key.Enter) { if (lv_SearchFoodItem.SelectedItem != null) { productsaleorpurchaseviewmodel item = (productsaleorpurchaseviewmodel)lv_SearchFoodItem.SelectedItem; addItem_To_purchase(item); tb_Search.Text = ""; lv_SearchFoodItem.Visibility = Visibility.Hidden; } } }
void addItem_To_purchase(productsaleorpurchaseviewmodel item) { foreach (productsaleorpurchaseviewmodel oldItem in purchaselist) { if (item.id == oldItem.id) { oldItem.quantity += 1; oldItem.total = oldItem.quantity * oldItem.price; dg.Items.Clear(); double totalBill1 = 0; foreach (productsaleorpurchaseviewmodel item1 in purchaselist) { totalBill1 += item1.total; dg.Items.Add(item1); } total_label.Content = totalBill1; return; } } purchaselist.Add(item); dg.Items.Clear(); double totalBill = 0; foreach (productsaleorpurchaseviewmodel item1 in purchaselist) { totalBill += item1.total; dg.Items.Add(item1); } total_label.Content = totalBill; }
public static dynamic mapproducttoproductsalemodel(List <data.dapper.product> products) { var mappedList = new List <productsaleorpurchaseviewmodel>(); foreach (var item in products) { productsaleorpurchaseviewmodel a = new productsaleorpurchaseviewmodel(); a.id = item.id; a.name = item.name; a.quantity = 1; a.price = 0; if (item.saleprice != null) { a.price = (double)item.saleprice; } var discount = 0; if (item.discount != null) { a.price = a.price - discount; } ; a.total = a.price; mappedList.Add(a); } return(mappedList); }
private void removeItemFromCart_btn_click(object sender, RoutedEventArgs e) { productsaleorpurchaseviewmodel obj = ((FrameworkElement)sender).DataContext as productsaleorpurchaseviewmodel; foreach (productsaleorpurchaseviewmodel oldItem in cart) { if (obj.id == oldItem.id) { cart.Remove(obj); refreshCartAndTotal(); break; } } }
void addItem_To_cart(productsaleorpurchaseviewmodel item) { foreach (productsaleorpurchaseviewmodel oldItem in cart) { if (item.id == oldItem.id) { oldItem.quantity += 1; oldItem.total = oldItem.quantity * oldItem.price; refreshCartAndTotal(); return; } } cart.Add(item); refreshCartAndTotal(); }
public static void printDuplicateRecipt(int saleid) { var financetransactionrepo = new financetransactionrepo(); var userrepo = new userrepo(); var productrepo = new productrepo(); var productsalepurchaserepo = new productsalepurchaserepo(); var ft = financetransactionrepo.get(saleid); data.dapper.user customer = null; if (ft.fk_user_targetto_in_financetransaction != null) { customer = userrepo.get((int)ft.fk_user_targetto_in_financetransaction); } // var soldproducts = db.productsalepurchase.Where(a => a.fk_financetransaction_in_productsalepurchase == saleid).ToList(); var soldproducts = productsalepurchaserepo.getmultiplebytransactionid(saleid); float totalbill = 0; var salelist = new List <productsaleorpurchaseviewmodel>(); foreach (var item in soldproducts) { totalbill = totalbill + (float)(item.price * item.quantity); //var dbproduct = db.product.Find(item.fk_product_in_productsalepurchase); var dbproduct = productrepo.get((int)item.fk_product_in_productsalepurchase); var p = new productsaleorpurchaseviewmodel(); p.id = dbproduct.id; p.name = dbproduct.name; p.price = (double)item.price; p.quantity = (double)item.quantity; p.total = (double)item.total; } ; //int salesId, List< ItemOrDealSaleModel > list, int totalBill,int remaining, int saleType,string customerAddress string customerAddress = ""; if (customer != null) { customerAddress = customer.address + " " + customer.phone; } printing.printSaleReceipt(saleid, salelist, (int)totalbill, (int)totalbill, 0, false, customerAddress); }
private async void cart_dg_roweditending(object sender, DataGridRowEditEndingEventArgs e) { productsaleorpurchaseviewmodel item = e.Row.Item as productsaleorpurchaseviewmodel; if (item != null) { foreach (productsaleorpurchaseviewmodel oldItem in cart) { if (item.id == oldItem.id) { oldItem.total = oldItem.quantity * oldItem.price; break; } } await Task.Delay(TimeSpan.FromSeconds(1)); refreshCartAndTotal(); } }
private void btn_RemoveQuantity(object sender, RoutedEventArgs e) { productsaleorpurchaseviewmodel obj = ((FrameworkElement)sender).DataContext as productsaleorpurchaseviewmodel; foreach (productsaleorpurchaseviewmodel oldItem in purchaselist) { if (obj.id == oldItem.id) { if (oldItem.quantity > 1) { oldItem.quantity -= 1; oldItem.total = oldItem.quantity * oldItem.price; dg.Items.Clear(); double totalBill1 = 0; foreach (productsaleorpurchaseviewmodel item1 in purchaselist) { totalBill1 += item1.total; dg.Items.Add(item1); } total_label.Content = totalBill1; return; } else { purchaselist.Remove(obj); dg.Items.Clear(); double totalBill1 = 0; foreach (productsaleorpurchaseviewmodel item1 in purchaselist) { totalBill1 += item1.total; dg.Items.Add(item1); } total_label.Content = totalBill1; return; } } } }
private void btn_AddQuantity(object sender, RoutedEventArgs e) { productsaleorpurchaseviewmodel obj = ((FrameworkElement)sender).DataContext as productsaleorpurchaseviewmodel; addItem_To_purchase(obj); }