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.ViewModel; using BS.Shared; using BS.Shared.Core; using BS.Shared.DataContracts; using BS.Shared.Extensions; using Microsoft.Win32; namespace BeWo.View.Navigation { public partial class UserGroupNavigationView { private IEnumerable objectList; private IEnumerable recentList; public UserGroupNavigationView() { InitializeComponent(); if (BeWoApp.LoggedOnUser.HasRight(UserRightType.UserGroupView_Create)) { mainNavigationView.btnCopy.Visibility = Visibility.Visible; } //###CB SERIENBRIEF mainNavigationView.MailMergeButton.Visibility = Visibility.Collapsed; } private void OnLoaded(object sender, RoutedEventArgs e) { ReloadData(false); } private void mainNavigationView_CreateNewObject() { VMFactory.CreateUserGroupVMAsync(cb => this.Dispatch(() => MainControl.NavigateTo(new UserGroupView(cb) {ParentView = this}))); } private bool mainNavigationView_DeleteObject(IFilterableDC obj) { var ugdc = obj as UserGroupDC; if (ugdc != null) { if (MessageBox.Show("Wollen Sie die " + BS.Shared.Translation.Translator.Translate("Benutzergruppe") + " '" + ugdc.Name + "' wirklich löschen?", "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { ServiceFacade.DoUserServiceAsync(s => s.DeactivateUserGroup(ugdc.UserGroupOid.Value, ugdc.UserGroupVersion.Value),() => this.Dispatch(() => ReloadData(true)), true); return true; } } return false; } private void mainNavigationView_ExcelExport(object sender, EventArgs> e) { var path = BeWoApp.GetAndCreateUserAppDataPath() + "\\Benutzergruppen.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.PrepareExcelFileUserGroupExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast().Select(c => c.UserGroupOid.Value).ToList()), sf.FileName)); } private void mainNavigationView_Print(object sender, EventArgs> e) { var oids = e.Data.Cast().Select(c => c.UserGroupOid.Value).ToList(); ServiceFacade.DoReportServiceAsync(s => s.CreateUserGroupListReport(oids), r => { this.Dispatch(() => { BeWoUtils.ShowReportWindow(r, "Benutzergruppen"); }); }); } private void mainNavigationView_OpenObject(IFilterableDC obj) { var ugdc = obj as UserGroupDC; if (ugdc != null) { VMFactory.CreateUserGroupVMAsync(ugdc.UserGroupOid.Value, cb => this.Dispatch(() => MainControl.NavigateTo(new UserGroupView(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.DoUserServiceAsync(s => s.GetAllUserGroups(), r => this.Dispatch(delegate { objectList = r; mainNavigationView.ShowSearchResult(objectList); }), true); ServiceFacade.DoUserServiceAsync(s => s.GetLastOpenedUserGroups(), r => this.Dispatch(delegate { recentList = r; mainNavigationView.ShowHistory(recentList); }), true); } else { mainNavigationView.ShowSearchResult(objectList); mainNavigationView.ShowHistory(recentList); } } private void MainNavigation_CopyObject(IFilterableDC obj) { var dc = (UserGroupDC)obj; var copy = new UserGroupDC(); copy.Name = "Kopie von " + dc.Name; copy.Rights = dc.Rights; this.MainControl.NavigateTo(new UserGroupView(new UserGroupVM(copy)) { ParentView = this }); } } }