Lab - 01 - AutomobileManagement - Using - EntityFramework and WPF
Lab - 01 - AutomobileManagement - Using - EntityFramework and WPF
Lab - 01 - AutomobileManagement - Using - EntityFramework and WPF
Introduction
Imagine you're an employee of a car retailer named Automobile Store. Your
manager has asked you to develop a WPF application for automobile management
(CarID, CarName, Manufacturer, Price, and ReleasedYear). The application has
to support adding, viewing, modifying, and removing products—a standardized
usage action verbs better known as Create, Read, Update, Delete (CRUD).
This lab explores creating an application using WPF with .NET Core, and C#. An
SQL Server Database will be created to persist the car's data that will be used for
reading and managing automobile data by Entity Framework Core
Lab Objectives
In this lab, you will:
▪ Use the Visual Studio.NET to create WPF application and Class Library (.dll)
project.
▪ Create a SQL Server database named MyStock that has a Cars table.
▪ Develop a DataProvider class to perform CRUD actions using Entity
Framework Core.
▪ Apply Dependency injection (DI) in WPF application.
▪ Apply Repository pattern and Singleton pattern in a project.
▪ Add CRUD action methods to WPF application.
▪ Run the project and test the WPF application actions.
1|Page
MyStock Database
2|Page
1
3|Page
Step 02. Create a Class Library project.
• From the File menu | Add | New Project, on the Add New Project dialog,
select “Class Library” and performs steps as follows:
4|Page
5
5|Page
Step 02. Create folders and add classes to the project as follows:
Step 04.
On the DataAccess folder, add a class named CarManagement.cs and
write codes as follows:
6|Page
7|Page
8|Page
Step 05. Write codes for ICarRepository.cs as follows:
9|Page
ListView Control
10 | P a g e
<Label Name="lbTitle" Foreground="Red" FontWeight="DemiBold"
FontSize="20" Content="Car Information" />
11 | P a g e
DisplayMemberBinding="{Binding Path=CarName}"/>
<GridViewColumn Header="Manufacturer" Width="200"
DisplayMemberBinding="{Binding Path=Manufacturer }"/>
<GridViewColumn Header="Price" Width="100"
DisplayMemberBinding="{Binding Path=Price,
StringFormat={}{0:N3}}"/>
<GridViewColumn Header="ReleasedYear" Width="100"
DisplayMemberBinding="{Binding Path=ReleasedYear}"/>
</GridView>
</ListView.View>
</ListView>
<! Button control-->
<Button Grid.Row="3" x:Name="btnClose" Margin="10"
HorizontalAlignment="Right" VerticalAlignment="Bottom"
Width="80" Content="Close" Click="btnClose_Click" />
</Grid>
</DockPanel>
</Grid>
</Window>
Step 02. Right-click on the project | Add | New Item, select JavaScript
JSON Configuration File then rename to appsettings.json, click Add and
write contents as follows:
12 | P a g e
1
1
13 | P a g e
Step 07. Open App.xaml and then update XAML code as follows:
14 | P a g e
Activity 05: Run the AutomobileWPFApp project and
test all actions
Step 01. Click the Load button and display the result as the below figure.
15 | P a g e
Step 02. Enter the values on TextBoxes then click the Insert button to add
a new car.
Step 03. Select a row on the ListView then click the Delete button to
remove a Car.
Step 04. Click a row on the ListView and edit the values on TextBoxes,
then click the Update button to update the car information.
16 | P a g e