using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Windows; using System.Windows.Controls; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using BeWo.ServiceProxy; namespace BeWo.View.Controls { /// /// Interaktionslogik für MultiSupportConceptSelectionControl.xaml /// public partial class MultiSupportConceptSelectionControl { public event EventHandler EditGroupButtonClicked; private ObservableSortCollection mSelectedSupportConcepts; public MultiSupportConceptSelectionControl() { this.InitializeComponent(); SearchView.SearchMode = Search.SearchMode.ActiveCostbearer2SupportConcepts; this.UpdateListBox(); GroupSearchView.EditGroupButtonClicked += GroupSearchView_EditGroupButtonClicked; } void GroupSearchView_EditGroupButtonClicked(object sender, EventArgs e) { if (EditGroupButtonClicked != null) { EditGroupButtonClicked(sender, e); popupGroup.IsOpen = false; } } public virtual bool AutoGetAllAfterLoaded { get { return this.SearchView != null && SearchView.AutoGetAllAfterLoaded; } set { SearchView.AutoGetAllAfterLoaded = value; GroupSearchView.AutoGetAllAfterLoaded = value; } } public List SupportConceptList { get { if(SearchView != null) return SearchView.SupportConcepts; else return new List(); } set { SearchView.SupportConcepts = value; } } public event EventHandler> ItemSelected; public CompactSupportConceptDC SelectedItem { get { return this.listBoxSupportConcepts != null ? this.listBoxSupportConcepts.SelectedItem as CompactSupportConceptDC : null; } } public ObservableSortCollection SelectedSupportConcepts { get { if (this.mSelectedSupportConcepts == null) { this.mSelectedSupportConcepts = new ObservableSortCollection(); this.mSelectedSupportConcepts.CollectionChanged += this.mSelectedSupportConcepts_CollectionChanged; } return this.mSelectedSupportConcepts; } } private void SupportConceptSearchView_ItemSelected(object sender, EventArgs e) { this.popupSupportConcepts.IsOpen = false; if (this.SelectedSupportConcepts != null && !this.SelectedSupportConcepts.Contains(e.Data)) { this.SelectedSupportConcepts.Add(e.Data); this.listBoxSupportConcepts.ScrollIntoView(e.Data); } } private void GroupSearchView_ItemSelected(object sender, EventArgs e) { this.popupGroup.IsOpen = false; if (this.SelectedSupportConcepts != null) { ServiceFacade.DoEmployeeServiceAsync(s => s.LoadGroupOfPeople(e.Data.GroupOfPeopleOid), cb => this.Dispatch(delegate { if (cb.SupportConceptList != null) { foreach (var sc in cb.SupportConceptList) { if (!this.SelectedSupportConcepts.Contains(sc)) { this.SelectedSupportConcepts.Add(sc); } } } })); } } internal void UpdateListBox() { if (listBoxSupportConcepts == null) return; listBoxSupportConcepts.ItemsSource = null; listBoxSupportConcepts.ItemsSource = SelectedSupportConcepts; } private void btnAddSupportConcept_Click(object sender, RoutedEventArgs e) { this.popupSupportConcepts.IsOpen = true; } private void btnAddGroup_Click(object sender, RoutedEventArgs e) { ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllGroupsCompact(MainSession.LoggedOnEmployee.EmployeeOid), r => { List list = r.Where(g => g.GroupType == GroupTypeId.ServiceRecordSupportConcepts).ToList(); list.Sort((x, y) => x.Name.CompareTo(y.Name)); this.Dispatch(delegate { GroupSearchView.GroupOfPeoples = list; }); }); this.popupGroup.IsOpen = true; } private void btnRemoveSupportConcept_Click(object sender, RoutedEventArgs e) { CompactSupportConceptDC dc = ((Button)sender).Tag as CompactSupportConceptDC; if (dc != null) { this.SelectedSupportConcepts.Remove(dc); } } private void listBoxSupportConcepts_SelectionChanged(object sender, SelectionChangedEventArgs e) { CompactSupportConceptDC dc = null; if (e.AddedItems != null && e.AddedItems.Count > 0) { dc = e.AddedItems[0] as CompactSupportConceptDC; } if (this.ItemSelected != null) { this.ItemSelected(this, new EventArgs(dc)); } } private void mSelectedSupportConcepts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (this.SearchView != null) this.SearchView.HiddenSupportConcepts = this.mSelectedSupportConcepts.ToList(); } public void UpdateSupportConcepts(CompactCustomerDC customer) { var oldList = mSelectedSupportConcepts; foreach (var item in oldList.Where(item => item.Customer.Equals(customer))) item.Customer = customer; mSelectedSupportConcepts = oldList; } } }