using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using BeWo.Core; using BeWo.Core.Config; using BeWo.ServiceProxy; using BeWo.View.Detail; using BeWo.View.Navigation.Filter; 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 BeWo.Core.Service; using BeWo.MultiLanguage; using BS.Shared.Translation; using Microsoft.Win32; using BeWo.View.Windows; using DevExpress.Mvvm; using System.Collections; using System.Windows.Input; using BeWo.Core.Commands; using BeWo.ViewModel.View; namespace BeWo.View.Navigation { /// /// Interaktionslogik für SupportConceptNavigationView.xaml /// public partial class SupportConceptNavigationView : BeWoView { //private readonly CheckBox chkShowOnlyMySCs; //private readonly CheckBox chkShowOnlyTeamSCs; private readonly ComboBox supportConceptFilterComboBox; private IEnumerable objectList = null; private IEnumerable recentList = null; public SupportConceptNavigationView() { this.InitializeComponent(); mainNavigationView.OpenAiWindowCommand = CommandFactory.GetAiViewCommand(OpenAiWindow, UserRightType.AiModuleView); mainNavigationView.OpenAiPopupCommand = CommandFactory.GetAiViewCommand(OpenAiPopup, UserRightType.AiModuleView2); this.mainNavigationView.Sorter = new SupportConceptSorter(); this.mainNavigationView.ArchiveButtonVisible = BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConceptView_AllowArchiving); this.mainNavigationView.ShowArchivedObjectsVisible = true; supportConceptFilterComboBox = new ComboBox(); supportConceptFilterComboBox.FontSize = 12; supportConceptFilterComboBox.Margin = new Thickness(10, 0, 0, 0); supportConceptFilterComboBox.MinWidth = 100; supportConceptFilterComboBox.Style = FindResource("SortComboBox") as Style; if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) { supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.All)); } if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) { supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.TeamCustomer)); } supportConceptFilterComboBox.Items.Add(new CustomerFilterItem(CustomerFilterEnum.MyCustomer)); CustomerFilterItem selectedItem = null; switch (BeWoApp.AppSettings.CustomerFilterSupportConcepts) { case CustomerFilterEnum.All: if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) { selectedItem = new CustomerFilterItem(CustomerFilterEnum.All); } break; case CustomerFilterEnum.TeamCustomer: if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) || BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) { selectedItem = new CustomerFilterItem(CustomerFilterEnum.TeamCustomer); } break; } if (selectedItem == null) { selectedItem = new CustomerFilterItem(CustomerFilterEnum.MyCustomer); } supportConceptFilterComboBox.SelectedItem = selectedItem; supportConceptFilterComboBox.SelectionChanged += SupportConceptFilterComboBoxOnSelectionChanged; //else //{ // this.chkShowOnlyTeamSCs.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamSupportConcepts; //} //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) //{ // this.chkShowOnlyMySCs.IsChecked = true; // this.chkShowOnlyMySCs.IsEnabled = false; // this.chkShowOnlyTeamSCs.IsChecked = false; // this.chkShowOnlyTeamSCs.IsEnabled = false; //} //else //{ // this.chkShowOnlyMySCs.IsChecked = BeWoApp.AppSettings.ShowOnlyMySupportConcepts; //} //this.chkShowOnlyMySCs = new CheckBox(); //this.chkShowOnlyMySCs.FontSize = 12; //this.chkShowOnlyMySCs.Margin = new Thickness(10, 0, 0, 0); //this.chkShowOnlyMySCs.Content = Translator.Translate("Meine Hilfepläne"); //this.chkShowOnlyTeamSCs = new CheckBox(); //this.chkShowOnlyTeamSCs.FontSize = 12; //this.chkShowOnlyTeamSCs.Margin = new Thickness(10, 0, 0, 0); //this.chkShowOnlyTeamSCs.Content = Translator.Translate("Hilfepläne meines Teams"); //this.chkShowOnlyMySCs.VerticalAlignment = VerticalAlignment.Center; //this.chkShowOnlyTeamSCs.VerticalAlignment = VerticalAlignment.Center; //Brush b = this.FindResource("MainGroupBoxForegroundBrush") as Brush; //if (b != null) //{ // this.chkShowOnlyMySCs.Foreground = b; // this.chkShowOnlyTeamSCs.Foreground = b; //} //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) //{ // this.chkShowOnlyTeamSCs.IsChecked = true; // //this.chkShowOnlyMySCs.IsEnabled = false; //} //else //{ // this.chkShowOnlyTeamSCs.IsChecked = BeWoApp.AppSettings.ShowOnlyTeamSupportConcepts; //} //if (!BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) && !BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewMyTeams)) //{ // this.chkShowOnlyMySCs.IsChecked = true; // this.chkShowOnlyMySCs.IsEnabled = false; // this.chkShowOnlyTeamSCs.IsChecked = false; // this.chkShowOnlyTeamSCs.IsEnabled = false; //} //else //{ // this.chkShowOnlyMySCs.IsChecked = BeWoApp.AppSettings.ShowOnlyMySupportConcepts; //} // if (BeWoApp.LoggedOnUser.Employee.IsTeamLeader) // { // chkShowOnlyTeamSCs.Visibility = Visibility.Visible; // } // else // { //this.chkShowOnlyTeamSCs.Visibility = Visibility.Collapsed; // } //this.chkShowOnlyMySCs.Click += this.chkShowOnlySCs_Click; //this.chkShowOnlyTeamSCs.Click += this.chkShowOnlySCs_Click; //this.mainNavigationView.AddControlToSortPanel(this.chkShowOnlyMySCs); //this.mainNavigationView.AddControlToSortPanel(this.chkShowOnlyTeamSCs); //this.mainNavigationView.AddControlToSortPanel(this.supportConceptFilterComboBox); TextBlock lbl = new TextBlock(); lbl.Text = "Filter:"; lbl.FontSize = 12; lbl.Margin = new Thickness(8, 2, -3, 0); this.mainNavigationView.sortPanel.Children.Insert(3, lbl); this.mainNavigationView.sortPanel.Children.Insert(4, this.supportConceptFilterComboBox); this.UpdateCustomFilter(); if (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConceptView_Create)) { mainNavigationView.btnCopy.Visibility = Visibility.Visible; } if (BeWoApp.AppSettings.ShowPersehImport && BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ImportData)) { //mainNavigationView.btnImport.Visibility = Visibility.Visible; } } public Dictionary GetVisibleInformationReferences() { var visible = mainNavigationView.objectListBox.ItemsSource; return GetVisibleInformationReferences(visible); } private Dictionary GetVisibleInformationReferences(IEnumerable visible_persons) { var oids = new List(); foreach (var p in visible_persons) { var scdc = p as CompactSupportConceptDC; oids.Add(scdc.SupportConceptOid); } var dict = new Dictionary() { { TableID.SupportConcept, oids.Distinct().ToArray()} }; return dict; } private AiConversationChatViewModel getAiConversationChatViewModel() { var context = GetVisibleInformationReferences(); var vm = VMFactory.CreateAiConversationChatViewModel(AiContextType.SupportConcept, context); return vm; } private void OpenAiWindow() { MainControl.WindowService.ShowAiConversationWindow(getAiConversationChatViewModel()); } private void OpenAiPopup() { MainControl.WindowService.ShowAiConversationModalViewWindow(getAiConversationChatViewModel()); } private void SupportConceptFilterComboBoxOnSelectionChanged(object o, SelectionChangedEventArgs selectionChangedEventArgs) { //chkShowOnlyTeamSCs.IsChecked = false; //BeWoApp.AppSettings.ShowOnlyMySupportConcepts = this.chkShowOnlyMySCs.IsChecked.Value; if (this.supportConceptFilterComboBox.SelectedItem != null) { BeWoApp.AppSettings.CustomerFilterSupportConcepts = ((CustomerFilterItem) this.supportConceptFilterComboBox.SelectedItem).CustomerFilter; } else { BeWoApp.AppSettings.CustomerFilterSupportConcepts = CustomerFilterEnum.MyCustomer; } BeWoApp.SaveAppSettings(); this.UpdateCustomFilter(); } private CustomFilter CreateNewCustomFilter() { SupportConceptNavigationFilter filter = new SupportConceptNavigationFilter(); if (this.supportConceptFilterComboBox.SelectedItem != null) { filter.CustomerFilter = ((CustomerFilterItem) this.supportConceptFilterComboBox.SelectedItem).CustomerFilter; } else { filter.CustomerFilter = CustomerFilterEnum.MyCustomer; } //filter.ShowOnlyMySupportConcepts = this.chkShowOnlyMySCs.IsChecked.Value; //filter.ShowOnlyTeamSupportConcepts = this.chkShowOnlyTeamSCs.IsChecked.Value; return filter; } private void OnLoaded(object sender, RoutedEventArgs e) { ReloadData(false); CommandManager.InvalidateRequerySuggested(); } private void UpdateCustomFilter() { this.mainNavigationView.CustomFilter = this.CreateNewCustomFilter(); } private bool mainNavigationView_ArchiveObject(IFilterableDC obj) { CompactSupportConceptDC dc = obj as CompactSupportConceptDC; if (dc != null) { if (MessageBox.Show(Translator.Translate("Wollen Sie den Hilfeplan wirklich archivieren?"), "Archivieren", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { ServiceFacade.DoCustomerServiceAsync( s => { s.ArchiveSupportConcept(dc.SupportConceptOid, dc.SupportConceptVersion); return dc; }, cb => cb.SupportConceptVersion ++); Cache.GetInstance().ClearSupportConceptTree(); return true; } } return false; } private void mainNavigationView_CreateNewObject() { //VMFactory.CreateSupportConceptVMAsync(cb => this.Dispatch(() => this.MainControl.NavigateTo(new SupportConceptView2(cb) { ParentView = this }))); VMFactory.CreateSupportConceptVMAsync(cb => this.Dispatch(() => this.MainControl.NavigateTo(new SupportConceptView(cb) { ParentView = this }))); } private bool mainNavigationView_DeleteObject(IFilterableDC obj) { var dc = obj as CompactSupportConceptDC; if (dc != null) { if (MessageBox.Show(Translator.Translate("Wollen Sie den Hilfeplan wirklich löschen?"), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.Yes) { var list = ServiceFacade.DoOperationsServiceSync(s => s.GetSupportConceptInfosForSupportConceptOid(dc.SupportConceptOid)); var delete = true; if (list != null && list.Count > 0) { var containsServiceRecords = false; foreach (var info in list.Where(info => info.RecordedHours > 0)) { containsServiceRecords = true; } if (containsServiceRecords) { if (MessageBox.Show(Translator.Translate("Für den gewählten Hilfeplan wurden bereits Leistungen hinterlegt.\n Möchten Sie wirklich fortfahren und den Hilfeplan löschen?"), "Löschen", MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { delete = false; } } } if (delete) { ServiceFacade.DoCustomerServiceAsync(s => { s.DeactivateSupportConcept(dc.SupportConceptOid, dc.SupportConceptVersion); return dc; }, cb => dc.Version++); Cache.GetInstance().ClearSupportConceptTree(); return true; } } } return false; } private void mainNavigationView_ExcelExport(object sender, EventArgs> e) { var path = BeWoApp.GetAndCreateUserAppDataPath() + Translator.Translate("\\Hilfepläne.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.PrepareExcelFileSupportConceptExport(mainNavigationView.DownloadLinkEngine.ExcelFileId, e.Data.Cast().Select(c => c.SupportConceptOid).ToList()), sf.FileName)); } private void mainNavigationView_Print(object sender, EventArgs> e) { var oids = e.Data.Cast().Select(c => c.SupportConceptOid).ToList(); ServiceFacade.DoReportServiceAsync(s => s.CreateSupportConceptListReport(oids), r => { this.Dispatch(() => { BeWoUtils.ShowReportWindow(r, "Hilfepläne"); }); }); } private void mainNavigationView_OpenObject(IFilterableDC obj) { var dc = obj as CompactSupportConceptDC; if (dc != null) { VMFactory.CreateSupportConceptVMAsync(dc.SupportConceptOid, cb => this.Dispatch(() => MainControl.NavigateTo(new SupportConceptView(cb) {ParentView = this}))); //VMFactory.CreateSupportConceptVMAsync(dc.SupportConceptOid, cb => this.Dispatch( // () => this.MainControl.NavigateTo(new SupportConceptView2(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.GetAllSupportConceptsCompact(BeWoApp.LoggedOnUser.Employee.EmployeeOid), r => this.Dispatch(delegate { objectList = r; mainNavigationView.ShowSearchResult(objectList); })); ServiceFacade.DoCustomerServiceAsync(s => s.GetLastOpenedSupportConcepts(), r => this.Dispatch(delegate { recentList = r; mainNavigationView.ShowHistory(recentList); })); } else { mainNavigationView.ShowSearchResult(objectList); mainNavigationView.ShowHistory(recentList); } } private void MainNavigationView_OnOpenMailMergeWindow(List allSupportConcepts, IFilterableDC selectedSupportConcept) { var mmw = new MailMergeWindow(this, typeof(SupportConceptDC), objectList.ToList(), selectedSupportConcept) { Sorter = new SupportConceptSorter() }; mmw.Show(); } public void MainNavigationView_OnReactivateObject(CompactSupportConceptDC selectedSupportConcept) { if (MessageBox.Show(Translator.Translate("Wollen Sie den Hilfeplan wirklich reaktivieren?"), Translator.Translate("Reaktivieren"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return; } ServiceFacade.DoCustomerServiceAsync(s => { s.ReactivateSupportConcept(selectedSupportConcept.SupportConceptOid, selectedSupportConcept.Version); return selectedSupportConcept; }, cb => cb.SupportConceptVersion++); Cache.GetInstance().ClearSupportConceptTree(); selectedSupportConcept.ActivationType = ActivationTypeId.Active; var context = mainNavigationView.objectListBox.DataContext; mainNavigationView.objectListBox.DataContext = null; mainNavigationView.objectListBox.DataContext = context; } public void MainNavigationView_AusArchivHolen(CompactSupportConceptDC selectedSupportConcept) { if (MessageBox.Show(Translator.Translate("Wollen Sie den Hilfeplan wirklich aus dem Archiv holen?"), Translator.Translate("Aus Archiv holen"), MessageBoxButton.YesNo, MessageBoxImage.Exclamation) == MessageBoxResult.No) { return; } ServiceFacade.DoCustomerServiceAsync(s => { s.ReactivateSupportConcept(selectedSupportConcept.SupportConceptOid, selectedSupportConcept.Version); return selectedSupportConcept; }, cb => cb.SupportConceptVersion++); Cache.GetInstance().ClearSupportConceptTree(); selectedSupportConcept.ActivationType = ActivationTypeId.Active; var context = mainNavigationView.objectListBox.DataContext; mainNavigationView.objectListBox.DataContext = null; mainNavigationView.objectListBox.DataContext = context; } private void MainNavigation_CopyObject(IFilterableDC obj) { var csc = (CompactSupportConceptDC) obj; var copy = new SupportConceptDC(); ServiceFacade.DoCustomerServiceAsync(s => s.LoadSupportConcept(csc.SupportConceptOid), cb => { copy.ActivationType = ActivationTypeId.Active; copy.Conference = cb.Conference; copy.ConferenceVenue = cb.ConferenceVenue; copy.ConsultingNeeded = cb.ConsultingNeeded; copy.Customer = cb.Customer; copy.Notice = cb.Notice; copy.Originator = cb.Originator; copy.ServiceAccountings = new List(); foreach (var kategorie in cb.ServiceAccountings) { var kat = new ServiceAccountingDC { AccountingInterval = kategorie.AccountingInterval, BillableAmount = kategorie.BillableAmount, IsDefault = kategorie.IsDefault, ServiceDescription = kategorie.ServiceDescription }; copy.ServiceAccountings.Add(kat); } foreach (var kt in cb.CostBearerRelations) { var rel = new SupportConceptCostBearerRelDC { CostBearer = kt.CostBearer, CostBearerContactPerson = kt.CostBearerContactPerson, CustomerReferenceNumber = kt.CustomerReferenceNumber, Notice = kt.Notice, Status = CostBearer2SupportConceptStatus.Created, SupportConcept = kt.SupportConcept }; if (kt.ApprovalPeriodList != null && kt.ApprovalPeriodList.Count > 0) { var ap1 = kt.ApprovalPeriodList[0]; rel.ApprovalPeriodList = new List(); var newap = new SupportConceptApprovalPeriodDC { IsApprovedBEShifting = ap1.IsApprovedBEShifting, IsApprovedFixedAmountShifting = ap1.IsApprovedFixedAmountShifting, ApprovedBEInterval = ap1.ApprovedBEInterval }; if (ap1.SupportConceptApprovalPeriodEmployeeRelations != null) { newap.SupportConceptApprovalPeriodEmployeeRelations = new List(); foreach (var item in ap1.SupportConceptApprovalPeriodEmployeeRelations) { newap.SupportConceptApprovalPeriodEmployeeRelations.Add(new SupportConceptApprovalPeriodEmployeeRelDC { Betreuungsschluessel = item.Betreuungsschluessel, Employee = item.Employee, IsAbsolut = item.IsAbsolut }); } } rel.ApprovalPeriodList.Add(newap); } copy.CostBearerRelations.Add(rel); } copy.Goals = new List(cb.Goals); VMFactory.CreateSupportConceptVMAsync(copy, sc => this.Dispatch(() => this.MainControl.NavigateTo(new SupportConceptView(sc) { ParentView = this })), true); //ServiceFacade.DoCustomerServiceAsync(s2 => s2.InsertNewSupportConcept(copy), l => this.Dispatch(() => ReloadData(true))); }); } private void MainNavigationView_OnImportObjects() { var ctrl = new HilfeplanImportView(null); var beWoWindow = BeWoWindowBuilder.GetBeWoWindow(Translator.Translate("Importiere Hilfeplan"), ctrl, this.Height, this.Width); ctrl.CloseButtonClicked += () => beWoWindow.Close(); beWoWindow.ShowDialog(); if (ctrl.ImportedSupportConcept != null) { VMFactory.CreateSupportConceptVMAsync(ctrl.ImportedSupportConcept, cb => this.Dispatch(() => this.MainControl.NavigateTo(new SupportConceptView(cb) { ParentView = this })), true); } //ReloadData(true); } } }