Initial commit
This commit is contained in:
8
FahrzeugProjekt/App.xaml
Normal file
8
FahrzeugProjekt/App.xaml
Normal file
@@ -0,0 +1,8 @@
|
||||
<Application x:Class="FahrzeugProjekt.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:FahrzeugProjekt">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
45
FahrzeugProjekt/App.xaml.cs
Normal file
45
FahrzeugProjekt/App.xaml.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
public static IServiceProvider ServiceProvider { get; private set; }
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
// Configuration laden
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
IConfiguration configuration = builder.Build();
|
||||
|
||||
string connectionString = configuration.GetConnectionString("FahrzeugProjektConnection");
|
||||
|
||||
// Services konfigurieren
|
||||
var services = new ServiceCollection();
|
||||
|
||||
// DbContext registrieren
|
||||
services.AddDbContext<FahrzeugProjektKontext>(options =>
|
||||
options.UseSqlServer(connectionString));
|
||||
|
||||
// Alle Fenster registrieren
|
||||
services.AddTransient<MainWindow>();
|
||||
services.AddTransient<FahrzeugEintragenWindow>();
|
||||
services.AddTransient<FahrzeugeAnzeigenWindow>();
|
||||
|
||||
// Service Provider erstellen
|
||||
ServiceProvider = services.BuildServiceProvider();
|
||||
|
||||
// MainWindow manuell erstellen und anzeigen
|
||||
var hauptFenster = ServiceProvider.GetRequiredService<MainWindow>();
|
||||
hauptFenster.Show();
|
||||
}
|
||||
}
|
||||
}
|
23
FahrzeugProjekt/Arbeiter.cs
Normal file
23
FahrzeugProjekt/Arbeiter.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
public class Arbeiter
|
||||
{
|
||||
[Column("ArbeiterID")]
|
||||
public int ArbeiterID { get; set; }
|
||||
|
||||
[Column("Vorname")]
|
||||
public string Vorname { get; set; }
|
||||
|
||||
[Column("Nachname")]
|
||||
public string Nachname { get; set; }
|
||||
|
||||
[Column("Email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Column("Passwort")]
|
||||
public string Passwort { get; set; }
|
||||
}
|
||||
}
|
10
FahrzeugProjekt/AssemblyInfo.cs
Normal file
10
FahrzeugProjekt/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
36
FahrzeugProjekt/Fahrzeug.cs
Normal file
36
FahrzeugProjekt/Fahrzeug.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
[Table("Fahrzeuge")]
|
||||
public class Fahrzeug
|
||||
{
|
||||
[Column("FahrzeugID")]
|
||||
public int FahrzeugID { get; set; }
|
||||
|
||||
[Column("ModellID")]
|
||||
public int ModellID { get; set; }
|
||||
|
||||
public Modell Modell { get; set; }
|
||||
|
||||
[Column("Getriebe")]
|
||||
public string Getriebe { get; set; }
|
||||
|
||||
[Column("Kraftstoff")]
|
||||
public string Kraftstoff { get; set; }
|
||||
|
||||
[Column("Baujahr")]
|
||||
public int Baujahr { get; set; }
|
||||
|
||||
[Column("Farbe")]
|
||||
public string Farbe { get; set; }
|
||||
|
||||
[Column("Kilometerstand")]
|
||||
public int Kilometerstand { get; set; }
|
||||
|
||||
[Column("Beschreibung")]
|
||||
public string Beschreibung { get; set; }
|
||||
}
|
||||
|
||||
}
|
95
FahrzeugProjekt/FahrzeugAnzeigenWindow.xaml
Normal file
95
FahrzeugProjekt/FahrzeugAnzeigenWindow.xaml
Normal file
@@ -0,0 +1,95 @@
|
||||
<Window x:Class="FahrzeugProjekt.FahrzeugeAnzeigenWindow"
|
||||
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:FahrzeugProjekt"
|
||||
mc:Ignorable="d"
|
||||
Title="Fahrzeuge Anzeigen" Height="700" Width="900"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Grid Margin="15">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Titel -->
|
||||
<TextBlock Grid.Row="0" Text="Alle Fahrzeuge"
|
||||
FontSize="20" FontWeight="Bold"
|
||||
HorizontalAlignment="Center" Margin="0,0,0,20"/>
|
||||
|
||||
<!-- Filters -->
|
||||
<GroupBox Grid.Row="1" Header="Filter" Margin="0,0,0,15">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Filters -->
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="0,0,0,10">
|
||||
<Label Content="Marke:" VerticalAlignment="Center" Width="60"/>
|
||||
<ComboBox Name="cmbFilterMarke" Width="130" Height="25" Margin="5,0,15,0"/>
|
||||
|
||||
<Label Content="Modell:" VerticalAlignment="Center" Width="60"/>
|
||||
<ComboBox Name="cmbFilterModell" Width="130" Height="25" Margin="5,0,15,0"/>
|
||||
|
||||
<Label Content="Kraftstoff:" VerticalAlignment="Center" Width="70"/>
|
||||
<ComboBox Name="cmbFilterKraftstoff" Width="100" Height="25" Margin="5,0,15,0"/>
|
||||
|
||||
<Label Content="Getriebe:" VerticalAlignment="Center" Width="60"/>
|
||||
<ComboBox Name="cmbFilterGetriebe" Width="130" Height="25" Margin="5,0,15,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Action knöpfe -->
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Name="kofAktuali" Content="Filter Anwenden"
|
||||
Width="120" Height="25" Margin="5,0"
|
||||
Click="Aktualisieren"/>
|
||||
<Button Name="FilZurücksetze" Content="Filter Zurücksetzen"
|
||||
Width="130" Height="25" Margin="5,0"
|
||||
Click="Zurücksetzen"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
<!-- Fahrzeuge Liste -->
|
||||
<DataGrid Grid.Row="2" Name="dgFahrzeuge"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="True"
|
||||
CanUserResizeColumns="True"
|
||||
CanUserSortColumns="False"
|
||||
GridLinesVisibility="Horizontal"
|
||||
AlternatingRowBackground="LightGray">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="ID" Binding="{Binding FahrzeugID}" Width="50"/>
|
||||
<DataGridTextColumn Header="Marke" Binding="{Binding Modell.Marke.Markenname}" Width="100"/>
|
||||
<DataGridTextColumn Header="Modell" Binding="{Binding Modell.Modellname}" Width="120"/>
|
||||
<DataGridTextColumn Header="Getriebe" Binding="{Binding Getriebe}" Width="100"/>
|
||||
<DataGridTextColumn Header="Kraftstoff" Binding="{Binding Kraftstoff}" Width="100"/>
|
||||
<DataGridTextColumn Header="Baujahr" Binding="{Binding Baujahr}" Width="80"/>
|
||||
<DataGridTextColumn Header="Farbe" Binding="{Binding Farbe}" Width="80"/>
|
||||
<DataGridTextColumn Header="Kilometer" Binding="{Binding Kilometerstand}" Width="100"/>
|
||||
<DataGridTextColumn Header="Beschreibung" Binding="{Binding Beschreibung}" Width="*"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<!-- Schließen knopf -->
|
||||
<!-- PDF -->
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal"
|
||||
HorizontalAlignment="Center" Margin="0,15,0,0">
|
||||
<Label Content="Fahrzeug ID:" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||
<TextBox Name="txtFahrzeugID" Width="80" Height="25" Margin="0,0,10,0"/>
|
||||
<Button Name="PDFErstellen" Content="PDF Erstellen"
|
||||
Width="100" Height="25" Margin="0,0,20,0"
|
||||
Click="Erstellen"/>
|
||||
<Button Name="kpfsch" Content="Schließen"
|
||||
Width="120" Height="35"
|
||||
Click="Schließ"/>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
215
FahrzeugProjekt/FahrzeugAnzeigenWindow.xaml.cs
Normal file
215
FahrzeugProjekt/FahrzeugAnzeigenWindow.xaml.cs
Normal file
@@ -0,0 +1,215 @@
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Win32;
|
||||
using PdfSharp.Drawing;
|
||||
using PdfSharp.Fonts;
|
||||
using PdfSharp.Pdf;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
public partial class FahrzeugeAnzeigenWindow : Window
|
||||
{
|
||||
private FahrzeugProjektKontext Kontext;
|
||||
private List<Fahrzeug> alleFahrzeuge;
|
||||
public MainWindow main { get; set; }
|
||||
|
||||
public FahrzeugeAnzeigenWindow(FahrzeugProjektKontext dbKontext)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.WindowState = WindowState.Maximized;
|
||||
Kontext = dbKontext;
|
||||
|
||||
// font resolver
|
||||
GlobalFontSettings.FontResolver = new SimpleFontResolver();
|
||||
|
||||
|
||||
this.Loaded += (sender, e) =>
|
||||
{
|
||||
FahrzeugeDatenLaden();
|
||||
Vorbereitung();
|
||||
};
|
||||
}
|
||||
|
||||
private void FahrzeugeDatenLaden()
|
||||
{
|
||||
alleFahrzeuge = Kontext.Fahrzeuge
|
||||
.Include(f => f.Modell)
|
||||
.ThenInclude(m => m.Marke)
|
||||
.ToList();
|
||||
|
||||
dgFahrzeuge.ItemsSource = alleFahrzeuge;
|
||||
}
|
||||
|
||||
private void Vorbereitung()
|
||||
{
|
||||
// Marken für Filter laden
|
||||
List<Marke> markenFürFilter = new List<Marke> { new Marke { MarkeID = -1, Markenname = "Alle Marken" } };
|
||||
List<Marke> alleMarken = Kontext.Marken.ToList();
|
||||
markenFürFilter.AddRange(alleMarken);
|
||||
cmbFilterMarke.ItemsSource = markenFürFilter;
|
||||
cmbFilterMarke.DisplayMemberPath = "Markenname";
|
||||
cmbFilterMarke.SelectedIndex = 0;
|
||||
|
||||
// Alle Modelle für Filter laden
|
||||
List<Modell> modelleFürFilter = new List<Modell> { new Modell { ModellID = -1, Modellname = "Alle Modelle" } };
|
||||
List<Modell> alleModelle = Kontext.Modelle.ToList();
|
||||
modelleFürFilter.AddRange(alleModelle);
|
||||
cmbFilterModell.ItemsSource = modelleFürFilter;
|
||||
cmbFilterModell.DisplayMemberPath = "Modellname";
|
||||
cmbFilterModell.SelectedIndex = 0;
|
||||
|
||||
// Kraftstoffe für Filter
|
||||
List<string> kraftstoffListe = new List<string> { "Alle", "Benzin", "Diesel", "Elektro", "Hybrid" };
|
||||
cmbFilterKraftstoff.ItemsSource = kraftstoffListe;
|
||||
cmbFilterKraftstoff.SelectedIndex = 0;
|
||||
|
||||
// Getriebe für Filter
|
||||
List<string> getriebeListe = new List<string> { "Alle", "Manuell", "Automatik", "Halbautomatik" };
|
||||
cmbFilterGetriebe.ItemsSource = getriebeListe;
|
||||
cmbFilterGetriebe.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private void Erstellen(object sender, RoutedEventArgs e)
|
||||
{
|
||||
int fahrzeugID = int.Parse(txtFahrzeugID.Text);
|
||||
|
||||
Fahrzeug fahrzeug = alleFahrzeuge.FirstOrDefault(f => f.FahrzeugID == fahrzeugID);
|
||||
|
||||
SaveFileDialog saveDialog = new SaveFileDialog
|
||||
{
|
||||
FileName = $"{fahrzeug.FahrzeugID}.pdf"
|
||||
};
|
||||
|
||||
if (saveDialog.ShowDialog() == true)
|
||||
{
|
||||
CreateVehiclePDF(fahrzeug, saveDialog.FileName);
|
||||
MessageBox.Show("PDF erfolgreich erstellt!");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateVehiclePDF(Fahrzeug fahrzeug, string filePath)
|
||||
{
|
||||
// PDF erstellen
|
||||
PdfDocument document = new PdfDocument();
|
||||
PdfPage page = document.AddPage();
|
||||
XGraphics gfx = XGraphics.FromPdfPage(page);
|
||||
XFont font = new XFont("Arial", 12);
|
||||
XFont titleFont = new XFont("Arial", 16);
|
||||
|
||||
// start pos
|
||||
double yPos = 50;
|
||||
double lineHeight = 25;
|
||||
|
||||
// Title
|
||||
gfx.DrawString("Fahrzeug Information", titleFont, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight * 2;
|
||||
|
||||
// Vehicle details
|
||||
gfx.DrawString($"Fahrzeug ID: {fahrzeug.FahrzeugID}", font, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight;
|
||||
|
||||
gfx.DrawString($"Marke: {fahrzeug.Modell?.Marke?.Markenname ?? "N/A"}", font, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight;
|
||||
|
||||
gfx.DrawString($"Modell: {fahrzeug.Modell?.Modellname ?? "N/A"}", font, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight;
|
||||
|
||||
gfx.DrawString($"Baujahr: {fahrzeug.Baujahr}", font, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight;
|
||||
|
||||
gfx.DrawString($"Kraftstoff: {fahrzeug.Kraftstoff ?? "N/A"}", font, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight;
|
||||
|
||||
gfx.DrawString($"Getriebe: {fahrzeug.Getriebe ?? "N/A"}", font, XBrushes.Black, 50, yPos);
|
||||
yPos += lineHeight;
|
||||
|
||||
gfx.DrawString($"Kilometerstand: {fahrzeug.Kilometerstand} km", font, XBrushes.Black, 50, yPos);
|
||||
|
||||
// Save
|
||||
document.Save(filePath);
|
||||
document.Close();
|
||||
}
|
||||
|
||||
private void Aktualisieren(object sender, RoutedEventArgs e)
|
||||
{
|
||||
List<Fahrzeug> ergebnisse = alleFahrzeuge.ToList();
|
||||
|
||||
// Marken Filter
|
||||
Marke ausgewählteMarke = cmbFilterMarke.SelectedItem as Marke;
|
||||
if (ausgewählteMarke.MarkeID != -1)
|
||||
{
|
||||
ergebnisse = ergebnisse
|
||||
.Where(f => f.Modell.MarkeID == ausgewählteMarke.MarkeID)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Modell Filter
|
||||
Modell ausgewähltesModell = cmbFilterModell.SelectedItem as Modell;
|
||||
if (ausgewähltesModell.ModellID != -1)
|
||||
{
|
||||
ergebnisse = ergebnisse
|
||||
.Where(f => f.ModellID == ausgewähltesModell.ModellID)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Kraftstoff Filter
|
||||
if (cmbFilterKraftstoff.SelectedItem.ToString() != "Alle")
|
||||
{
|
||||
string ausgewählterKraftstoff = cmbFilterKraftstoff.SelectedItem.ToString();
|
||||
ergebnisse = ergebnisse
|
||||
.Where(f => f.Kraftstoff == ausgewählterKraftstoff)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Getriebe Filter
|
||||
if (cmbFilterGetriebe.SelectedItem.ToString() != "Alle")
|
||||
{
|
||||
string ausgewähltesGetriebe = cmbFilterGetriebe.SelectedItem.ToString();
|
||||
ergebnisse = ergebnisse
|
||||
.Where(f => f.Getriebe == ausgewähltesGetriebe)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
dgFahrzeuge.ItemsSource = ergebnisse;
|
||||
this.Title = $"Fahrzeuge Anzeigen ({ergebnisse.Count} von {alleFahrzeuge.Count})";
|
||||
}
|
||||
|
||||
private void Zurücksetzen(object sender, RoutedEventArgs e)
|
||||
{
|
||||
cmbFilterMarke.SelectedIndex = 0;
|
||||
cmbFilterModell.SelectedIndex = 0;
|
||||
cmbFilterKraftstoff.SelectedIndex = 0;
|
||||
cmbFilterGetriebe.SelectedIndex = 0;
|
||||
|
||||
dgFahrzeuge.ItemsSource = alleFahrzeuge;
|
||||
this.Title = "Fahrzeuge Anzeigen";
|
||||
}
|
||||
|
||||
private void Schließ(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
main.Show();
|
||||
}
|
||||
}
|
||||
|
||||
// Font resolver
|
||||
public class SimpleFontResolver : IFontResolver
|
||||
{
|
||||
public FontResolverInfo ResolveTypeface(string familyName, bool isBold, bool isItalic)
|
||||
{
|
||||
return new FontResolverInfo("Arial");
|
||||
}
|
||||
|
||||
public byte[] GetFont(string faceName)
|
||||
{
|
||||
string windowsFontsPath = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Windows), "Fonts");
|
||||
string fontPath = Path.Combine(windowsFontsPath, "arial.ttf");
|
||||
|
||||
return File.ReadAllBytes(fontPath);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
68
FahrzeugProjekt/FahrzeugEintragenWindow.xaml
Normal file
68
FahrzeugProjekt/FahrzeugEintragenWindow.xaml
Normal file
@@ -0,0 +1,68 @@
|
||||
<Window x:Class="FahrzeugProjekt.FahrzeugEintragenWindow"
|
||||
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:FahrzeugProjekt"
|
||||
mc:Ignorable="d"
|
||||
Title="Neues Fahrzeug Eintragen" Height="600" Width="500"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<!-- Titel -->
|
||||
<TextBlock Grid.Row="0" Text="Neues Fahrzeug Hinzufügen"
|
||||
FontSize="20" FontWeight="Bold"
|
||||
HorizontalAlignment="Center" Margin="0,0,0,20"/>
|
||||
<!-- Eingabeformular -->
|
||||
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel>
|
||||
<!-- Modell auswählen -->
|
||||
<Label Content="Modell:" FontWeight="Bold"/>
|
||||
<ComboBox Name="cmbModell" Margin="0,0,0,10" Height="25"/>
|
||||
<!-- Getriebe -->
|
||||
<Label Content="Getriebe:" FontWeight="Bold"/>
|
||||
<ComboBox Name="cmbGetriebe" Margin="0,0,0,10" Height="25">
|
||||
<ComboBoxItem Content="Manuell"/>
|
||||
<ComboBoxItem Content="Automatik"/>
|
||||
<ComboBoxItem Content="Halbautomatik"/>
|
||||
</ComboBox>
|
||||
<!-- Kraftstoff -->
|
||||
<Label Content="Kraftstoff:" FontWeight="Bold"/>
|
||||
<ComboBox Name="cmbKraftstoff" Margin="0,0,0,10" Height="25">
|
||||
<ComboBoxItem Content="Benzin"/>
|
||||
<ComboBoxItem Content="Diesel"/>
|
||||
<ComboBoxItem Content="Elektro"/>
|
||||
<ComboBoxItem Content="Hybrid"/>
|
||||
</ComboBox>
|
||||
<!-- Baujahr -->
|
||||
<Label Content="Baujahr:" FontWeight="Bold"/>
|
||||
<TextBox Name="txtBaujahr" Margin="0,0,0,10" Height="25"/>
|
||||
<!-- Farbe -->
|
||||
<Label Content="Farbe:" FontWeight="Bold"/>
|
||||
<TextBox Name="txtFarbe" Margin="0,0,0,10" Height="25"/>
|
||||
<!-- Kilometerstand -->
|
||||
<Label Content="Kilometerstand:" FontWeight="Bold"/>
|
||||
<TextBox Name="txtKilometer" Margin="0,0,0,10" Height="25"/>
|
||||
<!-- Beschreibung -->
|
||||
<Label Content="Beschreibung:" FontWeight="Bold"/>
|
||||
<TextBox Name="txtBeschreibung" Margin="0,0,0,20" Height="80"
|
||||
TextWrapping="Wrap" AcceptsReturn="True"
|
||||
VerticalScrollBarVisibility="Auto"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
<!-- Buttons -->
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal"
|
||||
HorizontalAlignment="Center" Margin="0,20,0,0">
|
||||
<Button Name="kpfSpeichern" Content="Speichern"
|
||||
Width="100" Height="35" Margin="10,0"
|
||||
Click="Speichern"/>
|
||||
<Button Name="KpfAbbrechen" Content="Abbrechen"
|
||||
Width="100" Height="35" Margin="10,0"
|
||||
Click="Abbrechen"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
119
FahrzeugProjekt/FahrzeugEintragenWindow.xaml.cs
Normal file
119
FahrzeugProjekt/FahrzeugEintragenWindow.xaml.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
public partial class FahrzeugEintragenWindow : Window
|
||||
{
|
||||
private FahrzeugProjektKontext Kontext;
|
||||
bool idk;
|
||||
public MainWindow main { get; set; }
|
||||
|
||||
public FahrzeugEintragenWindow(FahrzeugProjektKontext dbKontext)
|
||||
{
|
||||
InitializeComponent();
|
||||
Kontext = dbKontext;
|
||||
DatenLaden();
|
||||
}
|
||||
|
||||
private void DatenLaden()
|
||||
{
|
||||
List<Modell> alleModelle = Kontext.Modelle.ToList();
|
||||
cmbModell.ItemsSource = alleModelle;
|
||||
cmbModell.DisplayMemberPath = "Modellname";
|
||||
}
|
||||
|
||||
private void Speichern(object sender, RoutedEventArgs e)
|
||||
{
|
||||
idk = EingabenValidieren();
|
||||
if (idk == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Modell ausgewähltesModell = cmbModell.SelectedItem as Modell;
|
||||
Fahrzeug neuesFahrzeug = new Fahrzeug
|
||||
{
|
||||
ModellID = ausgewähltesModell.ModellID,
|
||||
Getriebe = ((ComboBoxItem)cmbGetriebe.SelectedItem).Content.ToString(),
|
||||
Kraftstoff = ((ComboBoxItem)cmbKraftstoff.SelectedItem).Content.ToString(),
|
||||
Baujahr = int.Parse(txtBaujahr.Text),
|
||||
Farbe = txtFarbe.Text.Trim(),
|
||||
Kilometerstand = int.Parse(txtKilometer.Text),
|
||||
Beschreibung = txtBeschreibung.Text.Trim()
|
||||
};
|
||||
|
||||
Kontext.Fahrzeuge.Add(neuesFahrzeug);
|
||||
Kontext.SaveChanges();
|
||||
|
||||
MessageBox.Show("Fahrzeug erfolgreich gespeichert!");
|
||||
this.Close();
|
||||
main.Show();
|
||||
}
|
||||
|
||||
private bool EingabenValidieren()
|
||||
{
|
||||
if (cmbModell.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Bitte wählen Sie ein Modell aus!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cmbGetriebe.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Bitte wählen Sie ein Getriebe aus!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cmbKraftstoff.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Bitte wählen Sie einen Kraftstoff aus!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int baujahr = Convert.ToInt32(txtBaujahr.Text);
|
||||
if (baujahr < 1900)
|
||||
{
|
||||
MessageBox.Show("Bitte geben Sie ein gültiges Baujahr ein!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Bitte geben Sie ein gültiges Baujahr ein!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(txtFarbe.Text))
|
||||
{
|
||||
MessageBox.Show("Bitte geben Sie eine Farbe ein!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int km = Convert.ToInt32(txtKilometer.Text);
|
||||
if (km < 0)
|
||||
{
|
||||
MessageBox.Show("Bitte geben Sie einen gültigen Kilometerstand ein!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Bitte geben Sie einen gültigen Kilometerstand ein!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Abbrechen(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
main.Show();
|
||||
}
|
||||
}
|
||||
}
|
31
FahrzeugProjekt/FahrzeugProjekt.csproj
Normal file
31
FahrzeugProjekt/FahrzeugProjekt.csproj
Normal file
@@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.8" />
|
||||
<PackageReference Include="PDFsharp" Version="6.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="appsettings.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
38
FahrzeugProjekt/FahrzeugeProjektKontext.cs
Normal file
38
FahrzeugProjekt/FahrzeugeProjektKontext.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
public class FahrzeugProjektKontext : DbContext
|
||||
{
|
||||
public DbSet<Arbeiter> Arbeiter { get; set; }
|
||||
public DbSet<Ort> Orte { get; set; }
|
||||
public DbSet<Marke> Marken { get; set; }
|
||||
public DbSet<Modell> Modelle { get; set; }
|
||||
public DbSet<Fahrzeug> Fahrzeuge { get; set; }
|
||||
|
||||
public FahrzeugProjektKontext(DbContextOptions<FahrzeugProjektKontext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
modelBuilder.Entity<Marke>()
|
||||
.HasMany(m => m.Modelle)
|
||||
.WithOne(mo => mo.Marke)
|
||||
.HasForeignKey(mo => mo.MarkeID);
|
||||
|
||||
modelBuilder.Entity<Modell>()
|
||||
.HasMany(mo => mo.Fahrzeuge)
|
||||
.WithOne(f => f.Modell)
|
||||
.HasForeignKey(f => f.ModellID);
|
||||
}
|
||||
}
|
||||
}
|
43
FahrzeugProjekt/MainWindow.xaml
Normal file
43
FahrzeugProjekt/MainWindow.xaml
Normal file
@@ -0,0 +1,43 @@
|
||||
<Window x:Class="FahrzeugProjekt.MainWindow"
|
||||
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:FahrzeugProjekt"
|
||||
mc:Ignorable="d"
|
||||
Title="Fahrzeug Verwaltung" Height="450" Width="800"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Kopfzeile -->
|
||||
<TextBlock Grid.Row="0" Text="Fahrzeug Verwaltungssystem"
|
||||
FontSize="24" FontWeight="Bold"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="20"/>
|
||||
|
||||
<!-- main -->
|
||||
<StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="Wählen Sie eine Aktion:" FontSize="16"
|
||||
HorizontalAlignment="Center" Margin="0,0,0,30"/>
|
||||
|
||||
<Button Name="FahAnzeigen" Content="Fahrzeuge Anzeigen"
|
||||
Width="180" Height="50" Margin="10"
|
||||
FontSize="14" Click="Anzeigen"/>
|
||||
|
||||
<Button Name="FahEintragen" Content="Neues Fahrzeug Eintragen"
|
||||
Width="180" Height="50" Margin="10"
|
||||
FontSize="14" Click="Eintragen"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Fußzeile -->
|
||||
<TextBlock Grid.Row="2" Text="Firmen Fahrzeug Verwaltung"
|
||||
HorizontalAlignment="Center"
|
||||
Foreground="Gray" Margin="10"/>
|
||||
</Grid>
|
||||
</Window>
|
35
FahrzeugProjekt/MainWindow.xaml.cs
Normal file
35
FahrzeugProjekt/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Windows;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private IServiceProvider service;
|
||||
|
||||
public MainWindow(IServiceProvider serviceProvider)
|
||||
{
|
||||
InitializeComponent();
|
||||
service = serviceProvider; // Speichern für später
|
||||
}
|
||||
|
||||
private void Anzeigen(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Fenster von anzeigen öffnen
|
||||
FahrzeugeAnzeigenWindow fahrzeugeAnzeigenFenster = service.GetRequiredService<FahrzeugeAnzeigenWindow>();
|
||||
fahrzeugeAnzeigenFenster.main = this; // Referenz von MainWindow
|
||||
fahrzeugeAnzeigenFenster.Show();// Window zeigen
|
||||
this.Hide();//window verstecken
|
||||
|
||||
}
|
||||
|
||||
private void Eintragen(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Fenster von eintragen öffnen
|
||||
FahrzeugEintragenWindow fahrzeugEintragenFenster = service.GetRequiredService<FahrzeugEintragenWindow>();
|
||||
fahrzeugEintragenFenster.main = this;
|
||||
fahrzeugEintragenFenster.Show();
|
||||
this.Hide();
|
||||
}
|
||||
}
|
||||
}
|
19
FahrzeugProjekt/Marke.cs
Normal file
19
FahrzeugProjekt/Marke.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
[Table("Marken")]
|
||||
public class Marke
|
||||
{
|
||||
[Column("MarkenID")] // DB hat MarkenID, nicht MarkeID
|
||||
public int MarkeID { get; set; }
|
||||
|
||||
[Column("Name")] // DB hat Name, nicht Markenname
|
||||
public string Markenname { get; set; }
|
||||
|
||||
public ICollection<Modell> Modelle { get; set; }
|
||||
}
|
||||
|
||||
|
||||
}
|
22
FahrzeugProjekt/Modell.cs
Normal file
22
FahrzeugProjekt/Modell.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
[Table("Modelle")]
|
||||
public class Modell
|
||||
{
|
||||
[Column("ModellID")]
|
||||
public int ModellID { get; set; }
|
||||
|
||||
[Column("Name")] // DB hat Name, nicht Modellname
|
||||
public string Modellname { get; set; }
|
||||
|
||||
[Column("MarkenID")] // DB hat MarkenID, nicht MarkeID
|
||||
public int MarkeID { get; set; }
|
||||
|
||||
public Marke Marke { get; set; }
|
||||
public ICollection<Fahrzeug> Fahrzeuge { get; set; }
|
||||
}
|
||||
|
||||
}
|
18
FahrzeugProjekt/Ort.cs
Normal file
18
FahrzeugProjekt/Ort.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace FahrzeugProjekt
|
||||
{
|
||||
[Table("Orte")]
|
||||
public class Ort
|
||||
{
|
||||
[Column("OrtID")]
|
||||
public int OrtID { get; set; }
|
||||
|
||||
[Column("Stadt")] // DB hat Stadt, nicht Stadtname
|
||||
public string Stadtname { get; set; }
|
||||
|
||||
[Column("Land")] // Zusätzliche Spalte die du hast
|
||||
public string Land { get; set; }
|
||||
}
|
||||
}
|
5
FahrzeugProjekt/appsettings.json
Normal file
5
FahrzeugProjekt/appsettings.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"FahrzeugProjektConnection": "Server=NBSTUD;Database=FahrzeugProjekt;Trusted_Connection=True;TrustServerCertificate=True;"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user