GeneratePage.axaml.cs 9.5 KB

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