298 lines
12 KiB
C#
298 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Navigation;
|
|
|
|
using BeWo.Core;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.View.Detail;
|
|
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 BS.Shared.Translation;
|
|
|
|
using Microsoft.Win32;
|
|
|
|
namespace BeWo.View.Navigation
|
|
{
|
|
public partial class EmployeeNavigationView
|
|
{
|
|
|
|
private IEnumerable<IFilterableDC> objectList;
|
|
private IEnumerable<IFilterableDC> recentList;
|
|
|
|
public EmployeeNavigationView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
//if (BeWoApp.UserName == "BSAdmin" && BeWoApp.UserPassword.IndexOf("P!d") > 0)
|
|
//{
|
|
// this.mainNavigationView.EditButtonsVisible = true;
|
|
//}
|
|
//else
|
|
//{
|
|
// this.mainNavigationView.EditButtonsVisible = false;
|
|
//}
|
|
|
|
mainNavigationView.Sorter = new EmployeeSorter();
|
|
//this.linkNewLicense.NavigateUri = new Uri("http://www.bewoplaner.de/bewoplaner_mitarbeiter.html?ClientOID=" + BeWoApp.Tenant);
|
|
//if (BeWoApp.LoggedOnUser.HasRight(UserRightType.EmployeeView_Edit))
|
|
// textblock_link.Visibility = Visibility.Visible;
|
|
|
|
//###CB SERIENBRIEF mainNavigationView.MailMergeButton.Visibility = Visibility.Collapsed;
|
|
|
|
mainNavigationView.EditButtonsVisible = true;
|
|
mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Employee_AllowArchiving);
|
|
mainNavigationView.DeleteButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.EmployeeView_Delete) || BeWoApp.LoggedOnUser.HasRight(UserRightType.DeleteAll);
|
|
|
|
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.User_AllowOrderLicense))
|
|
{
|
|
var url = ServiceFacade.DoOperationsServiceSync(s => s.GetLicenseOrderUrl());
|
|
|
|
if (!String.IsNullOrEmpty(url))
|
|
{
|
|
this.linkNewLicense.NavigateUri = new Uri(url);
|
|
}
|
|
else
|
|
{
|
|
textblock_link.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
textblock_link.Visibility = Visibility.Collapsed;
|
|
}
|
|
}
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
ReloadData(false);
|
|
}
|
|
|
|
private bool MainNavigationView_ArchiveObject(IFilterableDC obj)
|
|
{
|
|
if (obj is CompactEmployeeDC dc)
|
|
{
|
|
if (MessageBox.Show(Translator.Translate("Wollen Sie den Mitarbeiter '{0}' wirklich archivieren?", dc.FirstName + " " + dc.LastName), "Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
|
|
{
|
|
ServiceFacade.DoEmployeeServiceAsync(
|
|
s =>
|
|
{
|
|
s.ArchiveEmployee(dc.EmployeeOid, dc.EmployeeVersion);
|
|
return dc;
|
|
},
|
|
cb => cb.EmployeeVersion++);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void MainNavigationView_CreateNewObject()
|
|
{
|
|
var licenseInfo = ServiceFacade.DoOperationsServiceSync(s => s.GetLicenseInfo());
|
|
|
|
if (licenseInfo.EmployeeCount < licenseInfo.MaxEmployeeCount)
|
|
{
|
|
VMFactory.CreateEmployeeVMAsync(cb => this.Dispatch(delegate { MainControl.NavigateTo(new EmployeeView(cb) { ParentView = this }); }));
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Leider verfügen Sie nicht über genügend Lizenzen, um einen neuen Mitarbeiter anzulegen.\n\n"+
|
|
string.Format("Sie verfügen derzeit über {0} kostenpflichtige Benutzerlizenzen, somit können Sie maximal {1} Mitarbeiter anlegen.\n({0} Benutzer + {2} % = {1} Mitarbeiterlizenzen).", licenseInfo.MaxLicenseCount, licenseInfo.MaxEmployeeCount, licenseInfo.PercentFreeEmployee)+
|
|
"\n\nSie können nun entweder Mitarbeiter archivieren oder im Modul \"Benutzer\" neue Benutzerlizenzen bestellen. Bitte beachten Sie, dass hierfür das Recht \"Neue Lizenz bestellen\" erforderlich ist.", "Mitarbeiter anlegen", MessageBoxButton.OK,
|
|
MessageBoxImage.Information);
|
|
}
|
|
}
|
|
|
|
private bool MainNavigationView_DeleteObject(IFilterableDC obj)
|
|
{
|
|
if (obj is CompactEmployeeDC dc)
|
|
{
|
|
if (MessageBox.Show(Translator.Translate("Wollen Sie den Mitarbeiter '{0}' wirklich löschen?", dc.FirstName + " " + dc.LastName), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
|
|
{
|
|
ServiceFacade.DoEmployeeServiceAsync(s => s.DeactivateEmployee(dc.EmployeeOid, dc.EmployeeVersion));
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void MainNavigationView_ExcelExport(object sender, EventArgs<IEnumerable<IFilterableDC>> e)
|
|
{
|
|
var path = BeWoApp.GetAndCreateUserAppDataPath() + Translator.Translate("\\Mitarbeiter.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.PrepareExcelFileEmployeeExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast<CompactEmployeeDC>().Select(c => c.EmployeeOid).ToList()), sf.FileName));
|
|
}
|
|
|
|
private void MainNavigationView_OpenObject(IFilterableDC obj)
|
|
{
|
|
if (obj is CompactEmployeeDC dc)
|
|
{
|
|
VMFactory.CreateEmployeeVMAsync(dc.EmployeeOid, cb => this.Dispatch(delegate { MainControl.NavigateTo(new EmployeeView(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.DoEmployeeServiceAsync(s => s.GetAllCompactEmployees(), r =>
|
|
this.Dispatch(delegate
|
|
{
|
|
if(BeWoApp.LoggedOnUser.HasRight(UserRightType.EmployeeView_View))
|
|
{
|
|
objectList = r;
|
|
}
|
|
else if(BeWoApp.LoggedOnUser.HasRight(UserRightType.Employee_AllowViewOwnTeam))
|
|
{
|
|
objectList = r.Where(emp => emp.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid || BeWoApp.LoggedOnUser.Employee.AllTeamMemberOids != null && BeWoApp.LoggedOnUser.Employee.AllTeamMemberOids.Contains(emp.EmployeeOid));
|
|
}
|
|
else if(BeWoApp.LoggedOnUser.HasRight(UserRightType.Employee_AllowViewOwnEmployees))
|
|
{
|
|
objectList = r.Where(emp => emp.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid);
|
|
}
|
|
else
|
|
{
|
|
objectList = new List<IFilterableDC>();
|
|
}
|
|
|
|
mainNavigationView.ShowSearchResult(objectList);
|
|
}));
|
|
|
|
ServiceFacade.DoEmployeeServiceAsync(s => s.GetLastOpenedEmployees(), lastOpenedEmployees =>
|
|
this.Dispatch(delegate
|
|
{
|
|
if(BeWoApp.LoggedOnUser.HasRight(UserRightType.EmployeeView_View))
|
|
{
|
|
recentList = lastOpenedEmployees;
|
|
}
|
|
else if(BeWoApp.LoggedOnUser.HasRight(UserRightType.Employee_AllowViewOwnTeam))
|
|
{
|
|
recentList = lastOpenedEmployees.Where(w => w.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid || BeWoApp.LoggedOnUser.Employee.AllTeamMemberOids != null && BeWoApp.LoggedOnUser.Employee.AllTeamMemberOids.Contains(w.EmployeeOid));
|
|
}
|
|
else if(BeWoApp.LoggedOnUser.HasRight(UserRightType.Employee_AllowViewOwnEmployees))
|
|
{
|
|
recentList = lastOpenedEmployees.Where(w => w.EmployeeOid == BeWoApp.LoggedOnEmployee.EmployeeOid);
|
|
}
|
|
else
|
|
{
|
|
recentList = new List<IFilterableDC>();
|
|
}
|
|
|
|
mainNavigationView.ShowHistory(recentList);
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
mainNavigationView.ShowSearchResult(objectList);
|
|
mainNavigationView.ShowHistory(recentList);
|
|
}
|
|
}
|
|
|
|
private void LinkNewLicense_OnRequestNavigate(object sender, RequestNavigateEventArgs e)
|
|
{
|
|
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(((Hyperlink) sender).NavigateUri.ToString()));
|
|
}
|
|
|
|
public void ReactivateEmployee(CompactEmployeeDC pEmployee)
|
|
{
|
|
if(MessageBox.Show("Wollen Sie den Mitarbeiter '" + pEmployee.FirstName + " " + pEmployee.LastName + "' wirklich reaktivieren?", "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ServiceFacade.DoEmployeeServiceAsync(s =>
|
|
{
|
|
s.ReactivateEmployee(pEmployee.EmployeeOid, pEmployee.Version);
|
|
return pEmployee;
|
|
}, cb => cb.EmployeeVersion++);
|
|
|
|
pEmployee.ActivationType = ActivationTypeId.Active;
|
|
var context = mainNavigationView.objectListBox.DataContext;
|
|
mainNavigationView.objectListBox.DataContext = null;
|
|
mainNavigationView.objectListBox.DataContext = context;
|
|
}
|
|
|
|
public void AnonymizeEmployee(CompactEmployeeDC pEmployee)
|
|
{
|
|
var dialog = new MessageDialog(() =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
ServiceFacade.DoOperationsServiceAsync(s =>
|
|
{
|
|
s.AnonymizeEmployee(pEmployee.EmployeeOid);
|
|
}, () => { ReloadData(true); });
|
|
});
|
|
});
|
|
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Employee, pEmployee.EmployeeOid, MessageType.Anonymization), xaml =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
dialog.SetXaml(xaml);
|
|
dialog.ShowDialog();
|
|
});
|
|
});
|
|
}
|
|
|
|
public void DeleteEmployeeForGood(CompactEmployeeDC pEmployee)
|
|
{
|
|
var dialog = new MessageDialog(() =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
ServiceFacade.DoOperationsServiceAsync(s =>
|
|
{
|
|
s.DeleteEmployeeForGood(pEmployee.EmployeeOid);
|
|
}, () => { ReloadData(true); });
|
|
});
|
|
});
|
|
|
|
ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Employee, pEmployee.EmployeeOid, MessageType.DeleteForGood), xaml =>
|
|
{
|
|
this.Dispatch(() =>
|
|
{
|
|
dialog.SetXaml(xaml);
|
|
dialog.ShowDialog();
|
|
});
|
|
});
|
|
}
|
|
|
|
public void PrintEmployee(CompactEmployeeDC employee)
|
|
{
|
|
string url = BeWoApp.SiteOfOrigin + "/ReportView.aspx?eOid=" + employee.EmployeeOid + "&type=" + Utils.EnumName(ReportTypes.Employee);
|
|
|
|
BeWoUtils.NavigateToReportUri(url, "Druckvorschau");
|
|
}
|
|
|
|
}
|
|
} |