Explorar el Código

all crushed again

bai hace 4 meses
padre
commit
4e16bf9ec8

+ 28 - 9
ViewModels/MainWindowViewModel.cs

@@ -42,6 +42,9 @@ namespace Acosta.ViewModels
         VisitsViewModel visitsVM = new VisitsViewModel(myConnection4);
         public VisitsViewModel VisitsVM { get => visitsVM; set => visitsVM = value; }
 
+        UserViewModel userVM = new UserViewModel(myConnection);
+        public UserViewModel UserVM { get => userVM; set => userVM = value; }
+
         public void SaveNetwork()
         {
             myConnection2.SaveChanges();
@@ -66,14 +69,16 @@ namespace Acosta.ViewModels
             UC = new VisitsView();
         }
 
+
+
         public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); } 
         private UserControl uc = new AuthorizationView();
         public int curUsId;
-
+        Employee? currentUser;
         public void LoadPersonalAccount()
         {
-            
-            Employee? currentUser = myConnection.Employees.FirstOrDefault(x => x.Email == AuthorizationVM.Login && x.Password == AuthorizationVM.Password);
+
+            currentUser = myConnection.Employees.FirstOrDefault(x => x.Email == AuthorizationVM.Login && x.Password == AuthorizationVM.Password);
             if (currentUser == null)
             {
                 AuthorizationVM.Message = "Пользователя с такими данными не существует.";
@@ -88,25 +93,39 @@ namespace Acosta.ViewModels
                 curUsId = currentUser.Employeesid;
                 PersonalAccountVM = new PersonalAccountViewModel(myConnection, curUsId);
                 UC = new PersonalAccountView();
+                
             }
         }
 
+        public void SavePassword()
+        {
+            ChangePasswordView changePasswordView = new ChangePasswordView();
+            currentUser = myConnection.Employees.FirstOrDefault(x => x.Email == AuthorizationVM.Login && x.Password == AuthorizationVM.Password);
+            changePasswordView.cp(currentUser);
+            myConnection.SaveChanges();
+            UC = new PersonalAccountView();
+        }
+
         public List<Project> ListProjects => myConnection.Projects.ToList();
         public List<TradeNetwork> ListTrades => myConnection.TradeNetworks.ToList();
         public List<Employee> ListEmployees => myConnection.Employees.ToList().Where(x => x.Employeesid != curUsId).ToList();
         public List<Outlet> ListOutlets => myConnection.Outlets.ToList();
         public List<Visit> ListVisits => myConnection.Visits.ToList();
+        public List<Acceptance> ListAcceptance => myConnection.Acceptances.ToList();
+
+        
+
         //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()));
         //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()));
-        
+
         //public struct a
         //{
         //    int Outlerid;
         //    string Address;
         //    string Location;
         //    string TradeNetworks;
-            
+
 
         //    public a(int oid, string ad, string loc, string tn)
         //    {
@@ -138,9 +157,9 @@ namespace Acosta.ViewModels
         //          Visits = outlet.Visits
         //      })
         //.ToList();
-        
 
-        
+
+
 
 
 
@@ -159,7 +178,7 @@ namespace Acosta.ViewModels
         {
             UC = new VisitsView();
         }
-        public void EditVisitView()
+        public void EditVisitView(int userID)
         {
             UC = new EditVisitView();
         }
@@ -173,7 +192,7 @@ namespace Acosta.ViewModels
         {
             UC = new ProjectsView();
         }
-        public void EditProjectsView()
+        public void EditProjectsView(int userID)
         {
             UC = new EditProjectsView();
         }

+ 38 - 0
ViewModels/UserViewModel.cs

