private void RefreshDtgMain() { var index = DataGridEmployees.SelectedIndex; if (SmpUcLookup.LookupText.Trim() == string.Empty) { EmployeesAll = new ObservableCollection <Employee>(_context.Employees.ToList()); } else { var lookups = SmpUcLookup.LookupText.Split(' '); var lists = lookups.Select(strLookup => (from x in _context.Employees where x.FName.Contains(strLookup) || x.LName.Contains(strLookup) || x.PersonnelCode.Contains(strLookup) || x.DossierNo.Contains(strLookup) || x.NationalCardNo.Contains(strLookup) || x.IdCardNo.Contains(strLookup) select x).ToList()).ToList(); var lookedUpList = _context.Employees.ToList(); lists.ForEach(x => lookedUpList.RemoveAll(employee => lookedUpList.Except(x).Contains(employee))); EmployeesAll = new ObservableCollection <Employee>(lookedUpList); } DataGridEmployees.GetBindingExpression(DataContextProperty)?.UpdateTarget(); if (DataGridEmployees.Items.Count > index) { DataGridEmployees.SelectedIndex = index; } }
private void Reload() { var selectedId = (DataGridEmployees.SelectedItem as Employee)?.Id; Context = new PaySysContext(); Context.MainGroups.Include(mg => mg.SubGroups).Load(); Context.SubGroups.Load(); Context.Jobs.Load(); Context.Employees.Include(employee => employee.ContractMasters).Load(); SmpUcContractMasterEdit.MainGroups = Context.MainGroups.Local; SmpUcContractMasterEdit.SubGroups = Context.SubGroups.Local; SmpUcContractMasterEdit.Jobs = Context.Jobs.Local; EmployeesAll = Context.Employees.Local; DataGridEmployees.GetBindingExpression(ItemsControl.ItemsSourceProperty)?.UpdateTarget(); DataGridEmployees.GetBindingExpression(DataContextProperty)?.UpdateTarget(); if (selectedId.HasValue) { DataGridEmployees.SelectedItem = EmployeesAll.FirstOrDefault(emp => emp.Id == selectedId.Value); } SmpUcLookup_OnLookupTextChanged(null, null); }