using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Threading; using BeWo.Core; using BeWo.ServiceProxy; using BeWo.View.Controls; using BeWo.View.Detail; using BeWo.ViewModel; using Blacklight.Wpf.Controls; using BS.Shared; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; using BS.Shared.Extensions; using BS.Shared.RSS; using System.Text.RegularExpressions; using BeWo.Annotations; using BeWo.ownChat; using BeWo.Scheduler.Utils; using BeWo.Scheduler.View; using BeWo.View.Master; using ChatController.HauptKlassen; using DevExpress.XtraScheduler; using DevExpress.XtraScheduler.Xml; using Brushes = System.Windows.Media.Brushes; using Button = System.Windows.Controls.Button; using Color = System.Windows.Media.Color; using Control = System.Windows.Controls.Control; using Image = System.Windows.Controls.Image; using ListBox = System.Windows.Controls.ListBox; using MessageBox = System.Windows.MessageBox; using ScrollBar = System.Windows.Controls.Primitives.ScrollBar; namespace BeWo.View { /// /// Interaction logic for HomeView.xaml /// public partial class HomeDragPanelView : BeWoView, INotifyPropertyChanged { private List _AllTasks; private List _AllSchedulerTasks; private bool _IsAllowedToSeeMitarbeitertermine; private bool _IsAllowedToSeeCustomerAppointments; private bool _IsAllowedToSeeResourceAppointments; //chat berechtigung protected bool berechtigt; private Dictionary newsItemExpandedState = new Dictionary(); public HomeDragPanelView() { InitializeComponent(); DataContext = this; txtHeader.Text = String.Format("{0} {1}", BeWoApp.LoggedOnUser.Employee.FirstName,BeWoApp.LoggedOnUser.Employee.LastName); txtVersion.Text = BeWoApp.Version; txtLoginTime.Text = string.Empty; txtLastLoginTime.Text = string.Empty; PasswortSchloss.Text = string.Join("", (from Match m in Regex.Matches("D83DDD12", @"\S{4}") select (char)int.Parse(m.Value, NumberStyles.HexNumber)).ToArray()); //PreparePanels(); InitPanels(null); HyperlinkZuPasswortsicherheit.NavigateUri = new Uri("http://news.bewoplaner.de/?NewsType=3&NewsCount=1&NewsOID=373457455"); #if DEBUG //txtChangePassword.Visibility = Visibility.Visible; #else if (BeWoApp.Tenant == "demo" || !BeWoApp.LoggedOnUser.HasRight(UserRightType.AllowChangeOwnPassword)) { txtChangePassword.Visibility = Visibility.Collapsed; } #endif // FillInbox(); // FillOutbox(); Loaded += HomeDragPanelViewLoaded; /*this.Dispatcher.BeginInvoke( DispatcherPriority.Normal, (Action)delegate { ConnectWithServer(); if(clientSocket.Connected) MessageBox.Show("Verbindung geglückt.", "Info", MessageBoxButton.OK,MessageBoxImage.Information); });*/ if (BeWoApp.AppSettings.IsChatAllowed) { var berechtigung = ServiceFacade.DoEmployeeServiceSync(s => s.GetAllChatActiveEmployeesCompact()); if (berechtigung != null) { foreach (var list in berechtigung) { if (list.PersonOid == BeWoApp.LoggedOnUser.Employee.PersonOid) { berechtigt = true; } } } } #if DEBUG berechtigt = true; #endif BewoChat.Visibility = berechtigt ? Visibility.Visible : Visibility.Hidden; PruefePasswortStaerke(); } private bool _IsShowingAppointments; private bool _HasRightsToSeeAppointments; private List _EmployeesForAppointmentView; public List EmployeesForAppointmentView { get => _EmployeesForAppointmentView ?? (_EmployeesForAppointmentView = new List()); set { _EmployeesForAppointmentView = value; OnPropertyChanged(nameof(EmployeesForAppointmentView)); } } private void PruefePasswortStaerke() { if ( BeWoApp.PasswortStrength == PasswortSecurityStrength.SehrSchwach) { PasswortSchloss.Foreground = new SolidColorBrush(Colors.Red); this.Dispatcher.BeginInvoke( DispatcherPriority.Normal, (Action)delegate { if (BeWoApp.AppSettings.IsPasswordSecurityActiv) { MessageBox.Show("Sie benutzen ein sehr schwaches Passwort.\nBitte ändern Sie Ihr Passwort, indem Sie im Startbildschirm oben auf \"Passwort ändern\" klicken.", "Achtung!", MessageBoxButton.OK,MessageBoxImage.Information); } }); }else if (BeWoApp.PasswortStrength == PasswortSecurityStrength.Schwach) { PasswortSchloss.Foreground = new SolidColorBrush(Colors.OrangeRed); this.Dispatcher.BeginInvoke( DispatcherPriority.Normal, (Action)delegate { if (BeWoApp.AppSettings.IsPasswordSecurityActiv) { MessageBox.Show("Sie benutzen ein schwaches Passwort.\nBitte ändern Sie Ihr Passwort, indem Sie im Startbildschirm oben auf \"Passwort ändern\" klicken.", "Achtung!", MessageBoxButton.OK, MessageBoxImage.Information); } }); } else if (BeWoApp.PasswortStrength == PasswortSecurityStrength.Mittelmass) { PasswortSchloss.Foreground = new SolidColorBrush(Colors.Yellow); } else if (BeWoApp.PasswortStrength == PasswortSecurityStrength.Stark) { PasswortSchloss.Foreground = new SolidColorBrush(Colors.Green); } else if (BeWoApp.PasswortStrength == PasswortSecurityStrength.SehrStark) { PasswortSchloss.Foreground = new SolidColorBrush(Colors.Green); } } private void PreparePanels() { ServiceFacade.DoOperationsServiceAsyncNoWait( s => s.GetUiElements(UiElementType.StartPanel, BeWoApp.LoggedOnUser.Employee.EmployeeOid, null, null), InitPanelsCallback, null); } private void InitPanelsCallback(IList elements, object state) { this.Dispatcher.BeginInvoke( DispatcherPriority.Normal, (Action) delegate { InitPanels(elements); }); } private void InitPanels(IList elements) { listboxExpiringSupportConcepts.Items.Clear(); listboxConferenceDates.Items.Clear(); listboxBirthdays.Items.Clear(); listboxNews.Items.Clear(); listboxTasks.Items.Clear(); //ListboxInternalNews.Items.Clear(); InternalNewsGrid.Children.Clear(); //if (elements == null || elements.Count == 0) //{ // // //} //else //{ // foreach (var uiElementDc in elements) // { // var xamlElement = System.Windows.Markup.XamlReader.Parse(uiElementDc.Xaml); // if (xamlElement is DragDockPanel) // { // panelHost.Children.Add(xamlElement as UIElement); // } // } //} ReorderPanels(); } private void HomeDragPanelViewLoaded(object o, RoutedEventArgs e) { InitContent(); //Warum klappt das bei Köln Ring nicht?= if (BeWoApp.LoggedOnUser == null || BeWoApp.LoggedOnUser.ResetPasswordInfos == null) { return; } if (!BeWoApp.LoggedOnUser.ResetPasswordInfos.Any(a => a.HasToChangePW)) { return; } var fenster = new PasswortAenderungsView {AbbrechenButton = {IsEnabled = false}}; fenster.CommandBindings.Clear(); fenster.ShowDialog(); } public void SaveState() { var order = new List(); DragDockPanel panelWithMaxHeight = null; double maxHeight = 0; double normalHeight = 0; var result = new List(); foreach (object item in panelHost.Children) { var p = item as DragDockPanel; if (order.Count == 0) { order.Add(p); } else { int newIndex = -1; int index = 0; Vector rect = VisualTreeHelper.GetOffset(p); foreach (DragDockPanel item2 in order) { string name1 = p.Name; string name2 = item2.Name; Vector rect2 = VisualTreeHelper.GetOffset(item2); if (rect.Y < rect2.Y) { newIndex = index; continue; } if (Equals(rect.Y, rect2.Y) && rect.X < rect2.X) { newIndex = index; continue; } index++; } if (newIndex < 0) { order.Add(p); } else { order.Insert(newIndex, p); } } if (p.Height > maxHeight) { maxHeight = p.ActualHeight; panelWithMaxHeight = p; } else { normalHeight = p.ActualHeight; } } if ((maxHeight - normalHeight) > 1 && panelWithMaxHeight != null) { BeWoApp.AppSettings.StartupPanelMaximized = panelWithMaxHeight.Name; } else { BeWoApp.AppSettings.StartupPanelMaximized = null; } List panelOrder = order.Select(item => item.Name).ToList(); BeWoApp.AppSettings.StartupPanelOrder = panelOrder; } private void ButtonOpenServiceRecordView_Click(object sender, RoutedEventArgs e) { var btn = sender as Button; if (btn != null) { var dc = btn.Tag as CompactSupportConceptDC; if (dc != null) BeWoApp.MainControl.NavigateToServiceRecordView(dc.SupportConceptOid); } } private void InitBewoNews() { try { if (BeWoApp.Tenant != "demo") { LoadFeed(); //LoadFeed("http://www.heise.de/foto/rss/news-atom.xml"); } } catch (Exception) { } } private void InitBirthdays() { DateTime endOfWeek = DateTime.Now.GetNext(DayOfWeek.Sunday).Date; endOfWeek = endOfWeek.AddDays(1).GetNext(DayOfWeek.Sunday).Date; ServiceFacade.DoAnalysisServiceAsync(s1 => s1.GetPersonsHavingBirthday(endOfWeek), ReloadBirthdays); } private void InitContent() { SetMaximizedPanel(); InitLoginInfo(); InitExpiredSupportConcepts(); InitNextConferenceDates(); InitBewoNews(); InitBirthdays(); rb_open.IsChecked = true; UpdateInternalNews(); InitTasks(); } private void InitExpiredSupportConcepts() { // DateTime endOfWeek = DateTime.Now.GetNext(DayOfWeek.Sunday).Date; // DateTime endOfWeek2 = endOfWeek.AddDays(8); DateTime dt = DateTime.Now.AddMonths(BeWoApp.AppSettings.HilfeplanAuslaufAuswahl); ServiceFacade.DoAnalysisServiceAsync( s1 => s1.GetExpiringSupportConcepts(BeWoApp.LoggedOnUser.Employee.EmployeeOid, dt), ReloadExpiringSupportConcepts); } private void UpdateInternalNews() { if (InternalNewsGrid != null) { newsItemExpandedState.Clear(); foreach (var child in InternalNewsGrid.Children) { var rootsp = child as StackPanel; if (rootsp != null && rootsp.Children.Count > 0) { foreach (var child2 in rootsp.Children) { var ex = child2 as Expander; if (ex != null) { var grid = ex.Header as Grid; String text = ""; if (grid != null) { foreach (var gridChild in grid.Children) { if (gridChild is TextBlock) { var tb = gridChild as TextBlock; text = tb.Text; } } } if (!newsItemExpandedState.ContainsKey(text)) { newsItemExpandedState.Add(text, ex.IsExpanded); } } } } } } var showTeamNews = BeWoApp.AppSettings.ShowTeamNews; //ServiceFacade.DoEmployeeServiceAsync(s => s.GetPublishedNewsItems(), cb => this.Dispatch(delegate { listboxInternalNews.ItemsSource = cb.OrderByDescending(i => i.PublishDate).ToList(); })); ServiceFacade.DoEmployeeServiceAsync( s => s.GetPublishedNewsItemsForEmployee(BeWoApp.LoggedOnUser.Employee.EmployeeOid, showTeamNews), RefreshInternalNews); } private void RefreshInternalNews(List news) { this.Dispatch(delegate { var team2News = new Dictionary(); var allNews = new TeamNewsItemVM(); allNews.Team = new CompactTeamDC(); allNews.Team.Name = "Allgemein"; allNews.AllowEdit = false; allNews.IsTitleVisible = true; foreach (var newsItemDc in news) { if (newsItemDc.Team != null) { newsItemDc.AllowEdit = true; newsItemDc.TitleString = String.Format("{0:dd.MM.yyyy}: {1}", newsItemDc.PublishDate, newsItemDc.Title); if (!team2News.ContainsKey(newsItemDc.Team.TeamOid)) { team2News[newsItemDc.Team.TeamOid] = new TeamNewsItemVM(); team2News[newsItemDc.Team.TeamOid].Team = newsItemDc.Team; team2News[newsItemDc.Team.TeamOid].AllowEdit = true; team2News[newsItemDc.Team.TeamOid].IsTitleVisible = true; } if (newsItemDc.NewsItemOid.HasValue) { team2News[newsItemDc.Team.TeamOid].NewsItems.Add(newsItemDc); } } else { newsItemDc.TitleString = newsItemDc.Title; allNews.NewsItems.Add(newsItemDc); } } var list = team2News.Values.OrderBy(i => i.Team.Name).ToList(); if (list.Count == 0) allNews.IsTitleVisible = false; list.Add(allNews); InternalNewsGrid.Children.Clear(); InternalNewsGrid.Children.Add(CreateInternalNewsControlList(list)); //ListboxInternalNews.ItemsSource = list; }); } private UIElement CreateInternalNewsControlList(List list) { bool expand = true; if (newsItemExpandedState.Count == 0) { if (list != null && list.Count > 1) { int count = 0; foreach (var teamNewsItemVm in list) { if (teamNewsItemVm.NewsItems != null) { count += teamNewsItemVm.NewsItems.Count; } } if (count > 10) { expand = false; } } } StackPanel sp = new StackPanel(); foreach (var teamNewsItemVm in list) { sp.Children.Add(CreateInternalNewsTeamControl(teamNewsItemVm, expand)); } return sp; } private UIElement CreateInternalNewsTeamControl(TeamNewsItemVM teamNewsItemVm, bool initExpand) { var sp = new StackPanel(); foreach (var newsItem in teamNewsItemVm.NewsItems) { sp.Children.Add(CreateInternalNewsControl(newsItem)); } if (teamNewsItemVm.IsTitleVisible) { Expander ex = new Expander(); ex.Style = (Style)FindResource("FlatLineExpander"); bool expanded = initExpand; if (newsItemExpandedState.ContainsKey(teamNewsItemVm.Team.Name)) { expanded = newsItemExpandedState[teamNewsItemVm.Team.Name]; } ex.IsExpanded = expanded; ex.Margin = new Thickness(0, 5, 5, 5); Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); TextBlock tb = new TextBlock(); tb.FontSize = 14; tb.FontWeight = FontWeights.Bold; tb.Text = teamNewsItemVm.Team.Name; grid.Children.Add(tb); if (teamNewsItemVm.AllowEdit) { Button newBtn = new Button(); newBtn.Style = (Style)FindResource("FlatButton"); newBtn.SetValue(Grid.ColumnProperty, 1); newBtn.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; newBtn.Width = 16; newBtn.Height = 16; newBtn.Click += BtnCreateNewsItem_OnClick; newBtn.Tag = teamNewsItemVm; newBtn.Margin = new Thickness(0, 0, -10, 0); Image img = new Image(); img.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\new.png", UriKind.Relative)); img.Stretch = Stretch.Uniform; newBtn.Content = img; grid.Children.Add(newBtn); } ex.Header = grid; ex.Content = sp; return ex; } return sp; // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // } private UIElement CreateInternalNewsControl(NewsItemDC newsItem) { Grid grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)}); grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Auto)}); grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Auto)}); grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(25, GridUnitType.Pixel)}); grid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(1, GridUnitType.Star)}); grid.Margin = new Thickness(0, 5, 0, 0); TextBlock tb = new TextBlock(); tb.Margin = new Thickness(0, 5, 0, 0); tb.Foreground = new SolidColorBrush(Color.FromRgb(43, 80, 139)); tb.Text = newsItem.TitleString; tb.FontSize = 12; tb.FontWeight = FontWeights.Bold; grid.Children.Add(tb); tb = new TextBlock(); tb.Text = newsItem.Text; tb.FontSize = 10; tb.TextWrapping = TextWrapping.Wrap; tb.SetValue(Grid.RowProperty, 1); tb.SetValue(Grid.ColumnSpanProperty, 3); grid.Children.Add(tb); if (newsItem.AllowEdit) { // // // // // // Border b = new Border(); b.Background = Brushes.Transparent; b.SetValue(Grid.ColumnProperty, 1); grid.Children.Add(b); // // Button editBtn = new Button(); editBtn.BorderThickness = new Thickness(1, 1, 1, 1); editBtn.Padding = new Thickness(1, 1, 1, 1); editBtn.Style = (Style) FindResource("FlatButton"); editBtn.SetValue(Grid.ColumnProperty, 1); editBtn.VerticalAlignment = VerticalAlignment.Top; editBtn.Width = 16; editBtn.Height = 16; editBtn.Click += BtnEditNewsItem_OnClick; editBtn.Tag = newsItem; editBtn.Visibility = Visibility.Hidden; Image img = new Image(); img.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\edit.png", UriKind.Relative)); img.Stretch = Stretch.Uniform; img.Margin = new Thickness(1, 1, 1, 1); editBtn.Content = img; grid.Children.Add(editBtn); b = new Border(); b.Background = Brushes.Transparent; b.SetValue(Grid.ColumnProperty, 2); grid.Children.Add(b); Button deleteBtn = new Button(); deleteBtn.Padding = new Thickness(1, 1, 1, 1); deleteBtn.Style = (Style) FindResource("FlatButton"); deleteBtn.SetValue(Grid.ColumnProperty, 2); deleteBtn.VerticalAlignment = VerticalAlignment.Top; deleteBtn.Width = 16; deleteBtn.Height = 16; deleteBtn.Click += BtnDeleteNewsItem_OnClick; deleteBtn.Tag = newsItem; deleteBtn.Visibility = Visibility.Hidden; img = new Image(); img.Source = new BitmapImage(new Uri(@"..\..\Ressources\Icons\delete.png", UriKind.Relative)); img.Stretch = Stretch.Uniform; img.Margin = new Thickness(1, 1, 1, 1); deleteBtn.Content = img; grid.Children.Add(deleteBtn); grid.MouseEnter += (s, e) => { editBtn.Visibility = Visibility.Visible; deleteBtn.Visibility = Visibility.Visible; }; grid.MouseLeave += (s, e) => { editBtn.Visibility = Visibility.Hidden; deleteBtn.Visibility = Visibility.Hidden; }; } // // // // // // return grid; } private void InitLoginInfo() { DateTime endOfWeek = DateTime.Now.GetNext(DayOfWeek.Sunday).Date; ServiceFacade.DoAnalysisServiceAsync(s1 => s1.GetLastLogins(BeWoApp.LoggedOnUser.LoginName), ReloadLogins); } private void InitNextConferenceDates() { DateTime endOfWeek = DateTime.Now.GetNext(DayOfWeek.Sunday).Date; DateTime endOfWeek2 = endOfWeek.AddDays(8); ServiceFacade.DoAnalysisServiceAsync( s1 => s1.GetSupportConceptsWithConferenceDate(BeWoApp.LoggedOnUser.Employee.EmployeeOid, endOfWeek2), ReloadConferenceDates); } public NewSchedulerView Scheduler; private void InitTasks() { var test = 0; while (BeWoApp.LoggedOnEmployee == null && test < 50) { Thread.Sleep(100); test++; } if (BeWoApp.LoggedOnEmployee != null) { var rights = new List { UserRightType.KalenderAnsehen }; _HasRightsToSeeAppointments = BeWoUtils.HasRight(UserRightType.KalenderAnsehen) || BeWoUtils.HasRight(UserRightType.ViewAll); var r2 = rights; r2.Add(UserRightType.KalenderMitarbeitertermineAnsehen); var r3 = rights; r3.Add(UserRightType.KalenderKliententermineAlleAnsehen); var r5 = rights; r5.Add(UserRightType.KalenderRessourcentermineAnsehen); _IsAllowedToSeeMitarbeitertermine = r2.All(BeWoUtils.HasRight) || BeWoUtils.HasRight(UserRightType.ViewAll); _IsAllowedToSeeCustomerAppointments = r3.All(BeWoUtils.HasRight) || BeWoUtils.HasRight(UserRightType.ViewAll); _IsAllowedToSeeResourceAppointments = r5.All(BeWoUtils.HasRight) || BeWoUtils.HasRight(UserRightType.ViewAll); if (_HasRightsToSeeAppointments && _IsAllowedToSeeMitarbeitertermine) { #if DEBUG TestTermineAnlegenButton.Visibility = Visibility.Visible; TestTermineLoeschenButton.Visibility = Visibility.Visible; #endif employeeFilterBox.Visibility = Visibility.Visible; ServiceFacade.DoEmployeeServiceAsync(s => s.GetAllActiveEmployeesCompact(), cb => { this.Dispatch(delegate { EmployeesForAppointmentView = cb.OrderBy(o => o.LastName + ", " + o.FirstName).ToList(); employeeFilterBox.SelectedItem = BeWoApp.CompactLoggedOnEmployee; }); }); } else { EmployeesForAppointmentView = new List { BeWoApp.CompactLoggedOnEmployee }; employeeFilterBox.SelectedItem = BeWoApp.CompactLoggedOnEmployee; } ShowAppointments(false); LoadTasksAndAppointments(true, true); } } private void BuildRecurringAppointments(List pRecurringAppointments, DateTime pStartDate, DateTime pEndDate) { var patternToExceptions = new List(); var recurrenceInterval = new TimeInterval(pStartDate, pEndDate - pStartDate); var scheduler = new SchedulerControl(); foreach(var appointment in pRecurringAppointments.OrderBy(o => o.Type)) { if(appointment.Type == (int) AppointmentType.Pattern) { var id = Utils.ExtractIdFromRecurrenceInfo(appointment.RecurrenceInfo); patternToExceptions.Add(new RecurringAppointment(id, pRecurringAppointments.Where(w => w.RecurrenceInfo.Contains(id) && w.Type != (int) AppointmentType.Pattern).ToDictionary(x => Utils.ExtractIndexFromRecurrenceInfo(x.RecurrenceInfo), y => y), appointment)); } } foreach (var appointment in patternToExceptions) { var patternAppointment = appointment.Pattern; var recurrenceInfo = RecurrenceInfoXmlPersistenceHelper.ObjectFromXml(patternAppointment.RecurrenceInfo); var instance = OccurrenceCalculator.CreateInstance(recurrenceInfo); scheduler.Storage = new SchedulerStorage(); var pattern = scheduler.Storage.CreateAppointment(AppointmentType.Pattern, appointment.Pattern.StartDate.Value, appointment.Pattern.EndDate.Value); var occurrences = instance.CalcOccurrences(recurrenceInterval, pattern); foreach(var devExpressAppointment in occurrences) { var index = devExpressAppointment.RecurrenceIndex; if(index == 0 && appointment.Occurrences.ContainsKey(0)) { _AllSchedulerTasks.Remove(appointment.Pattern); } var indizes = appointment.Occurrences.Keys.ToList(); if (indizes.Contains(index) || devExpressAppointment.Type == AppointmentType.Occurrence && devExpressAppointment.RecurrenceIndex == 0) { continue; } var occurrence = new SchedulerAppointmentDC { CustomerList = patternAppointment.CustomerList, AllDay = patternAppointment.AllDay, EndDate = devExpressAppointment.End, RecurrenceInfo = devExpressAppointment.RecurrenceInfo.ToXml(), StartDate = devExpressAppointment.Start, Type = (int) AppointmentType.Occurrence, CompletedDate = patternAppointment.CompletedDate, Description = patternAppointment.Description, DueDate = patternAppointment.DueDate, EmployeeList = patternAppointment.EmployeeList, CompletedNotice = patternAppointment.CompletedNotice, FormerBookingSequenceOid = patternAppointment.FormerBookingSequenceOid, FormerTaskOid = patternAppointment.FormerTaskOid, IsPrivate = patternAppointment.IsPrivate, IsTeilnahmeBestaetigung = patternAppointment.IsTeilnahmeBestaetigung, SupportConceptList = patternAppointment.SupportConceptList, TaskDescription = patternAppointment.TaskDescription, IsTask = patternAppointment.IsTask, ResourceList = patternAppointment.ResourceList, Originator = patternAppointment.Originator, Subject = patternAppointment.Subject, Location = patternAppointment.Location, Status = patternAppointment.Status, LabelId = patternAppointment.LabelId, RecurrenceIndex = devExpressAppointment.RecurrenceIndex, RecurrenceId = appointment.RecurrenceId }; _AllSchedulerTasks.Add(occurrence); } } } private static bool IsPartOf(object p, Type type) { if (p != null) { var fe = p as FrameworkElement; if (fe != null) { if (fe.GetType() == type) return true; return IsPartOf(fe.TemplatedParent, type); } } return false; } private void LoadFeed() { String url = BeWoApp.Mandator.RssFeedUrl; if (String.IsNullOrEmpty(url)) { ServiceFacade.DoDownloadServiceAsync( dwn => { try { return dwn.ReadRssFeed(null); } catch (Exception) { } return null; }, ReloadRssFeed); } else { RssFeed feed = new RssFeed(); RssManager mgr = new RssManager(url); feed.Items = mgr.GetFeed(); feed.Title = mgr.FeedTitle; feed.Description = mgr.FeedDescription; ReloadRssFeed(feed, false); } } private void RadioButton_Checked(object sender, RoutedEventArgs e) { if (_AllSchedulerTasks != null) { var controlName = ((Control) e.OriginalSource).Name; switch (controlName) { case "rb_all": _IsShowingAppointments = false; listboxTasks.ItemsSource = _AllSchedulerTasks.Where(w => w.IsTask).OrderBy(i => i.CompletedDate ?? i.DueDate).ToList(); ShowAppointments(false); break; case "rb_open": _IsShowingAppointments = false; listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => !i.CompletedDate.HasValue && i.IsTask).OrderBy(i => i.DueDate).ToList(); ShowAppointments(false); break; case "rb_closed": _IsShowingAppointments = false; listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => i.CompletedDate.HasValue && i.IsTask).OrderByDescending(i => i.CompletedDate).ToList(); ShowAppointments(false); break; case "rb_appointments": _IsShowingAppointments = true; listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => !i.IsTask).OrderByDescending(i => i.EndDate).ToList(); ShowAppointments(true); break; } } } private const int _DateBuffer = 14; private DateTime _BufferDate = DateTime.Today.AddDays(-1 * _DateBuffer); private DateTime _CurrentDate = DateTime.Today; public DateTime CurrentDate { get => _CurrentDate; set { if(!Equals(_CurrentDate, value)) { _CurrentDate = value; UpdateAppointmentDateTextBlock(value); OnPropertyChanged(nameof(CurrentDate)); } } } private void ShowAppointments(bool pShouldShowAppointments) { TimeIntervalNavigationStackPanel.Visibility = pShouldShowAppointments ? Visibility.Visible : Visibility.Collapsed; TimeIntervalBackButton.Visibility = pShouldShowAppointments ? Visibility.Visible : Visibility.Collapsed; AppointmentDateTextBlock.Visibility = pShouldShowAppointments ? Visibility.Visible : Visibility.Collapsed; TimeIntervalForwardsButton.Visibility = pShouldShowAppointments ? Visibility.Visible : Visibility.Collapsed; if(pShouldShowAppointments) { CurrentDate = DateTime.Today; UpdateAppointmentDateTextBlock(null); } } public void TimeIntervalBackButtonOnClick(object sender, EventArgs args) { CurrentDate = CurrentDate.AddDays(-1); UpdateAppointmentDateTextBlock(_CurrentDate); } public void TimeIntervalForwardsButtonOnClick(object sender, EventArgs args) { CurrentDate = CurrentDate.AddDays(1); UpdateAppointmentDateTextBlock(_CurrentDate); } private void UpdateAppointmentDateTextBlock(DateTime? pDate) { var date = pDate ?? DateTime.Today; var weekOfYear = date.GetIso8601WeekOfYear().ToString(); var dayOfWeek = date.ToString("dddd"); AppointmentDateTextBlock.Text = $"KW {weekOfYear}, {dayOfWeek} "; LoadTasksAndAppointments(false); } private void LoadTasksAndAppointments(bool pIsShowingTasks, bool pForceUpdate = false) { if(_CurrentDate < _BufferDate || _CurrentDate > _BufferDate.AddDays(3 * _DateBuffer) || pForceUpdate) { _BufferDate = _CurrentDate.AddDays(-1 * _DateBuffer); ServiceFacade.DoResourceServiceAsync(s => s.LoadTasksAndAppointmentsForEmployee(BeWoApp.LoggedOnEmployeeOid.Value, _CurrentDate, _DateBuffer, _SelectedEmployeeForAppointments?.EmployeeOid), cb => { this.Dispatch(delegate { _AllSchedulerTasks = cb; BuildRecurringAppointments(_AllSchedulerTasks.Where(w => w.RecurrenceInfo != null).ToList(), _CurrentDate, _CurrentDate.AddDays(3 * _DateBuffer)); if (pIsShowingTasks) { listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => i.IsTask && !i.CompletedDate.HasValue).OrderBy(i => i.DueDate).OrderBy(o => o.StartDate ?? DateTime.MinValue).ToList(); } else { listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => !i.IsTask && i.StartDate.HasValue && i.StartDate.Value.InBetween(_CurrentDate, _CurrentDate.AddDays(14), true) && i.EndDate.HasValue && i.EndDate.Value.InBetween(_CurrentDate, _CurrentDate.AddDays(14), true) && i.Type != (int) AppointmentType.DeletedOccurrence).OrderBy(o => o.StartDate ?? DateTime.MinValue).ToList(); } }); }); } else { if (pIsShowingTasks) { listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => i.IsTask && !i.CompletedDate.HasValue).OrderBy(i => i.DueDate).OrderBy(o => o.StartDate ?? DateTime.MinValue).ToList(); } else { listboxTasks.ItemsSource = _AllSchedulerTasks.Where(i => !i.IsTask && i.StartDate.HasValue && i.StartDate.Value.InBetween(_CurrentDate, _CurrentDate.AddDays(14), true) && i.EndDate.HasValue && i.EndDate.Value.InBetween(_CurrentDate, _CurrentDate.AddDays(14), true) && i.Type != (int) AppointmentType.DeletedOccurrence).OrderBy(o => o.StartDate ?? DateTime.MinValue).ToList(); foreach (var app in listboxTasks.ItemsSource) { var a = (SchedulerAppointmentDC)app; if (a.IsTask || a.RecurrenceInfo == null) { continue; } } } } } private void ReloadRssFeed(RssFeed feed) { ReloadRssFeed(feed, true); } private void ReloadRssFeed(RssFeed feed, bool addBeWoParameter) { if (feed != null) { if (feed.Items != null && addBeWoParameter) { foreach (RssItem rssItem in feed.Items) { if (!String.IsNullOrEmpty(rssItem.Link)) { rssItem.Link += String.Format("&k={0}&s={1}", BeWoApp.Tenant, BeWoApp.ServerName); } } } this.Dispatch(delegate { listboxNews.ItemsSource = feed.Items; }); } } private void ReloadBirthdays(List list) { this.Dispatch( delegate { list.Sort((l1, l2) => l1.DateOfBirth.Value.DayOfYear.CompareTo(l2.DateOfBirth.Value.DayOfYear)); listboxBirthdays.ItemsSource = list; }); } private void ReloadConferenceDates(List list) { this.Dispatch( delegate { list.Sort((l1, l2) => l1.ConferenceDate.Value.CompareTo(l2.ConferenceDate.Value)); listboxConferenceDates.ItemsSource = list; }); } private void ReloadExpiringSupportConcepts(List list) { this.Dispatch( delegate { list.Sort((l1, l2) => l1.EndDate.Value.CompareTo(l2.EndDate.Value)); listboxExpiringSupportConcepts.ItemsSource = list; }); } private void ReloadLogins(List list) { this.Dispatch( delegate { // listboxNews.ItemsSource = list; list.Sort((l1, l2) => l1.LoginDate.Value.CompareTo(l2.LoginDate.Value)); if (list.Count > 0) { LoginDC last = list[list.Count - 1]; txtLoginTime.Text = "Angemeldet seit " + last.LoginDate.Value.ToShortDateString() + " " + last.LoginDate.Value.ToShortTimeString(); if (list.Count > 1) { LoginDC dc = list[list.Count - 2]; txtLastLoginTime.Text = ", zuletzt angemeldet am " + dc.LoginDate.Value.ToShortDateString() + " " + dc.LoginDate.Value.ToShortTimeString(); } } }); } public void ReorderPanels() { List order = BeWoApp.AppSettings.StartupPanelOrder; if (order != null && order.Count > 0) { var panels = new Dictionary(); foreach (object item in panelHost.Children) { var p = item as DragDockPanel; panels.Add(p.Name, p); } panelHost.Children.Clear(); foreach (string item in order) { if (panels.ContainsKey(item)) { DragDockPanel p = panels[item]; panelHost.AddPanel(p); // Children.Add(p); panels.Remove(item); } } foreach (DragDockPanel item in panels.Values) { panelHost.AddPanel(item); } } } private void SetMaximizedPanel() { if (!String.IsNullOrEmpty(BeWoApp.AppSettings.StartupPanelMaximized)) { foreach (object item in panelHost.Children) { var p = item as DragDockPanel; if (BeWoApp.AppSettings.StartupPanelMaximized.Equals(p.Name)) { IEnumerable objekts = p.GetAllChildren(); foreach (DependencyObject child in objekts) { if (child is ToggleButton) { var btn = child as ToggleButton; btn.IsChecked = true; } } } } } } private void listboxBirthdays_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //if (!IsPartOf(e.OriginalSource, typeof (ScrollBar))) //{ // var dc = ((ListBox) sender).SelectedItem as CompactPersonDC; // if (dc != null) // { // if (dc.PersonType == PersonType.Customer) // { // if (BeWoApp.LoggedOnUser.HasRight(UserRightType.CustomerView_View) || // BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) // { // ServiceFacade.DoCustomerServiceAsync( // s => s.GetCustomerWithPersonOid(dc.PersonOid), // cb => VMFactory.CreateCustomerVMAsync( // cb, // cb2 => this.Dispatch( // delegate // { // MainControl.NavigateTo( // new CustomerView(cb2) // { // ParentView = this // }); // }))); // } // } // else if (dc.PersonType == PersonType.Employee) // { // if (BeWoApp.LoggedOnUser.HasRight(UserRightType.EmployeeView_View) || // BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) // { // ServiceFacade.DoEmployeeServiceAsync( // s => s.GetEmployeeWithPersonOid(dc.PersonOid), // cb => VMFactory.CreateEmployeeVMAsync( // cb, // cb2 => this.Dispatch( // delegate // { // MainControl.NavigateTo( // new EmployeeView(cb2) // { // ParentView = this // }); // }))); // } // } // else if (BeWoApp.LoggedOnUser.HasRight(UserRightType.PersonView_View) || // BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) // { // VMFactory.CreatePersonVMAsync( // dc.PersonOid, // cb => this.Dispatch( // delegate // { // MainControl.NavigateTo( // new PersonView(cb) // { // ParentView = this // }); // })); // } // } //} } private void listboxSupportConcepts_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (!IsPartOf(e.OriginalSource, typeof (ScrollBar))) { var sc = ((ListBox) sender).SelectedItem as CompactSupportConceptDC; if (sc != null && (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) || BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConceptView_View))) { VMFactory.CreateSupportConceptVMAsync( sc.SupportConceptOid, cb => this.Dispatch( delegate { MainControl.NavigateTo(new SupportConceptView(cb) {ParentView = this}); //new SupportConceptView2(cb) // { // ParentView = this // }); })); } } } private void listboxTasks_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (!IsPartOf(e.OriginalSource, typeof (ScrollBar))) { if (((ListBox) sender).SelectedItem is SchedulerAppointmentDC sc && sc.IsTask && sc.SupportConceptList.Count == 1 && (BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConcept_ViewAllSupportConcepts) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll) || BeWoApp.LoggedOnUser.HasRight(UserRightType.SupportConceptView_View))) { VMFactory.CreateSupportConceptVMAsync( sc.SupportConceptList.First().SupportConceptOid, cb => this.Dispatch( delegate { MainControl.NavigateTo( new SupportConceptView(cb, sc) { ParentView = this }); //new SupportConceptView2(cb) //{ // ParentView = this //}); })); } else if(((ListBox)sender).SelectedItem is SchedulerAppointmentDC sc2 && !sc2.IsTask && (BeWoApp.LoggedOnUser.HasRight(UserRightType.KalenderAnsehen) || BeWoApp.LoggedOnUser.HasRight(UserRightType.ViewAll)) && sc2.StartDate.HasValue) { MainControl.NavigateTo(new SchedulerMasterView(sc2.StartDate.Value, sc2) { ParentView = this}); } } } // private void FillOutbox() // { // if (BeWoApp.LoggedOnUser.Employee != null) // { // BeWo.ServiceProxy.ServiceFacade.DoMailServiceAsync( // s => s.GetOutgoingMails(BeWoApp.LoggedOnUser.Employee.EmployeeOid), // result => this.Dispatcher.BeginInvoke(new Call(delegate() // { // outboxList.ItemsSource = result; // })) // ); // } // } // private void FillInbox() // { // if (BeWoApp.LoggedOnUser.Employee != null) // { // BeWo.ServiceProxy.ServiceFacade.DoMailServiceAsync( // s => s.GetIncomingMails(BeWoApp.LoggedOnUser.Employee.EmployeeOid), // result => this.Dispatcher.BeginInvoke(new Call(delegate() // { // text.Text = GenerateMailText(result); // inboxList.ItemsSource = result; // })) // ); // } // } // delegate void Call(); // private static string GenerateMailText(List result) // { // //var builder = new StringBuilder(); // //var unreadMails = result.Where(r => r.Status == null || r.Status == Status.unread).Count(); // //builder.AppendLine("Sie haben " + unreadMails + "/" + result.Count + " Mails"); // //foreach (var item in result) // //{ // // builder.AppendLine(item.Subject); // //} // //return builder.ToString(); // var unreadMails = result.Where(r => r.Status == null || r.Status == Status.unread).Count(); // return "Sie haben " + unreadMails + "/" + result.Count + " Mails"; // } // private void ButtonNew_Click(object sender, RoutedEventArgs e) // { // OpenSendMailView(); // // throw new NotImplementedException(); // } // private void OpenSendMailView() // { // BeWoApp.MainControl.NavigateTo(new SendMailView() { ParentView = this }); // //throw new NotImplementedException(); // } // private void ButtonReplyNew_Click(object sender, RoutedEventArgs e) // { // if (boxTabControl.SelectedIndex == 0) // { // if (inboxList.SelectedIndex < 0) // { // MessageBox.Show("Sie haben keine Nachricht ausgewählt"); // return; // } // var mailDC = inboxList.SelectedItem as MailDC; // BeWoApp.MainControl.NavigateTo(new SendMailView(SendMailView.Mode.Reply, mailDC)); // } // else // { // MessageBox.Show("Sie können nicht auf Ihre eigene Mail antworten"); // } // } // private void ButtonForward_Click(object sender, RoutedEventArgs e) // { // if (boxTabControl.SelectedIndex == 0) // { // if (inboxList.SelectedIndex < 0) // { // MessageBox.Show("Sie haben keine Nachricht ausgewählt"); // return; // } // var mailDC = inboxList.SelectedItem as MailDC; // BeWoApp.MainControl.NavigateTo(new SendMailView(SendMailView.Mode.Forward, mailDC)); // } // else // { // MessageBox.Show("Sie können Ihre eigene Mail nicht wieterleiten"); // } // } // private void ButtonDelete_Click(object sender, RoutedEventArgs e) // { // if (boxTabControl.SelectedIndex == 0) // { // if (inboxList.SelectedIndex < 0) // { // MessageBox.Show("Sie haben keine Nachricht ausgewählt"); // return; // } // var mailDC = inboxList.SelectedItem as MailDC; // BeWo.ServiceProxy.ServiceFacade.DoMailServiceAsync(s => s.DeleteMail(BeWoApp.LoggedOnUser.Employee.EmployeeOid, mailDC)); // //inboxList.ItemsSource.RemoveAt(inboxList.SelectedIndex); // FillInbox(); // } // else // { // MessageBox.Show("Outbox funktioniert noch nicht"); // //BeWo.ServiceProxy.ServiceFacade.DoMailServiceAsync(s => s.DeleteMail(BeWoApp.LoggedOnUser.Employee.EmployeeOid, outboxList.SelectedItem as MailDC); // } // //throw new NotImplementedException(); // } // private void InboxItem_DoubleClick(object sender, RoutedEventArgs e) // { // var listboItem = sender as ListBoxItem; // var content = listboItem.Content as MailDC; // MainControl.NavigateTo(new ViewMailView(content) { ParentView = this }); // //throw new NotImplementedException(); // } // private void OutboxItem_DoubleClick(object sender, RoutedEventArgs e) // { // var listboItem = sender as ListBoxItem; // var content = listboItem.Content as MailDC; // MainControl.NavigateTo(new ViewMailView(content) { ParentView = this }); // } private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) { Process.Start(new ProcessStartInfo((sender as Hyperlink).NavigateUri.ToString())); } private delegate void loadFeed(string url); private void PasswortAendernLinkOnRequestNavigate(object sender, RequestNavigateEventArgs e) { var pav = new PasswortAenderungsView(); pav.ShowDialog(); } private void LinkNewDatenschutz_OnRequestNavigate(object sender, RequestNavigateEventArgs e) { Process.Start(new ProcessStartInfo((sender as Hyperlink)?.NavigateUri.ToString())); } private void BtnCreateNewsItem_OnClick(object sender, RoutedEventArgs e) { TeamNewsItemVM teamVm = ((Button) sender).Tag as TeamNewsItemVM; if (teamVm != null) { NewsItemDC dc = new NewsItemDC(); dc.PublishDate = DateTime.Now; dc.Team = teamVm.Team; NewsItemVM vm = new NewsItemVM(dc); var ctrl = new NewsItemEditControl(vm); BeWoWindow window = BeWoWpfUtils.CreateBeWoPopupWindow(400, 500); window.GroupBoxContent = ctrl; window.Height = 400; window.Owner = BeWoApp.CurrentBeWo.MainWindow; //ThemeManager.SetTheme(window, Theme.Office2010Black); ctrl.CancelButtonClicked += window.Close; ctrl.OkButtonClicked += () => { SaveNewsItem(vm); window.Close(); }; window.rootGroupBox.Header = "Neuer Eintrag"; window.Title = "Neuer Eintrag"; window.Show(); } } private void SaveNewsItem(NewsItemVM vm) { ServiceFacade.DoEmployeeServiceSync(s => s.InsertNewNewsItem(vm.CommitToDataContract())); UpdateInternalNews(); } private void BtnEditNewsItem_OnClick(object sender, RoutedEventArgs e) { NewsItemDC dc = ((Button) sender).Tag as NewsItemDC; if (dc != null) { NewsItemVM vm = new NewsItemVM(dc); var ctrl = new NewsItemEditControl(vm); BeWoWindow window = BeWoWpfUtils.CreateBeWoPopupWindow(400, 500); window.GroupBoxContent = ctrl; window.Height = 400; window.Owner = BeWoApp.CurrentBeWo.MainWindow; //ThemeManager.SetTheme(window, Theme.Office2010Black); ctrl.CancelButtonClicked += window.Close; ctrl.OkButtonClicked += () => { UpdateNewsItem(vm); window.Close(); }; window.rootGroupBox.Header = "Eintrag bearbeiten"; window.Title = "Eintrag bearbeiten"; window.Show(); } } private void UpdateNewsItem(NewsItemVM vm) { ServiceFacade.DoEmployeeServiceSync(s => s.UpdateNewsItem(vm.CommitToDataContract())); UpdateInternalNews(); } private void BtnDeleteNewsItem_OnClick(object sender, RoutedEventArgs e) { NewsItemDC dc = ((Button) sender).Tag as NewsItemDC; if (dc != null) { if (MessageBox.Show("Wollen Sie den Eintrag '" + dc.Title + "' wirklich löschen?", "Löschen bestätigen", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { ServiceFacade.DoEmployeeServiceSync( s => s.DeleteNewsItem(dc.NewsItemOid.Value, dc.NewsItemVersion.Value)); UpdateInternalNews(); } } } //####### Connection with Server ########### public ChatView ServiceChatView; private async void HyperlinkChat_OnRequestNavigate(object sender, RequestNavigateEventArgs e) { //#if DEBUG // var kundennummer = "5473568546"; // //var apikey = "0b50c09aff87f20d9ced75340e04e5ccaa11dd3e7bcf25e9c4f94dc20d3cbb97"; // Login _login = new Login(kundennummer, "kihqx-PiGka", "cb", "bewo", "0b50c09aff87f20d9ced75340e04e5ccaa11dd3e7bcf25e9c4f94dc20d3cbb97"); // var x = _login.AnmeldevorgangDurchFuehren(); // ServiceChatView = new ChatView(x); // ServiceChatView.Show(); //#else if (ServiceChatView == null) { #if DEBUG if (true) { string _Code = "8ycX9-ZWbyJ"; string _kundennummer = "5473568546"; string _benutzername = "cb"; string _passwort = "bewo"; string _apikey; #else var empAppCodes = ServiceFacade.DoEmployeeServiceSync(r=>r.GetAllEmployeeAppCodes(BeWoApp.LoggedOnUser.Employee.EmployeeOid)); if (empAppCodes != null && empAppCodes.Count > 0) { string _Code = ""; foreach (var item in empAppCodes) { if(item.EmployeeCode != null && !item.EmployeeCode.Equals("")) _Code = item.EmployeeCode; } //var xxx = empAppCodes.Last(); string _kundennummer = BeWoApp.Tenant; string _benutzername = BeWoApp.UserName; string _passwort = BeWoApp.UserPassword; string _apikey; #endif //string _ChatCode = ""; //if (xxx.EmployeeCode != null && !xxx.EmployeeCode.Equals("")) //{ // _ChatCode = xxx.EmployeeCode; //} _apikey = BeWoApp.Mandator.Apikey ?? "0000"; if (!_Code.Equals("")) { //Login _login = new Login(_kundennummer, _Code, _benutzername, _passwort, _apikey); //var x = _login.AnmeldevorgangDurchFuehren(); //if (x != null) //{ // ServiceChatView = new ChatView(x); // ServiceChatView.Show(); //} } else { MessageBox.Show("Sie benötigen einen gültigen Chat-Code.", "Info"); } } else { MessageBox.Show("Sie benötigen einen gültigen Zugang zum Chat. Bitte wenden Sie sich an den Support.", "Info"); } } //else if (ServiceChatView.Visibility == Visibility.Visible) //{ // ServiceChatView.Visibility = Visibility.Hidden; //} //else if (ServiceChatView.Visibility == Visibility.Hidden) //{ // ServiceChatView.Visibility = Visibility.Visible; // if (ServiceChatView.WindowState == WindowState.Minimized) // { // ServiceChatView.WindowState = WindowState.Normal; // ServiceChatView.Height = 700; // ServiceChatView.Width = 900; // } // ServiceChatView.Activate(); //} //#endif } private void ShowAppointmentRequests(object sender, RequestNavigateEventArgs e) { Scheduler.ShowAppointmentRequests(sender, e); } public void UpdateRequestsHyperLink() { if(Scheduler != null) { Scheduler.UpdateRequestString(); RequestsHyperLinkTextBlock.Text = Scheduler.Requests; RequestsHyperlink.IsEnabled = Scheduler.Enabled; RequestsTextBlock.IsEnabled = Scheduler.Enabled; } } public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private CompactEmployeeDC _SelectedEmployeeForAppointments; private void EmployeeFilterBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if(e?.AddedItems?.Count > 0 && _IsShowingAppointments) { _SelectedEmployeeForAppointments = (CompactEmployeeDC) e.AddedItems[0]; LoadTasksAndAppointments(false, true); } } private void CreateTestAppointmentsButtonOnClick(object sender, RoutedEventArgs e) { ServiceFacade.DoResourceServiceAsync(s => { if(BeWoApp.LoggedOnEmployeeOid != null) { s.InsertTestAppointments(BeWoApp.LoggedOnEmployeeOid.Value); this.Dispatch(() => { LoadTasksAndAppointments(false, true); }); } }); } private void DeleteTestAppointmentsButtonOnClick(object sender, RoutedEventArgs e) { ServiceFacade.DoResourceServiceAsync(s => { if(BeWoApp.LoggedOnEmployeeOid != null) { s.DeleteTestAppointments(); this.Dispatch(() => { LoadTasksAndAppointments(false, true); }); } }); } } public class TaskDateDescriptionConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is SchedulerAppointmentDC task) { if (task.CompletedDate.HasValue) { return $"erledigt am: {task.CompletedDate:d}"; } if(task.DueDate.HasValue && task.DueDate.Equals(DateTime.MaxValue)) { return string.Empty; } if (task.DueDate.HasValue) { return string.Format("bis {0:d} {0:t}", task.DueDate); } if(task.StartDate.HasValue) { return task.AllDay ? $"{task.StartDate:d}" : $"{task.StartDate:d} {task.StartDate:t}"; } } return string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } public class TaskListItemBackgroundConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value is SchedulerAppointmentDC task && !task.IsTask) { if(parameter != null) { switch(parameter.ToString()) { case "ResourceBackgroundBrush": return task.ResourceList?.Count > 0 ? task.ResourceList.First().GetBrush() : new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); case "CustomerBackgroundBrush": return new SolidColorBrush(task.CustomerList?.Count > 0 ? Color.FromRgb(59, 119, 153) : Color.FromArgb(0, 0, 0, 0)); case "EmployeeBackgroundBrush": return task.EmployeeList?.Count > 0 ? task.EmployeeList.First().Employee.FilterableBrush : task.Originator?.FilterableBrush ?? new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); } } return new LinearGradientBrush(Color.FromRgb(192, 255, 208), Color.FromRgb(192, 255, 208), new Point(0, 0), new Point(1, 1)); } return new LinearGradientBrush(Color.FromRgb(153, 59, 59), Color.FromRgb(92, 25, 25), new Point(0, 0), new Point(0, 1)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class BorderCornerRadiusConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var fallbackCornerRadius = new CornerRadius(0, 5, 5, 0); if(value is SchedulerAppointmentDC appointment && !appointment.IsTask && parameter != null) { switch(parameter.ToString()) { case "Customers": return appointment.CustomerList?.Count > 0 && appointment.ResourceList?.Count > 0 ? new CornerRadius(0, 5, 0, 0) : fallbackCornerRadius; case "Resources": return appointment.CustomerList?.Count > 0 && appointment.ResourceList?.Count > 0 ? new CornerRadius(0, 0, 5, 0) : fallbackCornerRadius; default: return fallbackCornerRadius; } } return fallbackCornerRadius; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } public class TaskListItemForegroundConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value is SchedulerAppointmentDC task && !task.IsTask) { return new SolidColorBrush(Color.FromRgb(0, 0, 0)); } return new SolidColorBrush(Color.FromRgb(201, 210, 210)); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class TaskAppointmentVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value is SchedulerAppointmentDC taskAppointment) { switch(parameter?.ToString()) { case "ToolTipTimeVisibility": return taskAppointment.IsTask || taskAppointment.AllDay ? Visibility.Collapsed : Visibility.Visible; case "ToolTipTrennstrichVisibility": return !taskAppointment.IsTask && (taskAppointment.EmployeeList?.Count > 0 || taskAppointment.CustomerList?.Count > 0 || taskAppointment.ResourceList?.Count > 0) ? Visibility.Visible : Visibility.Collapsed; case "ToolTipResourcesVisibility": return !taskAppointment.IsTask && taskAppointment.ResourceList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case "ToolTipEmployeesVisibility": return !taskAppointment.IsTask && taskAppointment.EmployeeList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case "ToolTipCustomersVisibility": return !taskAppointment.IsTask && taskAppointment.CustomerList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case "ToolTipZusageVisibility": return !taskAppointment.IsTask ? Visibility.Visible : Visibility.Collapsed; case "ToolTipCustomerColorVisibility": return !taskAppointment.IsTask && taskAppointment.CustomerList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case "ToolTipResourcesColorVisibility": return !taskAppointment.IsTask && taskAppointment.ResourceList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case "CustomerBorderVisibility": return !taskAppointment.IsTask && taskAppointment.CustomerList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case "ResourceBorderVisibility": return !taskAppointment.IsTask && taskAppointment.ResourceList?.Count > 0 ? Visibility.Visible : Visibility.Collapsed; case"EmployeeBorderVisibility": return !taskAppointment.IsTask && taskAppointment.EmployeeList?.Count > 0 ||taskAppointment.Originator != null ? Visibility.Visible : Visibility.Collapsed; } } return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } public class TaskAppointmentToolTipConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value is SchedulerAppointmentDC taskAppointment) { if(!taskAppointment.IsTask) { var custoemrs = taskAppointment.CustomerList; var resources = taskAppointment.ResourceList; var toolTip = string.Empty; var seperator = "; "; var selection = new List(); var isResourceOrCustomer = false; switch (parameter?.ToString()) { case "TimeText": return $"{taskAppointment.StartDate?.ToString("HH:mm")} - {taskAppointment.EndDate?.ToString("HH:mm")} Uhr"; case "ToolTip": return taskAppointment.Subject; case "Resources": isResourceOrCustomer = true; seperator = ", "; if (resources != null) { selection = resources.Cast().ToList(); } break; case "Employees": return taskAppointment.EmployeeList; case "Customers": isResourceOrCustomer = true; if (custoemrs != null) { selection = custoemrs.Cast().ToList(); } break; } if(isResourceOrCustomer) { foreach (var item in selection) { var index = selection.IndexOf(item); if (index % 3 == 0 && index < selection.Count - 1 && index > 0) { toolTip += "\n"; } toolTip += item.ToString(); if (index < selection.Count - 1) { toolTip += seperator; } } return toolTip; } } else { switch(parameter?.ToString()) { case "TimeText": return string.Empty; } } if(parameter != null && parameter.Equals("ToolTip")) { return taskAppointment.IsTask ? taskAppointment.TaskDescription : taskAppointment.Description; } } return null; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException(); } public class BorderHeightConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { const double fallbackValue = 0d; if(values.Length == 2) { var actualHeight = (double) values[0]; var appointment = (SchedulerAppointmentDC) values[1]; var newHeight = appointment?.CustomerList?.Count > 0 && appointment.ResourceList?.Count > 0 ? actualHeight / 2 : actualHeight; return newHeight; } return fallbackValue; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => throw new NotImplementedException(); } public struct RecurringAppointment { public string RecurrenceId { get; set;} public Dictionary Occurrences { get; set; } public SchedulerAppointmentDC Pattern { get; set;} public RecurringAppointment(string pRecurrenceId, Dictionary pOccurrences, SchedulerAppointmentDC pPattern) { RecurrenceId = pRecurrenceId; Occurrences = pOccurrences; Pattern = pPattern; } } }