init
This commit is contained in:
commit
fcad583362
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
28
Hard_Demo.sln
Normal file
28
Hard_Demo.sln
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hard_Demo", "Hard_Demo\Hard_Demo.csproj", "{894A6AE0-1ADB-47E1-959E-827D0BBA9445}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library", "Library\Library.csproj", "{F8410716-956E-41CD-BF67-B3BEF201633E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{5E1E0CBB-9205-4031-9A61-6910A62A476C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{894A6AE0-1ADB-47E1-959E-827D0BBA9445}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{894A6AE0-1ADB-47E1-959E-827D0BBA9445}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{894A6AE0-1ADB-47E1-959E-827D0BBA9445}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{894A6AE0-1ADB-47E1-959E-827D0BBA9445}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F8410716-956E-41CD-BF67-B3BEF201633E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F8410716-956E-41CD-BF67-B3BEF201633E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F8410716-956E-41CD-BF67-B3BEF201633E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F8410716-956E-41CD-BF67-B3BEF201633E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5E1E0CBB-9205-4031-9A61-6910A62A476C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5E1E0CBB-9205-4031-9A61-6910A62A476C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5E1E0CBB-9205-4031-9A61-6910A62A476C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5E1E0CBB-9205-4031-9A61-6910A62A476C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
36
Hard_Demo/AddClient.axaml
Normal file
36
Hard_Demo/AddClient.axaml
Normal file
@ -0,0 +1,36 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Hard_Demo.AddClient"
|
||||
x:CompileBindings="False"
|
||||
Title="FunctionWindow">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" DockPanel.Dock="Top">
|
||||
<TextBlock Text="Добавление пользователя" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<StackPanel DockPanel.Dock="Left" HorizontalAlignment="Left" Orientation="Vertical" Margin="10">
|
||||
<TextBlock Text="Код клиента"/>
|
||||
<TextBox x:Name="CodeBox" Width="250" HorizontalAlignment="Left" />
|
||||
<TextBlock Text="ФИО клиента"/>
|
||||
<TextBox x:Name="FIOBox" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="Email клиента"/>
|
||||
<TextBox x:Name="EmailBox" Width="250" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="Адрес клиента"/>
|
||||
<TextBox x:Name="AddressBox" Width="250" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="Дата рождения клиента"/>
|
||||
<TextBox x:Name="BirthdayBox" Width="250" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="Серия и номер паспорта клиента"/>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBox x:Name="SeriesBox" Width="30" HorizontalAlignment="Left"/>
|
||||
<TextBox x:Name="NumberPassBox" Width="71" HorizontalAlignment="Left"/>
|
||||
</StackPanel>
|
||||
<TextBlock Text="Пароль клиента"/>
|
||||
<TextBox x:Name="PasswordBox" Width="250" HorizontalAlignment="Left"/>
|
||||
<Button Content="Добавить пользователя" Margin="10" Width="250" Click="AddClient_OnClick" HorizontalAlignment="Left"/>
|
||||
<TextBlock Text="" x:Name="UserOutput" Margin="20" HorizontalAlignment="Left"/>
|
||||
<Button Content="Назад" HorizontalAlignment="Left" Margin="10" Width="200" Click="BackToOrder"/>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Window>
|
107
Hard_Demo/AddClient.axaml.cs
Normal file
107
Hard_Demo/AddClient.axaml.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Hard_Demo.Models;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class AddClient : Window
|
||||
{
|
||||
public List<int> ClientIds = new List<int>();
|
||||
public AddClient()
|
||||
{
|
||||
InitializeComponent();
|
||||
using var contextForId = new User2Context();
|
||||
ClientIds = contextForId.Clients.Select(c => c.Id).ToList();
|
||||
|
||||
}
|
||||
|
||||
public bool CheckInput()
|
||||
{
|
||||
if (CodeBox.Text.Length != 8)
|
||||
{
|
||||
UserOutput.Text ="В коде клиента должно быть ровно 8 символов";
|
||||
return false;
|
||||
}
|
||||
if(SeriesBox.Text.Length!=4 || NumberPassBox.Text.Length!=6)
|
||||
{
|
||||
UserOutput.Text ="Неверно введены паспортные данные";
|
||||
return false;
|
||||
}
|
||||
string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|" + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)" + @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
|
||||
var regex = new Regex(pattern, RegexOptions.IgnoreCase);
|
||||
if(!(regex.IsMatch(EmailBox.Text)))
|
||||
{
|
||||
UserOutput.Text ="Введите корректный email";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DateOnly.TryParse(BirthdayBox.Text, out DateOnly birthday))
|
||||
{
|
||||
UserOutput.Text = "Введите корректную дату рождения";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddClient_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
using var context = new User2Context();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(CodeBox.Text) || string.IsNullOrWhiteSpace(FIOBox.Text) ||
|
||||
string.IsNullOrWhiteSpace(EmailBox.Text) || string.IsNullOrWhiteSpace(AddressBox.Text) ||
|
||||
string.IsNullOrWhiteSpace(BirthdayBox.Text) || string.IsNullOrWhiteSpace(SeriesBox.Text) ||
|
||||
string.IsNullOrWhiteSpace(NumberPassBox.Text) || string.IsNullOrWhiteSpace(PasswordBox.Text))
|
||||
{
|
||||
UserOutput.Text = "Пожалуйста заполните все поля";
|
||||
return;
|
||||
}
|
||||
|
||||
if (CheckInput())
|
||||
{
|
||||
try
|
||||
{
|
||||
var passport = SeriesBox.Text + NumberPassBox.Text;
|
||||
var newClient = new Client
|
||||
{
|
||||
Id = ClientIds.Last() + 1,
|
||||
Fio = FIOBox.Text,
|
||||
Email = EmailBox.Text,
|
||||
ClientCode = Convert.ToInt32(CodeBox.Text),
|
||||
Passport = passport,
|
||||
Birthday = DateOnly.Parse(BirthdayBox.Text),
|
||||
Address = AddressBox.Text,
|
||||
Password = PasswordBox.Text,
|
||||
RoleId = 4
|
||||
};
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
|
||||
UserOutput.Text = "Клиент успешно добавлен";
|
||||
|
||||
FIOBox.Text = "";
|
||||
CodeBox.Text = "";
|
||||
EmailBox.Text = "";
|
||||
PasswordBox.Text = "";
|
||||
SeriesBox.Text = "";
|
||||
NumberPassBox.Text = "";
|
||||
AddressBox.Text = "";
|
||||
BirthdayBox.Text = "";
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
CheckInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BackToOrder(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new OrderWindow().ShowDialog(this);
|
||||
}
|
||||
}
|
10
Hard_Demo/App.axaml
Normal file
10
Hard_Demo/App.axaml
Normal file
@ -0,0 +1,10 @@
|
||||
<Application xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="Hard_Demo.App"
|
||||
RequestedThemeVariant="Default">
|
||||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||
|
||||
<Application.Styles>
|
||||
<FluentTheme />
|
||||
</Application.Styles>
|
||||
</Application>
|
23
Hard_Demo/App.axaml.cs
Normal file
23
Hard_Demo/App.axaml.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class App : Application
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
desktop.MainWindow = new MainWindow();
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
}
|
31
Hard_Demo/EnterHistoryWindow.axaml
Normal file
31
Hard_Demo/EnterHistoryWindow.axaml
Normal file
@ -0,0 +1,31 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Hard_Demo.EnterHistoryWindow"
|
||||
x:CompileBindings="False"
|
||||
Title="EnterHistoryWindow">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TextBlock Text="История входа сотрудников" TextAlignment="Center" FontWeight="Bold" FontSize="20" Margin="0,0,0,10" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<ComboBox x:Name="LoginComboBox" DataContext="{Binding Login}" SelectionChanged="LoginComboBox_OnSelectionChanged"/>
|
||||
<Button Content="Отсортировать по дате по возрастанию" Click="Button_Asc" ></Button>
|
||||
<Button Content="Отсортировать по дате по убыванию" Click="Button_Desc" ></Button>
|
||||
</StackPanel>
|
||||
<ListBox x:Name="lastEnters">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="80">
|
||||
<TextBlock Text="{Binding EmployeId}"></TextBlock>
|
||||
<TextBlock Text="{Binding Login}"></TextBlock>
|
||||
<TextBlock Text="{Binding EnterDatetime}"></TextBlock>
|
||||
<TextBlock Text="{Binding EnterType}"></TextBlock>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Window>
|
81
Hard_Demo/EnterHistoryWindow.axaml.cs
Normal file
81
Hard_Demo/EnterHistoryWindow.axaml.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Hard_Demo.Models;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class EnterHistoryWindow : Window
|
||||
{
|
||||
private ObservableCollection<LastEnter> lastEnter = new();
|
||||
public List<LastEnter> dataLastEnter;
|
||||
public bool sort = true;
|
||||
public EnterHistoryWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
using var context = new User2Context();
|
||||
|
||||
|
||||
dataLastEnter = context.LastEnters.Select(it => new LastEnter
|
||||
{
|
||||
EmployeId = it.EmployeId,
|
||||
EnterDatetime = it.EnterDatetime,
|
||||
EnterType = it.EnterType,
|
||||
Login = it.Login
|
||||
}).ToList();
|
||||
|
||||
foreach (var newlastEnter in dataLastEnter)
|
||||
{
|
||||
lastEnter.Add(newlastEnter);
|
||||
}
|
||||
lastEnters.ItemsSource = lastEnter;
|
||||
LoginComboBox.ItemsSource = dataLastEnter.Select(it => it.Login);
|
||||
SortLogin();
|
||||
}
|
||||
|
||||
private void SortLogin()
|
||||
{
|
||||
var temp = dataLastEnter;
|
||||
if (LoginComboBox.SelectedItem is String login)
|
||||
{
|
||||
temp = temp.Where(it => it.Login == login).ToList();
|
||||
}
|
||||
temp=sort ? temp.OrderBy(it => it.Login).ToList() : temp.OrderByDescending(it => it.Login).ToList();
|
||||
|
||||
lastEnter.Clear();
|
||||
foreach (var userlogin in temp)
|
||||
{
|
||||
lastEnter.Add(userlogin);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoginComboBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
sort=!sort;
|
||||
SortLogin();
|
||||
}
|
||||
|
||||
private void Button_Asc(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var sortedList = dataLastEnter.OrderBy(it => it.EnterDatetime).ToList();
|
||||
lastEnter.Clear();
|
||||
foreach (var item in sortedList)
|
||||
{
|
||||
lastEnter.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Button_Desc(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var sortedList = dataLastEnter.OrderByDescending(it => it.EnterDatetime).ToList();
|
||||
lastEnter.Clear();
|
||||
foreach (var descList in sortedList)
|
||||
{
|
||||
lastEnter.Add(descList);
|
||||
}
|
||||
}
|
||||
}
|
31
Hard_Demo/FunctionWindow.axaml
Normal file
31
Hard_Demo/FunctionWindow.axaml
Normal file
@ -0,0 +1,31 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Hard_Demo.FunctionWindow"
|
||||
x:CompileBindings="False"
|
||||
Title="FunctionWindow">
|
||||
<DockPanel>
|
||||
<StackPanel DockPanel.Dock="Top" HorizontalAlignment="Center" Orientation="Horizontal" >
|
||||
<StackPanel>
|
||||
<Image Source="{Binding Image}" Width="100" Height="100" Margin="5" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<TextBlock x:Name="Fio">
|
||||
<Run Text="ФИО:"/>
|
||||
<Run Text="{Binding Fio}"/>
|
||||
</TextBlock>
|
||||
<TextBlock>
|
||||
<Run Text="Роль:"/>
|
||||
<Run Text="{Binding RoleId}"/>
|
||||
</TextBlock>
|
||||
<TextBlock x:Name="Timer" Text="10:00" />
|
||||
<TextBlock Text="" HorizontalAlignment="Center" Margin="10" x:Name="WarningBlock"/>
|
||||
</StackPanel>
|
||||
<Button Content="Назад" Click="Back_Button"/>
|
||||
<Button Content="История входа" Click="Next_Function_Button" IsVisible="{Binding IsRole2}"/>
|
||||
<Button Content="Создание заказа" Click="newOrder_OnClick"></Button>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Window>
|
107
Hard_Demo/FunctionWindow.axaml.cs
Normal file
107
Hard_Demo/FunctionWindow.axaml.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Mime;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Media.Imaging;
|
||||
using Hard_Demo.Models;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class FunctionWindow : Window
|
||||
{
|
||||
private readonly TimeSpan sessionDuration = TimeSpan.FromMinutes(10);
|
||||
private readonly TimeSpan warningTime = TimeSpan.FromMinutes(5);
|
||||
private DateTime sessionStartTime;
|
||||
private bool warningShow = false;
|
||||
|
||||
public FunctionWindow(Employee user)
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new ImageEmployee()
|
||||
{
|
||||
EmployeId = user.EmployeId,
|
||||
Fio = user.Fio,
|
||||
EmployeLogin = user.EmployeLogin,
|
||||
EmployePassword = user.EmployePassword,
|
||||
RoleId = user.RoleId,
|
||||
EmployePhoto = user.EmployePhoto
|
||||
};
|
||||
|
||||
sessionStartTime = DateTime.Now;
|
||||
StartSessionTimer();
|
||||
}
|
||||
|
||||
private async void StartSessionTimer()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
TimeSpan ellapsedTime = DateTime.Now - sessionStartTime;
|
||||
TimeSpan remainingTime = sessionDuration - ellapsedTime;
|
||||
this.FindControl<TextBlock>("Timer").Text = $"Осталось: {remainingTime.Minutes}:{remainingTime.Seconds}";
|
||||
if (!warningShow && remainingTime <= warningTime)
|
||||
{
|
||||
warningShow = true;
|
||||
WarningBlock.Text = "Ваш сеанс закончится через 5 минут.";
|
||||
}
|
||||
|
||||
if (remainingTime <= TimeSpan.Zero)
|
||||
{
|
||||
EndSession();
|
||||
break;
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
private async void EndSession()
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
public FunctionWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private void Back_Button(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new MainWindow().ShowDialog(this);
|
||||
}
|
||||
|
||||
private void Next_Function_Button(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new EnterHistoryWindow().ShowDialog(this);
|
||||
}
|
||||
private void newOrder_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new OrderWindow().ShowDialog(this);
|
||||
}
|
||||
|
||||
|
||||
public class ImageEmployee: Employee
|
||||
{
|
||||
public bool IsRole2 => RoleId == 2;
|
||||
Bitmap? Image
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
string absolutePath = Path.Combine(AppContext.BaseDirectory, EmployePhoto);
|
||||
return new Bitmap(absolutePath);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
29
Hard_Demo/Hard_Demo.csproj
Normal file
29
Hard_Demo/Hard_Demo.csproj
Normal file
@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Avalonia" Version="11.2.1"/>
|
||||
<PackageReference Include="Avalonia.Desktop" Version="11.2.1"/>
|
||||
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1"/>
|
||||
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1"/>
|
||||
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.1">
|
||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
24
Hard_Demo/MainWindow.axaml
Normal file
24
Hard_Demo/MainWindow.axaml
Normal file
@ -0,0 +1,24 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Hard_Demo.MainWindow"
|
||||
x:CompileBindings="True"
|
||||
Title="demo_hard">
|
||||
<DockPanel>
|
||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" DockPanel.Dock="Top">
|
||||
<TextBlock Text="Точки проката горнолыжного комплекса «Благодать»"/>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="5">
|
||||
<TextBlock Text="Введите логин" HorizontalAlignment="Center" Margin="5"/>
|
||||
<TextBox x:Name="LoginBox" Margin="5" Width="200"/>
|
||||
<TextBlock Text="Введите пароль" HorizontalAlignment="Center" Margin="5"/>
|
||||
<TextBox x:Name="PasswordBox" Margin="5" Width="200" PasswordChar="*"/>
|
||||
<TextBlock x:Name="WrongData" Text="" HorizontalAlignment="Center"/>
|
||||
<Button x:Name="ForPassword" Content="Показать пароль" Margin="5" Click="TogglePasswordVisibility" HorizontalAlignment="Center"/>
|
||||
<Button x:Name="Authorize" Content="Авторизироваться" Margin="5" Click="AuthorizeButton" HorizontalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
|
||||
</DockPanel>
|
||||
</Window>
|
43
Hard_Demo/MainWindow.axaml.cs
Normal file
43
Hard_Demo/MainWindow.axaml.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Hard_Demo.Models;
|
||||
//using demo_hard.Models;
|
||||
using Tmds.DBus.Protocol;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void TogglePasswordVisibility(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
PasswordBox.PasswordChar = PasswordBox.PasswordChar == '*' ? '\0' : '*';
|
||||
}
|
||||
|
||||
private void AuthorizeButton(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
using var context = new User2Context();
|
||||
var user = context.Employees.FirstOrDefault(it => it.EmployeLogin == LoginBox.Text && it.EmployePassword == PasswordBox.Text);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
var functionWindow = new FunctionWindow(user);
|
||||
{
|
||||
DataContext = user;
|
||||
};
|
||||
functionWindow.ShowDialog(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
WrongData.Text = "Неверный логин или пароль";
|
||||
}
|
||||
}
|
||||
}
|
45
Hard_Demo/NewOrderWindow.axaml
Normal file
45
Hard_Demo/NewOrderWindow.axaml
Normal file
@ -0,0 +1,45 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Hard_Demo.NewOrderWindow"
|
||||
x:CompileBindings="False"
|
||||
Title="FunctionWindow">
|
||||
<DockPanel>
|
||||
<StackPanel Margin="10" Orientation="Vertical" VerticalAlignment="Center">
|
||||
<TextBlock Text="Данные заказа" FontSize="24" HorizontalAlignment="Center" Margin="10" />
|
||||
<TextBlock Text="Номер заказа" />
|
||||
<TextBlock x:Name="OrderNumberText" />
|
||||
|
||||
<TextBlock Text="Код клиента" />
|
||||
<TextBlock x:Name="ClientCode" />
|
||||
|
||||
<TextBlock Text="Время заказа" />
|
||||
<TextBlock x:Name="TimeOrder" />
|
||||
|
||||
|
||||
<TextBlock Text="ФИО клиента" />
|
||||
<TextBlock x:Name="FIO" />
|
||||
|
||||
|
||||
<TextBlock Text="Адрес клиента" />
|
||||
<TextBlock x:Name="Address" />
|
||||
|
||||
|
||||
<TextBlock Text="Услуги входящие в заказ:" />
|
||||
<ListBox x:Name="ServicesList" Margin="10" Height="200">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<TextBlock Text="Стоимость" />
|
||||
<TextBlock x:Name="Cost" />
|
||||
|
||||
|
||||
<Button Content="Назад" HorizontalAlignment="Center" Margin="10" Click="ButtonBack_OnClick" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</Window>
|
42
Hard_Demo/NewOrderWindow.axaml.cs
Normal file
42
Hard_Demo/NewOrderWindow.axaml.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Hard_Demo.Models;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class NewOrderWindow : Window
|
||||
{
|
||||
|
||||
public NewOrderWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public NewOrderWindow(Client client, List<Service> selectedServices, int duration )
|
||||
{
|
||||
InitializeComponent();
|
||||
using var context = new User2Context();
|
||||
List<int> orderNumbers = new List<int>();
|
||||
orderNumbers = new List<int>(context.Orders.Select(o=>o.Id));
|
||||
|
||||
OrderNumberText.Text = orderNumbers.Count+1.ToString();
|
||||
ClientCode.Text = client.ClientCode.ToString();
|
||||
TimeOrder.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
|
||||
FIO.Text = client.Fio;
|
||||
Address.Text = client.Address;
|
||||
ServicesList.ItemsSource = selectedServices.Select(it => it.ServiceName).ToList();
|
||||
var totalcost = selectedServices.Sum(it =>
|
||||
{
|
||||
var serviceCost = decimal.TryParse(it.ServiceCost, out var cost) ? cost : 0;
|
||||
return cost;
|
||||
});
|
||||
Cost.Text = $"{totalcost}.00 руб.";
|
||||
}
|
||||
|
||||
private void ButtonBack_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new OrderWindow().ShowDialog(this);
|
||||
}
|
||||
}
|
65
Hard_Demo/OrderWindow.axaml
Normal file
65
Hard_Demo/OrderWindow.axaml
Normal file
@ -0,0 +1,65 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
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"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Hard_Demo.OrderWindow"
|
||||
x:CompileBindings="False"
|
||||
Title="demo_hard">
|
||||
<DockPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" DockPanel.Dock="Top" Margin="10">
|
||||
<TextBlock Text="Окно создания нового заказа"/>
|
||||
</StackPanel>
|
||||
<StackPanel DockPanel.Dock="Left" Orientation="Vertical" VerticalAlignment="Center" Margin="10">
|
||||
<TextBlock Text="Поиск" Margin="10" />
|
||||
<TextBox x:Name="SearchBox" Width="200" TextChanged="SearchBox_OnTextChanged"></TextBox>
|
||||
<ListBox x:Name="SearchResultsList">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="10">
|
||||
<TextBlock Text="Место для штрихода" Margin="10" HorizontalAlignment="Center"/>
|
||||
|
||||
<ComboBox x:Name="clientName" Margin="10" HorizontalAlignment="Center" >
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Fio}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<ComboBox x:Name="serviceName" Width="200" HorizontalAlignment="Center" Margin="5">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding ServiceName}"/>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBlock HorizontalAlignment="Center" Margin="5" Text="Продолжительность в минутах"/>
|
||||
<TextBox Width="200" x:Name="Duration" />
|
||||
|
||||
<Button Content="Добавить услугу" HorizontalAlignment="Center" Margin="10" Click="AddService_OnClick" />
|
||||
|
||||
<ListBox x:Name="SelectedServicesListBox" Width="250" Height="100" HorizontalAlignment="Center" Margin="10">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding}"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
|
||||
<Button Content="Назад" Click="Go_Back_Button" HorizontalAlignment="Center" Margin="10"/>
|
||||
<Button Content="Создать штрих код" HorizontalAlignment="Center" Margin="10"/>
|
||||
<Button Content="Добавить Пользователя" Click="AddUser_Button" HorizontalAlignment="Center" Margin="10"/>
|
||||
<Button Content="Создать заказ" Click = "Create_Order" HorizontalAlignment="Center" Margin="10"/>
|
||||
</StackPanel>
|
||||
|
||||
</DockPanel>
|
||||
</Window>
|
131
Hard_Demo/OrderWindow.axaml.cs
Normal file
131
Hard_Demo/OrderWindow.axaml.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Hard_Demo.Models;
|
||||
using Tmds.DBus.Protocol;
|
||||
|
||||
namespace Hard_Demo;
|
||||
|
||||
public partial class OrderWindow : Window
|
||||
{
|
||||
private ObservableCollection<int> _ordersIds = new();
|
||||
private ObservableCollection<string> _clientsNames = new();
|
||||
private ObservableCollection<string> _servicesNames = new();
|
||||
private List<Service> SelectedServices = new();
|
||||
public List<int> OrderIdList;
|
||||
public List<string> ClientNamesList;
|
||||
public List<string> ServicesList;
|
||||
|
||||
public OrderWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
SearchItems();
|
||||
using var context = new User2Context();
|
||||
|
||||
OrderIdList = context.Orders.Select(it => it.Id).ToList();
|
||||
|
||||
var services = context.Services.ToList();
|
||||
serviceName.ItemsSource = services;
|
||||
|
||||
var clients = context.Clients.ToList();
|
||||
clientName.ItemsSource = clients;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void SearchItems()
|
||||
{
|
||||
using var context = new User2Context();
|
||||
string searchText = SearchBox.Text?.ToLower() ?? "";
|
||||
if (string.IsNullOrWhiteSpace(searchText))
|
||||
{
|
||||
SearchResultsList.ItemsSource = new List<string>();
|
||||
return;
|
||||
}
|
||||
|
||||
var clientRes = context.Clients
|
||||
.Where(c => c.Fio.ToLower().Contains(searchText))
|
||||
.Select(c => c.Fio);
|
||||
|
||||
var serviceRes = context.Services
|
||||
.Where(s => s.ServiceName.ToLower().Contains(searchText))
|
||||
.Select(s => s.ServiceName);
|
||||
|
||||
var results = clientRes.Concat(serviceRes).ToList();
|
||||
SearchResultsList.ItemsSource = results;
|
||||
}
|
||||
|
||||
private void SearchBox_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
SearchItems();
|
||||
}
|
||||
|
||||
private void AddService_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (serviceName.SelectedItem is Service selectedService && !SelectedServices.Contains(selectedService))
|
||||
{
|
||||
SelectedServices.Add(selectedService);
|
||||
UpdateServiceList();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateServiceList()
|
||||
{
|
||||
SelectedServicesListBox.ItemsSource = null;
|
||||
SelectedServicesListBox.ItemsSource = SelectedServices.Select(s => s.ServiceName).ToList();
|
||||
}
|
||||
|
||||
|
||||
private void Go_Back_Button(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new FunctionWindow().ShowDialog(this);
|
||||
}
|
||||
|
||||
private void AddUser_Button(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
new AddClient().ShowDialog(this);
|
||||
}
|
||||
|
||||
private void Create_Order(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
Client selectedClient = clientName.SelectedItem as Client;
|
||||
List<Service> selectedServices = new List<Service>(SelectedServices);
|
||||
var duration = int.Parse(Duration.Text);
|
||||
using var context = new User2Context();
|
||||
List<int> orderNumbers = new List<int>();
|
||||
Client client = selectedClient;
|
||||
foreach (var service in selectedServices)
|
||||
{
|
||||
|
||||
orderNumbers = new List<int>(context.Orders.Select(o=>o.Id));
|
||||
|
||||
var newOrder = new Order
|
||||
{
|
||||
Id = orderNumbers.Count+1,
|
||||
OrderCode = client.ClientCode + "/" + DateTime.Now.ToString("dd/MM/yyyy"),
|
||||
OrderDate = DateOnly.FromDateTime(DateTime.Now),
|
||||
OrderTime = TimeOnly.FromDateTime(DateTime.Now),
|
||||
ClientCode = client.ClientCode,
|
||||
ServiceId = service.Id,
|
||||
Status = "Новая",
|
||||
DateClose = null,
|
||||
RentalTime = duration
|
||||
};
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (selectedClient != null && duration!=null && selectedServices.Any())
|
||||
{
|
||||
new NewOrderWindow(selectedClient, selectedServices, duration).ShowDialog(this);
|
||||
}
|
||||
}
|
||||
}
|
18
Hard_Demo/app.manifest
Normal file
18
Hard_Demo/app.manifest
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<!-- This manifest is used on Windows only.
|
||||
Don't remove it as it might cause problems with window transparency and embedded controls.
|
||||
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
|
||||
<assemblyIdentity version="1.0.0.0" name="Hard_Demo.Desktop"/>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- A list of the Windows versions that this application has been tested on
|
||||
and is designed to work with. Uncomment the appropriate elements
|
||||
and Windows will automatically select the most compatible environment. -->
|
||||
|
||||
<!-- Windows 10 -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
</application>
|
||||
</compatibility>
|
||||
</assembly>
|
Loading…
Reference in New Issue
Block a user