private void Save_Data(bool msg)
        {
            try
            {
                _KTDTPNRepo = new KTDTPNRepo();
                int i = 0;
                foreach (int pos in _listUpdate)
                {
                    int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0);
                    KT_DTPN obj = _KTDTPNRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MA_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_DTPN"), "");
                        obj.TEN_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_DTPN"), "");
                        obj.DIA_CHI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DIA_CHI"), "");
                        obj.DIA_CHI_GH = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DIA_CHI_GH"), "");
                        obj.MA_SO_THUE = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_SO_THUE"), "");
                        obj.LIEN_HE = Utils.CStrDef(gridView1.GetRowCellValue(pos, "LIEN_HE"), "");
                        obj.DIEN_THOAI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DIEN_THOAI"), "");
                        obj.TK_NH = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_NH"), "");
                        obj.TEN_TKNH = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_TKNH"), "");
                        obj.MA_TT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_TT"), "");
                        obj.TEN_TT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_TT"), "");
                        obj.MA_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_NHOM"), "");
                        obj.TEN_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_NHOM"), "");
                        obj.CK_PT = Utils.CDblDef(gridView1.GetRowCellValue(pos, "CK_PT"), 0);
                        obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), "");
                        obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(pos, "TRANG_THAI"), 0);

                        _KTDTPNRepo.Update(obj);
                        i++;
                    }                    
                }
                _listUpdate = new List<int>();
                //if (i > 0 && msg)
                //{
                //    MessageBox.Show("Lưu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }            
        }
 private void Save_Tick()
 {
     try
     {
         _KTDTPNRepo = new KTDTPNRepo();
         int _id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0);
         KT_DTPN obj = _KTDTPNRepo.GetById(_id);
         if (obj != null)
         {
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T";
             _KTDTPNRepo.Update(obj);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view = sender as GridView;
                _KTDTPNRepo = new KTDTPNRepo();
                //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert
                if (view.IsNewItemRow(e.RowHandle))
                {
                    //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại
                    KT_DTPN obj = new KT_DTPN();
                    obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), "");
                    obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), "");
                    obj.DIA_CHI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI"), "");
                    obj.DIA_CHI_GH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI_GH"), "");
                    obj.MA_SO_THUE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_SO_THUE"), "");
                    obj.LIEN_HE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "LIEN_HE"), "");
                    obj.DIEN_THOAI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIEN_THOAI"), "");
                    obj.TK_NH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_NH"), "");
                    obj.TEN_TKNH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TKNH"), "");
                    obj.MA_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TT"), "");
                    obj.TEN_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TT"), "");
                    obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), "");
                    obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), "");
                    obj.CK_PT = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "CK_PT"), 0);
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                    obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);

                    _KTDTPNRepo.Create(obj);
                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0);
                    KT_DTPN obj = _KTDTPNRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), "");
                        obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), "");
                        obj.DIA_CHI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI"), "");
                        obj.DIA_CHI_GH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI_GH"), "");
                        obj.MA_SO_THUE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_SO_THUE"), "");
                        obj.LIEN_HE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "LIEN_HE"), "");
                        obj.DIEN_THOAI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIEN_THOAI"), "");
                        obj.TK_NH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_NH"), "");
                        obj.TEN_TKNH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TKNH"), "");
                        obj.MA_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TT"), "");
                        obj.TEN_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TT"), "");
                        obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), "");
                        obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), "");
                        obj.CK_PT = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "CK_PT"), 0);
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                        obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);

                        _KTDTPNRepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }