You are on page 1of 46

ĐẠI HỌC BÁCH KHOA HÀ NỘI

TRƯỜNG ĐIỆN – ĐIỆN TỬ


**********

BÁO CÁO BÀI TẬP LỚN


Kỹ Thuật Phần Mềm Ứng Dụng
Đề tài: Hệ thống quản lý CSDL chăn nuôi
Giảng viên hướng dẫn: Vũ Song Tùng

Mã lớp: 145539

Nhóm sinh viên thực hiện (STT:15)

Họ và tên MSSV
Phan Thanh An 20216032
Nguyễn Minh Quân 20210705
Nguyễn Thế Nghĩa 20214024
Nguyễn Quang Hoàng 20213935

Hà Nội, 1/2024
1
MỤC LỤC
MỤC LỤC.............................................................................................................................................2
MỞ ĐẦU...............................................................................................................................................3
CHƯƠNG I: TỔNG QUAN.................................................................................................................4
1.1. YÊU CẦU CHỨC NĂNG....................................................................................................4
1.2. YÊU CẦU PHI CHỨC NĂNG............................................................................................4
1.3. GIỚI THIỆU CÔNG CỤ, PHẦN MỀM SỬ DỤNG..........................................................5
1.3.1. Visual Studio C#............................................................................................................5
1.3.2. WPF (Windows Presentation Foundation).................................................................6
1.3.3. Microsoft SQL Server...................................................................................................6
1.4. MÔ HÌNH MVVM...............................................................................................................7
CHƯƠNG II: PHÂN TÍCH THIẾT KẾ HỆ THỐNG.......................................................................8
2.1. SƠ ĐỒ FHD..........................................................................................................................8
2.2. SƠ ĐỒ DFD..........................................................................................................................9
2.2.1. DFD Mức Ngữ Cảnh (mức 0).......................................................................................9
2.2.2. DFD Mức Đỉnh (mức 1)................................................................................................9
2.2.3. DFD Mức 2..................................................................................................................10
2.3. SƠ ĐỒ ERD........................................................................................................................10
Chương III: TRIỂN KHAI HỆ THỐNG..........................................................................................11
3.1. SQL SERVER.....................................................................................................................11
3.1.1. Quản Lý Về Dịch Bệnh, Cơ Sở, Vùng Chăn Nuôi..........................................................11
3.1.2. Quản Lý Văn Bản Pháp Luật Về Chăn Nuôi..................................................................14
3.2. GIAO DIỆN........................................................................................................................15
KẾT LUẬN.........................................................................................................................................15
TÀI LIỆU THAM KHẢO..................................................................................................................16

2
MỞ ĐẦU

Trong những năm qua, ngành chăn nuôi Việt Nam đang trên đà phát triển,
là một ngành nông nghiệp rất quan trọng, đóng góp vào nhu cầu thực phẩm của
con người. Tuy nhiên, để quản lý và kiểm soát dịch bệnh, các văn bản pháp luật
quy định về chăn nuôi, các cá nhân tổ chức thực hiện sản xuất, khảo nghiệm con
giống, xử lý chất thải, cơ sở giết mổ,…… cần phải có một hệ thống quản lý dữ
liệu hiệu quả.

Bài tập lớn này sẽ tập trung vào việc thiết kế một CSDL để quản lý các thông tin
liên quan đến chăn nuôi, bao gồm thông tin về dịch bệnh; văn bản pháp luật về
CSDL chăn nuôi và thống kê các cơ sở, tổ chức, cá nhân hoạt động trong lĩnh
vực chăn nuôi. Mục đích của bài tập này là giúp hiểu rõ hơn về cách thiết kế
CSDL, tăng cường kỹ năng phân tích và thiết kế hệ thống cơ sở dữ liệu.

Nhiệm vụ của bài tập lớn này bắt đầu bằng việc phân tích yêu cầu và thiết kế các
bảng dữ liệu, quan hệ giữa chúng, các khóa chính và ngoại. Sau đó, sẽ xây dựng
các truy vấn và hàm trong CSDL để truy xuất thông tin một cách hiệu quả. Bên
cạnh đó, cũng cần thiết kế giao diện dễ dàng sử dụng.

Bản cáo cáo này gồm có 3 chương. Chương I về tổng quan chương trình quản lý
CSDL chăn nuôi. Chương II về phân tích thiết kế hệ thống, bằng cách vẽ các sơ
đồ FHD, DFD, ERD. Chương III về triển khai hệ thống.

3
CHƯƠNG I: TỔNG QUAN
Chương này đặt vấn đề cần giải quyết khi đề xuất hệ thống quản lý và
phân tích các chức năng cần thiết để giải quyết vấn đề đặt ra. Đồng thời mô tả sơ
lược các công cụ hỗ trợ của bên thứ ba được sử dụng trong đề tài.

1.1. YÊU CẦU CHỨC NĂNG

 Đăng nhập và quản lý người dùng: Yêu cầu cho phép người dùng đăng
nhập và quản lý thông tin người dùng.
 Quản lý dữ liệu: Yêu cầu cho phép người dùng tạo, lưu trữ, cập nhật và
xóa dữ liệu.
 Tìm kiếm và lọc dữ liệu: Yêu cầu cho phép người dùng tìm kiếm và lọc
dữ liệu theo nhiều tiêu chí khác nhau.
 Hiển thị dữ liệu: Yêu cầu cho phép hiển thị dữ liệu theo cách rõ ràng,
