소스 검색

Создание пользователя без информации о еде

semen 5 달 전
부모
커밋
9ed4ee1162
3개의 변경된 파일62개의 추가작업 그리고 30개의 파일을 삭제
  1. 16 1
      FoodLogProject/ViewModels/MainWindowViewModel.cs
  2. 29 0
      FoodLogProject/ViewModels/Page3ViewModel.cs
  3. 17 29
      FoodLogProject/Views/Page3.axaml

+ 16 - 1
FoodLogProject/ViewModels/MainWindowViewModel.cs

@@ -16,13 +16,28 @@ namespace FoodLogProject.ViewModels
         public static GaruaevContext myConnection = new GaruaevContext();
         public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
         public Page2ViewModel Page2VM { get => page2VM; set => page2VM = value; }
+
+        public Page3ViewModel Page3VM { get => page3VM; set => page3VM = value; }
         public Page6ViewModel Page6VM { get => page6VM; set => page6VM = value; }
         public List<Recipe> ListRecipes { get => listRecipes; set => listRecipes = value; }
         public List<RecipesIngredient> ListIngridient { get => listIngridient; set => listIngridient = value; }
 
         private UserControl uc = new Page1();
         public void LoadPage2() => UC = new Page2();
-        public void LoadPage3() => UC = new Page3();
+
+        public void LoadPage2Create()
+        {
+            Page3VM.CreateUser();
+            UC = new Page2();
+        }
+
+        Page3ViewModel page3VM;
+        public void LoadPage3()
+        {
+            page3VM = new Page3ViewModel(myConnection,uc);
+            UC = new Page3();
+        }
+
 
         Page2ViewModel page2VM = new Page2ViewModel();
 

+ 29 - 0
FoodLogProject/ViewModels/Page3ViewModel.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using Avalonia.Controls;
+using FoodLogProject.Views;
+using ReactiveUI;
+
+namespace FoodLogProject.ViewModels
+{
+	public class Page3ViewModel : ReactiveObject
+	{
+        Customer? currentUser;
+        GaruaevContext myConnection;
+
+        public Page3ViewModel(GaruaevContext myConnection, UserControl UC)
+        {
+            CurrentUser = new Customer();
+            this.myConnection = myConnection;
+        }
+        public Customer? CurrentUser { get => currentUser; set => currentUser = value; }
+        public string Birthday { get => currentUser.CustomerBirthdate.ToString(); set => currentUser.CustomerBirthdate = Convert.ToDateTime(value); }
+
+        public void CreateUser()
+        {
+            myConnection.Add(currentUser);
+            myConnection.SaveChanges();
+
+        }
+    }
+}

+ 17 - 29
FoodLogProject/Views/Page3.axaml

@@ -1,10 +1,12 @@
 <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:vm="using:FoodLogProject.ViewModels"  
+			 xmlns:vm="using:FoodLogProject.ViewModels"
+			 x:DataType="vm:MainWindowViewModel"
 			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
              x:Class="FoodLogProject.Views.Page3">
+	<ScrollViewer >
 	<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" >
 		<StackPanel Name="Registration">
 			<StackPanel>
@@ -34,7 +36,7 @@
 							Данные для вашего плана
 						</TextBlock>
 						<TextBlock>Никнейм</TextBlock>
-						<TextBox Name="tbName" Watermark="Введите никнейм"></TextBox>
+						<TextBox Text="{Binding Page3VM.CurrentUser.CustomerNickname}" Watermark="Введите никнейм"></TextBox>
 						<TextBlock Name="ShowMessageName" Foreground="Red"></TextBlock>
 
 					</StackPanel>
@@ -42,46 +44,35 @@
 					<StackPanel >
 
 						<TextBlock>Номер телефона</TextBlock>
-						<TextBox Name="tbNumber" Watermark="+7***********"></TextBox>
+						<TextBox Text="{Binding Page3VM.CurrentUser.CustomerPhone}" Watermark="+7***********"></TextBox>
 						<TextBlock Name="ShowMessageNumber" Foreground="Red"></TextBlock>
