partial void DeleteKHACH_HANG(KHACH_HANG instance);
 partial void InsertKHACH_HANG(KHACH_HANG instance);
 partial void UpdateKHACH_HANG(KHACH_HANG instance);
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (!Check())
            {
                return;
            }

            try
            {
                if (tinh_trang == "them")
                {
                    KHACH_HANG kh = new KHACH_HANG
                    {
                        Ma_Khach_Hang = txtMaKhachHang.Text,
                        Ten_Khach_Hang = txtTenKhachHang.Text,
                        Ma_Khu_Vuc = string.IsNullOrEmpty(txtKhuVuc.Text) ? "" : txtKhuVuc.EditValue.ToString(),
                        Dia_Chi = txtDiaChi.Text,
                        Ma_So_Thue = txtMaSoThue.Text,
                        Dien_Thoai = txtDienThoai.Text,
                        Fax = txtFax.Text,
                        Email = txtEmail.Text,
                        Di_Dong = txtDiDong.Text,
                        Website = txtWebsite.Text,
                        Nguoi_Lien_He = txtNguoiLienHe.Text,
                        NickYM = txtYahoo.Text,
                        NickSky = txtSkype.Text,
                        Tai_Khoan_Ngan_Hang = txtTaiKhoanNganHang.Text,
                        Ten_Ngan_Hang = txtTenNganHang.Text,
                        Ghi_Chu = txtGhiChu.Text
                    };

                    db.KHACH_HANGs.InsertOnSubmit(kh);
                }
                else
                {
                    var kh = (from k in db.KHACH_HANGs
                              where k.Ma_Khach_Hang == txtMaKhachHang.Text
                              select k).FirstOrDefault();

                    kh.Ma_Khach_Hang = txtMaKhachHang.Text;
                    kh.Ten_Khach_Hang = txtTenKhachHang.Text;
                    kh.Ma_Khu_Vuc = string.IsNullOrEmpty(txtKhuVuc.Text) ? "" : txtKhuVuc.EditValue.ToString();
                    kh.Dia_Chi = txtDiaChi.Text;
                    kh.Ma_So_Thue = txtMaSoThue.Text;
                    kh.Dien_Thoai = txtDienThoai.Text;
                    kh.Fax = txtFax.Text;
                    kh.Email = txtEmail.Text;
                    kh.Di_Dong = txtDiDong.Text;
                    kh.Website = txtWebsite.Text;
                    kh.Nguoi_Lien_He = txtNguoiLienHe.Text;
                    kh.NickYM = txtYahoo.Text;
                    kh.NickSky = txtSkype.Text;
                    kh.Tai_Khoan_Ngan_Hang = txtTaiKhoanNganHang.Text;
                    kh.Ten_Ngan_Hang = txtTenNganHang.Text;
                    kh.Ghi_Chu = txtGhiChu.Text;
                }

                db.SubmitChanges();
                RaiseReloadEventHander();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }