Kết nối Entity Framework trong Phần mềm quản lý kho WPF - MVVM
Kết nối Entity Framework trong Phần mềm quản lý kho WPF - MVVM
Lập trình phần mềm quản lý kho WPF - MVVM

Danh sách bài học
Kết nối Entity Framework trong Phần mềm quản lý kho WPF - MVVM
Kết nối Entity Framework trong Phần mềm quản lý kho WPF - MVVM
Nội dung bài viết Học nhanh
Dẫn nhập
Nếu bạn đã từng rất thích thú với việc tự làm dự án thực tế qua serial hướng dẫn lập trình PHẦN MỀM QUẢN LÝ QUÁN CAFE bằng Winform thì chẳng có lý do gì để không tiếp tục nâng cao kinh nghiệm cá nhân với serial lập trình Phần mềm quản lý kho WPF – MVVM này. Không chỉ đề cập đến công nghệ WPF, serial còn kết hợp mô hình MVVM, entity framework, … và nhiều kỹ thuật khác.
Ở bài trước chúng ta đã tìm hiểu về cách TẠO CSDL SQL SERVER TRONG PHẦN MỀM QUẢN LÝ KHO . Trong bài này, Kteam sẽ giới thiệu đến các bạn cách Kết nối Entity Framework trong phần mềm quản lý kho WPF – MVVM.
Nội dung
Nội dung bao gồm Source code & các lưu ý chính về quá trình thực hiện phần mềm. Kteam khuyến khích bạn cập nhập thêm nhiều kinh nghiệm cũng như hiểu chi tiết hơn về các kỹ thuật được đề cập trong bài học thông qua các video đính kèm.
Đừng quên Like Facebook hoặc +1 Google để ủng hộ Kteam và tác giả.
Để theo dõi tốt khóa học này, hãy đảm bảo bạn đã xem qua kiến thức về:
Project tham khảo
script auto generate.sql
USE [master]
GO
/****** Object: Database [QuanLyKhoKteam] Script Date: 26-Feb-18 6:29:19 PM ******/
CREATE DATABASE [QuanLyKhoKteam]
GO
USE [QuanLyKhoKteam]
GO
/****** Object: Table [dbo].[Customer] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Customer](
[Id] [int] IDENTITY(1,1) NOT NULL,
[DisplayName] [nvarchar](max) NULL,
[Address] [nvarchar](max) NULL,
[Phone] [nvarchar](20) NULL,
[Email] [nvarchar](200) NULL,
[MoreInfo] [nvarchar](max) NULL,
[ContractDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Input] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Input](
[Id] [nvarchar](128) NOT NULL,
[DateInput] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[InputInfo] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[InputInfo](
[Id] [nvarchar](128) NOT NULL,
[IdObject] [nvarchar](128) NOT NULL,
[IdInput] [nvarchar](128) NOT NULL,
[Count] [int] NULL,
[InputPrice] [float] NULL,
[OutputPrice] [float] NULL,
[Status] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Object] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Object](
[Id] [nvarchar](128) NOT NULL,
[DisplayName] [nvarchar](max) NULL,
[IdUnit] [int] NOT NULL,
[IdSuplier] [int] NOT NULL,
[QRCode] [nvarchar](max) NULL,
[BarCode] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Output] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Output](
[Id] [nvarchar](128) NOT NULL,
[DateOutput] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[OutputInfo] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[OutputInfo](
[Id] [nvarchar](128) NOT NULL,
[IdObject] [nvarchar](128) NOT NULL,
[IdOutputInfo] [nvarchar](128) NOT NULL,
[IdCustomer] [int] NOT NULL,
[Count] [int] NULL,
[Status] [nvarchar](max) NULL,
foreign key (Id) references OutPut(Id),
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Suplier] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Suplier](
[Id] [int] IDENTITY(1,1) NOT NULL,
[DisplayName] [nvarchar](max) NULL,
[Address] [nvarchar](max) NULL,
[Phone] [nvarchar](20) NULL,
[Email] [nvarchar](200) NULL,
[MoreInfo] [nvarchar](max) NULL,
[ContractDate] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Unit] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Unit](
[Id] [int] IDENTITY(1,1) NOT NULL,
[DisplayName] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[UserRole] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserRole](
[Id] [int] IDENTITY(1,1) NOT NULL,
[DisplayName] [nvarchar](max) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
/****** Object: Table [dbo].[Users] Script Date: 26-Feb-18 6:29:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Users](
[Id] [int] IDENTITY(1,1) NOT NULL,
[DisplayName] [nvarchar](max) NULL,
[UserName] [nvarchar](100) NULL,
[Password] [nvarchar](max) NULL,
[IdRole] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[UserRole] ON
INSERT [dbo].[UserRole] ([Id], [DisplayName]) VALUES (1, N'Admin')
INSERT [dbo].[UserRole] ([Id], [DisplayName]) VALUES (2, N'Nhân viên')
SET IDENTITY_INSERT [dbo].[UserRole] OFF
SET IDENTITY_INSERT [dbo].[Users] ON
INSERT [dbo].[Users] ([Id], [DisplayName], [UserName], [Password], [IdRole]) VALUES (1, N'RongK9', N'admin', N'db69fc039dcbd2962cb4d28f5891aae1', 1)
INSERT [dbo].[Users] ([Id], [DisplayName], [UserName], [Password], [IdRole]) VALUES (2, N'Nhân viên', N'staff', N'978aae9bb6bee8fb75de3e4830a1be46', 2)
SET IDENTITY_INSERT [dbo].[Users] OFF
ALTER TABLE [dbo].[InputInfo] ADD DEFAULT ((0)) FOR [InputPrice]
GO
ALTER TABLE [dbo].[InputInfo] ADD DEFAULT ((0)) FOR [OutputPrice]
GO
ALTER TABLE [dbo].[InputInfo] WITH CHECK ADD FOREIGN KEY([IdInput])
REFERENCES [dbo].[Input] ([Id])
GO
ALTER TABLE [dbo].[InputInfo] WITH CHECK ADD FOREIGN KEY([IdObject])
REFERENCES [dbo].[Object] ([Id])
GO
ALTER TABLE [dbo].[Object] WITH CHECK ADD FOREIGN KEY([IdUnit])
REFERENCES [dbo].[Unit] ([Id])
GO
ALTER TABLE [dbo].[Object] WITH CHECK ADD FOREIGN KEY([IdSuplier])
REFERENCES [dbo].[Suplier] ([Id])
GO
ALTER TABLE [dbo].[OutputInfo] WITH CHECK ADD FOREIGN KEY([IdCustomer])
REFERENCES [dbo].[Customer] ([Id])
GO
ALTER TABLE [dbo].[OutputInfo] WITH CHECK ADD FOREIGN KEY([IdObject])
REFERENCES [dbo].[Object] ([Id])
GO
ALTER TABLE [dbo].[Users] WITH CHECK ADD FOREIGN KEY([IdRole])
REFERENCES [dbo].[UserRole] ([Id])
GO
USE [master]
GO
ALTER DATABASE [QuanLyKhoKteam] SET READ_WRITE
GO
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
App.xaml
<Application x:Class="QuanLyKho.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:QuanLyKho"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
<ResourceDictionary Source="/ResourceXAML/MainResource.xaml"></ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
12345678910111213141516171819
App.xaml.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
123456789101112131415161718
CustomerWindow.xaml
<Window x:Class="QuanLyKho.CustomerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Khách hàng" Height="500" Width="700">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<WrapPanel Margin="0 0 0 10">
<TextBox Text="{Binding DisplayName, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên khách hàng" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Address, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Địa chỉ" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Phone, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Điện thoại" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Email, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Email" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding MoreInfo, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Thông tin thêm" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<DatePicker VerticalAlignment="Center" SelectedDate="{Binding ContractDate, UpdateSourceTrigger=PropertyChanged}" Width="100" Margin="5 5 15 -7" materialDesign:HintAssist.Hint="Ngày hợp tác" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"></GridViewColumn>
<GridViewColumn Header="Tên khách hàng" DisplayMemberBinding="{Binding DisplayName}"></GridViewColumn>
<GridViewColumn Header="Địa chỉ" DisplayMemberBinding="{Binding Address}"></GridViewColumn>
<GridViewColumn Header="Điện thoại" DisplayMemberBinding="{Binding Phone}"></GridViewColumn>
<GridViewColumn Header="Email" DisplayMemberBinding="{Binding Email}"></GridViewColumn>
<GridViewColumn Header="Thông tin thêm" DisplayMemberBinding="{Binding MoreInfo}"></GridViewColumn>
<GridViewColumn Header="Ngày hợp tác" DisplayMemberBinding="{Binding ContractDate}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
CustomerWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for CustomerWindow.xaml
/// </summary>
public partial class CustomerWindow : Window
{
public CustomerWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
InputWindow.xaml
<Window x:Class="QuanLyKho.InputWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Khách hàng" Height="500" Width="700">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<WrapPanel Margin="0 0 0 10">
<TextBox Text="{Binding ObjectDisplayName, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên vật tư" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<DatePicker VerticalAlignment="Center" SelectedDate="{Binding DateInput}" Width="100" Margin="5 5 15 -7" materialDesign:HintAssist.Hint="Ngày nhập" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
<TextBox Text="{Binding Count, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Số lượng" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding PriceInput, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Giá nhập" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding PriceOutput, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Giá xuất" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Status, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Trạng thái nhập" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Vật tư" DisplayMemberBinding="{Binding Object.DisplayName}"></GridViewColumn>
<GridViewColumn Header="Ngày nhập" DisplayMemberBinding="{Binding Input.DateInput}"></GridViewColumn>
<GridViewColumn Header="Số lượng" DisplayMemberBinding="{Binding Count}"></GridViewColumn>
<GridViewColumn Header="Giá nhập" DisplayMemberBinding="{Binding InputPrice}"></GridViewColumn>
<GridViewColumn Header="Giá xuất" DisplayMemberBinding="{Binding OutputPrice}"></GridViewColumn>
<GridViewColumn Header="Trạng thái nhập" DisplayMemberBinding="{Binding Status}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
InputWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for InputWindow.xaml
/// </summary>
public partial class InputWindow : Window
{
public InputWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
LoginWindow.xaml
<Window x:Class="QuanLyKho.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Name="loginWindow"
Title="Đăng nhập" Height="300" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=loginWindow}"></uc:ControlBarUC>
</Grid>
<materialDesign:Card Grid.Row="1" Width="330" Height="150" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid>
<Grid.Resources>
<Style TargetType="Grid">
<Setter Property="Margin" Value="15 0 15 0"></Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBox materialDesign:HintAssist.Hint="Tên đăng nhập"
Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</Grid>
<Grid Grid.Row="1">
<PasswordBox x:Name="FloatingPasswordBox"
materialDesign:HintAssist.Hint="Mật khẩu"
Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" />
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
Style="{StaticResource MaterialDesignRaisedButton}"
Width="110"
ToolTip="Resource name: MaterialDesignRaisedButton" Content="Đăng nhập"></Button>
<Button Grid.Column="1"
Style="{StaticResource MaterialDesignRaisedButton}"
Width="110"
Background="OrangeRed"
ToolTip="Resource name: MaterialDesignRaisedButton" Content="Thoát"></Button>
</Grid>
</Grid>
</materialDesign:Card>
</Grid>
</Window>
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
LoginWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for LoginWindow.xaml
/// </summary>
public partial class LoginWindow : Window
{
public LoginWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
MainWindow.xaml
<Window x:Class="QuanLyKho.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
Name="mainWindow"
DataContext="{StaticResource MainVM}"
Title="Phần mềm quản lý kho" Height="500" Width="625">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadedWindowCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=mainWindow}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--menu-->
<Grid Grid.Row="0">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Transparent">
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="2 4 2 4"></Setter>
<Setter Property="Background" Value="LightCyan"></Setter>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Command="{Binding InputCommand}" Grid.Column="0" ToolTip="Nhập kho">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Nhập kho" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon HorizontalAlignment="Center" Width="24" Height="24" Kind="ArrowDownBoldCircleOutline" />
</Grid>
</Grid>
</Button>
<Button Command="{Binding OutputCommand}" Grid.Column="1" ToolTip="Xuất kho">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Xuất kho" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="ArrowUpBoldCircleOutline" />
</Grid>
</Grid>
</Button>
<Button Command="{Binding ObjectCommand}" Grid.Column="2" ToolTip="Vật tư">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Vật tư" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="Dns" />
</Grid>
</Grid>
</Button>
<Button Grid.Column="3" Command="{Binding UnitCommand}" ToolTip="Đơn vị đo">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Đơn vị đo" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="Altimeter" />
</Grid>
</Grid>
</Button>
<Button Grid.Column="4" Command="{Binding SuplierCommand}" ToolTip="Nhà cung cấp">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Nhà cung cấp" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="Factory" />
</Grid>
</Grid>
</Button>
<Button Grid.Column="5" Command="{Binding CustomerCommand}" ToolTip="Khách hàng">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Khách hàng" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="HumanHandsup" />
</Grid>
</Grid>
</Button>
<Button Grid.Column="6" Command="{Binding UserCommand}" ToolTip="Người dùng">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="Người dùng" HorizontalAlignment="Center"></TextBlock>
</Grid>
<Grid Grid.Row="1">
<materialDesign:PackIcon Width="24" Height="24" HorizontalAlignment="Center" Kind="AccountMultiple" />
</Grid>
</Grid>
</Button>
</Grid>
</Grid>
<!--main-->
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--Filter-->
<Grid Grid.Row="0">
<materialDesign:Card Margin="5">
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<DatePicker VerticalAlignment="Center" HorizontalAlignment="Left" Width="100" materialDesign:HintAssist.Hint="Ngày bắt đầu" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</Grid>
<Grid Grid.Column="1">
<DatePicker VerticalAlignment="Center" HorizontalAlignment="Left" Width="100" materialDesign:HintAssist.Hint="Ngày kết thúc" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</Grid>
<Grid Grid.Column="2">
<Button Style="{StaticResource MaterialDesignRaisedButton}" Margin="5"
Width="100"
Content="Lọc"
ToolTip="Resource name: MaterialDesignRaisedButton"></Button>
</Grid>
</Grid>
<Grid Grid.Row="1">
<Separator Margin="5"></Separator>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<materialDesign:Card Background="#03a9f4" Margin="5"
Foreground="{DynamicResource PrimaryHueDarkForegroundBrush}"
Padding="0" Width="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="16 16 16 4"
Text="Lượng nhập"
Style="{StaticResource MaterialDesignHeadlineTextBlock}">
</TextBlock>
<Separator Grid.Row="1" Style="{StaticResource MaterialDesignLightSeparator}" />
<TextBlock Grid.Row="2" Margin="16 0 16 8" VerticalAlignment="Center"
HorizontalAlignment="Left"
Text="998568"
Style="{StaticResource MaterialDesignDisplay1TextBlock}">
</TextBlock>
<materialDesign:PopupBox HorizontalAlignment="Right" Padding="2 0 2 0">
<StackPanel>
<!--đưa gì vào thì đưa-->
</StackPanel>
</materialDesign:PopupBox>
</Grid>
</materialDesign:Card>
</Grid>
<Grid Grid.Column="1">
<materialDesign:Card Background="#03a9f4" Margin="5"
Foreground="{DynamicResource PrimaryHueDarkForegroundBrush}"
Padding="0" Width="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="16 16 16 4"
Text="Lượng xuất"
Style="{StaticResource MaterialDesignHeadlineTextBlock}">
</TextBlock>
<Separator Grid.Row="1" Style="{StaticResource MaterialDesignLightSeparator}" />
<TextBlock Grid.Row="2" Margin="16 0 16 8" VerticalAlignment="Center"
HorizontalAlignment="Left"
Text="998568"
Style="{StaticResource MaterialDesignDisplay1TextBlock}">
</TextBlock>
<materialDesign:PopupBox HorizontalAlignment="Right" Padding="2 0 2 0">
<StackPanel>
<!--đưa gì vào thì đưa-->
</StackPanel>
</materialDesign:PopupBox>
</Grid>
</materialDesign:Card>
</Grid>
<Grid Grid.Column="2">
<materialDesign:Card Background="#03a9f4" Margin="5"
Foreground="{DynamicResource PrimaryHueDarkForegroundBrush}"
Padding="0" Width="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="16 16 16 4"
Text="Tồn kho"
Style="{StaticResource MaterialDesignHeadlineTextBlock}">
</TextBlock>
<Separator Grid.Row="1" Style="{StaticResource MaterialDesignLightSeparator}" />
<TextBlock Grid.Row="2" Margin="16 0 16 8" VerticalAlignment="Center"
HorizontalAlignment="Left"
Text="998568"
Style="{StaticResource MaterialDesignDisplay1TextBlock}">
</TextBlock>
<materialDesign:PopupBox HorizontalAlignment="Right" Padding="2 0 2 0">
<StackPanel>
<!--đưa gì vào thì đưa-->
</StackPanel>
</materialDesign:PopupBox>
</Grid>
</materialDesign:Card>
</Grid>
</Grid>
</Grid>
</materialDesign:Card>
</Grid>
<!--list-->
<materialDesign:Card Grid.Row="1" Margin="5" VerticalAlignment="Stretch">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<DatePicker VerticalAlignment="Center" HorizontalAlignment="Left" Width="100" materialDesign:HintAssist.Hint="Ngày bắt đầu" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</Grid>
<Grid Grid.Column="1">
<DatePicker VerticalAlignment="Center" HorizontalAlignment="Left" Width="100" materialDesign:HintAssist.Hint="Ngày kết thúc" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</Grid>
<Grid Grid.Column="2">
<Button Style="{StaticResource MaterialDesignRaisedButton}" Margin="5"
Width="100"
Content="Lọc"
ToolTip="Resource name: MaterialDesignRaisedButton"></Button>
</Grid>
</Grid>
<Grid Grid.Row="1">
<Separator></Separator>
</Grid>
<Grid Grid.Row="2">
<ListView>
<ListView.View>
<GridView>
<GridViewColumn Header="STT"></GridViewColumn>
<GridViewColumn Header="Tên vật tư"></GridViewColumn>
<GridViewColumn Header="Số lượng tồn"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Grid>
</materialDesign:Card>
</Grid>
</Grid>
</Grid>
</Window>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//http://materialdesigninxaml.net/home
public MainWindow()
{
InitializeComponent();
}
}
}
123456789101112131415161718192021222324252627282930
ObjectWindow.xaml
<Window x:Class="QuanLyKho.ObjectWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Khách hàng" Height="500" Width="700">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<WrapPanel Margin="0 0 0 10">
<TextBox Text="{Binding DisplayName, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên vật tư" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<ComboBox Margin="5 5 15 5" ItemsSource="{Binding Unit}" SelectedItem="{Binding SelectedUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" materialDesign:HintAssist.Hint="Đơn vị đo" IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}"></ComboBox>
<ComboBox Margin="5 5 15 5" ItemsSource="{Binding Suplier}" SelectedItem="{Binding SelectedSuplier, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" materialDesign:HintAssist.Hint="Nhà cung cấp" IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}"></ComboBox>
<TextBox Text="{Binding QRCode, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="QR code" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding BarCode, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Bar code" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"></GridViewColumn>
<GridViewColumn Header="Tên vật tư" DisplayMemberBinding="{Binding DisplayName}"></GridViewColumn>
<GridViewColumn Header="Đơn vị đo" DisplayMemberBinding="{Binding Unit.DisplayName}"></GridViewColumn>
<GridViewColumn Header="Nhà cung cấp" DisplayMemberBinding="{Binding Suplier.DisplayName}"></GridViewColumn>
<GridViewColumn Header="QRCode" DisplayMemberBinding="{Binding QRCode}"></GridViewColumn>
<GridViewColumn Header="BarCode" DisplayMemberBinding="{Binding BarCode}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
ObjectWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for ObjectWindow.xaml
/// </summary>
public partial class ObjectWindow : Window
{
public ObjectWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
OutputWindow.xaml
<Window x:Class="QuanLyKho.OutputWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Khách hàng" Height="500" Width="700">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<WrapPanel Margin="0 0 0 10">
<TextBox Text="{Binding ObjectDisplayName, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên vật tư" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<DatePicker VerticalAlignment="Center" SelectedDate="{Binding DateOnput}" Width="100" Margin="5 5 15 -7" materialDesign:HintAssist.Hint="Ngày xuất" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
<TextBox Text="{Binding Count, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Số lượng" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding PriceOutput, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Giá xuất" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<ComboBox Margin="5 5 15 5" ItemsSource="{Binding Customer}" SelectedItem="{Binding SelectedCustomer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" materialDesign:HintAssist.Hint="Khách hàng" IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}"></ComboBox>
<TextBox Text="{Binding Status, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Trạng thái xuất" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Vật tư" DisplayMemberBinding="{Binding Object.DisplayName}"></GridViewColumn>
<GridViewColumn Header="Ngày xuất" DisplayMemberBinding="{Binding Output.DateOnput}"></GridViewColumn>
<GridViewColumn Header="Số lượng" DisplayMemberBinding="{Binding Count}"></GridViewColumn>
<GridViewColumn Header="Giá xuất" DisplayMemberBinding="{Binding InputInfo.OutputPrice}"></GridViewColumn>
<GridViewColumn Header="Khách hàng" DisplayMemberBinding="{Binding Customer.DisplayName}"></GridViewColumn>
<GridViewColumn Header="Trạng thái xuất" DisplayMemberBinding="{Binding Status}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
OutputWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for OutputWindow.xaml
/// </summary>
public partial class OutputWindow : Window
{
public OutputWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
SuplierWindow.xaml
<Window x:Class="QuanLyKho.SuplierWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Nhà cung cấp" Height="500" Width="700">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<WrapPanel Margin="0 0 0 10">
<TextBox Text="{Binding DisplayName}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên nhà cung cấp" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Address}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Địa chỉ" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Phone}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Điện thoại" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding Email}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Email" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding MoreInfo}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Thông tin thêm" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<DatePicker VerticalAlignment="Center" SelectedDate="{Binding ContractDate}" Width="100" Margin="5 5 15 -7" materialDesign:HintAssist.Hint="Ngày hợp tác" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"></GridViewColumn>
<GridViewColumn Header="Tên nhà cung cấp" DisplayMemberBinding="{Binding DisplayName}"></GridViewColumn>
<GridViewColumn Header="Địa chỉ" DisplayMemberBinding="{Binding Address}"></GridViewColumn>
<GridViewColumn Header="Điện thoại" DisplayMemberBinding="{Binding Phone}"></GridViewColumn>
<GridViewColumn Header="Email" DisplayMemberBinding="{Binding Email}"></GridViewColumn>
<GridViewColumn Header="Thông tin thêm" DisplayMemberBinding="{Binding MoreInfo}"></GridViewColumn>
<GridViewColumn Header="Ngày hợp tác" DisplayMemberBinding="{Binding ContractDate}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
SuplierWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for SuplierWindow.xaml
/// </summary>
public partial class SuplierWindow : Window
{
public SuplierWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
UnitWindow.xaml
<Window x:Class="QuanLyKho.UnitWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Đơn vị đo" Height="500" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<Grid>
<TextBox Text="{Binding DisplayName, UpdateSourceTrigger=PropertyChanged}" Margin="5" materialDesign:HintAssist.Hint="Tên đơn vị đo" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</Grid>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"></GridViewColumn>
<GridViewColumn Header="Tên đơn vị đo" DisplayMemberBinding="{Binding DisplayName}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
UnitWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for UnitWindow.xaml
/// </summary>
public partial class UnitWindow : Window
{
public UnitWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
UserWindow.xaml
<Window x:Class="QuanLyKho.UserWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:QuanLyKho"
mc:Ignorable="d"
xmlns:uc="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
ResizeMode="NoResize"
WindowStyle="None"
WindowStartupLocation="CenterScreen"
x:Name="window"
Title="Khách hàng" Height="500" Width="700">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title, ElementName=window}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<!--các element binding từ selected item-->
<materialDesign:Card Grid.Row="0" Margin="5">
<WrapPanel Margin="0 0 0 10">
<TextBox Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên đăng nhập" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
<ComboBox Margin="5 5 15 5" ItemsSource="{Binding Role}" SelectedItem="{Binding SelectedRole, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" materialDesign:HintAssist.Hint="Quyền" IsEditable="True" Style="{StaticResource MaterialDesignFloatingHintComboBox}"></ComboBox>
<TextBox Text="{Binding DisplayName, UpdateSourceTrigger=PropertyChanged}" Margin="5 5 15 5" materialDesign:HintAssist.Hint="Tên hiển thị" Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm" Margin="5" Width="100"></Button>
<Button Command="{Binding EditCommand}" Content="Sửa" Margin="5" Width="100"></Button>
<Button Command="{Binding DeleteCommand}" Content="Xóa" Margin="5" Width="100"></Button>
<Button Command="{Binding ChangePasswordCommand}" Content="Đổi pass" Margin="5" Width="100"></Button>
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="2" Margin="5" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding SelectedItem, Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"></GridViewColumn>
<GridViewColumn Header="Tên đăng nhập" DisplayMemberBinding="{Binding UserName}"></GridViewColumn>
<GridViewColumn Header="Chức vụ" DisplayMemberBinding="{Binding Role.DisplayName}"></GridViewColumn>
<GridViewColumn Header="Tên hiển thị" DisplayMemberBinding="{Binding DisplayName}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
UserWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace QuanLyKho
{
/// <summary>
/// Interaction logic for UserWindow.xaml
/// </summary>
public partial class UserWindow : Window
{
public UserWindow()
{
InitializeComponent();
}
}
}
12345678910111213141516171819202122232425262728
ResourceXAML
ResourceXAML\MainResource.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewmodel="clr-namespace:QuanLyKho.ViewModel"
xmlns:local="clr-namespace:QuanLyKho.ResourceXAML">
<viewmodel:MainViewModel x:Key="MainVM"></viewmodel:MainViewModel>
</ResourceDictionary>
123456
UserControlKteam
UserControlKteam\ControlBarUC.xaml
<UserControl x:Class="QuanLyKho.UserControlKteam.ControlBarUC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:QuanLyKho.UserControlKteam"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
Name="ucControlBar"
mc:Ignorable="d">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding MouseMoveWindowCommand}" CommandParameter="{Binding ElementName=ucControlBar}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid>
<materialDesign:ColorZone Mode="PrimaryLight" >
<DockPanel>
<StackPanel DockPanel.Dock="Right" Background="Transparent" Orientation="Horizontal">
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="2 4 2 4"></Setter>
<Setter Property="Width" Value="40"></Setter>
</Style>
</StackPanel.Resources>
<Button Command="{Binding MinimizeWindowCommand}"
CommandParameter="{Binding ElementName=ucControlBar}"
ToolTip="Đóng" ToolBar.OverflowMode="AsNeeded" Background="ForestGreen">
<materialDesign:PackIcon Kind="WindowMinimize" />
</Button>
<Button Command="{Binding MaximizeWindowCommand}"
CommandParameter="{Binding ElementName=ucControlBar}"
ToolTip="Đóng" ToolBar.OverflowMode="AsNeeded" Background="ForestGreen">
<materialDesign:PackIcon Kind="WindowMaximize" />
</Button>
<Button Command="{Binding CloseWindowCommand}"
CommandParameter="{Binding ElementName=ucControlBar}"
ToolTip="Đóng" ToolBar.OverflowMode="AsNeeded" Background="OrangeRed">
<materialDesign:PackIcon Kind="WindowClose" />
</Button>
</StackPanel>
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
<ToggleButton Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />
<TextBlock VerticalAlignment="Center" Margin="16 0 0 0" Text="{Binding Tag, ElementName=ucControlBar}"></TextBlock>
</StackPanel>
</DockPanel>
</materialDesign:ColorZone>
</Grid>
</UserControl>
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
UserControlKteam\ControlBarUC.xaml.cs
using QuanLyKho.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace QuanLyKho.UserControlKteam
{
/// <summary>
/// Interaction logic for ControlBarUC.xaml
/// </summary>
public partial class ControlBarUC : UserControl
{
public ControlBarViewModel Viewmodel { get; set; }
public ControlBarUC()
{
InitializeComponent();
this.DataContext = Viewmodel = new ControlBarViewModel();
}
}
}
123456789101112131415161718192021222324252627282930313233
ViewModel
ViewModel\BaseViewModel.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
class RelayCommand<T> : ICommand
{
private readonly Predicate<T> _canExecute;
private readonly Action<T> _execute;
public RelayCommand(Predicate<T> canExecute, Action<T> execute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_canExecute = canExecute;
_execute = execute;
}
public bool CanExecute(object parameter)
{
try
{
return _canExecute == null ? true : _canExecute((T)parameter);
}
catch
{
return true;
}
}
public void Execute(object parameter)
{
_execute((T)parameter);
}
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
}
}
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
ViewModel\ ControlBarViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class ControlBarViewModel : BaseViewModel
{
#region commands
public ICommand CloseWindowCommand { get; set; }
public ICommand MaximizeWindowCommand { get; set; }
public ICommand MinimizeWindowCommand { get; set; }
public ICommand MouseMoveWindowCommand { get; set; }
#endregion
public ControlBarViewModel()
{
CloseWindowCommand = new RelayCommand<UserControl>((p)=> { return p == null? false : true; }, (p)=> {
FrameworkElement window = GetWindowParent(p);
var w = window as Window;
if (w != null)
{
w.Close();
}
}
);
MaximizeWindowCommand = new RelayCommand<UserControl>((p) => { return p == null ? false : true; }, (p) =>
{
FrameworkElement window = GetWindowParent(p);
var w = window as Window;
if (w != null)
{
if (w.WindowState != WindowState.Maximized)
w.WindowState = WindowState.Maximized;
else
w.WindowState = WindowState.Normal;
}
}
);
MinimizeWindowCommand = new RelayCommand<UserControl>((p) => { return p == null ? false : true; }, (p) =>
{
FrameworkElement window = GetWindowParent(p);
var w = window as Window;
if (w != null)
{
if (w.WindowState != WindowState.Minimized)
w.WindowState = WindowState.Minimized;
else
w.WindowState = WindowState.Maximized;
}
}
);
MouseMoveWindowCommand = new RelayCommand<UserControl>((p) => { return p == null ? false : true; }, (p) =>
{
FrameworkElement window = GetWindowParent(p);
var w = window as Window;
if (w != null)
{
w.DragMove();
}
}
);
}
FrameworkElement GetWindowParent(UserControl p)
{
FrameworkElement parent = p;
while (parent.Parent != null)
{
parent = parent.Parent as FrameworkElement;
}
return parent;
}
}
}
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
ViewModel\MainViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class MainViewModel : BaseViewModel
{
public bool Isloaded = false;
public ICommand LoadedWindowCommand { get; set; }
public ICommand UnitCommand { get; set; }
public ICommand SuplierCommand { get; set; }
public ICommand CustomerCommand { get; set; }
public ICommand ObjectCommand { get; set; }
public ICommand UserCommand { get; set; }
public ICommand InputCommand { get; set; }
public ICommand OutputCommand { get; set; }
// mọi thứ xử lý sẽ nằm trong này
public MainViewModel()
{
LoadedWindowCommand = new RelayCommand<object>((p) => { return true; }, (p) => {
Isloaded = true;
LoginWindow loginWindow = new LoginWindow();
loginWindow.ShowDialog();
}
);
UnitCommand = new RelayCommand<object>((p) => { return true; }, (p) => { UnitWindow wd = new UnitWindow(); wd.ShowDialog(); });
SuplierCommand = new RelayCommand<object>((p) => { return true; }, (p) => { SuplierWindow wd = new SuplierWindow(); wd.ShowDialog(); });
CustomerCommand = new RelayCommand<object>((p) => { return true; }, (p) => { CustomerWindow wd = new CustomerWindow(); wd.ShowDialog(); });
ObjectCommand = new RelayCommand<object>((p) => { return true; }, (p) => { ObjectWindow wd = new ObjectWindow(); wd.ShowDialog(); });
UserCommand = new RelayCommand<object>((p) => { return true; }, (p) => { UserWindow wd = new UserWindow(); wd.ShowDialog(); });
InputCommand = new RelayCommand<object>((p) => { return true; }, (p) => { InputWindow wd = new InputWindow(); wd.ShowDialog(); });
OutputCommand = new RelayCommand<object>((p) => { return true; }, (p) => { OutputWindow wd = new OutputWindow(); wd.ShowDialog(); });
}
}
}
12345678910111213141516171819202122232425262728293031323334353637383940414243
Tải Project
Nếu việc thực hành theo hướng dẫn không diễn ra suôn sẻ như mong muốn. Bạn cũng có thể tải xuống PROJECT THAM KHẢO ở link bên dưới!
Kết
Trong bài này, chúng ta đã tìm hiểu cách Kết nối Entity Framework vào project trong phần mềm quản lý kho.
Ở bài sau, Kteam sẽ giới thiệu đến bạn cách CLASS DATAPROVIDER TRONG PHẦN MỀM QUẢN LÝ KHO WPF – MVVM.
Cảm ơn các bạn đã theo dõi bài viết. Hãy để lại bình luận hoặc góp ý của mình để phát triển bài viết tốt hơn. Và đừng quên “Luyện tập – Thử Thách – Không ngại khó”
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Kết nối Entity Framework trong Phần mềm quản lý kho WPF - MVVM dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!

Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
Nội dung bài viết
Tác giả/Dịch giả
Khóa học
Lập trình phần mềm quản lý kho WPF - MVVM
Nếu bạn đã từng rất thích thú với việc tự làm dự án thực tế qua serial hướng dẫn lập trình PHẦN MỀM QUẢN LÝ QUÁN CAFE bằng Winform thì chẳng có lý do gì để không tiếp tục nâng cao kinh nghiệm cá nhân với serial lập trình Phần mềm quản lý kho WPF – MVVM.
Serial Phần mềm quản lý kho sử dụng công nghệ WPF cùng với mô hình MVVM, sử dụng entity framework và theme giao diện của WPF Material design,... cùng rất nhiều kỹ thuật, kinh nghiệm khác.
Không có gì tuyệt vời hơn là luyện tập với dự án thực tế. Nào cùng nhau thử thách bản thân với phần mềm Quản lý kho WPF – MVVM.
Bạn nào không tìm ADO thì xem lại cái này nhé
Mình cũng lên mạng tìm cách cài các thứ nhưng cuối cùng nó nằm ở bước tạo file á phải tạo WPF App (.Net FrameWork), nó phải là Framework mới có, chứ WPF Appication không thì không có
Khóa học của a rất hay!
Kteam ơi! cho mình hỏi, nếu muốn tạo thêm 1 window thực hiện chức năng kết nối đến database (tức có thể thay đổi thông tin kết nối, dùng cho nhiều máy con trong mạng LAN chẳng hạn) thì thực hiện như thế nào, mong Kteam giúp đỡ. TKS