2 次代碼提交 53baff0b49 ... 6f5410d8dd

作者 SHA1 備註 提交日期
  ГаряевСА 6f5410d8dd commit 1 月之前
  ГаряевСА aa46f225fe End part 1 1 月之前

+ 17 - 0
Captcha/Models/ModelClass.cs

@@ -10,8 +10,25 @@ namespace Captcha.Models
     {
         static string _login = "timan_cool";
         static string _password = "10082005";
+        public static List<string> _arithmetic = new List<string>
+        {
+            "Сложение",
+            "Вычитание",
+            "Умножение",
+            "Деление"
+        };
 
         public static string Login { get => _login; set => _login = value; }
         public static string Password { get => _password; set => _password = value; }
+
+
+
+
+
+        
+
+
+
+
     }
 }

+ 6 - 166
Captcha/ViewModels/MainWindowViewModel.cs

@@ -13,178 +13,18 @@ namespace Captcha.ViewModels
 {
     public class MainWindowViewModel : ViewModelBase
     {
-#pragma warning disable CA1822 // Mark members as static
+        public static MainWindowViewModel Instance;
 
-        DispatcherTimer timer = new DispatcherTimer();
+        UserControl _pageContent = new Page1();
         public MainWindowViewModel()
         {
-
-            timer.Interval = new TimeSpan(0, 0, 10); // задание того, на какое кол-во времени будет запущен таймер
-            timer.Tick += new EventHandler(timer_tick); // добавление объекту таймера событие, запускающего генерацию капчи (обработчик timer_tick реализован ниже)
-        }
-        private void timer_tick(object sender, EventArgs e)
-        {
-            StackVis = true;
-            TextEnab = true;
-            MessageCaptcha = "Введите символы с капчи:";
-            CreateCaptha();
-            timer.Stop();
-            strCaptcha = "";
-        }
-
-        string login = "";
-        string password = "";
-        string message = "";
-        string messageCaptcha = "";
-        string itCaptcha = "";
-        string strCaptcha = "";
-        bool butVis = true;
-        bool butCapVis = true;
-        bool stackVis = false;
-        bool textEnab = true;
-
-        public string Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }
-        public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
-        public string MessageCaptcha { get => messageCaptcha; set => this.RaiseAndSetIfChanged(ref messageCaptcha, value); }
-        public string ItCaptcha { get => itCaptcha; set => this.RaiseAndSetIfChanged(ref itCaptcha, value); }
-        public string Password { get => password; set => this.RaiseAndSetIfChanged(ref password, value); }
-        public bool ButVis { get => butVis; set => this.RaiseAndSetIfChanged(ref butVis, value); }
-        public bool ButCapVis { get => butCapVis; set => this.RaiseAndSetIfChanged(ref butCapVis, value); }
-        public bool StackVis { get => stackVis; set => this.RaiseAndSetIfChanged(ref stackVis,value); }
-        public bool TextEnab { get => textEnab; set => this.RaiseAndSetIfChanged(ref textEnab, value); }
-
-
-
-        public void Authorization()
-        {
-            if (login == ModelClass.Login && password == ModelClass.Password)
-            {
-                Message = "Авторизация прошла успешно";
-
-            }
-            else
-            {
-                StackVis = true;
-                MessageCaptcha = "Введите символы с капчи:";
-                Message = "Неверный логин или пароль";
-                ButVis = false;
-                CreateCaptha();
-            }
-        }
-
-        Canvas _can;
-
-        public Canvas Can
-        {
-            get => _can;
-            set => this.RaiseAndSetIfChanged(ref _can, value);
+            Instance = this;
         }
 
-        public static string RandomString()
+        public UserControl PageContent
         {
-            string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
-            string stringChars = "";
-            Random random = new Random();
-
-            stringChars = stringChars + chars[random.Next(chars.Length)];
-
-            return stringChars;
-        }
-
-        public void CreateCaptha()
-        {
-
-            Random rnd = new Random();
-
-            Canvas canvas = new Canvas() // создаем размеры Canvas
-            {
-                Width = 400,
-                Height = 400,
-                Background = Brushes.White
-            };
-            // генерируем линии
-            for (int i = 0; i < rnd.Next(7,10); i++)
-            {
-                switch (rnd.Next(3))
-                {
-                    case 0:
-                        TextBlock number1 = new TextBlock()
-                        {
-                            Text = RandomString(),
-                            FontSize = 50,
-                            Foreground = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)))),
-                            Padding = new Avalonia.Thickness(i * 50, rnd.Next(100, 300), 0, 0),
-                            FontStyle = FontStyle.Italic
-                        };
-                        strCaptcha = strCaptcha + number1.Text;
-                        canvas.Children.Add(number1);
-                        break;
-                    case 1:
-                        TextBlock number2 = new TextBlock()
-                        {
-                            Text = RandomString(),
-                            FontSize = 50,
-                            Foreground = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)))),
-                            Padding = new Avalonia.Thickness(i * 50, rnd.Next(100, 300), 0, 0),
-                            FontWeight = FontWeight.Bold
-                        };
-                        strCaptcha = strCaptcha + number2.Text;
-                        canvas.Children.Add(number2);
-                        break;
-                    case 2:
-                        TextBlock number3 = new TextBlock()
-                        {
-                            Text = RandomString(),
-                            FontSize = 50,
-                            Foreground = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)))),
-                            Padding = new Avalonia.Thickness(i * 40, rnd.Next(100, 300), 0, 0),
-                            FontWeight = FontWeight.Bold,
-                            FontStyle = FontStyle.Italic
-                        };
-                        strCaptcha = strCaptcha + number3.Text;
-                        canvas.Children.Add(number3);
-                        break;
-                    default:
-                        break;
-                }
-            }
-
-            for (int i = 0; i < 20; i++)
-            {
-                Line line = new Line()
-                {
-                    StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
-                    EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
-                    Stroke = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255)))),
-                    StrokeThickness = 3
-                };
-
-                canvas.Children.Add(line);
-            }
-
-            Can = canvas; // передача созданного Canvas св-ву Canvas для отображения
-        }
-
-        public void Trying()
-        {
-            if (login == ModelClass.Login && password == ModelClass.Password && itCaptcha == strCaptcha)
-            {
-                Message = "Авторизация прошла успешно";
-                StackVis = false;
-
-            }
-            else
-            {
-                Message = "Неверный логин, пароль или капча";
-                StackVis = false;
-                Login = "";
-                Password = "";
-                ItCaptcha = "";
-                TextEnab = false;
-                timer.Start();
-            }
+            get => _pageContent;
+            set => this.RaiseAndSetIfChanged(ref _pageContent, value);
         }
     }
