391 lines
12 KiB
C#
391 lines
12 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;
|
|
using BeWo.Core.Commands;
|
|
using DevExpress.XtraBars.Docking;
|
|
using BeWo.ViewModel.View.AI;
|
|
using DevExpress.Xpf.Editors;
|
|
using BS.Shared.Translation;
|
|
using System;
|
|
|
|
namespace BeWo.View.Navigation
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für PersonNavigationView.xaml
|
|
/// </summary>
|
|
public partial class PersonNavigationView
|
|
{
|
|
private readonly ComboBox filterComboBox;
|
|
private readonly ComboBoxEdit functionFilterComboBox;
|
|
|
|
private IEnumerable<IFilterableDC> objectList;
|
|
private IEnumerable<IFilterableDC> recentList;
|
|
|
|
public PersonNavigationView()
|
|
{
|
|
InitializeComponent();
|
|
|
|
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);
|
|
|
|
|
|
functionFilterComboBox = new ComboBoxEdit();
|
|
functionFilterComboBox.FontSize = 12;
|
|
functionFilterComboBox.Margin = new Thickness(10, 0, 0, 0);
|
|
functionFilterComboBox.Width = 180;
|
|
functionFilterComboBox.IsTextEditable = false;
|
|
functionFilterComboBox.NullText = Translator.Translate("Nach Funktion filtern");
|
|
functionFilterComboBox.ItemsSource = ServiceFacade.DoValueListServiceSync(s => s.GetAllValueListEntrysByType(ValueListEntryType.FunctionType));
|
|
functionFilterComboBox.DisplayMember = "TypeDescription";
|
|
functionFilterComboBox.StyleSettings = new CheckedComboBoxStyleSettings();
|
|
functionFilterComboBox.EditValueChanged += FunctionComboBox_EditValueChanged;
|
|
|
|
//< dxe:ComboBoxEdit x:Name = "checkedComboBox"
|
|
// NullText = "Select categories"
|
|
// IsTextEditable = "False"
|
|
// ItemsSource = "{Binding Categories}"
|
|
// EditValue = "{Binding SelectedCategories}"
|
|
// DisplayMember = "CategoryName"
|
|
// ShowCustomItems = "True" >
|
|
// < dxe:ComboBoxEdit.StyleSettings >
|
|
// < dxe:CheckedComboBoxStyleSettings />
|
|
// </ dxe:ComboBoxEdit.StyleSettings >
|
|
// </ dxe:ComboBoxEdit >
|
|
|
|
lbl = new TextBlock
|
|
{
|
|
Text = Translator.Translate("Funktion:"),
|
|
FontSize = 12,
|
|
Margin = new Thickness(8, 2, -3, 0)
|
|
};
|
|
|
|
mainNavigationView.sortPanel.Children.Insert(5, lbl);
|
|
mainNavigationView.sortPanel.Children.Insert(6, functionFilterComboBox);
|
|
|
|
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.Distinct().ToArray()}
|
|
};
|
|
|
|
return dict;
|
|
}
|
|
|
|
//private AiConversationChatViewModel getAiConversationChatViewModel()
|
|
//{
|
|
// throw new NotImplementedException();
|
|
// //var context = GetVisibleInformationReferences();
|
|
|
|
// //var vm = VMFactory.CreateAiConversationChatViewModel(AiContextType.PersonNavigation, context);
|
|
|
|
// //return vm;
|
|
//}
|
|
|
|
//private void OpenAiWindow()
|
|
//{
|
|
// MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel());
|
|
//}
|
|
|
|
private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs)
|
|
{
|
|
//BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((PersonFilterItem)filterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer;
|
|
|
|
//BeWoApp.SaveAppSettings();
|
|
|
|
UpdateCustomFilter();
|
|
}
|
|
|
|
private void FunctionComboBox_EditValueChanged(object sender, EditValueChangedEventArgs e)
|
|
{
|
|
UpdateCustomFilter();
|
|
}
|
|
|
|
private void UpdateCustomFilter()
|
|
{
|
|
mainNavigationView.CustomFilters = new List<CustomFilter> { CreateNewPersonFilter(), CreateNewFunctionFilter() };
|
|
}
|
|
|
|
private CustomFilter CreateNewFunctionFilter()
|
|
{
|
|
if (functionFilterComboBox.SelectedItems == null)
|
|
return null;
|
|
|
|
var list = new List<ValueListEntryDC>();
|
|
foreach (var item in functionFilterComboBox.SelectedItems)
|
|
{
|
|
list.Add(item as ValueListEntryDC);
|
|
}
|
|
|
|
var filter = new ValueListFilter { SelectedValueListEntries = list, ValueListProperty = "Function" };
|
|
|
|
return filter;
|
|
}
|
|
|
|
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();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
} |