Better model getting point how it works

This commit is contained in:
oreshki
2026-04-07 17:46:54 +05:00
parent b8aa8c44b2
commit 5274f8ed3f
31 changed files with 162 additions and 99 deletions

View File

@@ -13,6 +13,6 @@
</providers> </providers>
</entityFramework> </entityFramework>
<connectionStrings> <connectionStrings>
<add name="LaboratoryDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PC311-11;initial catalog=LaboratoryDB;integrated security=True;trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> <add name="LaboratoryDBEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=PC311-11;initial catalog=LaboratoryDB;integrated security=True;trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings> </connectionStrings>
</configuration> </configuration>

View File

@@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Labaratory" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:local="clr-namespace:Labaratory" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
StartupUri="MainWindow.xaml"> StartupUri="Views/MainWindow.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>

View File

@@ -89,67 +89,68 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="Analyzer.cs"> <Compile Include="Models\Analyzer.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Analyzer_Logs.cs"> <Compile Include="Models\Analyzer_Logs.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="BaseViewModel.cs" /> <Compile Include="Services\Valid.cs" />
<Compile Include="Insurance_Companies.cs"> <Compile Include="ViewModels\BaseViewModel.cs" />
<Compile Include="Models\Insurance_Companies.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Invoice.cs"> <Compile Include="Models\Invoice.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="LoginViewModel.cs" /> <Compile Include="ViewModels\LoginViewModel.cs" />
<Compile Include="Model1.Context.cs"> <Compile Include="Models\Model1.Context.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Model1.Context.tt</DependentUpon> <DependentUpon>Model1.Context.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Model1.cs"> <Compile Include="Models\Model1.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Model1.Designer.cs"> <Compile Include="Models\Model1.Designer.cs">
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
<DependentUpon>Model1.edmx</DependentUpon> <DependentUpon>Model1.edmx</DependentUpon>
</Compile> </Compile>
<Compile Include="Order.cs"> <Compile Include="Models\Order.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Order_Items.cs"> <Compile Include="Models\Order_Items.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Order_Statuses.cs"> <Compile Include="Models\Order_Statuses.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Patient.cs"> <Compile Include="Models\Patient.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Policy_Types.cs"> <Compile Include="Models\Policy_Types.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Rendered_Services.cs"> <Compile Include="Models\Rendered_Services.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Role.cs"> <Compile Include="Models\Role.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Service.cs"> <Compile Include="Models\Service.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Service_Statuses.cs"> <Compile Include="Models\Service_Statuses.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="SessionManager.cs" /> <Compile Include="Services\SessionManager.cs" />
<Compile Include="User.cs"> <Compile Include="Models\User.cs">
<DependentUpon>Model1.tt</DependentUpon> <DependentUpon>Model1.tt</DependentUpon>
</Compile> </Compile>
<Page Include="MainWindow.xaml"> <Page Include="Views\MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
@@ -157,7 +158,7 @@
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="MainWindow.xaml.cs"> <Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon> <DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@@ -180,11 +181,11 @@
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource> </EmbeddedResource>
<EntityDeploy Include="Model1.edmx"> <EntityDeploy Include="Models\Model1.edmx">
<Generator>EntityModelCodeGenerator</Generator> <Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>Model1.Designer.cs</LastGenOutput> <LastGenOutput>Model1.Designer.cs</LastGenOutput>
</EntityDeploy> </EntityDeploy>
<None Include="Model1.edmx.diagram"> <None Include="Models\Model1.edmx.diagram">
<DependentUpon>Model1.edmx</DependentUpon> <DependentUpon>Model1.edmx</DependentUpon>
</None> </None>
<None Include="packages.config" /> <None Include="packages.config" />
@@ -197,12 +198,12 @@
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Model1.Context.tt"> <Content Include="Models\Model1.Context.tt">
<Generator>TextTemplatingFileGenerator</Generator> <Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Model1.Context.cs</LastGenOutput> <LastGenOutput>Model1.Context.cs</LastGenOutput>
<DependentUpon>Model1.edmx</DependentUpon> <DependentUpon>Model1.edmx</DependentUpon>
</Content> </Content>
<Content Include="Model1.tt"> <Content Include="Models\Model1.tt">
<Generator>TextTemplatingFileGenerator</Generator> <Generator>TextTemplatingFileGenerator</Generator>
<DependentUpon>Model1.edmx</DependentUpon> <DependentUpon>Model1.edmx</DependentUpon>
<LastGenOutput>Model1.cs</LastGenOutput> <LastGenOutput>Model1.cs</LastGenOutput>

View File

@@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace Labaratory
{
public class LoginViewModel : BaseViewModel
{
private string _login;
private string _captchaText;
private bool _isCaptchaVisible;
public string Login
{
get => _login;
set { _login = value; OnPropertyChanged(); }
}
public bool IsCaptchaVisible
{
get => _isCaptchaVisible;
set { _isCaptchaVisible = value; OnPropertyChanged(); }
}
public ICommand LoginCommand { get; }
public LoginViewModel()
{
// Инициализация команд и капчи
}
}
}

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Data.Entity; using System.Data.Entity;

View File

