Procházet zdrojové kódy

Добавлено несколько новых функций

Fox před 6 měsíci
rodič
revize
7e8931fc9d

+ 2 - 1
App.axaml

@@ -1,7 +1,8 @@
 <Application xmlns="https://github.com/avaloniaui"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              x:Class="LoginGenerator.App"
-             RequestedThemeVariant="Default">
+             RequestedThemeVariant="Default"
+             >
              <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
   
     <Application.Styles>

binární
Assets/logo.ico


+ 17 - 1
LoginGenerator.csproj

@@ -6,13 +6,21 @@
     <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
     <ApplicationManifest>app.manifest</ApplicationManifest>
     <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
+    <ApplicationIcon>Assets\logo.ico</ApplicationIcon>
   </PropertyGroup>
 
   <ItemGroup>
-    <Folder Include="Models\" />
     <AvaloniaResource Include="Assets\**" />
   </ItemGroup>
 
+  <ItemGroup>
+    <None Remove="Assets\logo.ico" />
+  </ItemGroup>
+
+  <ItemGroup>
+    <Content Include="Assets\logo.ico" />
+  </ItemGroup>
+
 
   <ItemGroup>
     <PackageReference Include="Avalonia" Version="11.0.6" />
@@ -22,5 +30,13 @@
     <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
     <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.6" />
     <PackageReference Include="Avalonia.ReactiveUI" Version="11.0.6" />
+    <PackageReference Include="MessageBox.Avalonia" Version="3.1.5.1" />
+  </ItemGroup>
+
+
+  <ItemGroup>
+    <AvaloniaResource Update="Assets\logo.ico">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </AvaloniaResource>
   </ItemGroup>
 </Project>

+ 13 - 0
Models/FilePath.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LoginGenerator.Models
+{
+    public static class FilePath
+    {
+        public const string PATH = "D:\\RegistrationAssistant.txt";
+    }
+}

