Add clanker code
This commit is contained in:
84
dealer/windows/AddOwnerWindow.xaml
Normal file
84
dealer/windows/AddOwnerWindow.xaml
Normal file
@@ -0,0 +1,84 @@
|
||||
<Window x:Class="dealer.AddOwnerWindow"
|
||||
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 vlastnika" Height="400" Width="400"
|
||||
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="Novy vlastnik"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,20"
|
||||
HorizontalAlignment="Center" />
|
||||
|
||||
<TextBlock Text="Jmeno:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="JmenoTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Prijmeni:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="PrijmeniTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Telefon:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="TelefonTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Email:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="EmailTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Adresa:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="AdresaTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
TextWrapping="Wrap"
|
||||
AcceptsReturn="True"
|
||||
Height="60"
|
||||
Margin="0,0,0,10" />
|
||||
</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>
|
||||
49
dealer/windows/AddOwnerWindow.xaml.cs
Normal file
49
dealer/windows/AddOwnerWindow.xaml.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace dealer
|
||||
{
|
||||
public partial class AddOwnerWindow : Window
|
||||
{
|
||||
private DataManager dataManager;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the owner that was created when the user saved, or null if cancelled.
|
||||
/// </summary>
|
||||
public Owner? CreatedOwner { get; private set; }
|
||||
|
||||
public AddOwnerWindow(DataManager dataManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.dataManager = dataManager;
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(JmenoTextBox.Text) && string.IsNullOrWhiteSpace(PrijmeniTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte alespon jmeno nebo prijmeni.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var owner = new Owner
|
||||
{
|
||||
Jmeno = JmenoTextBox.Text.Trim(),
|
||||
Prijmeni = PrijmeniTextBox.Text.Trim(),
|
||||
Telefon = TelefonTextBox.Text.Trim(),
|
||||
Email = EmailTextBox.Text.Trim(),
|
||||
Adresa = AdresaTextBox.Text.Trim()
|
||||
};
|
||||
|
||||
dataManager.AddOwner(owner);
|
||||
dataManager.Save();
|
||||
CreatedOwner = owner;
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:dealer"
|
||||
mc:Ignorable="d"
|
||||
Title="Pridat vozidlo" Height="550" Width="450"
|
||||
Title="Pridat vozidlo" Height="700" Width="500"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
ResizeMode="NoResize">
|
||||
<Grid>
|
||||
@@ -30,6 +30,12 @@
|
||||
CharacterCasing="Upper"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Znacka:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="ZnackaTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Model:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="ModelTextBox"
|
||||
FontSize="14"
|
||||
@@ -66,6 +72,19 @@
|
||||
PreviewTextInput="NumericOnly_PreviewTextInput"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Palivo:" FontSize="14" Margin="0,5" />
|
||||
<ComboBox Name="PalivoComboBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10">
|
||||
<ComboBoxItem Content="Benzin" />
|
||||
<ComboBoxItem Content="Nafta" />
|
||||
<ComboBoxItem Content="Elektro" />
|
||||
<ComboBoxItem Content="Hybrid" />
|
||||
<ComboBoxItem Content="LPG" />
|
||||
<ComboBoxItem Content="CNG" />
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Text="Najete km:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="MileageTextBox"
|
||||
FontSize="14"
|
||||
@@ -94,6 +113,44 @@
|
||||
Foreground="Gray"
|
||||
Margin="0,0,0,10"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<Separator Margin="0,15,0,15" />
|
||||
|
||||
<TextBlock Text="Vlastnik" FontSize="16" FontWeight="Bold" Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Vybrat vlastnika:" FontSize="14" Margin="0,5" />
|
||||
<Grid Margin="0,0,0,10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox Name="OwnerComboBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
IsEditable="True"
|
||||
IsTextSearchEnabled="False"
|
||||
StaysOpenOnEdit="True"
|
||||
DisplayMemberPath="DisplayText"
|
||||
TextBoxBase.TextChanged="OwnerComboBox_TextChanged"
|
||||
SelectionChanged="OwnerComboBox_SelectionChanged" />
|
||||
<Button Name="AddNewOwnerButton"
|
||||
Grid.Column="1"
|
||||
Content="+"
|
||||
Width="35"
|
||||
Height="35"
|
||||
Margin="5,0,0,0"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
ToolTip="Pridat noveho vlastnika"
|
||||
Click="AddNewOwnerButton_Click" />
|
||||
</Grid>
|
||||
|
||||
<TextBlock Name="SelectedOwnerInfo"
|
||||
Text=""
|
||||
FontStyle="Italic"
|
||||
Foreground="Gray"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0,0,0,10" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.Win32;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using WinForms = System.Windows.Forms;
|
||||
@@ -13,12 +15,76 @@ namespace dealer
|
||||
public System.Windows.Media.Color SelectedColor { get; private set; } = Colors.White;
|
||||
|
||||
private DataManager dataManager;
|
||||
private Owner? selectedOwner;
|
||||
private bool isUpdatingOwnerComboBox = false;
|
||||
|
||||
public AddVehicleWindow(DataManager dataManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.dataManager = dataManager;
|
||||
LoadOwners();
|
||||
}
|
||||
|
||||
private void LoadOwners()
|
||||
{
|
||||
OwnerComboBox.ItemsSource = dataManager.GetAllOwners().ToList();
|
||||
}
|
||||
|
||||
private void OwnerComboBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (isUpdatingOwnerComboBox) return;
|
||||
|
||||
var comboBox = sender as System.Windows.Controls.ComboBox;
|
||||
if (comboBox == null) return;
|
||||
|
||||
string searchText = comboBox.Text;
|
||||
var filteredOwners = dataManager.SearchOwners(searchText).ToList();
|
||||
|
||||
isUpdatingOwnerComboBox = true;
|
||||
comboBox.ItemsSource = filteredOwners;
|
||||
comboBox.IsDropDownOpen = true;
|
||||
isUpdatingOwnerComboBox = false;
|
||||
}
|
||||
|
||||
private void OwnerComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
selectedOwner = OwnerComboBox.SelectedItem as Owner;
|
||||
UpdateSelectedOwnerInfo();
|
||||
}
|
||||
|
||||
private void UpdateSelectedOwnerInfo()
|
||||
{
|
||||
if (selectedOwner != null)
|
||||
{
|
||||
var info = selectedOwner.CeleJmeno;
|
||||
if (!string.IsNullOrEmpty(selectedOwner.Telefon))
|
||||
info += $"\nTel: {selectedOwner.Telefon}";
|
||||
if (!string.IsNullOrEmpty(selectedOwner.Email))
|
||||
info += $"\nEmail: {selectedOwner.Email}";
|
||||
if (!string.IsNullOrEmpty(selectedOwner.Adresa))
|
||||
info += $"\nAdresa: {selectedOwner.Adresa}";
|
||||
SelectedOwnerInfo.Text = info;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedOwnerInfo.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void AddNewOwnerButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var addOwnerWindow = new AddOwnerWindow(dataManager);
|
||||
addOwnerWindow.Owner = this;
|
||||
if (addOwnerWindow.ShowDialog() == true && addOwnerWindow.CreatedOwner != null)
|
||||
{
|
||||
LoadOwners();
|
||||
OwnerComboBox.SelectedItem = dataManager.GetAllOwners().FirstOrDefault(o => o.Id == addOwnerWindow.CreatedOwner.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadOwners();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectPhotoButton_Click(object sender, RoutedEventArgs e)
|
||||
@@ -74,22 +140,75 @@ namespace dealer
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string? base64Image = null;
|
||||
if (string.IsNullOrWhiteSpace(SpzTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte SPZ.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ZnackaTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte znacku.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ModelTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte model.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(YearTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte rok vyroby.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PalivoComboBox.SelectedItem == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte palivo.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(MileageTextBox.Text) && (!int.TryParse(MileageTextBox.Text, out int mileageVal) || mileageVal < 0))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Najete km musi byt nezaporne cele cislo.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(PriceTextBox.Text) && (!decimal.TryParse(PriceTextBox.Text, out decimal priceVal) || priceVal < 0))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Cena musi byt nezaporne cislo.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
Image? image = null;
|
||||
if (!string.IsNullOrEmpty(SelectedPhotoPath) && File.Exists(SelectedPhotoPath))
|
||||
{
|
||||
byte[] imageBytes = File.ReadAllBytes(SelectedPhotoPath);
|
||||
base64Image = Convert.ToBase64String(imageBytes);
|
||||
image = new Image
|
||||
{
|
||||
Data = Convert.ToBase64String(imageBytes),
|
||||
FileName = System.IO.Path.GetFileName(SelectedPhotoPath),
|
||||
ContentType = GetContentType(SelectedPhotoPath)
|
||||
};
|
||||
this.dataManager.AddImage(image);
|
||||
}
|
||||
|
||||
var vehicle = new Vehicle
|
||||
{
|
||||
Spz = SpzTextBox.Text,
|
||||
Znacka = ZnackaTextBox.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,
|
||||
Palivo = (PalivoComboBox.SelectedItem as System.Windows.Controls.ComboBoxItem)?.Content?.ToString(),
|
||||
NajeteKm = int.TryParse(MileageTextBox.Text, out int km) ? km : (int?)null,
|
||||
Cena = decimal.TryParse(PriceTextBox.Text, out decimal cena) ? cena : (decimal?)null,
|
||||
Fotografie = base64Image
|
||||
FotografieId = image?.Id,
|
||||
Fotografie = image,
|
||||
VlastnikId = selectedOwner?.Id,
|
||||
Vlastnik = selectedOwner
|
||||
};
|
||||
|
||||
this.dataManager.AddVehicle(vehicle);
|
||||
@@ -102,5 +221,19 @@ namespace dealer
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private static string GetContentType(string filePath)
|
||||
{
|
||||
var extension = System.IO.Path.GetExtension(filePath)?.ToLowerInvariant();
|
||||
return extension switch
|
||||
{
|
||||
".jpg" or ".jpeg" => "image/jpeg",
|
||||
".png" => "image/png",
|
||||
".gif" => "image/gif",
|
||||
".bmp" => "image/bmp",
|
||||
".webp" => "image/webp",
|
||||
_ => "application/octet-stream"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
84
dealer/windows/EditOwnerWindow.xaml
Normal file
84
dealer/windows/EditOwnerWindow.xaml
Normal file
@@ -0,0 +1,84 @@
|
||||
<Window x:Class="dealer.EditOwnerWindow"
|
||||
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 vlastnika" Height="400" Width="400"
|
||||
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 vlastnika"
|
||||
FontSize="20"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,20"
|
||||
HorizontalAlignment="Center" />
|
||||
|
||||
<TextBlock Text="Jmeno:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="JmenoTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Prijmeni:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="PrijmeniTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Telefon:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="TelefonTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Email:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="EmailTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Adresa:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="AdresaTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
TextWrapping="Wrap"
|
||||
AcceptsReturn="True"
|
||||
Height="60"
|
||||
Margin="0,0,0,10" />
|
||||
</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>
|
||||
74
dealer/windows/EditOwnerWindow.xaml.cs
Normal file
74
dealer/windows/EditOwnerWindow.xaml.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace dealer
|
||||
{
|
||||
public partial class EditOwnerWindow : Window
|
||||
{
|
||||
private Owner owner;
|
||||
private DataManager dataManager;
|
||||
|
||||
public EditOwnerWindow(Owner owner, DataManager dataManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.owner = owner;
|
||||
this.dataManager = dataManager;
|
||||
LoadOwnerData();
|
||||
}
|
||||
|
||||
private void LoadOwnerData()
|
||||
{
|
||||
JmenoTextBox.Text = owner.Jmeno ?? "";
|
||||
PrijmeniTextBox.Text = owner.Prijmeni ?? "";
|
||||
TelefonTextBox.Text = owner.Telefon ?? "";
|
||||
EmailTextBox.Text = owner.Email ?? "";
|
||||
AdresaTextBox.Text = owner.Adresa ?? "";
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(JmenoTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte jmeno.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(PrijmeniTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte prijmeni.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(TelefonTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte telefon.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(EmailTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte email.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(AdresaTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte adresu.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
owner.Jmeno = JmenoTextBox.Text.Trim();
|
||||
owner.Prijmeni = PrijmeniTextBox.Text.Trim();
|
||||
owner.Telefon = TelefonTextBox.Text.Trim();
|
||||
owner.Email = EmailTextBox.Text.Trim();
|
||||
owner.Adresa = AdresaTextBox.Text.Trim();
|
||||
|
||||
dataManager.Save();
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:dealer"
|
||||
mc:Ignorable="d"
|
||||
Title="Upravit vozidlo" Height="600" Width="450"
|
||||
Title="Upravit vozidlo" Height="700" Width="500"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
ResizeMode="NoResize">
|
||||
<Grid>
|
||||
@@ -30,6 +30,12 @@
|
||||
CharacterCasing="Upper"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Znacka:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="ZnackaTextBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Model:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="ModelTextBox"
|
||||
FontSize="14"
|
||||
@@ -66,6 +72,19 @@
|
||||
PreviewTextInput="NumericOnly_PreviewTextInput"
|
||||
Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Palivo:" FontSize="14" Margin="0,5" />
|
||||
<ComboBox Name="PalivoComboBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
Margin="0,0,0,10">
|
||||
<ComboBoxItem Content="Benzin" />
|
||||
<ComboBoxItem Content="Nafta" />
|
||||
<ComboBoxItem Content="Elektro" />
|
||||
<ComboBoxItem Content="Hybrid" />
|
||||
<ComboBoxItem Content="LPG" />
|
||||
<ComboBoxItem Content="CNG" />
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock Text="Najete km:" FontSize="14" Margin="0,5" />
|
||||
<TextBox Name="MileageTextBox"
|
||||
FontSize="14"
|
||||
@@ -100,6 +119,44 @@
|
||||
Foreground="Gray"
|
||||
Margin="0,0,0,10"
|
||||
TextWrapping="Wrap" />
|
||||
|
||||
<Separator Margin="0,15,0,15" />
|
||||
|
||||
<TextBlock Text="Vlastnik" FontSize="16" FontWeight="Bold" Margin="0,0,0,10" />
|
||||
|
||||
<TextBlock Text="Vybrat vlastnika:" FontSize="14" Margin="0,5" />
|
||||
<Grid Margin="0,0,0,10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<ComboBox Name="OwnerComboBox"
|
||||
FontSize="14"
|
||||
Padding="5"
|
||||
IsEditable="True"
|
||||
IsTextSearchEnabled="False"
|
||||
StaysOpenOnEdit="True"
|
||||
DisplayMemberPath="DisplayText"
|
||||
TextBoxBase.TextChanged="OwnerComboBox_TextChanged"
|
||||
SelectionChanged="OwnerComboBox_SelectionChanged" />
|
||||
<Button Name="AddNewOwnerButton"
|
||||
Grid.Column="1"
|
||||
Content="+"
|
||||
Width="35"
|
||||
Height="35"
|
||||
Margin="5,0,0,0"
|
||||
FontSize="18"
|
||||
FontWeight="Bold"
|
||||
ToolTip="Pridat noveho vlastnika"
|
||||
Click="AddNewOwnerButton_Click" />
|
||||
</Grid>
|
||||
|
||||
<TextBlock Name="SelectedOwnerInfo"
|
||||
Text=""
|
||||
FontStyle="Italic"
|
||||
Foreground="Gray"
|
||||
TextWrapping="Wrap"
|
||||
Margin="0,0,0,10" />
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
@@ -18,6 +20,8 @@ namespace dealer
|
||||
private DataManager dataManager;
|
||||
private Vehicle vehicle;
|
||||
private bool photoChanged = false;
|
||||
private Owner? selectedOwner;
|
||||
private bool isUpdatingOwnerComboBox = false;
|
||||
|
||||
public EditVehicleWindow(Vehicle vehicle, DataManager dataManager)
|
||||
{
|
||||
@@ -26,14 +30,72 @@ namespace dealer
|
||||
this.dataManager = dataManager;
|
||||
this.vehicle = vehicle;
|
||||
|
||||
LoadOwners();
|
||||
LoadVehicleData();
|
||||
}
|
||||
|
||||
private void LoadOwners()
|
||||
{
|
||||
OwnerComboBox.ItemsSource = dataManager.GetAllOwners().ToList();
|
||||
}
|
||||
|
||||
private void OwnerComboBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (isUpdatingOwnerComboBox) return;
|
||||
|
||||
var comboBox = sender as System.Windows.Controls.ComboBox;
|
||||
if (comboBox == null) return;
|
||||
|
||||
string searchText = comboBox.Text;
|
||||
var filteredOwners = dataManager.SearchOwners(searchText).ToList();
|
||||
|
||||
isUpdatingOwnerComboBox = true;
|
||||
comboBox.ItemsSource = filteredOwners;
|
||||
comboBox.IsDropDownOpen = true;
|
||||
isUpdatingOwnerComboBox = false;
|
||||
}
|
||||
|
||||
private void OwnerComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
selectedOwner = OwnerComboBox.SelectedItem as Owner;
|
||||
UpdateSelectedOwnerInfo();
|
||||
}
|
||||
|
||||
private void UpdateSelectedOwnerInfo()
|
||||
{
|
||||
if (selectedOwner != null)
|
||||
{
|
||||
var info = selectedOwner.CeleJmeno;
|
||||
if (!string.IsNullOrEmpty(selectedOwner.Telefon))
|
||||
info += $"\nTel: {selectedOwner.Telefon}";
|
||||
if (!string.IsNullOrEmpty(selectedOwner.Email))
|
||||
info += $"\nEmail: {selectedOwner.Email}";
|
||||
if (!string.IsNullOrEmpty(selectedOwner.Adresa))
|
||||
info += $"\nAdresa: {selectedOwner.Adresa}";
|
||||
SelectedOwnerInfo.Text = info;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedOwnerInfo.Text = "";
|
||||
}
|
||||
}
|
||||
|
||||
private void AddNewOwnerButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var addOwnerWindow = new AddOwnerWindow(dataManager);
|
||||
addOwnerWindow.Owner = this;
|
||||
addOwnerWindow.ShowDialog();
|
||||
LoadOwners();
|
||||
}
|
||||
|
||||
private void LoadVehicleData()
|
||||
{
|
||||
// SPZ
|
||||
SpzTextBox.Text = vehicle.Spz ?? "";
|
||||
|
||||
// Zna<6E>ka
|
||||
ZnackaTextBox.Text = vehicle.Znacka ?? "";
|
||||
|
||||
// Model
|
||||
ModelTextBox.Text = vehicle.Model ?? "";
|
||||
|
||||
@@ -57,18 +119,42 @@ namespace dealer
|
||||
// Rok vyroby
|
||||
YearTextBox.Text = vehicle.RokVyroby?.ToString() ?? "";
|
||||
|
||||
// Palivo
|
||||
if (!string.IsNullOrEmpty(vehicle.Palivo))
|
||||
{
|
||||
foreach (System.Windows.Controls.ComboBoxItem item in PalivoComboBox.Items)
|
||||
{
|
||||
if (item.Content?.ToString() == vehicle.Palivo)
|
||||
{
|
||||
PalivoComboBox.SelectedItem = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Najete km
|
||||
MileageTextBox.Text = vehicle.NajeteKm?.ToString() ?? "";
|
||||
|
||||
// Cena
|
||||
PriceTextBox.Text = vehicle.Cena?.ToString() ?? "";
|
||||
|
||||
// Vlastnik - select from combobox
|
||||
if (vehicle.VlastnikId.HasValue)
|
||||
{
|
||||
selectedOwner = dataManager.GetOwnerById(vehicle.VlastnikId);
|
||||
if (selectedOwner != null)
|
||||
{
|
||||
OwnerComboBox.SelectedItem = selectedOwner;
|
||||
UpdateSelectedOwnerInfo();
|
||||
}
|
||||
}
|
||||
|
||||
// Fotografie (base64)
|
||||
if (!string.IsNullOrEmpty(vehicle.Fotografie))
|
||||
if (vehicle.Fotografie != null && !string.IsNullOrEmpty(vehicle.Fotografie.Data))
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] imageBytes = Convert.FromBase64String(vehicle.Fotografie);
|
||||
byte[] imageBytes = Convert.FromBase64String(vehicle.Fotografie.Data);
|
||||
using (var ms = new MemoryStream(imageBytes))
|
||||
{
|
||||
var bitmap = new BitmapImage();
|
||||
@@ -155,19 +241,75 @@ namespace dealer
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(SpzTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte SPZ.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ZnackaTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte znacku.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(ModelTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte model.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(YearTextBox.Text))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyplnte rok vyroby.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PalivoComboBox.SelectedItem == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte palivo.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(MileageTextBox.Text) && (!int.TryParse(MileageTextBox.Text, out int mileageVal) || mileageVal < 0))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Najete km musi byt nezaporne cele cislo.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(PriceTextBox.Text) && (!decimal.TryParse(PriceTextBox.Text, out decimal priceVal) || priceVal < 0))
|
||||
{
|
||||
System.Windows.MessageBox.Show("Cena musi byt nezaporne cislo.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update vehicle properties
|
||||
vehicle.Spz = SpzTextBox.Text;
|
||||
vehicle.Znacka = ZnackaTextBox.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.Palivo = (PalivoComboBox.SelectedItem as System.Windows.Controls.ComboBoxItem)?.Content?.ToString();
|
||||
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 owner reference
|
||||
vehicle.VlastnikId = selectedOwner?.Id;
|
||||
vehicle.Vlastnik = selectedOwner;
|
||||
|
||||
// Update photo only if changed
|
||||
if (photoChanged && !string.IsNullOrEmpty(SelectedPhotoPath) && File.Exists(SelectedPhotoPath))
|
||||
{
|
||||
byte[] imageBytes = File.ReadAllBytes(SelectedPhotoPath);
|
||||
vehicle.Fotografie = Convert.ToBase64String(imageBytes);
|
||||
var image = new Image
|
||||
{
|
||||
Data = Convert.ToBase64String(imageBytes),
|
||||
FileName = System.IO.Path.GetFileName(SelectedPhotoPath),
|
||||
ContentType = GetContentType(SelectedPhotoPath)
|
||||
};
|
||||
this.dataManager.AddImage(image);
|
||||
vehicle.FotografieId = image.Id;
|
||||
vehicle.Fotografie = image;
|
||||
}
|
||||
|
||||
this.dataManager.Save();
|
||||
@@ -180,5 +322,19 @@ namespace dealer
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private static string GetContentType(string filePath)
|
||||
{
|
||||
var extension = System.IO.Path.GetExtension(filePath)?.ToLowerInvariant();
|
||||
return extension switch
|
||||
{
|
||||
".jpg" or ".jpeg" => "image/jpeg",
|
||||
".png" => "image/png",
|
||||
".gif" => "image/gif",
|
||||
".bmp" => "image/bmp",
|
||||
".webp" => "image/webp",
|
||||
_ => "application/octet-stream"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
MouseDoubleClick="VehiclesListView_MouseDoubleClick">
|
||||
<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 Header="SPZ" Width="120" DisplayMemberBinding="{Binding Spz}" />
|
||||
<GridViewColumn Header="Značka a Model" Width="200"
|
||||
DisplayMemberBinding="{Binding ZnackaModel}" />
|
||||
<GridViewColumn Header="Barva" Width="130">
|
||||
<GridViewColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@@ -45,16 +45,18 @@
|
||||
</DataTemplate>
|
||||
</GridViewColumn.CellTemplate>
|
||||
</GridViewColumn>
|
||||
<GridViewColumn Header="Rok" Width="70" DisplayMemberBinding="{Binding RokVyroby}" />
|
||||
<GridViewColumn Header="Palivo" Width="100" DisplayMemberBinding="{Binding Palivo}" />
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
|
||||
<!-- Tlačítka -->
|
||||
<!-- Tlacitka -->
|
||||
<StackPanel Grid.Row="2"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center">
|
||||
<Button Name="AddButton"
|
||||
Content="Přidat vozidlo"
|
||||
Content="Pridat vozidlo"
|
||||
Width="120"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
@@ -62,25 +64,33 @@
|
||||
Click="AddButton_Click" />
|
||||
<Button Name="DetailButton"
|
||||
Content="Detail"
|
||||
Width="120"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="DetailButton_Click" />
|
||||
<Button Name="EditButton"
|
||||
Content="Upravit"
|
||||
Width="120"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="EditButton_Click" />
|
||||
<Button Name="DeleteButton"
|
||||
Content="Smazat"
|
||||
Width="120"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="DeleteButton_Click" />
|
||||
<Button Name="OwnersButton"
|
||||
Content="Vlastnici"
|
||||
Width="100"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Background="#FFE0E0FF"
|
||||
Click="OwnersButton_Click" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -79,7 +79,7 @@ namespace dealer
|
||||
|
||||
if (selectedVehicle == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, které chcete zobrazit.", "Upozornění", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, ktere chcete zobrazit.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,13 +99,13 @@ namespace dealer
|
||||
|
||||
if (selectedVehicle == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, které chcete smazat.", "Upozornění", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
System.Windows.MessageBox.Show("Vyberte vozidlo, ktere chcete smazat.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = System.Windows.MessageBox.Show(
|
||||
$"Opravdu chcete smazat vozidlo {selectedVehicle.Model} (SPZ: {selectedVehicle.Spz})?",
|
||||
"Potvrzení smazání",
|
||||
"Potvrzeni smazani",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
@@ -117,5 +117,16 @@ namespace dealer
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
}
|
||||
|
||||
private void OwnersButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var ownersWindow = new OwnersWindow(this.dataManager);
|
||||
ownersWindow.Owner = this;
|
||||
ownersWindow.ShowDialog();
|
||||
|
||||
// Refresh vehicles list to update owner references
|
||||
this.VehiclesListView.ItemsSource = null;
|
||||
this.VehiclesListView.ItemsSource = this.dataManager.GetAllVehicles();
|
||||
}
|
||||
}
|
||||
}
|
||||
85
dealer/windows/OwnersWindow.xaml
Normal file
85
dealer/windows/OwnersWindow.xaml
Normal file
@@ -0,0 +1,85 @@
|
||||
<Window x:Class="dealer.OwnersWindow"
|
||||
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="Sprava vlastniku" Height="500" Width="700"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="Evidence vlastniku"
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
Margin="0,0,0,10"
|
||||
HorizontalAlignment="Center" />
|
||||
|
||||
<Grid Grid.Row="1" Margin="0,0,0,10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Hledat:" VerticalAlignment="Center" Margin="0,0,10,0" />
|
||||
<TextBox Name="SearchTextBox"
|
||||
Grid.Column="1"
|
||||
Padding="5"
|
||||
TextChanged="SearchTextBox_TextChanged" />
|
||||
</Grid>
|
||||
|
||||
<ListView Grid.Row="2"
|
||||
Name="OwnersListView"
|
||||
Margin="0,0,0,10"
|
||||
MouseDoubleClick="OwnersListView_MouseDoubleClick">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="Jmeno" Width="120" DisplayMemberBinding="{Binding Jmeno}" />
|
||||
<GridViewColumn Header="Prijmeni" Width="120" DisplayMemberBinding="{Binding Prijmeni}" />
|
||||
<GridViewColumn Header="Telefon" Width="120" DisplayMemberBinding="{Binding Telefon}" />
|
||||
<GridViewColumn Header="Email" Width="180" DisplayMemberBinding="{Binding Email}" />
|
||||
<GridViewColumn Header="Adresa" Width="150" DisplayMemberBinding="{Binding Adresa}" />
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
|
||||
<StackPanel Grid.Row="3"
|
||||
Orientation="Horizontal"
|
||||
HorizontalAlignment="Center">
|
||||
<Button Name="AddButton"
|
||||
Content="Pridat vlastnika"
|
||||
Width="130"
|
||||
Height="35"
|
||||
Margin="5"
|
||||
FontSize="14"
|
||||
Click="AddButton_Click" />
|
||||
<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>
|
||||
</Grid>
|
||||
</Window>
|
||||
91
dealer/windows/OwnersWindow.xaml.cs
Normal file
91
dealer/windows/OwnersWindow.xaml.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace dealer
|
||||
{
|
||||
public partial class OwnersWindow : Window
|
||||
{
|
||||
private DataManager dataManager;
|
||||
|
||||
public OwnersWindow(DataManager dataManager)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.dataManager = dataManager;
|
||||
RefreshOwnersList();
|
||||
}
|
||||
|
||||
private void RefreshOwnersList()
|
||||
{
|
||||
string searchText = SearchTextBox?.Text ?? "";
|
||||
OwnersListView.ItemsSource = null;
|
||||
OwnersListView.ItemsSource = dataManager.SearchOwners(searchText);
|
||||
}
|
||||
|
||||
private void SearchTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
|
||||
{
|
||||
RefreshOwnersList();
|
||||
}
|
||||
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var addWindow = new AddOwnerWindow(dataManager);
|
||||
addWindow.Owner = this;
|
||||
addWindow.ShowDialog();
|
||||
RefreshOwnersList();
|
||||
}
|
||||
|
||||
private void EditButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedOwner = OwnersListView.SelectedItem as Owner;
|
||||
if (selectedOwner == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vlastnika, ktereho chcete upravit.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var editWindow = new EditOwnerWindow(selectedOwner, dataManager);
|
||||
editWindow.Owner = this;
|
||||
editWindow.ShowDialog();
|
||||
RefreshOwnersList();
|
||||
}
|
||||
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedOwner = OwnersListView.SelectedItem as Owner;
|
||||
if (selectedOwner == null)
|
||||
{
|
||||
System.Windows.MessageBox.Show("Vyberte vlastnika, ktereho chcete smazat.", "Upozorneni", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = System.Windows.MessageBox.Show(
|
||||
$"Opravdu chcete smazat vlastnika {selectedOwner.CeleJmeno}?\n\nVozidla tohoto vlastnika zustanou, ale nebudou mit prirazeneho vlastnika.",
|
||||
"Potvrzeni smazani",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
dataManager.RemoveOwner(selectedOwner);
|
||||
dataManager.Save();
|
||||
RefreshOwnersList();
|
||||
}
|
||||
}
|
||||
|
||||
private void OwnersListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var selectedOwner = OwnersListView.SelectedItem as Owner;
|
||||
if (selectedOwner == null) return;
|
||||
|
||||
var editWindow = new EditOwnerWindow(selectedOwner, dataManager);
|
||||
editWindow.Owner = this;
|
||||
editWindow.ShowDialog();
|
||||
RefreshOwnersList();
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,16 @@
|
||||
<TextBlock Name="SpzTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Znacka -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Znacka:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="ZnackaTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Model -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -85,6 +95,16 @@
|
||||
<TextBlock Name="YearTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Palivo -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Palivo:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="PalivoTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Najete km -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -104,6 +124,50 @@
|
||||
<TextBlock Text="Cena:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="PriceTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<Separator Margin="0,15,0,15" />
|
||||
|
||||
<TextBlock Text="Vlastnik" FontSize="16" FontWeight="Bold" Margin="0,0,0,10" />
|
||||
|
||||
<!-- Vlastnik Jmeno -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Jmeno a Prijmeni:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="OwnerNameTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Adresa -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Adresa:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="AddressTextBlock" Grid.Column="1" FontSize="14" TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
|
||||
<!-- Telefon -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Telefon:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="PhoneTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
|
||||
<!-- Email -->
|
||||
<Grid Margin="0,5">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="120" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="Email:" FontSize="14" FontWeight="SemiBold" />
|
||||
<TextBlock Name="EmailTextBlock" Grid.Column="1" FontSize="14" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
@@ -139,3 +203,5 @@
|
||||
</Border>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ namespace dealer
|
||||
// SPZ
|
||||
SpzTextBlock.Text = vehicle.Spz ?? "Nezadano";
|
||||
|
||||
// Znacka
|
||||
ZnackaTextBlock.Text = vehicle.Znacka ?? "Nezadano";
|
||||
|
||||
// Model
|
||||
ModelTextBlock.Text = vehicle.Model ?? "Nezadano";
|
||||
|
||||
@@ -50,6 +53,9 @@ namespace dealer
|
||||
// Rok vyroby
|
||||
YearTextBlock.Text = vehicle.RokVyroby?.ToString() ?? "Nezadano";
|
||||
|
||||
// Palivo
|
||||
PalivoTextBlock.Text = vehicle.Palivo ?? "Nezadano";
|
||||
|
||||
// Najete km
|
||||
if (vehicle.NajeteKm != null)
|
||||
MileageTextBlock.Text = vehicle.NajeteKm.Value.ToString("N0") + " km";
|
||||
@@ -62,12 +68,28 @@ namespace dealer
|
||||
else
|
||||
PriceTextBlock.Text = "Nezadano";
|
||||
|
||||
// Vlastnik
|
||||
if (vehicle.Vlastnik != null)
|
||||
{
|
||||
OwnerNameTextBlock.Text = vehicle.Vlastnik.CeleJmeno;
|
||||
AddressTextBlock.Text = vehicle.Vlastnik.Adresa ?? "Nezadano";
|
||||
PhoneTextBlock.Text = vehicle.Vlastnik.Telefon ?? "Nezadano";
|
||||
EmailTextBlock.Text = vehicle.Vlastnik.Email ?? "Nezadano";
|
||||
}
|
||||
else
|
||||
{
|
||||
OwnerNameTextBlock.Text = "Nezadano";
|
||||
AddressTextBlock.Text = "Nezadano";
|
||||
PhoneTextBlock.Text = "Nezadano";
|
||||
EmailTextBlock.Text = "Nezadano";
|
||||
}
|
||||
|
||||
// Fotografie (base64)
|
||||
if (!string.IsNullOrEmpty(vehicle.Fotografie))
|
||||
if (vehicle.Fotografie != null && !string.IsNullOrEmpty(vehicle.Fotografie.Data))
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] imageBytes = Convert.FromBase64String(vehicle.Fotografie);
|
||||
byte[] imageBytes = Convert.FromBase64String(vehicle.Fotografie.Data);
|
||||
using (var ms = new MemoryStream(imageBytes))
|
||||
{
|
||||
var bitmap = new BitmapImage();
|
||||
@@ -129,3 +151,4 @@ namespace dealer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user