365 lines
12 KiB
C#
365 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls.Primitives;
|
|
using System.Windows.Input;
|
|
using BeWo.Core.Service;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.ClientPartials;
|
|
|
|
namespace BeWo.View.Controls
|
|
{
|
|
public partial class ComboBoxTreeViewControl
|
|
{
|
|
private SupportConceptGoalDC lastCheckedSupportConceptGoal;
|
|
|
|
public static readonly DependencyProperty ShowRatingPanelProperty = DependencyProperty.Register("ShowRatingPanel", typeof(bool), typeof(ComboBoxTreeViewControl), new FrameworkPropertyMetadata(false));
|
|
|
|
public bool ShowRatingPanel
|
|
{
|
|
get { return (bool)GetValue(ShowRatingPanelProperty); }
|
|
set { SetValue(ShowRatingPanelProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty SelectOnlyLeafsProperty = DependencyProperty.Register("SelectOnlyLeafs", typeof(bool), typeof(ComboBoxTreeViewControl), new FrameworkPropertyMetadata(true));
|
|
|
|
public bool SelectOnlyLeafs
|
|
{
|
|
get { return (bool)GetValue(SelectOnlyLeafsProperty); }
|
|
set { SetValue(SelectOnlyLeafsProperty, value); }
|
|
}
|
|
|
|
public double ParentWindowHeight
|
|
{
|
|
get { return (double) GetValue(ParentWindowHeightProperty); }
|
|
set { SetValue(ParentWindowHeightProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty ParentWindowHeightProperty = DependencyProperty.Register("ParentWindowHeight", typeof (double), typeof (ComboBoxTreeViewControl), new FrameworkPropertyMetadata(500.0));
|
|
|
|
|
|
public List<SupportConceptGoalDC> TreeViewSourceList
|
|
{
|
|
get { return (List<SupportConceptGoalDC>)GetValue(ListProperty); }
|
|
set
|
|
{
|
|
SetValue(ListProperty, value);
|
|
ShowCheckedValues();
|
|
}
|
|
}
|
|
|
|
public static readonly DependencyProperty ListProperty = DependencyProperty.Register("TreeViewSourceList", typeof (List<SupportConceptGoalDC>), typeof (ComboBoxTreeViewControl), new FrameworkPropertyMetadata(new List<SupportConceptGoalDC>()));
|
|
|
|
public ComboBoxTreeViewControl()
|
|
{
|
|
InitializeComponent();
|
|
DataContext = this;
|
|
InitRatings();
|
|
}
|
|
|
|
private void InitRatings()
|
|
{
|
|
ratingPanel.Children.Clear();
|
|
var ratingList = Cache.GetInstance().GetAllRatingTypeList();
|
|
foreach (var r in ratingList)
|
|
{
|
|
//<RadioButton x:Name="RadioButton0" Margin="3" FontSize="12" Click="RatingButton_OnClick" Tag="0" Content="xxx.0 - Problem nicht vorhanden (ohne, kein, unerheblich ...) 0 bis 4 %"></RadioButton>
|
|
|
|
var rb = new RadioButton();
|
|
rb.Margin = new Thickness(3);
|
|
rb.FontSize = 12;
|
|
rb.Click += RatingButton_OnClick;
|
|
rb.Tag = r;
|
|
rb.Content = r.DisplayName;
|
|
|
|
ratingPanel.Children.Add(rb);
|
|
}
|
|
}
|
|
|
|
private void ShowCheckedValues()
|
|
{
|
|
GoalCount = 0;
|
|
var selectedGoals = GetSelectedGoals();
|
|
|
|
var allSelected = selectedGoals.Count == GoalCount && GoalCount > 0;
|
|
|
|
var ToolTipString = selectedGoals.Aggregate(string.Empty, (s, dc) => s + (dc.DisplayName + "; "));
|
|
|
|
DeSelectAllCheckBox.IsChecked = allSelected;
|
|
|
|
Imitationheader.Text = ToolTipString;
|
|
|
|
if (string.IsNullOrWhiteSpace(ToolTipString))
|
|
{
|
|
Imitationheader.ToolTip = null;
|
|
return;
|
|
}
|
|
|
|
var splittedToolTip = ToolTipString.Split(';');
|
|
ToolTipString = string.Empty;
|
|
|
|
foreach (var item in splittedToolTip.Where(x => x != " "))
|
|
{
|
|
ToolTipString += item.Trim(' ');
|
|
|
|
if (splittedToolTip.Where(x => x != " ").ToList().IndexOf(item) < splittedToolTip.Count(x => x != " ") - 1)
|
|
{
|
|
ToolTipString += "\n";
|
|
}
|
|
}
|
|
|
|
Imitationheader.ToolTip = ToolTipString;
|
|
}
|
|
|
|
private List<ValueListEntryDC> GetSelectedGoals()
|
|
{
|
|
var goals = new List<ValueListEntryDC>();
|
|
|
|
AddCheckedGoals(TreeViewSourceList, goals);
|
|
|
|
return goals;
|
|
}
|
|
|
|
private int GoalCount;
|
|
private void AddCheckedGoals(IEnumerable<SupportConceptGoalDC> goals, ICollection<ValueListEntryDC> selectedGoals)
|
|
{
|
|
foreach (var item in goals)
|
|
{
|
|
if (item.Children == null || item.Children.Count == 0)
|
|
{
|
|
//if (item.GoalEntryDC.Type.Equals(ValueListEntryType.SupportConceptGoalType) || item.GoalEntryDC.Type.Equals(ValueListEntryType.SupportConceptIndividualGoalType))
|
|
//{
|
|
GoalCount++;
|
|
if (item.IsChecked)
|
|
{
|
|
selectedGoals.Add(item.GoalEntryDC);
|
|
}
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
if (!SelectOnlyLeafs)
|
|
{
|
|
GoalCount++;
|
|
if (item.IsChecked)
|
|
{
|
|
selectedGoals.Add(item.GoalEntryDC);
|
|
}
|
|
}
|
|
AddCheckedGoals(item.Children, selectedGoals);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OpenPopUpBtnClick(object sender, EventArgs e)
|
|
{
|
|
openPopup();
|
|
}
|
|
|
|
private void openPopup()
|
|
{
|
|
TreeViewPopup.Placement = PlacementMode.RelativePoint;
|
|
TreeViewPopup.PlacementTarget = Imitationheader;
|
|
TreeViewPopup.VerticalOffset = Imitationheader.Height;
|
|
TreeViewPopup.HorizontalOffset = 0;
|
|
TreeViewPopup.MinWidth = Imitationheader.Width;
|
|
TreeViewPopup.IsOpen = true;
|
|
|
|
if (ParentWindowHeight == 0)
|
|
{
|
|
ParentWindowHeight = 500;
|
|
}
|
|
|
|
OpenPopUpBtn.IsEnabled = false;
|
|
}
|
|
|
|
private void PopUpClosedEvent(object sender, EventArgs eventArgs)
|
|
{
|
|
ShowCheckedValues();
|
|
|
|
cbtv_search.Text = string.Empty;
|
|
OpenPopUpBtn.IsEnabled = true;
|
|
}
|
|
|
|
private void ApplyBtnClose(object sender, EventArgs e)
|
|
{
|
|
TreeViewPopup.IsOpen = false;
|
|
}
|
|
|
|
public void ResetControl()
|
|
{
|
|
TreeViewSourceList = new List<SupportConceptGoalDC>();
|
|
Imitationheader.Text = string.Empty;
|
|
Imitationheader.ToolTip = null;
|
|
DeSelectAllCheckBox.IsChecked = false;
|
|
}
|
|
|
|
private void Tree1_OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ParentWindowHeight >= TreeViewPopup.VerticalOffset)
|
|
{
|
|
TreeViewPopup.MaxHeight = ParentWindowHeight - TreeViewPopup.VerticalOffset - ParentWindowHeight/4;
|
|
}
|
|
}
|
|
|
|
private void Bd_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
ShowCheckedValues();
|
|
|
|
var cb = sender as CheckBox;
|
|
if (cb != null)
|
|
{
|
|
lastCheckedSupportConceptGoal = cb.Tag as SupportConceptGoalDC;
|
|
|
|
SetPopUpVisible(cb.IsChecked.Value);
|
|
}
|
|
}
|
|
|
|
private void SetPopUpVisible(bool visible)
|
|
{
|
|
if (!ShowRatingPanel || !BeWoApp.LoggedOnUser.HasRight(UserRightType.BewertenInZeiterfassung))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (ratingPanel.Children.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
if (lastCheckedSupportConceptGoal == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (lastCheckedSupportConceptGoal.Children != null && lastCheckedSupportConceptGoal.Children.Count > 0)
|
|
{
|
|
//return;
|
|
}
|
|
RatingPopup.IsOpen = visible;
|
|
|
|
RadioButtonNone.IsChecked = true;
|
|
if (lastCheckedSupportConceptGoal.GoalEntryDC.RatingTypeOid.HasValue)
|
|
{
|
|
foreach (var c in ratingPanel.Children)
|
|
{
|
|
RadioButton rb = c as RadioButton;
|
|
if (rb != null && rb.Tag != null)
|
|
{
|
|
RatingTypeDC rbRating = rb.Tag as RatingTypeDC;
|
|
|
|
if (rbRating != null && rbRating.RatingTypeOid ==
|
|
lastCheckedSupportConceptGoal.GoalEntryDC.RatingTypeOid)
|
|
{
|
|
rb.IsChecked = true;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void DeSelectAllOnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
var cb = (CheckBox)sender;
|
|
|
|
if (!cb.IsChecked.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var item in TreeViewSourceList)
|
|
{
|
|
item.IsChecked = cb.IsChecked.Value;
|
|
|
|
foreach (var item2 in item.Children)
|
|
{
|
|
item2.IsChecked = cb.IsChecked.Value;
|
|
}
|
|
}
|
|
|
|
ShowCheckedValues();
|
|
}
|
|
|
|
private void BdText_OnMouseDown(object sender, MouseButtonEventArgs e)
|
|
{
|
|
var SupportConceptGoal = ((TextBlock)sender).Tag as SupportConceptGoalDC;
|
|
|
|
if(SupportConceptGoal != null)
|
|
{
|
|
SupportConceptGoal.IsChecked = !SupportConceptGoal.IsChecked;
|
|
|
|
lastCheckedSupportConceptGoal = SupportConceptGoal;
|
|
|
|
SetPopUpVisible(SupportConceptGoal.IsChecked);
|
|
}
|
|
|
|
ShowCheckedValues();
|
|
}
|
|
|
|
|
|
//private void button_checkAllLeistungen_Click(object sender, RoutedEventArgs e)
|
|
//{
|
|
// CheckAllLeistungTreeItems(true);
|
|
//}
|
|
|
|
//private void button_uncheckAllLeistungen_Click(object sender, RoutedEventArgs e)
|
|
//{
|
|
// CheckAllLeistungTreeItems(false);
|
|
//}
|
|
|
|
private void button_aufklappenAllLeistungen_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SwitchAllLeistungTreeItems(true);
|
|
}
|
|
|
|
private void button_zuklappenAllLeistungen_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
SwitchAllLeistungTreeItems(false);
|
|
}
|
|
|
|
//private void CheckAllLeistungTreeItems(bool check)
|
|
//{
|
|
// var allItems = Tree1.ItemsSource;
|
|
|
|
// foreach (var item in allItems)
|
|
// {
|
|
// SupportConceptGoalDC goal = item as SupportConceptGoalDC;
|
|
// goal.IsChecked = check;
|
|
// }
|
|
//}
|
|
|
|
private void SwitchAllLeistungTreeItems(bool check)
|
|
{
|
|
Style stylee = new Style
|
|
{
|
|
TargetType = typeof(TreeViewItem)
|
|
};
|
|
|
|
stylee.Setters.Add(new Setter(TreeViewItem.IsExpandedProperty, check));
|
|
Tree1.ItemContainerStyle = stylee;
|
|
}
|
|
|
|
private void RatingButton_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (lastCheckedSupportConceptGoal != null)
|
|
{
|
|
RadioButton rb = sender as RadioButton;
|
|
if (rb.Tag != null)
|
|
{
|
|
var rt = rb.Tag as RatingTypeDC;
|
|
|
|
if (rt != null)
|
|
{
|
|
lastCheckedSupportConceptGoal.SetRatingType(rt);
|
|
}
|
|
}
|
|
}
|
|
RatingPopup.IsOpen = false;
|
|
}
|
|
}
|
|
}
|