2016-06-27 01:45:38 +02:00
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Windows ;
2021-04-19 01:15:53 +02:00
using System.Windows.Controls ;
2016-06-27 01:45:38 +02:00
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 ;
2021-04-19 01:15:53 +02:00
using BeWo.View.Navigation.Filter ;
2016-06-27 01:45:38 +02:00
using BeWo.View.Navigation.Sorter ;
using BeWo.ViewModel ;
using Microsoft.Win32 ;
namespace BeWo.View.Navigation
{
/// <summary>
/// Interaktionslogik für PersonNavigationView.xaml
/// </summary>
public partial class PersonNavigationView
{
2021-04-19 01:15:53 +02:00
private readonly ComboBox filterComboBox ;
2016-06-27 01:45:38 +02:00
private IEnumerable < IFilterableDC > objectList ;
private IEnumerable < IFilterableDC > recentList ;
public PersonNavigationView ( )
{
InitializeComponent ( ) ;
mainNavigationView . Sorter = new PersonSorter ( ) ;
mainNavigationView . ArchiveButtonVisible = BeWoApp . LoggedOnUser . HasRight ( UserRightType . Person_AllowArchiving ) ;
mainNavigationView . ShowArchivedObjectsVisible = true ;
2021-04-19 01:15:53 +02:00
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 ;
2016-06-27 01:45:38 +02:00
}
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 < IEnumerable < IFilterableDC > > 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 < CompactPersonDC > ( ) . Select ( c = > c . PersonOid ) . ToList ( ) ) ,
sf . FileName ) ) ;
}
2023-09-15 15:02:43 +02:00
private void mainNavigationView_Print ( object sender , EventArgs < IEnumerable < IFilterableDC > > e )
{
var oids = e . Data . Cast < CompactPersonDC > ( ) . Select ( c = > c . PersonOid ) . ToList ( ) ;
2016-06-27 01:45:38 +02:00
2023-09-15 15:02:43 +02:00
ServiceFacade . DoReportServiceAsync ( s = > s . CreatePersonListReport ( oids ) , r = >
{
this . Dispatch ( ( ) = >
{
BeWoUtils . ShowReportWindow ( r , "Personen" ) ;
} ) ;
} ) ;
}
2016-06-27 01:45:38 +02:00
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 < IFilterableDC > 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 ;
}
2018-05-20 13:19:28 +02:00
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 ( ) ;
} ) ;
} ) ;
}
2016-06-27 01:45:38 +02:00
}
}