Selaa lähdekoodia

some changes in adding in db

AngelikaSuhareva 4 kuukautta sitten
vanhempi
commit
4d9a5c2c30

+ 24 - 7
ViewModels/AddEmployeesViewModel.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using Acosta.Models;
 using Acosta.Views;
+using Avalonia.Controls;
 using ReactiveUI;
 
 namespace Acosta.ViewModels
@@ -10,13 +11,16 @@ namespace Acosta.ViewModels
 	{
         SuharevaContext myConnection;
         Employee currentUser;
-  /*      string f;
-        string i;
-        string o;
-        string phone;
-        string email;
-        int role;
-        string password;*/
+
+        private UserControl uce = new AddTradeNetworksView();
+        public UserControl UCE { get => uce; set => this.RaiseAndSetIfChanged(ref uce, value); }
+        /*      string f;
+              string i;
+              string o;
+              string phone;
+              string email;
+              int role;
+              string password;*/
 
         public AddEmployeesViewModel(SuharevaContext myConnection)
         {
@@ -31,6 +35,12 @@ namespace Acosta.ViewModels
             CurrentUser.Role = Role;*/
             myConnection.Add(currentUser);
         }
+        public AddEmployeesViewModel(SuharevaContext myConnection, int userID)
+        {
+            this.myConnection = myConnection;
+            CurrentUser = new Employee();
+            myConnection.Add(currentUser);
+        }
 
         public Employee CurrentUser { get => currentUser; set => currentUser = value; }
 
@@ -41,5 +51,12 @@ namespace Acosta.ViewModels
         public string F { get => f; set => f = value; }
         public string I { get => i; set => i = value; }
         public string O { get => o; set => o = value; }*/
+
+        public void SaveUser()
+        {
+            
+            myConnection.SaveChanges();
+            UCE = new EmployeesView();
+        }
     }
 }

+ 12 - 1
ViewModels/AddTradeNetworksViewViewModel.cs

@@ -2,6 +2,8 @@ using System;
 using System.Collections.Generic;
 using ReactiveUI;
 using Acosta.Models;
+using Acosta.Views;
+using Avalonia.Controls;
 
 namespace Acosta.ViewModels
 {
@@ -10,7 +12,10 @@ namespace Acosta.ViewModels
 		SuharevaContext myConnection;
 		TradeNetwork currentTrade;
 
-		public AddTradeNetworksViewViewModel(SuharevaContext myConnection)
+        private UserControl uct = new AddTradeNetworksView();
+        public UserControl UCT { get => uct; set => this.RaiseAndSetIfChanged(ref uct, value); }
+
+        public AddTradeNetworksViewViewModel(SuharevaContext myConnection)
 		{
             this.myConnection = myConnection;
             CurrentTrade = new TradeNetwork();
@@ -18,5 +23,11 @@ namespace Acosta.ViewModels
         }
 
         public TradeNetwork CurrentTrade { get => currentTrade; set => currentTrade = value; }
+
+        public void SaveNetwork()
+        {
+            myConnection.SaveChanges();
+            UCT = new TradeNetworksView();
+        }
     }
 }

+ 17 - 18
ViewModels/MainWindowViewModel.cs

@@ -19,8 +19,8 @@ namespace Acosta.ViewModels
         AddTradeNetworksViewViewModel addTradeNetworksVM = new AddTradeNetworksViewViewModel(myConnection);
         public AddTradeNetworksViewViewModel AddTradeNetworksVM { get => addTradeNetworksVM; set => addTradeNetworksVM = value; }
 
-        /*AddEmployeesViewModel addEmployeesViewModel = new AddEmployeesViewModel(myConnection);
-        public AddEmployeesViewModel AddEmployeesViewModel { get => addEmployeesViewModel; set => addEmployeesViewModel = value; }*/
+        AddEmployeesViewModel addEmployeesVM = new AddEmployeesViewModel(myConnection);
+        public AddEmployeesViewModel AddEmployeesVM { get => addEmployeesVM; set => addEmployeesVM = value; }
 
 
         AddOutletsViewModel outletVM = new AddOutletsViewModel(myConnection);
@@ -34,17 +34,9 @@ namespace Acosta.ViewModels
         PersonalAccountViewModel personalAccountVM = new PersonalAccountViewModel(myConnection);
         public PersonalAccountViewModel PersonalAccountVM { get => personalAccountVM; set => personalAccountVM = value; }
 
-        public void SaveNetwork()
-        {
-            myConnection.SaveChanges();
-            UC = new TradeNetworksView();
-        }
 