-						<TextBlock >Пароль:</TextBlock>
-						<TextBox Name="tbPassword" PasswordChar="*" Watermark="Введите пароль"/>
-						<TextBlock Name="ShowMessageParol" Foreground="Red"></TextBlock>
+							<TextBlock >Пароль:</TextBlock>
+							<TextBox Text="{Binding Page3VM.CurrentUser.CustomerPassword}" PasswordChar="*" Watermark="Введите пароль"/>
+							<TextBlock Name="ShowMessageParol" Foreground="Red"></TextBlock>
 
 						<TextBlock Margin="0,10,0,0" FontSize="16">Пол</TextBlock>
 					</StackPanel>
 					<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
 
-						<RadioButton Name="rbM" FontSize ="16" Margin="0,0,30,0">Мужской</RadioButton>
-						<RadioButton Name="rbF" FontSize ="16" Margin="0,0,30,0">Женский</RadioButton>
+						<RadioButton Name="rbM" FontSize ="16" Margin="0,0,30,0" IsChecked="{Binding !Page3VM.CurrentUser.CustomerGender}">Мужской</RadioButton>
+						<RadioButton Name="rbF" FontSize ="16" Margin="0,0,30,0" IsChecked="{Binding Page3VM.CurrentUser.CustomerGender}">Женский</RadioButton>
 					</StackPanel>
 					<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
 						<StackPanel >
 							<TextBlock>Рост,см</TextBlock>
-							<TextBox Name="tbHeight" Margin="0,0,30,0"></TextBox>
+							<TextBox Text="{Binding Page3VM.CurrentUser.CustomerHeight}" Margin="0,0,30,0"></TextBox>
 							<TextBlock Name="ShowMessageHeight" Foreground="Red"></TextBlock>
 						</StackPanel>
 						<StackPanel >
 							<TextBlock >Вес, кг</TextBlock>
-							<TextBox Name="tbWeight" Margin="0,0,30,0"></TextBox>
+							<TextBox Text="{Binding Page3VM.CurrentUser.CustomerWeight}" Margin="0,0,30,0"></TextBox>
 							<TextBlock Name="ShowMessageWeight" Foreground="Red"></TextBlock>
 						</StackPanel>
 						<StackPanel >
-							<TextBlock Margin="0,0,30,0">Дата рождения</TextBlock>
-							<TextBox Name="tbBirthday" Margin="0,0,30,0"></TextBox>
-							<TextBlock Name="ShowMessageBirthday" Foreground="Red"></TextBlock>
+							<TextBlock >Дата рождения</TextBlock>
+							<DatePicker SelectedDate="{Binding Page3VM.Birthday}" Margin="0,0,30,0"/>
 						</StackPanel>
 					</StackPanel>
-
-					<StackPanel>
-						<TextBlock>Цель</TextBlock>
-						<ComboBox Name="cbPurpose" FontSize ="16" SelectedIndex="0" >
-							<ComboBoxItem IsEnabled="false">Выберите значение из списка</ComboBoxItem>
-							<ComboBoxItem>Похудение</ComboBoxItem>
-							<ComboBoxItem>Набор мышечной массы</ComboBoxItem>
-							<ComboBoxItem>Поддержание здорового питания</ComboBoxItem>
-						</ComboBox>
-					</StackPanel>
 				</StackPanel>
 			</Border>
 			<Border Background="White"
@@ -277,11 +268,8 @@
 
 				</StackPanel>
 			</Border>
-			<Button Foreground="White" Background="Green" HorizontalAlignment="Center" Margin="40" Content="Составить индивидуальный план питания" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).LoadPage4}"/>
-		</StackPanel>
-
-
-
-		
+			<Button Foreground="White" Background="Green" HorizontalAlignment="Center" Margin="40" Content="Составить индивидуальный план питания" Command="{Binding $parent[Window].((vm:MainWindowViewModel)DataContext).LoadPage2Create}"/>
+		</StackPanel>	
 	</StackPanel>
+		</ScrollViewer>
 </UserControl>