dễ đọc và dễ hiểu.
 Thao tác và xử lý dữ liệu: Yêu cầu cho phép người dùng thao tác với
dữ liệu và thực hiện các xử lý dữ liệu.
 Tương tác với người dùng: Yêu cầu cho phép tương tác với người dùng
thông qua các giao diện người dùng thân thiện và dễ sử dụng.
 Bảo mật và phân quyền: Yêu cầu cho phép bảo mật dữ liệu và phân
quyền truy cập cho người dùng.
 Giao tiếp với các hệ thống khác: Yêu cầu cho phép phần mềm giao tiếp
với các hệ thống khác để chia sẻ và truyền dữ liệu.

1.2. YÊU CẦU PHI CHỨC NĂNG

 Hiệu suất: Yêu cầu về hiệu suất để đảm bảo rằng phần mềm hoạt động
một cách nhanh chóng và mượt mà.
 Độ tin cậy: Yêu cầu độ tin cậy để đảm bảo rằng phần mềm không gây
ra lỗi, sự cố hoặc mất dữ liệu.
4
 An ninh: Yêu cầu về an ninh để đảm bảo rằng phần mềm được bảo vệ
chống lại các cuộc tấn công và lỗ hổng bảo mật.
 Khả năng mở rộng: Yêu cầu về khả năng mở rộng để đảm bảo rằng
phần mềm có thể mở rộng và tích hợp với các hệ thống khác.
 Khả năng tương thích: Yêu cầu về khả năng tương thích để đảm bảo
rằng phần mềm có thể hoạt động trên các hệ điều hành khác nhau và
với các phiên bản khác nhau của các công nghệ khác nhau.
 Dễ sử dụng: Yêu cầu về dễ sử dụng để đảm bảo rằng người sử dụng có
thể sử dụng phần mềm một cách dễ dàng và không gặp phải khó khăn
trong việc tìm hiểu cách sử dụng.
 Tính linh hoạt: Yêu cầu về tính linh hoạt để đảm bảo rằng phần mềm
có thể tùy chỉnh và cấu hình cho các nhu cầu đặc biệt của khách hàng.
 Thân thiện với người dùng: Yêu cầu về thân thiện với người dùng để
đảm bảo rằng phần mềm tạo ra trải nghiệm người dùng tốt và thân
thiện.

1.3. GIỚI THIỆU CÔNG CỤ, PHẦN MỀM SỬ DỤNG

1.3.1. Visual Studio C#

Visual Studio là một môi trường phát triển tích hợp (IDE) do Microsoft thiết
kế, chủ yếu sử dụng cho việc phát triển ứng dụng trên nền tảng Microsoft. Dưới
đây là một tóm tắt về Visual Studio khi bạn sử dụng ngôn ngữ lập trình C#:

 Môi trường IDE: Visual Studio cung cấp một giao diện người dùng thân
thiện, giúp bạn dễ dàng phát triển, chạy và gỡ lỗi ứng dụng.
 Hỗ trợ C#: Visual Studio là một IDE mạnh mẽ cho ngôn ngữ lập trình C#,
giúp bạn tạo, quản lý và triển khai ứng dụng một cách thuận tiện.
 Debugger Tích hợp: Bạn có thể sử dụng bộ debugger mạnh mẽ để theo
dõi và gỡ lỗi mã nguồn, giúp bạn nhanh chóng tìm và sửa lỗi.
 Source Control: Visual Studio tích hợp với các hệ thống quản lý phiên bản
như Git, TFS, giúp bạn theo dõi sự thay đổi và quản lý mã nguồn.
5
 Thiết kế giao diện người dùng: Cho phép bạn dễ dàng thiết kế giao diện
người dùng đồ họa mà không cần kiến thức chuyên sâu về mã nguồn.
 IntelliSense: Tính năng tự động hoàn chỉnh mã giúp bạn viết mã nhanh
chóng và hiệu quả.
 Tích hợp Azure: Hỗ trợ tích hợp với dịch vụ đám mây Azure, giúp bạn
triển khai và quản lý ứng dụng trên nền tảng đám mây của Microsoft.

Đây chỉ là một số điểm nổi bật của Visual Studio khi sử dụng với ngôn ngữ lập
trình C#. IDE này dễ dàng xây dựng ứng dụng và tối ưu hóa quy trình phát triển.

1.3.2. WPF (Windows Presentation Foundation)

WPF (Windows Presentation Foundation) là một công nghệ phát triển


giao diện người dùng trong hệ điều hành Windows. Được Microsoft giới thiệu,
WPF cung cấp cách tiếp cận linh hoạt và mạnh mẽ để xây dựng ứng dụng
Windows với giao diện người dùng đẹp và tương tác cao. Thay vì sử dụng mã
XAML để mô tả giao diện người dùng và logic, WPF mang lại khả năng tách
biệt giữa giao diện và mã nguồn, giúp việc phát triển ứng dụng trở nên thuận
tiện và hiệu quả. WPF hỗ trợ các tính năng như đối tượng đồ họa vectơ, kiểu dữ
liệu, hiệu ứng và phong cách, giúp tạo ra ứng dụng Windows độc đáo và dễ bảo
trì.

1.3.3. Microsoft SQL Server

Microsoft SQL Server là một hệ quản trị cơ sở dữ liệu (RDBMS) do