-        /*public void SaveUser()
-        {
-            myConnection.SaveChanges();
-            UC = new EmployeesView();
-        }*/
+
+        
 
         /*public void SaveData()
         {
@@ -78,7 +70,7 @@ namespace Acosta.ViewModels
         }
 
         public List<Project> ListProjects => myConnection.Projects.ToList();
-        public List<Employee> ListEmployees => myConnection.Employees.ToList();
+        public List<Employee> ListEmployees => myConnection.Employees.ToList().Where(x => x.Employeesid != curUsId).ToList();
         public List<Outlet> ListOutlets => myConnection.Outlets.ToList();
         //public List<string> fkTrade => myConnection.TradeNetworks.ToList().Select(x => x.Title).Where()
         //List<a> newList = new List<a>(new a((from p in myConnection.Outlets.ToList() select p.Outletid).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.Outlets.ToList() select p.Address).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.Outlets.ToList() select p.Location).ToImmutableList().ToList().FirstOrDefault(), (from p in myConnection.TradeNetworks.ToList() select p.Title).ToImmutableList().ToList().FirstOrDefault()));
@@ -144,6 +136,8 @@ namespace Acosta.ViewModels
         {
             UC = new EditVisitView();
         }
+
+
         public void AddProjectsView()
         {
             UC = new AddProjectsView();
@@ -156,6 +150,8 @@ namespace Acosta.ViewModels
         {
             UC = new EditProjectsView();
         }
+
+
         public void BackPersonalAccountView()
         {
             UC = new PersonalAccountView();
@@ -164,15 +160,12 @@ namespace Acosta.ViewModels
         {
             UC = new ChangePasswordView();
         }
-
-
-
-
-
         public void ExitFromProfile()
         {
             UC = new AuthorizationView();
         }
+
+
         public void AddTradeNetworksView()
         {
             UC = new AddTradeNetworksView();
@@ -181,6 +174,8 @@ namespace Acosta.ViewModels
         {
             UC = new TradeNetworksView();
         }
+
+
         public void AddOutletsView()
         {
             UC = new AddOutletsView();
@@ -193,8 +188,11 @@ namespace Acosta.ViewModels
         {
             UC = new EditOutletsView();
         }
+
+
         public void AddEmployeesView()
         {
+
             UC = new AddEmployeesView();
         }
         public void BackEmployeesView()
@@ -203,6 +201,7 @@ namespace Acosta.ViewModels
         }
         public void EditEmployeesView(int userID)
         {
+            
             UC = new EditEmployeesView();
         }
     }

+ 8 - 8
Views/AddEmployeesView.axaml

@@ -152,37 +152,37 @@
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Фамилия:</TextBlock>
-						<TextBox  Watermark="Фамилия" Width="360" Margin="160 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Surname}" Watermark="Фамилия" Width="360" Margin="160 20 0 0"></TextBox>
 					</StackPanel>
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Имя:</TextBlock>
-						<TextBox  Watermark="Имя" Width="360" Margin="200 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Name}" Watermark="Имя" Width="360" Margin="200 20 0 0"></TextBox>
 					</StackPanel>
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Отчетсво:</TextBlock>
-						<TextBox  Watermark="Отчетсво" Width="360" Margin="156 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Patronymic}" Watermark="Отчетсво" Width="360" Margin="156 20 0 0"></TextBox>
 					</StackPanel>
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Почта:</TextBlock>
-						<TextBox  Watermark="Почта" Width="360" Margin="183 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Email}" Watermark="Почта" Width="360" Margin="183 20 0 0"></TextBox>
 					</StackPanel>
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Пароль:</TextBlock>
-						<TextBox  Watermark="Пароль" Width="360" Margin="170 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Password}" Watermark="Пароль" Width="360" Margin="170 20 0 0"></TextBox>
 					</StackPanel>
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Телефон:</TextBlock>
-						<TextBox  Watermark="Телефон" Width="360" Margin="165 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Phonenumber}" Watermark="Телефон" Width="360" Margin="165 20 0 0"></TextBox>
 					</StackPanel>
 					<Border Background="#969696" CornerRadius="13"  Width="1150" Height="0.5" Margin="200 30 0 10" HorizontalAlignment="Left"></Border>
 					<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Роль:</TextBlock>
-						<TextBox  Watermark="Роль" Width="360" Margin="200 20 0 0"></TextBox>
+						<TextBox Text="{Binding AddEmployeesVM.CurrentUser.Role}" Watermark="Роль" Width="360" Margin="200 20 0 0"></TextBox>
 					</StackPanel>
 					<!--<StackPanel Orientation="Horizontal">
 						<TextBlock Classes="TextToTextBox">Роль:</TextBlock>
@@ -262,7 +262,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="">
+			<Button Classes="BtSave" Command="{Binding AddEmployeesVM.SaveUser}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>

+ 1 - 1
Views/AddOutletsView.axaml

@@ -227,7 +227,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveNetwork}">
+			<Button Classes="BtSave" Command="{}">
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>
 		</StackPanel>

+ 1 - 1
Views/AddTradeNetworksView.axaml

@@ -185,7 +185,7 @@
 			<Button Classes="BtDelete" Command="">
 				<TextBlock Classes="TextBtDelete">Удалить</TextBlock>
 			</Button>
-			<Button Classes="BtSave" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).SaveNetwork}">
+			<Button Classes="BtSave" Command="{Binding AddTradeNetworksVM.SaveNetwork}">
 				
 				<TextBlock Classes="TextBtSave">Добавить</TextBlock>
 			</Button>