using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using BeWo.Core.Service; using BeWo.View.Navigation.Filter; using BS.Shared; using BS.Shared.DataContracts.Compact; using BS.Shared.Translation; namespace BeWo.View.Search { public class SupportConceptSearchView : GenericSearchView { public static readonly DependencyProperty CostBearerFilterProperty = DependencyProperty.Register( "CostBearerFilter", typeof (CompactOrganisationDC), typeof (SupportConceptSearchView), new UIPropertyMetadata(null, (s, e) => ((SupportConceptSearchView) s).UpdateFilteredList())); private CheckBox mChkBoxShowExpiredSupportConcepts; private ComboBox supportConceptFilterComboBox; private List mHiddenSupportConcepts; private bool mIgnoreFilterChange; private bool mShowFilterPanel; public SupportConceptSearchView() { if (!DesignerProperties.GetIsInDesignMode(this)) { ThemeColor = FindResource("SupportConceptContentBrush") as Brush; ListItemStyle = FindResource("SupportConceptSearchStyle") as Style; } } public CompactOrganisationDC CostBearerFilter { get { return (CompactOrganisationDC) GetValue(CostBearerFilterProperty); } set { SetValue(CostBearerFilterProperty, value); } } public List HiddenSupportConcepts { get { return mHiddenSupportConcepts; } set { mHiddenSupportConcepts = value; UpdateFilteredList(); } } public List SupportConcepts { get { return _ObjectList; } set { base.UpdateObjectList(value); } } public bool ShowFilterPanel { get { return mShowFilterPanel; } set { mShowFilterPanel = value; if (value) { CreateFilterPanel(); } } } public event EventHandler ControlInitialized; protected override void UpdateObjectList(List list) { base.UpdateObjectList(list); if (ControlInitialized != null) ControlInitialized(this, new EventArgs()); } protected void CreateFilterPanel() { if (BeWoApp.LoggedOnUser != null && supportConceptFilterComboBox == null) { mIgnoreFilterChange = true; var sp = new StackPanel {Margin = new Thickness(3, 3, 3, 3), Orientation = Orientation.Horizontal}; //mChkBoxShowOnlyMyClients = new CheckBox {Content = "Nur eigene Klienten anzeigen"}; //mChkBoxShowOnlyMyClients.Checked += FilterCheckBoxChanged; //mChkBoxShowOnlyMyClients.Unchecked += FilterCheckBoxChanged; //mChkBoxShowOnlyMyClients.FontSize = 12; //mChkBoxShowOnlyMyClients.VerticalAlignment = VerticalAlignment.Center; var b = FindResource("MainGroupBoxForegroundBrush") as Brush; //if (b != null) //{ // mChkBoxShowOnlyMyClients.Foreground = b; //} //sp.Children.Add(mChkBoxShowOnlyMyClients); supportConceptFilterComboBox = new ComboBox(); supportConceptFilterComboBox.FontSize = 12; supportConceptFilterComboBox.Margin = new Thickness(10, 0, 0, 0); supportConceptFilterComboBox.MinWidth = 100; supportConceptFilterComboBox.Style = FindResource("SortComboBox") as Style; if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) { supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.All)); } if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) { supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.TeamCustomer)); } supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.MyCustomer)); CustomerFilterItem selectedItem = null; switch (BeWoApp.AppSettings.CustomerFilterSupportConcepts) { case CustomerFilterEnum.All: if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) { selectedItem = new CustomerFilterItem(CustomerFilterEnum.All); } break; case CustomerFilterEnum.TeamCustomer: if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) || BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) { selectedItem = new CustomerFilterItem(CustomerFilterEnum.TeamCustomer); } break; } if (selectedItem == null) { selectedItem = new CustomerFilterItem(CustomerFilterEnum.MyCustomer); } supportConceptFilterComboBox.SelectedItem = selectedItem; supportConceptFilterComboBox.SelectionChanged += SupportConceptFilterComboBoxOnSelectionChanged; sp.Children.Add(supportConceptFilterComboBox); mChkBoxShowExpiredSupportConcepts = new CheckBox {Content = Translator.Translate("Abgelaufene Hilfepläne anzeigen"), Margin = new Thickness(5, 0, 0, 0)}; mChkBoxShowExpiredSupportConcepts.Checked += FilterCheckBoxChanged; mChkBoxShowExpiredSupportConcepts.Unchecked += FilterCheckBoxChanged; mChkBoxShowExpiredSupportConcepts.FontSize = 12; mChkBoxShowExpiredSupportConcepts.VerticalAlignment = VerticalAlignment.Center; if (b != null) { mChkBoxShowExpiredSupportConcepts.Foreground = b; } //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) //{ // mChkBoxShowOnlyMyClients.IsChecked = true; // mChkBoxShowOnlyMyClients.IsEnabled = false; //} //else //{ // mChkBoxShowOnlyMyClients.IsChecked = !BeWoApp.AppSettings.ShowAllClients; //} mChkBoxShowExpiredSupportConcepts.IsChecked = BeWoApp.AppSettings.ShowExpiredSupportConcepts; sp.Children.Add(mChkBoxShowExpiredSupportConcepts); AddCustomContentHeaderElement(sp); mIgnoreFilterChange = false; } } protected override void GetAll(Action> pCallBack) { if (SearchMode == SearchMode.ActiveApprovedLVRSupportConcepts) { Cache.GetInstance().GetAllActiveAndApprovedSupportConceptCostbearer(pCallBack); } else if (SearchMode == SearchMode.ActiveCostbearer2SupportConcepts) { Cache.GetInstance().GetActiveSupportConceptCostbearer(pCallBack); } else { Cache.GetInstance().GetAllActiveSupportConceptsCompact(pCallBack); } } protected override bool ShowDCInList(object dc) { bool show = true; var scDC = dc as CompactSupportConceptDC; if (scDC != null) { if (CostBearerFilter != null && !scDC.CostBearerList.Exists(i => i.CostBearerOid.Equals(CostBearerFilter.CostBearerOid))) { return false; } if (ShowFilterPanel) { if (!mChkBoxShowExpiredSupportConcepts.IsChecked.Value) { DateTime? endDate = scDC.EndDate; if (endDate != null) { show = endDate >= DateTime.Now.Date; } } if (show && this.supportConceptFilterComboBox.SelectedItem != null) { var item = ((CustomerFilterItem) this.supportConceptFilterComboBox.SelectedItem).CustomerFilter; switch (item) { case CustomerFilterEnum.MyCustomer: show = scDC.IsRelatedToEmployee; break; case CustomerFilterEnum.TeamCustomer: show = scDC.Customer.IsRelatedToTeam; break; } } } if (show && HiddenSupportConcepts != null) { foreach (CompactSupportConceptDC item in HiddenSupportConcepts) { if(item.Customer.Equals(scDC.Customer)) { return false; } } } } return show; } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) { FilterChanged(); } private void FilterCheckBoxChanged(object sender, RoutedEventArgs e) { FilterChanged(); } private void FilterChanged() { if (!mIgnoreFilterChange) { if (this.supportConceptFilterComboBox.SelectedItem != null) { BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((CustomerFilterItem)this.supportConceptFilterComboBox.SelectedItem).CustomerFilter; } else { BeWoApp.AppSettings.CustomerFilterSupportConcepts = CustomerFilterEnum.MyCustomer; } BeWoApp.AppSettings.ShowExpiredSupportConcepts = mChkBoxShowExpiredSupportConcepts.IsChecked.Value; BeWoApp.SaveAppSettings(); UpdateFilteredList(); } } } }