Files
BeWoPlaner/BeWo/View/Navigation/WohnheimNavigationView.xaml.cs

183 lines
5.8 KiB
C#

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 Microsoft.Win32;
namespace BeWo.View.Navigation
{
/// <summary>
/// Interaktionslogik für EmployeeNavigationView.xaml
/// </summary>
public partial class WohnheimNavigationView : BeWoView
{
private List<CompactCustomerDC> _Customers;
private IEnumerable<IFilterableDC> objectList;// = null;
private IEnumerable<IFilterableDC> recentList = null;
public WohnheimNavigationView()
{
InitializeComponent();
//if (BeWoApp.UserName == "BSAdmin" && BeWoApp.UserPassword.IndexOf("P!d") > 0)
//{
// this.mainNavigationView.EditButtonsVisible = true;
//}
//else
//{
// this.mainNavigationView.EditButtonsVisible = false;
//}
wohnheimNavigationView.Sorter = new WohnheimSorter();
//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;
wohnheimNavigationView.EditButtonsVisible = true;
wohnheimNavigationView.DeleteButtonVisible = false;
wohnheimNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Wohnheim_AllowArchiving);
wohnheimNavigationView.chkShowDeleted.Visibility = Visibility.Collapsed;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
ReloadData(false);
}
private bool wohnheimNavigationView_ArchiveObject(IFilterableDC obj)
{
CompactWohnheimDC dc = obj as CompactWohnheimDC;
if (dc != null)
{
if (MessageBox.Show("Wollen Sie den Wohnheim '" + dc.WohnheimName + "' wirklich archivieren?", "Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
{
ServiceFacade.DoWohnheimServiceAsync(
s =>
{
s.ArchiveWohnheim(dc.WohnheimOid, dc.Version);
return dc;
},
cb => cb.Version++);
return true;
}
}
return false;
}
private void wohnheimNavigationView_CreateNewObject()
{
VMFactory.CreateWohnheimVMAsync(_Customers, cb => this.Dispatch(delegate { this.MainControl.NavigateTo(new WohnheimView(cb) { ParentView = this }); }));
}
private bool wohnheimNavigationView_DeleteObject(IFilterableDC obj)
{
CompactWohnheimDC dc = obj as CompactWohnheimDC;
if (dc != null)
{
if (MessageBox.Show("Wollen Sie den Wohnheim '" + dc.WohnheimName + "' wirklich löschen?", "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
{
ServiceFacade.DoWohnheimServiceAsync(s => s.DeactivateWohnheim(dc.WohnheimOid, dc.Version));
return true;
}
}
return false;
}
private void wohnheimNavigationView_ExcelExport(object sender, EventArgs<IEnumerable<IFilterableDC>> e)
{
var path = BeWoApp.GetAndCreateUserAppDataPath() + "\\Wohnheime.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(wohnheimNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast<CompactWohnheimDC>().Select(c => c.WohnheimOid).ToList()), sf.FileName));
}
private void wohnheimNavigationView_Print(object sender, EventArgs<IEnumerable<IFilterableDC>> e)
{
var oids = e.Data.Cast<CompactWohnheimDC>().Select(c => c.WohnheimOid).ToList();
ServiceFacade.DoReportServiceAsync(s => s.CreateWohnheimListReport(oids), r =>
{
this.Dispatch(() =>
{
BeWoUtils.ShowReportWindow(r, "Wohnheime");
});
});
}
private void wohnheimNavigationView_OpenObject(IFilterableDC ofbj)
{
CompactWohnheimDC dc = ofbj as CompactWohnheimDC;
if (dc != null)
{
VMFactory.CreateWohnheimVMAsync(dc.WohnheimOid, _Customers, cb => this.Dispatch(delegate { this.MainControl.NavigateTo(new WohnheimView(cb) { ParentView = this }); }));
}
}
public override void ChildViewClosed()
{
recentList = null;
objectList = null;
}
private void WohnheimNavigationView_OnReloadData()
{
ReloadData(true);
}
private void ReloadData(bool refresh)
{
if (refresh || recentList == null)
{
ServiceFacade.DoWohnheimServiceAsync(s => s.GetAllActiveAndArchivedWohnheimCompact(), r =>
this.Dispatch(delegate
{
objectList = r.Cast<IFilterableDC>();
this.wohnheimNavigationView.ShowSearchResult(objectList);
}));
ServiceFacade.DoWohnheimServiceAsync(s => s.GetLastOpenedWohnheim(),
r => this.Dispatch(delegate
{
recentList = r.Cast<IFilterableDC>();
this.wohnheimNavigationView.ShowHistory(recentList);
#if DEBUG
if (DebugConfig.CurrentConfig is object && DebugConfig.CurrentConfig.DebugConfigMode == DebugConfigMode.FeatureWohnheimWohneinheit)
{
wohnheimNavigationView_OpenObject(recentList?.FirstOrDefault() ?? objectList?.FirstOrDefault());
}
#endif
}));
ServiceFacade.DoCustomerServiceAsync(c => c.GetAllCompactCustomers(), cb => _Customers = cb);
}
else
{
this.wohnheimNavigationView.ShowSearchResult(objectList);
this.wohnheimNavigationView.ShowHistory(recentList);
}
}
}
}