private void UpdateChooseChildren(bool?selectAll = null) { ChooseChildren.Items.Clear(); EnumerableOwnChildren = SourceFamily.GetEnumerableMembers().Where(m => m.Refs.ParentId == SourceMember.Id); EnumerableChildren = SourceFamily.GetEnumerableMembers().Where( m => m.Id != SourceMember.Id && m.BirthDate >= SourceMember.BirthDate && m.Refs.Parent == null && !SourceMember.Refs.Partner.Changes.Values.Any(p => p != null && p.Id == m.Id) ); if (EnumerableChildren.Any() || EnumerableOwnChildren.Any()) { foreach (Member child in EnumerableOwnChildren) { ChooseChildren.Items.Add(child, selectAll ?? true); } foreach (Member child in EnumerableChildren) { ChooseChildren.Items.Add(child, selectAll ?? false); } } else { ChooseChildren.Items.Add("No available members. Add children of this member at first.", CheckState.Indeterminate); } }
private void ChooseChildrenSaveChangesBtnOnClick(object sender, EventArgs e) { if (EnumerableChildren.Any() || EnumerableOwnChildren.Any()) { EnumerableOwnChildren = EnumerableOwnChildren.ToArray(); for (int i = 0; i < EnumerableOwnChildren.Count(); i++) { if (!ChooseChildren.CheckedIndices.Contains(i)) { SourceMember.Refs.RemoveChild(EnumerableOwnChildren.ElementAt(i)); } } try { EnumerableChildren = EnumerableChildren.ToArray(); foreach (int i in ChooseChildren.CheckedIndices) { if (i >= EnumerableOwnChildren.Count()) { SourceMember.HadChild(EnumerableChildren.ElementAt( i - EnumerableOwnChildren.Count() )); } } } catch (Exception ex) { if (new ValidationFailedDialog(ex.Message).ShowDialog() == DialogResult.OK) { } } } UpdateChooseChildren(); ChooseChildrenSaveChangesBtn.Enabled = false; }