public ActionResult BillPayment(FormCollection f) { using (DataContext db = new DataContext()) { Bill bill = new Bill(); bill.customerName = f["txtKhachHang"]; bill.phoneNumber = f["txtSoDienThoai"]; bill.date_set = DateTime.Now; bill.customerAddress = f["txtDiaChi"]; bill.total = Convert.ToInt32(Session["ThanhTien"]); bill.isPayment = false; bill.isDelivered = false; db.Bills.Add(bill); db.SaveChanges(); var bill_id_max = db.Bills.Max(x => x.Bill_ID); foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { DetailBill detailBill = new DetailBill(); detailBill.Bill_ID = bill_id_max; detailBill.Book_ID = item.book_id; detailBill.quantity = item.number; db.DetailBills.Add(detailBill); db.SaveChanges(); } Session["Cart"] = null; } return(View("SuccessView")); }
public ActionResult addCheckout(Customer customer) { var cart = Session[CartSession]; var model = (List <DetailBill>)cart; if (cart != null) { BillF billF = new BillF(); Bill bill = new Bill(); bill.id = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); bill.Date = DateTime.Now; bill.CustomerNameOnline = customer.Name; bill.CustomerAddressOnline = customer.Address; bill.CustomerPhoneOnline = customer.Phone; billF.Insert(bill); foreach (var item in model) { DetailBill detailBill = new DetailBill(); detailBill.BiLLID = bill.id; detailBill.quality = item.quality; detailBill.ProductID = item.ProductID; DetailBillF detailBillF = new DetailBillF(); detailBillF.Insert(detailBill); } return(View("Index")); } return(View("Index")); }
public bool Delete(DetailBill model) { DetailBill dbDetailBill = context.DetailBills.Find(model.BiLLID, model.ProductID); if (dbDetailBill != null) { context.DetailBills.Remove(dbDetailBill); } return(false); }
public List <int> SelectIdDetailBillTrungSize(int price, int idProduct, int idBill) { List <int> idDetailBills = new List <int>(); DataTable data = DataProvider.Instance.ExecuteQuery("select * from detailbill where idProduct = " + idProduct + " and price = " + price + " and idBill = " + idBill); foreach (DataRow item in data.Rows) { DetailBill detailTopping = new DetailBill(item); idDetailBills.Add(detailTopping.IdDeTailBill); } return(idDetailBills); }
public List <int> SelectIdDetailBill(int idBill) { List <int> idDetailBill = new List <int>(); DataTable data = DataProvider.Instance.ExecuteQuery("SELECT * FROM detailbill WHERE idBill = " + idBill); foreach (DataRow item in data.Rows) { DetailBill detail = new DetailBill(item); idDetailBill.Add(detail.IdDeTailBill); } return(idDetailBill); }
public bool Update(DetailBill model) { DetailBill dbDetailBill = context.DetailBills.Find(model.BiLLID, model.ProductID); if (dbDetailBill != null) { dbDetailBill.quality = model.quality; context.SaveChanges(); return(true); } return(false); }
public List <DetailBill> SelectDetailBill(int idBill) { List <DetailBill> details = new List <DetailBill>(); DataTable data = DataProvider.Instance.ExecuteQuery("SELECT * FROM detailbill WHERE idBill ='" + idBill + "'"); foreach (DataRow item in data.Rows) { DetailBill detail = new DetailBill(item); details.Add(detail); } return(details); }
public List <DetailBill> loadDetailBill(int mahd) { List <DetailBill> dbList = new List <DetailBill>(); DataTable data = DataProvider.Instance.ExecuteQuery("EXEC sp_loadDetailBill @MAHD", new object[] { mahd }); foreach (DataRow row in data.Rows) { DetailBill db = new DetailBill(row); dbList.Add(db); } return(dbList); }
static void Main() { Console.OutputEncoding = Encoding.Unicode; Console.InputEncoding = Encoding.Unicode; int n = 0; string outputData = ""; Console.Write("Số lượng hóa đơn muốn nhập: "); try { n = int.Parse(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(0); } SimpleBill[] simpleBill = new SimpleBill[100]; DetailBill[] detailBill = new DetailBill[100]; CustomerClass[] customer = new CustomerClass[100]; for (int i = 0; i < n; i++) { Console.WriteLine("Nhập thông tin hóa đơn: "); simpleBill[i] = new SimpleBill(); simpleBill[i].InputBill(); Console.Write("Thông tin khách hàng số: "); customer[i] = new CustomerClass(); customer[i].InputInfor(); Console.Write("Thông tin chi tiết đơn số: "); detailBill[i] = new DetailBill(); detailBill[i].InputDetailBill(); } FileStream Mbill = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\danh_sach_hoa_don.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter outputBills = new StreamWriter(Mbill); for (int c = 0; c < n; c++) { outputData += simpleBill[c].OutputBill(); outputData += customer[c].OutputInfor(); outputData += detailBill[c].GetData(); } outputBills.WriteLine("========================Bill======================"); outputBills.WriteLine(outputData); outputBills.WriteLine("=================================================="); outputBills.Flush(); Console.WriteLine("File dang_sach_hoa_don.txt da dc xuat ra o desktop"); Console.ReadKey(); }
public bool Insert(DetailBill model) { DetailBill dbDetailBill = context.DetailBills.Find(model.BiLLID, model.ProductID); if (dbDetailBill != null) { return(false); } else { context.DetailBills.Add(model); context.SaveChanges(); return(true); } return(false); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } DetailBill = await _context.DetailBill .Include(d => d.Bill) .Include(d => d.Product).FirstOrDefaultAsync(m => m.DetailBillID == id); if (DetailBill == null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } DetailBill = await _context.DetailBill.FindAsync(id); if (DetailBill != null) { _context.DetailBill.Remove(DetailBill); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } DetailBill = await _context.DetailBill .Include(d => d.Bill) .Include(d => d.Product).FirstOrDefaultAsync(m => m.DetailBillID == id); if (DetailBill == null) { return(NotFound()); } ViewData["BillID"] = new SelectList(_context.Bill, "BillID", "CodeBill"); ViewData["ProductID"] = new SelectList(_context.Set <Product>(), "ProductID", "Code"); return(Page()); }
public ActionResult AddCart(string productID, int quality) { var product = new ProductF().FindProduct(productID); var cart = Session[CartSession]; if (cart != null) { var list = (List <DetailBill>)cart; if (list.Exists(x => x.ProductID == productID)) { foreach (var item in list) { if (item.ProductID == productID) { item.quality += quality; } } } else { var item = new DetailBill(); item.Product = product; item.ProductID = productID; item.quality = quality; list.Add(item); } Session[CartSession] = list; } else { var item = new DetailBill(); item.Product = product; item.ProductID = productID; item.quality = quality; var list = new List <DetailBill>(); list.Add(item); Session[CartSession] = list; } return(Redirect("Index")); }
public ActionResult Bill(BillsPost bi, FormCollection f) { using (DataContext db = new DataContext()) { if (f["payment"] != null) { if (Convert.ToInt32(f["payment"]) == 1) { Bill bills = new Bill(); bills.Customer_ID = SessionCheckingCustomes.customerID; bills.customerName = f["txtKhachHang"]; bills.phoneNumber = f["txtSoDienThoai"]; bills.date_set = DateTime.Now; bills.customerAddress = f["txtDiaChi"]; bills.total = (double?)Session["ThanhTien"]; bills.payment_method = Convert.ToInt32(f["payment"]); bills.payment_status = false; bills.delivered_status = false; db.Bills.Add(bills); db.SaveChanges(); var bill_id_max = db.Bills.Max(x => x.Bill_ID); foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { DetailBill detailBill = new DetailBill(); detailBill.Bill_ID = bill_id_max; detailBill.Book_ID = item.book_id; detailBill.quantity = item.number; db.DetailBills.Add(detailBill); db.SaveChanges(); } foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { Book b = db.Books.Where(x => x.Book_ID == item.book_id).FirstOrDefault(); if (b != null) { if (b.sellNumber == null) { b.sellNumber = item.number; db.SaveChanges(); } else { b.sellNumber = b.sellNumber + item.number; db.SaveChanges(); } } } foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { int? quantityExist = 0; var quantity = (from bo in db.Books where bo.Book_ID == item.book_id select new { bo.quantityExists }).ToList(); Book b = db.Books.Where(x => x.Book_ID == item.book_id).FirstOrDefault(); foreach (var sl in quantity) { quantityExist = (sl.quantityExists - item.number); } b.quantityExists = quantityExist; db.SaveChanges(); } Session["Cart"] = null; return(RedirectToAction("SuccessView")); } else { Bill bills = new Bill(); bills.Customer_ID = SessionCheckingCustomes.customerID; bills.customerName = f["txtKhachHang"]; bills.phoneNumber = f["txtSoDienThoai"]; bills.date_set = DateTime.Now; bills.customerAddress = f["txtDiaChi"]; bills.total = (double?)Session["ThanhTien"]; bills.payment_method = Convert.ToInt32(f["payment"]); bills.payment_status = false; bills.delivered_status = false; db.Bills.Add(bills); db.SaveChanges(); var bill_id_max = db.Bills.Max(x => x.Bill_ID); foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { DetailBill detailBill = new DetailBill(); detailBill.Bill_ID = bill_id_max; detailBill.Book_ID = item.book_id; detailBill.quantity = item.number; db.DetailBills.Add(detailBill); db.SaveChanges(); } foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { int? quantityExist = 0; var quantity = (from bo in db.Books where bo.Book_ID == item.book_id select new { bo.quantityExists }).ToList(); Book b = db.Books.Where(x => x.Book_ID == item.book_id).FirstOrDefault(); foreach (var sl in quantity) { quantityExist = (sl.quantityExists - item.number); } b.quantityExists = quantityExist; db.SaveChanges(); } return(RedirectToAction("PaymentWithPaypal")); } } else { return(Json(new { _mess__ = 0 })); } } }
private void bbiDetail_ItemClick(object sender, ItemClickEventArgs e) { DataGridView grvPrint = new DataGridView(); DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Name", typeof(string))); dt.Columns.Add(new DataColumn("Price", typeof(int))); dt.Columns.Add(new DataColumn("Quantity", typeof(int))); using (var db = new PetStoreEntities()) { var list = db.BillDetails.Where(x => x.b_id == selectedID); PetModel pm = new PetModel(); PetFoodModel pfm = new PetFoodModel(); PetMedicineModel pmm = new PetMedicineModel(); PetToyModel ptm = new PetToyModel(); PetAccessoryModel pam = new PetAccessoryModel(); int d = 0; while (d != list.Count()) { var bd = list.ToList()[d]; if (bd.p_id != null) { var p = pm.getPet(bd.p_id); var qty = list.Where(x => x.p_id == bd.p_id).Count(); dt.Rows.Add(p.p_name, p.p_salePrice, qty); d += qty; } else if (bd.pt_id != null) { var pt = ptm.getPetToy(bd.pt_id); var qty = list.Where(x => x.pt_id == bd.pt_id).Count(); dt.Rows.Add(pt.pt_name, pt.pt_salePrice, qty); d += qty; } else if (bd.pf_id != null) { var pf = pfm.getPetFood(bd.pf_id); var qty = list.Where(x => x.pf_id == bd.pf_id).Count(); dt.Rows.Add(pf.pf_name, pf.pf_salePrice, qty); d += qty; } else if (bd.pm_id != null) { var pmd = pmm.getPetMedicine(bd.pm_id); var qty = list.Where(x => x.pm_id == bd.pm_id).Count(); dt.Rows.Add(pmd.pm_name, pmd.pm_salePrice, qty); d += qty; } else if (bd.pa_id != null) { var pa = pam.getPetAccessory(bd.pa_id); var qty = list.Where(x => x.pa_id == bd.pa_id).Count(); dt.Rows.Add(pa.pa_name, pa.pa_salePrice, qty); d += qty; } } } DetailBill dbf = new DetailBill(); dbf.grvDetail.DataSource = dt; dbf.ShowDialog(this); }
public ActionResult PaymentWithPaypal(FormCollection f, string Cancel = null) { //getting the apiContext APIContext apiContext = PaypalConfiguration.GetAPIContext(); try { //A resource representing a Payer that funds a payment Payment Method as paypal //Payer Id will be returned when payment proceeds or click to pay string payerId = Request.Params["PayerID"]; if (string.IsNullOrEmpty(payerId)) { //this section will be executed first because PayerID doesn't exist //it is returned by the create function call of the payment class // Creating a payment // baseURL is the url on which paypal sendsback the data. string baseURI = Request.Url.Scheme + "://" + Request.Url.Authority + "/Home/PaymentWithPayPal?"; //here we are generating guid for storing the paymentID received in session //which will be used in the payment execution var guid = Convert.ToString((new Random()).Next(100000)); //CreatePayment function gives us the payment approval url //on which payer is redirected for paypal account payment var createdPayment = this.CreatePayment(apiContext, baseURI + "guid=" + guid); //get links returned from paypal in response to Create function call var links = createdPayment.links.GetEnumerator(); string paypalRedirectUrl = null; while (links.MoveNext()) { Links lnk = links.Current; if (lnk.rel.ToLower().Trim().Equals("approval_url")) { //saving the payapalredirect URL to which user will be redirected for payment paypalRedirectUrl = lnk.href; } } // saving the paymentID in the key guid Session.Add(guid, createdPayment.id); using (DataContext db = new DataContext()) { Bill bill = new Bill(); bill.customerName = f["txtKhachHang"]; bill.phoneNumber = f["txtSoDienThoai"]; bill.date_set = DateTime.Now; bill.customerAddress = f["txtDiaChi"]; bill.total = Convert.ToInt32(Session["ThanhTien"]); bill.isPayment = true; bill.isDelivered = false; db.Bills.Add(bill); db.SaveChanges(); var bill_id_max = db.Bills.Max(x => x.Bill_ID); foreach (var item in (List <Cart_ViewModels>)Session["Cart"]) { DetailBill detailBill = new DetailBill(); detailBill.Bill_ID = bill_id_max; detailBill.Book_ID = item.book_id; detailBill.quantity = item.number; db.DetailBills.Add(detailBill); db.SaveChanges(); } Session["Cart"] = null; } return(Redirect(paypalRedirectUrl)); } else { // This function exectues after receving all parameters for the payment var guid = Request.Params["guid"]; var executedPayment = ExecutePayment(apiContext, payerId, Session[guid] as string); //If executed payment failed then we will show payment failure message to user if (executedPayment.state.ToLower() != "approved") { return(View("FailureView")); } } } catch (Exception ex) { return(View("FailureView")); } //on successful payment, show success page to user. return(View("SuccessView")); }