public bool LayThongTinVeDon(string MaHoSo)
        {
            try
            {
                using (DMCWebEntities db = new DMCWebEntities())
                {
                    long _maHS = long.Parse(MaHoSo);
                    var kq = from h in db.tblHoSoKeKhaiDuBis
                             join dt in db.tblChuHoSoDuBis on h.MaHoSoKeKhai equals dt.MaHoSoKeKhai
                             where h.MaHoSoKeKhai == _maHS
                             select new
                             {
                                 MaHS = h.MaHoSoKeKhai,
                                 Dvhc = h.DonViHanhChinh,
                                 LoaiDT = h.MaLoaiDoiTuong
                             };
                    Session["MaDVHC"] = kq.Single().Dvhc;
                    string strLoaiDoiTuong = kq.Single().LoaiDT;
                    if (strLoaiDoiTuong == null || strLoaiDoiTuong == "")
                        drLoaiDoiTuong.SelectedIndex = -1;
                    else
                        drLoaiDoiTuong.SelectedValue = strLoaiDoiTuong;
                    drDonViHanhChinh.SelectedValue = Session["MaDVHC"].ToString();
                    return true;
                }
            }
            catch (Exception ex)
            {

                string s = ex.Message;
                return false;
            }
        }
        public bool LayThongTinVeDon(string MaDangKyBienDong)
        {
            try
            {
                using (DMCWebEntities db = new DMCWebEntities())
                {
                    long _maDangKyBienDong = long.Parse(MaDangKyBienDong);

                    if (Session["LoaiHoSo"] == "DuBi")
                    {
                        var kq = from h in db.tblDonXinDangKyBienDongDuBis
                                 where h.ID == _maDangKyBienDong
                                 select h;

                        Session["MaDVHC"] = kq.Single().DonViHanhChinh;
                        if (Session["MaDVHC"] != null && Session["MaDVHC"].ToString() != "")
                            drDonViHanhChinh.SelectedValue = Session["MaDVHC"].ToString();

                        Session["LoaiBienDong"] = kq.Single().LoaiBienDong;
                        string s = Session["LoaiBienDong"].ToString();
                        if (Convert.ToInt32(Session["LoaiBienDong"]) > 0)
                            drLoaiBienDong.SelectedValue = Session["LoaiBienDong"].ToString();
                        return true;
                    }
                    else if(Session["LoaiHoSo"] == "ChinhThuc")
                    {
                        var kq = from h in db.tblDonXinDangKyBienDongs
                                 where h.MaDangKyBienDong == _maDangKyBienDong
                                 select h;

                        Session["MaDVHC"] = kq.Single().DonViHanhChinh;
                        if (Session["MaDVHC"] != null && Session["MaDVHC"].ToString() != "")
                            drDonViHanhChinh.SelectedValue = Session["MaDVHC"].ToString();

                        Session["LoaiBienDong"] = kq.Single().LoaiBienDong;
                        string s = Session["LoaiBienDong"].ToString();
                        if (Convert.ToInt32(Session["LoaiBienDong"]) > 0)
                            drLoaiBienDong.SelectedValue = Session["LoaiBienDong"].ToString();
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {

                string s = ex.Message;
                return false;
            }
        }
        protected void grvChu_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                NhapThongTinChu_Visible(true);
                string _maChu = e.CommandArgument.ToString();
                Session["ThaoTac"] = ThaoTac.DangSua;
                Session["MaChu"] = _maChu;

                using (DMCWebEntities db = new DMCWebEntities())
                {
                    long maChu = long.Parse(_maChu);
                    if (Session["LoaiHoSo"] == "DuBi")
                    {
                        tblChuDuBi chu = db.tblChuDuBis.SingleOrDefault(n => n.MaChu == maChu);

                        lblMaChu.Text = _maChu.ToString();
                        txtHoTen.Text = chu.HoTen;
                        drDanhXung.Text = chu.DanhXung;
                        txtNamSinh.Text = chu.NamSinh;
                        txtDiaChi.Text = chu.DiaChi;
                        txtSoDinhDanh.Text = chu.SoDinhDanh;
                        txtNoiCap.Text = chu.NoiCap;
                        txtNgayCap.Text = chu.NgayCap.ToString();
                        txtDinhDanh.Text = chu.DinhDanh;
                    }
                    else if (Session["LoaiHoSo"] == "ChinhThuc")
                    {
                        tblChu chu = db.tblChus.SingleOrDefault(n => n.MaChu == maChu);

                        lblMaChu.Text = "Mã chủ: " + _maChu.ToString();
                        txtHoTen.Text = chu.HoTen;
                        drDanhXung.Text = chu.DanhXung;
                        txtNamSinh.Text = chu.NamSinh;
                        txtDiaChi.Text = chu.DiaChi;
                        txtSoDinhDanh.Text = chu.SoDinhDanh;
                        txtNoiCap.Text = chu.NoiCap;
                        txtNgayCap.Text = chu.NgayCap.ToString();
                        txtDinhDanh.Text = chu.DinhDanh;
                    }
                }

            }
        }
        protected void grvThuaDat_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                NhapThongTinThuaDat_Visible(true);
                string _maThuaDat = e.CommandArgument.ToString();
                Session["ThaoTac"] = ThaoTac.DangSua;
                Session["MaThuaDat"] = _maThuaDat;

                using (DMCWebEntities db = new DMCWebEntities())
                {
                    long maThuaDat = long.Parse(_maThuaDat);
                    var thuadatdangxet = (from td in db.tblThuaDatDuBis
                              where td.MaThuaDat == maThuaDat
                              select td).Single();
                    tblThuaDatDuBi thua = (tblThuaDatDuBi)thuadatdangxet;
                    lblMaThuaDat.Text = thua.MaThuaDat.ToString();
                    lblMaHoSo.Text = thua.MaHoSoKeKhai.ToString();
                    txtToBanDo.Text = thua.ToBanDo;
                    txtSoThua.Text = thua.SoThua;
                    txtDiaChi.Text = thua.DiaChi;
                    txtDienTich.Text = thua.DienTich;
                    txtDTSDChung.Text = thua.SuDungChung;
                    txtDTSDRieng.Text = thua.SuDungRieng;
                    txtMucDich.Text = thua.MucDichSuDung;
                    txtThoiHan.Text = thua.ThoiHanSuDung;
                    txtNgayBatDau.Text = thua.NgayBatDauSuDung.ToString();

                    drHanChe.SelectedValue = thua.CoHanCheSuDung.ToString().ToLower();
                    txtHanChe.Text = thua.NoiDungHanCheSuDung;
                    drLoaiNguonGoc.SelectedValue = thua.LoaiNguonGocSuDung;

                }

            }
        }
        protected void grvNhaO_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                NhapThongTinNhaO_Visible(true);
                string _maNhaO = e.CommandArgument.ToString();
                Session["ThaoTac"] = ThaoTac.DangSua;
                Session["MaNhaO"] = _maNhaO;

                using (DMCWebEntities db = new DMCWebEntities())
                {
                    long maNhaO = long.Parse(_maNhaO);
                    var q = (from n in db.tblThongTinNhaODuBis
                             where n.MaNhaO == maNhaO
                             select n).Single();
                    tblThongTinNhaODuBi nha = (tblThongTinNhaODuBi)q;
                    lblMaNhaO.Text =nha.MaNhaO.ToString();
                    drLoaiNhaO.SelectedValue = nha.LoaiNhaO;
                    txtDienTichXayDung.Text =nha.DienTichXayDung;
                    txtDienTichSan.Text =nha.DienTichSan;
                    txtSoHuuChung.Text =nha.SoHuuChung;
                    txtSoHuuRieng.Text =nha.SoHuuRieng;
                    txtKetCau.Text = nha.KetCau;
                    txtHanCheNha.Text =nha.ThoiHanSoHuu;
                    drHanCheNha.SelectedValue=nha.CoHanCheThoiHanSoHuu.ToString();
                    txtSoTang.Text =nha.SoTang;
                }

            }
        }
        protected void grvChu_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                NhapThongTinChu_Visible(true);
               string _maChu = e.CommandArgument.ToString();
                Session["ThaoTac"] = ThaoTac.DangSua;
                Session["MaChu"] = _maChu;

                using(DMCWebEntities db = new DMCWebEntities())
                {
                    long maChu = long.Parse(_maChu);
                    var q = (from c in db.tblChuDuBis
                            where c.MaChu == maChu
                                 select c).Single();
                    tblChuDuBi chu = (tblChuDuBi)q;
                    lblMaChu.Text ="Mã chủ: "+ _maChu.ToString();
                    txtHoTen.Text = chu.HoTen;
                    drDanhXung.Text = chu.DanhXung;
                    txtNamSinh.Text = chu.NamSinh;
                    txtDiaChi.Text = chu.DiaChi;
                    txtSoDinhDanh.Text = chu.SoDinhDanh;
                    txtNoiCap.Text = chu.NoiCap;
                    txtNgayCap.Text = chu.NgayCap.ToString();
                    txtDinhDanh.Text = chu.DinhDanh;
                }

            }
        }