using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using BeWo.Core; using BeWo.ServiceProxy; using BeWo.View.Detail; using BeWo.View.Navigation.Filter; using BeWo.View.Navigation.Sorter; using BeWo.ViewModel; using Microsoft.Win32; namespace BeWo.View.Navigation { /// /// Interaktionslogik für PersonNavigationView.xaml /// public partial class PersonNavigationView { private readonly ComboBox filterComboBox; private IEnumerable objectList; private IEnumerable recentList; public PersonNavigationView() { InitializeComponent(); mainNavigationView.Sorter = new PersonSorter(); mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Person_AllowArchiving); mainNavigationView.ShowArchivedObjectsVisible = true; filterComboBox = new ComboBox(); filterComboBox.FontSize = 12; filterComboBox.Margin = new Thickness(10, 0, 0, 0); filterComboBox.MinWidth = 100; filterComboBox.Style = FindResource("SortComboBox") as Style; var lbl = new TextBlock { Text = "Filter:", FontSize = 12, Margin = new Thickness(8, 2, -3, 0) }; PersonFilterItem selectedItem = null; if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Person_FamilyView)) { filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.All)); filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.ContactPersons)); filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.Family)); selectedItem = new PersonFilterItem(PersonFilterEnum.All); ; } else { filterComboBox.Visibility = Visibility.Collapsed; lbl.Visibility = Visibility.Collapsed; filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.ContactPersons)); selectedItem = new PersonFilterItem(PersonFilterEnum.ContactPersons); ; } filterComboBox.SelectedItem = selectedItem; filterComboBox.SelectionChanged += SupportConceptFilterComboBoxOnSelectionChanged; mainNavigationView.sortPanel.Children.Insert(3, lbl); mainNavigationView.sortPanel.Children.Insert(4, filterComboBox); UpdateCustomFilter(); } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) { //BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((PersonFilterItem)filterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer; //BeWoApp.SaveAppSettings(); UpdateCustomFilter(); } private void UpdateCustomFilter() { mainNavigationView.CustomFilter = CreateNewPersonFilter(); } private PersonNavigationFilter CreateNewPersonFilter() { var filter = new PersonNavigationFilter { PersonFilter = ((PersonFilterItem)filterComboBox.SelectedItem)?.Filter ?? PersonFilterEnum.ContactPersons }; return filter; } private void OnLoaded(object sender, RoutedEventArgs e) { ReloadData(false); } private bool mainNavigationView_ArchiveObject(IFilterableDC obj) { var dc = obj as CompactPersonDC; if (dc != null) { if ( MessageBox.Show( "Wollen Sie die Person '" + dc.FirstName + " " + dc.LastName + "' wirklich archivieren?", "Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { ServiceFacade.DoCustomerServiceAsync( s => { s.ArchivePerson(dc.PersonOid, dc.PersonVersion); return dc; }, cb => cb.PersonVersion++); return true; } } return false; } private void mainNavigationView_CreateNewObject() { VMFactory.CreatePersonVMAsync(cb => this.Dispatch(() => MainControl.NavigateTo(new PersonView(cb) {ParentView = this}))); } private bool mainNavigationView_DeleteObject(IFilterableDC obj) { var dc = obj as CompactPersonDC; if (dc != null) { if ( MessageBox.Show( "Wollen Sie die Person '" + dc.FirstName + " " + dc.LastName + "' wirklich löschen?", "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { ServiceFacade.DoCustomerServiceAsync(s => s.DeactivatePerson(dc.PersonOid, dc.PersonVersion)); return true; } } return false; } private void mainNavigationView_ExcelExport(object sender, EventArgs> e) { // string path = BeWoApp.LoginControl.GetAndCreateTempDataPath() + "\\Personen.xls"; var path = BeWoApp.GetAndCreateUserAppDataPath() + "\\Personen.xls"; var sf = new SaveFileDialog { FileName = Path.GetFileName(path), Filter = "Microsoft Excel 97-2003-Arbeitsblatt|*.xls|Alle Dateien|*.*" }; if (sf.ShowDialog() != true) return; ServiceFacade.DoDownloadServiceSync( s => BeWoUtils.WriteExcelFile( s.PrepareExcelFilePersonExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast().Select(c => c.PersonOid).ToList()), sf.FileName)); } private void mainNavigationView_OpenObject(IFilterableDC obj) { var dc = obj as CompactPersonDC; if (dc != null) { VMFactory.CreatePersonVMAsync(dc.PersonOid, cb => this.Dispatch(() => MainControl.NavigateTo(new PersonView(cb) {ParentView = this}))); } } public override void ChildViewClosed() { recentList = null; objectList = null; } private void MainNavigationView_OnReloadData() { ReloadData(true); } private void ReloadData(bool refresh) { if (refresh || recentList == null) { ServiceFacade.DoCustomerServiceAsync( s => s.GetAllPersonsByTypeCompact(PersonType.Others), r => this.Dispatch(delegate { objectList = r; mainNavigationView.ShowSearchResult(objectList); })); ServiceFacade.DoCustomerServiceAsync(s => s.GetLastOpenedPersons(), r => this.Dispatch(delegate { recentList = r; mainNavigationView.ShowHistory(recentList); })); } else { mainNavigationView.ShowSearchResult(objectList); mainNavigationView.ShowHistory(recentList); } } private void MainNavigationView_OnOpenMailMergeWindow(List allPersons, IFilterableDC selectedPerson) { var mmw = new MailMergeWindow(this, typeof(PersonDC), objectList.ToList(), selectedPerson) { Sorter = new PersonSorter() }; mmw.Show(); } public void ReactivatePerson(CompactPersonDC person) { if (MessageBox.Show("Wollen Sie die Person '" + person.FirstName + " " + person.LastName + "' wirklich reaktivieren?", "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return; } ServiceFacade.DoCustomerServiceAsync(s => { s.ReactivatePerson(person.PersonOid, person.Version); return person; }, cb => cb.PersonVersion++); person.ActivationType = ActivationTypeId.Active; var context = mainNavigationView.objectListBox.DataContext; mainNavigationView.objectListBox.DataContext = null; mainNavigationView.objectListBox.DataContext = context; } public void DeleteForGood(CompactPersonDC person) { var dialog = new MessageDialog(() => { this.Dispatch(() => { ServiceFacade.DoOperationsServiceAsync(s => { s.DeletePersonForGood(person.PersonOid); }, () => { ReloadData(true); }); }); }); ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Person, person.PersonOid, MessageType.DeleteForGood), xaml => { this.Dispatch(() => { dialog.SetXaml(xaml); dialog.ShowDialog(); }); }); } } }