Files
BeWoPlaner/BeWo/View/Controls/GoalRatingControl.xaml.cs
2020-08-17 15:50:00 +02:00

134 lines
3.6 KiB
C#

using BeWo.Core;
using BeWo.ServiceProxy;
using BS.Shared.Extensions;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using BeWo.Core.Service;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.ClientPartials;
using BS.Shared.Translation;
using DevExpress.Data.Helpers;
using DevExpress.Xpf.Editors.Settings;
namespace BeWo.View.Controls
{
/// <summary>
/// Interaktionslogik für TestEMailControl.xaml
/// </summary>
public partial class GoalRatingControl : UserControl
{
private List<SupportConceptGoalDC> _Goals;
public event Action CancelButtonClicked;
public event Action ActionButtonClicked;
public GoalRatingControl()
{
InitializeComponent();
ColumnRating.EditSettings = new ComboBoxEditSettings { ItemsSource = Cache.GetInstance().GetAllRatingTypeList(), IsTextEditable = false };
IsDirty = false;
}
public List<SupportConceptGoalDC> Goals
{
get { return _Goals;}
set
{
_Goals = value;
CreateList();
}
}
private void CreateList()
{
List<GoalRatingEntry> entries = new List<GoalRatingEntry>();
foreach (var goal in Goals)
{
GoalRatingEntry entry = new GoalRatingEntry();
entry.Goal = goal;
entry.Name = goal.DetailDescription;
if (goal.HasRating)
{
entry.RatingType = Cache.GetInstance().GetAllRatingTypeList().FirstOrDefault(r => r.RatingTypeOid == goal.GoalEntryDC.RatingTypeOid);
}
entries.Add(entry);
}
Entries = entries;
}
private void CancelButton_OnClick(object sender, RoutedEventArgs e)
{
if (IsDirty)
{
if (MessageBox.Show(
Translator.Translate("Möchten Sie wirklich abbrechen und die Änderungen verwerfen?"),
"BeWoPlaner", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
{
return;
}
}
CancelButtonClicked?.Invoke();
}
private void ActionButton_OnClick(object sender, RoutedEventArgs e)
{
Save();
ActionButtonClicked?.Invoke();
}
private void TableView_CellValueChanged(object sender, DevExpress.Xpf.Grid.CellValueChangedEventArgs e)
{
IsDirty = true;
}
public bool IsDirty { get; set; }
public List<GoalRatingEntry> Entries
{
get { return DatagridRegions.ItemsSource as List<GoalRatingEntry>; }
set
{
DatagridRegions.ItemsSource = value;
}
}
public void Save()
{
foreach (var e in Entries)
{
if (e.RatingType != null)
{
e.Goal.SetRatingType(e.RatingType);
}
else
{
e.Goal.SetRatingType(null);
}
}
}
}
public class GoalRatingEntry
{
public SupportConceptGoalDC Goal { get; set; }
public String Name { get; set; }
public RatingTypeDC RatingType { get; set; }
}
}