Page1ViewModel.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. using System.Collections.Generic;
  3. using ReactiveUI;
  4. using Avalonia.Media;
  5. using Avalonia.Controls.Shapes;
  6. using Avalonia.Threading;
  7. using AvaloniaApplication4.Models;
  8. using Avalonia.Controls;
  9. using static System.Net.Mime.MediaTypeNames;
  10. using Avalonia.Controls.Documents;
  11. namespace AvaloniaApplication4.ViewModels
  12. {
  13. public class Page1ViewModel : ReactiveObject
  14. {
  15. DispatcherTimer timer = new DispatcherTimer(); // ñîçäàíèå îáúåêòà äëÿ òàéìåðà
  16. // êîíñòðóêòîð
  17. public int count = 0;
  18. public string loginn = "";
  19. public int pass = 0;
  20. public string result = "";
  21. public string result1 = "";
  22. bool _isButtonVisible = true;
  23. bool _isButtonVisible1 = false;
  24. bool _isButtonVisible2 = false;
  25. bool _tbvis = false;
  26. public char[] stringChars;
  27. public string Login
  28. {
  29. get { return loginn; }
  30. set
  31. {
  32. this.RaiseAndSetIfChanged(ref loginn, value);
  33. }
  34. }
  35. public int Password
  36. {
  37. get { return pass; }
  38. set
  39. {
  40. this.RaiseAndSetIfChanged(ref pass, value);
  41. }
  42. }
  43. public string Res
  44. {
  45. get { return result; }
  46. set { this.RaiseAndSetIfChanged(ref result, value); }
  47. }
  48. public bool IsButtonVisible
  49. {
  50. get => _isButtonVisible;
  51. set => this.RaiseAndSetIfChanged(ref _isButtonVisible, value);
  52. }
  53. public bool IsButtonVisible1
  54. {
  55. get => _isButtonVisible1;
  56. set => this.RaiseAndSetIfChanged(ref _isButtonVisible1, value);
  57. }
  58. public bool IsButtonVisible2
  59. {
  60. get => _isButtonVisible2;
  61. set => this.RaiseAndSetIfChanged(ref _isButtonVisible2, value);
  62. }
  63. public bool IsTBvis
  64. {
  65. get => _tbvis;
  66. set => this.RaiseAndSetIfChanged(ref _tbvis, value);
  67. }
  68. Canvas _canva;
  69. public Canvas Canva
  70. {
  71. get => _canva;
  72. set => this.RaiseAndSetIfChanged(ref _canva, value);
  73. }
  74. private FontStyle GetRandomFontStyle()
  75. {
  76. Random random = new Random();
  77. FontStyle style = FontStyle.Normal;
  78. int font_ss = random.Next(1,2);
  79. if (font_ss == 1)
  80. {
  81. style = FontStyle.Italic;
  82. }
  83. else
  84. {
  85. style = FontStyle.Normal;
  86. }
  87. return style;
  88. }
  89. private FontWeight GetRandomFontW()
  90. {
  91. Random random = new Random();
  92. FontWeight style = FontWeight.Regular;
  93. int font_ss = random.Next(1, 2);
  94. if (font_ss == 1)
  95. {
  96. style = FontWeight.Bold;
  97. }
  98. else
  99. {
  100. style = FontWeight.Regular;
  101. }
  102. return style;
  103. }
  104. public void CreateCaptha()
  105. {
  106. Random rnd = new Random();
  107. SolidColorBrush color = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
  108. FontStyle[] fs = new FontStyle[2] { FontStyle.Normal, FontStyle.Italic};
  109. FontWeight[] fw = new FontWeight[2] { FontWeight.Bold, FontWeight.Normal };
  110. int a;
  111. Canvas canvas = new Canvas()
  112. {
  113. Width = 400,
  114. Height = 400,
  115. Background = color
  116. };
  117. // ãåíåðèðóåì ëèíèè
  118. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  119. var rs = rnd.Next(7, 11);
  120. stringChars = new char[rs];
  121. var random = new Random();
  122. int fixedLetterSpacing = 30;
  123. int font_ss = rnd.Next(0, 3);
  124. for (int i = 0; i < stringChars.Length; i++)
  125. {
  126. stringChars[i] = chars[random.Next(chars.Length)];
  127. }
  128. int min = 50;
  129. var finalString = new String(stringChars);
  130. for (int i = 0; i < stringChars.Length; i++)
  131. {
  132. TextBlock number = new TextBlock()
  133. {
  134. Text = stringChars[i].ToString(),
  135. FontSize = 40,
  136. Foreground = Brushes.Black,
  137. Padding = new Avalonia.Thickness(0, 0, 0, 0),
  138. Margin = new Avalonia.Thickness(min, rnd.Next(150, 250), 0, 0), // äîáàâëÿåì îòñòóïû
  139. FontStyle = fs[rnd.Next(0, 2)],
  140. FontWeight = fw[rnd.Next(0, 2)]
  141. };
  142. min += fixedLetterSpacing;
  143. canvas.Children.Add(number);
  144. }
  145. for (int i = 0; i < 20; i++)
  146. {
  147. Line line = new Line()
  148. {
  149. StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
  150. EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
  151. Stroke = new SolidColorBrush(Color.FromArgb(128, 255, 255, 255)),
  152. StrokeThickness = 3
  153. };
  154. canvas.Children.Add(line);
  155. }
  156. Canva = canvas; // ïåðåäà÷à ñîçäàííîãî Canvas ñâ-âó Canvas äëÿ îòîáðàæåíèÿ
  157. }
  158. public string enteredtext = "";
  159. public string Enteredt
  160. {
  161. get { return enteredtext; }
  162. set
  163. {
  164. this.RaiseAndSetIfChanged(ref enteredtext, value);
  165. }
  166. }
  167. public string Res1
  168. {
  169. get { return result1; }
  170. set { this.RaiseAndSetIfChanged(ref result1, value); }
  171. }
  172. public bool _Enabled = true;
  173. public bool Enabled
  174. {
  175. get
  176. {
  177. return _Enabled;
  178. }
  179. set
  180. {
  181. this.RaiseAndSetIfChanged(ref _Enabled, value);
  182. }
  183. }
  184. }
  185. }