Idk
This commit is contained in:
@@ -103,4 +103,4 @@ namespace dealer
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
130
dealer/windows/EditVehicleWindow.xaml
Normal file
130
dealer/windows/EditVehicleWindow.xaml
Normal file
@@ -0,0 +1,130 @@
|
||||
<Window x:Class="dealer.EditVehicleWindow"
|
||||
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="Upravit vozidlo" Height="600" 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="Upravit 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" />
|
||||
<Border Name="CurrentPhotoBorder" BorderBrush="Gray" BorderThickness="1" Margin="0,0,0,10" HorizontalAlignment="Left" Visibility="Collapsed">
|
||||
<Image Name="CurrentPhotoImage"
|
||||
Width="150"
|
||||
Height="100"
|
||||
Stretch="Uniform" />
|
||||
</Border>
|
||||
<Button Name="SelectPhotoButton"
|
||||
Content="Vybrat novou fotografii"
|
||||
Width="180"
|
||||
Height="30"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,0,0,5"
|
||||
Click="SelectPhotoButton_Click" />
|
||||
<TextBlock Name="PhotoPathTextBlock"
|
||||
Text="Zadna zmena fotografie"
|
||||
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>
|
||||
184
dealer/windows/EditVehicleWindow.xaml.cs
Normal file
184
dealer/windows/EditVehicleWindow.xaml.cs
Normal file
@@ -0,0 +1,184 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using WinForms = System.Windows.Forms;
|
||||
|
||||
namespace dealer
|
||||
{
|
||||
public partial class EditVehicleWindow : Window
|
||||
{
|
||||
public string? SelectedPhotoPath { get; private set; }
|
||||
public System.Windows.Media.Color SelectedColor { get; private set; } = Colors.White;
|
||||
public bool WasEdited { get; private set; } = false;
|
||||
|
||||
private DataManager dataManager;
|
||||
private Vehicle vehicle;
|
||||
private bool photoChanged = false;
|
||||
|
||||
public EditVehicleWindow(Vehicle vehicle, DataManager dataManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.dataManager = dataManager;
|
||||
this.vehicle = vehicle;
|
||||
|
||||
LoadVehicleData();
|
||||
}
|
||||
|
||||
private void LoadVehicleData()
|
||||
{
|
||||
// SPZ
|
||||
SpzTextBox.Text = vehicle.Spz ?? "";
|
||||
|
||||
// Model
|
||||
ModelTextBox.Text = vehicle.Model ?? "";
|
||||
|
||||
// Barva
|
||||
if (!string.IsNullOrEmpty(vehicle.Barva))
|
||||
{
|
||||
try
|
||||
{
|
||||
SelectedColor = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(vehicle.Barva);
|
||||
ColorPreviewBorder.Background = new SolidColorBrush(SelectedColor);
|
||||
ColorNameTextBlock.Text = vehicle.Barva;
|
||||
ColorNameTextBlock.FontStyle = FontStyles.Normal;
|
||||
ColorNameTextBlock.Foreground = System.Windows.Media.Brushes.Black;
|
||||
}
|
||||
catch
|
||||
{
|
||||
ColorPreviewBorder.Background = System.Windows.Media.Brushes.White;
|
||||
}
|
||||
}
|
||||
|
||||
// Rok vyroby
|
||||
YearTextBox.Text = vehicle.RokVyroby?.ToString() ?? "";
|
||||
|
||||
// Najete km
|
||||
MileageTextBox.Text = vehicle.NajeteKm?.ToString() ?? "";
|
||||
|
||||
// Cena
|
||||
PriceTextBox.Text = vehicle.Cena?.ToString() ?? "";
|
||||
|
||||
// Fotografie (base64)
|
||||
if (!string.IsNullOrEmpty(vehicle.Fotografie))
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] imageBytes = Convert.FromBase64String(vehicle.Fotografie);
|
||||
using (var ms = new MemoryStream(imageBytes))
|
||||
{
|
||||
var bitmap = new BitmapImage();
|
||||
bitmap.BeginInit();
|
||||
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmap.StreamSource = ms;
|
||||
bitmap.EndInit();
|
||||
bitmap.Freeze();
|
||||
CurrentPhotoImage.Source = bitmap;
|
||||
}
|
||||
CurrentPhotoBorder.Visibility = Visibility.Visible;
|
||||
PhotoPathTextBlock.Text = "Aktualni fotografie zobrazena vyse";
|
||||
}
|
||||
catch
|
||||
{
|
||||
CurrentPhotoBorder.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
photoChanged = true;
|
||||
|
||||
// Show preview of new photo
|
||||
try
|
||||
{
|
||||
var bitmap = new BitmapImage(new Uri(SelectedPhotoPath));
|
||||
CurrentPhotoImage.Source = bitmap;
|
||||
CurrentPhotoBorder.Visibility = Visibility.Visible;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore preview errors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// Update vehicle properties
|
||||
vehicle.Spz = SpzTextBox.Text;
|
||||
vehicle.Model = ModelTextBox.Text;
|
||||
vehicle.Barva = $"#{SelectedColor.R:X2}{SelectedColor.G:X2}{SelectedColor.B:X2}";
|
||||
vehicle.RokVyroby = int.TryParse(YearTextBox.Text, out int rok) ? rok : (int?)null;
|
||||
vehicle.NajeteKm = int.TryParse(MileageTextBox.Text, out int km) ? km : (int?)null;
|
||||
vehicle.Cena = decimal.TryParse(PriceTextBox.Text, out decimal cena) ? cena : (decimal?)null;
|
||||
|
||||
// Update photo only if changed
|
||||
if (photoChanged && !string.IsNullOrEmpty(SelectedPhotoPath) && File.Exists(SelectedPhotoPath))
|
||||
{
|
||||
byte[] imageBytes = File.ReadAllBytes(SelectedPhotoPath);
|
||||
vehicle.Fotografie = Convert.ToBase64String(imageBytes);
|
||||
}
|
||||
|
||||
this.dataManager.Save();
|
||||
WasEdited = true;
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,8 @@
|
||||
<!-- ListView s vozidly -->
|
||||
<ListView Grid.Row="1"
|
||||
Name="VehiclesListView"
|
||||
Margin="0,0,0,10">
|
||||
Margin="0,0,0,10"
|
||||
MouseDoubleClick="VehiclesListView_MouseDoubleClick">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="SPZ" Width="150" DisplayMemberBinding="{Binding Spz}" />
|
||||
@@ -59,6 +60,13 @@
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="AddButton_Click" />
|
||||
<Button Name="DetailButton"
|
||||
Content="Detail"
|
||||
Width="120"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="DetailButton_Click" />
|
||||
<Button Name="EditButton"
|
||||
Content="Upravit"
|
||||
Width="120"
|
||||
|
||||
@@ -31,16 +31,91 @@ namespace dealer
|
||||
{
|
||||
var window = new AddVehicleWindow(this.dataManager);
|
||||
window.ShowDialog();
|
||||
|
||||
this.VehiclesListView.ItemsSource = null;
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
|
||||
private void EditButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
var selectedVehicle = this.VehiclesListView.SelectedItem as Vehicle;
|
||||
|
||||
if (selectedVehicle == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, ktere chcete upravit.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var editWindow = new EditVehicleWindow(selectedVehicle, this.dataManager);
|
||||
editWindow.ShowDialog();
|
||||
|
||||
if (editWindow.WasEdited)
|
||||
{
|
||||
this.VehiclesListView.ItemsSource = null;
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
}
|
||||
|
||||
private void VehiclesListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var selectedVehicle = this.VehiclesListView.SelectedItem as Vehicle;
|
||||
|
||||
if (selectedVehicle == null)
|
||||
return;
|
||||
|
||||
var detailWindow = new VehicleDetailWindow(selectedVehicle, this.dataManager);
|
||||
detailWindow.ShowDialog();
|
||||
|
||||
if (detailWindow.WasDeleted || detailWindow.WasEdited)
|
||||
{
|
||||
this.VehiclesListView.ItemsSource = null;
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
}
|
||||
|
||||
private void DetailButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedVehicle = this.VehiclesListView.SelectedItem as Vehicle;
|
||||
|
||||
if (selectedVehicle == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, které chcete zobrazit.", "Upozornění", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var detailWindow = new VehicleDetailWindow(selectedVehicle, this.dataManager);
|
||||
detailWindow.ShowDialog();
|
||||
|
||||
if (detailWindow.WasDeleted || detailWindow.WasEdited)
|
||||
{
|
||||
this.VehiclesListView.ItemsSource = null;
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
var selectedVehicle = this.VehiclesListView.SelectedItem as Vehicle;
|
||||
|
||||
if (selectedVehicle == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, které chcete smazat.", "Upozornění", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = System.Windows.MessageBox.Show(
|
||||
$"Opravdu chcete smazat vozidlo {selectedVehicle.Model} (SPZ: {selectedVehicle.Spz})?",
|
||||
"Potvrzení smazání",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
this.dataManager.RemoveVehicle(selectedVehicle);
|
||||
this.dataManager.Save();
|
||||
this.VehiclesListView.ItemsSource = null;
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
141
dealer/windows/VehicleDetailWindow.xaml
Normal file
141
dealer/windows/VehicleDetailWindow.xaml
Normal file
@@ -0,0 +1,141 @@
|
||||
<Window x:Class="dealer.VehicleDetailWindow"
|
||||
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="Detail vozidla" Height="600" Width="500"
|
||||
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="Detail vozidla"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,20"
|
||||
HorizontalAlignment="Center" />
|
||||
|
||||
<!-- Fotografie -->
|
||||
<Border BorderBrush="Gray" BorderThickness="1" Margin="0,0,0,20" HorizontalAlignment="Center">
|
||||
<Image Name="VehicleImage"
|
||||
Width="300"
|
||||
Height="200"
|
||||
Stretch="Uniform" />
|
||||
</Border>
|
||||
<TextBlock Name="NoPhotoTextBlock"
|
||||
Text="Zadna fotografie"
|
||||
FontStyle="Italic"
|
||||
Foreground="Gray"
|
||||
HorizontalAlignment="Center"
|
||||
Margin="0,0,0,20"
|
||||
Visibility="Collapsed" />
|
||||
|
||||
<!-- SPZ -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="SPZ:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="SpzTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Model -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Model:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="ModelTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Barva -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Barva:" FontSize="14" FontWeight="SemiBold" />
|
||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
||||
<Border Name="ColorPreviewBorder"
|
||||
Width="20"
|
||||
Height="20"
|
||||
BorderBrush="Gray"
|
||||
BorderThickness="1"
|
||||
Margin="0,0,8,0" />
|
||||
<TextBlock Name="ColorTextBlock" FontSize="14" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Rok vyroby -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Rok vyroby:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="YearTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Najete km -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Najete km:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="MileageTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Cena -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Cena:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="PriceTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
</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="EditButton"
|
||||
Content="Upravit"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="EditButton_Click" />
|
||||
<Button Name="DeleteButton"
|
||||
Content="Smazat"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="DeleteButton_Click" />
|
||||
<Button Name="CloseButton"
|
||||
Content="Zavrit"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="CloseButton_Click" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
131
dealer/windows/VehicleDetailWindow.xaml.cs
Normal file
131
dealer/windows/VehicleDetailWindow.xaml.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace dealer
|
||||
{
|
||||
public partial class VehicleDetailWindow : Window
|
||||
{
|
||||
private Vehicle vehicle;
|
||||
private DataManager dataManager;
|
||||
|
||||
public bool WasDeleted { get; private set; } = false;
|
||||
public bool WasEdited { get; private set; } = false;
|
||||
|
||||
public VehicleDetailWindow(Vehicle vehicle, DataManager dataManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.vehicle = vehicle;
|
||||
this.dataManager = dataManager;
|
||||
|
||||
LoadVehicleDetails();
|
||||
}
|
||||
|
||||
private void LoadVehicleDetails()
|
||||
{
|
||||
// SPZ
|
||||
SpzTextBlock.Text = vehicle.Spz ?? "Nezadano";
|
||||
|
||||
// Model
|
||||
ModelTextBlock.Text = vehicle.Model ?? "Nezadano";
|
||||
|
||||
// Barva
|
||||
ColorTextBlock.Text = vehicle.Barva ?? "Nezadano";
|
||||
if (!string.IsNullOrEmpty(vehicle.Barva))
|
||||
{
|
||||
try
|
||||
{
|
||||
var color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString(vehicle.Barva);
|
||||
ColorPreviewBorder.Background = new SolidColorBrush(color);
|
||||
}
|
||||
catch
|
||||
{
|
||||
ColorPreviewBorder.Background = System.Windows.Media.Brushes.White;
|
||||
}
|
||||
}
|
||||
|
||||
// Rok vyroby
|
||||
YearTextBlock.Text = vehicle.RokVyroby?.ToString() ?? "Nezadano";
|
||||
|
||||
// Najete km
|
||||
if (vehicle.NajeteKm != null)
|
||||
MileageTextBlock.Text = vehicle.NajeteKm.Value.ToString("N0") + " km";
|
||||
else
|
||||
MileageTextBlock.Text = "Nezadano";
|
||||
|
||||
// Cena
|
||||
if (vehicle.Cena != null)
|
||||
PriceTextBlock.Text = vehicle.Cena.Value.ToString("N0") + " Kc";
|
||||
else
|
||||
PriceTextBlock.Text = "Nezadano";
|
||||
|
||||
// Fotografie (base64)
|
||||
if (!string.IsNullOrEmpty(vehicle.Fotografie))
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] imageBytes = Convert.FromBase64String(vehicle.Fotografie);
|
||||
using (var ms = new MemoryStream(imageBytes))
|
||||
{
|
||||
var bitmap = new BitmapImage();
|
||||
bitmap.BeginInit();
|
||||
bitmap.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmap.StreamSource = ms;
|
||||
bitmap.EndInit();
|
||||
bitmap.Freeze();
|
||||
VehicleImage.Source = bitmap;
|
||||
}
|
||||
VehicleImage.Visibility = Visibility.Visible;
|
||||
NoPhotoTextBlock.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
catch
|
||||
{
|
||||
VehicleImage.Visibility = Visibility.Collapsed;
|
||||
NoPhotoTextBlock.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VehicleImage.Visibility = Visibility.Collapsed;
|
||||
NoPhotoTextBlock.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var result = System.Windows.MessageBox.Show(
|
||||
$"Opravdu chcete smazat vozidlo {vehicle.Model} (SPZ: {vehicle.Spz})?",
|
||||
"Potvrzeni smazani",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
dataManager.RemoveVehicle(vehicle);
|
||||
dataManager.Save();
|
||||
WasDeleted = true;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void EditButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var editWindow = new EditVehicleWindow(vehicle, dataManager);
|
||||
editWindow.ShowDialog();
|
||||
|
||||
if (editWindow.WasEdited)
|
||||
{
|
||||
WasEdited = true;
|
||||
LoadVehicleDetails();
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user