@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Acosta.Models;
+using ReactiveUI;
+
+namespace Acosta.ViewModels
+{
+	public class UserViewModel : ReactiveObject
+	{
+        SuharevaContext myConnection;
+        Employee? currentUser;
+
+        public UserViewModel(SuharevaContext myC)
+        {
+            this.myConnection = myC;
+            CurrentUser = new Employee();
+        }
+        public UserViewModel(SuharevaContext myConnection, int id, string password)
+        {
+            this.myConnection = myConnection;
+            currentUser = myConnection.Employees.FirstOrDefault(x => x.Employeesid == id);
+            if (password == CurrentUser.Password)
+            {
+                currentUser.Surname = currentUser.Surname;
+                currentUser.Name = currentUser.Name;
+                currentUser.Patronymic = currentUser.Patronymic;
+                currentUser.Email = currentUser.Email;
+                currentUser.Phonenumber = currentUser.Phonenumber;
+                currentUser.Role = currentUser.Role;
+                currentUser.Password = password;
+                myConnection.SaveChanges();
+            }
+        }
+
+        public Employee? CurrentUser { get => currentUser; set => currentUser = value; }
+    }
+}

+ 27 - 2
Views/ChangePasswordView.axaml

@@ -117,6 +117,29 @@
 					<Style Selector="TextBox:focus /template/ TextBlock#PART_Watermark">
 						<Setter Property="TextBox.BorderBrush" Value="#A10009" />
 					</Style>
+					
+					
+					<Style Selector="TextBlock.TextBtSave">
+						<Setter Property="Foreground" Value="#F5F5F5"></Setter>
+						<Setter Property="FontFamily" Value="Roboto"></Setter>
+						<Setter Property="FontWeight" Value="Medium"></Setter>
+						<Setter Property="FontSize" Value="20"></Setter>
+						<Setter Property="HorizontalAlignment" Value="Center"></Setter>
+						<Setter Property="VerticalAlignment" Value="Center"></Setter>
+					</Style>
+					<Style Selector="Button.BtSave">
+						<Setter Property="Width" Value="180"></Setter>
+						<Setter Property="Height" Value="38"></Setter>
+						<Setter Property="Margin" Value="0 740 30 20"></Setter>
+						<Setter Property="Background" Value="#E40714"></Setter>
+						<Setter Property="CornerRadius" Value="13"></Setter>
+					</Style>
+					<Style Selector="Button.BtSave:pointerover /template/ ContentPresenter">
+						<Setter Property="Background" Value="#A10009"></Setter>
+					</Style>
+					<Style Selector="Button.BtSave:pressed">
+						<Setter Property="RenderTransform" Value="none"/>
+					</Style>
 				</StackPanel.Styles>
 				<StackPanel Orientation="Horizontal" Margin="0 0 0 30">
 					<TextBlock Classes="TextToTextBox" Margin="0 0 50 0">Введите ваш пароль:</TextBlock>
@@ -124,9 +147,11 @@
 				</StackPanel>
 				<StackPanel Orientation="Horizontal">
 					<TextBlock Classes="TextToTextBox">Введите новый пароль:</TextBlock>
-					<TextBox Width="360"></TextBox>
+					<TextBox Name="tbNewPas" Width="360"></TextBox>
 				</StackPanel>
-
+				<Button Classes="BtSave" Command="{Binding SavePassword}">
+					<TextBlock Classes="TextBtSave">Сохранить</TextBlock>
+				</Button>
 			</StackPanel>
 		</StackPanel>
 	</Grid>

+ 21 - 0
Views/ChangePasswordView.axaml.cs

@@ -1,13 +1,34 @@
+using Acosta.Models;
+using Acosta.ViewModels;
 using Avalonia;
 using Avalonia.Controls;
+using Avalonia.Interactivity;
 using Avalonia.Markup.Xaml;
+using Acosta.Views;
+using Avalonia.Controls;
+using ReactiveUI;
+using Acosta.Models;
+using System.Linq;
+using System.Collections.Generic;
+using Microsoft.EntityFrameworkCore;
+using System.Collections.Immutable;
+using System.Collections.ObjectModel;
 
 namespace Acosta.Views;
 
 public partial class ChangePasswordView : UserControl
 {
+    SuharevaContext myConnection;
+    AuthorizationViewModel authorizationVM = new AuthorizationViewModel();
+    public AuthorizationViewModel AuthorizationVM { get => authorizationVM; set => authorizationVM = value; }
     public ChangePasswordView()
     {
         InitializeComponent();
     }
+
+    public void cp(Employee? currentUser)
+    {
+        int curUsId = currentUser.Employeesid;
+        UserViewModel userVM = new UserViewModel(myConnection, curUsId, tbNewPas.Text, currentUser);
+    }
 }