-
-#pragma warning restore CA1822 // Mark members as static
 }

+ 158 - 0
Captcha/ViewModels/Page1VM.cs

@@ -0,0 +1,158 @@
+using Avalonia.Controls.Shapes;
+using Avalonia.Controls;
+using Avalonia.Media;
+using Avalonia.Threading;
+using Captcha.Models;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Captcha.ViewModels
+{
+    internal class Page1VM : ViewModelBase
+    {
+        DispatcherTimer timer = new DispatcherTimer();
+        public Page1VM()
+        {
+
+            timer.Interval = new TimeSpan(0, 0, 10); // задание того, на какое кол-во времени будет запущен таймер
+            timer.Tick += new EventHandler(timer_tick); // добавление объекту таймера событие, запускающего генерацию капчи (обработчик timer_tick реализован ниже)
+        }
+        private void timer_tick(object sender, EventArgs e)
+        {
+            StackVis = true;
+            TextEnab = true;
+            MessageCaptcha = "Введите символы с капчи:";
+            strCaptcha = "";
+            CreateCaptha();
+            timer.Stop();
+        }
+
+        string login = "";
+        string password = "";
+        string message = "";
+        string messageCaptcha = "";
+        string itCaptcha = "";
+        string strCaptcha = "";
+        bool butVis = true;
+        bool butCapVis = true;
+        bool stackVis = false;
+        bool textEnab = true;
+
+        public string Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }
+        public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
+        public string MessageCaptcha { get => messageCaptcha; set => this.RaiseAndSetIfChanged(ref messageCaptcha, value); }
+        public string ItCaptcha { get => itCaptcha; set => this.RaiseAndSetIfChanged(ref itCaptcha, value); }
+        public string Password { get => password; set => this.RaiseAndSetIfChanged(ref password, value); }
+        public bool ButVis { get => butVis; set => this.RaiseAndSetIfChanged(ref butVis, value); }
+        public bool ButCapVis { get => butCapVis; set => this.RaiseAndSetIfChanged(ref butCapVis, value); }
+        public bool StackVis { get => stackVis; set => this.RaiseAndSetIfChanged(ref stackVis, value); }
+        public bool TextEnab { get => textEnab; set => this.RaiseAndSetIfChanged(ref textEnab, value); }
+
+
+
+        public void Authorization()
+        {
+            if (login == ModelClass.Login && password == ModelClass.Password)
+            {
+                ToPageCalculate();
+            }
+            else
+            {
+                StackVis = true;
+                MessageCaptcha = "Введите символы с капчи:";
+                Message = "Неверный логин или пароль";
+                ButVis = false;
+                CreateCaptha();
+            }
+        }
+
+        Canvas _can;
+
+        public Canvas Can
+        {
+            get => _can;
+            set => this.RaiseAndSetIfChanged(ref _can, value);
+        }
+
+        public static string RandomString()
+        {
+            string chars = "abcdefghijklmnopqrstuvwxyz0123456789";
+            string stringChars = "";
+            Random random = new Random();
+
+            stringChars = stringChars + chars[random.Next(chars.Length)];
+
+            return stringChars;
+        }
+
+        public void CreateCaptha()
+        {
+
+            Random rnd = new Random();
+
+            Canvas canvas = new Canvas() // создаем размеры Canvas
+            {
+                Width = 400,
+                Height = 400,
+                Background = Brushes.White
+            };
+            // генерируем линии
+            for (int i = 0; i < rnd.Next(7, 10); i++)
+            {
+                        TextBlock number = new TextBlock()
+                        {
+                            Text = RandomString(),
+                            FontSize = 50,
+                            Foreground = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(256)))),
+                            Padding = new Avalonia.Thickness(i * 50, rnd.Next(100, 300), 0, 0),
+                            FontWeight = (rnd.Next(2) == 0) ? FontWeight.Bold : FontWeight.Normal,
+                            FontStyle = (rnd.Next(2) == 0) ? FontStyle.Italic : FontStyle.Normal,
+                        };
+                        strCaptcha = strCaptcha + number.Text;
+                        canvas.Children.Add(number);
+            }
+
+            for (int i = 0; i < 20; i++)
+            {
+                Line line = new Line()
+                {
+                    StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
+                    EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
+                    Stroke = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255)))),
+                    StrokeThickness = 3
+                };
+
+                canvas.Children.Add(line);
+            }
+
+            Can = canvas; // передача созданного Canvas св-ву Canvas для отображения
+        }
+        public void Trying()
+        {
+            if (login == ModelClass.Login && password == ModelClass.Password && itCaptcha == strCaptcha)
+            {
+                ToPageCalculate();
+            }
+            else
+            {
+                Message = "Неверный логин, пароль или капча";
+                StackVis = false;
+                Login = "";
+                Password = "";
+                ItCaptcha = "";
+                TextEnab = false;
+                timer.Start();
+            }
+        }
+
+        public void ToPageCalculate()
+        {
+            MainWindowViewModel.Instance.PageContent = new PageCalculate();
+        }
+    }
+}
+

