Exemplo n.º 1
0
        //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!");
            }
        }
Exemplo n.º 2
0
        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)
            {
            }
        }