//修改外来人员到访记录 public static void UpdateRecord(VisitorAccessManagement rec) { using (var entity = new CommunityEpidemicManagementSystemContext()) { try { entity.VisitorAccessManagements.Remove(Get(rec.VisitorAccessManagementId)); entity.VisitorAccessManagements.Add(rec); entity.SaveChanges(); } catch (Exception ex) { string errorInfo = ex.Message; if (ex is DbEntityValidationException) { foreach (var validationResult in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (var error in validationResult.ValidationErrors) { errorInfo = $"{errorInfo}" + "\n" + $"{error.ErrorMessage}"; } } } throw new ApplicationException("更新时出错!\n" + $"{errorInfo}"); } } }
private void btnLeave_Click(object sender, EventArgs e) { VisitorAccessManagement visitorAccessManagement = VisitorAccessManagementBindingSource.Current as VisitorAccessManagement; if (visitorAccessManagement == null) { MessageBox.Show("请选择一位访客"); return; } else { visitorAccessManagement.LeaveTime = DateTime.Now; VisitorsAccessManagementService.UpdateRecord(visitorAccessManagement); VisitorQueryALL(); } }
public AccessManagementAddOut(VisitorAccessManagement visitorAccessManagement) : this() { VisitorAccessManagement = visitorAccessManagement; VisitorAccessBindingSource.DataSource = visitorAccessManagement; }