@@ -1,4 +1,4 @@
// Создание кода T4 для модели "C:\Users\usersql\source\repos\UP01TASK3\Labaratory\Labaratory\Model1.edmx" включено. // Создание кода T4 для модели "C:\Users\usersql\source\repos\UP01TASK3\Labaratory\Labaratory\Models\Model1.edmx" включено.
// Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора // Чтобы включить формирование кода прежних версий, измените значение свойства "Стратегия создания кода" конструктора
// на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель // на "Legacy ObjectContext". Это свойство доступно в окне "Свойства", если модель
// открыта в конструкторе. // открыта в конструкторе.

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -7,7 +7,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace Labaratory namespace Labaratory.Models
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Labaratory.Services
{
public static class Valid
{
public static string GenerateCaptchaText()
{
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
Random rand = new Random();
return new string(Enumerable.Repeat(chars, 4)
.Select(s => s[rand.Next(s.Length)]).ToArray());
}
public static bool IsPasswordStrong(string password)
{
return false;
}
public static bool ValidateCaptcha(string input, string original)
{
if (string.IsNullOrEmpty(input)) return false;
return input.Trim().ToUpper() == original.ToUpper();
}
}
}

View File

@@ -0,0 +1,78 @@
using Labaratory.Services;
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Wpf.Ui.Input;
namespace Labaratory
{
public class LoginViewModel : BaseViewModel
{
private string _login;
private string _password;
private string _captchaText;
private string _captchaInput;
private bool _isCaptchaVisible;
private bool _isLoginEnabled = true;
private int _failedAttempts = 0;
private Models.LaboratoryDBEntities db = new Models.LaboratoryDBEntities();
// Свойства для привязки (Binding)
public string Login { get => _login; set { _login = value; OnPropertyChanged(); } }
public string Password { get => _password; set { _password = value; OnPropertyChanged(); } }
public string CaptchaText { get => _captchaText; set { _captchaText = value; OnPropertyChanged(); } }
public string CaptchaInput { get => _captchaInput; set { _captchaInput = value; OnPropertyChanged(); } }
public bool IsCaptchaVisible { get => _isCaptchaVisible; set { _isCaptchaVisible = value; OnPropertyChanged(); } }
public bool IsLoginEnabled { get => _isLoginEnabled; set { _isLoginEnabled = value; OnPropertyChanged(); } }
// Команды
public ICommand LoginCommand { get; }
public ICommand RefreshCaptchaCommand { get; }
public LoginViewModel()
{
LoginCommand = new RelayCommand<object>(execute => ExecuteLogin());
RefreshCaptchaCommand = new RelayCommand<object>(execute => GenerateNewCaptcha());
}
private void GenerateNewCaptcha()
{
CaptchaText = Valid.GenerateCaptchaText();
CaptchaInput = string.Empty;
}
private async void ExecuteLogin()
{
if (IsCaptchaVisible && !Valid.ValidateCaptcha(CaptchaInput, CaptchaText))
{
MessageBox.Show("Неверная капча!");
GenerateNewCaptcha();
await LockSystem(10); //Блокировка на 10 сек
return;
}
if (Login == "admin" && Password == "123")
{
MessageBox.Show("Успешный вход!");
}
else
{
MessageBox.Show("Неверный логин или пароль");
IsCaptchaVisible = true;
GenerateNewCaptcha();
}
}
private async Task LockSystem(int seconds)
{
IsLoginEnabled = false;
await Task.Delay(TimeSpan.FromSeconds(seconds));
IsLoginEnabled = true;
}
}
}

View File

@@ -1,4 +1,5 @@
using System; using Labaratory.Models;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -28,34 +29,22 @@ namespace Labaratory
InitializeComponent(); InitializeComponent();
DataContext = new LoginViewModel(); DataContext = new LoginViewModel();
} }
private void GenerateCaptcha()
{
const string chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
Random rand = new Random();
_activeCaptcha = new string(Enumerable.Repeat(chars, 5)
.Select(s => s[rand.Next(s.Length)]).ToArray());
CaptchaVisual.Text = _activeCaptcha;
CaptchaInput.Clear();
}
private void RefreshCaptcha_Click(object sender, RoutedEventArgs e) private void RefreshCaptcha_Click(object sender, RoutedEventArgs e)
{ {
GenerateCaptcha();
} }
private void LoginButton_Click(object sender, RoutedEventArgs e) private void LoginButton_Click(object sender, RoutedEventArgs e)
{ {
if (CaptchaInput.Visibility == Visibility.Visible) if (CaptchaInput.Visibility != Visibility.Visible)
{ {
Login(); Login();
} }
else else
{ {
MessageBox.Show("Неверная капча!"); MessageBox.Show("Неверный логин или пароль!");
GenerateCaptcha(); //GenerateCaptcha();
} }
if (CaptchaInput.Visibility != Visibility.Visible) if (CaptchaInput.Visibility != Visibility.Visible)
@@ -65,12 +54,12 @@ namespace Labaratory
else else
{ {
MessageBox.Show("Неверная капча!"); MessageBox.Show("Неверная капча!");
GenerateCaptcha(); //GenerateCaptcha();
} }
} }
private bool Login() private bool Login()
{ {
return false;
} }
} }