910 lines
36 KiB
C#
910 lines
36 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Input;
|
|
|
|
using BeWo.Annotations;
|
|
using BeWo.Core;
|
|
using BeWo.Core.Service;
|
|
using BeWo.Scheduler.Utils;
|
|
using BeWo.Scheduler.ViewModel;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.View.Search;
|
|
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.Mvvm.Native;
|
|
using DevExpress.Xpf.Editors;
|
|
using DevExpress.Xpf.Scheduler.UI;
|
|
using DevExpress.XtraScheduler;
|
|
using Employee2SchedulerAppointmentDC = BS.Shared.DataContracts.Employee2SchedulerAppointmentDC;
|
|
using SchedulerControl = DevExpress.Xpf.Scheduler.SchedulerControl;
|
|
|
|
namespace BeWo.Scheduler.View
|
|
{
|
|
public partial class SchedulerAppointmentEditForm : INotifyPropertyChanged
|
|
{
|
|
public bool IsInCustomerViewMode { get; set; }
|
|
|
|
private readonly bool IsInTaskViewMode;
|
|
|
|
private List<ValueListEntryDC> _Categories;
|
|
public List<ValueListEntryDC> Categories
|
|
{
|
|
get => _Categories;
|
|
set { _Categories = value; OnPropertyChanged(nameof(Categories)); }
|
|
}
|
|
|
|
private List<ResourceDC> _ResourceList;
|
|
public List<ResourceDC> ResourceList
|
|
{
|
|
get => _ResourceList;
|
|
set { _ResourceList = value; OnPropertyChanged(nameof(ResourceList)); }
|
|
}
|
|
|
|
public SchedulerAppointmentListVM ViewModel { get; set; }
|
|
|
|
private static void RecurrenceControlLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
LocalizeVisualChild(sender as DependencyObject);
|
|
}
|
|
|
|
public NewSchedulerAppointmentFormController NewSchedulerAppointmentFormController => Controller as NewSchedulerAppointmentFormController;
|
|
|
|
private ObservableCollection<ResourceDC> _SelectedResources;
|
|
public ObservableCollection<ResourceDC> SelectedResources
|
|
{
|
|
get => _SelectedResources ?? (_SelectedResources = new ObservableCollection<ResourceDC>(NewSchedulerAppointmentFormController.ResourceList ?? new List<ResourceDC>()));
|
|
set
|
|
{
|
|
_SelectedResources = value;
|
|
SelectedResources.CollectionChanged += SelectedResourcesCollectionChanged;
|
|
NewSchedulerAppointmentFormController.ResourceList = value.ToList();
|
|
OnPropertyChanged(nameof(SelectedResources));
|
|
}
|
|
}
|
|
|
|
private ObservableCollection<Employee2SchedulerAppointmentDC> _SelectedEmployees;
|
|
public ObservableCollection<Employee2SchedulerAppointmentDC> SelectedEmployees
|
|
{
|
|
get => _SelectedEmployees ?? (_SelectedEmployees = new ObservableCollection<Employee2SchedulerAppointmentDC>(NewSchedulerAppointmentFormController.EmployeeList ?? new ObservableCollection<Employee2SchedulerAppointmentDC>()));
|
|
set
|
|
{
|
|
if(_SelectedEmployees.Equals(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_SelectedEmployees = value;
|
|
SelectedEmployees.CollectionChanged += SelectedEmployeesCollectionChanged;
|
|
NewSchedulerAppointmentFormController.EmployeeList = value;
|
|
OnPropertyChanged(nameof(SelectedEmployees));
|
|
}
|
|
}
|
|
|
|
private ObservableCollection<CompactCustomerDC> _SelectedCustomers;
|
|
public ObservableCollection<CompactCustomerDC> SelectedCustomers
|
|
{
|
|
get => _SelectedCustomers ?? (_SelectedCustomers = new ObservableCollection<CompactCustomerDC>(NewSchedulerAppointmentFormController.CustomerList ?? new List<CompactCustomerDC>()));
|
|
set
|
|
{
|
|
if(_SelectedCustomers.Equals(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_SelectedCustomers = value;
|
|
SelectedCustomers.CollectionChanged += SelectedCustomersCollectionChanged;
|
|
NewSchedulerAppointmentFormController.CustomerList = value.ToList();
|
|
OnPropertyChanged(nameof(SelectedCustomers));
|
|
}
|
|
}
|
|
|
|
private ObservableCollection<CompactSupportConceptDC> _SelectedSupportConcepts;
|
|
|
|
public ObservableCollection<CompactSupportConceptDC> SelectedSupportConcepts
|
|
{
|
|
get => _SelectedSupportConcepts ?? (_SelectedSupportConcepts = new ObservableCollection<CompactSupportConceptDC>(NewSchedulerAppointmentFormController.SupportConceptList ?? new List<CompactSupportConceptDC>()));
|
|
|
|
set
|
|
{
|
|
if(Equals(_SelectedSupportConcepts, value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_SelectedSupportConcepts = value;
|
|
SelectedSupportConcepts.CollectionChanged += SelectedSupportConceptsCollectionChanged;
|
|
NewSchedulerAppointmentFormController.SupportConceptList = value.ToList();
|
|
OnPropertyChanged(nameof(SelectedSupportConcepts));
|
|
}
|
|
}
|
|
|
|
public static Appointment CurrentAppointment { get; set; }
|
|
public static bool IsNew { get; set; }
|
|
public static bool IsOwnAppointment { get; set; }
|
|
public static bool IsAllowedToChange { get; set; }
|
|
|
|
public SchedulerAppointmentEditForm(SchedulerAppointmentListVM vm, SchedulerControl schedulerControl, Appointment appointment, IEnumerable<CompactEmployeeDC> employees, IEnumerable<CompactCustomerDC> customers, Dictionary<ValueListEntryDC, List<ResourceDC>> categoriesToResources, bool pIsInTaskViewMode) : base(schedulerControl, appointment)
|
|
{
|
|
ViewModel = vm;
|
|
|
|
CurrentAppointment = appointment;
|
|
IsNew = Controller.IsNewAppointment;
|
|
|
|
IsOwnAppointment = Equals(MainSession.CompactLoggedOnEmployee, NewSchedulerAppointmentFormController.Originator) && (NewSchedulerAppointmentFormController.EmployeeList?.Count == 0 || NewSchedulerAppointmentFormController.EmployeeList.Any(a => Equals(a.Employee, MainSession.CompactLoggedOnEmployee)));
|
|
|
|
IsInTaskViewMode = pIsInTaskViewMode;
|
|
|
|
InitializeComponent();
|
|
|
|
EdtRecurrenceType.Visibility = ShouldShowRecurrence ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
SelectedResources.CollectionChanged += SelectedResourcesCollectionChanged;
|
|
SelectedCustomers.CollectionChanged += SelectedCustomersCollectionChanged;
|
|
SelectedEmployees.CollectionChanged += SelectedEmployeesCollectionChanged;
|
|
SelectedSupportConcepts.CollectionChanged += SelectedSupportConceptsCollectionChanged;
|
|
|
|
DataContext = this;
|
|
|
|
Categories = categoriesToResources.Keys.ToList();
|
|
|
|
if(categoriesToResources.Count > 0)
|
|
{
|
|
ResourceList = categoriesToResources.First().Value;
|
|
}
|
|
|
|
MonthlyRecurrenceControl.Loaded += RecurrenceControlLoaded;
|
|
YearlyRecurrenceControl.Loaded += RecurrenceControlLoaded;
|
|
|
|
ResourcesTreeSearchView.Sauce = categoriesToResources;
|
|
ResourcesTreeSearchView.AusgewaehlteRessourcen = SelectedResources.ToList();
|
|
ResourcesTreeSearchView.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => this.Dispatch(() => { PopupResource.IsOpen = false; })));
|
|
|
|
MultiEmployeeSearch.Sauce = employees.ToObservableCollection();
|
|
MultiEmployeeSearch.AusgewaehlteMitarbeiter = SelectedEmployees.Select(e=>e.Employee).ToList();
|
|
MultiEmployeeSearch.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => this.Dispatch(() => { PopupEmployee.IsOpen = false; })));
|
|
|
|
MultiCustomerSearch.Sauce = customers.ToObservableCollection();
|
|
MultiCustomerSearch.AusgewaehlteKlienten = SelectedCustomers.ToList();
|
|
MultiCustomerSearch.CommandBindings.Add(new CommandBinding(ApplicationCommands.Close, (s, e) => this.Dispatch(() => { CustomerSearchViewPopup.IsOpen = false; })));
|
|
|
|
EdtRecurrenceType.CustomDisplayText += EdtRecurrenceType_CustomDisplayText;
|
|
|
|
if(IsInTaskViewMode && !SelectedEmployees.Any(a => a.Employee.Equals(MainSession.CompactLoggedOnEmployee)))
|
|
{
|
|
SelectedEmployees.Add(new Employee2SchedulerAppointmentDC { Employee = MainSession.CompactLoggedOnEmployee });
|
|
MitarbeiterToggleButton.IsChecked = true;
|
|
}
|
|
|
|
InitRights();
|
|
}
|
|
|
|
private void InitRights()
|
|
{
|
|
var darfKlientermineAnsehen = BeWoUtils.HasRight(UserRightType.CustomerView_View);
|
|
var darfKliententermineAnlegen = BeWoUtils.HasRight(UserRightType.KalenderKliententermineAnlegen);
|
|
var darfKliententermineAendern = BeWoUtils.HasRight(UserRightType.KalenderKliententermineAendern);
|
|
|
|
var darfMitarbeitertermineAnlegen = BeWoUtils.HasRight(UserRightType.KalenderMitarbeitertermineAnlegen);
|
|
var darfMitarbeitertermineAendern = BeWoUtils.HasRight(UserRightType.KalenderMitarbeitertermineAendern);
|
|
|
|
var darfRessourcentermineAnlegen = BeWoUtils.HasRight(UserRightType.KalenderRessourcentermineAnlegen);
|
|
var darfRessourcentermineAendern = BeWoUtils.HasRight(UserRightType.KalenderRessourcentermineAendern);
|
|
|
|
if(IsNew && !darfKliententermineAnlegen)
|
|
{
|
|
KlientenPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
SelectedCustomers.Clear();
|
|
}
|
|
|
|
if(!IsNew && (!darfKliententermineAendern || !darfKlientermineAnsehen) || !darfKlientermineAnsehen)
|
|
{
|
|
KlientenPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
}
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
if(IsNew && !darfMitarbeitertermineAnlegen)
|
|
{
|
|
MitarbeiterPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
SelectedEmployees.Clear();
|
|
}
|
|
|
|
if(!IsNew && (!darfMitarbeitertermineAendern || !darfMitarbeitertermineAnlegen))
|
|
{
|
|
MitarbeiterPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
}
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
if(IsNew && !darfRessourcentermineAnlegen)
|
|
{
|
|
RessourcenPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
SelectedResources.Clear();
|
|
}
|
|
|
|
if(!IsNew && !darfRessourcentermineAendern)
|
|
{
|
|
RessourcenPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
}
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
var checkType = IsNew ? SchedulerRightsCheckType.Create : SchedulerRightsCheckType.Edit;
|
|
var allowedToChange = BS.Shared.Core.Utils.CheckSchedulerRights(SelectedCustomers.ToList(), SelectedResources.ToList(), SelectedEmployees.ToList(), NewSchedulerAppointmentFormController.Originator, IsNew, checkType, MainSession.LoggedOnUser);
|
|
|
|
if(IsInTaskViewMode)
|
|
{
|
|
BetreffLabel.Content = "Titel";
|
|
StartLabel.Content = "Beginn";
|
|
|
|
EndDate.Visibility = Visibility.Collapsed;
|
|
EndTime.Visibility = Visibility.Collapsed;
|
|
EndLabel.Visibility = Visibility.Collapsed;
|
|
AllDay.Visibility = Visibility.Collapsed;
|
|
OrtLabel.Visibility = Visibility.Collapsed;
|
|
Ort.Visibility = Visibility.Collapsed;
|
|
SerienLabel.Visibility = Visibility.Collapsed;
|
|
EdtRecurrenceType.Visibility = Visibility.Collapsed;
|
|
SerienGrid.Visibility = Visibility.Collapsed;
|
|
IsPrivateCheckBox.Visibility = Visibility.Collapsed;
|
|
NoticeLabel.Visibility = Visibility.Collapsed;
|
|
Notice.Visibility = Visibility.Collapsed;
|
|
|
|
DueDateLabel.Visibility = Visibility.Visible;
|
|
DueDate.Visibility = Visibility.Visible;
|
|
DueDateTime.Visibility = Visibility.Visible;
|
|
TaskDescriptionLabel.Visibility = Visibility.Visible;
|
|
TaskDescription.Visibility = Visibility.Visible;
|
|
|
|
SupportConceptBtn.Visibility = Visibility.Visible;
|
|
SupportConceptsPopUpOeffnenBtn.Visibility = Visibility.Visible;
|
|
SelectedSupportConceptsListBox.Visibility = Visibility.Visible;
|
|
|
|
CustomersLabel.Visibility = Visibility.Collapsed;
|
|
CustomersGrid.Visibility = Visibility.Collapsed;
|
|
CustomerSearchViewPopup.Visibility = Visibility.Collapsed;
|
|
SelectedCustomersListBox.Visibility = Visibility.Collapsed;
|
|
KlientenPopUpOeffnenBtn.Visibility = Visibility.Collapsed;
|
|
|
|
SelectedCustomers.Clear();
|
|
|
|
if (!Controller.IsNewAppointment)
|
|
{
|
|
NoticeLabel.Visibility = Visibility.Visible;
|
|
Notice.Visibility = Visibility.Visible;
|
|
|
|
CompletedDateLabel.Visibility = Visibility.Visible;
|
|
CompletedDate.Visibility = Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
NewSchedulerAppointmentFormController.DisplayDueDateTime = NewSchedulerAppointmentFormController.DueDate;
|
|
|
|
IsAllowedToChange = allowedToChange;
|
|
|
|
if(allowedToChange)
|
|
{
|
|
return;
|
|
}
|
|
|
|
BetreffEditText.IsReadOnly = true;
|
|
Ort.IsReadOnly = true;
|
|
StartDate.IsReadOnly = true;
|
|
StartTime.IsReadOnly = true;
|
|
AllDay.IsReadOnly = true;
|
|
EndDate.IsReadOnly = true;
|
|
EndTime.IsReadOnly = true;
|
|
TaskDescription.IsReadOnly = true;
|
|
CompletedDate.IsReadOnly = true;
|
|
EdtRecurrenceType.IsReadOnly = true;
|
|
IsPrivateCheckBox.IsEnabled = false;
|
|
Notice.IsReadOnly = true;
|
|
|
|
KlientenPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
MitarbeiterPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
RessourcenPopUpOeffnenBtn.Visibility = Visibility.Hidden;
|
|
SupportConceptsPopUpOeffnenBtn.Visibility = Visibility.Collapsed;
|
|
|
|
OkButton.Visibility = Visibility.Collapsed;
|
|
DeleteButton.Visibility = Visibility.Collapsed;
|
|
|
|
CancelButton.HorizontalAlignment = HorizontalAlignment.Right;
|
|
}
|
|
|
|
private static void EdtRecurrenceType_CustomDisplayText(object sender, CustomDisplayTextEventArgs e)
|
|
{
|
|
var conv = new Converter.Recurrence2GermanConverter();
|
|
|
|
e.DisplayText = (string) conv.Convert(e.EditValue, typeof (string), null, null);
|
|
e.Handled = true;
|
|
}
|
|
|
|
public string CountSelectedEmployees => $"{SelectedEmployees.Count} Mitarbeiter ausgewählt";
|
|
public string CountSelectedResources => $"{SelectedResources.Count} Resourcen ausgewählt";
|
|
public string CountSelectedCustomers => $"{SelectedCustomers.Count} Klienten ausgewählt";
|
|
public string CountSelectedSupportConcepts => $"{SelectedSupportConcepts.Count} Hilfepläne ausgewählt";
|
|
|
|
public override AppointmentFormController CreateFormController(SchedulerControl schedulerControl, Appointment appointment)
|
|
{
|
|
return new NewSchedulerAppointmentFormController(schedulerControl, appointment);
|
|
}
|
|
|
|
private void SelectedCustomersCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
NewSchedulerAppointmentFormController.CustomerList = SelectedCustomers.ToList();
|
|
MultiCustomerSearch.AusgewaehlteKlienten = SelectedCustomers.ToList();
|
|
}
|
|
|
|
private void SelectedResourcesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
NewSchedulerAppointmentFormController.ResourceList = SelectedResources.ToList();
|
|
ResourcesTreeSearchView.AusgewaehlteRessourcen = SelectedResources.ToList();
|
|
}
|
|
|
|
private void SelectedEmployeesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
NewSchedulerAppointmentFormController.EmployeeList = SelectedEmployees;
|
|
MultiEmployeeSearch.AusgewaehlteMitarbeiter = SelectedEmployees.Select(em => em.Employee).ToList();
|
|
}
|
|
|
|
private void SelectedSupportConceptsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
{
|
|
NewSchedulerAppointmentFormController.SupportConceptList = SelectedSupportConcepts.ToList();
|
|
}
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
[NotifyPropertyChangedInvocator]
|
|
protected void OnPropertyChanged(string propertyName)
|
|
{
|
|
var handler = PropertyChanged;
|
|
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
|
|
private void EmployeePopupClick(object sender, RoutedEventArgs e)
|
|
{
|
|
PopupEmployee.IsOpen = true;
|
|
}
|
|
|
|
private void CustomerPopUpEditClick(object sender, RoutedEventArgs e)
|
|
{
|
|
ResourcesTreeSearchView.AusgewaehlteRessourcen = _SelectedResources.ToList();
|
|
CustomerSearchViewPopup.IsOpen = true;
|
|
}
|
|
|
|
private void ResourcePopUpClick(object sender, RoutedEventArgs e)
|
|
{
|
|
PopupResource.IsOpen = true;
|
|
}
|
|
|
|
private void OkButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
var isWeeklyRecurrence = RecurrenceVisualController.IsWeeklyRecurrence;
|
|
var weekDays = WeeklyRecurrenceControl.WeekDays;
|
|
|
|
if (isWeeklyRecurrence && weekDays == 0)
|
|
{
|
|
MessageBox.Show("Bei einem sich wöchentlich wiederholenden Termin muss mindestens ein Wochentag ausgewählt sein!", "Fehler", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
|
return;
|
|
}
|
|
|
|
Controller.Storage.BeginUpdate();
|
|
|
|
var employees = NewSchedulerAppointmentFormController.EmployeeList;
|
|
var customers = NewSchedulerAppointmentFormController.CustomerList;
|
|
var resources = NewSchedulerAppointmentFormController.ResourceList;
|
|
var originator = NewSchedulerAppointmentFormController.Originator;
|
|
var isPrivate = NewSchedulerAppointmentFormController.IsPrivate;
|
|
var isTask = NewSchedulerAppointmentFormController.IsTask;
|
|
var taskDescription = NewSchedulerAppointmentFormController.TaskDescription;
|
|
var dueDate = NewSchedulerAppointmentFormController.DueDate;
|
|
var dueTime = NewSchedulerAppointmentFormController.DisplayDueDateTime;
|
|
var completedDate = NewSchedulerAppointmentFormController.CompletedDate;
|
|
var completedNotice = Appointment.Description;
|
|
var supportConceptList = NewSchedulerAppointmentFormController.SupportConceptList;
|
|
var start = NewSchedulerAppointmentFormController.Start;
|
|
var end = NewSchedulerAppointmentFormController.End;
|
|
|
|
|
|
ViewModel.NewVM.AllDay = !Appointment.AllDay;
|
|
ViewModel.NewVM.IsPrivate = isPrivate;
|
|
ViewModel.NewVM.ResourceList = resources;
|
|
ViewModel.NewVM.CustomerList = customers;
|
|
ViewModel.NewVM.EmployeeList = new ObservableCollection<Employee2SchedulerAppointmentDC>(employees);
|
|
ViewModel.NewVM.Originator = originator;
|
|
ViewModel.NewVM.IsTask = isTask;
|
|
ViewModel.NewVM.TaskDescription = taskDescription;
|
|
ViewModel.NewVM.DueDate = dueDate;
|
|
ViewModel.NewVM.DueTime = dueTime;
|
|
ViewModel.NewVM.CompletedDate = completedDate;
|
|
ViewModel.NewVM.CompletedNotice = completedNotice;
|
|
ViewModel.NewVM.SupportConceptList = supportConceptList;
|
|
ViewModel.NewVM.Start = start;
|
|
ViewModel.NewVM.End = end;
|
|
|
|
// Änderung an den CustomFields lösen das NewSchedulerStorage_AppointmentsChanged-Event aus
|
|
|
|
var employeeOids = new List<long>();
|
|
var customerOids = new List<long>();
|
|
var overlaps = false;
|
|
|
|
foreach (var emp in employees)
|
|
{
|
|
employeeOids.AddIfNotIn(emp.Employee.EmployeeOid);
|
|
}
|
|
|
|
foreach (var customer in customers)
|
|
{
|
|
customerOids.AddIfNotIn(customer.CustomerOid);
|
|
}
|
|
|
|
var item = (SchedulerAppointmentVM) Appointment.GetSourceObject(Control.GetCoreStorage());
|
|
|
|
if(!IsInTaskViewMode){
|
|
ServiceFacade.DoResourceServiceSync(definedBelow => overlaps = definedBelow.OverlappingAppointmentsExist(Appointment.Start, Appointment.End, employeeOids, customerOids, resources.Select(res => res.ResourceOid.Value).ToList(), ViewModel.NewVM.Originator.EmployeeOid, item?.CommitToDataContract().SchedulerAppointmentOid, string.Empty, Appointment.RecurrenceIndex));
|
|
|
|
if (overlaps)
|
|
{
|
|
var erg = MessageBox.Show("Dieser Termin überschneidet sich mit einem anderen bereits existierenden Termin.\n Möchten Sie ihn wirklich speichern?", "Überschneidung", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
|
|
|
|
if (erg.Equals(MessageBoxResult.No))
|
|
{
|
|
Controller.Storage.EndUpdate();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
ViewModel.ShouldLockOverlappingAppointmentCheck = true;
|
|
|
|
if (Appointment.RecurrenceInfo != null)
|
|
{
|
|
ViewModel.ApplyChangesToChangedOccurencyCustomFields(employees, customers, resources, originator, isPrivate, Appointment.RecurrenceIndex.ToString(), new Guid(Appointment.RecurrenceInfo.Id.ToString()), isTask, taskDescription, completedDate, dueDate, completedNotice, supportConceptList, Appointment.Subject, Appointment.AllDay);
|
|
}
|
|
|
|
//if(Appointment.IsOccurrence && item == null)
|
|
//{
|
|
// Appointment.GetCustomFieldStorage().EmployeeList.ForEach(each =>
|
|
// {
|
|
// each.Employee2SchedulerAppointmentOid = null;
|
|
// each.Employee2SchedulerAppointmentVersion = null;
|
|
// each.SchedulerAppointmentOid = null;
|
|
// each.IsPChanged = false;
|
|
// each.IsPC_CheckedTs = null;
|
|
// });
|
|
//}
|
|
|
|
ApplyChanges();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
MessageBox.Show(exception.Message + "\n" + exception.StackTrace);
|
|
}
|
|
finally
|
|
{
|
|
Controller.Storage.EndUpdate();
|
|
ViewModel.ShouldLockOverlappingAppointmentCheck = false;
|
|
}
|
|
}
|
|
|
|
private void CancelButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
Cancel();
|
|
}
|
|
|
|
private void DeleteButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
DeleteAppointment();
|
|
}
|
|
|
|
private void CreatZeiterfassungButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var employ = SelectedMitarbeiter.Items;
|
|
var y = SelectedCustomersListBox.Items;
|
|
|
|
|
|
if(y.Count == 0)
|
|
{
|
|
MessageBox.Show("Bitte wählen Sie mindestens einen Klienten aus!");
|
|
}
|
|
else
|
|
{
|
|
var startDate = StartDate.DateTime;
|
|
var startTime = DateTime.Parse(StartTime.Text);
|
|
|
|
var endDate = EndDate.DateTime;
|
|
var endTime = DateTime.Parse(EndTime.Text);
|
|
|
|
var start = new DateTime(startDate.Year, startDate.Month, startDate.Day, startTime.Hour, startTime.Minute, startTime.Second);
|
|
var end = new DateTime(endDate.Year, endDate.Month, endDate.Day, endTime.Hour, endTime.Minute, endTime.Second);
|
|
|
|
var employeelist = (from Employee2SchedulerAppointmentDC xy in employ select xy.Employee).ToList();
|
|
|
|
var customerlist = y.Cast<CompactCustomerDC>().ToList();
|
|
|
|
BeWoUtils.CreateZeiterfassung(start, end, customerlist, employeelist, Notice.Text);
|
|
}
|
|
}
|
|
|
|
private void BtnRemoveElement_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var obj = ((Button) sender).Tag;
|
|
|
|
switch(obj)
|
|
{
|
|
case ResourceDC res:
|
|
SelectedResources.Remove(res);
|
|
OnPropertyChanged(nameof(CountSelectedResources));
|
|
break;
|
|
case CompactCustomerDC cus:
|
|
SelectedCustomers.Remove(cus);
|
|
OnPropertyChanged(nameof(CountSelectedCustomers));
|
|
break;
|
|
case CompactSupportConceptDC sup:
|
|
SelectedSupportConcepts.Remove(sup);
|
|
OnPropertyChanged(nameof(CountSelectedSupportConcepts));
|
|
break;
|
|
}
|
|
|
|
if(!(obj is Employee2SchedulerAppointmentDC))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var emp = (Employee2SchedulerAppointmentDC) obj;
|
|
SelectedEmployees.Remove(emp);
|
|
OnPropertyChanged(nameof(CountSelectedEmployees));
|
|
}
|
|
|
|
private void ResourcesTreeSearchView_OnSelectionChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
var resourcesTreeSearchView = (ResourcesTreeSearchView) e.Source;
|
|
|
|
var resOC = resourcesTreeSearchView.SelectedResources.ToObservableCollection();
|
|
foreach (var res in resOC.Where(res => !SelectedResources.Contains(res)))
|
|
{
|
|
SelectedResources.Add(res);
|
|
}
|
|
|
|
SelectedResources = SelectedResources.Except(SelectedResources.Where(sr => !resOC.Contains(sr)).ToList()).ToObservableCollection();
|
|
|
|
OnPropertyChanged(nameof(CountSelectedResources));
|
|
}
|
|
|
|
private void MultiEmployeeSearch_OnSelectionChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
var multiEmployeeSearch = (MultiEmployeeSearch)e.Source;
|
|
|
|
var empOC = multiEmployeeSearch.SelectedEmployees.ToObservableCollection();
|
|
foreach (var emp in empOC.Where(emp => !SelectedEmployees.Any(se => se.Employee.Equals(emp))))
|
|
{
|
|
SelectedEmployees.Add(new Employee2SchedulerAppointmentDC { Employee = emp, ParticipationAnswer = ParticipationAnswer.Offen });
|
|
}
|
|
|
|
var ex = SelectedEmployees.Where(se => !empOC.Contains(se.Employee));
|
|
var ab = SelectedEmployees.Except(ex);
|
|
var cd = ab.ToObservableCollection();
|
|
SelectedEmployees = cd;
|
|
|
|
OnPropertyChanged(nameof(CountSelectedEmployees));
|
|
}
|
|
|
|
private void MultiCustomerSearch_OnSelectionChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
var multiCustomerSearchView = (MultiCustomerSearchView)e.Source;
|
|
SelectedCustomers = multiCustomerSearchView.SelectedCustomers.ToObservableCollection();
|
|
|
|
OnPropertyChanged(nameof(CountSelectedCustomers));
|
|
}
|
|
|
|
private void SupportConceptsPopUpClick(object sender, RoutedEventArgs e)
|
|
{
|
|
PopupSupportConcepts.IsOpen = true;
|
|
}
|
|
|
|
private void SupportConceptSelectionControl_ItemSelected(object sender, EventArgs<CompactSupportConceptDC> e)
|
|
{
|
|
PopupSupportConcepts.IsOpen = false;
|
|
|
|
SelectedSupportConcepts.Clear();
|
|
SelectedSupportConcepts.Add(e.Data);
|
|
|
|
OnPropertyChanged(nameof(CountSelectedSupportConcepts));
|
|
OnPropertyChanged(nameof(SelectedSupportConcepts));
|
|
}
|
|
|
|
private void BtnRemoveSupportConcept_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if(((Button) sender).Tag is CompactSupportConceptDC dc)
|
|
{
|
|
SelectedSupportConcepts.Remove(dc);
|
|
|
|
OnPropertyChanged(nameof(CountSelectedSupportConcepts));
|
|
}
|
|
}
|
|
}
|
|
|
|
public class NewSchedulerAppointmentFormController : AppointmentFormController
|
|
{
|
|
private List<ResourceDC> SourceResourceList
|
|
{
|
|
get => SourceAppointment.CF_ResourceList();
|
|
set => SourceAppointment.CF_ResourceList(value);
|
|
}
|
|
public List<ResourceDC> ResourceList
|
|
{
|
|
get => EditedAppointmentCopy.CF_ResourceList();
|
|
set => EditedAppointmentCopy.CF_ResourceList(value);
|
|
}
|
|
|
|
private ObservableCollection<Employee2SchedulerAppointmentDC> SourceEmployeeList
|
|
{
|
|
get => SourceAppointment.CF_EmployeeList();
|
|
set => SourceAppointment.CF_EmployeeList(value);
|
|
}
|
|
public ObservableCollection<Employee2SchedulerAppointmentDC> EmployeeList
|
|
{
|
|
get => EditedAppointmentCopy.CF_EmployeeList();
|
|
set => EditedAppointmentCopy.CF_EmployeeList(value);
|
|
}
|
|
|
|
private List<CompactCustomerDC> SourceCustomerList
|
|
{
|
|
get => SourceAppointment.CF_CustomerList();
|
|
set => SourceAppointment.CF_CustomerList(value);
|
|
}
|
|
public List<CompactCustomerDC> CustomerList
|
|
{
|
|
get => EditedAppointmentCopy.CF_CustomerList();
|
|
set => EditedAppointmentCopy.CF_CustomerList(value);
|
|
}
|
|
|
|
private List<CompactSupportConceptDC> SourceSupportConceptList
|
|
{
|
|
get => SourceAppointment.CF_SupportConceptList();
|
|
set => SourceAppointment.CF_SupportConceptList(value);
|
|
}
|
|
public List<CompactSupportConceptDC> SupportConceptList
|
|
{
|
|
get => EditedAppointmentCopy.CF_SupportConceptList();
|
|
set => EditedAppointmentCopy.CF_SupportConceptList(value);
|
|
}
|
|
|
|
private CompactEmployeeDC SourceOriginator
|
|
{
|
|
get => SourceAppointment.CF_Originator();
|
|
set => SourceAppointment.CF_Originator(value);
|
|
}
|
|
public CompactEmployeeDC Originator
|
|
{
|
|
get => EditedAppointmentCopy.CF_Originator();
|
|
set => EditedAppointmentCopy.CF_Originator(value);
|
|
}
|
|
|
|
private bool SourceIsPrivate
|
|
{
|
|
get => SourceAppointment.CF_IsPrivate();
|
|
set => SourceAppointment.CF_IsPrivate(value);
|
|
}
|
|
public bool IsPrivate
|
|
{
|
|
get => EditedAppointmentCopy.CF_IsPrivate();
|
|
set => EditedAppointmentCopy.CF_IsPrivate(value);
|
|
}
|
|
|
|
private DateTime? SourceDueDate
|
|
{
|
|
get => SourceAppointment.CF_DueDate();
|
|
set => SourceAppointment.CF_DueDate(value);
|
|
}
|
|
public DateTime? DueDate
|
|
{
|
|
get => EditedAppointmentCopy.CF_DueDate();
|
|
set => EditedAppointmentCopy.CF_DueDate(value);
|
|
}
|
|
|
|
public DateTime? DisplayDueDateDate
|
|
{
|
|
get => DueDate?.Date;
|
|
set
|
|
{
|
|
if (value == null)
|
|
{
|
|
DueDate = null;
|
|
|
|
EditedAppointmentCopy.Start = DateTime.Now;
|
|
EditedAppointmentCopy.End = new DateTime(9999, 12, 31, 0, 0, 0);
|
|
|
|
NotifyPropertyChanged(nameof(DisplayDueDateTime));
|
|
|
|
return;
|
|
}
|
|
|
|
var newEnd = value.Value.Date.AddDays(1);
|
|
|
|
EditedAppointmentCopy.Start = CompletedDate.HasValue ? newEnd.AddDays(-1) : DateTime.Today;
|
|
EditedAppointmentCopy.End = newEnd;
|
|
|
|
if (DueDate == null)
|
|
{
|
|
DueDate = value;
|
|
|
|
NotifyPropertyChanged(nameof(DisplayDueDateTime));
|
|
return;
|
|
}
|
|
|
|
DueDate = value.Value.MergeDatesByDate(DueDate.Value);//new DateTime(value.Value.Year, value.Value.Month, value.Value.Day, DueDate.Value.Hour, DueDate.Value.Minute, DueDate.Value.Second));
|
|
NotifyPropertyChanged(nameof(DisplayDueDateTime));
|
|
}
|
|
}
|
|
|
|
private DateTime? _DueTime;
|
|
|
|
public DateTime? DisplayDueDateTime
|
|
{
|
|
get => _DueTime ?? EditedAppointmentCopy.CF_DueDate();
|
|
|
|
set
|
|
{
|
|
if(!Equals(value, _DueTime))
|
|
{
|
|
_DueTime = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private DateTime? SourceCompletedDate
|
|
{
|
|
get => SourceAppointment.CF_CompletedDate();
|
|
set => SourceAppointment.CF_CompletedDate(value);
|
|
|
|
}
|
|
|
|
public DateTime? CompletedDate
|
|
{
|
|
get => EditedAppointmentCopy.CF_CompletedDate();
|
|
set => EditedAppointmentCopy.CF_CompletedDate(value);
|
|
|
|
}
|
|
|
|
public DateTime? DisplayCompletedDateDate
|
|
{
|
|
get => CompletedDate?.Date;
|
|
set
|
|
{
|
|
if (CompletedDate == null)
|
|
{
|
|
CompletedDate = value;
|
|
return;
|
|
}
|
|
|
|
if (value != null)
|
|
{
|
|
CompletedDate = new DateTime(value.Value.Year, value.Value.Month, value.Value.Day, CompletedDate.Value.Hour, CompletedDate.Value.Minute, CompletedDate.Value.Second);
|
|
}
|
|
}
|
|
}
|
|
|
|
public TimeSpan? DisplayCompletedDateTime
|
|
{
|
|
get => CompletedDate?.TimeOfDay;
|
|
|
|
set
|
|
{
|
|
if (CompletedDate != null && value.HasValue)
|
|
{
|
|
CompletedDate = CompletedDate.Value.Date + value.Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool SourceIsTask
|
|
{
|
|
get => SourceAppointment.CF_IsTask();
|
|
set => SourceAppointment.CF_IsTask(value);
|
|
}
|
|
public bool IsTask
|
|
{
|
|
get => EditedAppointmentCopy.CF_IsTask();
|
|
set => EditedAppointmentCopy.CF_IsTask(value);
|
|
}
|
|
|
|
private string SourceTaskDescription
|
|
{
|
|
get => SourceAppointment.CF_TaskDescription();
|
|
set => SourceAppointment.CF_TaskDescription(value);
|
|
}
|
|
public string TaskDescription
|
|
{
|
|
get => EditedAppointmentCopy.CF_TaskDescription();
|
|
set => EditedAppointmentCopy.CF_TaskDescription(value);
|
|
}
|
|
|
|
public override bool IsAppointmentChanged()
|
|
{
|
|
if(base.IsAppointmentChanged())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (SourceResourceList != null && ResourceList != null ||
|
|
SourceEmployeeList != null && EmployeeList != null ||
|
|
SourceCustomerList != null && CustomerList != null ||
|
|
SourceOriginator != null && Originator != null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var resourceListsAreEqual = SourceResourceList == null || ResourceList == null || !Equals(SourceResourceList, ResourceList);
|
|
var employeeListsAreEqual = SourceEmployeeList == null || EmployeeList == null || !Equals(SourceEmployeeList, EmployeeList);
|
|
var customerListsAreEqual = SourceCustomerList == null || CustomerList == null || !Equals(SourceCustomerList, CustomerList);
|
|
var originatorsAreEqual = SourceOriginator == null || Originator == null || !Equals(SourceOriginator, Originator);
|
|
var isPrivatesAreEqual = !Equals(SourceIsPrivate, IsPrivate);
|
|
var dueDatesAreEqal = Equals(SourceDueDate, DueDate);
|
|
var completedDatesAreEqal = Equals(SourceCompletedDate, CompletedDate);
|
|
var taskDescriptionsAreEqual = Equals(SourceTaskDescription, TaskDescription);
|
|
var supportConceptListsAreEqual = SourceSupportConceptList == null || SupportConceptList == null || !Equals(SourceSupportConceptList, SupportConceptList);
|
|
|
|
return resourceListsAreEqual || employeeListsAreEqual || customerListsAreEqual || originatorsAreEqual || isPrivatesAreEqual || dueDatesAreEqal || completedDatesAreEqal || taskDescriptionsAreEqual || supportConceptListsAreEqual;
|
|
}
|
|
|
|
public NewSchedulerAppointmentFormController(SchedulerControl control, Appointment apt) : base(control, apt) { }
|
|
|
|
protected override void ApplyCustomFieldsValues()
|
|
{
|
|
SourceResourceList = ResourceList;
|
|
SourceEmployeeList = EmployeeList;
|
|
SourceCustomerList = CustomerList;
|
|
SourceOriginator = Originator;
|
|
SourceIsPrivate = IsPrivate;
|
|
SourceDueDate = DueDate;
|
|
|
|
if(_DueTime.HasValue)
|
|
{
|
|
SourceDueDate = SourceDueDate?.MergeDatesByDate(_DueTime.Value);
|
|
}
|
|
|
|
SourceCompletedDate = CompletedDate;
|
|
SourceTaskDescription = TaskDescription;
|
|
SourceSupportConceptList = SupportConceptList;
|
|
}
|
|
}
|
|
|
|
public class RemoveElementVisibilityConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if(value == null)
|
|
{
|
|
return Visibility.Visible;
|
|
}
|
|
|
|
var isNew = SchedulerAppointmentEditForm.IsNew;
|
|
|
|
var isAllowedToChange = BeWoUtils.CheckSchedulerRights(SchedulerAppointmentEditForm.CurrentAppointment, isNew, SchedulerRightsCheckType.Edit);
|
|
|
|
|
|
return isAllowedToChange ? Visibility.Visible : Visibility.Hidden;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|