2017-11-17 22:24:00 +01:00
using System ;
using System.Collections.Generic ;
2016-06-27 01:45:38 +02:00
using System.IO ;
using System.Linq ;
using System.Windows ;
using System.Windows.Controls ;
using System.Windows.Media ;
using BeWo.Core ;
2017-11-17 22:24:00 +01:00
using BeWo.Core.Config ;
2016-06-27 01:45:38 +02:00
using BeWo.ServiceProxy ;
using BeWo.View.Detail ;
using BeWo.View.Navigation.Filter ;
using BeWo.View.Navigation.Sorter ;
using BeWo.ViewModel ;
using BS.Shared ;
using BS.Shared.Core ;
using BS.Shared.DataContracts ;
using BS.Shared.DataContracts.Compact ;
using BS.Shared.Extensions ;
using BeWo.Core.Service ;
2017-11-06 10:30:25 +01:00
using BeWo.MultiLanguage ;
using BS.Shared.Translation ;
2016-06-27 01:45:38 +02:00
using Microsoft.Win32 ;
namespace BeWo.View.Navigation
{
/// <summary>
/// Interaktionslogik für SupportConceptNavigationView.xaml
/// </summary>
public partial class SupportConceptNavigationView : BeWoView
{
2017-11-17 22:24:00 +01:00
//private readonly CheckBox chkShowOnlyMySCs;
2016-06-27 01:45:38 +02:00
2017-11-17 22:24:00 +01:00
//private readonly CheckBox chkShowOnlyTeamSCs;
private readonly ComboBox supportConceptFilterComboBox ;
2016-06-27 01:45:38 +02:00
private IEnumerable < IFilterableDC > objectList = null ;
private IEnumerable < IFilterableDC > recentList = null ;
public SupportConceptNavigationView ( )
{
this . InitializeComponent ( ) ;
this . mainNavigationView . Sorter = new SupportConceptSorter ( ) ;
this . mainNavigationView . ArchiveButtonVisible = BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConceptView_AllowArchiving ) ;
this . mainNavigationView . ShowArchivedObjectsVisible = true ;
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox = new ComboBox ( ) ;
supportConceptFilterComboBox . FontSize = 12 ;
supportConceptFilterComboBox . Margin = new Thickness ( 10 , 0 , 0 , 0 ) ;
supportConceptFilterComboBox . MinWidth = 100 ;
supportConceptFilterComboBox . Style = FindResource ( "SortComboBox" ) as Style ;
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConcept_ViewAllSupportConcepts ) | |
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 ) ) ;
2017-11-14 10:46:54 +01:00
}
2017-11-17 22:24:00 +01:00
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConcept_ViewMyTeams ) )
2017-11-14 10:46:54 +01:00
{
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . Items . Add ( new CustomerFilterItem ( CustomerFilterEnum . TeamCustomer ) ) ;
2017-11-14 10:46:54 +01:00
}
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . Items . Add ( new CustomerFilterItem ( CustomerFilterEnum . MyCustomer ) ) ;
2017-11-14 10:46:54 +01:00
2017-11-17 22:24:00 +01:00
CustomerFilterItem selectedItem = null ;
switch ( BeWoApp . AppSettings . CustomerFilterSupportConcepts )
2016-06-27 01:45:38 +02:00
{
2017-11-17 22:24:00 +01:00
case CustomerFilterEnum . All :
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConcept_ViewAllSupportConcepts ) | | BeWoApp . LoggedOnUser . HasRight ( UserRightType . ViewAll ) )
{
selectedItem = new CustomerFilterItem ( CustomerFilterEnum . All ) ;
}
break ;
case CustomerFilterEnum . TeamCustomer :
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConcept_ViewAllSupportConcepts ) | |
BeWoApp . LoggedOnUser . HasRight ( UserRightType . ViewAll ) | |
BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConcept_ViewMyTeams ) )
{
selectedItem = new CustomerFilterItem ( CustomerFilterEnum . TeamCustomer ) ;
}
break ;
2016-06-27 01:45:38 +02:00
}
2017-11-17 22:24:00 +01: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
}
2017-11-17 22:24:00 +01:00
supportConceptFilterComboBox . SelectedItem = selectedItem ;
supportConceptFilterComboBox . SelectionChanged + = SupportConceptFilterComboBoxOnSelectionChanged ;
2017-11-14 10:46:54 +01:00
2017-11-17 22:24:00 +01:00
//else
//{
// this.chkShowOnlyTeamSCs.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamSupportConcepts;
//}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams))
//{
// this.chkShowOnlyMySCs.IsChecked = true;
// this.chkShowOnlyMySCs.IsEnabled = false;
// this.chkShowOnlyTeamSCs.IsChecked = false;
// this.chkShowOnlyTeamSCs.IsEnabled = false;
//}
//else
//{
// this.chkShowOnlyMySCs.IsChecked = BeWoApp.AppSettings.ShowOnlyMySupportConcepts;
//}
//this.chkShowOnlyMySCs = new CheckBox();
//this.chkShowOnlyMySCs.FontSize = 12;
//this.chkShowOnlyMySCs.Margin = new Thickness(10, 0, 0, 0);
//this.chkShowOnlyMySCs.Content = Translator.Translate("Meine Hilfepläne");
//this.chkShowOnlyTeamSCs = new CheckBox();
//this.chkShowOnlyTeamSCs.FontSize = 12;
//this.chkShowOnlyTeamSCs.Margin = new Thickness(10, 0, 0, 0);
//this.chkShowOnlyTeamSCs.Content = Translator.Translate("Hilfepläne meines Teams");
//this.chkShowOnlyMySCs.VerticalAlignment = VerticalAlignment.Center;
//this.chkShowOnlyTeamSCs.VerticalAlignment = VerticalAlignment.Center;
//Brush b = this.FindResource("MainGroupBoxForegroundBrush") as Brush;
//if (b != null)
//{
// this.chkShowOnlyMySCs.Foreground = b;
// this.chkShowOnlyTeamSCs.Foreground = b;
//}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams))
//{
// this.chkShowOnlyTeamSCs.IsChecked = true;
// //this.chkShowOnlyMySCs.IsEnabled = false;
//}
//else
//{
// this.chkShowOnlyTeamSCs.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamSupportConcepts;
//}
//if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams))
//{
// this.chkShowOnlyMySCs.IsChecked = true;
// this.chkShowOnlyMySCs.IsEnabled = false;
// this.chkShowOnlyTeamSCs.IsChecked = false;
// this.chkShowOnlyTeamSCs.IsEnabled = false;
//}
//else
//{
// this.chkShowOnlyMySCs.IsChecked = BeWoApp.AppSettings.ShowOnlyMySupportConcepts;
//}
2017-11-14 10:46:54 +01:00
2016-06-27 01:45:38 +02:00
// if (BeWoApp.LoggedOnUser.Employee.IsTeamLeader)
// {
// chkShowOnlyTeamSCs.Visibility = Visibility.Visible;
// }
// else
// {
2017-11-17 22:24:00 +01:00
//this.chkShowOnlyTeamSCs.Visibility = Visibility.Collapsed;
2016-06-27 01:45:38 +02:00
// }
2017-11-17 22:24:00 +01:00
//this.chkShowOnlyMySCs.Click += this.chkShowOnlySCs_Click;
//this.chkShowOnlyTeamSCs.Click += this.chkShowOnlySCs_Click;
//this.mainNavigationView.AddControlToSortPanel(this.chkShowOnlyMySCs);
//this.mainNavigationView.AddControlToSortPanel(this.chkShowOnlyTeamSCs);
//this.mainNavigationView.AddControlToSortPanel(this.supportConceptFilterComboBox);
TextBlock lbl = new TextBlock ( ) ;
lbl . Text = "Filter:" ;
lbl . FontSize = 12 ;
lbl . Margin = new Thickness ( 8 , 2 , - 3 , 0 ) ;
this . mainNavigationView . sortPanel . Children . Insert ( 3 , lbl ) ;
this . mainNavigationView . sortPanel . Children . Insert ( 4 , this . supportConceptFilterComboBox ) ;
2016-06-27 01:45:38 +02:00
this . UpdateCustomFilter ( ) ;
if ( BeWoApp . LoggedOnUser . HasRight ( UserRightType . SupportConceptView_Create ) )
{
mainNavigationView . btnCopy . Visibility = Visibility . Visible ;
}
}
2017-11-17 22:24:00 +01:00
private void SupportConceptFilterComboBoxOnSelectionChanged ( object o , SelectionChangedEventArgs selectionChangedEventArgs )
{
//chkShowOnlyTeamSCs.IsChecked = false;
//BeWoApp.AppSettings.ShowOnlyMySupportConcepts = this.chkShowOnlyMySCs.IsChecked.Value;
if ( this . supportConceptFilterComboBox . SelectedItem ! = null )
{
BeWoApp . AppSettings . CustomerFilterSupportConcepts =
( ( CustomerFilterItem ) this . supportConceptFilterComboBox . SelectedItem ) . CustomerFilter ;
}
else
{
BeWoApp . AppSettings . CustomerFilterSupportConcepts = CustomerFilterEnum . MyCustomer ;
}
BeWoApp . SaveAppSettings ( ) ;
this . UpdateCustomFilter ( ) ;
}
2016-06-27 01:45:38 +02:00
private CustomFilter CreateNewCustomFilter ( )
{
SupportConceptNavigationFilter filter = new SupportConceptNavigationFilter ( ) ;
2017-11-17 22:24:00 +01:00
if ( this . supportConceptFilterComboBox . SelectedItem ! = null )
{
filter . CustomerFilter =
( ( CustomerFilterItem ) this . supportConceptFilterComboBox . SelectedItem ) . CustomerFilter ;
}
else
{
filter . CustomerFilter = CustomerFilterEnum . MyCustomer ;
}
//filter.ShowOnlyMySupportConcepts = this.chkShowOnlyMySCs.IsChecked.Value;
//filter.ShowOnlyTeamSupportConcepts = this.chkShowOnlyTeamSCs.IsChecked.Value;
2016-06-27 01:45:38 +02:00
return filter ;
}
private void OnLoaded ( object sender , RoutedEventArgs e )
{
ReloadData ( false ) ;
}
private void UpdateCustomFilter ( )
{
this . mainNavigationView . CustomFilter = this . CreateNewCustomFilter ( ) ;
}
2017-11-14 10:46:54 +01:00
2016-06-27 01:45:38 +02:00
private bool mainNavigationView_ArchiveObject ( IFilterableDC obj )
{
CompactSupportConceptDC dc = obj as CompactSupportConceptDC ;
if ( dc ! = null )
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Hilfeplan wirklich archivieren?" ) , "Archivieren" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
2016-06-27 01:45:38 +02:00
{
ServiceFacade . DoCustomerServiceAsync (
s = >
{
s . ArchiveSupportConcept ( dc . SupportConceptOid , dc . SupportConceptVersion ) ;
return dc ;
} ,
cb = > cb . SupportConceptVersion + + ) ;
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
return true ;
}
}
return false ;
}
private void mainNavigationView_CreateNewObject ( )
{
//VMFactory.CreateSupportConceptVMAsync(cb => this.Dispatch(() => this.MainControl.NavigateTo(new SupportConceptView2(cb) { ParentView = this })));
VMFactory . CreateSupportConceptVMAsync ( cb = > this . Dispatch ( ( ) = > this . MainControl . NavigateTo ( new SupportConceptView ( cb ) { ParentView = this } ) ) ) ;
}
private bool mainNavigationView_DeleteObject ( IFilterableDC obj )
{
var dc = obj as CompactSupportConceptDC ;
if ( dc ! = null )
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Hilfeplan wirklich löschen?" ) , "Löschen" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . Yes )
2016-06-27 01:45:38 +02:00
{
var list = ServiceFacade . DoOperationsServiceSync ( s = > s . GetSupportConceptInfosForSupportConceptOid ( dc . SupportConceptOid ) ) ;
var delete = true ;
if ( list ! = null & & list . Count > 0 )
{
var containsServiceRecords = false ;
foreach ( var info in list . Where ( info = > info . RecordedHours > 0 ) )
{
containsServiceRecords = true ;
}
if ( containsServiceRecords )
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Für den gewählten Hilfeplan wurden bereits Leistungen hinterlegt.\n Möchten Sie wirklich fortfahren und den Hilfeplan löschen?" ) , "Löschen" , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . No )
2016-06-27 01:45:38 +02:00
{
delete = false ;
}
}
}
if ( delete )
{
ServiceFacade . DoCustomerServiceAsync ( s = >
{
s . DeactivateSupportConcept ( dc . SupportConceptOid , dc . SupportConceptVersion ) ;
return dc ;
} , cb = > dc . Version + + ) ;
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
return true ;
}
}
}
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 ( "\\Hilfepläne.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 . PrepareExcelFileSupportConceptExport ( mainNavigationView . DownloadLinkEngine . ExcelFileId , e . Data . Cast < CompactSupportConceptDC > ( ) . Select ( c = > c . SupportConceptOid ) . ToList ( ) ) , sf . FileName ) ) ;
}
private void mainNavigationView_OpenObject ( IFilterableDC obj )
{
var dc = obj as CompactSupportConceptDC ;
if ( dc ! = null )
{
VMFactory . CreateSupportConceptVMAsync ( dc . SupportConceptOid , cb = > this . Dispatch ( ( ) = > MainControl . NavigateTo ( new SupportConceptView ( cb ) { ParentView = this } ) ) ) ;
//VMFactory.CreateSupportConceptVMAsync(dc.SupportConceptOid, cb => this.Dispatch(
// () => this.MainControl.NavigateTo(new SupportConceptView2(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 . GetAllSupportConceptsCompact ( BeWoApp . LoggedOnUser . Employee . EmployeeOid ) , r = > this . Dispatch ( delegate
{
objectList = r ;
mainNavigationView . ShowSearchResult ( objectList ) ;
} ) ) ;
ServiceFacade . DoCustomerServiceAsync ( s = > s . GetLastOpenedSupportConcepts ( ) , r = > this . Dispatch ( delegate
{
recentList = r ;
mainNavigationView . ShowHistory ( recentList ) ;
} ) ) ;
}
else
{
mainNavigationView . ShowSearchResult ( objectList ) ;
mainNavigationView . ShowHistory ( recentList ) ;
}
}
private void MainNavigationView_OnOpenMailMergeWindow ( List < IFilterableDC > allSupportConcepts , IFilterableDC selectedSupportConcept )
{
var mmw = new MailMergeWindow ( this , typeof ( SupportConceptDC ) , objectList . ToList ( ) , selectedSupportConcept )
{
Sorter = new SupportConceptSorter ( )
} ;
mmw . Show ( ) ;
}
public void MainNavigationView_OnReactivateObject ( CompactSupportConceptDC selectedSupportConcept )
{
2017-11-06 10:30:25 +01:00
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Hilfeplan wirklich reaktivieren?" ) , Translator . Translate ( "Reaktivieren" ) , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . No )
2016-06-27 01:45:38 +02:00
{
return ;
}
ServiceFacade . DoCustomerServiceAsync ( s = >
{
s . ReactivateSupportConcept ( selectedSupportConcept . SupportConceptOid , selectedSupportConcept . Version ) ;
return selectedSupportConcept ;
} , cb = > cb . SupportConceptVersion + + ) ;
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
selectedSupportConcept . ActivationType = ActivationTypeId . Active ;
var context = mainNavigationView . objectListBox . DataContext ;
mainNavigationView . objectListBox . DataContext = null ;
mainNavigationView . objectListBox . DataContext = context ;
}
2022-08-11 17:42:18 +02:00
public void MainNavigationView_AusArchivHolen ( CompactSupportConceptDC selectedSupportConcept )
{
if ( MessageBox . Show ( Translator . Translate ( "Wollen Sie den Hilfeplan wirklich aus dem Archiv holen?" ) , Translator . Translate ( "Aus Archiv holen" ) , MessageBoxButton . YesNo , MessageBoxImage . Exclamation ) = = MessageBoxResult . No )
{
return ;
}
ServiceFacade . DoCustomerServiceAsync ( s = >
{
s . ReactivateSupportConcept ( selectedSupportConcept . SupportConceptOid , selectedSupportConcept . Version ) ;
return selectedSupportConcept ;
} , cb = > cb . SupportConceptVersion + + ) ;
Cache . GetInstance ( ) . ClearSupportConceptTree ( ) ;
selectedSupportConcept . ActivationType = ActivationTypeId . Active ;
var context = mainNavigationView . objectListBox . DataContext ;
mainNavigationView . objectListBox . DataContext = null ;
mainNavigationView . objectListBox . DataContext = context ;
}
2016-06-27 01:45:38 +02:00
private void MainNavigation_CopyObject ( IFilterableDC obj )
{
var csc = ( CompactSupportConceptDC ) obj ;
var copy = new SupportConceptDC ( ) ;
ServiceFacade . DoCustomerServiceAsync ( s = > s . LoadSupportConcept ( csc . SupportConceptOid ) , cb = >
{
copy . ActivationType = ActivationTypeId . Active ;
copy . Conference = cb . Conference ;
copy . ConferenceVenue = cb . ConferenceVenue ;
copy . ConsultingNeeded = cb . ConsultingNeeded ;
copy . Customer = cb . Customer ;
copy . Notice = cb . Notice ;
copy . Originator = cb . Originator ;
copy . ServiceAccountings = new List < ServiceAccountingDC > ( ) ;
foreach ( var kategorie in cb . ServiceAccountings )
{
var kat = new ServiceAccountingDC
{
AccountingInterval = kategorie . AccountingInterval ,
BillableAmount = kategorie . BillableAmount ,
IsDefault = kategorie . IsDefault ,
ServiceDescription = kategorie . ServiceDescription
} ;
copy . ServiceAccountings . Add ( kat ) ;
}
foreach ( var kt in cb . CostBearerRelations )
{
var rel = new SupportConceptCostBearerRelDC
{
CostBearer = kt . CostBearer ,
CostBearerContactPerson = kt . CostBearerContactPerson ,
CustomerReferenceNumber = kt . CustomerReferenceNumber ,
Notice = kt . Notice ,
Status = CostBearer2SupportConceptStatus . Created ,
2023-03-14 18:12:07 +01:00
SupportConcept = kt . SupportConcept
2016-06-27 01:45:38 +02:00
} ;
2023-03-14 18:12:07 +01:00
if ( kt . ApprovalPeriodList ! = null & & kt . ApprovalPeriodList . Count > 0 )
{
var ap1 = kt . ApprovalPeriodList [ 0 ] ;
rel . ApprovalPeriodList = new List < SupportConceptApprovalPeriodDC > ( ) ;
2016-06-27 01:45:38 +02:00
2023-03-14 18:12:07 +01:00
var newap = new SupportConceptApprovalPeriodDC
{
IsApprovedBEShifting = ap1 . IsApprovedBEShifting ,
IsApprovedFixedAmountShifting = ap1 . IsApprovedFixedAmountShifting ,
ApprovedBEInterval = ap1 . ApprovedBEInterval
} ;
if ( ap1 . SupportConceptApprovalPeriodEmployeeRelations ! = null )
{
newap . SupportConceptApprovalPeriodEmployeeRelations = new List < SupportConceptApprovalPeriodEmployeeRelDC > ( ) ;
foreach ( var item in ap1 . SupportConceptApprovalPeriodEmployeeRelations )
{
newap . SupportConceptApprovalPeriodEmployeeRelations . Add ( new SupportConceptApprovalPeriodEmployeeRelDC
{
Betreuungsschluessel = item . Betreuungsschluessel ,
Employee = item . Employee ,
IsAbsolut = item . IsAbsolut
} ) ;
}
}
rel . ApprovalPeriodList . Add ( newap ) ;
}
2016-06-27 01:45:38 +02:00
copy . CostBearerRelations . Add ( rel ) ;
}
copy . Goals = new List < ValueListEntryDC > ( cb . Goals ) ;
VMFactory . CreateSupportConceptVMAsync ( copy , sc = > this . Dispatch ( ( ) = >
this . MainControl . NavigateTo ( new SupportConceptView ( sc ) { ParentView = this } ) ) , true ) ;
//ServiceFacade.DoCustomerServiceAsync(s2 => s2.InsertNewSupportConcept(copy), l => this.Dispatch(() => ReloadData(true)));
} ) ;
}
}
}