+ 1 - 1
PasswordGenerator.cs → Models/PasswordGenerator.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace LoginGenerator
+namespace LoginGenerator.Models
 {
     public class PasswordGenerator
     {

+ 1 - 1
StructData.cs → Models/StructData.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace LoginGenerator
+namespace LoginGenerator.Models
 {
     public class Users
     {

+ 1 - 1
Transliteration.cs → Models/Transliteration.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace LoginGenerator
+namespace LoginGenerator.Models
 {
     public class Transliteration
     {

+ 9 - 3
ViewModels/DataOutputViewModel.cs

@@ -2,14 +2,14 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using LoginGenerator.Models;
 using ReactiveUI;
 
 namespace LoginGenerator.ViewModels
 {
-	public class DataOutputViewModel : ReactiveObject
+    public class DataOutputViewModel : ReactiveObject
 	{
-        public static string Path = "D:\\RegistrationAssistant.txt";
-        public string[] AllData = File.ReadAllLines(Path);
+        public string[] AllData;
         private List<Users>? users;
         public List<Users>? Userss { get => users; set => this.RaiseAndSetIfChanged(ref users, value); }
         public string[] OneUser;
@@ -26,6 +26,12 @@ namespace LoginGenerator.ViewModels
 
         public void FillingUsersList()
         {
+            if (!File.Exists(FilePath.PATH))
+            {
+                var file = File.Create(FilePath.PATH);
+                file.Close();
+            }
+            AllData = File.ReadAllLines(FilePath.PATH);
             List<Users>? newUsers = new List<Users>();
             foreach (string user in AllData)
             {

+ 5 - 0
ViewModels/MainWindowViewModel.cs

@@ -1,11 +1,15 @@
 using Avalonia.Controls;
+using LoginGenerator.Models;
 using ReactiveUI;
 using System;
+using System.IO;
 
 namespace LoginGenerator.ViewModels
 {
+
     public class MainWindowViewModel : ViewModelBase
     {
+
         UserControl us = new GeneratePage();
 
         public UserControl US
@@ -25,6 +29,7 @@ namespace LoginGenerator.ViewModels
         public void ViewUsersData()
         {
             US = new DataOutput();
+            DataOutputVM.FillingUsersList();
         }
 
         public void ViewGeneratePage()

+ 2 - 0
Views/DataOutput.axaml

@@ -19,6 +19,8 @@
       <TextBox Height="10" Width="236" Margin="10 0 0 0" Watermark="Поиск по логину" Text="{Binding DataOutputVM.FindLogin}"/>
       <TextBox Height="10" Width="236" Margin="10 0 0 0" Watermark="Поиск по паролю" Text="{Binding DataOutputVM.FindPass}"/>
       <ComboBox SelectedIndex="0" Width="236" Margin="10 0 0 0" ItemsSource="{Binding DataOutputVM.Sort}" SelectedItem="{Binding DataOutputVM.SelectedSort}"/>
+      <Button Content="↻" Command="{Binding DataOutputVM.FillingUsersList}"/>
+      <Button Content="На страницу генерации" Command="{Binding ViewGeneratePage}"/>
     </StackPanel>
     
     <ListBox Background="#F9F8FF" Grid.Row="1" ItemsSource="{Binding DataOutputVM.Userss}">

+ 6 - 5
Views/GeneratePage.axaml

@@ -5,10 +5,11 @@
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="LoginGenerator.GeneratePage"
              xmlns:vm="using:LoginGenerator.ViewModels"
-			       x:DataType="vm:MainWindowViewModel">
+			       x:DataType="vm:MainWindowViewModel"
+             >
 
   <StackPanel  VerticalAlignment="Center">
-    <TextBlock FontSize="24" FontWeight="Bold" HorizontalAlignment="Center">ГЕНЕРАТОР ЛОГИНОВ/ПАРОЛЕЙ</TextBlock>
+    <TextBlock FontSize="24" FontWeight="Bold" HorizontalAlignment="Center">АССИСТЕНТ РЕГИСТРАЦИИ</TextBlock>
     <StackPanel>
       <TextBox Width="700" Watermark="Введите ФИО" Name="FIO"/>
       <StackPanel Margin="0 10 0 0" HorizontalAlignment="Center" Orientation="Horizontal">
@@ -31,9 +32,9 @@
       </StackPanel>
       
       <StackPanel Margin="0 10 0 0" Orientation="Horizontal" HorizontalAlignment="Center">
-        <Button Width="226" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Execute" Click="WriteIn"/>
-        <Button Width="226" Margin="10 0 0 0" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Copy all" Click="CopyAll_Click"/>
-        <Button Width="226" Margin="10 0 0 0" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Generate"  Click="GenerateAll"/>
+        <Button Width="226" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Записать данные" Click="WriteIn"/>
+        <Button Width="226" Margin="10 0 0 0" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Скопировать данные" Click="CopyAll_Click"/>
+        <Button Width="226" Margin="10 0 0 0" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Сгенерировать данные"  Click="GenerateAll"/>
       </StackPanel>
 
       <StackPanel Margin="0 10 0 0" HorizontalAlignment="Center">

+ 112 - 3
Views/GeneratePage.axaml.cs

@@ -3,15 +3,17 @@ using Avalonia.Controls;
 using Avalonia.Input.Platform;
 using Avalonia.Interactivity;
 using Avalonia.Markup.Xaml;
+using MsBox.Avalonia;
 using System;
 using System.IO;
+using LoginGenerator.Models;
+using System.Collections.Generic;
+using System.Linq;
 
 namespace LoginGenerator;
 
 public partial class GeneratePage : UserControl
 {
-    public static string Path = "D:\\RegistrationAssistant.txt";
-
     public Transliteration transliteration = new Transliteration();
     public PasswordGenerator passwordGenerator = new PasswordGenerator();
 
@@ -31,8 +33,19 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
+            if (!CheckOnExisting())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Ïîëüçîâàòåëü ñ òàêèì ëîãèíîì óæå ñóùåñòâóåò");
+                box.ShowAsync();
+            }
             DateTime dateTime = DateTime.Now;
-            File.AppendAllText(Path, $"{FIO.Text} {Login.Text} {Pass.Text} {dateTime.ToShortDateString()}\n");
+            File.AppendAllText(FilePath.PATH, $"{FIO.Text} {Login.Text} {Pass.Text} {dateTime.ToShortDateString()}\n");
         }
         catch (Exception) { }
     }
@@ -41,6 +54,12 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
             IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
             string[] parts = FIO.Text.Split(' ');
             Clipboard.SetTextAsync(parts[0]);
@@ -52,6 +71,12 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
             IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
             string[] parts = FIO.Text.Split(' ');
             Clipboard.SetTextAsync(parts[1]);
@@ -63,6 +88,12 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
             IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
             string[] parts = FIO.Text.Split(' ');
             Clipboard.SetTextAsync(parts[2]);
@@ -74,6 +105,12 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
             IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
             string[] parts = FIO.Text.Split(' ');
             Clipboard.SetTextAsync(parts[1] + " " + parts[2]);
@@ -85,6 +122,12 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
             Random r = new Random();
             string[] parts = FIO.Text.Split(' ');
             string newTransliteration = transliteration.Execute(parts[0]) + ".";
@@ -105,6 +148,18 @@ public partial class GeneratePage : UserControl
     {
         try
         {
+            if (string.IsNullOrEmpty(FIO.Text))
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                box.ShowAsync();
+                return;
+            }
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
             string[] parts = FIO.Text.Split(' ');
             Login.Text = transliteration.Execute($"{parts[0]}.{parts[1][0]}{parts[2][0]}");
             Pass.Text = passwordGenerator.Execute();
@@ -114,6 +169,12 @@ public partial class GeneratePage : UserControl
 
     private void RegenPass(object sender, RoutedEventArgs e)
     {
+        if (!CheckOnSmoothly())
+        {
+            var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+            box.ShowAsync();
+            return;
+        }
         Pass.Text = passwordGenerator.Execute();
     }
 
@@ -129,4 +190,52 @@ public partial class GeneratePage : UserControl
         IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
         Clipboard.SetTextAsync(Pass.Text);
     }
+
+    public bool CheckOnExisting()
+    {
+        string[] OneUser;
+        Users u;
+        string[] AllData = File.ReadAllLines(FilePath.PATH);
+        if (AllData.Count() == 0)
+        {
+            return true;
+        }
+        List<Users>? newUsers = new List<Users>();
+        foreach (string user in AllData)
+        {
+            if (!string.IsNullOrEmpty(user))
+            {
+                u = new Users();
+                OneUser = user.Split(' ');
+                u.Surname = OneUser[0].ToString();
+                u.Name = OneUser[1].ToString();
+                u.Patronymic = OneUser[2].ToString();
+                u.Login = OneUser[3].ToString();
+                u.Password = OneUser[4].ToString();
+                u.DateReg = Convert.ToDateTime(OneUser[5]);
+                newUsers.Add(u);
+            }
+        }
+        if(newUsers.Where(x=>x.Login == Login.Text).First()==null)
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    public bool CheckOnSmoothly()
+    {
+        string[] parts = FIO.Text.Split(' ');
+        if (parts.Count() != 3)
+        {
+            return false;
+        }
+        else
+        {
+            return true;
+        }
+    }
 }