diff --git a/BeWo/View/Navigation/CustomerNavigationView.xaml.cs b/BeWo/View/Navigation/CustomerNavigationView.xaml.cs index 14b452fe7..3297df190 100644 --- a/BeWo/View/Navigation/CustomerNavigationView.xaml.cs +++ b/BeWo/View/Navigation/CustomerNavigationView.xaml.cs @@ -33,172 +33,172 @@ using System.Collections; namespace BeWo.View.Navigation { - /// - /// Interaktionslogik für CustomerNavigationView.xaml - /// - public partial class CustomerNavigationView - { - //private readonly CheckBox chkShowOnlyMyCustomers; - //private readonly CheckBox chkShowOnlyTeamCustomers; - private readonly ComboBox supportConceptFilterComboBox; + /// + /// Interaktionslogik für CustomerNavigationView.xaml + /// + public partial class CustomerNavigationView + { + //private readonly CheckBox chkShowOnlyMyCustomers; + //private readonly CheckBox chkShowOnlyTeamCustomers; + private readonly ComboBox supportConceptFilterComboBox; - private IEnumerable objectList; - private IEnumerable recentList; + private IEnumerable objectList; + private IEnumerable recentList; - public CustomerNavigationView() - { - InitializeComponent(); + public CustomerNavigationView() + { + InitializeComponent(); mainNavigationView.OpenAiWindowCommand = new DelegateCommand(OpenAiWindow, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView), false); mainNavigationView.OpenAiPopupCommand = new DelegateCommand(OpenAiPopup, () => BeWoApp.HasLoggedOnUserRight(UserRightType.AiModuleView2), false); mainNavigationView.Sorter = new CustomerSorter(); - mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_AllowArchiving); - mainNavigationView.ShowArchivedObjectsVisible = true; + mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_AllowArchiving); + mainNavigationView.ShowArchivedObjectsVisible = true; - supportConceptFilterComboBox = new ComboBox(); - //supportConceptFilterComboBox.HorizontalAlignment = "Left"; - //supportConceptFilterComboBox.FontFamily = "Microsoft Sans Serif"; + supportConceptFilterComboBox = new ComboBox(); + //supportConceptFilterComboBox.HorizontalAlignment = "Left"; + //supportConceptFilterComboBox.FontFamily = "Microsoft Sans Serif"; - //supportConceptFilterComboBox.Foreground = new SolidColorBrush(Color.FromRgb(210, 210, 210)); - supportConceptFilterComboBox.FontSize = 12; - supportConceptFilterComboBox.Margin = new Thickness(10, 0, 0, 0); - supportConceptFilterComboBox.MinWidth = 100; - //supportConceptFilterComboBox.DisplayMemberPath = "DisplayName"; - //supportConceptFilterComboBox.SelectionChanged = "sortCombo_SelectionChanged"; - supportConceptFilterComboBox.Style = FindResource("SortComboBox") as Style; + //supportConceptFilterComboBox.Foreground = new SolidColorBrush(Color.FromRgb(210, 210, 210)); + supportConceptFilterComboBox.FontSize = 12; + supportConceptFilterComboBox.Margin = new Thickness(10, 0, 0, 0); + supportConceptFilterComboBox.MinWidth = 100; + //supportConceptFilterComboBox.DisplayMemberPath = "DisplayName"; + //supportConceptFilterComboBox.SelectionChanged = "sortCombo_SelectionChanged"; + supportConceptFilterComboBox.Style = FindResource("SortComboBox") as Style; - if (BeWoApp.AppSettings.ShowAIInternal) - { - mainNavigationView.btnOpenAi.Visibility = Visibility.Visible; - } + if (BeWoApp.AppSettings.ShowAIInternal) + { + mainNavigationView.btnOpenAi.Visibility = Visibility.Visible; + } - if (BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) - { - supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.All)); - } - - if(BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyTeams)) - { - supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.TeamCustomer)); - } - supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.MyCustomer)); + if (BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) + { + supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.All)); + } - CustomerFilterItem selectedItem = null; + if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyTeams)) + { + supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.TeamCustomer)); + } + supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.MyCustomer)); - switch(BeWoApp.AppSettings.CustomerFilterSupportConcepts) - { - case CustomerFilterEnum.All: - if(BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) - { - selectedItem = new CustomerFilterItem(CustomerFilterEnum.All); - } - - break; - case CustomerFilterEnum.TeamCustomer: - if(BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || - BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) || - BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyTeams)) - { - selectedItem = new CustomerFilterItem(CustomerFilterEnum.TeamCustomer); - } - - break; - } - - if(selectedItem == null) - { - selectedItem = new CustomerFilterItem(CustomerFilterEnum.MyCustomer); - } - - supportConceptFilterComboBox.SelectedItem = selectedItem; - supportConceptFilterComboBox.SelectionChanged += SupportConceptFilterComboBoxOnSelectionChanged; + CustomerFilterItem selectedItem = null; - //chkShowOnlyMyCustomers = new CheckBox - // { - // FontSize = 12, - // Margin = new Thickness(10, 0, 0, 0), - // Content = Translator.Translate("Meine Klienten"), - // VerticalAlignment = VerticalAlignment.Center - // }; - //chkShowOnlyTeamCustomers = new CheckBox - //{ - // FontSize = 12, - // Margin = new Thickness(10, 0, 0, 0), - // Content = Translator.Translate("Klienten meines Teams"), - // VerticalAlignment = VerticalAlignment.Center - //}; + switch (BeWoApp.AppSettings.CustomerFilterSupportConcepts) + { + case CustomerFilterEnum.All: + if (BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) + { + selectedItem = new CustomerFilterItem(CustomerFilterEnum.All); + } - //var b = FindResource("MainGroupBoxForegroundBrush") as Brush; - //if (b != null) - //{ - // chkShowOnlyMyCustomers.Foreground = b; - // chkShowOnlyTeamCustomers.Foreground = b; - //} + break; + case CustomerFilterEnum.TeamCustomer: + if (BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || + BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) || + BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyTeams)) + { + selectedItem = new CustomerFilterItem(CustomerFilterEnum.TeamCustomer); + } - //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && - // !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) - //{ - // chkShowOnlyMyCustomers.IsChecked = true; - // chkShowOnlyMyCustomers.IsEnabled = false; - //} - //else - //{ - // chkShowOnlyMyCustomers.IsChecked = BeWoApp.AppSettings.ShowOnlyMyClients; - //} + break; + } - //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && - // !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) - //{ - // chkShowOnlyTeamCustomers.IsChecked = true; - // chkShowOnlyTeamCustomers.IsEnabled = false; - //} - //else - //{ - // chkShowOnlyTeamCustomers.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamClients; - //} + if (selectedItem == null) + { + selectedItem = new CustomerFilterItem(CustomerFilterEnum.MyCustomer); + } - //chkShowOnlyMyCustomers.Click += chkShowOnlyMyCustomers_Click; - //chkShowOnlyTeamCustomers.Click += chkShowOnlyMyCustomers_Click; + supportConceptFilterComboBox.SelectedItem = selectedItem; + supportConceptFilterComboBox.SelectionChanged += SupportConceptFilterComboBoxOnSelectionChanged; - //mainNavigationView.AddControlToSortPanel(chkShowOnlyMyCustomers); - //mainNavigationView.AddControlToSortPanel(chkShowOnlyTeamCustomers); - var lbl = new TextBlock - { - Text = "Filter:", - FontSize = 12, - Margin = new Thickness(8, 2, -3, 0) - }; + //chkShowOnlyMyCustomers = new CheckBox + // { + // FontSize = 12, + // Margin = new Thickness(10, 0, 0, 0), + // Content = Translator.Translate("Meine Klienten"), + // VerticalAlignment = VerticalAlignment.Center + // }; + //chkShowOnlyTeamCustomers = new CheckBox + //{ + // FontSize = 12, + // Margin = new Thickness(10, 0, 0, 0), + // Content = Translator.Translate("Klienten meines Teams"), + // VerticalAlignment = VerticalAlignment.Center + //}; - mainNavigationView.sortPanel.Children.Insert(3, lbl); - mainNavigationView.sortPanel.Children.Insert(4, supportConceptFilterComboBox); - - UpdateCustomFilter(); - } + //var b = FindResource("MainGroupBoxForegroundBrush") as Brush; + //if (b != null) + //{ + // chkShowOnlyMyCustomers.Foreground = b; + // chkShowOnlyTeamCustomers.Foreground = b; + //} - public Dictionary GetVisibleInformationReferences() - { - var visible = mainNavigationView.objectListBox.ItemsSource; + //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && + // !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) + //{ + // chkShowOnlyMyCustomers.IsChecked = true; + // chkShowOnlyMyCustomers.IsEnabled = false; + //} + //else + //{ + // chkShowOnlyMyCustomers.IsChecked = BeWoApp.AppSettings.ShowOnlyMyClients; + //} - return GetVisibleInformationReferences(visible); + //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) && + // !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) + //{ + // chkShowOnlyTeamCustomers.IsChecked = true; + // chkShowOnlyTeamCustomers.IsEnabled = false; + //} + //else + //{ + // chkShowOnlyTeamCustomers.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamClients; + //} + + //chkShowOnlyMyCustomers.Click += chkShowOnlyMyCustomers_Click; + //chkShowOnlyTeamCustomers.Click += chkShowOnlyMyCustomers_Click; + + //mainNavigationView.AddControlToSortPanel(chkShowOnlyMyCustomers); + //mainNavigationView.AddControlToSortPanel(chkShowOnlyTeamCustomers); + var lbl = new TextBlock + { + Text = "Filter:", + FontSize = 12, + Margin = new Thickness(8, 2, -3, 0) + }; + + mainNavigationView.sortPanel.Children.Insert(3, lbl); + mainNavigationView.sortPanel.Children.Insert(4, supportConceptFilterComboBox); + + UpdateCustomFilter(); } - private Dictionary GetVisibleInformationReferences(IEnumerable selected_records) - { - foreach (var record in selected_records) - { - var t = record is CompactCustomerDC; + public Dictionary GetVisibleInformationReferences() + { + var visible = mainNavigationView.objectListBox.ItemsSource; + return GetVisibleInformationReferences(visible); + } - if (record is CompactCustomerDC) - { + private Dictionary GetVisibleInformationReferences(IEnumerable visible_customers) + { + var oids = new List(); + foreach (var c in visible_customers) + { + var customer = c as CompactCustomerDC; + oids.Add(customer.CustomerOid); + } - } - } + var dict = new Dictionary() { + { TableID.Customer, oids.ToArray()} + }; - return null; - } + return dict; + } private void OpenAiWindow() { @@ -219,337 +219,337 @@ namespace BeWo.View.Navigation } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) - { - BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((CustomerFilterItem) supportConceptFilterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer; + { + BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((CustomerFilterItem)supportConceptFilterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer; - BeWoApp.SaveAppSettings(); + BeWoApp.SaveAppSettings(); - UpdateCustomFilter(); - } + UpdateCustomFilter(); + } - private CustomFilter CreateNewCustomFilter() - { - var filter = new CustomerNavigationFilter {CustomerFilter = ((CustomerFilterItem) supportConceptFilterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer}; + private CustomFilter CreateNewCustomFilter() + { + var filter = new CustomerNavigationFilter { CustomerFilter = ((CustomerFilterItem)supportConceptFilterComboBox.SelectedItem)?.CustomerFilter ?? CustomerFilterEnum.MyCustomer }; - return filter; - } + return filter; + } - private void OnLoaded(object sender, RoutedEventArgs e) - { - ServiceFacade.DoCustomerServiceAsync(s => s.ConvertToNewSubstitutionType(), n => this.Dispatch(delegate - { - ReloadData(false); - })); - } + private void OnLoaded(object sender, RoutedEventArgs e) + { + ServiceFacade.DoCustomerServiceAsync(s => s.ConvertToNewSubstitutionType(), n => this.Dispatch(delegate + { + ReloadData(false); + })); + } - private void UpdateCustomFilter() - { - mainNavigationView.CustomFilter = CreateNewCustomFilter(); - } + private void UpdateCustomFilter() + { + mainNavigationView.CustomFilter = CreateNewCustomFilter(); + } - private void ChkShowOnlyMyCustomers_Click(object sender, RoutedEventArgs e) - { - //if (chkShowOnlyMyCustomers.IsChecked != null) - // BeWoApp.AppSettings.ShowOnlyMyClients = chkShowOnlyMyCustomers.IsChecked.Value; - //if (chkShowOnlyTeamCustomers.IsChecked != null) - // BeWoApp.AppSettings.ShowOnlyTeamClients = chkShowOnlyTeamCustomers.IsChecked.Value; - BeWoApp.SaveAppSettings(); + private void ChkShowOnlyMyCustomers_Click(object sender, RoutedEventArgs e) + { + //if (chkShowOnlyMyCustomers.IsChecked != null) + // BeWoApp.AppSettings.ShowOnlyMyClients = chkShowOnlyMyCustomers.IsChecked.Value; + //if (chkShowOnlyTeamCustomers.IsChecked != null) + // BeWoApp.AppSettings.ShowOnlyTeamClients = chkShowOnlyTeamCustomers.IsChecked.Value; + BeWoApp.SaveAppSettings(); - UpdateCustomFilter(); - } + UpdateCustomFilter(); + } - private bool mainNavigationView_ArchiveObject(IFilterableDC obj) - { - var cdc = obj as CompactCustomerDC; - if (cdc != null) - { - if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich archivieren?", cdc.FirstName + " " + cdc.LastName), "Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) - { - ServiceFacade.DoCustomerServiceAsync( - s => - { - s.ArchiveCustomer(cdc.CustomerOid, cdc.CustomerVersion); - return cdc; - }, - cb => cb.CustomerVersion++); + private bool mainNavigationView_ArchiveObject(IFilterableDC obj) + { + var cdc = obj as CompactCustomerDC; + if (cdc != null) + { + if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich archivieren?", cdc.FirstName + " " + cdc.LastName), "Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) + { + ServiceFacade.DoCustomerServiceAsync( + s => + { + s.ArchiveCustomer(cdc.CustomerOid, cdc.CustomerVersion); + return cdc; + }, + cb => cb.CustomerVersion++); - Cache.GetInstance().ClearSupportConceptTree(); - return true; - } - } + Cache.GetInstance().ClearSupportConceptTree(); + return true; + } + } - return false; - } + return false; + } - private void mainNavigationView_CreateNewObject() - { - VMFactory.CreateCustomerVMAsync(cb => this.Dispatch(() => MainControl.NavigateTo(new CustomerView(cb) {ParentView = this}))); - } + private void mainNavigationView_CreateNewObject() + { + VMFactory.CreateCustomerVMAsync(cb => this.Dispatch(() => MainControl.NavigateTo(new CustomerView(cb) { ParentView = this }))); + } - private bool mainNavigationView_DeleteObject(IFilterableDC obj) - { - var cdc = obj as CompactCustomerDC; - if (cdc != null) - { - if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich löschen?", cdc.FirstName + " " + cdc.LastName), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) - { + private bool mainNavigationView_DeleteObject(IFilterableDC obj) + { + var cdc = obj as CompactCustomerDC; + if (cdc != null) + { + if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich löschen?", cdc.FirstName + " " + cdc.LastName), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) + { - CustomerInfoDC details = ServiceFacade.DoOperationsServiceSync(s => s.GetCustomerInfosForCustomerOid(cdc.CustomerOid)); - bool delete = true; - if (details != null) - { - if (!string.IsNullOrEmpty(details.CurrentSupportConcept) && details.CurrentSupportConcept.ToLower() != Translator.Translate("Kein aktueller Hilfeplan").ToLower()) - { - if (MessageBox.Show(Translator.Translate("Für Klient '{0}' wurde bereits ein Hilfeplan angelegt. Der Hilfeplan wird dadurch auch gelöscht!\n Möchten Sie wirklich fortfahren und den Klient löschen?", cdc.FirstName + " " + cdc.LastName), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) - { - delete = false; - } - } - - } - if (delete) - { - - ServiceFacade.DoCustomerServiceAsync( - s => - { - s.DeactivateCustomer(cdc.CustomerOid, cdc.CustomerVersion); - return cdc; - }, cb => cb.CustomerVersion++); + CustomerInfoDC details = ServiceFacade.DoOperationsServiceSync(s => s.GetCustomerInfosForCustomerOid(cdc.CustomerOid)); + bool delete = true; + if (details != null) + { + if (!string.IsNullOrEmpty(details.CurrentSupportConcept) && details.CurrentSupportConcept.ToLower() != Translator.Translate("Kein aktueller Hilfeplan").ToLower()) + { + if (MessageBox.Show(Translator.Translate("Für Klient '{0}' wurde bereits ein Hilfeplan angelegt. Der Hilfeplan wird dadurch auch gelöscht!\n Möchten Sie wirklich fortfahren und den Klient löschen?", cdc.FirstName + " " + cdc.LastName), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) + { + delete = false; + } + } - Cache.GetInstance().ClearSupportConceptTree(); - return true; - - } - } - } + } + if (delete) + { - return false; - } + ServiceFacade.DoCustomerServiceAsync( + s => + { + s.DeactivateCustomer(cdc.CustomerOid, cdc.CustomerVersion); + return cdc; + }, cb => cb.CustomerVersion++); - private void mainNavigationView_ExcelExport(object sender, EventArgs> e) - { + Cache.GetInstance().ClearSupportConceptTree(); + return true; + + } + } + } + + return false; + } + + private void mainNavigationView_ExcelExport(object sender, EventArgs> e) + { var path = BeWoApp.GetAndCreateUserAppDataPath() + Translator.Translate("\\Klienten.xls"); - var sf = new SaveFileDialog { FileName = Path.GetFileName(path), Filter = "Microsoft Excel 97-2003-Arbeitsblatt|*.xls|Alle Dateien|*.*" }; - if (sf.ShowDialog() != true) - return; + 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.PrepareExcelFileCustomerExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast().Select(c => c.CustomerOid).ToList()), sf.FileName)); - } + ServiceFacade.DoDownloadServiceSync(s => BeWoUtils.WriteExcelFile(s.PrepareExcelFileCustomerExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast().Select(c => c.CustomerOid).ToList()), sf.FileName)); + } - private void mainNavigationView_OpenObject(IFilterableDC obj) - { - var cdc = obj as CompactCustomerDC; - if (cdc != null) - { - VMFactory.CreateCustomerVMAsync(cdc.CustomerOid, cb => this.Dispatch(() => MainControl.NavigateTo(new CustomerView(cb) {ParentView = this}))); - } - } - - public override void ChildViewClosed() - { - recentList = null; - objectList = null; - } - private void MainNavigationView_OnReloadData() - { - ReloadData(true); - } - - private void ReloadData(bool refresh) + private void mainNavigationView_OpenObject(IFilterableDC obj) { - if (refresh || recentList == null) - { - ServiceFacade.DoCustomerServiceAsync( + var cdc = obj as CompactCustomerDC; + if (cdc != null) + { + VMFactory.CreateCustomerVMAsync(cdc.CustomerOid, cb => this.Dispatch(() => MainControl.NavigateTo(new CustomerView(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.GetAllCustomersCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid), - r => this.Dispatch(delegate - { - objectList = r; - - mainNavigationView.ShowSearchResult(objectList); - })); + r => this.Dispatch(delegate + { + objectList = r; - ServiceFacade.DoCustomerServiceAsync(s => s.GetLastOpenedCustomers(), - r => - this.Dispatch(delegate - { - if(BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) - { - recentList = r; - } - else if(BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers)) - { - recentList = r.Where(w => BeWoApp.LoggedOnEmployee.RelatedCustomers.Select(s3 => s3.Customer.CustomerOid).Contains(w.CustomerOid)); - } - else - { - recentList = new List(); - } + mainNavigationView.ShowSearchResult(objectList); + })); - mainNavigationView.ShowHistory(recentList); + ServiceFacade.DoCustomerServiceAsync(s => s.GetLastOpenedCustomers(), + r => + this.Dispatch(delegate + { + if (BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) + { + recentList = r; + } + else if (BeWoApp.LoggedOnUser.HasRight(UserRightType.Customer_ViewMyCustomers)) + { + recentList = r.Where(w => BeWoApp.LoggedOnEmployee.RelatedCustomers.Select(s3 => s3.Customer.CustomerOid).Contains(w.CustomerOid)); + } + else + { + recentList = new List(); + } + + mainNavigationView.ShowHistory(recentList); #if DEBUG - if(DebugConfig.CurrentConfig is object && DebugConfig.CurrentConfig.DebugConfigMode == DebugConfigMode.FeatureCustomerWohnhilfe) - { - mainNavigationView_OpenObject(recentList.FirstOrDefault() ?? objectList.FirstOrDefault()); - } + if (DebugConfig.CurrentConfig is object && DebugConfig.CurrentConfig.DebugConfigMode == DebugConfigMode.FeatureCustomerWohnhilfe) + { + mainNavigationView_OpenObject(recentList.FirstOrDefault() ?? objectList.FirstOrDefault()); + } #endif - }) - ); - } - else - { - mainNavigationView.ShowSearchResult(objectList); - mainNavigationView.ShowHistory(recentList); - } - } + }) + ); + } + else + { + mainNavigationView.ShowSearchResult(objectList); + mainNavigationView.ShowHistory(recentList); + } + } - private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) - { - //var alleVorlagen = ServiceFacade.DoOperationsServiceSync(s => s.Getvor()); + private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) + { + //var alleVorlagen = ServiceFacade.DoOperationsServiceSync(s => s.Getvor()); - var alleVorlagen = ServiceFacade.DoOperationsServiceSync(s => s.GetDokumentvorlagenForType(TableID.Customer)); - if (alleVorlagen.Count > 0) - { - var c = (CompactCustomerDC)((Hyperlink)sender).Tag; + var alleVorlagen = ServiceFacade.DoOperationsServiceSync(s => s.GetDokumentvorlagenForType(TableID.Customer)); + if (alleVorlagen.Count > 0) + { + var c = (CompactCustomerDC)((Hyperlink)sender).Tag; - DokumentViewHelper.OpenTemplateSelectionDialog(alleVorlagen, TableID.Customer, c.CustomerOid); - } - else - { - BeWoUtils.NavigateToReportUri(((Hyperlink)sender).NavigateUri.ToString(), "Druckvorschau"); - } - //var folderDCs = VMFactory.CreateFolderList(TableID.Vorlagentabelle, (long)vm.DocTreeItemOid); + DokumentViewHelper.OpenTemplateSelectionDialog(alleVorlagen, TableID.Customer, c.CustomerOid); + } + else + { + BeWoUtils.NavigateToReportUri(((Hyperlink)sender).NavigateUri.ToString(), "Druckvorschau"); + } + //var folderDCs = VMFactory.CreateFolderList(TableID.Vorlagentabelle, (long)vm.DocTreeItemOid); - - } - + } - private void MainNavigationView_OnOpenMailMergeWindow(List allCustomers, IFilterableDC selectedCustomer) - { - var mmw = new MailMergeWindow(this, typeof(CustomerDC), objectList.ToList(), selectedCustomer) { Sorter = new CustomerSorter() }; - - mmw.Show(); - } - private void Hyperlink_Reaktivieren_Click(object sender, RoutedEventArgs e) - { - var customer = (CompactCustomerDC) ((Hyperlink)sender).Tag; - if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich reaktivieren?", customer.FirstName + " " + customer.LastName), "Reaktivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) - { - return; - } + private void MainNavigationView_OnOpenMailMergeWindow(List allCustomers, IFilterableDC selectedCustomer) + { + var mmw = new MailMergeWindow(this, typeof(CustomerDC), objectList.ToList(), selectedCustomer) { Sorter = new CustomerSorter() }; - ServiceFacade.DoCustomerServiceAsync(s => - { + mmw.Show(); + } + + private void Hyperlink_Reaktivieren_Click(object sender, RoutedEventArgs e) + { + var customer = (CompactCustomerDC)((Hyperlink)sender).Tag; + + if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich reaktivieren?", customer.FirstName + " " + customer.LastName), "Reaktivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) + { + return; + } + + ServiceFacade.DoCustomerServiceAsync(s => + { s.ReactivateCustomer(customer.CustomerOid, customer.CustomerVersion); - return customer; - }, cb => cb.CustomerVersion++); + return customer; + }, cb => cb.CustomerVersion++); Cache.GetInstance().ClearSupportConceptTree(); - customer.ActivationType = ActivationTypeId.Active; + customer.ActivationType = ActivationTypeId.Active; var context = mainNavigationView.objectListBox.DataContext; mainNavigationView.objectListBox.DataContext = null; mainNavigationView.objectListBox.DataContext = context; - } - - private void Hyperlink_AusArchivHolen_Click(object sender, RoutedEventArgs e) - { - var customer = (CompactCustomerDC) ((Hyperlink)sender).Tag; + } - if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich aus dem Archiv holen?", customer.FirstName + " " + customer.LastName), "Reaktivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) - { - return; - } + private void Hyperlink_AusArchivHolen_Click(object sender, RoutedEventArgs e) + { + var customer = (CompactCustomerDC)((Hyperlink)sender).Tag; - ServiceFacade.DoCustomerServiceAsync(s => - { + if (MessageBox.Show(Translator.Translate("Wollen Sie den Klient '{0}' wirklich aus dem Archiv holen?", customer.FirstName + " " + customer.LastName), "Reaktivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) + { + return; + } + + ServiceFacade.DoCustomerServiceAsync(s => + { s.ReactivateCustomer(customer.CustomerOid, customer.CustomerVersion); - return customer; - }, cb => cb.CustomerVersion++); + return customer; + }, cb => cb.CustomerVersion++); Cache.GetInstance().ClearSupportConceptTree(); - customer.ActivationType = ActivationTypeId.Active; + customer.ActivationType = ActivationTypeId.Active; var context = mainNavigationView.objectListBox.DataContext; mainNavigationView.objectListBox.DataContext = null; mainNavigationView.objectListBox.DataContext = context; - } + } - private void Hyperlink_Anonymize_Click(object sender, RoutedEventArgs e) - { - var customer = (CompactCustomerDC) ((Hyperlink) sender).Tag; + private void Hyperlink_Anonymize_Click(object sender, RoutedEventArgs e) + { + var customer = (CompactCustomerDC)((Hyperlink)sender).Tag; - var dialog = new MessageDialog(() => - { - this.Dispatch(() => - { - ServiceFacade.DoOperationsServiceAsync(s => - { - s.AnonymizeCustomer(customer.CustomerOid); - }, () => - { - ReloadData(true); - }); - }); - }); + var dialog = new MessageDialog(() => + { + this.Dispatch(() => + { + ServiceFacade.DoOperationsServiceAsync(s => + { + s.AnonymizeCustomer(customer.CustomerOid); + }, () => + { + ReloadData(true); + }); + }); + }); - ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Customer, customer.CustomerOid, MessageType.Anonymization), xaml => - { - this.Dispatch(() => - { - dialog.SetXaml(xaml); - dialog.ShowDialog(); - }); - }); - } + ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Customer, customer.CustomerOid, MessageType.Anonymization), xaml => + { + this.Dispatch(() => + { + dialog.SetXaml(xaml); + dialog.ShowDialog(); + }); + }); + } - private void Hyperlink_Delete_For_Good_Click(object sender, RoutedEventArgs e) - { - var customer = (CompactCustomerDC) ((Hyperlink) sender).Tag; + private void Hyperlink_Delete_For_Good_Click(object sender, RoutedEventArgs e) + { + var customer = (CompactCustomerDC)((Hyperlink)sender).Tag; - var dialog = new MessageDialog(() => - { - this.Dispatch(() => - { - ServiceFacade.DoOperationsServiceAsync(s => - { - s.DeleteCustomerForGood(customer.CustomerOid); - }, () => { ReloadData(true); }); - }); - }); + var dialog = new MessageDialog(() => + { + this.Dispatch(() => + { + ServiceFacade.DoOperationsServiceAsync(s => + { + s.DeleteCustomerForGood(customer.CustomerOid); + }, () => { ReloadData(true); }); + }); + }); - ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Customer, customer.CustomerOid, MessageType.DeleteForGood), xaml => - { - this.Dispatch(() => - { - dialog.SetXaml(xaml); - dialog.ShowDialog(); - }); - }); - } + ServiceFacade.DoOperationsServiceAsync(s => s.GetMessageFromServer(TableID.Customer, customer.CustomerOid, MessageType.DeleteForGood), xaml => + { + this.Dispatch(() => + { + dialog.SetXaml(xaml); + dialog.ShowDialog(); + }); + }); + } - private void mainNavigationView_Print(object sender, EventArgs> e) - { - var oids = e.Data.Cast().Select(c => c.CustomerOid).ToList(); + private void mainNavigationView_Print(object sender, EventArgs> e) + { + var oids = e.Data.Cast().Select(c => c.CustomerOid).ToList(); - ServiceFacade.DoReportServiceAsync(s => s.CreateCustomerListReport(oids), r => - { - this.Dispatch(() => - { - BeWoUtils.ShowReportWindow(r, Translator.Translate("Klienten")); - }); - }); - } + ServiceFacade.DoReportServiceAsync(s => s.CreateCustomerListReport(oids), r => + { + this.Dispatch(() => + { + BeWoUtils.ShowReportWindow(r, Translator.Translate("Klienten")); + }); + }); + } - private void MainNavigationView_OpenAiChat() - { - AiChatController.ShowAiChatViewForObjects(TableID.Customer, 800, 1200); - } - } + private void MainNavigationView_OpenAiChat() + { + AiChatController.ShowAiChatViewForObjects(TableID.Customer, 800, 1200); + } + } } \ No newline at end of file diff --git a/BeWo/View/Windows/AiWindowBuilder.cs b/BeWo/View/Windows/AiWindowBuilder.cs index c8303001e..87b96a998 100644 --- a/BeWo/View/Windows/AiWindowBuilder.cs +++ b/BeWo/View/Windows/AiWindowBuilder.cs @@ -28,18 +28,18 @@ namespace BeWo.View.Windows if (string.IsNullOrEmpty(title)) title = "default"; - var control = GetAiConversationControl(uIContext, context, height, width); + var control = GetAiConversationControl(uIContext, context); var window = GetAnimatedBeWoWindow(title, control, 400, height, 1000, 500, width, 1600); return window; } - public UserControl GetAiConversationControl(UIContext uIContext, Dictionary context, double height = 600, double width = 1200) + public UserControl GetAiConversationControl(UIContext uIContext, Dictionary context) { var control = new AiConversationChatView(); - control.ViewModel.UIContext = (int)(UIContext.ServiceRecord); + control.ViewModel.UIContext = (int)uIContext; control.ViewModel.ContextBeWoObjects = context; return control; diff --git a/Service/Service.csproj b/Service/Service.csproj index e4fafcd94..cfacac3fb 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -227,6 +227,11 @@ + + + + + diff --git a/Service/ServiceUtils/AiSystemBuilder.cs b/Service/ServiceUtils/AiSystemBuilder.cs index 374e5bf01..520153c38 100644 --- a/Service/ServiceUtils/AiSystemBuilder.cs +++ b/Service/ServiceUtils/AiSystemBuilder.cs @@ -2,6 +2,8 @@ using BeWo.Data.Entities; using BeWo.Service.DCEntityMapper; using BS.Shared; +using BS.Shared.DataContracts; +using BS.Shared.DataContracts.Compact; using DevExpress.PivotGrid.OLAP.Mdx; using DevExpress.XtraRichEdit.Commands; using Newtonsoft.Json; @@ -22,12 +24,13 @@ namespace BeWo.Service.ServiceUtils { var system_prompt = getSystemPrompt(2); - string data = string.Empty; + Dictionary data = null; switch (uicontext) { case 0: break; case 1: + data = createCustomerNavigationContext(bewoobjects); break; case 2: break; @@ -71,18 +74,38 @@ namespace BeWo.Service.ServiceUtils throw new NotImplementedException("UI Context unknown"); } - var result = system_prompt + data; + var text = JsonConvert.SerializeObject(data); - var escape = HttpUtility.JavaScriptStringEncode(result); + var result = system_prompt + text; - return escape; + return result; } - private static string createServiceRecordContext(Dictionary bewoobjects) + private static Dictionary createCustomerNavigationContext(Dictionary bewoobjects) { if (bewoobjects is null || !bewoobjects.Any()) return null; + var customers = new List>(); + if (bewoobjects.TryGetValue(TableID.Customer, out long[] cvalues) && (cvalues?.Length ?? 0) > 0) + { + var customers_e = DAOFactory.GenericDAO.GetByIDs(cvalues); + var customers_dc = MapperFactory.CompactCustomerDC_Customer.MapToNewDCs(customers_e); + customers = customers_dc.Select(getCustomer).ToList(); + } + + var dict = new Dictionary + { + { "Aktuelle Ansicht", "Klienten Navigation" }, + { "Klienten", customers } + }; + + return dict; + } + private static Dictionary createServiceRecordContext(Dictionary bewoobjects) + { + if (bewoobjects is null || !bewoobjects.Any()) + return null; var selected = new Dictionary(); if (bewoobjects.TryGetValue(TableID.Customer, out long[] cvalues) && (cvalues?.Length ?? 0) > 0) @@ -114,7 +137,23 @@ namespace BeWo.Service.ServiceUtils foreach (var service_record in service_records_dc) { - var record_dict = new Dictionary + records.Add(getServiceRecord(service_record)); + } + } + + var dict = new Dictionary + { + { "Aktuelle Ansicht", "Zeiterfassung" }, + { "Selected", selected }, + { "Zeiterfassungen", records } + }; + + return dict; + } + + private static Dictionary getServiceRecord(ServiceRecordDC service_record) + { + var record_dict = new Dictionary { { "StartDate", service_record.Start }, { "EndDate", service_record.End }, @@ -132,20 +171,27 @@ namespace BeWo.Service.ServiceUtils { "InsertUser", service_record.InsUser }, { "Employee", service_record.Employee } }; - records.Add(record_dict); - } - } - var dict = new Dictionary - { - { "Aktuelle Ansicht", "Zeiterfassung" }, - { "Selected", selected }, - { "Zeiterfassungen", records } - }; + return record_dict; + } + private static Dictionary getCustomer(CompactCustomerDC customer) + { + var record_dict = new Dictionary + { + {"Address", customer.AddressString}, + {"Alias", customer.CustomerAlias}, + {"CustomerOid", customer.CustomerOid}, + {"DateOfBirth", customer.DateOfBirthString}, + {"EqutyContribution", customer.EquityContribution}, + {"Fullname", customer.FullName}, + {"InvoiceAddress", customer.InvoiceAddressString} + }; - var json = JsonConvert.SerializeObject(dict); - - return json; + return record_dict; + } + private static Dictionary getEmployee(CompactEmployeeDC compactEmployee) + { + return null; } private static string getSystemPrompt(int i) diff --git a/Service/ai/Core/AiMapperFactory.cs b/Service/ai/Core/AiMapperFactory.cs new file mode 100644 index 000000000..3c4300a4f --- /dev/null +++ b/Service/ai/Core/AiMapperFactory.cs @@ -0,0 +1,36 @@ +using BeWo.Data.Entities; +using BeWo.Service.AI.Mappings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.AI.Core +{ + internal class AiMapperFactory + { + private readonly Dictionary _Mappers; + + public AiMapperFactory() + { + _Mappers = new Dictionary() + { + {typeof(CompactCustomerAiMapping), new Lazy(() => new CompactCustomerAiMapping()) }, + {typeof(CustomerAiMapping), new Lazy(() => new CustomerAiMapping()) }, + {typeof(ServiceRecordAiMapping), new Lazy(() => new ServiceRecordAiMapping()) }, + }; + } + + public T GetMapper() where T : class + { + if (_Mappers.TryGetValue(typeof(T), out var lazy)) + { + return (lazy as Lazy)?.Value; + } + + throw new InvalidOperationException($"No mapper registered for type {typeof(T).Name}"); + } + } +} diff --git a/Service/ai/Core/BaseAiMapping.cs b/Service/ai/Core/BaseAiMapping.cs new file mode 100644 index 000000000..fc7d0f6f1 --- /dev/null +++ b/Service/ai/Core/BaseAiMapping.cs @@ -0,0 +1,24 @@ +using BS.Shared.DataContracts; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.AI.Core +{ + internal abstract class BaseAiMapping where TDataContract : IDataContract + { + public string ToJson(TDataContract dataContract) + { + var json_dict = ToJsonDictionary(dataContract); + + var json = JsonConvert.SerializeObject(json_dict); + + return json; + } + + public abstract Dictionary ToJsonDictionary(TDataContract dataContract); + } +} diff --git a/Service/ai/Mappings/CompactCustomerAiMapping.cs b/Service/ai/Mappings/CompactCustomerAiMapping.cs new file mode 100644 index 000000000..3c2d2feed --- /dev/null +++ b/Service/ai/Mappings/CompactCustomerAiMapping.cs @@ -0,0 +1,18 @@ +using BeWo.Service.AI.Core; +using BS.Shared.DataContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.AI.Mappings +{ + internal class CompactCustomerAiMapping : BaseAiMapping + { + public override Dictionary ToJsonDictionary(CustomerDC customer) + { + throw new NotImplementedException(); + } + } +} diff --git a/Service/ai/Mappings/CustomerAiMapping.cs b/Service/ai/Mappings/CustomerAiMapping.cs new file mode 100644 index 000000000..c0890eeb3 --- /dev/null +++ b/Service/ai/Mappings/CustomerAiMapping.cs @@ -0,0 +1,18 @@ +using BeWo.Service.AI.Core; +using BS.Shared.DataContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.AI.Mappings +{ + internal class CustomerAiMapping : BaseAiMapping + { + public override Dictionary ToJsonDictionary(CustomerDC customer) + { + throw new NotImplementedException(); + } + } +} diff --git a/Service/ai/Mappings/ServiceRecordAiMapping.cs b/Service/ai/Mappings/ServiceRecordAiMapping.cs new file mode 100644 index 000000000..c0841b618 --- /dev/null +++ b/Service/ai/Mappings/ServiceRecordAiMapping.cs @@ -0,0 +1,18 @@ +using BeWo.Service.AI.Core; +using BS.Shared.DataContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BeWo.Service.AI.Mappings +{ + internal class ServiceRecordAiMapping : BaseAiMapping + { + public override Dictionary ToJsonDictionary(ServiceRecordDC dataContract) + { + throw new NotImplementedException(); + } + } +}