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

336 lines
9.8 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using BeWo.Core;
using BeWo.ServiceProxy;
using BeWo.View.Detail;
using BeWo.View.Navigation.Filter;
using BeWo.View.Navigation.Sorter;
using BeWo.ViewModel;
using Microsoft.Win32;
using DevExpress.Mvvm;
using BeWo.View.Windows;
using System.Collections;
using System.Windows.Input;
namespace BeWo.View.Navigation
{
/// <summary>
/// Interaktionslogik für PersonNavigationView.xaml
/// </summary>
public partial class PersonNavigationView
{
private readonly ComboBox filterComboBox;
private IEnumerable<IFilterableDC> objectList;
private IEnumerable<IFilterableDC> recentList;
public PersonNavigationView()
{
InitializeComponent();
mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView));
mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2));
mainNavigationView.Sorter = new PersonSorter();
mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Person_AllowArchiving);
mainNavigationView.ShowArchivedObjectsVisible = true;
filterComboBox = new ComboBox();
filterComboBox.FontSize = 12;
filterComboBox.Margin = new Thickness(10, 0, 0, 0);
filterComboBox.MinWidth = 100;
filterComboBox.Style = FindResource("SortComboBox") as Style;
var lbl = new TextBlock
{
Text = "Filter:",
FontSize = 12,
Margin = new Thickness(8, 2, -3, 0)
};
PersonFilterItem selectedItem = null;
if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Person_FamilyView))
{
filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.All));
filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.ContactPersons));
filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.Family));
selectedItem = new PersonFilterItem(PersonFilterEnum.All); ;
}
else
{
filterComboBox.Visibility = Visibility.Collapsed;
lbl.Visibility = Visibility.Collapsed;
filterComboBox.Items.Add(new PersonFilterItem(PersonFilterEnum.ContactPersons));
selectedItem = new PersonFilterItem(PersonFilterEnum.ContactPersons); ;
}
filterComboBox.SelectedItem = selectedItem;
filterComboBox.SelectionChanged += SupportConceptFilterComboBoxOnSelectionChanged;
mainNavigationView.sortPanel.Children.Insert(3, lbl);
mainNavigationView.sortPanel.Children.Insert(4, filterComboBox);
UpdateCustomFilter();
}
public Dictionary<TableID, long[]> GetVisibleInformationReferences()
{
var visible = mainNavigationView.objectListBox.ItemsSource;
return GetVisibleInformationReferences(visible);
}
private Dictionary<TableID, long[]> GetVisibleInformationReferences(IEnumerable visible_persons)
{
var oids = new List<long>();
foreach (var p in visible_persons)
{
var person = p as CompactPersonDC;
oids.Add(person.PersonOid);
}
var dict = new Dictionary<TableID, long[]>() {
{
TableID.Person, oids.ToArray()}
};
return dict;
}
private void OpenAiWindow()
{
var context = GetVisibleInformationReferences();
var window = BeWoWindowBuilder.AiWindowBuilder.GetAiConversationWindow(UIContext.Person, context);
window?.Show();
}
private void OpenAiPopup()
{
var context = GetVisibleInformationReferences();
var control = BeWoWindowBuilder.AiWindowBuilder.GetAiConversationControl(UIContext.Person, context);
if (control is object)
MainControl.ShowControlAsModalPopup(control);
}
private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs)
{
//BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((PersonFilterItem)filterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer;
//BeWoApp.SaveAppSettings();
UpdateCustomFilter();
}
private void UpdateCustomFilter()
{
mainNavigationView.CustomFilter = CreateNewPersonFilter();
}
private PersonNavigationFilter CreateNewPersonFilter()
{
var filter = new PersonNavigationFilter { PersonFilter = ((PersonFilterItem)filterComboBox.SelectedItem)?.Filter ?? PersonFilterEnum.ContactPersons };
return filter;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
ReloadData(false);
CommandManager.InvalidateRequerySuggested();
}
private bool mainNavigationView_ArchiveObject(IFilterableDC obj)
{
var dc = obj as CompactPersonDC;
if (dc != null)
{
if (
MessageBox.Show(
"Wollen Sie die Person '" + dc.FirstName + " " + dc.LastName + "' wirklich archivieren?",
"Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
{
ServiceFacade.DoCustomerServiceAsync(
s =>
{
s.ArchivePerson(dc.PersonOid, dc.PersonVersion);
return dc;
},
cb => cb.PersonVersion++);
return true;
}
}
return false;
}
private void mainNavigationView_CreateNewObject()
{
VMFactory.CreatePersonVMAsync(cb => this.Dispatch(() => MainControl.NavigateTo(new PersonView(cb) { ParentView = this })));
}
private bool mainNavigationView_DeleteObject(IFilterableDC obj)
{
var dc = obj as CompactPersonDC;
if (dc != null)
{
if (
MessageBox.Show(
"Wollen Sie die Person '" + dc.FirstName + " " + dc.LastName + "' wirklich löschen?", "Löschen",
MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes)
{
ServiceFacade.DoCustomerServiceAsync(s => s.DeactivatePerson(dc.PersonOid, dc.PersonVersion));
return true;
}
}
return false;
}
private void mainNavigationView_ExcelExport(object sender, EventArgs<IEnumerable<IFilterableDC>> e)
{
// string path = BeWoApp.LoginControl.GetAndCreateTempDataPath() + "\\Personen.xls";
var path = BeWoApp.GetAndCreateUserAppDataPath() + "\\Personen.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.PrepareExcelFilePersonExport(mainNavigationView.DownloadLinkEngine.ExcelFileId,
e.Data.Cast<CompactPersonDC>().Select(c => c.PersonOid).ToList()),
sf.FileName));
}
private void mainNavigationView_Print(object sender, EventArgs<IEnumerable<IFilterableDC>> e)
{
var oids = e.Data.Cast<CompactPersonDC>().Select(c => c.PersonOid).ToList();
ServiceFacade.DoReportServiceAsync(s => s.CreatePersonListReport(oids), r =>
{
this.Dispatch(() =>
{
BeWoUtils.ShowReportWindow(r, "Personen");
});
});
}
private void mainNavigationView_OpenObject(IFilterableDC obj)
{
var dc = obj as CompactPersonDC;
if (dc != null)
{
VMFactory.CreatePersonVMAsync(dc.PersonOid, cb => this.Dispatch(() => MainControl.NavigateTo(new PersonView(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.GetAllPersonsByTypeCompact(PersonType.Others), r => this.Dispatch(delegate
{
objectList = r;
mainNavigationView.ShowSearchResult(objectList);
}));
ServiceFacade.DoCustomerServiceAsync(s => s.GetLastOpenedPersons(), r => this.Dispatch(delegate
{
recentList = r;
mainNavigationView.ShowHistory(recentList);
}));
}
else
{
mainNavigationView.ShowSearchResult(objectList);
mainNavigationView.ShowHistory(recentList);
}
}
private void MainNavigationView_OnOpenMailMergeWindow(List<IFilterableDC> allPersons, IFilterableDC selectedPerson)
{
var mmw = new MailMergeWindow(this, typeof(PersonDC), objectList.ToList(), selectedPerson)
{
Sorter = new PersonSorter()
};
mmw.Show();
}
public void ReactivatePerson(CompactPersonDC person)
{
if (MessageBox.Show("Wollen Sie die Person '" + person.FirstName + " " + person.LastName + "' wirklich reaktivieren?", "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No)
{
return;
}
ServiceFacade.DoCustomerServiceAsync(s =>
{
s.ReactivatePerson(person.PersonOid, person.Version);
return person;
}, cb => cb.PersonVersion++);
person.ActivationType = ActivationTypeId.Active;
var context = mainNavigationView.objectListBox.DataContext;
mainNavigationView.objectListBox.DataContext = null;
mainNavigationView.objectListBox.DataContext = context;
}
public void DeleteForGood(CompactPersonDC person)
{
var dialog = new MessageDialog(() =>
{
this.Dispatch(() =>
{
ServiceFacade.DoOperationsServiceAsync(s =>
{
s.DeletePersonForGood(person.PersonOid);
}, () => { ReloadData(true); });
});
});
ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Person, person.PersonOid, MessageType.DeleteForGood), xaml =>
{
this.Dispatch(() =>
{
dialog.SetXaml(xaml);
dialog.ShowDialog();
});
});
}
}
}