+ 47 - 0
Captcha/ViewModels/PageCalculateVM.cs

@@ -0,0 +1,47 @@
+using Captcha.Models;
+using ReactiveUI;
+using System;
+using System.Collections.Generic;
+using System.IO.Pipelines;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Captcha.ViewModels
+{
+    internal class PageCalculateVM : ViewModelBase
+    {
+        List<string> _arif = ModelClass._arithmetic;
+
+        float _a, _b, _result = 0;
+
+        char _c = ' ';
+
+        public List<string> Arif { get => _arif; set => _arif = value; }
+        public float A { get => _a; set => _a = value; }
+        public float B { get => _b; set => _b = value; }
+        public char C { get => _c; set => _c = value; }
+        public float Result { get => _result; set => this.RaiseAndSetIfChanged(ref _result, value); }
+        void Сalculation()
+        {
+            int index = 0;
+            switch (index)
+            {
+                case 0:
+                    _result = A + B;
+                    break;
+                case 1:
+                    _result = A - B;
+                    break;
+                case 2:
+                    _result = A * B;
+                    break;
+                case 3:
+                    _result = A / B;
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+}

+ 2 - 33
Captcha/Views/MainWindow.axaml

@@ -14,39 +14,8 @@
              to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
         <vm:MainWindowViewModel/>
     </Design.DataContext>
+
 	<StackPanel>
-		<TextBlock>Главное окно</TextBlock>
-		<UserControl Content="{Binding Us}"></UserControl>
-	</StackPanel>
-	<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
-		<StackPanel Name="Login" Margin="20">
-			<Border Classes = "trash" Padding="40">
-				<StackPanel >
-					<StackPanel HorizontalAlignment="Center">
-						<TextBlock Margin="0,0,40,20" >
-							Авторизация
-						</TextBlock>
-					</StackPanel>
-					<StackPanel >
-						<TextBlock>Логин:</TextBlock>
-						<TextBox Text="{Binding Login}" IsEnabled="{Binding TextEnab}"></TextBox>
-						<TextBlock >Пароль:</TextBlock>
-						<TextBox Text="{Binding Password}" IsEnabled="{Binding TextEnab}" PasswordChar="*"/>
-						<Button HorizontalAlignment="Center" Content="Войти" Command="{Binding Authorization}" IsDefault="True" IsVisible="{Binding ButVis}" />
-						<TextBlock Text="{Binding Message}"></TextBlock>
-					</StackPanel>
-				</StackPanel>
-			</Border>
-		</StackPanel>
-		<StackPanel IsVisible="{Binding StackVis}" Margin="20">
-			<Border Classes = "trash" Padding="40">
-				<StackPanel>
-				<TextBlock Text="{Binding MessageCaptcha}"></TextBlock>
-				<TextBox Text="{Binding ItCaptcha}"></TextBox>
-				<Button HorizontalAlignment="Center" Content="Проверить" Command="{Binding Trying}" IsDefault="True" IsVisible="{Binding ButCapVis}" />
-				<UserControl Content="{Binding Can}"></UserControl>
-				</StackPanel>
-			</Border>
-		</StackPanel>
+		<UserControl Content="{Binding PageContent}"></UserControl>
 	</StackPanel>
 </Window>

+ 40 - 0
Captcha/Views/Page1.axaml

@@ -0,0 +1,40 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+                xmlns:vm="using:Captcha.ViewModels"
+			 mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+				x:DataType="vm:Page1VM"
+			 x:Class="Captcha.Page1">
+	<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal">
+		<StackPanel Name="Login" Margin="20">
+			<Border Classes = "trash" Padding="40">
+				<StackPanel >
+					<StackPanel HorizontalAlignment="Center">
+						<TextBlock Margin="0,0,40,20" >
+							Авторизация
+						</TextBlock>
+					</StackPanel>
+					<StackPanel >
+						<TextBlock>Логин:</TextBlock>
+						<TextBox Text="{Binding Login}" IsEnabled="{Binding TextEnab}"></TextBox>
+						<TextBlock >Пароль:</TextBlock>
+						<TextBox Text="{Binding Password}" IsEnabled="{Binding TextEnab}" PasswordChar="*"/>
+						<Button HorizontalAlignment="Center" Content="Войти" Command="{Binding Authorization}" IsDefault="True" IsVisible="{Binding ButVis}" />
+						<TextBlock Text="{Binding Message}"></TextBlock>
+					</StackPanel>
+				</StackPanel>
+			</Border>
+		</StackPanel>
+		<StackPanel IsVisible="{Binding StackVis}" Margin="20">
+			<Border Classes = "trash" Padding="40">
+				<StackPanel>
+					<TextBlock Text="{Binding MessageCaptcha}"></TextBlock>
+					<TextBox Text="{Binding ItCaptcha}"></TextBox>
+					<Button HorizontalAlignment="Center" Content="Проверить" Command="{Binding Trying}" IsDefault="True" IsVisible="{Binding ButCapVis}" />
+					<UserControl Content="{Binding Can}"></UserControl>
+				</StackPanel>
+			</Border>
+		</StackPanel>
+	</StackPanel>
+</UserControl>

+ 15 - 0
Captcha/Views/Page1.axaml.cs

@@ -0,0 +1,15 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Captcha.ViewModels;
+
+namespace Captcha;
+
+public partial class Page1 : UserControl
+{
+    public Page1()
+    {
+        InitializeComponent();
+        DataContext = new Page1VM();
+    }
+}

+ 33 - 0
Captcha/Views/PageCalculate.axaml

@@ -0,0 +1,33 @@
+<UserControl xmlns="https://github.com/avaloniaui"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+                        xmlns:vm="using:Captcha.ViewModels"
+			 mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
+                        x:DataType="vm:PageCalculateVM"
+			 x:Class="Captcha.PageCalculate">
+	<StackPanel HorizontalAlignment="Center" Name="Login" Margin="20">
+			<Border Classes = "trash" Padding="40">
+				<StackPanel >
+					<StackPanel>
+						<TextBlock Margin="0,0,0,20" >
+							Выберете арифметическую операцию:
+						</TextBlock>
+						<ComboBox Margin="0,0,0,20" HorizontalAlignment = "Center" ItemsSource="{Binding Arif}" SelectedItem="{Binding SelIt}"></ComboBox>
+					</StackPanel>
+					<StackPanel HorizontalAlignment = "Center" Orientation="Horizontal">
+						<TextBox Text="{Binding A}" Margin="0,0,20,20"></TextBox>
+						<TextBlock Text="{Binding C}" Margin="0,0,20,20"></TextBlock>
+						<TextBox Text="{Binding B}" Margin="0,0,0,20"></TextBox>
+					</StackPanel>
+					<StackPanel>
+						<Button HorizontalAlignment = "Center" Margin="0,0,0,20" Content="Вычислить"/>
+						<StackPanel Orientation="Horizontal">
+							<TextBlock Text="Результат: " Margin="0,0,0,20"></TextBlock>
+							<TextBlock Text="{Binding Result}" Margin="0,0,0,20"></TextBlock>
+						</StackPanel>
+					</StackPanel>					
+				</StackPanel>
+			</Border>
+		</StackPanel>
+</UserControl>

+ 15 - 0
Captcha/Views/PageCalculate.axaml.cs

@@ -0,0 +1,15 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Captcha.ViewModels;
+
+namespace Captcha;
+
+public partial class PageCalculate : UserControl
+{
+    public PageCalculate()
+    {
+        InitializeComponent();
+        DataContext = new PageCalculateVM();
+    }
+}