WpfMaterial 1.0.0
dotnet add package WpfMaterial --version 1.0.0
NuGet\Install-Package WpfMaterial -Version 1.0.0
<PackageReference Include="WpfMaterial" Version="1.0.0" />
<PackageVersion Include="WpfMaterial" Version="1.0.0" />
<PackageReference Include="WpfMaterial" />
paket add WpfMaterial --version 1.0.0
#r "nuget: WpfMaterial, 1.0.0"
#:package WpfMaterial@1.0.0
#addin nuget:?package=WpfMaterial&version=1.0.0
#tool nuget:?package=WpfMaterial&version=1.0.0
//AddCarWindow //xaml using static System.Net.Mime.MediaTypeNames; using System.Windows.Controls; using System.Windows.Media.Media3D; using System.Windows;
using System.Xml.Linq; using System; using System.Reflection.Metadata; using System.Security.Claims; using System.Windows.Media; using System.Reflection.PortableExecutable; using System.Windows.Data; using System.Collections.Generic;
< Window x: Class = "CarRentalApp.AddCarWindow" 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:CarRentalApp" mc: Ignorable = "d" Title = "AddCarWindow" Height = "450" Width = "800" > < Grid Margin = "10" > < StackPanel > < TextBlock Text = "Название машины:" /> < TextBox x: Name = "NameTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Год выпуска:" />
< TextBox x: Name = "YearTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Цена за сутки:" />
< TextBox x: Name = "PriceTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Объем бензобака:" />
< TextBox x: Name = "FuelCapacityTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Количество мест:" />
< TextBox x: Name = "SeatsTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Описание машины:" />
< TextBox x: Name = "DescriptionTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Тип руля:" />
< ComboBox x: Name = "SteeringTypeComboBox" Margin = "0 0 0 10" >
< ComboBoxItem Content = "Левый" Tag = "1" />
< ComboBoxItem Content = "Правый" Tag = "2" />
< ComboBoxItem Content = "Центр" Tag = "3" />
</ ComboBox >
< Button Content = "Сохранить" Width = "100" HorizontalAlignment = "Center" Click = "SaveButton_Click" />
</ StackPanel >
</ Grid >
</ Window >
//c# using System.Windows; using System.Windows.Controls; using Npgsql;
namespace CarRentalApp { /// <summary> /// Логика взаимодействия для AddCarWindow.xaml /// </summary> public partial class AddCarWindow : Window { public AddCarWindow() { InitializeComponent(); }
private void SaveButton_Click(object sender, EventArgs e)
{
string connectionString = "Host=localhost;Port=5432;Username=postgres;Password=1234;Database=postgres;SearchPath=car_rental_system";
using var connection = new NpgsqlConnection(connectionString);
try
{
connection.Open();
string query = @"insert into cars
(name, year, price_per_day, fuel_capacity, seats, description, steering_type_id)
values (@name, @year, @price, @fuelcapacity, @seats, @description, @steeringTypeId)";
var command = new NpgsqlCommand(query, connection);
command.Parameters.AddWithValue("@name", NameTextBox.Text);
command.Parameters.AddWithValue("@year", int.Parse(YearTextBox.Text));
command.Parameters.AddWithValue("@price", decimal.Parse(PriceTextBox.Text));
command.Parameters.AddWithValue("@fuelcapacity", decimal.Parse(FuelCapacityTextBox.Text));
command.Parameters.AddWithValue("@seats", int.Parse(SeatsTextBox.Text));
command.Parameters.AddWithValue("@description", DescriptionTextBox.Text);
var selectedSteeringType = (ComboBoxItem)SteeringTypeComboBox.SelectedItem;
int steeringTypeId = int.Parse(selectedSteeringType.Tag.ToString());
command.Parameters.AddWithValue("@steeringTypeId", steeringTypeId);
command.ExecuteNonQuery();
MessageBox.Show("Машина успешно добавлена!");
this.Close();
}
catch (System.Exception ex)
{
MessageBox.Show("Ошибка добавления: " + ex.Message);
}
}
}
}
//car.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace CarRentalApp { public class Car { public int Id { get; set; } public string Name { get; set; } public int Year { get; set; } public decimal PricePerDay { get; set; } public string Description { get; set; } public string ImagePath { get; set; } public decimal FuelCapacity { get; set; } public int Seats { get; set; } public int SteeringTypeId { get; set; } } }
//CarDetailWIndow //xaml < Window x: Class = "CarRentalApp.CarDetailWindow" 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:CarRentalApp" mc: Ignorable = "d" Title = "CarDetailWindow" Height = "450" Width = "800" > < ScrollViewer VerticalScrollBarVisibility = "Auto" > < Grid Margin = "10" > < StackPanel > < Image Source = "{Binding ImagePath}" Height = "200" Stretch = "Uniform" Margin = "0 0 0 10" /> < TextBlock Text = "{Binding Name}" FontSize = "20" FontWeight = "Bold" Margin = "0 0 0 10" TextAlignment = "Center" /> < TextBlock Text = "Год выпуска:" FontWeight = "Bold" /> < TextBlock Text = "{Binding Year}" FontSize = "16" FontWeight = "Bold" Margin = "0 0 0 5" /> < TextBlock Text = "Цена за сутки:" FontWeight = "Bold" /> < TextBlock Text = "{Binding PricePerDay}" FontSize = "16" FontWeight = "Bold" Margin = "0 0 0 5" /> < TextBlock Text = "Описание:" FontWeight = "Bold" /> < TextBlock Text = "{Binding Description}" TextWrapping = "Wrap" Margin = "0 0 0 20" /> < Button Content = "Закрыть" Width = "100" HorizontalAlignment = "Center" Click = "CloseButton_Click" /> </ StackPanel >
</ Grid >
</ ScrollViewer >
</ Window >
//c# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes;
namespace CarRentalApp { /// <summary> /// Логика взаимодействия для CarDetailWindow.xaml /// </summary> public partial class CarDetailWindow : Window { public CarDetailWindow(Car car) { InitializeComponent(); DataContext = car; } private void CloseButton_Click(object sender, RoutedEventArgs e) { this.Close(); } } }
//DeleteCarWindow //xaml < Window x: Class = "CarRentalApp.DeleteCarWindow" 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:CarRentalApp" mc: Ignorable = "d" Title = "Удаление машины" Height = "150" Width = "250" WindowStartupLocation = "CenterScreen" > < Grid Margin = "10" > < StackPanel VerticalAlignment = "Top" HorizontalAlignment = "Center" Margin = "0 0 0 10" > < TextBlock Text = "Вы действительно хотите удалить:" FontWeight = "Bold" Margin = "0 0 0 5" /> < TextBlock Text = "{Binding Name}" FontSize = "14" Foreground = "DarkRed" /> </ StackPanel > < StackPanel Orientation = "Horizontal" HorizontalAlignment = "Center" VerticalAlignment = "Bottom" > < Button Content = "Удалить" Height = "30" Width = "80" Click = "DeleteCarButton_Click" /> < Button Content = "Отменить" Height = "30" Width = "80" Margin = "10 0 0 0" Click = "CancelDeleteCarButton_Click" /> </ StackPanel > </ Grid > </ Window >
//c# using System; using System.Windows; using Npgsql;
namespace CarRentalApp { public partial class DeleteCarWindow : Window { private readonly Car _car;
public DeleteCarWindow(Car car)
{
InitializeComponent();
_car = car;
DataContext = car;
}
private void DeleteCarButton_Click(object sender, RoutedEventArgs e)
{
string connectionString = "Host=localhost;Port=5432;Username=postgres;Password=1234;Database=postgres;SearchPath=car_rental_system";
using var connection = new NpgsqlConnection(connectionString);
try
{
connection.Open();
string query = "DELETE FROM cars WHERE id = @id";
using var command = new NpgsqlCommand(query, connection);
command.Parameters.AddWithValue("id", _car.Id);
int result = command.ExecuteNonQuery();
if (result > 0)
{
MessageBox.Show("Машина успешно удалена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
MessageBox.Show("Машина не найдена в базе данных.", "Информация", MessageBoxButton.OK, MessageBoxImage.Warning);
}
this.Close();
}
catch (Exception ex)
{
MessageBox.Show("Ошибка удаления: " + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void CancelDeleteCarButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
//EditCarWindow //xaml < Window x: Class = "CarRentalApp.EditCarWindow" 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:CarRentalApp" mc: Ignorable = "d" Title = "EditCarWindow" Height = "450" Width = "800" > < Grid Margin = "10" > < StackPanel > < TextBlock Text = "Название машины:" /> < TextBox x: Name = "NameTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Год выпуска:" />
< TextBox x: Name = "YearTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Цена за сутки:" />
< TextBox x: Name = "PriceTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Объём бака (литры):" />
< TextBox x: Name = "FuelCapacityTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Количество мест:" />
< TextBox x: Name = "SeatsTextBox" Margin = "0 0 0 10" />
< TextBlock Text = "Описание машины:" />
< TextBox x: Name = "DescriptionTextBox" Margin = "0 0 0 10" Height = "60" TextWrapping = "Wrap" AcceptsReturn = "True" />
< TextBlock Text = "Тип руля:" />
< ComboBox x: Name = "SteeringTypeComboBox" Margin = "0 0 0 10" >
< ComboBoxItem Content = "Левый" Tag = "1" />
< ComboBoxItem Content = "Правый" Tag = "2" />
< ComboBoxItem Content = "Центр" Tag = "3" />
</ ComboBox >
< Button Content = "Сохранить изменения" Width = "150" HorizontalAlignment = "Center" Click = "SaveButton_Click" />
</ StackPanel >
</ Grid >
</ Window >
//c#
using System.Windows; using System.Windows.Controls; using Npgsql;
namespace CarRentalApp { /// <summary> /// Логика взаимодействия для EditCarWindow.xaml /// </summary> public partial class EditCarWindow : Window { private readonly Car _car; public EditCarWindow(Car car) { InitializeComponent(); _car = car; FillFields(); } private void FillFields() { NameTextBox.Text = _car.Name; YearTextBox.Text = _car.Year.ToString(); PriceTextBox.Text = _car.PricePerDay.ToString(); FuelCapacityTextBox.Text = _car.FuelCapacity.ToString(); SeatsTextBox.Text = _car.Seats.ToString(); DescriptionTextBox.Text = _car.Description;
if (_car.SteeringTypeId == 1)
SteeringTypeComboBox.SelectedIndex = 0; // Левый
else if (_car.SteeringTypeId == 2)
SteeringTypeComboBox.SelectedIndex = 1; // Правый
else if (_car.SteeringTypeId == 3)
SteeringTypeComboBox.SelectedIndex = 2; // Центр
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
string connectionString = "Host=localhost;Port=5432;Username=postgres;Password=1234;Database=postgres;SearchPath=car_rental_system";
using var connection = new NpgsqlConnection(connectionString);
try
{
connection.Open();
string query = @"update cars set name = @name, year = @year,
price_per_day = @price,
fuel_capacity = @fuel,
seats = @seats,
description = @description,
steering_type_id = @steeringTypeId
where id = @id";
var command = new NpgsqlCommand(query, connection);
command.Parameters.AddWithValue("@name", NameTextBox.Text);
command.Parameters.AddWithValue("@year", int.Parse(YearTextBox.Text));
command.Parameters.AddWithValue("@price", decimal.Parse(PriceTextBox.Text));
command.Parameters.AddWithValue("@fuel", int.Parse(FuelCapacityTextBox.Text));
command.Parameters.AddWithValue("@seats", int.Parse(SeatsTextBox.Text));
command.Parameters.AddWithValue("@description", DescriptionTextBox.Text);
var selectedItem = (ComboBoxItem)SteeringTypeComboBox.SelectedItem;
int steeringTypeId = int.Parse(selectedItem.Tag.ToString());
command.Parameters.AddWithValue("@steeringTypeId", steeringTypeId);
command.Parameters.AddWithValue("@id", _car.Id);
command.ExecuteNonQuery();
MessageBox.Show("Машина успешно обновлена!");
this.Close();
}
catch (System.Exception ex)
{
MessageBox.Show("Ошибка обновления:" + ex.Message);
}
}
}
}
//MainWindow //xaml < Window x: Class = "CarRentalApp.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:CarRentalApp" mc: Ignorable = "d" Title = "MainWindow" Height = "450" Width = "800" > < Grid Margin = "10" > < Grid.RowDefinitions > < RowDefinition Height = "*" /> < RowDefinition Height = "Auto" /> </ Grid.RowDefinitions > < DataGrid x: Name = "CarsDataGrid" AutoGenerateColumns = "False" Margin = "10" IsReadOnly = "False" CanUserAddRows = "False" > < DataGrid.Columns > < DataGridTextColumn Header = "ID" Binding = "{Binding Id}" Width = "Auto" /> < DataGridTextColumn Header = "Название машины" Binding = "{Binding Name}" Width = "Auto" /> < DataGridTextColumn Header = "Год выпуска" Binding = "{Binding Year}" Width = "Auto" /> < DataGridTextColumn Header = "Цена за сутки" Binding = "{Binding PricePerDay}" Width = "Auto" /> </ DataGrid.Columns > </ DataGrid > < StackPanel Grid.Row = "1" Orientation = "Horizontal" HorizontalAlignment = "Center" > < Button Content = "Добавить машину" Width = "150" Height = "40" Click = "AddCarButton_Click" /> < Button Content = "Редактировать машину" Margin = "10 0 0 0" Width = "150" Height = "40" Click = "EditCarButton_Click" /> < Button Content = "Удалить машину" Margin = "10 0 0 0" Width = "150" Height = "40" Click = "DeleteCarButton_Click" /> </ StackPanel > </ Grid > </ Window >
//c# using System; using System.Data; using System.Linq.Expressions; using System.Windows; using Npgsql;
namespace CarRentalApp { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CarsDataGrid.MouseDoubleClick += CarsDataGrid_MouseDoubleClick; LoadCars(); }
private void LoadCars()
{
string connectionString = "Host=localhost;Port=5432;Username=postgres;Password=1234;Database=postgres;SearchPath=car_rental_system";
var cars = new List<Car>();
using var connection = new NpgsqlConnection(connectionString);
try
{
connection.Open();
string query = "select id, name, year, price_per_day, description, image_path from cars";
var command = new NpgsqlCommand(query, connection);
var reader = command.ExecuteReader();
while (reader.Read())
{
var car = new Car
{
Id = reader.GetInt32(0),
Name = reader.GetString(1),
Year = reader.GetInt32(2),
PricePerDay = reader.GetDecimal(3),
Description = reader.IsDBNull(4) ? "" : reader.GetString(4),
ImagePath = reader.IsDBNull(5) ? "" : reader.GetString(5)
};
cars.Add(car);
}
}
catch (System.Exception ex)
{
MessageBox.Show("Ошибка подключения: " + ex.Message);
}
CarsDataGrid.ItemsSource = cars;
}
private void CarsDataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (CarsDataGrid.SelectedItem is Car selectedCar)
{
var detailWindow = new CarDetailWindow(selectedCar);
detailWindow.ShowDialog();
}
}
private void AddCarButton_Click(object sender, RoutedEventArgs e)
{
var addCarWindow = new AddCarWindow();
addCarWindow.ShowDialog();
LoadCars();
}
private void EditCarButton_Click(object sender, RoutedEventArgs e)
{
if (CarsDataGrid.SelectedItem is Car selectedCar)
{
var editCarWindow = new EditCarWindow(selectedCar);
editCarWindow.ShowDialog();
LoadCars();
}
else
{
MessageBox.Show("Пожалуйста, выберите машину для редактирования");
}
}
private void DeleteCarButton_Click(Object sender, RoutedEventArgs e)
{
if (CarsDataGrid.SelectedItem is Car selectedCar)
{
var deleteCarWindow = new DeleteCarWindow(selectedCar);
deleteCarWindow.ShowDialog();
LoadCars();
}
else
{
MessageBox.Show("Пожалуйста, выберите машину для удаления");
}
}
}
}
//bd CREATE TABLE cars ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, year INT NOT NULL, fuel_capacity DECIMAL(5,2) NOT NULL, seats INT NOT NULL, price_per_day DECIMAL(10,2) NOT NULL, steering_type VARCHAR(50), description TEXT );
CREATE TABLE rentals ( id SERIAL PRIMARY KEY, car_id INT NOT NULL, rental_date DATE NOT NULL, return_date DATE, customer_name VARCHAR(100), CONSTRAINT fk_car FOREIGN KEY (car_id) REFERENCES cars(id) ON DELETE CASCADE );
INSERT INTO cars (name, year, fuel_capacity, seats, price_per_day, steering_type, description) VALUES ('Toyota Corolla', 2020, 50.0, 5, 3000.00, 'Left', 'Compact reliable car'), ('BMW X5', 2021, 85.0, 5, 7000.00, 'Left', 'Luxury SUV'), ('Honda Civic', 2019, 47.0, 5, 2500.00, 'Right', 'Economical city car'), ('Tesla Model 3', 2022, 0.0, 5, 10000.00, 'Left', 'Electric car, no fuel tank');
insert into rentals (car_id, rental_date, return_date, customer_name) values (1,'2024-04-25', '2024-04-28','Ivan Petrov'), (2,'2024-04-26', null,'Maria Ivanova'), (3,'2024-04-27','2024-05-01','Sergey Smirnov');
select * from cars; select name, price_per_day from cars; select * from cars where price_per_day < 5000;
select rentals.id, rentals.customer_name, rentals.rental_date, rentals.return_date, cars.name as car_name from rentals join cars on rentals.car_id = cars.id;
create table steering_types( id serial primary key, name varchar(50) not null );
insert into steering_types (name) values ('Left'), ('Right'), ('Center');
alter table cars drop column steering_type;
alter table cars add column steering_type_id int, add constraint fk_steering_type foreign key (steering_type_id) references steering_types(id);
update cars set steering_type_id = 1 where id = 1; UPDATE cars SET steering_type_id = 1 WHERE id = 2; UPDATE cars SET steering_type_id = 2 WHERE id = 3; UPDATE cars SET steering_type_id = 1 WHERE id = 4;
select cars.id, cars.name, cars.year, cars.fuel_capacity, cars.seats, cars.price_per_day, steering_types.name as steering_type, cars.description from cars join steering_types on cars.steering_type_id = steering_types.id;
alter table cars add column image_path text;
UPDATE cars SET image_path = 'Images/toyota_corolla.png' WHERE id = 1; UPDATE cars SET image_path = 'Images/bmw_x5.png' WHERE id = 2; UPDATE cars SET image_path = 'Images/honda_civic.png' WHERE id = 3; UPDATE cars SET image_path = 'Images/tesla_model3.png' WHERE id = 4;
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net8.0-windows was computed. net9.0-windows was computed. net10.0-windows was computed. |
-
net6.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 141 | 6/18/2025 |