123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using Avalonia;
- 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 Transliteration transliteration = new Transliteration();
- public PasswordGenerator passwordGenerator = new PasswordGenerator();
- public GeneratePage()
- {
- InitializeComponent();
- }
- private void CopyAll_Click(object sender, RoutedEventArgs e)
- {
- IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
- Clipboard.SetTextAsync($"{FIO.Text}\n{Login.Text}\n{Pass.Text}");
- }
- private void WriteIn(object sender, RoutedEventArgs e)
- {
- 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(FilePath.PATH, $"{FIO.Text} {Login.Text} {Pass.Text} {dateTime.ToShortDateString()}\n");
- }
- catch (Exception) { }
- }
- private void OSurnameCopy_Click(object sender, RoutedEventArgs e)
- {
- 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]);
- }
- catch (Exception) { }
- }
- private void ONameCopy_Click(object sender, RoutedEventArgs e)
- {
- 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]);
- }
- catch (Exception) { }
- }
- private void OPatronymicCopy_Click(object sender, RoutedEventArgs e)
- {
- 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]);
- }
- catch (Exception) { }
- }
- private void ONamePatronymicCopy_Click(object sender, RoutedEventArgs e)
- {
- 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]);
- }
- catch (Exception) { }
- }
- private void TMore_Click(object sender, RoutedEventArgs e)
- {
- 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]) + ".";
- 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.Text = newTransliteration;
- }
- catch (Exception) { }
- }
- private void GenerateAll(object sender, RoutedEventArgs e)
- {
- 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();
- }
- catch (Exception) { }
- }
- private void RegenPass(object sender, RoutedEventArgs e)
- {
- if (!CheckOnSmoothly())
- {
- var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
- box.ShowAsync();
- return;
- }
- Pass.Text = passwordGenerator.Execute();
- }
- private void LoginCopy(object sender, RoutedEventArgs e)
- {
- IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
- Clipboard.SetTextAsync(Login.Text);
- }
- private void PassCopy(object sender, RoutedEventArgs e)
- {
- 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;
- }
- }
- }
|