Files
BeWoPlaner/BeWo/ownChat/ChatDokumentationsView.xaml.cs
Christian 49a5f5e7dd cb
2022-04-29 20:37:37 +02:00

457 lines
20 KiB
C#

using System;
using System.Windows;
using System.Windows.Input;
using BeWo.ViewModel;
using BS.Shared.Extensions;
using System.Windows.Controls;
using System.Windows.Threading;
using System.Collections.Generic;
using BeWo.Core.Service;
using BeWo.View;
using BeWo.View.Detail;
using BeWo.ViewModel.ListViewModel;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using ChatController.ChatKlassen;
using DevExpress.XtraScheduler;
using BeWo.View.Detail.Zeiterfassung;
using BeWo.ServiceProxy;
using System.Linq;
namespace BeWo.ownChat
{
public partial class ChatDokumentationsView
{
private ServiceRecordVM _ServiceRecord;
public ChatDokumentationsView() {}
public ChatDokumentationsView(ServiceRecordListVM list, ServiceRecordVM serviceRecord)
{
InitializeComponent();
_ServiceRecord = serviceRecord;
var newView = new ServiceRecordEditView();
newView.InitView(list, serviceRecord, false);
newView.SetSearchText(serviceRecord.Customer != null ? serviceRecord.Customer.LastName : "");
CommandBindingsCloseSave(newView, null);
Popup_Content(newView);
}
//public ChatDokumentationsView(List<ChatMessage> messages, CompactCustomerDC compactCustomer)
//{
// InitializeComponent();
// CreateControl(messages, compactCustomer);
//}
//private void CreateControl(List<ChatMessage> messages, CompactCustomerDC compactCustomer)
//{
// Cache.GetInstance().GetActiveSupportConceptCostbearer(scList =>
// VMFactory.CreateServiceRecordVMAsync(
// BeWoApp.LoggedOnUser.Employee.EmployeeOid,
// vm => this.Dispatch(
// delegate
// {
// var newView = new ServiceRecordEditView();
// vm.DispatcherObject = this;
// var dc = SupportConceptService.ErstelleServiceRecordDC(firstTime, lastTime, compactCustomer, scList);
// if(vm.PrototypeVM.SortedCategories != null && vm.PrototypeVM.SortedCategories.Count > 0)
// {
// var cat1 = vm.PrototypeVM.SortedCategories[0];
// dc.ServiceDescription = vm.PrototypeVM.Category2Services[cat1][0];
// }
// serviceRecord = new ServiceRecordVM(dc, vm.PrototypeVM.Category2Services, vm.PrototypeVM.AllGoalCategories, vm.PrototypeVM.AllGoals)
// {
// Notice = message
// };
// if(serviceRecord.SupportConcept == null)
// {
// MessageBox.Show(
// Translator.Translate("Es wurde kein passender Hilfeplan gefunden."),
// "ownChat Fehler", MessageBoxButton.OK, MessageBoxImage.Exclamation);
// return;
// }
// newView.InitView(vm, serviceRecord, false);
// newView.SetSearchText(compactCustomer != null ? compactCustomer.LastName : "");
// CommandBindingsCloseSave(newView);
// Popup_Content(newView);
// EndWaiting();
// })));
//}
//Konstruktor für Kalender
public ChatDokumentationsView(string notice, CompactCustomerDC _compactCustomer, DateTime firstTime, DateTime lastTime, CompactEmployeeDC employee, Action schedulerCallback = null, Appointment appointment = null)
{
InitializeComponent();
var customerCompact = _compactCustomer;
Cache.GetInstance().GetActiveSupportConceptCostbearer(scList =>
VMFactory.CreateServiceRecordVMAsync(
BeWoApp.LoggedOnUser.Employee.EmployeeOid,
vm => this.Dispatch(
delegate
{
var serviceRecordEditView = new ServiceRecordEditView();
vm.DispatcherObject = this;
var dc = SupportConceptService.ErstelleServiceRecordDC(firstTime, lastTime, customerCompact, scList);
if (employee != null)
{
dc.Employee = employee;
}
//####
long? scOid = null;
long? customerOid = null;
long? cb2scOid = null;
if (customerCompact != null)
{
customerOid = customerCompact.Oid;
}
if (dc.SupportConcept != null)
{
scOid = dc.SupportConcept.SupportConceptOid;
if (dc.SupportConcept.CostBearerRelOids.Count > 0)
{
cb2scOid = dc.SupportConcept.CostBearerRelOids[0];
}
}
if (customerOid != null && scOid != null)
{
var infoDC = ServiceFacade.DoOperationsServiceSync(s => s.GetSupportConceptTreeNodeDetailInfo(customerOid.Value, scOid, cb2scOid));
if (infoDC.SupportConceptGoals != null && infoDC.SupportConceptGoals.Count > 0)
{
var goalCats = new List<ValueListEntryDC>();
var goals = new List<ValueListEntryDC>();
var goalCategoryDict = vm.AllGoalCategories.ToDictionary(goalCat => goalCat.ValueListEntryOid.Value);
foreach (var goal in infoDC.SupportConceptGoals)
{
if (goal.ParentOid != null && goalCategoryDict.ContainsKey(goal.ParentOid.Value))
{
var path = ServiceRecordListVM.GetAllParentGoalCategoies(goalCategoryDict, goal);
foreach (var goalCat in path)
{
goalCats.Add(goalCat);
goalCategoryDict.Remove(goalCat.ValueListEntryOid.Value);
}
}
goals.Add(goal);
}
var copyGoalCats = GoalService.CopyGoals(goalCats, false);
var copyGoals = GoalService.CopyGoals(goals, false);
vm.PrototypeVM.ChangeGoalTree(copyGoalCats, copyGoals);
}
vm.PrototypeVM.UpdateServiceAccountings(infoDC.ServiceAccountings, vm.PrototypeVM.Category2Services, true);
}
else
{
vm.PrototypeVM.UpdateServiceAccountings(null, vm.PrototypeVM.Category2Services, customerCompact != null);
}
//####
//vm.PrototypeVM.ChangeGoalTree()
if(vm.PrototypeVM.SortedCategories != null && vm.PrototypeVM.SortedCategories.Count > 0)
{
var cat1 = vm.PrototypeVM.SortedCategories[0];
dc.ServiceDescription = vm.PrototypeVM.Category2Services[cat1][0];
}
_ServiceRecord = new ServiceRecordVM(dc, vm.PrototypeVM.Category2Services, vm.PrototypeVM.AllGoalCategories, vm.PrototypeVM.AllGoals) {Notice = notice};
_ServiceRecord.SetInsertedOn(DateTime.Now);
var hideCustomerCombo = _ServiceRecord.SupportConcept == null;
serviceRecordEditView.InitView(vm, _ServiceRecord, hideCustomerCombo);
serviceRecordEditView.SetSearchText(customerCompact != null ? customerCompact.LastName : "");
CommandBindingsCloseSave(serviceRecordEditView, schedulerCallback);
Popup_Content(serviceRecordEditView);
})));
}
//GruppenBuchung Konstruktor für Kalender
public ChatDokumentationsView(string notice, DateTime firstTime, DateTime lastTime, List<CompactCustomerDC> _compactCustomer, List<CompactEmployeeDC> _compactEmployee, Action schedulerCallback = null, Appointment appointment = null)
{
InitializeComponent();
Cache.GetInstance().GetActiveSupportConceptCostbearer(scList =>
VMFactory.CreateServiceRecordVMAsync(
BeWoApp.LoggedOnUser.Employee.EmployeeOid,
vm => this.Dispatch(
delegate
{
var newView = new ServiceRecordGroupEditView();
vm.DispatcherObject = this;
var serviceRecordGroup = new ServiceRecordGroupDC
{
StartDate = firstTime,
EndDate = lastTime,
CustomerCount = _compactCustomer.Count,
EmployeeCount = _compactEmployee.Count,
Notice = notice
};
var serviceRecordList = new List<ServiceRecordDC>();
foreach (var emp in _compactEmployee)
{
foreach (var cus in _compactCustomer)
{
var supportConcept = SupportConceptService.HoleHilfeplanAusListe(scList, cus, firstTime, lastTime);
if (supportConcept != null)
{
var serviceRecord = new ServiceRecordDC
{
Start = firstTime,
End = lastTime,
Employee = emp,
Customer = cus,
SupportConcept = SupportConceptService.HoleHilfeplanAusListe(scList, cus, firstTime, lastTime),
GroupEmployeeCount = _compactEmployee.Count,
GroupPersonCount = _compactCustomer.Count
};
if (BeWoApp.AppSettings.IsEndDateVisible)
{
serviceRecord.ServiceRecordFormat = ServiceRecordFormate.ZeiterfassungMitEndDatum;
}
else if (BeWoApp.AppSettings.IsOnlyYearMonthVisible)
{
serviceRecord.ServiceRecordFormat =
ServiceRecordFormate.ZeiterfassungMitMonatJahr;
}
else
{
serviceRecord.ServiceRecordFormat = ServiceRecordFormate.OriginaleZeiterfassung;
}
serviceRecord.DurationInStunden = ZeiterfassungsDauer.Minuten;
if (serviceRecord.SupportConcept.CostBearerList != null && serviceRecord.SupportConcept.CostBearerList.Count > 0)
{
serviceRecord.CostBearer = serviceRecord.SupportConcept.CostBearerList[0].Organisation;
}
serviceRecordList.Add(serviceRecord);
}
}
}
if (serviceRecordList.Count == 0)
{
MessageBox.Show(
"Es wurden keine laufenden Hilfepläne für die ausgewählten Klienten gefunden. Die Übernahme in die Zeiterfassung ist nicht möglich.",
"Übernahme nicht möglich", MessageBoxButton.OK, MessageBoxImage.Exclamation);
Close();
return;
}
serviceRecordGroup.ServiceRecordList = serviceRecordList;
if (vm.PrototypeVM.SortedCategories != null && vm.PrototypeVM.SortedCategories.Count > 0)
{
var cat1 = vm.PrototypeVM.SortedCategories[0];
serviceRecordList[0].ServiceDescription = vm.PrototypeVM.Category2Services[cat1][0];
}
_ServiceRecord = new ServiceRecordVM(serviceRecordList[0], vm.PrototypeVM.Category2Services, vm.PrototypeVM.AllGoalCategories, vm.PrototypeVM.AllGoals) {Notice = notice};
newView.InitView(vm, _ServiceRecord, serviceRecordGroup);
if (newView.CommandBindings.Count == 0)
{
newView.CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Close,
(s, e) =>
{
if (!newView.DoSaveCheck())
{
return;
}
Close();
}));
newView.CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Save,
(s, e) =>
{
var save = newView.IsValid();
if (!save)
{
return;
}
newView.SaveData();
schedulerCallback?.Invoke();
Close();
}));
}
popup_contentChat.Child = newView;
popup_contentChat.Visibility = Visibility.Visible;
})));
}
private void CommandBindingsCloseSave(ServiceRecordEditView newView, Action schedulerCallback)
{
if (newView.CommandBindings.Count == 0)
{
newView.CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Close,
(s, e) =>
{
if (!newView.DoSaveCheck())
{
return;
}
Close();
}));
newView.CommandBindings.Add(
new CommandBinding(
ApplicationCommands.Save,
(s, e) =>
{
var isValid = newView.IsValid();
if (!isValid)
{
return;
}
// TODO: Callback einbauen, das den Termin verändert (vom Kalender übergeben)
if(newView.SaveData())
{
schedulerCallback?.Invoke();
}
Close();
}));
}
}
private void Popup_Content(UIElement serviceRecordEditView)
{
popup_contentChat.Child = serviceRecordEditView;
popup_contentChat.Visibility = Visibility.Visible;
}
private void RootGroupBox_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{
DragMove();
}
catch (Exception)
{
}
}
private DateTime ConvertToDateTimeStart(string startTime)
{
return DateTime.Parse(startTime);
}
private DateTime ConvertToDateTimeEnd(string endTime)
{
return DateTime.Parse(endTime);
}
#region Waitlayer
private WaitLayer2 _waitLayer = null;
public void StartWaiting()
{
Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)StartWaitingImmediately);
}
public void StartWaitingImmediately()
{
if (_waitLayer == null)
{
_waitLayer = new WaitLayer2();
//Grid.SetColumnSpan(_waitLayer, 3);
//Grid.SetRowSpan(_waitLayer, 3);
DokumentGrid.Children.Add(_waitLayer);// wieder einkommentieren
Panel.SetZIndex(_waitLayer, int.MaxValue);
_waitLayer.RefreshChatUI();
}
}
public void EndWaiting()
{
Dispatcher.BeginInvoke(
DispatcherPriority.Background,
(Action)delegate
{
if (_waitLayer != null)
{
DokumentGrid.Children.Remove(_waitLayer);// wieder einkommentieren
_waitLayer = null;
}
});
}
#endregion
}
}