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 { /// /// Interaktionslogik für TestEMailControl.xaml /// public partial class GoalRatingControl : UserControl { private List _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 Goals { get { return _Goals;} set { _Goals = value; CreateList(); } } private void CreateList() { List entries = new List(); 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 Entries { get { return DatagridRegions.ItemsSource as List; } 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; } } }