private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view = sender as GridView;

                //validation
                GridColumn madm_meCol = view.Columns["MADM_ME"];
                GridColumn madm_conCol = view.Columns["MADM_CON"];
                string madm_me = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, madm_meCol), "");
                string madm_con = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, madm_conCol), "");
                if (madm_me.Trim().Length == 0 || madm_con.Trim().Length == 0)
                {
                    e.Valid = false;
                    if (madm_me.Trim().Length == 0)
                        view.SetColumnError(madm_meCol, "Mã danh mục mẹ không được rổng");
                    if (madm_con.Trim().Length == 0)
                        view.SetColumnError(madm_conCol, "Mã danh mục con không được rổng");

                    return;
                }
                _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo();
                //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_DMCauThanhSP obj = new KT_DMCauThanhSP();
                    obj.MADM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_ME"), "");
                    obj.MADM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_CON"), "");
                    obj.TENDM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_ME"), "");
                    obj.TENDM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_CON"), "");
                    obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0);
                    obj.TK_DU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DU"), "");
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                    _KTDMCauThanhSPRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0);
                    KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MADM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_ME"), "");
                        obj.MADM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_CON"), "");
                        obj.TENDM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_ME"), "");
                        obj.TENDM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_CON"), "");
                        obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0);
                        obj.TK_DU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DU"), "");
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                        _KTDMCauThanhSPRepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                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)
         {
             _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo();
             KT_DMCauThanhSP obj = new KT_DMCauThanhSP();
             obj.MADM_ME = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MADM_ME"), "");
             obj.MADM_CON = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MADM_CON"), "");
             obj.TENDM_ME = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TENDM_ME"), "");
             obj.TENDM_CON = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TENDM_CON"), "");
             obj.SL = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SL"), 0);
             obj.TK_DU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_DU"), "");
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "");
             
             _KTDMCauThanhSPRepo.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);
     }
 }