GeneratePage.axaml.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Input.Platform;
  4. using Avalonia.Interactivity;
  5. using Avalonia.Markup.Xaml;
  6. using MsBox.Avalonia;
  7. using System;
  8. using System.IO;
  9. using LoginGenerator.Models;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. namespace LoginGenerator;
  13. public partial class GeneratePage : UserControl
  14. {
  15. public Transliteration transliteration = new Transliteration();
  16. public PasswordGenerator passwordGenerator = new PasswordGenerator();
  17. public GeneratePage()
  18. {
  19. InitializeComponent();
  20. }
  21. private void CopyAll_Click(object sender, RoutedEventArgs e)
  22. {
  23. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  24. Clipboard.SetTextAsync($"{FIO.Text}\n{Login.Text}\n{Pass.Text}");
  25. }
  26. private void WriteIn(object sender, RoutedEventArgs e)
  27. {
  28. try
  29. {
  30. if (!CheckOnSmoothly())
  31. {
  32. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  33. box.ShowAsync();
  34. return;
  35. }
  36. if (!CheckOnExisting())
  37. {
  38. var box = MessageBoxManager.GetMessageBoxStandard("Îøèáêà", "Ïîëüçîâàòåëü ñ òàêèì ëîãèíîì óæå ñóùåñòâóåò");
  39. box.ShowAsync();
  40. }
  41. DateTime dateTime = DateTime.Now;
  42. File.AppendAllText(FilePath.PATH, $"{FIO.Text} {Login.Text} {Pass.Text} {dateTime.ToShortDateString()}\n");
  43. }
  44. catch (Exception) { }
  45. }
  46. private void OSurnameCopy_Click(object sender, RoutedEventArgs e)
  47. {
  48. try
  49. {
  50. if (!CheckOnSmoothly())
  51. {
  52. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  53. box.ShowAsync();
  54. return;
  55. }
  56. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  57. string[] parts = FIO.Text.Split(' ');
  58. Clipboard.SetTextAsync(parts[0]);
  59. }
  60. catch (Exception) { }
  61. }
  62. private void ONameCopy_Click(object sender, RoutedEventArgs e)
  63. {
  64. try
  65. {
  66. if (!CheckOnSmoothly())
  67. {
  68. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  69. box.ShowAsync();
  70. return;
  71. }
  72. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  73. string[] parts = FIO.Text.Split(' ');
  74. Clipboard.SetTextAsync(parts[1]);
  75. }
  76. catch (Exception) { }
  77. }
  78. private void OPatronymicCopy_Click(object sender, RoutedEventArgs e)
  79. {
  80. try
  81. {
  82. if (!CheckOnSmoothly())
  83. {
  84. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  85. box.ShowAsync();
  86. return;
  87. }
  88. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  89. string[] parts = FIO.Text.Split(' ');
  90. Clipboard.SetTextAsync(parts[2]);
  91. }
  92. catch (Exception) { }
  93. }
  94. private void ONamePatronymicCopy_Click(object sender, RoutedEventArgs e)
  95. {
  96. try
  97. {
  98. if (!CheckOnSmoothly())
  99. {
  100. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  101. box.ShowAsync();
  102. return;
  103. }
  104. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  105. string[] parts = FIO.Text.Split(' ');
  106. Clipboard.SetTextAsync(parts[1] + " " + parts[2]);
  107. }
  108. catch (Exception) { }
  109. }
  110. private void TMore_Click(object sender, RoutedEventArgs e)
  111. {
  112. try
  113. {
  114. if (!CheckOnSmoothly())
  115. {
  116. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  117. box.ShowAsync();
  118. return;
  119. }
  120. Random r = new Random();
  121. string[] parts = FIO.Text.Split(' ');
  122. string newTransliteration = transliteration.Execute(parts[0]) + ".";
  123. for (int i = 0; i < r.Next(5); i++)
  124. {
  125. newTransliteration += transliteration.Execute(parts[1][i].ToString());
  126. }
  127. for (int i = 0; i < r.Next(1, 5); i++)
  128. {
  129. newTransliteration += transliteration.Execute(parts[2][i].ToString());
  130. }
  131. Login.Text = newTransliteration;
  132. }
  133. catch (Exception) { }
  134. }
  135. private void GenerateAll(object sender, RoutedEventArgs e)
  136. {
  137. try
  138. {
  139. if (string.IsNullOrEmpty(FIO.Text))
  140. {
  141. var box = MessageBoxManager.GetMessageBoxStandard("Ïóñòîå ïîëå", "Ââåäèòå ÔÈÎ äëÿ ãåíåðàöèè äàííûõ");
  142. box.ShowAsync();
  143. return;
  144. }
  145. if (!CheckOnSmoothly())
  146. {
  147. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  148. box.ShowAsync();
  149. return;
  150. }
  151. string[] parts = FIO.Text.Split(' ');
  152. Login.Text = transliteration.Execute($"{parts[0]}.{parts[1][0]}{parts[2][0]}");
  153. Pass.Text = passwordGenerator.Execute();
  154. }
  155. catch (Exception) { }
  156. }
  157. private void RegenPass(object sender, RoutedEventArgs e)
  158. {
  159. if (!CheckOnSmoothly())
  160. {
  161. var box = MessageBoxManager.GetMessageBoxStandard("ÔÈÎ íåïðàâèëüíîå", "ÔÈÎ äîëæíî ñîñòîÿòü èç òð¸õ ÷àñòåé (1-Ô,2-È,3-Î)");
  162. box.ShowAsync();
  163. return;
  164. }
  165. Pass.Text = passwordGenerator.Execute();
  166. }
  167. private void LoginCopy(object sender, RoutedEventArgs e)
  168. {
  169. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  170. Clipboard.SetTextAsync(Login.Text);
  171. }
  172. private void PassCopy(object sender, RoutedEventArgs e)
  173. {
  174. IClipboard Clipboard = TopLevel.GetTopLevel(this)?.Clipboard;
  175. Clipboard.SetTextAsync(Pass.Text);
  176. }
  177. public bool CheckOnExisting()
  178. {
  179. string[] OneUser;
  180. Users u;
  181. string[] AllData = File.ReadAllLines(FilePath.PATH);
  182. if (AllData.Count() == 0)
  183. {
  184. return true;
  185. }
  186. List<Users>? newUsers = new List<Users>();
  187. foreach (string user in AllData)
  188. {
  189. if (!string.IsNullOrEmpty(user))
  190. {
  191. u = new Users();
  192. OneUser = user.Split(' ');
  193. u.Surname = OneUser[0].ToString();
  194. u.Name = OneUser[1].ToString();
  195. u.Patronymic = OneUser[2].ToString();
  196. u.Login = OneUser[3].ToString();
  197. u.Password = OneUser[4].ToString();
  198. u.DateReg = Convert.ToDateTime(OneUser[5]);
  199. newUsers.Add(u);
  200. }
  201. }
  202. if(newUsers.Where(x=>x.Login == Login.Text).First()==null)
  203. {
  204. return true;
  205. }
  206. else
  207. {
  208. return false;
  209. }
  210. }
  211. public bool CheckOnSmoothly()
  212. {
  213. string[] parts = FIO.Text.Split(' ');
  214. if (parts.Count() != 3)
  215. {
  216. return false;
  217. }
  218. else
  219. {
  220. return true;
  221. }
  222. }
  223. }