public ThanhToan(string soPhong) { InitializeComponent(); if (SQLConnection.isExist("PhieuDatPhong", "IDPhong", soPhong)) { FillData(soPhong); } }
void LoadData() { string date = dtpThang.Value.ToString("MM/yyyy"); try { int sum = 0; string where = "ThoiGian LIKE '" + date + "'"; DataTable dt = SQLConnection.SelectWhere("*", "DOANHTHU_Thang", where); lvThongKe.Items.Clear(); foreach (DataRow dr in dt.Rows) { string _ID_DTNgay = dr["ID_DTNGay"].ToString(); int tongPhong = 0; int tongDV = 0; int tongCong = 0; string wherePDP = ""; string whereNgay = "ID_DTNGay = " + _ID_DTNgay; DataTable dtNgay = SQLConnection.SelectWhere("*", "DOANHTHU_Ngay", whereNgay); foreach (DataRow drN in dtNgay.Rows) { wherePDP = "IDPhieuDatPhong = " + drN["IDPhieuDatPhong"].ToString(); int tienPhong = int.Parse(SQLConnection.SelectOne("TongCong", "PhieuDatPhong", wherePDP)) + int.Parse(SQLConnection.SelectOne("PhiDoiPhong", "PhieuDatPhong", wherePDP)); int tienDV = int.Parse(SQLConnection.SelectOne("Phi_MonAn", "PhieuDatPhong", wherePDP)) + int.Parse(SQLConnection.SelectOne("Phi_DichVu", "PhieuDatPhong", wherePDP)); int valCoupon; if (SQLConnection.isExist("MaGiamGia", "IDMaGiamGia", SQLConnection.SelectOne("IDMaGiamGia", "PhieuDatPhong", wherePDP))) { valCoupon = int.Parse(SQLConnection.SelectOne("HieuQua", "MaGiamGia", "IDMaGiamGia = N'" + dr["IDMaGiamGia"].ToString() + "'")); } else { valCoupon = 0; } int discount = (tienPhong + tienDV) * valCoupon / 100; int tongTien = tienDV + tienPhong - discount; tongPhong += tienPhong; tongDV += tienDV; tongCong += tongTien; sum += tongCong; } ListViewItem i = new ListViewItem(SQLConnection.SelectOne("ThoiGian", "DOANHTHU_Ngay", whereNgay)); i.SubItems.Add(tongPhong.ToString()); i.SubItems.Add(tongDV.ToString()); i.SubItems.Add(tongCong.ToString()); lvThongKe.Items.Add(i); } lblTongCong.Text = "Tổng cộng: " + sum; } catch { } }
private void btnDatPhong_Click(object sender, EventArgs e) { try { string _IDKhachHang = cbCMND.SelectedIndex == 0 ? tbCMND.Text : cbCMND.SelectedValue.ToString(); bool selectedCB = cbCMND.SelectedIndex == 0 ? true : SQLConnection.isExist("KhachHang", "CMND", cbCMND.Text); if (selectedCB && tbCMND.Text.All(char.IsDigit) && tbSDT.Text.All(char.IsDigit) && tbDatCoc.Text.All(char.IsDigit) && tbSLNguoi.Text.All(char.IsDigit)) { if ((tbCMND.Text.Equals(string.Empty) || tbName.Text.Equals(string.Empty)) && cbCMND.SelectedIndex == 0) { MessageBox.Show("Hãy kiểm tra lại các trường vừa nhập\n\nError: Thiếu thông tin", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string _IDPhong = cbSoPhong.Text; string _IDMaGiamGia = cbCoupon.SelectedIndex == 0 ? "NULL" : cbCoupon.Text; string _IDPhieuDatPhong = SQLConnection.IncrID("PhieuDatPhong", "IDPhieuDatPhong").ToString(); //Insert Khách Hàng if (cbCMND.SelectedIndex == 0) { string loaiKH = cbType.SelectedIndex == 0 ? "0" : "1"; string insCol_KH = "IDKhachHang, TenKhachHang, CMND, SDT, Mail, LoaiKhachHang, IDPhieuDatPhong"; string insVal_KH = "'" + _IDKhachHang + "', N'" + tbName.Text + "', '" + tbCMND.Text + "', '" + tbSDT.Text + "', N'" + tbEmail.Text + "', " + loaiKH + ", " + _IDPhieuDatPhong; SQLConnection.Insert("KhachHang", insCol_KH, insVal_KH); } //Insert Phiếu đặt phòng string insCol_PDP = "IDPhong, IDKhachHang, SLNguoi, NgayDen, SoTienCoc, IDMaGiamGia, NgayDi, TongCong, IDPhieuDatPhong, PhiDoiPhong, Phi_DichVu, Phi_MonAn, SoLanDoiPhong, DaThanhToan"; string insVal_PDP = "'" + _IDPhong + "', " + "'" + _IDKhachHang + "', " + "" + tbSLNguoi.Text + ", '" + DateTime.Now.ToString() + "', " + tbDatCoc.Text + ", " + "'" + _IDMaGiamGia + "', '" + dtpNgayDi.Value.ToString() + "', " + lblTongTien.Text + ", " + _IDPhieuDatPhong + ", 0, 0, 0, 0, 0"; SQLConnection.Insert("PhieuDatPhong", insCol_PDP, insVal_PDP); if (cbCMND.SelectedIndex != 0) { SQLConnection.Update("KhachHang", "IDPhieuDatPhong = " + _IDPhieuDatPhong, "IDKhachHang = " + _IDKhachHang); } string updateVal = "TinhTrang = 1"; string updateWhere = "IDPhong LIKE '" + _IDPhong + "'"; SQLConnection.Update("Phong", updateVal, updateWhere); MessageBox.Show("Thành Công!", "Đặt phòng", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show("Hãy kiểm tra lại các trường vừa nhập\n\nError: Sai định dạng", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Hãy kiểm tra lại các trường vừa nhập\n\nError: " + ex.Message, "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void FillData(string soPhong) { soPhongDat = soPhong; string where = "IDPHONG LIKE '" + soPhong + "'"; DataTable dt = SQLConnection.SelectWhere("*", "PhieuDatPhong", where); DataRow dr = dt.Rows[0]; GetData_KH(dr["IDKhachHang"].ToString()); _IDKhachHang = dr["IDKhachHang"].ToString(); lblSoPhong.Text = "Số phòng: " + dr["IDPhong"].ToString(); lblNgayDi.Text = "Ngày đi: " + dr["NgayDi"].ToString(); lblNgayDen.Text = "Ngày đến: " + dr["NgayDen"].ToString(); lblTienPhong.Text = "Tổng tiền phòng: " + dr["TongCong"].ToString(); if (int.Parse(dr["PhiDoiPhong"].ToString()) > 0) { lblTienPhong.Text += " + " + dr["PhiDoiPhong"].ToString(); } tongCong += int.Parse(dr["TongCong"].ToString()) + int.Parse(dr["PhiDoiPhong"].ToString()); lblTienService.Text = "Tổng tiền dịch vụ: " + dr["Phi_DichVu"].ToString(); tongCong += int.Parse(dr["Phi_DichVu"].ToString()); lblTienFood.Text = "Tổng tiền món ăn: " + dr["Phi_MonAn"].ToString(); tongCong += int.Parse(dr["Phi_MonAn"].ToString()); doanhthu += tongCong; lblDatCoc.Text = "Đặt cọc: " + dr["SoTienCoc"].ToString(); giamGia += int.Parse(dr["SoTienCoc"].ToString()); int valCoupon; if (SQLConnection.isExist("MaGiamGia", "IDMaGiamGia", dr["IDMaGiamGia"].ToString())) { valCoupon = int.Parse(SQLConnection.SelectOne("HieuQua", "MaGiamGia", "IDMaGiamGia = N'" + dr["IDMaGiamGia"].ToString() + "'")); } else { valCoupon = 0; } int discount = tongCong * valCoupon / 100; lblGiamGia.Text = "Giảm giá: " + discount.ToString(); giamGia += discount; lblThanhTien.Text = (tongCong - giamGia).ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("de")); doanhthu -= discount; _IDPhieuDatPhong = dr["IDPhieuDatPhong"].ToString(); GetData_PV(dr["IDPhieuDatPhong"].ToString()); }
void LoadData() { string date = dtpNgay.Value.ToString("MM/dd/yyyy"); try { int sum = 0; string where = "ThoiGian = '" + date + "'"; DataTable dt = SQLConnection.SelectWhere("*", "DOANHTHU_NGAY", where); lvThongKe.Items.Clear(); foreach (DataRow dr in dt.Rows) { string _IDPhieuDatPhong = dr["IDPhieuDatPhong"].ToString(); string wherePDP = "IDPhieuDatPhong = " + _IDPhieuDatPhong; string idPhong = SQLConnection.SelectOne("IDPhong", "PhieuDatPhong", wherePDP); string ngayDen = SQLConnection.SelectOne("NgayDen", "PhieuDatPhong", wherePDP); int tienPhong = int.Parse(SQLConnection.SelectOne("TongCong", "PhieuDatPhong", wherePDP)) + int.Parse(SQLConnection.SelectOne("PhiDoiPhong", "PhieuDatPhong", wherePDP)); int tienDV = int.Parse(SQLConnection.SelectOne("Phi_MonAn", "PhieuDatPhong", wherePDP)) + int.Parse(SQLConnection.SelectOne("Phi_DichVu", "PhieuDatPhong", wherePDP)); int valCoupon; if (SQLConnection.isExist("MaGiamGia", "IDMaGiamGia", SQLConnection.SelectOne("IDMaGiamGia", "PhieuDatPhong", wherePDP))) { valCoupon = int.Parse(SQLConnection.SelectOne("HieuQua", "MaGiamGia", "IDMaGiamGia = N'" + dr["IDMaGiamGia"].ToString() + "'")); } else { valCoupon = 0; } int discount = (tienPhong + tienDV) * valCoupon / 100; int tongCong = tienDV + tienPhong - discount; sum += tongCong; ListViewItem i = new ListViewItem(idPhong); i.SubItems.Add(ngayDen); i.SubItems.Add(tienPhong.ToString()); i.SubItems.Add(tienDV.ToString()); i.SubItems.Add(tongCong.ToString()); lvThongKe.Items.Add(i); } lblTongCong.Text = "Tổng cộng: " + sum; } catch { } }
void LoadData() { try { int sum = 0; string where = "DaThanhToan = 0"; DataTable dt = SQLConnection.SelectWhere("*", "PhieuDatPhong", where); lvThongKe.Items.Clear(); foreach (DataRow dr in dt.Rows) { string _IDPhieuDatPhong = dr["IDPhieuDatPhong"].ToString(); string wherePDP = "IDPhieuDatPhong = " + _IDPhieuDatPhong; string tenKH = SQLConnection.SelectOne("TenKhachHang", "KhachHang", wherePDP); int tienPhong = int.Parse(dr["TongCong"].ToString()) + int.Parse(dr["PhiDoiPhong"].ToString()); int tienDV = int.Parse(dr["Phi_DichVu"].ToString()) + int.Parse(dr["Phi_MonAn"].ToString()); int valCoupon; if (SQLConnection.isExist("MaGiamGia", "IDMaGiamGia", SQLConnection.SelectOne("IDMaGiamGia", "PhieuDatPhong", wherePDP))) { valCoupon = int.Parse(SQLConnection.SelectOne("HieuQua", "MaGiamGia", "IDMaGiamGia = N'" + dr["IDMaGiamGia"].ToString() + "'")); } else { valCoupon = 0; } int discount = (tienPhong + tienDV) * valCoupon / 100; int tongCong = (tienDV + tienPhong - discount) - int.Parse(dr["SoTienCoc"].ToString()); sum += tongCong; ListViewItem i = new ListViewItem(dr["NgayDi"].ToString()); i.SubItems.Add(dr["IDPhong"].ToString()); i.SubItems.Add(tenKH); i.SubItems.Add(dr["SoTienCoc"].ToString()); i.SubItems.Add(tongCong.ToString()); lvThongKe.Items.Add(i); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }