private void Save_Data(bool msg)
 {
     try
     {
         _KBKQKDRepo = new KBKQKDRepo();
         int i = 0;
         foreach (int pos in _listUpdate)
         {
             string id = Utils.CStrDef(gridView1.GetRowCellValue(pos, "CHI_TIEU"), "");
             KB_KQKD obj = _KBKQKDRepo.GetById(id.Trim());
             if (obj != null)
             {
                 Get_Data(obj, pos);
                 _KBKQKDRepo.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
     {
         _KBKQKDRepo = new KBKQKDRepo();
         string _id = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CHI_TIEU").ToString(), "");
         KB_KQKD obj = _KBKQKDRepo.GetById(_id.Trim());
         if (obj != null)
         {
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T";
             _KBKQKDRepo.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;
                _KBKQKDRepo = new KBKQKDRepo();
                //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
                    KB_KQKD obj = new KB_KQKD();
                    Get_Data(obj, e.RowHandle);
                    _KBKQKDRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    string id = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "CHI_TIEU").ToString(), "");
                    KB_KQKD obj = _KBKQKDRepo.GetById(id);
                    if (obj != null)
                    {
                        Get_Data(obj, e.RowHandle);
                        _KBKQKDRepo.Update(obj);
                    }

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