Add adding and detail

This commit is contained in:
2026-02-10 15:12:01 +01:00
parent ad447d109f
commit d6ae47d23d
13 changed files with 491 additions and 40 deletions

View File

@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:dealer"
StartupUri="MainWindow.xaml">
StartupUri="windows/MainWindow.xaml">
<Application.Resources>
</Application.Resources>

View File

@@ -1,14 +1,12 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace dealer
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : System.Windows.Application
{
}
}

47
dealer/DataManager.cs Normal file
View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dealer
{
public class DataManager
{
private List<Vehicle> vehicles = new List<Vehicle>();
public void AddVehicle(Vehicle vehicle)
{
vehicles.Add(vehicle);
}
public IEnumerable<Vehicle> GetAllVehicles()
{
return vehicles;
}
public void RemoveVehicle(Vehicle vehicle)
{
vehicles.Remove(vehicle);
}
public void Save()
{
// Implementace ukládání dat do souboru - JSON
var json = System.Text.Json.JsonSerializer.Serialize(vehicles);
System.IO.File.WriteAllText("vehicles.json", json);
}
public void Load()
{
string path = "vehicles.json";
// Implementace načítání dat ze souboru - JSON
if (System.IO.File.Exists(path))
{
var json = System.IO.File.ReadAllText(path);
vehicles = System.Text.Json.JsonSerializer.Deserialize<List<Vehicle>>(json) ?? new List<Vehicle>();
}
}
}
}

View File

@@ -1,12 +0,0 @@
<Window x:Class="dealer.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:dealer"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
</Grid>
</Window>

View File

@@ -1,24 +0,0 @@
using System.Text;
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.Navigation;
using System.Windows.Shapes;
namespace dealer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

19
dealer/Vehicle.cs Normal file
View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dealer
{
public class Vehicle
{
public string? Spz { get; set; }
public string? Model { get; set; }
public string? Barva { get; set; }
public int? RokVyroby { get; set; }
public int? NajeteKm { get; set; }
public decimal? Cena { get; set; }
public string? Fotografie { get; set; }
}
}

View File

@@ -6,6 +6,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,124 @@
<Window x:Class="dealer.AddVehicleWindow"
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:dealer"
mc:Ignorable="d"
Title="Pridat vozidlo" Height="550" Width="450"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
<StackPanel Margin="20">
<TextBlock Text="Nove vozidlo"
FontSize="20"
FontWeight="Bold"
Margin="0,0,0,20"
HorizontalAlignment="Center" />
<TextBlock Text="SPZ:" FontSize="14" Margin="0,5" />
<TextBox Name="SpzTextBox"
FontSize="14"
Padding="5"
MaxLength="10"
CharacterCasing="Upper"
Margin="0,0,0,10" />
<TextBlock Text="Model:" FontSize="14" Margin="0,5" />
<TextBox Name="ModelTextBox"
FontSize="14"
Padding="5"
Margin="0,0,0,10" />
<TextBlock Text="Barva:" FontSize="14" Margin="0,5" />
<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
<Border Name="ColorPreviewBorder"
Width="40"
Height="32"
BorderBrush="Gray"
BorderThickness="1"
Background="White"
Margin="0,0,10,0" />
<Button Name="SelectColorButton"
Content="Vybrat barvu"
Width="120"
Height="32"
Click="SelectColorButton_Click" />
<TextBlock Name="ColorNameTextBlock"
Text="Nevybrano"
VerticalAlignment="Center"
Margin="10,0,0,0"
FontStyle="Italic"
Foreground="Gray" />
</StackPanel>
<TextBlock Text="Rok vyroby:" FontSize="14" Margin="0,5" />
<TextBox Name="YearTextBox"
FontSize="14"
Padding="5"
MaxLength="4"
PreviewTextInput="NumericOnly_PreviewTextInput"
Margin="0,0,0,10" />
<TextBlock Text="Najete km:" FontSize="14" Margin="0,5" />
<TextBox Name="MileageTextBox"
FontSize="14"
Padding="5"
PreviewTextInput="NumericOnly_PreviewTextInput"
Margin="0,0,0,10" />
<TextBlock Text="Cena (Kc):" FontSize="14" Margin="0,5" />
<TextBox Name="PriceTextBox"
FontSize="14"
Padding="5"
PreviewTextInput="DecimalOnly_PreviewTextInput"
Margin="0,0,0,10" />
<TextBlock Text="Fotografie:" FontSize="14" Margin="0,15,0,5" />
<Button Name="SelectPhotoButton"
Content="Vybrat fotografii"
Width="150"
Height="30"
HorizontalAlignment="Left"
Margin="0,0,0,5"
Click="SelectPhotoButton_Click" />
<TextBlock Name="PhotoPathTextBlock"
Text="Zadna fotografie nevybrana"
FontStyle="Italic"
Foreground="Gray"
Margin="0,0,0,10"
TextWrapping="Wrap" />
</StackPanel>
</ScrollViewer>
<Border Grid.Row="1"
BorderBrush="LightGray"
BorderThickness="0,1,0,0"
Background="WhiteSmoke">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
Margin="0,15">
<Button Name="SaveButton"
Content="Ulozit"
Width="100"
Height="35"
Margin="5"
FontSize="14"
Click="SaveButton_Click" />
<Button Name="CancelButton"
Content="Zrusit"
Width="100"
Height="35"
Margin="5"
FontSize="14"
Click="CancelButton_Click" />
</StackPanel>
</Border>
</Grid>
</Window>

