123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- 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;
- using TextCopy;
- namespace LoginGenerator.ViewModels
- {
- public class GeneratePageViewModel : ReactiveObject
- {
- public Transliteration transliteration = new Transliteration();
- public PasswordGenerator passwordGenerator = new PasswordGenerator();
- public bool Theme = false;
- private SolidColorBrush background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(236, 233, 255));
- public SolidColorBrush Background
- {
- 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 RegenLogin()
- {
- 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()
- {
- if(Theme == false)
- {
- Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(80, 80, 80));
- Theme = true;
- }
- else
- {
- Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(236, 233, 255));
- Theme = false;
- }
- }
- }
- }
|