Microsoft phát triển. Được thiết kế để quản lý và lưu trữ dữ liệu trong môi
trường doanh nghiệp, SQL Server cung cấp một loạt các tính năng mạnh mẽ:

 Quản lí dữ liệu : SQL Server hỗ trợ lưu trữ, truy xuất và quản lý dữ liệu
với hiệu suất cao và độ tin cậy.
 Ngôn ngữ truy vấn T-SQL: Sử dụng Transact-SQL (T-SQL) để thực hiện
các truy vấn và thao tác dữ liệu.

6
 Bảo mật dữ liệu: Cung cấp cơ chế bảo mật mạnh mẽ để bảo vệ dữ liệu,
bao gồm quản lý quyền truy cập và mã hóa.
 Khả năng mở rộng: SQL Server hỗ trợ mô hình dữ liệu phức tạp, có khả
năng mở rộng để đáp ứng nhu cầu của các ứng dụng doanh nghiệp lớn.
 Quản lí hiệu suất: Cung cấp các công cụ quản lý hiệu suất, theo dõi và tối
ưu hóa truy vấn để đảm bảo hoạt động hiệu quả.
 Tích hợp với công nghệ Microsoft: SQL Server chặt chẽ tích hợp với
nhiều công nghệ Microsoft khác nhau, như .NET Framework và Azure, để
tối ưu hóa quy trình phát triển và triển khai.

SQL Server đóng vai trò quan trọng trong việc lưu trữ và quản lý dữ liệu cho các
ứng dụng doanh nghiệp và là một trong những hệ quản trị cơ sở dữ liệu phổ biến
trên thị trường.

1.4. MÔ HÌNH MVC

Mô hình MVC (Model-View-Controller) là một mô hình phát triển phần mềm


được sử dụng rộng rãi trong việc xây dựng các ứng dụng web. Mô hình này tách
biệt logic xử lý dữ liệu (Model), giao diện người dùng (View) và điều khiển
luồng thông tin (Controller). Bằng cách tổ chức ứng dụng thành các thành phần
riêng biệt, MVC giúp tăng tính linh hoạt, sửa chữa dễ dàng và tăng khả năng mở
rộng của ứng dụng. - Model (M): Đây là thành phần đại diện cho dữ liệu và
logic xử lý dữ liệu. Model đảm nhận vai trò quản lý dữ liệu, thực hiện các thao
tác truy xuất, cập nhật, xóa dữ liệu và thực hiện các quy tắc kinh doanh liên
quan. Model không phụ thuộc vào View hoặc Controller, điều này giúp nó có thể
được sử dụng lại trong các ứng dụng khác nhau. - View (V): Đây là thành phần
đại diện cho giao diện người dùng. View có nhiệm vụ hiển thị dữ liệu từ Model
và cung cấp cách thức cho người dùng tương tác với ứng dụng. View không chịu
trách nhiệm xử lý logic hay lưu trữ dữ liệu, nó chỉ làm nhiệm vụ biểu diễn dữ
liệu. - Controller (C): Đây là thành phần đại diện cho điều khiển luồng thông tin
giữa Model và View. Controller nhận lệnh từ người dùng thông qua View, xử lý
các yêu cầu và gọi các phương thức tương ứng trong Model để thực hiện các
7
thao tác liên quan đến dữ liệu. Sau đó, Controller chuyển kết quả trả về từ
Model cho View hiển thị cho người dùng. Mô hình MVC giúp tách biệt logic
ứng dụng thành các thành phần riêng biệt, từ đó giúp tạo ra mã nguồn dễ bảo trì,
tái sử dụng và phát triển. Nó cũng thúc đẩy sự phân chia công việc giữa các
thành viên trong đội ngũ phát triển, giúp tăng hiệu suất làm việc. Ngoài ra, mô
hình MVC cũng cho phép dễ dàng thay đổi giao diện người dùng mà không ảnh
hưởng đến dữ liệu và logic xử lý bên trong ứng dụng.

CHƯƠNG II: PHÂN TÍCH THIẾT KẾ HỆ THỐNG


Để mang đến một sản phẩm phần mềm chất lượng đáng tin cậy thì việc
phân tích yêu cầu là khâu vô cùng quan trọng trong quá trình xây dựng phần
mềm, chương này sẽ đi vào phân tích hệ thống thông qua các sơ đồ FHD, DFD,
ERD.

2.1. SƠ ĐỒ FHD

Sơ đồ FHD( Function Hierarchy Diagram ) thường được sử dụng trong giai


đoạn thiết kế hệ thống phần mềm, sau khi đã xác định được các yêu cầu của
khách hàng và các chức năng cần có trong hệ thống. Nó giúp cho các nhà phát
triển và nhà thiết kế có thể phân tích và trình bày các chức năng của hệ thống
một cách cụ thể, đồng thời tạo ra một cái nhìn tổng quan về các chức năng chính
và cách chúng tương tác với nhau.

Dưới đây là sơ đồ FHD của phần mềm.

8
Hình 2.1: sơ đồ FHD

Từ sơ đồ FHD bên trên, thiết kế hệ thống thực hiện 2 chức năng chính đó là
Quản trị hệ thống và Quản lý CSDL về chăn nuôi. Bên trong Quản trị hệ thống
gồm: Quản lý chức năng hệ thống, Quản lý thông tin người dùng và Bảo mật,
phân quyền. Bên trong Quản lý CSDL chăn nuôi gồm: Quản lý CSDL về dịch
bệnh, thống kê, báo cáo về CSDL chăn nuôi, quản lý văn bản pháp luật về CSDL
chăn nuôi.

