2016-06-27 01:45:38 +02:00
using System.Collections.Generic ;
2019-09-27 15:55:01 +02:00
using System.Diagnostics ;
2016-06-27 01:45:38 +02:00
using System.IO ;
using System.Linq ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Documents ;
using System.Windows.Navigation ;
using BeWo.Core ;
using BeWo.ServiceProxy ;
using BeWo.View.Detail ;
using BeWo.View.Navigation.Filter ;
using BeWo.View.Navigation.Sorter ;
using BeWo.ViewModel ;
using BeWo.Core.Service ;
using BS.Shared ;
using BS.Shared.Core ;
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
using BS.Shared.Extensions ;
2017-11-06 10:30:25 +01:00
using BS.Shared.Translation ;
2018-05-20 13:19:28 +02:00
2016-06-27 01:45:38 +02:00
using Microsoft.Win32 ;
namespace BeWo.View.Navigation
{
/// <summary>
/// Interaktionslogik für CustomerNavigationView.xaml
/// </summary>
public partial class CustomerNavigationView
{
2017-11-17 22:24:00 +01:00
//private readonly CheckBox chkShowOnlyMyCustomers;
//private readonly CheckBox chkShowOnlyTeamCustomers;
private readonly ComboBox supportConceptFilterComboBox ;
2016-06-27 01:45:38 +02:00
private IEnumerable < IFilterableDC > objectList ;
private IEnumerable < IFilterableDC > recentList ;
public CustomerNavigationView ( )
{
InitializeComponent ( ) ;
mainNavigationView . Sorter = new CustomerSorter ( ) ;
2018-05-20 13:19:28 +02:00
mainNavigationView . ArchiveButtonVisible = BeWoApp . LoggedOnUser . HasRight ( UserRightType . Customer_AllowArchiving ) ;
2016-06-27 01:45:38 +02:00
mainNavigationView . ShowArchivedObjectsVisible = true ;
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox = new ComboBox ( ) ;
//supportConceptFilterComboBox.HorizontalAlignment = "Left";
//supportConceptFilterComboBox.FontFamily = "Microsoft Sans Serif";
//supportConceptFilterComboBox.Foreground = new SolidColorBrush(Color.FromRgb(210, 210, 210));
supportConceptFilterComboBox . FontSize = 12 ;
supportConceptFilterComboBox . Margin = new Thickness ( 10 , 0 , 0 , 0 ) ;
supportConceptFilterComboBox . MinWidth = 100 ;
//supportConceptFilterComboBox.DisplayMemberPath = "DisplayName";
//supportConceptFilterComboBox.SelectionChanged = "sortCombo_SelectionChanged";
supportConceptFilterComboBox . Style = FindResource ( "SortComboBox" ) as Style ;
2018-05-20 13:19:28 +02:00
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . CustomerView_View ) | | BeWoApp . LoggedOnUser . HasRight ( UserRightType . ViewAll ) )
2017-11-14 10:46:54 +01:00
{
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . Items . Add ( new CustomerFilterItem ( CustomerFilterEnum . All ) ) ;
}
2018-05-20 13:19:28 +02:00
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . Customer_ViewMyTeams ) )
2016-06-27 01:45:38 +02:00
{
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . Items . Add ( new CustomerFilterItem ( CustomerFilterEnum . TeamCustomer ) ) ;
2016-06-27 01:45:38 +02:00
}
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . Items . Add ( new CustomerFilterItem ( CustomerFilterEnum . MyCustomer ) ) ;
CustomerFilterItem selectedItem = null ;
2016-06-27 01:45:38 +02:00
2018-05-20 13:19:28 +02:00
switch ( BeWoApp . AppSettings . CustomerFilterSupportConcepts )
2016-06-27 01:45:38 +02:00
{
2017-11-17 22:24:00 +01:00
case CustomerFilterEnum . All :
2018-05-20 13:19:28 +02:00
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . CustomerView_View ) | | BeWoApp . LoggedOnUser . HasRight ( UserRightType . ViewAll ) )
2017-11-17 22:24:00 +01:00
{
selectedItem = new CustomerFilterItem ( CustomerFilterEnum . All ) ;
}
2018-05-20 13:19:28 +02:00
2017-11-17 22:24:00 +01:00
break ;
case CustomerFilterEnum . TeamCustomer :
2018-05-20 13:19:28 +02:00
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . CustomerView_View ) | |
BeWoApp . LoggedOnUser . HasRight ( UserRightType . ViewAll ) | |
BeWoApp . LoggedOnUser . HasRight ( UserRightType . Customer_ViewMyTeams ) )
2017-11-17 22:24:00 +01:00
{
selectedItem = new CustomerFilterItem ( CustomerFilterEnum . TeamCustomer ) ;
}
2018-05-20 13:19:28 +02:00
2017-11-17 22:24:00 +01:00
break ;
2016-06-27 01:45:38 +02:00
}
2018-05-20 13:19:28 +02:00
if ( selectedItem = = null )
2016-06-27 01:45:38 +02:00
{
2017-11-17 22:24:00 +01:00
selectedItem = new CustomerFilterItem ( CustomerFilterEnum . MyCustomer ) ;
2016-06-27 01:45:38 +02:00
}
2018-05-20 13:19:28 +02:00
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . SelectedItem = selectedItem ;
supportConceptFilterComboBox . SelectionChanged + = SupportConceptFilterComboBoxOnSelectionChanged ;
//chkShowOnlyMyCustomers = new CheckBox
// {
// FontSize = 12,
// Margin = new Thickness(10, 0, 0, 0),
// Content = Translator.Translate("Meine Klienten"),
// VerticalAlignment = VerticalAlignment.Center
// };
//chkShowOnlyTeamCustomers = new CheckBox
//{
// FontSize = 12,
// Margin = new Thickness(10, 0, 0, 0),
// Content = Translator.Translate("Klienten meines Teams"),
// VerticalAlignment = VerticalAlignment.Center
//};
//var b = FindResource("MainGroupBoxForegroundBrush") as Brush;
//if (b != null)
//{
// chkShowOnlyMyCustomers.Foreground = b;
// chkShowOnlyTeamCustomers.Foreground = b;
//}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) &&
// !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll))
//{
// chkShowOnlyMyCustomers.IsChecked = true;
// chkShowOnlyMyCustomers.IsEnabled = false;
//}
//else
//{
// chkShowOnlyMyCustomers.IsChecked = BeWoApp.AppSettings.ShowOnlyMyClients;
//}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) &&
// !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll))
//{
// chkShowOnlyTeamCustomers.IsChecked = true;
// chkShowOnlyTeamCustomers.IsEnabled = false;
//}
//else
//{
// chkShowOnlyTeamCustomers.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamClients;
//}
//chkShowOnlyMyCustomers.Click += chkShowOnlyMyCustomers_Click;
//chkShowOnlyTeamCustomers.Click += chkShowOnlyMyCustomers_Click;
//mainNavigationView.AddControlToSortPanel(chkShowOnlyMyCustomers);
//mainNavigationView.AddControlToSortPanel(chkShowOnlyTeamCustomers);
2018-05-20 13:19:28 +02:00
var lbl = new TextBlock
{
Text = "Filter:" ,
FontSize = 12 ,
Margin = new Thickness ( 8 , 2 , - 3 , 0 )
} ;
2017-11-17 22:24:00 +01:00
2018-05-20 13:19:28 +02:00
mainNavigationView . sortPanel . Children . Insert ( 3 , lbl ) ;
mainNavigationView . sortPanel . Children . Insert ( 4 , supportConceptFilterComboBox ) ;
2017-11-17 22:24:00 +01:00
UpdateCustomFilter ( ) ;
}
2016-06-27 01:45:38 +02:00
2017-11-17 22:24:00 +01:00
private void SupportConceptFilterComboBoxOnSelectionChanged ( object o , SelectionChangedEventArgs selectionChangedEventArgs )
{
2018-02-26 17:34:55 +01:00
BeWoApp . AppSettings . CustomerFilterSupportConcepts = ( ( CustomerFilterItem ) supportConceptFilterComboBox . SelectedItem ) ? . CustomerFilter ? ? CustomerFilterEnum . MyCustomer ;
2017-11-17 22:24:00 +01:00
BeWoApp . SaveAppSettings ( ) ;
2017-11-14 10:46:54 +01:00
2018-02-26 17:34:55 +01:00
UpdateCustomFilter ( ) ;
2016-06-27 01:45:38 +02:00
}
private CustomFilter CreateNewCustomFilter ( )
{
2018-02-26 17:34:55 +01:00
var filter = new CustomerNavigationFilter { CustomerFilter = ( ( CustomerFilterItem ) supportConceptFilterComboBox . SelectedItem ) ? . CustomerFilter ? ? CustomerFilterEnum . MyCustomer } ;
2016-06-27 01:45:38 +02:00
return filter ;
}
private void OnLoaded ( object sender , RoutedEventArgs e )
{
2019-09-27 15:55:01 +02:00
ServiceFacade . DoCustomerServiceAsync ( s = > s . ConvertToNewSubstitutionType ( ) , n = > this . Dispatch ( delegate
{
ReloadData ( false ) ;
} ) ) ;
2016-06-27 01:45:38 +02:00
}
private void UpdateCustomFilter ( )
{
mainNavigationView . CustomFilter = CreateNewCustomFilter ( ) ;
}
2018-05-20 13:19:28 +02:00
private void ChkShowOnlyMyCustomers_Click ( object sender , RoutedEventArgs e )
2016-06-27 01:45:38 +02:00
{
2017-11-17 22:24:00 +01:00
//if (chkShowOnlyMyCustomers.IsChecked != null)
// BeWoApp.AppSettings.ShowOnlyMyClients = chkShowOnlyMyCustomers.IsChecked.Value;
//if (chkShowOnlyTeamCustomers.IsChecked != null)
// BeWoApp.AppSettings.ShowOnlyTeamClients = chkShowOnlyTeamCustomers.IsChecked.Value;
2016-06-27 01:45:38 +02:00
BeWoApp . SaveAppSettings ( ) ;
UpdateCustomFilter ( ) ;
}
private bool mainNavigationView_ArchiveObject ( IFilterableDC obj )
{
var cdc = obj as CompactCustomerDC ;
if ( cdc ! = null )
2017-03-14 14:06:12 +01:00
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Klient '{0}' wirklich archivieren?" , cdc . FirstName + " " + cdc . LastName ) , "Archivieren" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
2016-06-27 01:45:38 +02:00
{
ServiceFacade . DoCustomerServiceAsync (
s = >
{
s . ArchiveCustomer ( cdc . CustomerOid , cdc . CustomerVersion ) ;
return cdc ;
} ,
cb = > cb . CustomerVersion + + ) ;
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
return true ;
2017-03-14 14:06:12 +01:00
}
2016-06-27 01:45:38 +02:00
}
return false ;
}
private void mainNavigationView_CreateNewObject ( )
{
VMFactory . CreateCustomerVMAsync ( cb = > this . Dispatch ( ( ) = > MainControl . NavigateTo ( new CustomerView ( cb ) { ParentView = this } ) ) ) ;
}
private bool mainNavigationView_DeleteObject ( IFilterableDC obj )
{
var cdc = obj as CompactCustomerDC ;
if ( cdc ! = null )
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Klient '{0}' wirklich löschen?" , cdc . FirstName + " " + cdc . LastName ) , "Löschen" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
2016-06-27 01:45:38 +02:00
{
CustomerInfoDC details = ServiceFacade . DoOperationsServiceSync ( s = > s . GetCustomerInfosForCustomerOid ( cdc . CustomerOid ) ) ;
bool delete = true ;
if ( details ! = null )
{
2018-01-08 22:29:10 +01:00
if ( ! string . IsNullOrEmpty ( details . CurrentSupportConcept ) & & details . CurrentSupportConcept . ToLower ( ) ! = Translator . Translate ( "Kein aktueller Hilfeplan" ) . ToLower ( ) )
2016-06-27 01:45:38 +02:00
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Für Klient '{0}' wurde bereits ein Hilfeplan angelegt. Der Hilfeplan wird dadurch auch gelöscht!\n Möchten Sie wirklich fortfahren und den Klient löschen?" , cdc . FirstName + " " + cdc . LastName ) , "Löschen" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . No )
2016-06-27 01:45:38 +02:00
{
delete = false ;
}
}
}
if ( delete )
{
2017-03-14 14:06:12 +01:00
2016-06-27 01:45:38 +02:00
ServiceFacade . DoCustomerServiceAsync (
2017-03-14 14:06:12 +01:00
s = >
{
s . DeactivateCustomer ( cdc . CustomerOid , cdc . CustomerVersion ) ;
return cdc ;
} , cb = > cb . CustomerVersion + + ) ;
2016-06-27 01:45:38 +02:00
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
return true ;
2017-03-14 14:06:12 +01:00
2016-06-27 01:45:38 +02:00
}
}
}
return false ;
}
private void mainNavigationView_ExcelExport ( object sender , EventArgs < IEnumerable < IFilterableDC > > e )
{
2017-11-06 10:30:25 +01:00
var path = BeWoApp . GetAndCreateUserAppDataPath ( ) + Translator . Translate ( "\\Klienten.xls" ) ;
2016-06-27 01:45:38 +02:00
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 . PrepareExcelFileCustomerExport ( mainNavigationView . DownloadLinkEngine . ExcelFileId , e . Data . Cast < CompactCustomerDC > ( ) . Select ( c = > c . CustomerOid ) . ToList ( ) ) , sf . FileName ) ) ;
}
private void mainNavigationView_OpenObject ( IFilterableDC obj )
{
var cdc = obj as CompactCustomerDC ;
if ( cdc ! = null )
{
VMFactory . CreateCustomerVMAsync ( cdc . CustomerOid , cb = > this . Dispatch ( ( ) = > MainControl . NavigateTo ( new CustomerView ( 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 . GetAllCustomersCompact ( BeWoApp . LoggedOnUser . Employee . EmployeeOid ) ,
r = > this . Dispatch ( delegate
2019-09-27 15:55:01 +02:00
{
objectList = r ;
mainNavigationView . ShowSearchResult ( objectList ) ;
} ) ) ;
2016-06-27 01:45:38 +02:00
ServiceFacade . DoCustomerServiceAsync ( s = > s . GetLastOpenedCustomers ( ) ,
r = >
2018-02-26 17:34:55 +01:00
this . Dispatch ( delegate
{
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . CustomerView_View ) | | BeWoApp . LoggedOnUser . HasRight ( UserRightType . ViewAll ) )
{
recentList = r ;
}
else if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . Customer_ViewMyCustomers ) )
{
recentList = r . Where ( w = > BeWoApp . LoggedOnEmployee . RelatedCustomers . Select ( s3 = > s3 . Customer . CustomerOid ) . Contains ( w . CustomerOid ) ) ;
}
else
{
recentList = new List < IFilterableDC > ( ) ;
}
2016-06-27 01:45:38 +02:00
mainNavigationView . ShowHistory ( recentList ) ;
2018-02-26 17:34:55 +01:00
} )
) ;
2016-06-27 01:45:38 +02:00
}
else
{
mainNavigationView . ShowSearchResult ( objectList ) ;
mainNavigationView . ShowHistory ( recentList ) ;
}
}
private void Hyperlink_OnRequestNavigate ( object sender , RequestNavigateEventArgs e )
{
BeWoUtils . NavigateToReportUri ( ( ( Hyperlink ) sender ) . NavigateUri . ToString ( ) , "Druckvorschau" ) ;
}
private void MainNavigationView_OnOpenMailMergeWindow ( List < IFilterableDC > allCustomers , IFilterableDC selectedCustomer )
{
2018-05-20 13:19:28 +02:00
var mmw = new MailMergeWindow ( this , typeof ( CustomerDC ) , objectList . ToList ( ) , selectedCustomer ) { Sorter = new CustomerSorter ( ) } ;
2016-06-27 01:45:38 +02:00
mmw . Show ( ) ;
}
private void Hyperlink_Reaktivieren_Click ( object sender , RoutedEventArgs e )
{
2018-05-22 17:19:56 +02:00
var customer = ( CompactCustomerDC ) ( ( Hyperlink ) sender ) . Tag ;
2016-06-27 01:45:38 +02:00
2018-05-20 13:19:28 +02:00
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Klient '{0}' wirklich reaktivieren?" , customer . FirstName + " " + customer . LastName ) , "Reaktivieren" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . No )
2016-06-27 01:45:38 +02:00
{
return ;
}
ServiceFacade . DoCustomerServiceAsync ( s = >
{
2018-05-20 13:19:28 +02:00
s . ReactivateCustomer ( customer . CustomerOid , customer . CustomerVersion ) ;
return customer ;
2016-06-27 01:45:38 +02:00
} , cb = > cb . CustomerVersion + + ) ;
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
2018-05-20 13:19:28 +02:00
customer . ActivationType = ActivationTypeId . Active ;
2016-06-27 01:45:38 +02:00
var context = mainNavigationView . objectListBox . DataContext ;
mainNavigationView . objectListBox . DataContext = null ;
mainNavigationView . objectListBox . DataContext = context ;
}
2018-05-20 13:19:28 +02:00
private void Hyperlink_Anonymize_Click ( object sender , RoutedEventArgs e )
{
var customer = ( CompactCustomerDC ) ( ( Hyperlink ) sender ) . Tag ;
var dialog = new MessageDialog ( ( ) = >
{
this . Dispatch ( ( ) = >
{
ServiceFacade . DoOperationsServiceAsync ( s = >
{
s . AnonymizeCustomer ( customer . CustomerOid ) ;
} , ( ) = >
{
ReloadData ( true ) ;
} ) ;
} ) ;
} ) ;
ServiceFacade . DoOperationsServiceAsync ( s = > s . GetMessageFromServer ( TableID . Customer , customer . CustomerOid , MessageType . Anonymization ) , xaml = >
{
this . Dispatch ( ( ) = >
{
dialog . SetXaml ( xaml ) ;
dialog . ShowDialog ( ) ;
} ) ;
} ) ;
}
private void Hyperlink_Delete_For_Good_Click ( object sender , RoutedEventArgs e )
{
var customer = ( CompactCustomerDC ) ( ( Hyperlink ) sender ) . Tag ;
var dialog = new MessageDialog ( ( ) = >
{
this . Dispatch ( ( ) = >
{
ServiceFacade . DoOperationsServiceAsync ( s = >
{
s . DeleteCustomerForGood ( customer . CustomerOid ) ;
} , ( ) = > { ReloadData ( true ) ; } ) ;
} ) ;
} ) ;
ServiceFacade . DoOperationsServiceAsync ( s = > s . GetMessageFromServer ( TableID . Customer , customer . CustomerOid , MessageType . DeleteForGood ) , xaml = >
{
this . Dispatch ( ( ) = >
{
dialog . SetXaml ( xaml ) ;
dialog . ShowDialog ( ) ;
} ) ;
} ) ;
}
2016-06-27 01:45:38 +02:00
}
}