//Nút Lưu private void btnSave_Click(object sender, EventArgs e) { //Sinh Ma Khach moi ThongTinThuePhongBUS data = new ThongTinThuePhongBUS(); makhach = data.newID(); //Lay thong tin bang ThongTinKhach ho = txtHo.Text.Trim(); ten = txtTen.Text.Trim(); ngaysinh = dtpNgaySinh.Value; if (cbGioiTinh.SelectedItem.ToString() == "Nam") { gioitinh = "Nam"; } else { gioitinh = "Nữ"; } cmnd = txtCMND.Text.Trim(); quequan = txtQueQuan.Text.Trim(); nghenghiep = txtNgheNghiep.Text.Trim(); maphong = lbMaPhong.Text.Trim(); ghichu = "1"; tiendatcoc = Convert.ToInt32(txtTienDatCoc.Text); //Lay thong tin ThongTinThuePhong string idtttp = new ThongTinThuePhongBUS().newID_tttp().ToString(); string select_maphong = lbMaPhong.Text; DateTime ngaythue = dtpNgayThue.Value; if (MessageBox.Show("Bạn có muốn lưu?", "Mã khách trọ: " + makhach, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //Them vao bang ThongTinKhach KhachThue kt = new KhachThue(makhach, ho, ten, gioitinh, ngaysinh, cmnd, quequan, nghenghiep, maphong, ghichu); string sqlAddKhachInfo = "INSERT INTO ThongTinKhach(MaKhachTro,Ho,Ten,GioiTinh,NgaySinh,CMND,QueQuan,NgheNghiep,MaPhong,GhiChu) VALUES(@makhach,@ho,@ten,@gioitinh,@ngaysinh,@cmnd,@quequan,@nghenghiep,@maphong,@ghichu)"; int j = new KhachThueBUS().Insert(sqlAddKhachInfo, kt); //Them vao bang ThongTinThuePhong ThongTinThue ttp = new ThongTinThue(idtttp, makhach, maphong, ngaythue, tiendatcoc); string sqlinsert = "INSERT INTO ThongTinThuePhong(MaHD, MaKhachTro, MaPhong, NgayThue,TienDatCoc) VALUES(@id, @makhachtro,@maphong,@ngaythue,@tiendatcoc)"; int i = new ThongTinThuePhongBUS().Insert(sqlinsert, ttp); //Cap nhat trang thai phong ThongTinThuePhongBUS update = new ThongTinThuePhongBUS(); string sqlupdate = "UPDATE Phong SET TrangThai=@trangthai WHERE MaPhong='" + select_maphong + "'"; update.Update(sqlupdate); //Refresh Form lvPhong.Items.Clear(); LoadData_ListPhong(); ClearAll(); Load_ListKhach(maphong); MessageBox.Show("Đã thêm thành công!"); } }
private void btnTraPhong_Click(object sender, EventArgs e) { string maphong = lbPhong.Text; ThongTinThuePhongBUS ttt = new ThongTinThuePhongBUS(); //Id int id = new ThongTinThuePhongBUS().newID_traphong(); DateTime ngaythue, ngaytra; string makhach = lbMaKhach.Text; ngaythue = dtNgayThue.Value; ngaytra = dtNgayTraPhong.Value; string str_tdc = string.Format("{0:#,##0}", tiendatcoc); //Them vao bang TraPhong ThongTinThuePhongBUS tttTraphong = new ThongTinThuePhongBUS(); MRDTO.TraPhong tp = new MRDTO.TraPhong(id, makhach, maphong, ngaythue, ngaytra); if (MessageBox.Show("Ngày thuê: " + dtNgayThue.Text.ToString() + "\nTiền đặt cọc: " + str_tdc + " vnd", "Xác nhận trả phòng: " + maphong, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string sqlinsert = "INSERT INTO TraPhong(Id,MaPhong,MaKhachTro,NgayThue,NgayTraPhong) VALUES(@id,@maphong,@makhach,@ngaythue,@ngaytra)"; int insert = tttTraphong.Insert_Tra_phong(sqlinsert, tp); //Xoa ben ThongTinThue var sqlttt = ttt.Delete("DELETE FROM ThongTinThuePhong WHERE MaPhong=@maphong", maphong); //Xoa khach thuoc phong vua tra var xoakhachthue = ttt.Delete("DELETE FROM ThongTinKhach WHERE MaPhong=@maphong", maphong); //Sua trang thai var update = ttt.Update_TraPhong("UPDATE Phong SET TrangThai=@trangthai WHERE MaPhong='" + maphong + "'"); MessageBox.Show("Đã trả phòng"); //Refresh Load_listPhong(); ClearAll(); lvKhach.Items.Clear(); } }
private void load_khach_dau(string id) { KhachThueBUS kt = new KhachThueBUS(); var sqlkt = kt.GetKhachTheoMaPhong("SELECT * FROM ThongTinKhach WHERE MaKhachTro='" + id + "'"); lbHoTen.Text = sqlkt.Rows[0][1] + " " + sqlkt.Rows[0][2]; dtNgaySinh.Text = sqlkt.Rows[0][5].ToString(); lbGioiTinh.Text = sqlkt.Rows[0][3].ToString(); lbCMND.Text = sqlkt.Rows[0][6].ToString(); lbQueQuan.Text = sqlkt.Rows[0][7].ToString(); lbNgheNghiep.Text = sqlkt.Rows[0][8].ToString(); lbMaKhach.Text = sqlkt.Rows[0][0].ToString(); ThongTinThuePhongBUS ttt = new ThongTinThuePhongBUS(); var sqlttt = ttt.GetKhach("SELECT * FROM ThongTinThuePhong WHERE MaKhachTro='" + id + "'"); lbPhong.Text = sqlttt.Rows[0][2].ToString(); dtNgayThue.Text = sqlttt.Rows[0][3].ToString(); tiendatcoc = Convert.ToInt32(sqlttt.Rows[0][4].ToString()); lbTienDatCoc.Text = string.Format("{0:#,##0}", tiendatcoc); }
private void btnSave_Click(object sender, EventArgs e) { try { string ho, ten, gioitinh, cmnd, quequan, nghenghiep, maphong, ghichu, makhach; DateTime ngaysinh; //Sinh Ma Khach moi ThongTinThuePhongBUS data = new ThongTinThuePhongBUS(); makhach = data.newID(); //Lay thong tin bang ThongTinKhach ho = txtHo.Text.Trim(); ten = txtTen.Text.Trim(); ngaysinh = dtpNgaySinh.Value; gioitinh = cbGioiTinh.SelectedItem.ToString(); cmnd = txtCMND.Text.Trim(); quequan = txtQueQuan.Text.Trim(); nghenghiep = txtNgheNghiep.Text.Trim(); maphong = lbMaPhong.Text.Trim(); ghichu = "1"; List <string> tmp = new List <string>(); tmp.Add(ho); tmp.Add(ten); tmp.Add(gioitinh); tmp.Add(nghenghiep); tmp.Add(quequan); tmp.Add(cmnd); tmp.Add(txtTienDatCoc.Text); foreach (string chuoi in tmp) { if (chuoi == "") { kiemtra = 1; } } if (kiemtra == 1) { MessageBox.Show("Quý khách phải nhập đủ thông tin!"); kiemtra = 0; } else { if (MessageBox.Show("Bạn có muốn lưu?", "Mã khách trọ: " + makhach, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { //Them vao bang ThongTinKhach KhachThue kt = new KhachThue(makhach, ho, ten, gioitinh, ngaysinh, cmnd, quequan, nghenghiep, maphong, ghichu); string sqlAddKhachInfo = "INSERT INTO ThongTinKhach(MaKhachTro,Ho,Ten,GioiTinh,NgaySinh,CMND,QueQuan,NgheNghiep,MaPhong,GhiChu) VALUES(@makhach,@ho,@ten,@gioitinh,@ngaysinh,@cmnd,@quequan,@nghenghiep,@maphong,@ghichu)"; int j = new KhachThueBUS().Insert(sqlAddKhachInfo, kt); //Them vao bang ThongTinThuePhong //Lay thong tin string idtttp = new ThongTinThuePhongBUS().newID_tttp().ToString(); string select_maphong = lbMaPhong.Text; DateTime ngaythue = dtpNgayThue.Value; tiendatcoc = Convert.ToInt32(txtTienDatCoc.Text); //INSERT vao bang ThongTinThue ttp = new ThongTinThue(idtttp, makhach, maphong, ngaythue, tiendatcoc); string sqlinsert = "INSERT INTO ThongTinThuePhong(MaHD, MaKhachTro, MaPhong, NgayThue,TienDatCoc) VALUES(@id, @makhachtro,@maphong,@ngaythue,@tiendatcoc)"; int i = new ThongTinThuePhongBUS().Insert(sqlinsert, ttp); //Cap nhat trang thai phong ThongTinThuePhongBUS update = new ThongTinThuePhongBUS(); string sqlupdate = "UPDATE Phong SET TrangThai=@trangthai WHERE MaPhong='" + select_maphong + "'"; update.Update(sqlupdate); //Xoa Khach tu DS Dang Ky ListViewItem item = listKDK.SelectedItems[0]; int id_kdk = Convert.ToInt32(item.Text); string sqlxoa = "DELETE From ThongTinDangKyPhong Where Id=" + id_kdk; int z = new ThongTinDKBUS().XoaKDK(sqlxoa); //Refresh Form lvPhong.Items.Clear(); LoadData_ListPhong(); Load_ListKDK(); MessageBox.Show("Đã thêm thành công!"); } } } catch (FormatException) { } }