2.2. SƠ ĐỒ DFD

Sơ đồ luồng dữ liệu( Data Flow Diagram ), viết tắt là DFD, là một mô


hình hệ thống cân xứng cả dữ liệu và tiến trình (progress). Nó chỉ ra cách thông
tin chuyển vận từ một tiến trình hoặc từ chức năng này trong hệ thống sang một
tiến trình hoăc chức năng khác.

2.2.1. DFD Mức Ngữ Cảnh (mức 0)

9
Hình 2.2.1: sơ đồ DFD mức ngữ cảnh

(1) Trả kết quả tìm kiếm


(2) Gửi yêu cầu tìm kiếm
(3) Trả kết quả thống kê
(4) Gửi kết quả thống kê
2.2.2. DFD Mức Đỉnh (mức 1)

Hình 2.2.2: Sơ đồ DFD mức đỉnh

2.2.3. DFD Mức 2

10
Hình 2.2.3: lược đồ chức năng thống kê

2.3. SƠ ĐỒ ERD

Mô hình ERD ( Entity Relationship Diagram) hay sơ đồ quan hệ thực thể


ERD là một mô hình được sử dụng để mô phỏng mối quan hệ giữa các thực thể
như con người, đồ vật và các khái niệm liên quan trong một hệ thống hoặc lĩnh
vực cụ thể. Trong một mô hình ERD sẽ bao gồm các thực thể cụ thể, những thực
thể này sẽ có mối quan hệ gắn kết với nhau trong các trường hợp khác nhau.

Hình 2.3a: Sơ đồ ERD quản lý về dịch bệnh, cơ sở, vùng chăn nuôi
11
Hình 2.3b: Sơ đồ ERD quản lý văn bản pháp luật về chăn nuôi

Chương III: TRIỂN KHAI HỆ THỐNG


3.1. SQL SERVER

3.1.1. Quản Lý Về Dịch Bệnh, Cơ Sở, Vùng Chăn Nuôi

3.1.1.1. Database

use master
go

drop database QuanLyChanNuoi


go

create database QuanLyChanNuoi


go

use QuanLyChanNuoi
go

create table ToChucCapGCN(


Ten nvarchar(50) primary key,
DiaChi nvarchar(100),
SDT nvarchar(11)
)

12
create table GiayChungNhan(
ID int identity primary key,
NoiCap nvarchar(50) foreign key references
ToChucCapGCN(Ten),
ChiTieuDanhGia nvarchar(100)
)

create table LoaiCoSo(


Id int identity primary key,
Ten nvarchar(200)
)

create table Vung(


Id int identity primary key,
Ten nvarchar(50),
TinhTrang nvarchar(50)
)

create table CoSo(


Id int identity primary key,
LoaiCoSoId int foreign key references LoaiCoSo(Id),
VungId int foreign key references Vung(Id),
Ten nvarchar(100),
DiaChi nvarchar(100),
GiayChungNhanId int foreign key references
GiayChungNhan(ID),
SDT nvarchar(11)
)

create table LoaiDichBenh(


Id int identity primary key,
Ten nvarchar(100),
TrieuChung nvarchar(500)
)

13
create table ODich(
Id int identity primary key,
Ten nvarchar(100),
LoaiDichBenhId int foreign key references
LoaiDichBenh(Id),
VungId int foreign key references Vung(Id),
ChuanDoanODich nvarchar(500),
TiemPhong nvarchar(100),
BanDo nvarchar(5)
)
3.1.1.2. Tạo View
a. Tạo View ổ dịch

create view ViewODich as


select ODich.Id as ID, ODich.Ten as TenODich,
ODich.ChuanDoanODich, ODich.TiemPhong, Vung.Ten as Vung,
LoaiDichBenh.Ten as LoaiDich
from ODich
inner join Vung on VungId = Vung.Id
inner join LoaiDichBenh on LoaiDichBenhId = LoaiDichBenh.Id;
b. Tạo View Loại dịch bệnh

create view ViewLoaiDichBenh as


select LoaiDichBenh.Ten, count(ODich.Id) as SoODich
from LoaiDichBenh
left join ODich on LoaiDichBenhId = LoaiDichBenh.Id
group by LoaiDichBenh.Ten
c. Tạo View loại cơ sở

create view ViewLoaiCoSo as


select LoaiCoSo.Ten, count(CoSo.Id) as SoCoSo
from LoaiCoSo
left join CoSo on LoaiCoSoId = LoaiCoSo.Id
group by LoaiCoSo.Ten
d. Tạo view vùng
14
create view ViewVung as
select Vung.Ten, count(ODich.Id) as SoODich
from Vung
left join ODich on VungId = Vung.Id
group by Vung.Ten

3.1.2. Quản Lý Văn Bản Pháp Luật Về Chăn Nuôi


3.1.2.1. Database

use master
go

drop database VBPhapLuat


go

create database VBPhapLuat


go

use VBPhapLuat
go

create table VBPhapLuat(


Id int primary key,
Ten nvarchar(100)
)

create table FileDinhKem(


Id int primary key,
VbPhapLuatID int foreign key references VBPhapLuat(Id),
fileVanBan nvarchar(200)
)

3.1.2.2. Tạo View

create view ViewVBPhapLuat as

15
select VBPhapLuat.Ten as VanBanPhapLuat, FileDinhKem.fileVanBan as
fileDinhKem
from VBPhapLuat
left join FileDinhKem on VbPhapLuatID = VBPhapLuat.Id