View File

@@ -0,0 +1,106 @@
using Microsoft.Win32;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using WinForms = System.Windows.Forms;
namespace dealer
{
public partial class AddVehicleWindow : Window
{
public string? SelectedPhotoPath { get; private set; }
public System.Windows.Media.Color SelectedColor { get; private set; } = Colors.White;
private DataManager dataManager;
public AddVehicleWindow(DataManager dataManager)
{
InitializeComponent();
this.dataManager = dataManager;
}
private void SelectPhotoButton_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Title = "Vyberte fotografii vozidla",
Filter = "Obrazky|*.jpg;*.jpeg;*.png;*.bmp;*.gif|Vsechny soubory|*.*",
FilterIndex = 1
};
if (openFileDialog.ShowDialog() == true)
{
SelectedPhotoPath = openFileDialog.FileName;
PhotoPathTextBlock.Text = SelectedPhotoPath;
}
}
private void SelectColorButton_Click(object sender, RoutedEventArgs e)
{
WinForms.ColorDialog colorDialog = new WinForms.ColorDialog
{
AllowFullOpen = true,
FullOpen = true
};
if (colorDialog.ShowDialog() == WinForms.DialogResult.OK)
{
SelectedColor = System.Windows.Media.Color.FromArgb(
colorDialog.Color.A,
colorDialog.Color.R,
colorDialog.Color.G,
colorDialog.Color.B);
ColorPreviewBorder.Background = new SolidColorBrush(SelectedColor);
ColorNameTextBlock.Text = $"#{SelectedColor.R:X2}{SelectedColor.G:X2}{SelectedColor.B:X2}";
ColorNameTextBlock.FontStyle = FontStyles.Normal;
ColorNameTextBlock.Foreground = System.Windows.Media.Brushes.Black;
}
}
private void NumericOnly_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
e.Handled = !int.TryParse(e.Text, out _);
}
private void DecimalOnly_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
var textBox = sender as System.Windows.Controls.TextBox;
string newText = textBox?.Text.Insert(textBox.SelectionStart, e.Text) ?? e.Text;
e.Handled = !decimal.TryParse(newText, out _);
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string? base64Image = null;
if (!string.IsNullOrEmpty(SelectedPhotoPath) && File.Exists(SelectedPhotoPath))
{
byte[] imageBytes = File.ReadAllBytes(SelectedPhotoPath);
base64Image = Convert.ToBase64String(imageBytes);
}
var vehicle = new Vehicle
{
Spz = SpzTextBox.Text,
Model = ModelTextBox.Text,
Barva = $"#{SelectedColor.R:X2}{SelectedColor.G:X2}{SelectedColor.B:X2}",
RokVyroby = int.TryParse(YearTextBox.Text, out int rok) ? rok : (int?)null,
NajeteKm = int.TryParse(MileageTextBox.Text, out int km) ? km : (int?)null,
Cena = decimal.TryParse(PriceTextBox.Text, out decimal cena) ? cena : (decimal?)null,
Fotografie = base64Image
};
this.dataManager.AddVehicle(vehicle);
this.dataManager.Save();
this.Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

View File

@@ -0,0 +1,78 @@
<Window x:Class="dealer.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:dealer"
mc:Ignorable="d"
Title="Evidence vozidel - Autobazar" Height="450" Width="800">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Nadpis -->
<TextBlock Grid.Row="0"
Text="Evidence vozidel"
FontSize="24"
FontWeight="Bold"
Margin="0,0,0,10"
HorizontalAlignment="Center" />
<!-- ListView s vozidly -->
<ListView Grid.Row="1"
Name="VehiclesListView"
Margin="0,0,0,10">
<ListView.View>
<GridView>
<GridViewColumn Header="SPZ" Width="150" DisplayMemberBinding="{Binding Spz}" />
<GridViewColumn Header="Model" Width="250"
DisplayMemberBinding="{Binding Model}" />
<GridViewColumn Header="Barva" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Border Width="20" Height="20" BorderBrush="Gray" BorderThickness="1" Margin="0,0,8,0">
<Border.Background>
<SolidColorBrush Color="{Binding Barva}" />
</Border.Background>
</Border>
<TextBlock Text="{Binding Barva}" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<!-- Tlačítka -->
<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center">
<Button Name="AddButton"
Content="Přidat vozidlo"
Width="120"
Height="35"
Margin="5"
FontSize="14"
Click="AddButton_Click" />
<Button Name="EditButton"
Content="Upravit"
Width="120"
Height="35"
Margin="5"
FontSize="14"
Click="EditButton_Click" />
<Button Name="DeleteButton"
Content="Smazat"
Width="120"
Height="35"
Margin="5"
FontSize="14"
Click="DeleteButton_Click" />
</StackPanel>
</Grid>
</Window>

View File

@@ -0,0 +1,46 @@
using System.Text;
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.Navigation;
using System.Windows.Shapes;
namespace dealer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private DataManager dataManager = new DataManager();
public MainWindow()
{
InitializeComponent();
this.dataManager.Load();
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
}
private void AddButton_Click(object sender, RoutedEventArgs e)
{
var window = new AddVehicleWindow(this.dataManager);
window.ShowDialog();
}
private void EditButton_Click(object sender, RoutedEventArgs e)
{
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
}
}
}