private void btnGui_Click(object sender, EventArgs e) { try { string ho, ten, cmnd, quequan, nghenghiep, makhuvuc; DateTime ngaysinh; ThongTinDKBUS ttdk = new ThongTinDKBUS(); string sql = "SELECT * FROM ThongTinDangKyPhong"; var table = ttdk.GetThongTinDK(sql); table.PrimaryKey = new DataColumn[] { table.Columns["Id"] }; int id, k; for (k = 1; k <= table.Rows.Count; k++) { if (table.Rows.Find(k) == null) { break; } } id = k; ho = txtHo.Text; ten = txtTen.Text; ngaysinh = dtiNgaySinh.Value; cmnd = txtCmnd.Text; quequan = txtQuequan.Text; nghenghiep = txtNghenghiep.Text; makhuvuc = cbKhuVuc.SelectedValue.ToString(); //maloaiphong = lstLoaiPhong.SelectedItems[0].Text; List <string> lc = new List <string>(); lc.Add(ho); lc.Add(ten); lc.Add(cmnd); lc.Add(lbKhuvuc.Text); lc.Add(lbLoai.Text); lc.Add(quequan); lc.Add(nghenghiep); lc.Add(ngaysinh.ToString()); lc.Add(cbKhuVuc.SelectedItem.ToString()); foreach (string c in lc) { if (c == "") { check = 1; } } if (check == 1) { check = 0; MessageBox.Show("Phải nhập đầy đủ thông tin!"); } else { KhachDangKy kdk = new KhachDangKy(id, ho, ten, cbGioiTinh.SelectedItem.ToString(), ngaysinh, cmnd, quequan, nghenghiep, makhuvuc, lstLoaiPhong.SelectedItems[0].Text); string sqlInsert = "INSERT INTO ThongTinDangKyPhong(Id,Ho,Ten,GioiTinh,NgaySinh,CMND,QueQuan,NgheNghiep,MaKhuVuc,MaLoaiPhong) VALUES(@id,@ho,@ten,@gioitinh,@ngaysinh,@cmnd,@quequan,@nghenghiep,@makhuvuc,@maloaiphong)"; int i = new ThongTinDKBUS().Insert(sqlInsert, kdk); MessageBox.Show("Đã thêm thành công!"); } } catch (FormatException) { //MessageBox.Show("Phải nhập đầy đủ thông tin!"); } }
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) { } }