Grundlegene Funktionen geschrieben

This commit is contained in:
2023-06-09 15:53:11 +02:00
parent 2c4e8fb4cb
commit fd84775aa4
26 changed files with 721 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
using dcnsanplanung.DAL.Services.PostgresqlData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.DAL.Helper
{
public class WriteToDatabase
{
List<shared.Model.Haltung> haltungen = new List<shared.Model.Haltung>();
List<shared.Model.LeistungsverzeichnisPosition> LVPositionen = new List<shared.Model.LeistungsverzeichnisPosition>();
public WriteToDatabase(string XMLFile, string connectionstring = "Host = localhost; Database = sanplaner; Username = dcnsanplaner; Password = sanplaner")
{
haltungen = new shared.Helper.ImportToSoftware(XMLFile).haltungen;
LVPositionen = new shared.Helper.ImportLVToSoftware(@"C:\Users\damia\source\repos\dcnsanplanung\BE-BS-AWN DW_0001_OOWV_Stamm_LV_Kanalsanierung_xml33.X81").LVPositionen;
}
public async Task<bool> WriteInHaltung()
{
string connectionstring = "Host = localhost; Database = sanplaner; Username = dcnsanplaner; Password = sanplaner";
HaltungDataService haltungDataService = new HaltungDataService(connectionstring);
await haltungDataService.InsertHaltungBulk(haltungen);
return true;
}
public async Task<bool> WriteInLV()
{
string connectionstring = "Host = localhost; Database = sanplaner; Username = dcnsanplaner; Password = sanplaner";
LVDataService lVDataService = new LVDataService(connectionstring);
await lVDataService.InsertLeistungsverzeichnisPositionBulk(LVPositionen);
return true;
}
}
}

View File

@@ -0,0 +1,87 @@
using dcnsanplanung.shared.Model;
using Npgsql;
using Schnittstelle.Import.XML.v2013.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.DAL.Services.PostgresqlData
{
public class HaltungDataService : PostgresqlDataService
{
SchadenDataService schadenDataService;
public HaltungDataService(string connectionstring) : base(connectionstring, "haltung")
{
schadenDataService = new SchadenDataService(connectionstring);
}
public async Task<Haltung> Create(Haltung entity)
{
string command = "INSERT INTO " + tableName + " (guid, ref_projekt_guid, objektbezeichnung, bewertungklasse) VALUES " +
"(@1,@2,@3,@4) RETURNING id";
using (var cmd = new NpgsqlCommand(command, conn))
{
cmd.Parameters.AddWithValue("1", entity.Guid.ToString());
cmd.Parameters.AddWithValue("2", entity.Ref_Projekt_Guid.ToString());
cmd.Parameters.AddWithValue("3", entity.Objektbezeichnung);
cmd.Parameters.AddWithValue("4", NpgsqlTypes.NpgsqlDbType.Oid, entity.Bewertungklasse);
using var reader = await cmd.ExecuteReaderAsync();
reader.Read();
entity.ID = reader.GetInt32(0);
}
await schadenDataService.InsertSchadenBulk(entity.Kodierungen);
return entity;
}
public async Task<IEnumerable<Haltung>> GetAllByProjekt(int projektID)
{
List<Haltung> result = new List<Haltung>();
//ISchachtDataService schachtDataService = new SchachtDataService(connString);
//IEnumerable<Schacht> schaechte = await schachtDataService.GetAllByProjekt(projektID);
string command = "SELECT * FROM " + tableName + ";";//" WHERE ref_projekt_id = @1";
using (var cmd = new NpgsqlCommand(command, conn))
{
//cmd.Parameters.AddWithValue("1", projektID);
using (var reader = await cmd.ExecuteReaderAsync())
{
while (reader.Read())
{
Haltung adding = parseHaltung(reader);
result.Add(adding);
}
}
}
return result;
}
private Haltung parseHaltung(NpgsqlDataReader reader)
{
Haltung result = new Haltung()
{
ID = reader.GetInt32(0),
Guid = Guid.Parse(reader.GetString(1)),
Ref_Projekt_Guid = Guid.Parse(reader.GetString(2)),
Objektbezeichnung = reader.GetString(3),
Bewertungklasse = Convert.ToUInt32(reader.GetValue(4)),
};
return result;
}
public async Task<bool> InsertHaltungBulk(List<Haltung> haltungen)
{
foreach (var item in haltungen)
{
await Create(item);
}
return true;
}
}
}

