Fox пре 7 месеци
родитељ
комит
c4cb65631a

+ 1 - 0
LoginGenerator.csproj

@@ -31,6 +31,7 @@
     <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" />
+    <PackageReference Include="TextCopy" Version="6.2.1" />
   </ItemGroup>
 
 

+ 315 - 0
ViewModels/GeneratePageViewModel.cs

@@ -0,0 +1,315 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input.Platform;
+using Avalonia.Interactivity;
+using Avalonia.Markup.Xaml;
+using MsBox.Avalonia;
+using System.Windows;
+using System.Text;
+using System.IO;
+using LoginGenerator.Models;
+using System.Linq;
+using System.Drawing.Imaging;
+using Avalonia.Input;
+using Avalonia.Media;
+using System.Drawing;
+
+namespace LoginGenerator.ViewModels
+{
+	public class GeneratePageViewModel : ReactiveObject
+	{
+
+        public Transliteration transliteration = new Transliteration();
+        public PasswordGenerator passwordGenerator = new PasswordGenerator();
+
+        private SolidColorBrush background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(255, 255, 255));
+
+        public SolidColorBrush MyProperty
+        {
+            get => background;
+            set => this.RaiseAndSetIfChanged(ref background, value);
+        }
+
+        private string? fio;
+        public string? FIO
+        {
+            get => fio;
+            set => this.RaiseAndSetIfChanged(ref fio, value);
+        }
+
+        private string? login;
+        public string? Login
+        {
+            get => login;
+            set => this.RaiseAndSetIfChanged(ref login, value);
+        }
+
+        private string? pass;
+        public string? Pass
+        {
+            get => pass;
+            set => this.RaiseAndSetIfChanged(ref pass, value);
+        }
+
+        public void CopyAll_Click()
+        {
+            ClipboardService.SetText($"{FIO}\n{Login}\n{Pass}");
+        }
+
+        public void WriteIn()
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnExisting())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Ïîëüçîâàòåëü ñ òàêèì ëîãèíîì óæå ñóùåñòâóåò");
+                    box.ShowAsync();
+                    return;
+                }
+                DateTime dateTime = DateTime.Now;
+                File.AppendAllText(FilePath.PATH, $"{FIO} {Login} {Pass} {dateTime.ToShortDateString()}\n");
+            }
+            catch (Exception) { }
+        }
+
+        public void OSurnameCopy_Click()
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                string[] parts = FIO.Split(' ');
+                ClipboardService.SetText(parts[0]);
+            }
+            catch (Exception) { }
+        }
+
+        public void ONameCopy_Click()
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                string[] parts = FIO.Split(' ');
+                ClipboardService.SetText(parts[1]);
+            }
+            catch (Exception) { }
+        }
+
+        public void OPatronymicCopy_Click()
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                string[] parts = FIO.Split(' ');
+                ClipboardService.SetText(parts[2]);
+            }
+            catch (Exception) { }
+        }
+
+        public void ONamePatronymicCopy_Click()
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                string[] parts = FIO.Split(' ');
+                ClipboardService.SetText(parts[1] + " " + parts[2]);
+            }
+            catch (Exception) { }
+        }
+
+        public void TMore_Click(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                Random r = new Random();
+                string[] parts = FIO.Split(' ');
+                string newTransliteration = transliteration.Execute(parts[0]) + ".";
+                for (int i = 0; i < r.Next(5); i++)
+                {
+                    newTransliteration += transliteration.Execute(parts[1][i].ToString());
+                }
+                for (int i = 0; i < r.Next(1, 5); i++)
+                {
+                    newTransliteration += transliteration.Execute(parts[2][i].ToString());
+                }
+                Login = newTransliteration;
+            }
+            catch (Exception) { }
+        }
+
+        public void GenerateAll()
+        {
+            try
+            {
+                if (string.IsNullOrEmpty(FIO))
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                    box.ShowAsync();
+                    return;
+                }
+                if (!CheckOnSmoothly())
+                {
+                    var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                    box.ShowAsync();
+                    return;
+                }
+                string[] parts = FIO.Split(' ');
+                Login = transliteration.Execute($"{parts[0]}.{parts[1][0]}{parts[2][0]}");
+                Pass = passwordGenerator.Execute();
+            }
+            catch (Exception) { }
+        }
+
+        public void RegenPass()
+        {
+            if (string.IsNullOrEmpty(FIO))
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
+                box.ShowAsync();
+                return;
+            }
+            if (!CheckOnSmoothly())
+            {
+                var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
+                box.ShowAsync();
+                return;
+            }
+            Pass = passwordGenerator.Execute();
+        }
+
+
+        public void LoginCopy()
+        {
+            ClipboardService.SetText(Login);
+        }
+
+        public void PassCopy()
+        {
+            ClipboardService.SetText(Pass);
+        }
+
+        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);
+                }
+            }
+            Users? maybeNew = newUsers.Where(x => x.Login == Login).FirstOrDefault();
+            if (maybeNew == null)
+            {
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        public bool CheckOnSmoothly()
+        {
+            string[] parts = FIO.Split(' ');
+            if (parts.Count() != 3)
+            {
+                return false;
+            }
+            else
+            {
+                return true;
+            }
+        }
+
+        public void SwitchTheme()
+        {
+
+        }
+    }
+}

+ 6 - 0
ViewModels/MainWindowViewModel.cs

@@ -25,6 +25,12 @@ namespace LoginGenerator.ViewModels
             set => dataOutput = value;
         }
 
+        GeneratePageViewModel generatePage = new GeneratePageViewModel();
+        public GeneratePageViewModel GeneratePageVM
+        {
+            get => generatePage;
+            set => generatePage = value;
+        }
 
         public void ViewUsersData()
         {

+ 4 - 4
Views/GeneratePage.axaml

@@ -17,10 +17,10 @@
       </StackPanel>
      
       <StackPanel Margin="0 10 0 0" HorizontalAlignment="Center" Orientation="Horizontal">
-        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Ф" Click="OSurnameCopy_Click"/>
-        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Margin="10 0 0 0" Content="И" Click="ONameCopy_Click"/>
-        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Margin="10 0 0 0" Content="О" Click="OPatronymicCopy_Click"/>
-        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Margin="10 0 0 0" Content="ИО" Click="ONamePatronymicCopy_Click"/>
+        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Content="Ф" Command="{Binding GeneratePageVM.OSurnameCopy_Click}"/>
+        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Margin="10 0 0 0" Content="И" Command="{Binding GeneratePageVM.ONameCopy_Click}"/>
+        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Margin="10 0 0 0" Content="О" Command="{Binding GeneratePageVM.OPatronymicCopy_Click}" />
+        <Button Width="167" HorizontalContentAlignment="Center" FontWeight="Bold" BorderBrush="Black" Background="White" Foreground="#545454" Margin="10 0 0 0" Content="ИО" Command="{Binding GeneratePageVM.ONamePatronymicCopy_Click}"/>
       </StackPanel>
 
       <StackPanel Margin="0 10 0 0" HorizontalAlignment="Center" Orientation="Horizontal">