public bool Insert(PhieuThuTienPhong phieuThuTienPhong)
        {
            try
            {
                string         query       = "SELECT * FROM PhieuThuTienPhong";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                table = GetData();
                DataRow row = table.NewRow();

                row["DoiTuongId"]  = phieuThuTienPhong.DoiTuongId;
                row["NhanVienId"]  = phieuThuTienPhong.NhanVienId;
                row["NguoiDungId"] = phieuThuTienPhong.NguoiDungId;
                row["tenNguoiLap"] = phieuThuTienPhong.TenNguoiLap;
                row["ngayThu"]     = phieuThuTienPhong.NgayThu;
                row["tuNgay"]      = phieuThuTienPhong.TuNgay;
                row["denNgay"]     = phieuThuTienPhong.DenNgay;
                row["tienThu"]     = phieuThuTienPhong.TienThu;
                row["ghiChu"]      = phieuThuTienPhong.GhiChu;
                row["tinhTrang"]   = phieuThuTienPhong.TinhTrang;

                table.Rows.Add(row);

                SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Update(table);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool Update(PhieuThuTienPhong phieuThuTienPhong)
        {
            try
            {
                string         query       = "SELECT * FROM PhieuThuTienPhong";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                table            = GetData();
                table.PrimaryKey = new DataColumn[] { table.Columns[0] };
                DataRow row = table.Rows.Find(phieuThuTienPhong.PhieuThuTienPhongId);

                if (row != null)
                {
                    row["DoiTuongId"]  = phieuThuTienPhong.DoiTuongId;
                    row["NhanVienId"]  = phieuThuTienPhong.NhanVienId;
                    row["NguoiDungId"] = phieuThuTienPhong.NguoiDungId;
                    row["tenNguoiLap"] = phieuThuTienPhong.TenNguoiLap;
                    row["ngayThu"]     = phieuThuTienPhong.NgayThu;
                    row["tuNgay"]      = phieuThuTienPhong.TuNgay;
                    row["denNgay"]     = phieuThuTienPhong.DenNgay;
                    row["tienThu"]     = phieuThuTienPhong.TienThu;
                    row["ghiChu"]      = phieuThuTienPhong.GhiChu;
                    row["tinhTrang"]   = phieuThuTienPhong.TinhTrang;
                }

                SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Update(table);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (DoiTuongId != 0 && checkTime((DateTime)dteTuNgay.EditValue, (DateTime)dteDenNgay.EditValue))
            {
                PhieuThuTienPhong phieuThuTienPhong = new PhieuThuTienPhong();
                phieuThuTienPhong.DoiTuongId  = DoiTuongId;
                phieuThuTienPhong.NguoiDungId = Const.CurrentUser.NguoiDungId;
                phieuThuTienPhong.NhanVienId  = (int)cbbNhanVien.SelectedValue;
                phieuThuTienPhong.TenNguoiLap = cbbNhanVien.Text;
                phieuThuTienPhong.NgayThu     = (DateTime)dteNgayThu.EditValue;
                phieuThuTienPhong.TuNgay      = (DateTime)dteTuNgay.EditValue;
                phieuThuTienPhong.DenNgay     = (DateTime)dteDenNgay.EditValue;
                phieuThuTienPhong.GhiChu      = txtGhiChu.Text;
                phieuThuTienPhong.TienThu     = int.Parse(txtTienThu.Text);
                phieuThuTienPhong.TinhTrang   = (cbTinhTrang.Checked) ? true : false;



                if (BUS_PhieuThuTienPhong.Insert(phieuThuTienPhong))
                {
                    MessageBox.Show("Thêm thành công!");
                }
                else
                {
                    MessageBox.Show("Thất bại!");
                }
                DoiTuongId = 0;

                eventTaoPhieuDone(sender, e);
            }
            else
            {
                DoiTuongId = 0;
                MessageBox.Show("Bạn cần chọn đối tượng để tạo phiếu!");
            }
        }