View File

@@ -0,0 +1,75 @@
using dcnsanplanung.shared.Model;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.DAL.Services.PostgresqlData
{
public class LVDataService : PostgresqlDataService
{
public LVDataService(string connectionstring) : base(connectionstring, "leistungsverzeichnisposition")
{
}
public async Task<LeistungsverzeichnisPosition> Create(LeistungsverzeichnisPosition entity)
{
string command = "INSERT INTO " + tableName + " (guid, positionsnummer, titel, einheit) VALUES " +
"(@1,@2,@3,@4) RETURNING id";
using (var cmd = new NpgsqlCommand(command, conn))
{
cmd.Parameters.AddWithValue("1", entity.Guid.ToString());
cmd.Parameters.AddWithValue("2", entity.Positionsnummer);
cmd.Parameters.AddWithValue("3", entity.Titel);
cmd.Parameters.AddWithValue("4", entity.Einheit);
using var reader = await cmd.ExecuteReaderAsync();
reader.Read();
entity.ID = reader.GetInt32(0);
}
return entity;
}
public async Task<IEnumerable<LeistungsverzeichnisPosition>> GetAll()
{
List<LeistungsverzeichnisPosition> result = new List<LeistungsverzeichnisPosition>();
string command = "SELECT * FROM " + tableName + ";";
using (var cmd = new NpgsqlCommand(command, conn))
{
using (var reader = await cmd.ExecuteReaderAsync())
{
while (reader.Read())
{
LeistungsverzeichnisPosition adding = parsePosition(reader);
result.Add(adding);
}
}
}
return result;
}
private LeistungsverzeichnisPosition parsePosition(NpgsqlDataReader reader)
{
LeistungsverzeichnisPosition result = new LeistungsverzeichnisPosition()
{
ID = reader.GetInt32(0),
Guid = Guid.Parse(reader.GetString(1)),
Positionsnummer = reader.GetString(2),
Titel = reader.GetString(3),
Einheit = reader.GetString(4)
};
return result;
}
public async Task<bool> InsertLeistungsverzeichnisPositionBulk(List<LeistungsverzeichnisPosition> position)
{
foreach (var item in position)
{
await Create(item);
}
return true;
}
}
}

View File

@@ -0,0 +1,47 @@
using Npgsql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.DAL.Services.PostgresqlData
{
public class PostgresqlDataService : IDisposable
{
protected readonly string connString; // = "Host = localhost; Database = sanplaner; Username = dcnsanplaner; Password = sanplaner";
NpgsqlDataSource dataSource;
protected NpgsqlConnection? conn = null;
protected string tableName = "";
public PostgresqlDataService(string connectionstring, string tableName)
{
this.connString = connectionstring;
var dataSourceBuilder = new NpgsqlDataSourceBuilder(connString);
dataSource = dataSourceBuilder.Build();
conn = dataSource.OpenConnection();
this.tableName = string.Format("public.{0}", tableName);
}
public virtual async Task<bool> Delete(int id)
{
string command = $"DELETE " + tableName + " WHERE \"Id\" = @1";
await using (var cmd = new NpgsqlCommand(command, conn))
{
cmd.Parameters.AddWithValue("1", id);
int res = await cmd.ExecuteNonQueryAsync();
}
return true;
}
public void Dispose()
{
if (conn != null && conn.State == System.Data.ConnectionState.Open)
{
conn.Close();
conn.Dispose();
}
}
}
}

View File