3.2. GIAO DIỆN

Hình 1: cửa sổ đăng nhập

Hình 2: hiển thị khi đăng nhập tài khoản không chính xác

16
Hình 3: giao diện vào cửa sổ chính

Hình 4: giao diện quản lý dịch bệnh


3.2.1: code
Core
3.2.1.1 RelayComand.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

17
namespace QuanLyKho.Core
{
class RelayCommand : ICommand
{
private readonly Action<object> _execute;
private readonly Func<object, bool> _canExecute;

public event EventHandler CanExecuteChanged


{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public RelayCommand(Action<object> execute, Func<object, bool>
canExecute = null)
{
_execute = execute;
_canExecute = canExecute;
}
public bool CanExecute(object parameter) => _canExecute == null ||
_canExecute(parameter);
public void Execute(object parameter) => _execute(parameter);
}
}

3.2.2 Model
3.2.2.1: Epidemic.cs
using QuanLyKho.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyKho.Model
{
public partial class Epidemic: BaseViewModel
{
private string _DisplayName01;
public string DisplayName01 { get => _DisplayName01; set { _DisplayName01 =
value; OnPropertyChanged(); } }

private string _DisplayName02;


public string DisplayName02 { get => _DisplayName02; set { _DisplayName02 =
value; OnPropertyChanged(); } }

private string _DisplayName03;


public string DisplayName03 { get => _DisplayName03; set { _DisplayName03 =
value; OnPropertyChanged(); } }

private string _DisplayName04;


public string DisplayName04 { get => _DisplayName04; set { _DisplayName04 =
value; OnPropertyChanged(); } }

private string _DisplayName05;


public string Displ
18
3.2.2.2:LegaDocument.cs
using QuanLyKho.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyKho.Model
{
public partial class LegalDocument: BaseViewModel
{
private string _DisplayName;
public string DisplayName { get => _DisplayName; set { _DisplayName =
value; OnPropertyChanged(); } }

private string _Quantity;


public string Quantity { get => _Quantity; set { _Quantity = value;
OnPropertyChanged(); } }
private int _Id;
public int Id { get => _Id; set { _Id = value;
OnPropertyChanged(); } }

public LegalDocument() { }

public LegalDocument(int _id, string _name, string _amount)


{
Id = _id;
DisplayName = _name;
Quantity = _amount;
}
}

}
3.2.2.3 Stactical.cs
using QuanLyKho.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyKho.Model
{
public partial class Statistical : BaseViewModel
{
private string _DisplayName;
public string DisplayName { get => _DisplayName; set { _DisplayName =
value; OnPropertyChanged(); } }

19
private int _Quantity;
public int Quantity { get => _Quantity; set { _Quantity = value;
OnPropertyChanged(); } }
private int _Id;
public int Id { get => _Id; set { _Id = value;
OnPropertyChanged(); } }

public Statistical() { }

public Statistical(int _id, string _name, int _amount)


{
Id = _id;
DisplayName = _name;
Quantity = _amount;
}
}
}
3.2.3 ViewModel
3.2.3.1: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;

20
}

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; }
}
}
}
3.2.3.2 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;

21
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;

22
}

return parent;
}
}
}
3.2.3.3 EpidemicViewModel.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;
}
}
);

23
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;
}
}
}
3.2.3.4 HomeViewModel.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyKho.ViewModel
{
class HomeViewModel : BaseViewModel
{

24
}
3.2.3.5 LegalDocumentViewModel.cs
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 LegalDocumentViewModel: BaseViewModel
{
private ObservableCollection<LegalDocument> _List = new
ObservableCollection<LegalDocument>();
public ObservableCollection<LegalDocument> List { get => _List; set { _List = value;
OnPropertyChanged(); } }

private string _DisplayName;


public string DisplayName { get => _DisplayName; set { _DisplayName = value;
OnPropertyChanged(); } }

private string _Quantity;


public string Quantity { get => _Quantity; set { _Quantity = value; OnPropertyChanged(); } }

public ICommand AddCommand { get; set; }


public ICommand DeleteCommand { get; set; }
public ICommand EditCommand { get; set; }

private LegalDocument _SelectedItem;


public LegalDocument SelectedItem { get => _SelectedItem;
set { _SelectedItem = value;
OnPropertyChanged();
if (SelectedItem != null)
{
DisplayName = SelectedItem.DisplayName;
Quantity = SelectedItem.Quantity;
}
}
}
public LegalDocumentViewModel()
{
AddCommand = new RelayCommand<object>((p) =>
{
if (DisplayName == null || Quantity == null) return false;
return true;
}, (p) => {
List.Add(new LegalDocument(List.Count + 1, DisplayName, Quantity));
});

DeleteCommand = new RelayCommand<object>((p) =>


{
25
return true;
}, (p) => {
List.Remove(SelectedItem);
for(int i = 0; i < List.Count; i++)
{
List[i].Id = i + 1;
}
});

EditCommand = new RelayCommand<object>((p) =>


{
return true;
}, (p) => {
SelectedItem.DisplayName = DisplayName;
SelectedItem.Quantity = Quantity;
});
}
}
}
3.2.3.6 LoginViewModel.cs
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 LegalDocumentViewModel: BaseViewModel
{
private ObservableCollection<LegalDocument> _List = new
ObservableCollection<LegalDocument>();
public ObservableCollection<LegalDocument> List { get => _List; set
{ _List = value; OnPropertyChanged(); } }

private string _DisplayName;


public string DisplayName { get => _DisplayName; set { _DisplayName =
value; OnPropertyChanged(); } }

private string _Quantity;


public string Quantity { get => _Quantity; set { _Quantity = value;
OnPropertyChanged(); } }

public ICommand AddCommand { get; set; }


public ICommand DeleteCommand { get; set; }
public ICommand EditCommand { get; set; }

private LegalDocument _SelectedItem;


public LegalDocument SelectedItem { get => _SelectedItem;
set { _SelectedItem = value;
OnPropertyChanged();
26
if (SelectedItem != null)
{
DisplayName = SelectedItem.DisplayName;
Quantity = SelectedItem.Quantity;
}
}
}
public LegalDocumentViewModel()
{
AddCommand = new RelayCommand<object>((p) =>
{
if (DisplayName == null || Quantity == null) return false;
return true;
}, (p) => {
List.Add(new LegalDocument(List.Count + 1, DisplayName,
Quantity));
});

DeleteCommand = new RelayCommand<object>((p) =>


{
return true;
}, (p) => {
List.Remove(SelectedItem);
for(int i = 0; i < List.Count; i++)
{
List[i].Id = i + 1;
}
});

EditCommand = new RelayCommand<object>((p) =>


{
return true;
}, (p) => {
SelectedItem.DisplayName = DisplayName;
SelectedItem.Quantity = Quantity;
});
}
}
}
3.2.3.7 MainViewModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using QuanLyKho.View;
using System.Windows.Media.Media3D;
using QuanLyKho.ViewModel;
using QuanLyKho.Core;
using System.Security.Cryptography.X509Certificates;

