//Thanh toán bill private void btn_ThanhToan_Click(object sender, EventArgs e) { /* * Bill hiện tại không có (-1) * bill thanh toán rồi --> không làm gì hết * bill chưa thành toán bắt đầu thanh toán -- > hỏi trước khi thanh toán */ //lấy ra cái bàn hiện tại CBanAn tbf = lv_HoaDon.Tag as CBanAn; if (tbf == null) { return; } if (tbf.TinhTrangBan == 0) { return; } //lấy idbill int idBill = BillDAO.Instance.iDBill(tbf.IDBanAn); int tongtien = Int32.Parse(txt_TongTien.Text.ToString()); int giamgia = (int)nbr_GiamGia.Value; if (idBill != -1)//tồn tại cái bill { if (MessageBox.Show("Bạn có muốn thanh toán cho bàn " + tbf.TenBanAn, "Thông báo", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { BillDAO.Instance.payBill(idBill, tongtien, giamgia); showBill(tbf.IDBanAn); loadTableFood(); } } }
//hàm load Danh sách bàn public List <CBanAn> loadListTableFood() { List <CBanAn> listTableFood = new List <CBanAn>(); DataTable data = DataProviderDAO.Provider.ExcuteQuery("SELECT * FROM dbo.BanAn"); foreach (DataRow item in data.Rows) { CBanAn tableFood = new CBanAn(item); listTableFood.Add(tableFood); } return(listTableFood); }
//thêm món ăn vào bill private void btn_ThemMonAn_Click(object sender, EventArgs e) { //lấy ra cái table hiện tại CBanAn tbf = lv_HoaDon.Tag as CBanAn; if (tbf == null) { return; } //lấy cái idFood if (cb_MonAn.Text == "") { return; } int idFood = (cb_MonAn.SelectedItem as CMonAn).IDMonAn; //lấy số lượng int count = (int)nbr_SoLuongMon.Value; //lấy ra cái idbill int idBill = BillDAO.Instance.iDBill(tbf.IDBanAn); if (idBill == -1)//chưa có cái bill nào { //thêm bill mới BillDAO.Instance.insertBill(tbf.IDBanAn, 1);///////// chưa Bk thằng NHÂN VIÊN NÀO nên cho là 1 để DEMO //lấy ra cái IdBill vừa mới thêm vào int idNewBill; try { string query = " SELECT Max(dbo.Bill.IDBill) FROM dbo.Bill "; idNewBill = (int)DataProviderDAO.Provider.ExcuteScalar(query); } catch { idNewBill = -1; } BillInfoDAO.Instance.insertBillInfo(idNewBill, idFood, count); //load lại bàn loadTableFood(); loadBanTrong(); } else //bill đã tồn tại { BillInfoDAO.Instance.insertBillInfo(idBill, idFood, count); } showBill(tbf.IDBanAn); }