public List <eBillDetail> getAllBillDetail(int i) { var listBD = (from b in db.ct_hoaDons join t in db.thuocs on b.maThuoc equals t.maThuoc where b.maHD == i select new { t.tenThuoc, b.soLuong, b.donGia, b.maHD } ).ToList(); List <eBillDetail> ls = new List <eBillDetail>(); foreach (var m in listBD) { eBillDetail e = new eBillDetail(); e.BillID = m.maHD.ToString(); e.MedicineID = m.tenThuoc; e.Price = (double)m.donGia; e.Quantity = (int)m.soLuong; ls.Add(e); } return(ls); }
//NÚT THANH TOÁN private void btnPay_Click(object sender, EventArgs e) { eBill or = new eBill(); or.OrderDate = DateTime.Now; or.CustomerID = txtCusID.Text; or.EmployeeID = empID; int orderID = bB.insertOrders(or); List <eBillDetail> listBill = new List <eBillDetail>(); //Thêm chi tiết vào hóa đơn đã tạo for (int i = 0; i < lstvBill.Items.Count; i++) { eBillDetail ord = new eBillDetail(); ord.BillID = orderID.ToString(); ord.MedicineID = this.lstvBill.Items[i].SubItems[0].Text; ord.Quantity = int.Parse(this.lstvBill.Items[i].SubItems[2].Text); ord.Price = double.Parse(this.lstvBill.Items[i].SubItems[3].Text); ord.Discount = 0.1; listBill.Add(ord); } bBD.insertOrderDetail(listBill); MessageBox.Show("Thêm hóa đơn mới thành công !", "Thêm HĐ", MessageBoxButtons.OK, MessageBoxIcon.Information); lstvBill.Clear(); InsertColumnsListView(); btnCancelBill.Enabled = false; btnPay.Enabled = false; txtTotalMoney.Text = "0"; }