27
namespace QuanLyKho.ViewModel
{
public class MainViewModel : BaseViewModel
{
public object _currentView;
public object CurrentView
{
get { return _currentView; }
set { _currentView = value; OnPropertyChanged(); }
}

public ICommand LoadedWindowCommand { get; set; }


public ICommand HomeViewCommand { get; set; }
public ICommand EpidemicViewCommand { get; set; }
public ICommand StactisticalViewCommand { get; set; }
public ICommand LegalDocumentViewCommand { get; set; }

public void Home(object obj) => CurrentView = new HomeViewModel();

public bool Isloaded = false;


public MainViewModel()
{

//if (!Isloaded)
//{
// Isloaded = true;
// LoginWindow loginWindow = new LoginWindow();
// loginWindow.ShowDialog();
//}

LoadedWindowCommand = new RelayCommand<Window>((p) => { return


true; }, (p) => {
Isloaded = true;
if (p == null)
return;
p.Hide();
LoginWindow loginWindow = new LoginWindow();
loginWindow.ShowDialog();

if (loginWindow.DataContext == null)
return;

var loginVM = loginWindow.DataContext as LoginViewModel;

if (loginVM.IsLogin)
{
p.Show();
}
else
{
p.Close();

28
}
}
);

HomeViewCommand = new RelayCommand(Home);


EpidemicViewCommand = new RelayCommand<object>((p) => { return
true; }, (p) =>{ Epidemic ep =new Epidemic(); ep.ShowDialog();} );
StactisticalViewCommand = new RelayCommand<object>((p) => { return
true; }, (p) => { Statistical st = new Statistical(); st.ShowDialog(); });

LegalDocumentViewCommand = new RelayCommand<object>((p) => {


return true; }, (p) => { LegalDocument ld = new LegalDocument();
ld.ShowDialog(); });

// Startup Page
CurrentView = new HomeViewModel();
}
}
}
3.2.3.8:StatiscalViewModel.cs
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 StatisticalViewModel: BaseViewModel
{
private ObservableCollection<Statistical> _List = new
ObservableCollection<Statistical>();
public ObservableCollection<Statistical> List { get => _List; set
{ _List = value; OnPropertyChanged(); } }

private string _DisplayName;


public string DisplayName { get => _DisplayName; set { _DisplayName =
value; OnPropertyChanged(); } }

private int _Quantity;


public int Quantity { get => _Quantity; set { _Quantity = value;
OnPropertyChanged(); } }

public ICommand AddCommand { get; set; }


public ICommand DeleteCommand { get; set; }
public ICommand EditCommand { get; set; }

private Statistical _SelectedItem;


public Statistical SelectedItem { get => _SelectedItem;

29
set { _SelectedItem = value;
OnPropertyChanged();
if (SelectedItem != null)
{
DisplayName = SelectedItem.DisplayName;
Quantity = SelectedItem.Quantity;
}
}
}
public StatisticalViewModel()
{
AddCommand = new RelayCommand<object>((p) =>
{
if (DisplayName == null || Quantity == 0) return true;
return true;
}, (p) => {
List.Add(new Statistical(List.Count + 1, DisplayName,
Quantity));
});

DeleteCommand = new RelayCommand<object>((p) =>


{
return true;
}, (p) => {
List.Remove(SelectedItem);
for (int i = 0; i < List.Count; i++)
{
List[i].Id = i + 1;
}
});

EditCommand = new RelayCommand<object>((p) =>


{
return true;
}, (p) => {
SelectedItem.DisplayName = DisplayName;
SelectedItem.Quantity = Quantity;
});
}
}
}
VIEW
3.2.3.9 Epidemic.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;