@@ -0,0 +1,44 @@
using dcnsanplanung.shared.Model;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.DAL.Services.PostgresqlData
{
public class SchadenDataService : PostgresqlDataService
{
public SchadenDataService(string connectionstring) : base(connectionstring, "schaden")
{
}
public async Task<Schaden> Create(Schaden entity)
{
string command = "INSERT INTO " + tableName + " (guid, ref_haltung_guid, entfernung, kodierung, schadensklasse) VALUES " +
"(@1,@2,@3,@4,@5) RETURNING id";
using(var cmd = new NpgsqlCommand(command,conn))
{
cmd.Parameters.AddWithValue("1", entity.Guid.ToString());
cmd.Parameters.AddWithValue("2", entity.Ref_Haltung_Guid.ToString());
cmd.Parameters.AddWithValue("3", entity.Entfernung);
cmd.Parameters.AddWithValue("4", entity.Kodierung);
cmd.Parameters.AddWithValue("5", NpgsqlTypes.NpgsqlDbType.Oid, entity.Schadensklasse);
using var reader = await cmd.ExecuteReaderAsync();
reader.Read();
entity.ID = reader.GetInt32(0);
}
return entity;
}
public async Task<bool> InsertSchadenBulk(List<Schaden> schaden)
{
foreach(var item in schaden)
{
await Create(item);
}
return true;
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="7.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\dcnsanplanung.shared\dcnsanplanung.shared.csproj" />
<ProjectReference Include="..\Schnittstelle\Schnittstelle\Schnittstelle.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using dcnsanplanung.DAL.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.DAL.Helper.Tests
{
[TestClass()]
public class WriteToDatabaseTests
{
[TestMethod()]
public void WriteToDatabaseTest()
{
WriteToDatabase writeToDatabase = new WriteToDatabase(@"C:\Users\damia\source\repos\dcnsanplanung\test_code.xml");
}
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\dcnsanplanung.DAL\dcnsanplanung.DAL.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Helper
{
public class ImportLVToSoftware
{
public List<Model.LeistungsverzeichnisPosition> LVPositionen = new List<Model.LeistungsverzeichnisPosition>();
public ImportLVToSoftware(string XMLFile)
{
ReadSchnittstelle(XMLFile);
}
private void ReadSchnittstelle(string xMLFile)
{
foreach(Schnittstelle.Import.LV.Model.LVPosition src_lv in new Schnittstelle.Import.LV.X81(xMLFile).ExportedLVPosition)
{
LVPositionen.Add(new Model.LeistungsverzeichnisPosition()
{
Guid = Guid.NewGuid(),
Einheit = src_lv.Einheit,
Titel = src_lv.Title,
Positionsnummer = src_lv.Positionsnummer,
});
}
}
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Helper
{
public class ImportToSoftware
{
public List<Model.Haltung> haltungen = new List<Model.Haltung>();
public ImportToSoftware(string XMLFile)
{
ReadSchnittstelle(XMLFile);
}
private void ReadSchnittstelle(string XMLFile)
{
List<Schnittstelle.Import.XML.v2013.Model.KanalObjekt> source_KanalObjekt = new Schnittstelle.Import.XML.v2013.XML2013(XMLFile).KanalObjekte.FindAll(x => x.Inspektionsdaten.Anlagentyp == Schnittstelle.Import.XML.v2013.Model.EAnlagetyp.Haltung);
//List<Model.Haltung> haltungen = new List<Model.Haltung>();
foreach (Schnittstelle.Import.XML.v2013.Model.KanalObjekt src in source_KanalObjekt)
{
Model.Haltung haltung = new Model.Haltung();
haltung.Guid = Guid.NewGuid();
haltung.Objektbezeichnung = src.Stammdaten.Objektbezeichnung;
haltung.Bewertungklasse = src.Inspektionsdaten.OptischeInspektion.Rohrleitung.Bewertung == null ? 6 : src.Inspektionsdaten.OptischeInspektion.Rohrleitung.Bewertung.KlasseAutomatisch;
List<Model.Schaden> kodierungen = new List<Model.Schaden>();
foreach (Schnittstelle.Import.XML.v2013.Model.RZustand src_kodierung in src.Inspektionsdaten.OptischeInspektion.Rohrleitung.Zustaende)
{
Model.Schaden kodierung = new Model.Schaden();
kodierung.Guid = Guid.NewGuid();
kodierung.Ref_Haltung_Guid = haltung.Guid;
kodierung.Entfernung = src_kodierung.Station;
kodierung.Kodierung = string.Format("{0}#{1}#{2}#{3}", src_kodierung.Inspektionskode ,src_kodierung.Charakterisierung1 , src_kodierung.Charakterisierung2 , src_kodierung.Quantifizierung1);
kodierung.Schadensklasse = src_kodierung.Klassifizierung == null ? 6 : src_kodierung.Klassifizierung.MaxSKeAuto;
kodierungen.Add(kodierung);
}
haltung.Kodierungen = kodierungen;
haltungen.Add(haltung);
}
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Model
{
public class DBObjekt
{
public int ID { get; set; }
public Guid Guid { get; set; }
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Model
{
public class Haltung : DBObjekt
{
public Guid Ref_Projekt_Guid;
public string Objektbezeichnung { get; set; } = "";
public uint Bewertungklasse { get; set; }
public List<Schaden> Kodierungen = new List<Schaden>();
}
public class Schaden : DBObjekt
{
public Guid Ref_Haltung_Guid;
public decimal Entfernung;
public string Kodierung = "";
public uint Schadensklasse;
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Model
{
public class LeistungsverzeichnisPosition : DBObjekt
{
public string Positionsnummer { get; set; } = "";
public string Titel { get; set; } = "";
public string Einheit { get; set; } = "";
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Model
{
public class Projekt : DBObjekt
{
public List<Haltung> Haltungen = new List<Haltung>();
}
}

View File

@@ -6,4 +6,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Schnittstelle\Schnittstelle\Schnittstelle.csproj" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using dcnsanplanung.shared.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.shared.Helper.Tests
{
[TestClass()]
public class ImportToSoftwareTests
{
[TestMethod()]
public void ImportToSoftwareTest()
{
ImportToSoftware importToSoftware = new ImportToSoftware(@"C:\Users\damia\source\repos\dcnsanplanung\test_code.xml");
}
}
}

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\dcnsanplanung.shared\dcnsanplanung.shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -3,7 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505 VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dcnsanplanung.wpf", "dcnsanplanung.wpf\dcnsanplanung.wpf.csproj", "{B0DDBF77-B592-4485-8705-E0B3AABBF171}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dcnsanplanung.wpf", "dcnsanplanung.wpf\dcnsanplanung.wpf.csproj", "{B0DDBF77-B592-4485-8705-E0B3AABBF171}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dcnsanplanung.shared", "dcnsanplanung.shared\dcnsanplanung.shared.csproj", "{AC43208D-6A5B-4A62-B8DE-DAE110C6CAFC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Schnittstelle", "Schnittstelle\Schnittstelle\Schnittstelle.csproj", "{3CD21512-6B4B-4590-A00E-36E40B791940}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dcnsanplanung.DAL", "dcnsanplanung.DAL\dcnsanplanung.DAL.csproj", "{FA2F4994-301B-4C11-8F44-585D4B726B97}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dcnsanplanung.sharedTests", "dcnsanplanung.sharedTests\dcnsanplanung.sharedTests.csproj", "{BD28F6AD-DA89-4BC7-A82D-7E28BB00E0EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dcnsanplanung.DALTests", "dcnsanplanung.DALTests\dcnsanplanung.DALTests.csproj", "{91A48C89-5E1F-4C70-B995-A2AC9459E6C1}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +25,26 @@ Global
{B0DDBF77-B592-4485-8705-E0B3AABBF171}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0DDBF77-B592-4485-8705-E0B3AABBF171}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0DDBF77-B592-4485-8705-E0B3AABBF171}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0DDBF77-B592-4485-8705-E0B3AABBF171}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0DDBF77-B592-4485-8705-E0B3AABBF171}.Release|Any CPU.Build.0 = Release|Any CPU {B0DDBF77-B592-4485-8705-E0B3AABBF171}.Release|Any CPU.Build.0 = Release|Any CPU
{AC43208D-6A5B-4A62-B8DE-DAE110C6CAFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC43208D-6A5B-4A62-B8DE-DAE110C6CAFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC43208D-6A5B-4A62-B8DE-DAE110C6CAFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC43208D-6A5B-4A62-B8DE-DAE110C6CAFC}.Release|Any CPU.Build.0 = Release|Any CPU
{3CD21512-6B4B-4590-A00E-36E40B791940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3CD21512-6B4B-4590-A00E-36E40B791940}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3CD21512-6B4B-4590-A00E-36E40B791940}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3CD21512-6B4B-4590-A00E-36E40B791940}.Release|Any CPU.Build.0 = Release|Any CPU
{FA2F4994-301B-4C11-8F44-585D4B726B97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA2F4994-301B-4C11-8F44-585D4B726B97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA2F4994-301B-4C11-8F44-585D4B726B97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA2F4994-301B-4C11-8F44-585D4B726B97}.Release|Any CPU.Build.0 = Release|Any CPU
{BD28F6AD-DA89-4BC7-A82D-7E28BB00E0EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD28F6AD-DA89-4BC7-A82D-7E28BB00E0EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD28F6AD-DA89-4BC7-A82D-7E28BB00E0EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD28F6AD-DA89-4BC7-A82D-7E28BB00E0EB}.Release|Any CPU.Build.0 = Release|Any CPU
{91A48C89-5E1F-4C70-B995-A2AC9459E6C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91A48C89-5E1F-4C70-B995-A2AC9459E6C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91A48C89-5E1F-4C70-B995-A2AC9459E6C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91A48C89-5E1F-4C70-B995-A2AC9459E6C1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -13,5 +13,30 @@ namespace dcnsanplanung.wpf
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
protected override void OnStartup(StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
base.OnStartup(e);
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = (Exception)e.ExceptionObject;
string text = "An application error occured. Plrease contact the Administrator with the following information:\n\n";
MessageBox.Show(text + " " + ex.Message + "\n\n" + ex.StackTrace);
}
catch (Exception ex2)
{
MessageBox.Show("Fatal Non-UI error", ex2.Message, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
throw new NotImplementedException();
}
} }
} }

View File

@@ -5,8 +5,23 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:dcnsanplanung.wpf" xmlns:local="clr-namespace:dcnsanplanung.wpf"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
<Grid> <Grid>
<StackPanel>
<ComboBox Name="Items" SelectionChanged="Items_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Objektbezeichnung}" />
<TextBlock Text=" | " />
<TextBlock Text="{Binding Bewertungklasse}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Name="LoadXML" Click="LoadXML_Click" Content="LoadXML" />
</StackPanel>
</Grid> </Grid>
</Window> </Window>

View File

@@ -1,4 +1,6 @@
using System; using dcnsanplanung.shared.Model;
using Schnittstelle.Import.XML.v2013.Model;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -24,5 +26,33 @@ namespace dcnsanplanung.wpf
{ {
InitializeComponent(); InitializeComponent();
} }
private async void LoadXML_Click(object sender, RoutedEventArgs e)
{
DAL.Helper.WriteToDatabase writer = new DAL.Helper.WriteToDatabase(@"C:\Users\damia\source\repos\dcnsanplanung\test_code.xml");
//await writer.WriteInHaltung();
await writer.WriteInLV();
}
private void Items_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Haltung? selectedItem = Items.SelectedItem as Haltung;
if (selectedItem == null) return;
W_ObjektView w_ObjektView = new W_ObjektView(selectedItem);
w_ObjektView.ShowDialog();
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
//
DAL.Services.PostgresqlData.HaltungDataService haltungsdataservice = new DAL.Services.PostgresqlData.HaltungDataService("Host = localhost; Database = sanplaner; Username = dcnsanplaner; Password = sanplaner");
var s = await haltungsdataservice.GetAllByProjekt(0);
foreach(var item in s)
{
Items.Items.Add(item);
}
}
} }
} }

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace dcnsanplanung.wpf.ViewModel
{
internal class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if(PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}

View File

@@ -0,0 +1,13 @@
<Window x:Class="dcnsanplanung.wpf.W_ObjektView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:dcnsanplanung.wpf"
mc:Ignorable="d"
Title="W_ObjektView" Height="450" Width="800">
<Grid>
<Label Name="Schadensklasse" />
</Grid>
</Window>

View File

@@ -0,0 +1,31 @@
using dcnsanplanung.shared.Model;
using Schnittstelle.Import.XML.v2013.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace dcnsanplanung.wpf
{
/// <summary>
/// Interaktionslogik für W_ObjektView.xaml
/// </summary>
public partial class W_ObjektView : Window
{
public W_ObjektView(Haltung haltung)
{
InitializeComponent();
Schadensklasse.Content = haltung.Bewertungklasse;
}
}
}

View File

@@ -7,4 +7,10 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\dcnsanplanung.DAL\dcnsanplanung.DAL.csproj" />
<ProjectReference Include="..\dcnsanplanung.shared\dcnsanplanung.shared.csproj" />
<ProjectReference Include="..\Schnittstelle\Schnittstelle\Schnittstelle.csproj" />
</ItemGroup>
</Project> </Project>