2016-06-27 01:45:38 +02:00
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Windows ;
2018-02-26 17:34:55 +01:00
2016-06-27 01:45:38 +02:00
using BeWo.Core ;
using BeWo.ServiceProxy ;
using BeWo.View.Detail ;
using BeWo.View.Navigation.Sorter ;
using BeWo.ViewModel ;
2018-02-26 17:34:55 +01:00
using BS.Shared ;
2016-06-27 01:45:38 +02:00
using BS.Shared.Core ;
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
using BS.Shared.Extensions ;
2018-02-26 17:34:55 +01:00
2016-06-27 01:45:38 +02:00
using Microsoft.Win32 ;
namespace BeWo.View.Navigation
{
2018-02-26 17:34:55 +01:00
public partial class TeamNavigationView
2016-06-27 01:45:38 +02:00
{
2018-02-26 17:34:55 +01:00
private IEnumerable < IFilterableDC > objectList ;
private IEnumerable < IFilterableDC > recentList ;
2016-06-27 01:45:38 +02:00
public TeamNavigationView ( )
{
2018-02-26 17:34:55 +01:00
InitializeComponent ( ) ;
2016-06-27 01:45:38 +02:00
//###CB SERIENBRIEF mainNavigationView.MailMergeButton.Visibility = Visibility.Collapsed;
2018-02-26 17:34:55 +01:00
mainNavigationView . Sorter = new TeamSorter ( ) ;
mainNavigationView . ShowArchivedObjectsVisible = false ;
2016-06-27 01:45:38 +02:00
}
private void OnLoaded ( object sender , RoutedEventArgs e )
{
ReloadData ( false ) ;
}
private void mainNavigationView_CreateNewObject ( )
{
VMFactory . CreateTeamVMAsync ( cb = > this . Dispatch ( delegate { this . MainControl . NavigateTo ( new TeamView ( cb ) { ParentView = this } ) ; } ) ) ;
}
private bool mainNavigationView_DeleteObject ( IFilterableDC obj )
{
2018-02-26 17:34:55 +01:00
if ( obj is CompactTeamDC dc )
2016-06-27 01:45:38 +02:00
{
if ( MessageBox . Show ( "Wollen Sie das Team '" + dc . Name + "' wirklich löschen?" , "Löschen" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
{
ServiceFacade . DoEmployeeServiceAsync ( s = > s . DeactivateTeam ( dc . TeamOid , dc . TeamVersion ) ) ;
return true ;
}
}
return false ;
}
private void mainNavigationView_ExcelExport ( object sender , EventArgs < IEnumerable < IFilterableDC > > e )
{
var path = BeWoApp . GetAndCreateUserAppDataPath ( ) + "\\Teams.xls" ;
var sf = new SaveFileDialog { FileName = Path . GetFileName ( path ) , Filter = "Microsoft Excel 97-2003-Arbeitsblatt|*.xls|Alle Dateien|*.*" } ;
if ( sf . ShowDialog ( ) ! = true )
2018-02-26 17:34:55 +01:00
{
2016-06-27 01:45:38 +02:00
return ;
2018-02-26 17:34:55 +01:00
}
2016-06-27 01:45:38 +02:00
ServiceFacade . DoDownloadServiceSync ( s = > BeWoUtils . WriteExcelFile ( s . PrepareExcelFileTeamExport ( mainNavigationView . DownloadLinkEngine . ExcelFileId , e . Data . Cast < CompactTeamDC > ( ) . Select ( c = > c . TeamOid ) . ToList ( ) ) , sf . FileName ) ) ;
}
private void mainNavigationView_OpenObject ( IFilterableDC obj )
{
2018-02-26 17:34:55 +01:00
if ( obj is CompactTeamDC dc )
2016-06-27 01:45:38 +02:00
{
2018-02-26 17:34:55 +01:00
VMFactory . CreateTeamVMAsync ( dc . TeamOid , cb = > this . Dispatch ( delegate { MainControl . NavigateTo ( new TeamView ( cb ) { ParentView = this } ) ; } ) ) ;
2016-06-27 01:45:38 +02:00
}
}
public override void ChildViewClosed ( )
{
recentList = null ;
objectList = null ;
}
private void MainNavigationView_OnReloadData ( )
{
ReloadData ( true ) ;
}
private void ReloadData ( bool refresh )
{
if ( refresh | | recentList = = null )
{
2018-02-26 17:34:55 +01:00
ServiceFacade . DoEmployeeServiceAsync ( s = > s . GetAllTeamsCompact ( ) , r = >
this . Dispatch ( delegate
{
objectList = r ;
mainNavigationView . ShowSearchResult ( objectList ) ;
} ) ) ;
ServiceFacade . DoEmployeeServiceAsync ( s = > s . GetLastOpenedTeams ( ) , r = >
this . Dispatch ( delegate
{
ServiceFacade . DoEmployeeServiceAsync ( sx = > sx . GetTeamOidsByEmployee ( BeWoApp . LoggedOnEmployee . EmployeeOid . Value ) , cbx = > this . Dispatch ( delegate
{
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . TeamView_ViewAll ) )
{
recentList = r ;
}
else if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . TeamView_ViewMyTeams ) )
{
recentList = r . Where ( w = > ! cbx . Contains ( w ) ) ;
}
else
{
recentList = new List < IFilterableDC > ( ) ;
}
recentList = r ;
mainNavigationView . ShowHistory ( recentList ) ;
} ) ) ;
} ) ) ;
2016-06-27 01:45:38 +02:00
}
else
{
2018-02-26 17:34:55 +01:00
mainNavigationView . ShowSearchResult ( objectList ) ;
mainNavigationView . ShowHistory ( recentList ) ;
2016-06-27 01:45:38 +02:00
}
}
}
}