Professional Documents
Culture Documents
Bài: Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF -
MVVM
Xem bài học trên website để ủng hộ Kteam: Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM
Mọi vấn đề về lỗi website làm ảnh hưởng đến bạn hoặc thắc mắc, mong muốn khóa học mới, nhằm hỗ trợ cải thiện Website. Các bạn vui lòng phản hồi
đến Fanpage How Kteam nhé!
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ề THÊM XÓA SỬA OBJECT 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 về
Thêm xóa sửa Customer 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ề:
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 2|43
<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>
App.xaml.cs
C#:
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
{
}
}
CustomerWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 3|43
<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"
DataContext="{StaticResource CustomerVM}"
Title="Khách hàng" Height="500" Width="800">
<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>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 4|43
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
CustomerWindow.xaml.cs
C#:
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();
}
}
}
InputWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 5|43
<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"
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 6|43
InputWindow.xaml.cs
C#:
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();
}
}
}
LoginWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 7|43
<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: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"
DataContext="{StaticResource LoginVM}"
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"
Text="{Binding UserName}"
Style="{StaticResource MaterialDesignFloatingHintTextBox}" />
</Grid>
<Grid Grid.Row="1">
<PasswordBox x:Name="FloatingPasswordBox"
materialDesign:HintAssist.Hint="Mật khẩu"
Style="{StaticResource MaterialDesignFloatingHintPasswordBox}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="PasswordChanged">
<i:InvokeCommandAction Command="{Binding PasswordChangedCommand}"
CommandParameter="{Binding ElementName=FloatingPasswordBox}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</PasswordBox>
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 8|43
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
IsDefault="True"
Style="{StaticResource MaterialDesignRaisedButton}"
Width="110"
Command="{Binding LoginCommand}"
CommandParameter="{Binding ElementName=loginWindow}"
ToolTip="Resource name: MaterialDesignRaisedButton" Content="Đăng nhập"></Button>
<Button Grid.Column="1"
Style="{StaticResource MaterialDesignRaisedButton}"
Width="110"
Command="{Binding CloseCommand}"
CommandParameter="{Binding ElementName=loginWindow}"
Background="OrangeRed"
ToolTip="Resource name: MaterialDesignRaisedButton" Content="Thoát"></Button>
</Grid>
</Grid>
</materialDesign:Card>
</Grid>
</Window>
LoginWindow.xaml.cs
C#:
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();
}
}
}
MainWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 9|43
<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="700" Width="725">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadedWindowCommand}"
CommandParameter="{Binding ElementName=mainWindow}"/>
</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>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 10|43
<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">
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 11|43
<!--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"
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 12|43
<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"
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 13|43
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.Column="0">
<DatePicker VerticalAlignment="Center" HorizontalAlignment="Left" Width="100"
materialDesign:HintAssist.Hint="Ngày bắt đầu" Style="{StaticResource MaterialDesignFloatingHintDatePicker}" />
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 14|43
</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 ItemsSource="{Binding TonKhoList}">
<ListView.View>
<GridView>
<GridViewColumn Header="STT" DisplayMemberBinding="{Binding STT}"></GridViewColumn>
<GridViewColumn Header="Tên vật tư" DisplayMemberBinding="{Binding Object.DisplayName}">
</GridViewColumn>
<GridViewColumn Header="Số lượng tồn" DisplayMemberBinding="{Binding Count}">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Grid>
</materialDesign:Card>
</Grid>
</Grid>
</Grid>
</Window>
MainWindow.xaml.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 15|43
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();
}
}
}
ObjectWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 16|43
<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"
DataContext="{StaticResource ObjectVM}"
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>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 17|43
<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>
ObjectWindow.xaml.cs
C#:
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();
}
}
}
OutputWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 18|43
<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"
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 19|43
OutputWindow.xaml.cs
C#:
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();
}
}
}
SuplierWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 20|43
<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"
DataContext="{StaticResource SuplierVM}"
Title="Nhà cung cấp" Height="500" Width="800">
<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>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 21|43
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
SuplierWindow.xaml.cs
C#:
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();
}
}
}
UnitWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 22|43
<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"
DataContext="{StaticResource UnitVM}"
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>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 23|43
</ListView>
</ScrollViewer>
</materialDesign:Card>
</Grid>
</Grid>
</Window>
UnitWindow.xaml.cs
C#:
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();
}
}
}
UserWindow.xaml
xml:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 24|43
<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"
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 25|43
UserWindow.xaml.cs
C#:
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();
}
}
}
ResourceXAML
ResourceXAML\MainResource.xaml
xml:
<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>
<viewmodel:LoginViewModel x:Key="LoginVM"></viewmodel:LoginViewModel>
<viewmodel:UnitViewModel x:Key="UnitVM"></viewmodel:UnitViewModel>
<viewmodel:SuplierViewModel x:Key="SuplierVM"></viewmodel:SuplierViewModel>
<viewmodel:ObjectViewModel x:Key="ObjectVM"></viewmodel:ObjectViewModel>
<viewmodel:CustomerViewModel x:Key="CustomerVM"></viewmodel:CustomerViewModel>
</ResourceDictionary>
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 26|43
UserControlKteam
UserControlKteam\ControlBarUC.xaml
xml:
<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>
UserControlKteam\ControlBarUC.xaml.cs
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 27|43
C#:
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();
}
}
}
ViewModel
ViewModel\BaseViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 28|43
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;
ViewModel\ ControlBarViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 29|43
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();
}
}
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 30|43
);
}
FrameworkElement GetWindowParent(UserControl p)
{
FrameworkElement parent = p;
return parent;
}
}
}
ViewModel\CustomerViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 31|43
using QuanLyKho.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class CustomerViewModel : BaseViewModel
{
private ObservableCollection<Customer> _List;
public ObservableCollection<Customer> List { get => _List; set { _List = value; OnPropertyChanged(); } }
public CustomerViewModel()
{
List = new ObservableCollection<Customer>(DataProvider.Ins.DB.Customers);
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 32|43
}, (p) =>
{
var Customer = new Customer() { DisplayName = DisplayName, Phone = Phone, Address = Address, Email = Email,
ContractDate = ContractDate, MoreInfo = MoreInfo };
DataProvider.Ins.DB.Customers.Add(Customer);
DataProvider.Ins.DB.SaveChanges();
List.Add(Customer);
});
return false;
}, (p) =>
{
var Customer = DataProvider.Ins.DB.Customers.Where(x => x.Id == SelectedItem.Id).SingleOrDefault();
Customer.DisplayName = DisplayName;
Customer.Phone = Phone;
Customer.Address = Address;
Customer.Email = Email;
Customer.ContractDate = ContractDate;
Customer.MoreInfo = MoreInfo;
DataProvider.Ins.DB.SaveChanges();
SelectedItem.DisplayName = DisplayName;
});
}
}
}
ViewModel\ LoginViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 33|43
using QuanLyKho.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
class LoginViewModel : BaseViewModel
{
public bool IsLogin { get; set; }
private string _UserName;
public string UserName { get=>_UserName; set { _UserName = value;OnPropertyChanged(); } }
private string _Password;
public string Password { get => _Password; set { _Password = value; OnPropertyChanged(); } }
void Login(Window p)
{
if (p == null)
return;
/*
admin
admin
staff
staff
*/
if (accCount > 0)
{
IsLogin = true;
p.Close();
}
else
{
IsLogin = false;
MessageBox.Show("Sai tài khoản hoặc mật khẩu!");
}
}
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 34|43
}
}
ViewModel\MainViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 35|43
using QuanLyKho.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class MainViewModel : BaseViewModel
{
private ObservableCollection<TonKho> _TonKhoList;
public ObservableCollection<TonKho> TonKhoList { get=> _TonKhoList; set { _TonKhoList = value;OnPropertyChanged(); } }
if (loginWindow.DataContext == null)
return;
var loginVM = loginWindow.DataContext as LoginViewModel;
if (loginVM.IsLogin)
{
p.Show();
LoadTonKhoData();
}
else
{
p.Close();
}
}
);
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(); });
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 36|43
OutputCommand = new RelayCommand<object>((p) => { return true; }, (p) => { OutputWindow wd = new OutputWindow();
wd.ShowDialog(); });
}
void LoadTonKhoData()
{
TonKhoList = new ObservableCollection<TonKho>();
int i = 1;
foreach (var item in objectList)
{
var inputList = DataProvider.Ins.DB.InputInfoes.Where(p => p.IdObject == item.Id);
var outputList = DataProvider.Ins.DB.OutputInfoes.Where(p => p.IdObject == item.Id);
int sumInput = 0;
int sumOutput = 0;
TonKhoList.Add(tonkho);
i++;
}
}
}
}
ViewModel\ObjectViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 37|43
using QuanLyKho.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class ObjectViewModel : BaseViewModel
{
private ObservableCollection<Model.Object> _List;
public ObservableCollection<Model.Object> List { get => _List; set { _List = value; OnPropertyChanged(); } }
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 38|43
public ObjectViewModel()
{
List = new ObservableCollection<Model.Object>(DataProvider.Ins.DB.Objects);
Unit = new ObservableCollection<Model.Unit>(DataProvider.Ins.DB.Units);
Suplier = new ObservableCollection<Model.Suplier>(DataProvider.Ins.DB.Supliers);
AddCommand = new RelayCommand<object>((p) =>
{
if (SelectedSuplier == null || SelectedUnit == null)
return false;
return true;
}, (p) =>
{
var Object = new Model.Object() { DisplayName = DisplayName, BarCode = BarCode, QRCode = QRCode, IdSuplier =
SelectedSuplier.Id, IdUnit = SelectedUnit.Id, Id = Guid.NewGuid().ToString()};
DataProvider.Ins.DB.Objects.Add(Object);
DataProvider.Ins.DB.SaveChanges();
List.Add(Object);
});
return false;
}, (p) =>
{
var Object = DataProvider.Ins.DB.Objects.Where(x => x.Id == SelectedItem.Id).SingleOrDefault();
Object.DisplayName = DisplayName;
Object.BarCode = BarCode;
Object.QRCode = QRCode;
Object.IdSuplier = SelectedSuplier.Id;
Object.IdUnit = SelectedUnit.Id;
DataProvider.Ins.DB.SaveChanges();
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 39|43
SelectedItem.DisplayName = DisplayName;
});
}
}
}
ViewModel\SuplierViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 40|43
using QuanLyKho.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class SuplierViewModel : BaseViewModel
{
private ObservableCollection<Suplier> _List;
public ObservableCollection<Suplier> List { get => _List; set { _List = value; OnPropertyChanged(); } }
public SuplierViewModel()
{
List = new ObservableCollection<Suplier>(DataProvider.Ins.DB.Supliers);
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 41|43
}, (p) =>
{
var Suplier = new Suplier() { DisplayName = DisplayName, Phone = Phone, Address = Address, Email = Email,
ContractDate = ContractDate, MoreInfo = MoreInfo };
DataProvider.Ins.DB.Supliers.Add(Suplier);
DataProvider.Ins.DB.SaveChanges();
List.Add(Suplier);
});
return false;
}, (p) =>
{
var Suplier = DataProvider.Ins.DB.Supliers.Where(x => x.Id == SelectedItem.Id).SingleOrDefault();
Suplier.DisplayName = DisplayName;
Suplier.Phone = Phone;
Suplier.Address = Address;
Suplier.Email = Email;
Suplier.ContractDate = ContractDate;
Suplier.MoreInfo = MoreInfo;
DataProvider.Ins.DB.SaveChanges();
SelectedItem.DisplayName = DisplayName;
});
}
}
}
ViewModel\UnitViewModel.cs
C#:
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 42|43
using QuanLyKho.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace QuanLyKho.ViewModel
{
public class UnitViewModel : BaseViewModel
{
private ObservableCollection<Unit> _List;
public ObservableCollection<Unit> List { get=> _List; set { _List = value;OnPropertyChanged(); } }
public UnitViewModel()
{
List = new ObservableCollection<Unit>(DataProvider.Ins.DB.Units);
return true;
}, (p) =>
{
var unit = new Unit() { DisplayName = DisplayName };
DataProvider.Ins.DB.Units.Add(unit);
DataProvider.Ins.DB.SaveChanges();
List.Add(unit);
});
Copyright © Howkteam.com
Thêm xóa sửa Customer trong phần mềm Quản lý kho WPF - MVVM 43|43
return true;
}, (p) =>
{
var unit = DataProvider.Ins.DB.Units.Where(x=>x.Id == SelectedItem.Id).SingleOrDefault();
unit.DisplayName = DisplayName;
DataProvider.Ins.DB.SaveChanges();
SelectedItem.DisplayName = DisplayName;
});
}
}
}
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 về cách Thêm xóa sửa Customer trong Phần mềm quản lý kho WPF – MVVM.
Ở bài sau, Kteam sẽ giới thiệu đến bạn về cách THÊM XÓA SỬA PHIẾU XUẤT 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ó”
Copyright © Howkteam.com