First connection with entity object UI to Object

This commit is contained in:
2025-08-19 07:39:54 +02:00
parent 0d46bd3ade
commit 44419a880d
7 changed files with 124 additions and 32 deletions

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,44 @@
namespace AdventureWorks.EntityLayer.EntityClasses
{
public class User
{
public User()
{
LoginId = string.Empty;
FirstName = string.Empty;
LastName = string.Empty;
Email = string.Empty;
Password = string.Empty;
Phone = string.Empty;
PhoneType = string.Empty;
//IsFullTime = true;
//IsEnrolledIn401k = true;
//IsEnrolledInFlexTime = true;
//IsEnrolledInHealthCare = true;
//IsEnrolledInHSA = false;
//IsActive = true;
//BirthDate = "10-03-1975";
StartTime = new TimeSpan(6, 0, 0);
}
public int UserId { get; set; }
public string LoginId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Phone { get; set; }
public string PhoneType { get; set; }
public bool IsFullTime { get; set; }
public bool IsEnrolledIn401k { get; set; }
public bool IsEnrolledInFlexTime { get; set; }
public bool IsEnrolledInHealthCare { get; set; }
public bool IsEnrolledInHSA { get; set; }
public bool IsActive { get; set; }
public DateTime BirthDate { get; set; }
public TimeSpan StartTime { get; set; }
}
}

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.14.36408.4
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventureWorks.MAUI", "AdventureWorks.MAUI\AdventureWorks.MAUI.csproj", "{403BA6B6-E816-4A0A-992D-E54FDCEA7E7D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventureWorks.EntityLayer", "AdventureWorks.EntityLayer\AdventureWorks.EntityLayer.csproj", "{33E62110-0EA1-48B1-B62F-CA856D13B114}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -13,8 +15,13 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{403BA6B6-E816-4A0A-992D-E54FDCEA7E7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{403BA6B6-E816-4A0A-992D-E54FDCEA7E7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{403BA6B6-E816-4A0A-992D-E54FDCEA7E7D}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{403BA6B6-E816-4A0A-992D-E54FDCEA7E7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{403BA6B6-E816-4A0A-992D-E54FDCEA7E7D}.Release|Any CPU.Build.0 = Release|Any CPU
{33E62110-0EA1-48B1-B62F-CA856D13B114}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33E62110-0EA1-48B1-B62F-CA856D13B114}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33E62110-0EA1-48B1-B62F-CA856D13B114}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33E62110-0EA1-48B1-B62F-CA856D13B114}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -64,6 +64,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AdventureWorks.EntityLayer\AdventureWorks.EntityLayer.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\LoginView.xaml.cs">
<DependentUpon>LoginView.xaml</DependentUpon>

View File

@ -5,6 +5,11 @@
x:Class="AdventureWorks.MAUI.App">
<Application.Resources>
<ResourceDictionary>
<x:Array x:Key="phoneTypes" Type="{x:Type x:String}">
<x:String>Home</x:String>
<x:String>Mobile</x:String>
<x:String>Other</x:String>
</x:Array>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />

View File

@ -4,13 +4,31 @@
x:Class="AdventureWorks.MAUI.Views.UserDetailView"
xmlns:partial="clr-namespace:AdventureWorks.MAUI.ViewsPartial"
xmlns:converters="clr-namespace:AdventureWorks.MAUI.Converters"
xmlns:vm="clr-namespace:AdventureWorks.EntityLayer.EntityClasses;assembly=AdventureWorks.EntityLayer"
x:DataType="vm:User"
Title="User Information">
<ContentPage.Resources>
<converters:InvertedBoolConverter x:Key="invertedBoolean" />
<vm:User x:Key="viewModel"
LoginId="JohnSmith123"
FirstName="John222"
LastName="Smith"
Email="john@smith.com"
Phone="615.222.2333"
PhoneType="Mobile"
IsFullTime="True"
IsEnrolledIn401k="True"
IsEnrolledInFlexTime="False"
IsEnrolledInHealthCare="True"
IsEnrolledInHSA="False"
IsActive="True"
BirthDate="10-03-1975"
/>
</ContentPage.Resources>
<Border Style="{StaticResource Border.Page}">
<Border Style="{StaticResource Border.Page}"
BindingContext="{StaticResource viewModel}" >
<ScrollView>
<Grid RowDefinitions="Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto, Auto,Auto, Auto, Auto , Auto"
ColumnDefinitions="Auto, *"
@ -25,9 +43,9 @@
<Label Grid.Row="1"
Text="Login ID" />
<VerticalStackLayout Grid.Row="3"
<VerticalStackLayout Grid.Row="1"
Grid.Column="1">
<Entry Text=""
<Entry Text="{Binding LoginId}"
Placeholder="Please use a combination of letters and numbers."/>
<Label FontSize="Micro"
Text="Please use a combination of letters and numbers." />
@ -36,17 +54,17 @@
Text="First Name" />
<Entry Grid.Row="2"
Grid.Column="1"
Text=""/>
Text="{Binding FirstName}"/>
<Label Grid.Row="3"
Text="Last Name" />
<Entry Grid.Row="3"
Grid.Column="1"
Text=""/>
Text="{Binding LastName}"/>
<Label Grid.Row="4"
Text="Email Address" />
<Entry Grid.Row="4"
Grid.Column="1"
Text=""/>
Text="{Binding Email}"/>
<Label Grid.Row="5" Text="Is Enrolled ?"/>
<FlexLayout Grid.Row="5"
@ -55,26 +73,27 @@
Direction="Row">
<HorizontalStackLayout>
<Label Text="401k?"/>
<CheckBox IsChecked="True"/>
<CheckBox IsChecked="{Binding IsEnrolledIn401k}"/>
</HorizontalStackLayout>
<HorizontalStackLayout >
<Label Text="Flex Time?"/>
<CheckBox x:Name="FlexTime"/>
<CheckBox x:Name="FlexTime" IsChecked="{Binding IsEnrolledInFlexTime}"/>
</HorizontalStackLayout>
<HorizontalStackLayout >
<Label Text="Health Care?"/>
<CheckBox IsChecked="True"/>
<CheckBox IsChecked="{Binding IsEnrolledInHealthCare}"/>
</HorizontalStackLayout>
<HorizontalStackLayout >
<Label Text="Health Savings Account?"/>
<CheckBox IsChecked="True"/>
<CheckBox IsChecked="{Binding IsEnrolledInHSA}"/>
</HorizontalStackLayout>
</FlexLayout>
<Label Grid.Row="6"
Text="Still Employed"/>
<Switch Grid.Row="6"
Grid.Column="1"/>
Grid.Column="1"
IsToggled="{Binding IsActive}"/>
<Label Text="Employee Type"
Grid.Row="7"/>
<FlexLayout Grid.Row="7"
@ -84,12 +103,12 @@
<HorizontalStackLayout>
<Label Text="Full-Time"/>
<RadioButton x:Name="FullTime"
IsChecked="True"
IsChecked="{Binding IsFullTime}"
GroupName="EmployeeType"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="Part-Time"/>
<RadioButton GroupName="EmployeeType"/>
<RadioButton GroupName="EmployeeType" IsChecked="{Binding IsFullTime, Converter={StaticResource invertedBoolean}}"/>
</HorizontalStackLayout>
</FlexLayout>
@ -97,14 +116,14 @@
Grid.Row="8"/>
<DatePicker Grid.Row="8"
Grid.Column="1"
Date="{Binding BirthDate}"
HorizontalOptions="Start"/>
<Label Text="Start Time"
Grid.Row="9"/>
<TimePicker Grid.Row="9"
Grid.Column="1"
Time="06:00:00"
BindingContext="{x:Reference FullTime}"
IsEnabled="{Binding IsChecked, Converter={StaticResource invertedBoolean}}"/>
Time="{Binding StartTime}"
IsEnabled="{Binding IsFullTime, Converter={StaticResource invertedBoolean}}"/>
<Label Text="Phone"
Grid.Row="10"/>
@ -113,18 +132,12 @@
Wrap="Wrap"
Direction="Row">
<HorizontalStackLayout>
<Entry MinimumWidthRequest="120"/>
<Entry MinimumWidthRequest="120"
Text="{Binding Phone}"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Picker>
<Picker.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Home</x:String>
<x:String>Mobile</x:String>
<x:String>Other</x:String>
</x:Array>
</Picker.ItemsSource>
</Picker>
<Picker ItemsSource="{StaticResource phoneTypes}"
SelectedItem="{Binding PhoneType}"/>
</HorizontalStackLayout>
</FlexLayout>
@ -134,7 +147,7 @@
<HorizontalStackLayout Grid.Row="12"
Grid.Column="1"
Spacing="5">
<Button Text="Save" />
<Button Text="Save" Clicked="SaveButton_Clicked"/>
<Button Text="Cancel" />
</HorizontalStackLayout>
</Grid>

View File

@ -1,3 +1,5 @@
using AdventureWorks.EntityLayer.EntityClasses;
namespace AdventureWorks.MAUI.Views;
public partial class UserDetailView : ContentPage
@ -5,5 +7,13 @@ public partial class UserDetailView : ContentPage
public UserDetailView()
{
InitializeComponent();
UserObject = (User)this.Resources["viewModel"];
}
public User UserObject { get; set; }
private void SaveButton_Clicked(object sender, EventArgs e)
{
System.Diagnostics.Debugger.Break();
}
}