Przeglądaj źródła

all pretty calculator

bai 3 tygodni temu
rodzic
commit
09edd4515c

BIN
task5_avalonia_mvvm_start/Assets/bg.png


+ 58 - 3
task5_avalonia_mvvm_start/Styles1.axaml

@@ -5,27 +5,82 @@
       <!-- Add Controls for Previewer Here -->
     </Border>
   </Design.PreviewWith>
-
+	<Style Selector="StackPanel.spBackground">
+		<!--<Setter	Property="Background" Value="#f5fec9"></Setter>-->
+		<Setter Property="VerticalAlignment" Value="Stretch"></Setter>
+		<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
+	</Style>
 	<Style Selector="TextBox.tbLogin">
 		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
 		<Setter Property="Width" Value="500"></Setter>
-		<Setter Property="Margin" Value="10"></Setter>
-		<!--<Setter Property=""></Setter>-->
+		<Setter Property="Margin" Value="0 20 0 10"></Setter>
+		<Setter Property="Background" Value="#adbf8f"></Setter>
 	</Style>
 	<Style Selector="TextBox.tbPassword">
 		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
 		<Setter Property="Width" Value="500"></Setter>
 		<Setter Property="Margin" Value="10"></Setter>
+		<Setter Property="Background" Value="#adbf8f"></Setter>
 	</Style>
 	<Style Selector="Button.bAuth">
 		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
 		<Setter Property="Width" Value="500"></Setter>
 		<Setter Property="Margin" Value="10"></Setter>
 		<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
+		<Setter Property="FontSize" Value="17"></Setter>
+		<Setter Property="Background" Value="#4f4114"></Setter>
+		<Setter Property="Foreground" Value="#f5fec9"></Setter>
+	</Style>
+	<Style Selector="Button.bCalc">
+		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
+		<Setter Property="Width" Value="400"></Setter>
+		<Setter Property="Margin" Value="10"></Setter>
+		<Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
+		<Setter Property="FontSize" Value="17"></Setter>
+		<Setter Property="Background" Value="#4f4114"></Setter>
+		<Setter Property="Foreground" Value="#f5fec9"></Setter>
+		<Setter Property="Padding" Value="10"></Setter>
 	</Style>
 	<Style Selector="TextBlock.tblSuccess">
 		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
 		<Setter Property="Width" Value="500"></Setter>
 		<Setter Property="Margin" Value="10"></Setter>
 	</Style>
+	<Style Selector="TextBlock.headerCalc">
+		<Setter Property="FontSize" Value="25"></Setter>
+		<Setter Property="Padding" Value="0 25 0 50"></Setter>
+		<Setter Property="TextAlignment" Value="Center"></Setter>
+		<Setter Property="Foreground" Value="#4f4114"></Setter>
+		<Setter Property="FontWeight" Value="Bold"></Setter>
+	</Style>
+	<Style Selector="TextBlock.footerCalc">
+		<Setter Property="FontSize" Value="25"></Setter>
+		<Setter Property="TextAlignment" Value="Center"></Setter>
+		<Setter Property="Foreground" Value="#788e3c"></Setter>
+	</Style>
+	<Style Selector="StackPanel.spAriphmetic">
+		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
+		<Setter Property="Margin" Value="0 0 0 50"></Setter>
+	</Style>
+	<Style Selector="ComboBox.cbAriphm">
+		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
+		<Setter Property="Width" Value="250"></Setter>
+		<Setter Property="Margin" Value="0 0 0 25"></Setter>
+		<Setter Property="FontSize" Value="17"></Setter>
+		<Setter Property="Background" Value="#adbf8f"></Setter>
+		<Setter Property="Foreground" Value="#f5fec9"></Setter>
+	</Style>
+	<Style Selector="StackPanel.spNums">
+		<Setter Property="HorizontalAlignment" Value="Center"></Setter>
+	</Style>
+	<Style Selector="TextBox.tbNum">
+		<Setter Property="Background" Value="#adbf8f"></Setter>
+		<Setter Property="Margin" Value="20 0 20 0"></Setter>
+		<Setter Property="Width" Value="110"></Setter>
+	</Style>
+	<Style Selector="TextBlock.tbNum">
+		<Setter Property="Foreground" Value="#4f4114"></Setter>
+		<Setter Property="Margin" Value="10 0 10 0"></Setter>
+		<Setter Property="FontSize" Value="17"></Setter>
+	</Style>
 </Styles>