30
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace QuanLyKho.View
{
/// <summary>
/// Interaction logic for Epidemic.xaml
/// </summary>
public partial class Epidemic : Window
{
public Epidemic()
{
InitializeComponent();
}
3.2.3.9 Epidemic.xaml
<Window x:Class="QuanLyKho.View.Epidemic"
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.View"
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="epidemic"
DataContext="{StaticResource EpidemicVM}"
Title="Quản lý dịch bệnh" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title,
ElementName=epidemic}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
31
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<materialDesign:Card Grid.Row="0" >
<WrapPanel>
<TextBox Text="{Binding DisplayName01}" Margin="5 5 15 5"
materialDesign:HintAssist.Hint="Tên Dịch"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding DisplayName02}" Margin="5"
materialDesign:HintAssist.Hint="Triệu chứng"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding DisplayName03}" Margin="5"
materialDesign:HintAssist.Hint="Chuẩn đoán ổ Dịch"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding DisplayName04}" Margin="5"
materialDesign:HintAssist.Hint="Thông tin ổ dịch"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding DisplayName05}" Margin="5"
materialDesign:HintAssist.Hint="Tiêm Phòng"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" />
<TextBox Text="{Binding DisplayName06}" Margin="5"
materialDesign:HintAssist.Hint="Bản đồ"
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">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding
SelectedItem,Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="Id"
DisplayMemberBinding="{Binding Id }"></GridViewColumn>
<GridViewColumn Header="Tên Dịch"
DisplayMemberBinding="{Binding DisplayName01 }"></GridViewColumn>
<GridViewColumn Header="Tên Triệu chứng"
DisplayMemberBinding="{Binding DisplayName02 }"></GridViewColumn>
<GridViewColumn Header="Chuẩn Đoán ổ dịch"
DisplayMemberBinding="{Binding DisplayName03 }"></GridViewColumn>

32
<GridViewColumn Header="Thông tin ổ dịch"
DisplayMemberBinding="{Binding DisplayName04 }"></GridViewColumn>
<GridViewColumn Header="Tiêm phòng"
DisplayMemberBinding="{Binding DisplayName05 }"></GridViewColumn>
<GridViewColumn Header="Bản đồ"
DisplayMemberBinding="{Binding DisplayName06 }"></GridViewColumn>

</GridView>
</ListView.View>
</ListView>
</materialDesign:Card>
</Grid>

</Grid>
</Window>
mic.xaml
3.2.3.10 LegalDocument.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.Shapes;

namespace QuanLyKho.View
{
/// <summary>
/// Interaction logic for LegalDocument.xaml
/// </summary>
public partial class LegalDocument : Window
{
public ICommand AddCommand { get; set; }
public LegalDocument()
{
InitializeComponent();
}
}
}

3.2.3.10 LegalDocument.xaml
<Window x:Class="QuanLyKho.View.LegalDocument"
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"

33
xmlns:local="clr-namespace:QuanLyKho.View"
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="legalDocument"
DataContext="{StaticResource LegalDocumentVM}"
Title="Văn bản pháp luật" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title,
ElementName=legalDocument}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<materialDesign:Card Grid.Row="0" Margin="5" >
<WrapPanel>
<TextBox Text="{Binding DisplayName}"
materialDesign:HintAssist.Hint="Tên Văn Bản"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" Width="100" />
<TextBox Text="{Binding Quantity}"
materialDesign:HintAssist.Hint="Link văn bản"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" Width="100" />

</WrapPanel>

</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm"
Margin="5" Width="100" ></Button>

34
<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" Width="auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding
SelectedItem,Mode=OneWayToSource}">
<ListView.View>
<GridView>
<GridViewColumn Header="STT"
DisplayMemberBinding="{Binding Id }"></GridViewColumn>
<GridViewColumn Width="200" Header="Tên văn bản"
DisplayMemberBinding="{Binding DisplayName }"></GridViewColumn>
<GridViewColumn Header="Đường link văn bản"
DisplayMemberBinding="{Binding Quantity }"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</materialDesign:Card>
</Grid>

</Grid>
</Window>
3.2.3.11:statiscal.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.View
{
/// <summary>
/// Interaction logic for Statistical.xaml
/// </summary>
public partial class Statistical : Window
{
public Statistical()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)


35
{

private void TextBox_TextChanged(object sender, TextChangedEventArgs


e)
{

private void ListView_SelectionChanged(object sender,


SelectionChangedEventArgs e)
{

private void TextBox_TextChanged_1(object sender, TextChangedEventArgs


e)
{

}
}
}

3.2.3.11:statistical.xaml
<Window x:Class="QuanLyKho.View.Statistical"
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.View"
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="statistical"
DataContext="{StaticResource StatisticalVM}"
Title="Bảng thống kê" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition></RowDefinition>

36
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<uc:ControlBarUC Tag="{Binding Title,
ElementName=statistical}"></uc:ControlBarUC>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<materialDesign:Card Grid.Row="0" Margin="5" >
<WrapPanel>
<TextBox Text="{Binding DisplayName}"
materialDesign:HintAssist.Hint="Tên thống Kê"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" Width="400"
TextChanged="TextBox_TextChanged" />
<TextBox Text="{Binding Quantity}"
materialDesign:HintAssist.Hint="Số Lượng"
Style="{StaticResource
MaterialDesignFloatingHintTextBox}" Width="100"
TextChanged="TextBox_TextChanged_1" />
</WrapPanel>
</materialDesign:Card>
<materialDesign:Card Grid.Row="1" Margin="5">
<WrapPanel>
<Button Command="{Binding AddCommand}" Content="Thêm"
Margin="5" Width="100" Click="Button_Click" ></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" Width="auto">
<ListView ItemsSource="{Binding List}" SelectedItem="{Binding
SelectedItem,Mode=OneWayToSource}"
SelectionChanged="ListView_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Header="STT"
DisplayMemberBinding="{Binding Id }"></GridViewColumn>
<GridViewColumn Header="Thống Kê báo cáo"
DisplayMemberBinding="{Binding DisplayName}"></GridViewColumn>
<GridViewColumn Header="Số Lượng"
DisplayMemberBinding="{Binding Quantity}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</materialDesign:Card>
</Grid>

