private void _setObjectEntities(ref QL_USERS item) { item.USER_NAME = txtUSER_NAME.Text; item.USER_FULLNAME = txtUSER_FULLNAME.Text; item.USER_PASS = txtUSER_PASS.Text; item.USER_LOCK = chkUSER_LOCK.Checked; }
private void _loadDataFocusRow() { _clearData(); QL_USERS item = gvGrid.GetFocusedRow() as QL_USERS; if (item != null) { txtUSER_NAME.EditValue = item.USER_NAME; txtUSER_FULLNAME.EditValue = item.USER_FULLNAME; txtUSER_PASS.EditValue = item.USER_PASS; chkUSER_LOCK.EditValue = item.USER_LOCK; } _loadUserPermission(); }
protected override bool SaveData() { if (_validateControl()) { WaitDialogForm _wait = new WaitDialogForm("Đang lưu dữ liệu ...", "Vui lòng đợi giây lát"); using (var _context = new QL_HOIVIEN_KTEntities()) { QL_USERS item; switch (_formStatus) { case EnumFormStatus.ADD: item = new QL_USERS(); _setObjectEntities(ref item); _context.QL_USERS.Add(item); var listFunc = FuncCategory.loadFunctionName(); foreach (var func in listFunc) { QL_USERS_PERMISSION per = new QL_USERS_PERMISSION(); per.PER_NAME = Convert.ToInt32(func.ID); per.PER_VIEW = true; per.PER_ADD = false; per.PER_MODIFY = false; per.PER_DELETE = false; per.PER_PRINT = false; per.QL_USERS = item; _context.QL_USERS_PERMISSION.Add(per); } break; case EnumFormStatus.MODIFY: Int64 userId = Convert.ToInt64(gvGrid.GetFocusedRowCellValue(colUSER_ID)); item = (from p in _context.QL_USERS where p.USER_ID == userId select p).FirstOrDefault <QL_USERS>(); if (item != null) { _setObjectEntities(ref item); } var entity = _context.QL_USERS.Find(userId); _context.Entry(entity).CurrentValues.SetValues(item); gvChucNang.PostEditor(); gvChucNang.UpdateCurrentRow(); context.SaveChanges(); break; case EnumFormStatus.DELETE: Int64 deleteId = Convert.ToInt64(gvGrid.GetFocusedRowCellValue(colUSER_ID)); var entitiesPermission = (from p in _context.QL_USERS_PERMISSION where p.USER_ID == deleteId select p); foreach (var per in entitiesPermission) { _context.QL_USERS_PERMISSION.Remove(per); } QL_USERS entities = (from p in _context.QL_USERS where p.USER_ID == deleteId select p).FirstOrDefault(); _context.QL_USERS.Remove(entities); break; default: break; } _context.SaveChanges(); } FormStatus = EnumFormStatus.VIEW; _wait.Close(); } return(base.SaveData()); }