+ 22 - 21
task5_avalonia_mvvm_start/ViewModels/MainWindowViewModel.cs

@@ -13,15 +13,14 @@ namespace task5_avalonia_mvvm_start.ViewModels
     public class MainWindowViewModel : ViewModelBase
     {
         #region timer
-        DispatcherTimer timer = new DispatcherTimer(); // создание объекта для таймера
+        DispatcherTimer timer = new DispatcherTimer();
 
         public MainWindowViewModel()
         {
-            timer.Interval = new TimeSpan(0, 0, 10); // задание того, на какое кол-во времени будет запущен таймер
-            timer.Tick += new EventHandler(timer_tick); // добавление объекту таймера событие, запускающего генерацию капчи (обработчик timer_tick реализован ниже)
+            timer.Interval = new TimeSpan(0, 0, 10);
+            timer.Tick += new EventHandler(timer_tick);
         }
 
-        // событие, которое происходит после истечения времени таймера
         private void timer_tick(object sender, EventArgs e)
         {
             CaptchaAnswer = "";
@@ -35,8 +34,8 @@ namespace task5_avalonia_mvvm_start.ViewModels
         #endregion
 
         #region properties
-        string l;
-        string p;
+        string loginEntered;
+        string passwordEntered;
         string success;
         string captchaKey = "";
         string captchaAnswer;
@@ -46,11 +45,11 @@ namespace task5_avalonia_mvvm_start.ViewModels
         int numberOfTry = 1;
         int remainingSeconds = DateTime.Now.Second;
 
-        public string L { get => l; set => this.RaiseAndSetIfChanged(ref l, value); }
-        public string P { get => p; set => this.RaiseAndSetIfChanged(ref p, value); }
+        public string LoginEntered { get => loginEntered; set => this.RaiseAndSetIfChanged(ref loginEntered, value); }
+        public string PasswordEntered { get => passwordEntered; set => this.RaiseAndSetIfChanged(ref passwordEntered, value); }
         public string Success { get => success; set => this.RaiseAndSetIfChanged(ref success, value); }
         
-        UserControl _us = new CalculatorView();
+        UserControl _us = new Auth();
         CalculatorViewModel calculatorVM = new CalculatorViewModel();
 
         public UserControl Us
@@ -77,7 +76,7 @@ namespace task5_avalonia_mvvm_start.ViewModels
 
         public void ToAuth()
         {
-            if (L != "" && L == Models.AuthData.login && P != "" && P == Models.AuthData.password)
+            if (LoginEntered != "" && LoginEntered == Models.AuthData.login && PasswordEntered != "" && PasswordEntered == Models.AuthData.password)
             {
                 Success = "Авторизация успешна";
                 toCalculator();
@@ -86,8 +85,8 @@ namespace task5_avalonia_mvvm_start.ViewModels
             {
                 BAuthIsVisible = false;
                 CaptchaIsVisible = true;
-                L = "";
-                P = "";
+                LoginEntered = "";
+                PasswordEntered = "";
                 Success = "Ошибка! Подтвердите, что вы не робот и попробуйте снова";
                 CreateCaptcha();
             }
@@ -97,13 +96,13 @@ namespace task5_avalonia_mvvm_start.ViewModels
         {
             if (numberOfTry == 1)
             {
-                if (L != "" && L == Models.AuthData.login && P != "" && P == Models.AuthData.password && CaptchaAnswer == captchaKey) toCalculator();
+                if (LoginEntered != "" && LoginEntered == Models.AuthData.login && PasswordEntered != "" && PasswordEntered == Models.AuthData.password && CaptchaAnswer == captchaKey) toCalculator();
                 else
                 {
                     Captcha = null;
                     CaptchaIsVisible = false;
-                    L = "";
-                    P = "";
+                    LoginEntered = "";
+                    PasswordEntered = "";
                     CaptchaAnswer = "";
                     TbIsReadOnly = true;
                     timer.Start();
@@ -112,13 +111,13 @@ namespace task5_avalonia_mvvm_start.ViewModels
             }
             else
             {
-                if (L != "" && L == Models.AuthData.login && P != "" && P == Models.AuthData.password && CaptchaAnswer == captchaKey) toCalculator();
+                if (LoginEntered != "" && LoginEntered == Models.AuthData.login && PasswordEntered != "" && PasswordEntered == Models.AuthData.password && CaptchaAnswer == captchaKey) toCalculator();
                 else
                 {
                     Captcha = null;
                     CaptchaIsVisible = false;
-                    L = "";
-                    P = "";
+                    LoginEntered = "";
+                    PasswordEntered = "";
                     CaptchaAnswer = "";
                     TbIsReadOnly = true;
                     timer.Start();
@@ -137,9 +136,10 @@ namespace task5_avalonia_mvvm_start.ViewModels
             {
                 Width = 600,
                 Height = 400,
-                Background = color
+                Background = color,
             };
 
+            //вспомогательные переменные для управления отступами в капче
             int b = 55;
             int t = 60;
             int b1 = 100;
@@ -150,7 +150,7 @@ namespace task5_avalonia_mvvm_start.ViewModels
             for (int i = 0; i < countSigns; i++)
             {
                 TextBlock sign = new TextBlock();
-                if (rnd.Next(2) == 0)
+                if (rnd.Next(2) == 0) //выбор - генерируем число или букву
                 {
                     sign.Text = rnd.Next(10).ToString();
                     sign.FontSize = rnd.Next(30, 55);
@@ -183,7 +183,8 @@ namespace task5_avalonia_mvvm_start.ViewModels
                 }
                 canvas.Children.Add(sign);
             }
-            // генерируем числа
+
+            //генерация линий
             for (int i = 0; i < 20; i++)
             {
                 Line line = new Line()

+ 11 - 9
task5_avalonia_mvvm_start/Views/Auth.axaml

@@ -6,13 +6,15 @@
              x:Class="task5_avalonia_mvvm_start.Auth"
 			 x:DataType="vm:MainWindowViewModel"
 			 xmlns:vm="using:task5_avalonia_mvvm_start.ViewModels">
-	<StackPanel>
-		<TextBox Classes="tbLogin" Watermark="Логин" IsReadOnly="{Binding TbIsReadOnly}" Text="{Binding L}"></TextBox>
-		<TextBox Classes="tbPassword" Watermark="Пароль" IsReadOnly="{Binding TbIsReadOnly}" Text="{Binding P}"></TextBox>
-		<Button Classes="bAuth" IsVisible="{Binding BAuthIsVisible}" Command="{Binding ToAuth}">Авторизоваться</Button>
-		<TextBlock Classes="tblSuccess" Text="{Binding Success}"></TextBlock>
-		<UserControl Content="{Binding Captcha}"></UserControl>
-		<TextBox Classes="tbPassword" IsVisible="{Binding CaptchaIsVisible}" Watermark="Введите текст с картинки" Text="{Binding CaptchaAnswer}"></TextBox>
-		<Button Classes="bAuth" IsVisible="{Binding CaptchaIsVisible}" Command="{Binding checkCaptcha}">Проверить</Button>
-	</StackPanel>
+	<Grid>
+		<StackPanel Classes="spBackground">
+			<TextBox Classes="tbLogin" Watermark="Логин" IsReadOnly="{Binding TbIsReadOnly}" Text="{Binding LoginEntered}"></TextBox>
+			<TextBox Classes="tbPassword" Watermark="Пароль" IsReadOnly="{Binding TbIsReadOnly}" Text="{Binding PasswordEntered}"></TextBox>
+			<Button Classes="bAuth" IsVisible="{Binding BAuthIsVisible}" Command="{Binding ToAuth}">Авторизоваться</Button>
+			<TextBlock Classes="tblSuccess" Text="{Binding Success}"></TextBlock>
+			<UserControl Content="{Binding Captcha}"></UserControl>
+			<TextBox Classes="tbPassword" IsVisible="{Binding CaptchaIsVisible}" Watermark="Введите текст с картинки" Text="{Binding CaptchaAnswer}"></TextBox>
+			<Button Classes="bAuth" IsVisible="{Binding CaptchaIsVisible}" Command="{Binding checkCaptcha}">Проверить</Button>
+		</StackPanel>
+	</Grid>
 </UserControl>

+ 21 - 24
task5_avalonia_mvvm_start/Views/CalculatorView.axaml

@@ -6,29 +6,26 @@
              x:Class="task5_avalonia_mvvm_start.CalculatorView"
 			 x:DataType="vm:MainWindowViewModel"
 			 xmlns:vm="using:task5_avalonia_mvvm_start.ViewModels">
-	<StackPanel>
-		<TextBlock Text="Выберите арифметическую операцию"></TextBlock>
-		<!--<ComboBox Name="cb" ItemsSource="{Binding OperationsList}" SelectedItem="{Binding SelectedOperation}">
-			<ComboBox.ItemTemplate>
-				<DataTemplate>
-					<TextBlock Text="{Binding Name}"/>
-				</DataTemplate>
-			</ComboBox.ItemTemplate>
-		</ComboBox>-->
-		<ComboBox ItemsSource="{Binding CalculatorVM.OperationsList}" SelectedItem="{Binding CalculatorVM.SelectedOperation}">
-			<ComboBox.ItemTemplate>
-				<DataTemplate>
-					<TextBlock Text="{Binding Name}"/>
-				</DataTemplate>
-			</ComboBox.ItemTemplate>
-		</ComboBox>
-		<StackPanel Orientation="Horizontal">
-			<TextBox Text="{Binding CalculatorVM.Num1}"></TextBox>
-			<TextBlock Text="{Binding CalculatorVM.SelectedSign}"></TextBlock>
-			<TextBox Text="{Binding CalculatorVM.Num2}"></TextBox>
+	<Grid>
+		<StackPanel Classes="spBackground">
+			<TextBlock Classes="headerCalc" Text="Выберите арифметическую операцию"></TextBlock>
+			<StackPanel Classes="spAriphmetic">
+				<ComboBox Classes="cbAriphm" ItemsSource="{Binding CalculatorVM.OperationsList}" SelectedItem="{Binding CalculatorVM.SelectedOperation}">
+					<ComboBox.ItemTemplate>
+						<DataTemplate>
+							<TextBlock Text="{Binding Name}"/>
+						</DataTemplate>
+					</ComboBox.ItemTemplate>
+				</ComboBox>
+				<StackPanel Classes="spNums" Orientation="Horizontal">
+					<TextBox Classes="tbNum" Text="{Binding CalculatorVM.Num1}"></TextBox>
+					<TextBlock Classes="tbNum" Text="{Binding CalculatorVM.SelectedSign}"></TextBlock>
+					<TextBox Classes="tbNum" Text="{Binding CalculatorVM.Num2}"></TextBox>
+				</StackPanel>
+			</StackPanel>
+			<Button Classes="bCalc" Command="{Binding CalculatorVM.ToCalculate}">Вычислить</Button>
+			<TextBlock Classes="headerCalc">Результат:</TextBlock>
+			<TextBlock Classes="footerCalc" Text="{Binding CalculatorVM.Result}"></TextBlock>
 		</StackPanel>
-		<Button Command="{Binding CalculatorVM.ToCalculate}">Вычислить</Button>
-		<TextBlock>Результат:</TextBlock>
-		<TextBlock Text="{Binding CalculatorVM.Result}"></TextBlock>
-	</StackPanel>
+	</Grid>
 </UserControl>

+ 5 - 3
task5_avalonia_mvvm_start/Views/MainWindow.axaml

@@ -7,15 +7,17 @@
         x:Class="task5_avalonia_mvvm_start.Views.MainWindow"
         x:DataType="vm:MainWindowViewModel"
         Icon="/Assets/avalonia-logo.ico"
-        Title="task5_avalonia_mvvm_start">
+        Title="Calculator">
 
     <Design.DataContext>
         <!-- This only sets the DataContext for the previewer in an IDE,
              to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
         <vm:MainWindowViewModel/>
     </Design.DataContext>
-
-	<StackPanel>
+	<Window.Background>
+		<ImageBrush Source="/Assets/bg.png" Stretch="Fill"></ImageBrush>
+	</Window.Background>
+	<StackPanel Classes="spBackground">
 		<UserControl Content="{Binding Us}"></UserControl>
 	</StackPanel>