Ohne Syncfusion

This commit is contained in:
2023-04-11 19:09:28 +02:00
parent d9e3fdb793
commit c4fd240f59
10 changed files with 107 additions and 107 deletions

View File

@@ -46,6 +46,7 @@ namespace SewerStammGen.EntityFramework.Services.Common
{
using SewerStammGenDbContext context = _contextFactory.CreateDbContext();
entity.Id = id;
context.Set<T>().Update(entity);
await context.SaveChangesAsync();
return entity;

View File

@@ -55,6 +55,15 @@ namespace SewerStammGen.EntityFramework.Services
throw new NotImplementedException();
}
public async Task<Schacht> GetSchachtByNameAndProjekt(string name, int projektID)
{
using(SewerStammGenDbContext context = _contextFactory.CreateDbContext())
{
Schacht entity = await context.Set<Schacht>().Where(x => x.Projekt.Id.Equals(projektID) && x.Objektbezeichnung.Equals(name)).FirstOrDefaultAsync();
return entity;
}
}
public async Task<Schacht> Update(int id, Schacht entity)
{
return await _nonQueryDataService.Update(id, entity);

View File

@@ -0,0 +1,38 @@
using SewerStammGen.Shared.Contracts;
using SewerStammGen.WPF.ViewModel;
using Shared.Contracts;
using Shared.Domain;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewerStammGen.WPF.Commands
{
internal class HaltungEditSaveCommand : AsyncCommandBase
{
private HaltungEditViewModel haltungEditViewModel;
private IDataService<Kanal> kanalDataService;
private ISchachtService schachtService;
public HaltungEditSaveCommand(HaltungEditViewModel haltungEditViewModel, IDataService<Kanal> kanalDataService, ISchachtService schachtService)
{
this.haltungEditViewModel = haltungEditViewModel;
this.kanalDataService = kanalDataService;
this.schachtService = schachtService;
}
public override async Task ExecuteAsync(object? parameter)
{
if(haltungEditViewModel._oberePunkt != haltungEditViewModel.Model.StartSchacht.Objektbezeichnung)
{
Schacht s = await schachtService.FindSchachtByNameAndProjektID(haltungEditViewModel._oberePunkt, haltungEditViewModel.Model.Projekt.Id);
haltungEditViewModel.Model.StartSchacht = s;
}
haltungEditViewModel.Model = await kanalDataService.Update(haltungEditViewModel.Model.Id, haltungEditViewModel.Model);
Trace.WriteLine("Daten gespeichert");
}
}
}

View File

@@ -27,7 +27,11 @@ namespace SewerStammGen.HostBuilders
if (databaseToUse.Equals("default"))
{
connectionString = context.Configuration.GetConnectionString("default");
configureDbContext = o => o.UseNpgsql(connectionString);
configureDbContext = o =>
{
o.EnableSensitiveDataLogging();
o.UseNpgsql(connectionString);
};
}
else if (databaseToUse.Equals("sqlite"))
{

View File

@@ -72,11 +72,11 @@ namespace SewerStammGen.HostBuilders
);
});
services.AddSingleton<CreateViewModel<HaltungEditViewModel>>(services =>
services.AddTransient<CreateViewModel<HaltungEditViewModel>>(services =>
{
return () => new HaltungEditViewModel(
services.GetRequiredService<IHaltungDataService>(),
services.GetRequiredService<ISchachtDataService>(),
services.GetRequiredService<ISchachtService>(),
services.GetRequiredService<IActualState>()
);
});

View File

@@ -1,4 +1,5 @@
using SewerStammGen.Shared.Contracts;
using SewerStammGen.WPF.Commands;
using SewerStammGen.WPF.ViewModel.State;
using Shared.Contracts;
using Shared.Domain;
@@ -17,42 +18,49 @@ namespace SewerStammGen.WPF.ViewModel
{
private readonly IActualState _actualState;
private readonly IHaltungDataService _kanalDataService;
private readonly ISchachtService _schachtService;
private Kanal _model;
private ObservableCollection<Schacht> _verfuegbareSchaechte;
public ObservableCollection<Schacht> VerfuegbareSchaechte
public Kanal Model
{
get => _verfuegbareSchaechte;
}
public Schacht ObereSchacht
{
get => _model.StartSchacht;
get => _model;
set
{
if(_model.StartSchacht != value)
_model = value;
}
}
public string _oberePunkt { get; set; }
public string _unterePunkt { get; set; }
public string ObereSchacht
{
_model.StartSchacht = value;
get => _oberePunkt;
set
{
if (_oberePunkt != value)
{
_oberePunkt = value;
OnPropertyChanged();
}
}
}
public Schacht UntereSchacht
public string UntereSchacht
{
get => _model.EndSchacht;
get => _unterePunkt;
set
{
if(_model.EndSchacht != value)
if (_unterePunkt != value)
{
_model.EndSchacht = value;
_unterePunkt = value;
OnPropertyChanged();
}
}
}
public string Haltungsbezeichnung
{
get => _model.Objektbezeichnung;
@@ -105,43 +113,25 @@ namespace SewerStammGen.WPF.ViewModel
public ICommand Speichern { get; set; }
public HaltungEditViewModel(IHaltungDataService kanalDataService,
ISchachtDataService schachtDataService,
ISchachtService schachtService,
IActualState actualState)
{
_actualState = actualState;
_kanalDataService = kanalDataService;
_verfuegbareSchaechte = new ObservableCollection<Schacht>();
_schachtService = schachtService;
_model = new Kanal();
Speichern = new RelayCommand((x) => SaveKanal());
Speichern = new HaltungEditSaveCommand(this, kanalDataService, schachtService);
LoadModel();
LoadSchaechte(schachtDataService);
}
private async void LoadSchaechte(ISchachtDataService schachtDataService)
{
var s = await schachtDataService.GetAll(_actualState.ProjektID);
InitCollection(_verfuegbareSchaechte, s);
}
private void InitCollection(ObservableCollection<Schacht> dst, IEnumerable<Schacht> src)
{
dst.Clear();
foreach (var srcItem in src) {
dst.Add(srcItem);
}
OnPropertyChanged(nameof(VerfuegbareSchaechte));
}
private void SaveKanal()
{
_kanalDataService.Update(_model.Id, _model);
}
private async void LoadModel()
{
_model = await _kanalDataService.Get(_actualState.HaltungID);
UntereSchacht = _model.EndSchacht.Objektbezeichnung;
ObereSchacht = _model.StartSchacht.Objektbezeichnung;
OnPropertyChanged(nameof(ObereSchacht));
OnPropertyChanged(nameof(UntereSchacht));
OnPropertyChanged(nameof(Haltungslaenge));

View File

@@ -3,24 +3,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
xmlns:local="clr-namespace:SewerStammGen.WPF.Views"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>
<DataTemplate x:Key="headerTemplate">
<TextBox x:Name="searchTextBox" Margin="4" Text="{Binding Path=DataContext.SearchText, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=syncfusion:SfMultiColumnDropDownControl}}">
<behaviors:Interaction.Triggers>
<behaviors:EventTrigger EventName="TextChanged">
<local:TextBoxFilterAction TargetObject="{x:Reference Name=MultiColumnControl5}" />
</behaviors:EventTrigger>
</behaviors:Interaction.Triggers>
</TextBox>
</DataTemplate>
</UserControl.Resources>
<Grid>
<Grid>
<Grid.RowDefinitions>
@@ -43,51 +29,8 @@
<Label Grid.Row="1" Grid.Column="0" Content="Untere Schacht" />
<Label Grid.Row="2" Grid.Column="0" Content="Haltungsbezeichnung" />
<syncfusion:SfMultiColumnDropDownControl Grid.Column="1" Grid.Row="0"
Width="250"
Margin="10,0"
ItemsSource="{Binding VerfuegbareSchaechte}"
SelectedItem="{Binding ObereSchacht, Mode=TwoWay}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AllowAutoComplete="True"
AllowImmediatePopup="True"
AllowIncrementalFiltering="True"
AutoGenerateColumns="False"
DisplayMember="Objektbezeichnung"
HeaderTemplate="{StaticResource headerTemplate}"
PopupWidth="400"
ValueMember="Cast"
>
<syncfusion:SfMultiColumnDropDownControl.Columns>
<syncfusion:GridTextColumn MappingName="Objektbezeichnung" />
</syncfusion:SfMultiColumnDropDownControl.Columns>
</syncfusion:SfMultiColumnDropDownControl>
<syncfusion:SfMultiColumnDropDownControl Grid.Column="1" Grid.Row="1"
Width="250"
Margin="10,0"
ItemsSource="{Binding VerfuegbareSchaechte}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AllowAutoComplete="True"
AllowImmediatePopup="True"
AllowIncrementalFiltering="True"
AutoGenerateColumns="False"
DisplayMember="Objektbezeichnung"
HeaderTemplate="{StaticResource headerTemplate}"
PopupWidth="400"
ValueMember="Cast"
SelectedItem="{Binding UntereSchacht }"
>
<syncfusion:SfMultiColumnDropDownControl.Columns>
<syncfusion:GridTextColumn MappingName="Objektbezeichnung" />
</syncfusion:SfMultiColumnDropDownControl.Columns>
</syncfusion:SfMultiColumnDropDownControl>
<TextBox Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding ObereSchacht}" />
<TextBox Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding UntereSchacht}" />
<TextBox Grid.Row="2" Grid.Column="1" Margin="5" Text="{Binding Haltungsbezeichnung}" />
</Grid>
@@ -119,7 +62,7 @@
</Grid>
<StackPanel Grid.Row="4">
<Button Content="Speichern" Command="{Binding Speichern}" />
<ListBox ItemsSource="{Binding VerfuegbareSchaechte }" />
<!--<ListBox ItemsSource="{Binding VerfuegbareSchaechte }" />-->
</StackPanel>
</Grid>
</Grid>

View File

@@ -11,5 +11,6 @@ namespace SewerStammGen.Shared.Contracts
public interface ISchachtDataService : IDataService<Schacht>
{
Task<IEnumerable<Schacht>> GetAll(int projektID);
Task<Schacht> GetSchachtByNameAndProjekt(string name, int projektID);
}
}

View File

@@ -10,5 +10,6 @@ namespace SewerStammGen.Shared.Contracts
public interface ISchachtService
{
Task<Schacht> CreateSchacht(Projekt proj);
Task<Schacht> FindSchachtByNameAndProjektID(string name, int projektID);
}
}

View File

@@ -12,10 +12,15 @@ namespace SewerStammGen.Shared.Services
public class SchachtService : ISchachtService
{
private readonly IDataService<Projekt> _projectService;
private readonly ISchachtDataService _schachtDataService;
public SchachtService(IDataService<Projekt> projectService)
public SchachtService(
IDataService<Projekt> projectService,
ISchachtDataService schachtDataService
)
{
_projectService = projectService;
_schachtDataService = schachtDataService;
}
public async Task<Schacht> CreateSchacht(Projekt proj)
@@ -27,5 +32,13 @@ namespace SewerStammGen.Shared.Services
await _projectService.Update(proj.Id, proj);
return schacht;
}
public async Task<Schacht> FindSchachtByNameAndProjektID(string name, int projektID)
{
Schacht result = await _schachtDataService.GetSchachtByNameAndProjekt(name, projektID);
return result;
}
}
}