2025-04-15 14:23:25 +02:00
using System.Collections ;
using System.Collections.Generic ;
2016-06-27 01:45:38 +02:00
using System.IO ;
using System.Linq ;
using System.Windows ;
2025-04-15 14:23:25 +02:00
using System.Windows.Input ;
2016-06-27 01:45:38 +02:00
using BeWo.Core ;
2025-06-10 16:15:34 +02:00
using BeWo.Core.Commands ;
2016-06-27 01:45:38 +02:00
using BeWo.Core.Service ;
using BeWo.ServiceProxy ;
using BeWo.View.Detail ;
using BeWo.View.Navigation.Sorter ;
using BeWo.ViewModel ;
2025-11-05 11:49:53 +01:00
using BeWo.ViewModel.View.AI ;
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 ;
2025-04-15 14:23:25 +02:00
using DevExpress.Mvvm ;
2016-06-27 01:45:38 +02:00
using Microsoft.Win32 ;
namespace BeWo.View.Navigation
{
/// <summary>
/// Interaktionslogik für OrganisationNavigationView.xaml
/// </summary>
public partial class OrganisationNavigationView : BeWoView
{
private IEnumerable < IFilterableDC > objectList = null ;
private IEnumerable < IFilterableDC > recentList = null ;
public OrganisationNavigationView ( )
{
2025-04-15 14:23:25 +02:00
InitializeComponent ( ) ;
2016-06-27 01:45:38 +02:00
2025-06-10 16:15:34 +02:00
mainNavigationView . OpenAiWindowCommand = CommandFactory . GetAiViewCommand ( OpenAiWindow , UserRightType . AiModuleView ) ;
mainNavigationView . OpenAiPopupCommand = CommandFactory . GetAiViewCommand ( OpenAiPopup , UserRightType . AiModuleView2 ) ;
2016-06-27 01:45:38 +02:00
2025-04-15 14:23:25 +02:00
mainNavigationView . Sorter = new OrganisationSorter ( ) ;
mainNavigationView . ArchiveButtonVisible =
2016-06-27 01:45:38 +02:00
BeWoApp . LoggedOnUser . HasRight ( UserRightType . Organisation_AllowArchiving ) ;
2025-04-15 14:23:25 +02:00
mainNavigationView . ShowArchivedObjectsVisible = true ;
2016-06-27 01:45:38 +02:00
}
private void OnLoaded ( object sender , RoutedEventArgs e )
{
ReloadData ( false ) ;
2025-04-15 14:23:25 +02:00
CommandManager . InvalidateRequerySuggested ( ) ;
}
public Dictionary < TableID , long [ ] > GetVisibleInformationReferences ( )
{
var visible = mainNavigationView . objectListBox . ItemsSource ;
return GetVisibleInformationReferences ( visible ) ;
}
private Dictionary < TableID , long [ ] > GetVisibleInformationReferences ( IEnumerable visible_persons )
{
var oids = new List < long > ( ) ;
foreach ( var p in visible_persons )
{
var orga = p as CompactOrganisationDC ;
oids . Add ( orga . OrganisationOid ) ;
}
var dict = new Dictionary < TableID , long [ ] > ( ) {
{
2025-08-07 16:40:07 +02:00
TableID . Organisation , oids . Distinct ( ) . ToArray ( ) }
2025-04-15 14:23:25 +02:00
} ;
return dict ;
}
2025-05-14 10:05:15 +02:00
private AiConversationChatViewModel getAiConversationChatViewModel ( )
2025-04-15 14:23:25 +02:00
{
var context = GetVisibleInformationReferences ( ) ;
2025-09-08 15:17:51 +02:00
var vm = VMFactory . CreateAiConversationChatViewModel ( AiContextType . OrganisationNavigation , context ) ;
2025-05-14 10:05:15 +02:00
return vm ;
2025-04-15 14:23:25 +02:00
}
2025-05-14 10:05:15 +02:00
private void OpenAiWindow ( )
2025-04-15 14:23:25 +02:00
{
2025-05-14 10:05:15 +02:00
MainControl . WindowService . ShowAiConversationWindow ( getAiConversationChatViewModel ( ) ) ;
}
2025-04-15 14:23:25 +02:00
2025-05-14 10:05:15 +02:00
private void OpenAiPopup ( )
{
MainControl . WindowService . ShowAiConversationModalViewWindow ( getAiConversationChatViewModel ( ) ) ;
2025-04-15 14:23:25 +02:00
}
private void mainNavigationView_CreateNewObject ( )
2016-06-27 01:45:38 +02:00
{
VMFactory . CreateOrganisationVMAsync ( cb = > this . Dispatch ( delegate { this . MainControl . NavigateTo ( new OrganisationView ( cb ) { ParentView = this } ) ; } ) ) ;
}
private bool mainNavigationView_DeleteObject ( IFilterableDC obj )
{
CompactOrganisationDC dc = obj as CompactOrganisationDC ;
if ( dc ! = null )
{
if ( MessageBox . Show ( "Wollen Sie die Organisation '" + dc . Name + "' wirklich löschen?" , "Löschen" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
{
ServiceFacade . DoCustomerServiceAsync ( s = > s . DeactivateOrganisation ( dc . OrganisationOid , dc . OrganisationVersion ) ) ;
return true ;
}
}
return false ;
}
private bool mainNavigationView_ArchiveObject ( IFilterableDC obj )
{
CompactOrganisationDC dc = obj as CompactOrganisationDC ;
if ( dc ! = null )
{
if ( MessageBox . Show ( "Wollen Sie die Organisation '" + dc . Name + "' wirklich archivieren?" , "Archivieren" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
{
ServiceFacade . DoCustomerServiceAsync (
s = >
{
s . ArchiveOrganisation ( dc . OrganisationOid , dc . OrganisationVersion ) ;
return dc ;
} ,
cb = > cb . OrganisationVersion + + ) ;
return true ;
}
}
return false ;
}
private void mainNavigationView_ExcelExport ( object sender , EventArgs < IEnumerable < IFilterableDC > > e )
{
var path = BeWoApp . GetAndCreateUserAppDataPath ( ) + "\\Organisationen.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 . PrepareExcelFileOrganisationExport ( mainNavigationView . DownloadLinkEngine . ExcelFileId , e . Data . Cast < CompactOrganisationDC > ( ) . Select ( c = > c . OrganisationOid ) . ToList ( ) ) , sf . FileName ) ) ;
}
2023-10-18 17:50:40 +02:00
private void mainNavigationView_Print ( object sender , EventArgs < IEnumerable < IFilterableDC > > e )
{
var oids = e . Data . Cast < CompactOrganisationDC > ( ) . Select ( c = > c . OrganisationOid ) . ToList ( ) ;
ServiceFacade . DoReportServiceAsync ( s = > s . CreateOrganisationListReport ( oids ) , r = >
{
this . Dispatch ( ( ) = >
{
BeWoUtils . ShowReportWindow ( r , "Organisationen" ) ;
} ) ;
} ) ;
}
2016-06-27 01:45:38 +02:00
private void mainNavigationView_OpenObject ( IFilterableDC obj )
{
CompactOrganisationDC dc = obj as CompactOrganisationDC ;
if ( dc ! = null )
{
VMFactory . CreateOrganisationVMAsync ( dc . OrganisationOid , cb = > this . Dispatch ( delegate { this . MainControl . NavigateTo ( new OrganisationView ( 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 . GetAllOrganisationsCompact ( ) , r = > this . Dispatch ( delegate
{
objectList = r . Cast < IFilterableDC > ( ) ;
this . mainNavigationView . ShowSearchResult ( objectList ) ;
} ) ) ;
ServiceFacade . DoCustomerServiceAsync ( s = > s . GetLastOpenedOrganisations ( ) , r = > this . Dispatch ( delegate
{
recentList = r . Cast < IFilterableDC > ( ) ;
this . mainNavigationView . ShowHistory ( recentList ) ;
} ) ) ;
}
else
{
this . mainNavigationView . ShowSearchResult ( objectList ) ;
this . mainNavigationView . ShowHistory ( recentList ) ;
}
}
private void MainNavigationView_OnOpenMailMergeWindow ( List < IFilterableDC > allOrganisations , IFilterableDC selectedOrganisation )
{
var mmw = new MailMergeWindow ( this , typeof ( OrganisationDC ) , objectList . ToList ( ) , selectedOrganisation )
{
Sorter = new OrganisationSorter ( )
} ;
mmw . Show ( ) ;
}
public void ReactivateOrganisation ( CompactOrganisationDC organisation )
{
if ( MessageBox . Show ( "Wollen Sie die Organisation wirklich reaktivieren?" , "Reaktivieren" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . No )
{
return ;
}
ServiceFacade . DoCustomerServiceAsync ( s = >
{
s . ReactivateOrganisation ( organisation . OrganisationOid , organisation . Version ) ;
return organisation ;
} , cb = > cb . OrganisationVersion + + ) ;
organisation . ActivationType = ActivationTypeId . Active ;
var context = mainNavigationView . objectListBox . DataContext ;
mainNavigationView . objectListBox . DataContext = null ;
mainNavigationView . objectListBox . DataContext = context ;
}
}
}