130 lines
4.2 KiB
C#
130 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
using BeWo.Core;
|
|
using BeWo.Core.Service;
|
|
using BeWo.ServiceProxy;
|
|
using BeWo.Validation;
|
|
using BeWo.ViewModel;
|
|
using BeWo.ViewModel.ListViewModel;
|
|
|
|
using BS.Shared.Core;
|
|
using BS.Shared.Extensions;
|
|
|
|
using DevExpress.Xpf.Editors.Settings;
|
|
|
|
namespace BeWo.View.Detail
|
|
{
|
|
public partial class ServiceCategoryView : BeWoView
|
|
{
|
|
private ServiceCategoryListVM _ViewModel;
|
|
|
|
public ServiceCategoryView(ServiceCategoryListVM pViewModel)
|
|
{
|
|
InitializeComponent();
|
|
ViewModel = pViewModel;
|
|
|
|
column_visibility.EditSettings = new ComboBoxEditSettings { ItemsSource = EnumTranslations.Accountingvisibility2Translations, DisplayMember = "Value", ValueMember = "Key" };
|
|
|
|
//if (combo_approvedvisibility.SelectedIndex == -1)
|
|
// combo_approvedvisibility.SelectedIndex = 1;
|
|
|
|
column_interval.EditSettings = new ComboBoxEditSettings { ItemsSource = EnumTranslations.AccountingInterval2Translations, DisplayMember = "Value", ValueMember = "Key" };
|
|
|
|
if(pViewModel.VMList.Count > 0)
|
|
{
|
|
ViewModel.NewVM.Position = pViewModel.VMList.Max(s => s.Position) + 1;
|
|
}
|
|
}
|
|
|
|
public override bool IsDirty => ViewModel != null && ViewModel.IsDirty;
|
|
|
|
public override string Title => "Leistungskategorien";
|
|
|
|
// TODO
|
|
internal override DependencyObject ValidationOnSaveRootElement => button_addCategory;
|
|
|
|
private ServiceCategoryListVM ViewModel
|
|
{
|
|
get => _ViewModel;
|
|
|
|
set
|
|
{
|
|
_ViewModel = value;
|
|
root.DataContext = value;
|
|
}
|
|
}
|
|
|
|
protected override void Save()
|
|
{
|
|
var lToDos = new List<Action<IOperationsService>>();
|
|
|
|
if (ViewModel.RemovedCount > 0)
|
|
{
|
|
lToDos.Add(s => s.DeactivateServiceCategories(ViewModel.GetRemoved().ToDictionary(dc => dc.ServiceCategoryOid.Value, dc => dc.ServiceCategoryVersion.Value)));
|
|
}
|
|
|
|
if (ViewModel.AddedCount > 0)
|
|
{
|
|
lToDos.Add(s => s.InsertNewServiceCategories(ViewModel.CommitAdded()));
|
|
}
|
|
|
|
if (ViewModel.ChangedCount > 0)
|
|
{
|
|
lToDos.Add(s => s.UpdateServiceCategories(ViewModel.CommitChanged()));
|
|
}
|
|
|
|
ServiceFacade.DoMultipleOperationsServicesAsync(lToDos, ReloadViewModel);
|
|
}
|
|
|
|
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var lVM = datagrid_categories.GetCurrentValue<ServiceCategoryVM>();
|
|
if (lVM != null)
|
|
{
|
|
ViewModel.VMList.Remove(lVM);
|
|
BeWoWpfUtils.RefreshDXGrid(datagrid_categories);
|
|
}
|
|
}
|
|
|
|
private void ReloadViewModel()
|
|
{
|
|
Cache.GetInstance().ClearServiceCategoryDescriptions();
|
|
VMFactory.CreateServiceCategoryListVMAsync(r => this.Dispatch(delegate { ViewModel = r; }));
|
|
}
|
|
|
|
private void button_addCategory_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (ValidationTrigger.Validate(this))
|
|
{
|
|
ViewModel.AddNewVMToList();
|
|
|
|
if(ViewModel.VMList.Count > 0)
|
|
{
|
|
ViewModel.NewVM.Position = ViewModel.VMList.Max(s => s.Position) + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PART_Editor_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var data = datagrid_categories.View.FocusedRowData;
|
|
|
|
if (data?.RowHandle != null)
|
|
{
|
|
if (datagrid_categories.GetRow(data.RowHandle.Value) is ServiceCategoryVM vm)
|
|
{
|
|
ViewModel.EditVM = vm;
|
|
popup_costrateperiods.IsOpen = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button_edit_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
popup_costrateperiods.IsOpen = false;
|
|
}
|
|
}
|
|
} |