+ 12 - 0
Views/PersonalAccountView.axaml

@@ -225,6 +225,18 @@
 									</DataTemplate>
 								</ListBox.ItemTemplate>
 							</ListBox>
+							<ComboBox ItemsSource="{Binding ListAcceptance}" IsVisible="False">
+								<ComboBox.ItemTemplate>
+									<DataTemplate>
+										<StackPanel Orientation="Horizontal" Margin="40 20 0 0">
+											<TextBlock Text="{Binding Acceptanceid}" Classes="EditTextBox" Width="70" Margin="0 0 140 0">Типа id</TextBlock>
+											<Border  Classes="Data" CornerRadius="13"  Width="220" Height="40" Margin="0 0 145 0">
+												<TextBlock Text="{Binding Title}" Classes="Data">Типа  адрес</TextBlock>
+											</Border>
+										</StackPanel>
+									</DataTemplate>
+								</ComboBox.ItemTemplate>
+							</ComboBox>
 						</StackPanel>
 					</Grid>
 				</Border>

+ 1 - 15
Views/VisitsView.axaml

@@ -204,25 +204,11 @@
 							<ListBox.ItemTemplate>
 								<DataTemplate>
 									<StackPanel Orientation="Horizontal" Margin="40 20 0 0">
-										<!--<TextBlock Text="{Binding Outletid}" Classes="EditTextBox" Width="70" Margin="0 0 140 0">Типа id</TextBlock>
-									<TextBlock Text="{Binding TradeNetworksNavigation.Title}" Classes="EditTextBox" Width="200" Margin="0 0 140 0">Типа название торговой сети</TextBlock>
-									<Border  Classes="Data" CornerRadius="13"  Width="220" Height="40" Margin="0 0 145 0">
-										<TextBlock Text="{Binding Address}" Classes="Data">Типа  адрес</TextBlock>
-									</Border>
-									<Border  Classes="Data" CornerRadius="13"  Width="280" Height="40">
-										<TextBlock Text="{Binding Location}" Classes="Data">Типа  местоположение</TextBlock>
-									</Border>-->
 										<TextBlock Text="{Binding OutletNavigation.Address}" Classes="TextColumn">Название торговой точки</TextBlock>
 										<TextBlock Text="{Binding ProjectNavigation.Title}" Classes="TextColumn">Название проекта</TextBlock>
 										<TextBlock Text="{Binding Visitdate}" Classes="TextColumn" Margin="30 0">Дата визита</TextBlock>
 										<TextBlock Text="{Binding Visittime}" Classes="TextColumn">Время визита</TextBlock>
-										<!--<ComboBox ItemsSource="{Binding }" SelectedItem="{Binding VisitsVM.CurrentVisit.AcceptedNavigation}" Classes="TextColumn">
-										<ComboBox.ItemTemplate>
-											<DataTemplate>
-												<TextBlock Text="{Binding }" Classes="TextColumn">Время визита</TextBlock>
-											</DataTemplate>
-										</ComboBox.ItemTemplate>
-									</ComboBox>-->
+										<TextBlock Text="{Binding AcceptedNavigation.Title}" Classes="TextColumn">Принят</TextBlock>
 									</StackPanel>
 								</DataTemplate>
 							</ListBox.ItemTemplate>

+ 15 - 0
Views/VisitsView.axaml.cs

@@ -1,5 +1,6 @@
 using Avalonia;
 using Avalonia.Controls;
+using Avalonia.Input;
 using Avalonia.Markup.Xaml;
 
 namespace Acosta.Views;
@@ -10,4 +11,18 @@ public partial class VisitsView : UserControl
     {
         InitializeComponent();
     }
+
+    //private void VisitClicked(object sender, PointerPressedEventArgs e, UserControl uc)
+    //{
+    //    // Assuming you have a navigation service instance or a way to swap views
+    //    // Navigate to another page (Page2.xaml in this example)
+
+    //    // Option 1: Using navigation service if available
+    //    // _navigationService.NavigateTo(new Page2());
+
+    //    // Option 2: Manually swapping views
+    //    // Assuming MainContentControl is where you display your pages
+    //    uc = new EditVisitView();
+        
+    //}
 }