using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows; 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 { public partial class TeamNavigationView { private IEnumerable objectList; private IEnumerable recentList; public TeamNavigationView() { InitializeComponent(); //###CB SERIENBRIEF mainNavigationView.MailMergeButton.Visibility = Visibility.Collapsed; mainNavigationView.Sorter = new TeamSorter(); mainNavigationView.ShowArchivedObjectsVisible = false; } 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) { if (obj is CompactTeamDC dc) { 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> 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) { return; } ServiceFacade.DoDownloadServiceSync(s => BeWoUtils.WriteExcelFile(s.PrepareExcelFileTeamExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast().Select(c => c.TeamOid).ToList()), sf.FileName)); } private void mainNavigationView_OpenObject(IFilterableDC obj) { if (obj is CompactTeamDC dc) { VMFactory.CreateTeamVMAsync(dc.TeamOid, cb => this.Dispatch(delegate { MainControl.NavigateTo(new TeamView(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.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(); } recentList = r; mainNavigationView.ShowHistory(recentList); })); })); } else { mainNavigationView.ShowSearchResult(objectList); mainNavigationView.ShowHistory(recentList); } } } }