37
</Grid>
</Window>
3.2.4.2 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>
App.xaml

3.2.4.2 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
{
}
}
3.2.5.1 Mainwindow.xaml
<Window x:Class="QuanLyKho.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

38
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ý cơ sở dữ liệu chăn nuôi" Height="600"
Width="1024">
<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>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Grid Grid.Column="1" Grid.Row="1" Background="#FFCFCFCF">


<ScrollViewer Margin="0,0,0,-32">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
39
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>

<Grid Grid.Column="0">

</Grid>

</Grid>
</ScrollViewer>
</Grid>

<Grid Grid.Row="1">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="LightGray" Offset="1"/>
<GradientStop Color="#FFE6E6E6"/>
</LinearGradientBrush>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Effect>
<DropShadowEffect BlurRadius="20" Color="#FFDEDEDE"
RenderingBias="Quality" ShadowDepth="1"/>
</Grid.Effect>

<Grid Background="#FFA46FE4">
<TextBlock Text="TRANG QUẢN LÝ"
HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="WS Simple
Gallifreyan" Foreground="Black" FontSize="16"/>
</Grid>

<StackPanel Grid.Row="1">
<Button Margin="10" Background="#FF8522BD"
BorderBrush="#FF8522BD">
<Grid Width="150">
<materialDesign:PackIcon Kind="ViewDashboard"
VerticalAlignment="Center"/>
<TextBlock HorizontalAlignment="Center"
Text="TRANG CHỦ" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

<Button Margin="10" Background="#FF8522BD"


BorderBrush="#FF8522BD">
<Grid Width="150">
<materialDesign:PackIcon Kind="Account"
VerticalAlignment="Center"/>

40
<TextBlock HorizontalAlignment="Center" Text="TÀI
KHOẢN" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

<Button Command="{Binding StactisticalViewCommand}"


Margin="10" Background="#FF8522BD" BorderBrush="#FF8522BD">
<Grid Width="150">
<materialDesign:PackIcon Kind="ContentPaste"
VerticalAlignment="Center"/>
<TextBlock HorizontalAlignment="Center"
Text="THỐNG KÊ" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

<Button Command="{Binding EpidemicViewCommand}"


Margin="10" Background="#FF8522BD" BorderBrush="#FF8522BD">
<Grid Width="150">
<materialDesign:PackIcon Kind="Drupal" />
<TextBlock HorizontalAlignment="Center" Text="DỊCH
BỆNH" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

<Button Command="{Binding LegalDocumentViewCommand}"


Margin="10" Background="#FF8522BD" BorderBrush="#FF8522BD">
<Grid Width="150">
<materialDesign:PackIcon Kind="ImageFilter" />
<TextBlock HorizontalAlignment="Center" Text="PHÁP
LUẬT" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

<Button Margin="10" Background="#FF8522BD"


BorderBrush="#FF8522BD">
<Grid Width="150">
<materialDesign:PackIcon Kind="Settings"
VerticalAlignment="Center"/>
<TextBlock HorizontalAlignment="Center" Text="CẤU
HÌNH" FontFamily="Champagne &amp; Limousines" Height="17"
VerticalAlignment="Top"/>
</Grid>
</Button>
</StackPanel>
</Grid>
</Grid>
</Grid>
</Grid>
</Window>
3.2.5.2 MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
41
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();
}
}

3.2.6.1 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: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"
42
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"

43
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>
</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>

44
</Grid>
</materialDesign:Card>
</Grid>
</Window>

3.2.6.2 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();
}
}
}

KẾT LUẬN

Dựa trên quá trình thiết kế CSDL chăn nuôi, bản báo cáo này đã hoàn
thành các công việc cơ bản như phân tích yêu cầu, thiết kế mô hình dữ liệu, đặc
tả các chức năng của hệ thống và xây dựng sơ đồ DFD. Qua đó, hi vọng rằng hệ
thống CSDL chăn nuôi được thiết kế sẽ giúp cho các cơ quan, tổ chức trong lĩnh
vực chăn nuôi có thể quản lý, theo dõi và nắm bắt thông tin chung về chăn nuôi
như tình hình dịch bênh, văn bản pháp luât, các cơ sở, vùng chăn nuôi.

45
Tuy nhiên, đây chỉ là một bài tập lớn trên giảng đường học tập, do đó hệ
thống CSDL chăn nuôi còn cần được phát triển và hoàn thiện hơn trong thực tế
để đáp ứng nhu cầu sử dụng của cơ quan nhà nước, doanh nghiệp và mang lại
hiệu quả kinh tế cao nhất.

TÀI LIỆU THAM KHẢO


 https://howkteam.vn/
 https://www.w3schools.com/
 https://lytuong.net/mo-hinh-luong-du-lieu-dfd/
 https://viblo.asia/p/phan-tich-yeu-cau-phan-mem-gDVK2WRvZLj

46

You might also like