Explorar el Código

add db, authorizationd and adding trade networks

AngelikaSuhareva hace 4 meses
padre
commit
1a61eb962a

+ 22 - 0
ViewModels/AddTradeNetworksViewViewModel.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+using Acosta.Models;
+
+namespace Acosta.ViewModels
+{
+	public class AddTradeNetworksViewViewModel : ReactiveObject
+	{
+		SuharevaContext myConnection;
+		TradeNetwork currentTrade;
+
+		public AddTradeNetworksViewViewModel(SuharevaContext myConnection)
+		{
+            this.myConnection = myConnection;
+            CurrentTrade = new TradeNetwork();
+            myConnection.Add(CurrentTrade);
+        }
+
+        public TradeNetwork CurrentTrade { get => currentTrade; set => currentTrade = value; }
+    }
+}

+ 17 - 0
ViewModels/AuthorizationViewModel.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using ReactiveUI;
+
+namespace Acosta.ViewModels
+{
+	public class AuthorizationViewModel : ReactiveObject
+	{
+        string login = "";
+        string password = "";
+        string message = "";
+
+        public string Login { get => login; set => login = value; }
+        public string Password { get => password; set => password = value; }
+        public string Message { get => message; set => this.RaiseAndSetIfChanged(ref message, value); }
+    }
+}

+ 33 - 3
ViewModels/MainWindowViewModel.cs

@@ -1,17 +1,47 @@
 using Acosta.Views;
 using Avalonia.Controls;
 using ReactiveUI;
+using Acosta.Models;
+using System.Linq;
+using Acosta.ViewModels;
 
 namespace Acosta.ViewModels
 {
     public class MainWindowViewModel : ViewModelBase
     {
-        public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
-        private UserControl uc = new AuthorizationView();
+        public static SuharevaContext myConnection = new SuharevaContext();
+
+        AuthorizationViewModel authorizationVM = new AuthorizationViewModel();
+        public AuthorizationViewModel AuthorizationVM { get => authorizationVM; set => authorizationVM = value; }
+
+        AddTradeNetworksViewViewModel addTradeNetworksVM = new AddTradeNetworksViewViewModel(myConnection);
+        public AddTradeNetworksViewViewModel AddTradeNetworksVM { get => addTradeNetworksVM; set => addTradeNetworksVM = value; }
+
+        public void SaveData()
+        {
+            myConnection.SaveChanges();
+            UC = new TradeNetworksView();
+        }
+
+        public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }  
+
+        private UserControl uc = new AddEmployeesView();
 
         public void LoadPersonalAccount()
         {
-            UC = new PersonalAccountView();
+            Employee? currentUser = myConnection.Employees.FirstOrDefault(x => x.Email == AuthorizationVM.Login && x.Password == AuthorizationVM.Password);
+            if (currentUser == null)
+            {
+                AuthorizationVM.Message = "Пользователя с такими данными не существует.";
+            }
+            else if (currentUser.Role != 1)
+            {
+                AuthorizationVM.Message = "Ваша роль не соответсвует требованиям.";
+            }
+            else
+            {
+                AuthorizationVM.Message = "Успех!";
+            }
         }
         public void ExitFromProfile()
         {

+ 2 - 2
Views/AddEmployeesView.axaml

@@ -1,10 +1,10 @@
 <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"
-             mc:Ignorable="d" d:DesignWidth="1550" d:DesignHeight="800.5"
 			 xmlns:vm="using:Acosta.ViewModels"
 			 x:DataType="vm:MainWindowViewModel"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+             mc:Ignorable="d" d:DesignWidth="1920" d:DesignHeight="1080"
              x:Class="Acosta.Views.AddEmployeesView">
 	<Grid>
 		<StackPanel Width="1550" Height="50" Background="#E40714" VerticalAlignment="Top">

+ 2 - 2
Views/AddTradeNetworksView.axaml

@@ -132,7 +132,7 @@
 			</StackPanel>
 			<StackPanel Orientation="Horizontal">
 				<TextBlock Classes="TextToTextBox">Наименование:</TextBlock>
-				<TextBox Watermark="Наименование торговой сети" Width="360"></TextBox>
+				<TextBox Text="{Binding AddTradeNetworksVM.CurrentTrade.Title}" Watermark="Наименование торговой сети" Width="360"></TextBox>
 			</StackPanel>
 		</StackPanel>
 		<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
@@ -187,7 +187,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="">
+			<Button Classes="BtSave" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveData}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>

+ 3 - 2
Views/AuthorizationView.axaml

@@ -26,8 +26,9 @@
 			</StackPanel.Styles>
 			
 			<Image Source="avares://Acosta/Assets/AcostaLogo.png" Width="450" Margin="0 0 0 100"></Image>
-			<TextBox Watermark="Логин" Width="360" FontSize="13" Margin="0 0 0 10"></TextBox>
-			<TextBox Watermark="Пароль" PasswordChar="•" Width="360"></TextBox>
+			<TextBox Text="{Binding AuthorizationVM.Login}" Watermark="Логин" Width="360" FontSize="13" Margin="0 0 0 10"></TextBox>
+			<TextBox Text="{Binding AuthorizationVM.Password}" Watermark="Пароль" PasswordChar="•" Width="360"></TextBox>
+			<TextBlock Text="{Binding AuthorizationVM.Message}"/>
 			<TextBlock Margin="0 5 0 0" HorizontalAlignment="Center" FontFamily="Roboto" FontSize="13" Foreground="#A52C2C"></TextBlock>
 			<Button HorizontalAlignment="Center" Margin="0 20 0 10" Width="230" Height="45" CornerRadius="10" Background="#E40714" Command="{Binding LoadPersonalAccount}">
 				<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Roboto" FontSize="16" FontWeight="DemiBold" Foreground="White">Войти</TextBlock>