private void Save_Data(bool msg)
 {
     try
     {
         _DSThongTinDNRepo = new DSThongTinDNRepo();
         int i = 0;
         foreach (int pos in _listUpdate)
         {
             int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0);
             DS_ThongTinDN obj = _DSThongTinDNRepo.GetById(id);
             if (obj != null)
             {
                 obj.STT = Utils.CIntDef(gridView1.GetRowCellValue(pos, "STT"), 0);
                 obj.CHI_TIEU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "CHI_TIEU"), "");
                 obj.GIA_TRI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "GIA_TRI"), "");
                 obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(pos, "TRANG_THAI"),0);
                 obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), "");
                 _DSThongTinDNRepo.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 Load_Data()
 {
     try
     {
         _DSThongTinDNRepo = new DSThongTinDNRepo();
         gridData.DataSource = _DSThongTinDNRepo.GetAll();
         //_db = new dbVstoreAppDataContext(Const.builder.ConnectionString);
         //gridData.DataSource = null;
         //gridData.DataSource = _db.CFGs;
         //gridData.RefreshDataSource();
         //gridView1.RefreshData();
     }
     catch (Exception) { }
 }
 private void Save_Tick()
 {
     try
     {
         _DSThongTinDNRepo = new DSThongTinDNRepo();
         int _id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);
         DS_ThongTinDN obj = _DSThongTinDNRepo.GetById(_id);
         if (obj != null)
         {
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T";
             _DSThongTinDNRepo.Update(obj);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void Save_Duplicate()
 {
     try
     {
         if (MessageBox.Show("Bạn có muốn copy dòng này thành dòng mới?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             _DSThongTinDNRepo = new DSThongTinDNRepo();
             DS_ThongTinDN obj = new DS_ThongTinDN();
             obj.STT = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "STT"), 0);
             obj.CHI_TIEU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CHI_TIEU"), "");
             obj.GIA_TRI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GIA_TRI"), "");
             obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0);
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "");
             _DSThongTinDNRepo.Create(obj);
             MessageBox.Show("Đã copy dòng này vào cuối bảng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     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;
                _DSThongTinDNRepo = new DSThongTinDNRepo();
                //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
                    DS_ThongTinDN obj = new DS_ThongTinDN(); 

                    obj.STT = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "STT"), 0);
                    obj.CHI_TIEU = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "CHI_TIEU"), "");
                    obj.GIA_TRI = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "GIA_TRI"), "");
                    obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);
                    obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                    _DSThongTinDNRepo.Update(obj);

                    _DSThongTinDNRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "ID").ToString(), 0);
                    DS_ThongTinDN obj = _DSThongTinDNRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.STT = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "STT"), 0);
                        obj.CHI_TIEU = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "CHI_TIEU"), "");
                        obj.GIA_TRI = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "GIA_TRI"), "");
                        obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);
                        obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                        _DSThongTinDNRepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Remove_Data()
        {
            try
            {
                //if (_listUpdate.Count > 0)
                //{
                //    MessageBox.Show("Hãy thực hiện lưu trước khi xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return;
                //}
                Save_Data(false);

                _DSThongTinDNRepo = new DSThongTinDNRepo();
                int Id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);
                _DSThongTinDNRepo.Remove(Id);

                //MessageBox.Show("Xóa dòng ID:" + Id + " thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Load_Data();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }