private void btnXacnhanThanhtoan_Click(object sender, EventArgs e) { int phonghatID = (int)dgvPhonghat.CurrentRow.Cells["ID"].Value; Hoadon hoadon = db.Hoadons.Where(x => x.PhonghatID == phonghatID).OrderByDescending(x => x.ID).FirstOrDefault(); Phonghat phonghat = db.Phonghats.FirstOrDefault(x => x.ID == phonghatID); var tienphong = Convert.ToInt32(txtTienphong.Text); hoadon.Tienphong = tienphong; var tiendoan = 0; foreach (var cthd in hoadon.ChitietHoadons) { var soluong = cthd.Soluong; var dongia = cthd.Product.Dongia; var sotienphaitra = Convert.ToInt32(soluong * dongia); tiendoan += sotienphaitra; } hoadon.Thanhtien = tiendoan + tienphong; phonghat.IsReserved = false; phonghat.Trangthai = true; showGroupThanhtoan(false); db.SaveChanges(); reload(); reportHoadonThanhtoan.hoadonID = hoadon.ID; reportHoadonThanhtoan rp = new reportHoadonThanhtoan(); rp.Show(); }
private void dgvPhonghat_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { int row = e.RowIndex; int col = e.ColumnIndex; if (row > -1) { if (col == 3) { if (!(bool)dgvPhonghat["Trangthai", row].Value) { if ((bool)dgvPhonghat["IsReserved", row].Value) { e.Value = "Đã đặt trước"; if (dgvPhonghat["IsReserverdBy", row].Value != null) { int khachhangid = (int)dgvPhonghat["IsReserverdBy", row].Value; KhachHang khachHang = db.KhachHangs.FirstOrDefault(x => x.ID == khachhangid); dgvPhonghat[7, row].Value = "Đặt trước bởi " + khachHang.HoTen + ". SĐT: " + khachHang.SDT; } } else { e.Value = "Đang sử dụng"; int phonghatID = (int)dgvPhonghat["ID", row].Value; Hoadon hoadon = db.Hoadons.Where(x => x.PhonghatID == phonghatID).OrderByDescending(x => x.ID).FirstOrDefault(); if (hoadon != null) { dgvPhonghat[7, row].Value = "Bắt đầu lúc " + hoadon.ThoigianBatdau; if ((bool)hoadon.LoaiPhong) { dgvPhonghat["LoaiPhong", row].Value = "Theo giờ"; } else { dgvPhonghat["LoaiPhong", row].Value = "Theo bài hát"; } } } } else { e.Value = "Phòng trống"; } } } }
private void btnXacnhan_Click(object sender, EventArgs e) { cbbKhachhang.Visible = false; btnChon.Visible = false; label2.Visible = false; lbLoaiphong.Visible = false; cbbLoaiphong.Visible = false; int khachhangID = (int)cbbKhachhang.SelectedValue; int phongID = (int)dgvPhonghat.CurrentRow.Cells["ID"].Value; //Dat truoc if (button1.Enabled == false) { button1.Enabled = true; Phonghat phonghat = db.Phonghats.FirstOrDefault(x => x.ID == phongID); phonghat.IsReserved = true; phonghat.IsReserverdBy = khachhangID; phonghat.Trangthai = false; db.SaveChanges(); reload(); } //sudung if (button2.Enabled == false) { Hoadon hoadon = new Hoadon(); hoadon.NhanvienID = nhanvienID; hoadon.KhachhangID = khachhangID; hoadon.PhonghatID = phongID; hoadon.LoaiPhong = Convert.ToBoolean(cbbLoaiphong.SelectedIndex); hoadon.ThoigianBatdau = DateTime.Now; Phonghat phonghat = db.Phonghats.FirstOrDefault(x => x.ID == phongID); phonghat.Trangthai = false; phonghat.IsReserved = false; phonghat.IsReserverdBy = null; db.Hoadons.Add(hoadon); db.SaveChanges(); reload(); button2.Enabled = true; } }
private void btnXacnhanOrder_Click(object sender, EventArgs e) { showGroupOrder(false); int phonghatID = (int)dgvPhonghat.CurrentRow.Cells["ID"].Value; Hoadon hoadon = db.Hoadons.Where(x => x.PhonghatID == phonghatID).OrderByDescending(x => x.ID).FirstOrDefault(); ChitietHoadon chitietHoadon = new ChitietHoadon(); chitietHoadon.HoadonID = hoadon.ID; chitietHoadon.ProductID = (int)cbbProduct.SelectedValue; chitietHoadon.Soluong = Convert.ToInt32(txtSoluong.Text); db.ChitietHoadons.Add(chitietHoadon); db.SaveChanges(); MessageBox.Show("Thêm món thành công", "Thông báo", MessageBoxButtons.OK); }
private void btnThanhtoan_Click(object sender, EventArgs e) { int phonghatID = (int)dgvPhonghat.CurrentRow.Cells["ID"].Value; Hoadon hoadon = db.Hoadons.Where(x => x.PhonghatID == phonghatID).OrderByDescending(x => x.ID).FirstOrDefault(); Phonghat phonghat = db.Phonghats.FirstOrDefault(x => x.ID == phonghatID); showGroupThanhtoan(true); //thanh toán double tienphong = 0; if ((bool)hoadon.LoaiPhong) { var hours = (DateTime.Now - hoadon.ThoigianBatdau).Value.TotalHours; tienphong = (double)phonghat.Dongia * hours; txtTienphong.Text = Convert.ToInt32((Math.Round(tienphong / 1000) * 1000)).ToString(); } }