void CreateDTThang() { string dateDTNgay = Convert.ToDateTime(SQLConnection.SelectOne("ThoiGian", "DoanhThu_Ngay", "IDPhieuDatPhong = " + _IDPhieuDatPhong)) .ToString("MM/yyyy"); string _ID_DTNgay = SQLConnection.SelectOne("ID_DTNgay", "DoanhThu_Ngay", "IDPhieuDatPhong = " + _IDPhieuDatPhong); SqlConnection con = SQLConnection.GetConnection(); using (con) { con.Open(); SqlCommand sqlCommand = new SqlCommand("SELECT COUNT(*) FROM DoanhThu_Thang WHERE ThoiGian LIKE '" + dateDTNgay + "'", con); int result = int.Parse(sqlCommand.ExecuteScalar().ToString()); if (result == 0) { int id = SQLConnection.IncrID("DoanhThu_Thang", "ID_DTThang"); string insCol = "ID_DTThang, ThoiGian, ID_DTNgay"; string insVal = id + ", '" + dateDTNgay + "', " + _ID_DTNgay; SQLConnection.Insert("DoanhThu_Thang", insCol, insVal); } else { sqlCommand = new SqlCommand("SELECT COUNT(*) FROM DoanhThu_Thang WHERE ID_DTNgay = " + _ID_DTNgay, con); result = int.Parse(sqlCommand.ExecuteScalar().ToString()); if (result == 0) { int id = int.Parse(SQLConnection.SelectOne("ID_DTThang", "DoanhThu_Thang", "ThoiGian LIKE '" + dateDTNgay + "'")); string insCol = "ID_DTThang, ThoiGian, ID_DTNgay"; string insVal = id + ", '" + dateDTNgay + "', " + _ID_DTNgay; SQLConnection.Insert("DoanhThu_Thang", insCol, insVal); } } } }
void InsertDTNgay() { string ngayDi = Convert.ToDateTime(SQLConnection.SelectOne("NgayDi", "PhieuDatPhong", "IDPhieuDatPhong = " + _IDPhieuDatPhong)) .ToString("MM/dd/yyyy"); SqlConnection con = SQLConnection.GetConnection(); using (con) { con.Open(); SqlCommand sqlCommand = new SqlCommand("SELECT COUNT(*) FROM DoanhThu_Ngay WHERE ThoiGian = '" + ngayDi + "'", con); int result = int.Parse(sqlCommand.ExecuteScalar().ToString()); int id; if (result == 0) { id = SQLConnection.IncrID("DoanhThu_Ngay", "ID_DTNgay"); } else { id = int.Parse(SQLConnection.SelectOne("ID_DTNgay", "DoanhThu_Ngay", "ThoiGian = '" + ngayDi + "'")); } string insCol = "ID_DTNgay, ThoiGian, IDPhieuDatPhong"; string insVal = id + ", '" + ngayDi + "', " + _IDPhieuDatPhong; SQLConnection.Insert("DoanhThu_Ngay", insCol, insVal); } }
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); } }