Files
BeWoPlaner/BeWo/View/Detail/SchedulerSettingsView.xaml.cs
2016-06-27 01:45:38 +02:00

157 lines
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using BeWo.Core;
using BeWo.ServiceProxy;
using BeWo.Validation;
using BeWo.ViewModel;
using BeWo.ViewModel.ListViewModel;
using BS.Shared.Extensions;
using DevExpress.Xpf.Editors.Settings;
using DevExpress.Xpf.Grid;
namespace BeWo.View.Detail
{
/// <summary>
/// Interaction logic for RessourceView.xaml
/// </summary>
public partial class SchedulerSettingsView : BeWoView
{
private AppointmentCategoryListVM _ViewModel;
public SchedulerSettingsView(AppointmentCategoryListVM pViewModel)
{
this.InitializeComponent();
this.combobox_brush.ItemTemplateSelector = new ComboBoxTemplateSelector(this.combobox_brush);
this.ViewModel = pViewModel;
}
public override bool IsDirty
{
get
{
return this.ViewModel != null ? this.ViewModel.IsDirty : false;
}
}
public override string Title
{
get
{
return "Kategorien für Termine";
}
}
internal override DependencyObject ValidationOnSaveRootElement
{
get
{
return this.datagrid_categorys;
}
}
private AppointmentCategoryListVM ViewModel
{
get
{
return this._ViewModel;
}
set
{
this.root.DataContext = value;
this._ViewModel = value;
}
}
protected override void Save()
{
var lToDos = new List<Action<ICustomerService>>();
if (this.ViewModel.AddedCount > 0)
{
lToDos.Add(s => s.InsertNewAppointmentCategories(this.ViewModel.CommitAdded()));
}
if (this.ViewModel.ChangedCount > 0)
{
lToDos.Add(s => s.UpdateAppointmentCategories(this.ViewModel.CommitChanged()));
}
if (this.ViewModel.RemovedCount > 0)
{
lToDos.Add(s => s.DeactivateAppointmentCategories(this.ViewModel.GetRemoved().ToDictionary(dc => dc.AppointmentCategoryOid.Value, dc => dc.AppointmentCategoryVersion.Value)));
}
ServiceFacade.DoMultipleCustomerServicesAsync(lToDos, this.ReloadViewModel);
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
var lVM = this.datagrid_categorys.GetCurrentValue<AppointmentCategoryVM>();
if (lVM != null)
{
this.ViewModel.VMList.Remove(lVM);
BeWoWpfUtils.RefreshDXGrid(this.datagrid_categorys);
}
}
private void ReloadViewModel()
{
VMFactory.CreateAppointmentCategoryListVMAsync(cb => this.Dispatch(delegate { this.ViewModel = cb; }));
}
private void button_addAppointmentCategory_Click(object sender, RoutedEventArgs e)
{
if (ValidationTrigger.Validate(this))
{
this.ViewModel.AddNewVMToList();
}
}
private void button_select_color_Click(object sender, RoutedEventArgs e)
{
this.popup_color.IsOpen = true;
}
private void colorEditor_Loaded(object sender, RoutedEventArgs e)
{
((ListBox)sender).ItemsSource = this.ViewModel.AllBrushes;
((ListBox)sender).ItemTemplateSelector = new ComboBoxTemplateSelector((ListBox)sender);
}
private void listbox_colorpicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count == 1)
{
object selection = e.AddedItems[0];
var view = this.datagrid_categorys.View;
RowData data = view.FocusedRowData;
if (data != null && data.RowHandle != null)
{
int rowHandle = data.RowHandle.Value;
AppointmentCategoryVM vm = this.datagrid_categorys.GetRow(rowHandle) as AppointmentCategoryVM;
if (vm != null)
{
vm.Brush = selection as SolidColorBrush;
}
}
this.popup_color.IsOpen = false;
}
}
}
}