public void InsertSaleHistory(SaleHistory newsale) { using (var dbConn = new SQLiteConnection(App.DB_PATH)) { dbConn.RunInTransaction(() => { dbConn.Insert(newsale); }); } }
/* ProductRateList에 h 추가, 이미 물품이 있으면 개수를 더함 */ private void insertHistory(SaleHistory h, List <ProductRate> ProductRateList) { bool has = false; foreach (ProductRate p in ProductRateList) { if (h.Name.Equals(p.Name)) // 리스트에 물품이 있는 경우 -> 개수 더함 { p.Count += h.Count; has = true; break; } } if (!has) // 리스트에 물품이 없는 경우 -> 새로운 물품 추가 { ProductRateList.Add(new ProductRate(h.Name, h.Count)); } }
public ActionResult AddProductToSale(Sale sale, int Product_id) { sale.StartDate = DateTime.Now; salerepo.Insert(sale); SaleHistory salehis = new SaleHistory(); salehis.Amount = sale.Amount; salehis.StartDate = sale.StartDate; saleHistoryRepo.Insert(salehis); Product x = product.Get(Product_id); x.SaleID = sale.SaleID; product.Update(x); ProductHistory xh = producthis.GetByProductNameCategory(product.Get(Product_id).Product_name, product.Get(Product_id).CategoryID); xh.SaleID = salehis.SaleID; producthis.Update(xh); return(RedirectToAction("Index")); }
public void ChooseSaleHistory() { SaleHistoryDAL saleHistoryDAL = new SaleHistoryDAL(); Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\n"); Console.WriteLine("What action you want to choose?\n" + "1. View all SaleHistories\n" + "2. Get SaleHistories by Id\n" + "3. Get SaleHistories by name of column\n" + "4. Add SaleHistories\n" + "5. Edit info about SaleHistories\n" + "6. Delete SaleHistories by Id\n" + "7. Delete SaleHistories by name of column\n" + "8. Back to start menu"); Console.Write("\nYour selection: "); string ch = Console.ReadLine(); switch (ch) { case "1": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\n"); saleHistoryDAL.PrintListOfSaleHistory(saleHistoryDAL.GetAll()); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "2": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\nId: "); int id = Convert.ToInt32(Console.ReadLine()); saleHistoryDAL.PrintSaleHistory(saleHistoryDAL.GetById(id)); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "3": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\n"); Console.WriteLine("Name of column: "); string fieldName = Console.ReadLine(); Console.WriteLine("\nValue: "); string text = Console.ReadLine(); saleHistoryDAL.PrintListOfSaleHistory(saleHistoryDAL.GetByFieldName(fieldName, text)); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "4": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\n"); Console.WriteLine("COUNT: "); int count = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("DATEORDERED"); string dateTimeOrdered = Console.ReadLine(); Console.WriteLine("DATEDELIVERY"); string dateTimeDelivery = Console.ReadLine(); Console.WriteLine("ID_PRODUCT"); int id_product = Convert.ToInt32(Console.ReadLine()); SaleHistory saleHistory = new SaleHistory(count, dateTimeOrdered, dateTimeDelivery, id_product); saleHistoryDAL.Insert(saleHistory); Console.WriteLine("SaleHistory succesfully inserted."); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "5": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\n"); Console.WriteLine("Name of column (set): "); string fieldName = Console.ReadLine(); Console.WriteLine("Value (set): "); string text = Console.ReadLine(); Console.WriteLine("Name of column (condition): "); string fieldCondition = Console.ReadLine(); Console.WriteLine("Value (condition): "); string textCondition = Console.ReadLine(); saleHistoryDAL.UpdateByFieldName(fieldName, text, fieldCondition, textCondition); Console.WriteLine("SaleHistory succesfully updated."); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "6": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\nId: "); int id = Convert.ToInt32(Console.ReadLine()); saleHistoryDAL.deleteById(id); Console.WriteLine("SaleHistroy succesfully deleted."); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "7": { try { Console.Clear(); Console.WriteLine("TABLE: SALEHISTORY\n\n "); Console.WriteLine("Name of column (condition): "); string fieldCondition = Console.ReadLine(); Console.WriteLine("Value (condition): "); string textCondition = Console.ReadLine(); saleHistoryDAL.deleteByFieldName(fieldCondition, textCondition); Console.WriteLine("SaleHistory succesfully deleted."); Console.ReadKey(); break; } finally { Menu menu = new Menu(); menu.ChooseSaleHistory(); } } case "8": { Menu menu = new Menu(); menu.ChooseTable(); break; } default: Console.WriteLine("Invalid selection. Please select 1, 2, 3, 4, 5, 6, 7 or 8."); break; } }