



















Preview text:
lOMoAR cPSD| 60797905
Báo Cáo Kết Thúc Môn Học Lập Trình .NET Với C# 1.Yêu cầu:
Xây dựng ứng dụng Windows Forms phần mềm quản lí sinh viên với chức năng cập nhật danh sách
học sinh, danh sách giáo viên, danh sách môn học, danh sách học kỳ, điểm, lớp, và chức năng đăng
nhập, đăng ký, thay đổi mật khẩu, quên mật khẩu, tìm kiếm, in thông tin các đối tượng được chọn.
Chức năng cập nhập bao gồm các chức năng: thêm, lưu, sửa, xoá các đối tượng cần cập nhật. Một
học sinh có các thông tin: mã học sinh, tên học sinh, ngày sinh, giới tính, địa chỉ, khối, niên khoá, mã
lớp. Một giáo viên có các thông tin: mã giáo viên, tên giáo viên, giới tính, địa chỉ, trình độ, tên môn
học. một môn học có các thông tin: tên môn học, hệ số môn học. Một đối tượng điểm có các thông
tin: mã điểm, mã học sinh, tên môn học, mã học kì, điểm miệng, điểm 15 phút, điểm 1 tiết, điểm thi,
điểm trung bình môn .Một lớp có các thông tin: mã lớp, tên lớp, giáo viên chủ nhiệm, tên ban. Chức
năng đăng nhập bao gồm các chức năng: đăng nhập vào ứng dụng, đăng kí tài khoản nếu như chưa có
tài khoản đăng nhập, thay đổi mật khẩu nếu muốn và tìm lại mật khẩu nếu như quên mật khẩu. Chức
năng tìm kiếm bao gồm các chức năng; tìm kiếm thông tin học sinh theo tuỳ chọn mã học sinh, tên
học sinh và xuất ra tất cả thông tin của đối tượng được chọn. Chức năng in bao gồm các chức năng:
tìm kiếm và in ra tất cả thông tin học sinh được chọn. 2. Data base:
2.1 Cơ sở dữ liệu mô hình: 2.2 Bảng đặc tả lOMoAR cPSD| 60797905
B 愃ऀ ng 1: B 愃ऀ ng Học Sinh
B 愃ऀ ng 2: B 愃ऀ ng Lớp
B 愃ऀ ng 3: B 愃ऀ ng Điểm
B 愃ऀ ng 4: B 愃ऀ ng Học Kỳ lOMoAR cPSD| 60797905
B 愃ऀ ng 5: B 愃ऀ ng Môn Học
B 愃ऀ ng 6: B 愃ऀ ng Giáo Viên
B 愃ऀ ng 7: B 愃ऀ ng Đăng Nhập
3. chương trình➡Ứng dụng trong dự án lOMoAR cPSD| 60797905 3.1 Sử dụng giao diện
Giao diện Form frm_hocsinh.cs: lOMoAR cPSD| 60797905 Code: Class hocsinh.cs: using System;
using System.Collections.Generic; using
System.Linq; using System.Text; using System.Threading.Tasks; using
System.Data; using System.Data.SqlClient;
using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap { internal class cl_hocsinh { SqlConnection con; SqlCommand cmd; DataTable table;
Encoding encoding = Encoding.UTF8; public void moketnoi() {
con = new SqlConnection(@"Data Source = .\SQLEXPRESS; Initial Catalog =
QuanLyHocSinh; Trusted_Connection = yes"); con.Open(); }
public DataTable timkiemtheoten(string tenhs) { moketnoi(); string caulenh = ""; if (tenhs == "")
caulenh = "select * from HocSinh"; else
caulenh = "select * from HocSinh where TenHS like '%" + tenhs + "%'";
SqlCommand cmd = new SqlCommand(caulenh, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; }
public DataTable timkiemtheomahs(string mahs) { lOMoAR cPSD| 60797905 moketnoi(); string caulenh = ""; if (mahs == "")
caulenh = "select * from HocSinh"; else
caulenh = "select * from HocSinh where mahs like '%" + mahs + "%'";
SqlCommand cmd = new SqlCommand(caulenh, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; }
public void capnhat(string mahs, string tenhs, string ngaysinh, string gioitinh, string diachi, string khoi, string nienkhoa, string malop) { moketnoi();
string caulenh = "update hocsinh set mahs = '" + mahs + "', tenhs = N'" + tenhs + "', ngaysinh = '" + ngaysinh +
"', gioitinh = N'" + gioitinh + "', diachi = N'" + diachi + "', khoi = N'" + khoi + "', nienkhoa = '" + nienkhoa + "', malop = '"
+ malop + "' where mahs = '" + mahs + "' ";
SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); }
public void xoa(string mahs, string tenhs, string ngaysinh, string gioitinh, string diachi, string khoi, string nienkhoa, string malop) { moketnoi();
string caulenh = "delete from hocsinh where mahs = '" + mahs + "'";
SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); }
public void luu(string mahs, string tenhs, string ngaysinh, string gioitinh, string diachi, string khoi, string nienkhoa, string malop) { moketnoi();
string caulenh = "insert into hocsinh(mahs, tenhs, ngaysinh, gioitinh, diachi, khoi, nienkhoa, malop) values ('" +
mahs + "',N'" + tenhs + "','" + ngaysinh + "',N'" + gioitinh +
"',N'" + diachi + "',N'" + khoi + "','" + nienkhoa + "','" + malop + "')"; SqlCommand cmd = new
SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); } public DataTable gettable() { moketnoi();
SqlCommand cmd = new SqlCommand("select * from HocSinh", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; }
public DataTable gettable(string malop) { moketnoi(); string caulenh = ""; if (malop == "")
caulenh = "select * from Hocsinh"; else
caulenh = "select * from HocSinh where malop like '%" + malop + "%'";
SqlCommand cmd = new SqlCommand(caulenh, con); lOMoAR cPSD| 60797905
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; }
public DataSet gettabledataset() { moketnoi();
SqlCommand cmd = new SqlCommand("select * from HocSinh", con);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
da.Fill(ds,"Hocsinh"); return ds; }
public DataSet get_dataset(string tenhs) { moketnoi();
SqlCommand cmd = new SqlCommand("select * from HocSinh where TenHS like '%" + tenhs + "%'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
da.Fill(ds,"Hocsinh"); return ds; } } } Form frm_hocsinh.cs: using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using
System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap {
public partial class frm_hocsinh : Form { DataTable _table;
cl_hocsinh _hocsinh = new cl_hocsinh(); DataSet ds;
Encoding encoding = Encoding.UTF8; public frm_hocsinh() { InitializeComponent(); } public void xoabuocdulieu() {
txt_mahs.DataBindings.Clear(); txt_tenhs.DataBindings.Clear();
txt_ngaysinh.DataBindings.Clear(); txt_gioitinh.DataBindings.Clear();
txt_diachi.DataBindings.Clear(); txt_khoi.DataBindings.Clear();
txt_nienkhoa.DataBindings.Clear(); txt_malop.DataBindings.Clear(); } lOMoAR cPSD| 60797905 private void buocdulieu() {
txt_mahs.DataBindings.Add("Text", _table, "mahs"); txt_tenhs.DataBindings.Add("Text", _table,
"tenhs"); txt_ngaysinh.DataBindings.Add("Text", _table, "ngaysinh");
txt_gioitinh.DataBindings.Add("Text", _table, "gioitinh"); txt_diachi.DataBindings.Add("Text", _table, "diachi");
txt_khoi.DataBindings.Add("Text", _table, "khoi"); txt_nienkhoa.DataBindings.Add("Text", _table, "nienkhoa");
txt_malop.DataBindings.Add("Text", _table, "malop"); } public void loaddulieu() {
_table = _hocsinh.gettable(); dataGridView1.DataSource = _table; buocdulieu(); }
private void frm_hocsinh_Load(object sender, EventArgs e) { loaddulieu();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; cl_hocsinh cn = new cl_hocsinh();
DataTable _table = cn.gettable(cbb_mahs.Text);
cbb_mahs.DataSource = _table; dataGridView1.DataSource = _table;
cbb_mahs.DisplayMember = "TenLop"; cbb_mahs.ValueMember =
"Malop"; cbb_mahs.SelectedValue.ToString().Trim(); }
private void cmd_dau_Click(object sender, EventArgs e) {
this.BindingContext[_table].Position = 0; }
private void cmd_tien_Click(object sender, EventArgs e) {
this.BindingContext[_table].Position++; }
private void cmd_lui_Click(object sender, EventArgs e) {
this.BindingContext[_table].Position--; }
private void cmd_cuoi_Click(object sender, EventArgs e) {
int vtc = _table.Rows.Count - 1;
this.BindingContext[_table].Position = vtc; }
private void cmd_them_Click(object sender, EventArgs e) {
txt_mahs.Text = ""; txt_tenhs.Text = ""; txt_diachi.Text = "";
txt_gioitinh.Text = ""; txt_ngaysinh.Text = "";
txt_khoi.Text = ""; txt_nienkhoa.Text = ""; txt_malop.Text = ""; }
private void cmd_luu_Click(object sender, EventArgs e) {
if (txt_tenhs.Text==""||txt_nienkhoa.Text==""||txt_ngaysinh.Text==""||
txt_malop.Text==""||txt_mahs.Text==""||txt_khoi.Text==""||txt_gioitinh.Text==""|| txt_diachi.Text=="") {
MessageBox.Show("Thông tin không hợp lệ!", "Thông báo!"); lOMoAR cPSD| 60797905 } else {
DialogResult h = MessageBox.Show("Bạn có cập nhật mới dữ liệu này không?",
"Thông báo", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_hocsinh.luu(txt_mahs.Text, txt_tenhs.Text, txt_ngaysinh.Text, txt_gioitinh.Text, txt_diachi.Text,
txt_khoi.Text, txt_nienkhoa.Text, txt_malop.Text); xoabuocdulieu(); loaddulieu();
MessageBox.Show("Cập nhật thông tin thành công!", "Thông báo!"); } else {
MessageBox.Show("Cập nhật thông tin thất bại!", "Thông báo!"); } } }
private void cmd_huy_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn huỷ dữ liệu này không?",
"Thông báo", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
xoabuocdulieu(); loaddulieu(); } }
private void cmd_thoat_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn thoát ứng dụng này không?",
"Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) { this.Close(); } }
private void cmd_sua_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn cập nhật dữ liệu này không?",
"Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_hocsinh.capnhat(txt_mahs.Text, txt_tenhs.Text, txt_ngaysinh.Text, txt_gioitinh.Text,
txt_diachi.Text, txt_khoi.Text, txt_nienkhoa.Text, txt_malop.Text); xoabuocdulieu(); loaddulieu(); } }
private void cmd_xoa_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn xoá dữ liệu này không?",
"Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_hocsinh.xoa(txt_mahs.Text, txt_tenhs.Text, txt_ngaysinh.Text, txt_gioitinh.Text, txt_diachi.Text,
txt_khoi.Text, txt_nienkhoa.Text, txt_malop.Text); xoabuocdulieu(); loaddulieu(); } }
private void rdb_mahs_CheckedChanged(object sender, EventArgs e) lOMoAR cPSD| 60797905 {
if (rdb_mahs.Checked == true) {
cbb_mahs.BringToFront(); txt_tim.SendToBack(); } }
private void rdb_tenhs_CheckedChanged(object sender, EventArgs e) {
if (rdb_tenhs.Checked == true) {
cbb_mahs.SendToBack(); txt_tim.BringToFront(); } }
private void cmd_tim_Click(object sender, EventArgs e) {
if (rdb_mahs.Checked == true) {
cl_hocsinh cn = new cl_hocsinh(); DataTable dt =
cn.gettable(cbb_mahs.Text); dataGridView1.DataSource = dt; }
if(rdb_tenhs.Checked == true) {
cl_hocsinh cn = new cl_hocsinh();
DataTable dt = cn.timkiemtheoten(txt_tim.Text); dataGridView1.DataSource = dt; } } } }
Giao diện Form frm_lop.cs: CODE: Class lop.cs: using System; lOMoAR cPSD| 60797905
using System.Collections.Generic; using
System.Linq; using System.Text; using System.Threading.Tasks; using
System.Data; using System.Data.SqlClient;
using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap { internal class cl_lop { SqlConnection con; SqlCommand cmd; DataTable table;
Encoding encoding = Encoding.UTF8; public void moketnoi() {
con = new SqlConnection(@"Data Source = .\SQLEXPRESS; Initial Catalog =
QuanLyHocSinh; Trusted_Connection = yes"); con.Open(); }
public DataTable timkiemtheomalop(string malop) { moketnoi(); string caulenh = ""; if (malop == "")
caulenh = "select * from Lop"; else
caulenh = "select * from lop where malop like '%" + malop + "%'";
SqlCommand cmd = new SqlCommand(caulenh, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; }
public DataTable timkiemtheotenlop(string tenlop) { moketnoi(); string caulenh = ""; if (tenlop == "")
caulenh = "select * from Lop"; else
caulenh = "select * from Lop where tenhk like '%" + tenlop + "%'";
SqlCommand cmd = new SqlCommand(caulenh, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; }
public void capnhat(string malop, string tenlop, string gvcn, string tenban) { moketnoi();
string caulenh = "update lop set tenlop = N'" + tenlop + "', gvcn = N'" + gvcn + "', tenban = N'" + tenban + "'
where malop = '"+ malop+"'"; SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); }
public void xoa(string malop, string tenlop, string gvcn, string tenban) { moketnoi(); lOMoAR cPSD| 60797905
string caulenh = "delete from lop where malop = '" + malop + "'";
SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); }
public void luu(string malop, string tenlop, string GVCN, string tenban) { moketnoi();
string caulenh = "insert into lop(malop, tenlop, gvcn, tenban) values ('" + malop +
"',N'" + tenlop + "',N'" + GVCN + "',N'" + tenban + "')"; SqlCommand cmd = new
SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); } public DataTable gettable() { moketnoi();
SqlCommand cmd = new SqlCommand("select * from Lop", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; } } } Form frm_lop.cs: using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using
System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap {
public partial class frm_lop : Form {
DataTable _table; cl_lop _lop = new cl_lop(); DataSet ds;
Encoding encoding = Encoding.UTF8; public frm_lop() { InitializeComponent(); } public void xoabuocdulieu() {
txt_malop.DataBindings.Clear(); txt_tenlop.DataBindings.Clear();
txt_giaovien.DataBindings.Clear(); txt_tenban.DataBindings.Clear(); } private void buocdulieu() { lOMoAR cPSD| 60797905
txt_malop.DataBindings.Add("Text", _table, "Malop"); txt_tenlop.DataBindings.Add("Text", _table,
"tenlop"); txt_giaovien.DataBindings.Add("Text", _table, "GVCN"); txt_tenban.DataBindings.Add("Text", _table, "tenban"); } public void loaddulieu() {
_table = _lop.gettable(); dataGridView1.DataSource = _table; buocdulieu(); }
private void frm_lop_Load(object sender, EventArgs e) { loaddulieu();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; }
private void cmd_dau_Click(object sender, EventArgs e) {
this.BindingContext[_table].Position = 0; }
private void cmd_tien_Click(object sender, EventArgs e) {
this.BindingContext[_table].Position++; }
private void cmd_lui_Click(object sender, EventArgs e) {
this.BindingContext[_table].Position--; }
private void cmd_cuoi_Click(object sender, EventArgs e) {
int vtc = _table.Rows.Count - 1;
this.BindingContext[_table].Position = vtc; }
private void cmd_them_Click(object sender, EventArgs e) {
txt_malop.Text = ""; txt_tenlop.Text = ""; txt_giaovien.Text = ""; txt_tenban.Text = ""; }
private void cmd_luu_Click(object sender, EventArgs e) {
if(txt_giaovien.Text ==""||txt_malop.Text==""||txt_tenban.Text==""|| txt_tenlop.Text=="") {
MessageBox.Show("Thông tin không hợp lệ!", "Thông báo!"); } else {
DialogResult h = MessageBox.Show("Bạn có cập nhật mới dữ liệu này không?",
"Thông báo", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_lop.luu(txt_malop.Text, txt_tenlop.Text, txt_giaovien.Text, txt_tenban.Text);
xoabuocdulieu(); loaddulieu();
MessageBox.Show("Cập nhật thông tin thành công!", "Thông báo!"); } else {
MessageBox.Show("Cập nhật thông tin thất bại!", "Thông báo!"); lOMoAR cPSD| 60797905 } } }
private void cmd_thoat_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có muốn đóng ứng dụng không?", "Thông báo",
MessageBoxButtons.OKCancel); if (h == DialogResult.OK) { this.Close(); } }
private void cmd_sua_Click(object sender, EventArgs e) {
if (txt_giaovien.Text ==""|| txt_malop.Text == "" || txt_tenlop.Text==""|| txt_tenban.Text=="") {
MessageBox.Show("Thông tin cập nhật không hợp lệ!", "Thông báo!"); } else {
DialogResult h = MessageBox.Show("Bạn có chắc muốn cập nhật dữ liệu này không?", "Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_lop.capnhat(txt_malop.Text, txt_tenlop.Text, txt_giaovien.Text, txt_tenban.Text);
xoabuocdulieu(); loaddulieu();
MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo!"); } else {
MessageBox.Show("Cập nhật dữ liệu thất bại!", "Thông báo!"); } } }
private void cmd_xoa_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn xoá dữ liệu này không?",
"Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_lop.xoa(txt_malop.Text, txt_tenlop.Text, txt_giaovien.Text, txt_tenban.Text);
xoabuocdulieu(); loaddulieu();
MessageBox.Show("Xoá dữ liệu thành công!", "Thông báo!"); } else {
MessageBox.Show("Xoá dữ liệu thất bại!", "Thông báo!"); } }
private void cmd_huy_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn huỷ những thông tin này không?", "Thông
báo!",MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
xoabuocdulieu(); loaddulieu(); } }
private void cmd_tim_Click(object sender, EventArgs e) { lOMoAR cPSD| 60797905 if (rdb_malop.Checked) { cl_lop cn = new cl_lop();
DataTable dt = cn.timkiemtheomalop(txt_tim.Text); dataGridView1.DataSource = dt; } else if (rdb_tenlop.Checked) { cl_lop cn = new cl_lop();
DataTable dt = cn.timkiemtheotenlop(txt_tim.Text); dataGridView1.DataSource = dt; } } } }
Giao diện Form frm_xylydiem.cs: CODE: Class cl_xulydiem.cs: using System;
using System.Collections.Generic; using
System.Linq; using System.Text; using System.Threading.Tasks; using
System.Data; using System.Data.SqlClient;
using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap { internal class cl_xulydiem { SqlConnection con; SqlCommand cmd; DataTable table;
Encoding encoding = Encoding.UTF8; public void moketnoi() {
con = new SqlConnection(@"Data Source = .\SQLEXPRESS; Initial Catalog = lOMoAR cPSD| 60797905
QuanLyHocSinh; Trusted_Connection = yes"); con.Open(); }
public void xoa(string madiem, string mahs, string tenmh, string mahk, string diemmieng, string diem15phut,
string diem1tiet, string diemthi, string dtbmon) { moketnoi();
string caulenh = "delete from diem where madiem = '" + madiem + "'";
SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); }
public void sua(string madiem, string mahs, string tenmh, string mahk, string diemmieng, string diem15phut,
string diem1tiet, string diemthi, string dtbmon) { moketnoi();
string caulenh = "update diem set mahs = '" + mahs + "', tenmh = '" + tenmh + "', mahk = '" + mahk + "',
diemmieng = '" + diemmieng + "', diem15phut = '" + diem15phut + "', diem1tiet = '" + diem1tiet + "', diemthi = '" +
diemthi + "', dtbmon = '" + dtbmon + "' where madiem = '"+ madiem+"'";
SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); }
public void luu(string madiem, string mahs, string tenmh, string mahk, string diemmieng, string diem15phut,
string diem1tiet, string diemthi, string dtbmon) { moketnoi();
string caulenh = "insert into diem(madiem, mahs, tenmh, mahk, diemmieng, diem15phut, diem1tiet, diemthi,
dtbmon) values ('" + madiem + "','" + mahs + "','" + tenmh + "','" + mahk + "','" + diemmieng + "','" + diem15phut +
"','" + diem1tiet + "','" + diemthi + "','" + dtbmon + "')";
SqlCommand cmd = new SqlCommand(caulenh, con); cmd.ExecuteNonQuery(); } public DataTable gettable() { moketnoi();
SqlCommand cmd = new SqlCommand("select * from diem", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable(); da.Fill(dt); return dt; } } } Form frm_xulydiem.cs: using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using
System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap {
public partial class frm_xulydiem : Form lOMoAR cPSD| 60797905 { DataTable _table;
cl_xulydiem _xulydiem = new cl_xulydiem(); DataSet ds;
Encoding encoding = Encoding.UTF8; public void xoabuocdulieu() {
txt_madiem.DataBindings.Clear(); txt_mahs.DataBindings.Clear();
txt_tenmh.DataBindings.Clear(); txt_mahk.DataBindings.Clear();
txt_diemmieng.DataBindings.Clear(); txt_diem15p.DataBindings.Clear();
txt_diem1tiet.DataBindings.Clear(); txt_diemthi.DataBindings.Clear();
txt_diemtrungbinh.DataBindings.Clear(); } private void buocdulieu() {
txt_madiem.DataBindings.Add("Text", _table, "Madiem"); txt_mahs.DataBindings.Add("Text", _table,
"mahs"); txt_tenmh.DataBindings.Add("Text", _table, "tenmh"); txt_mahk.DataBindings.Add("Text",
_table, "mahk"); txt_diemmieng.DataBindings.Add("Text", _table, "diemmieng");
txt_diem15p.DataBindings.Add("Text", _table, "diem15phut"); txt_diem1tiet.DataBindings.Add("Text", _table,
"diem1tiet"); txt_diemthi.DataBindings.Add("Text", _table, "diemthi");
txt_diemtrungbinh.DataBindings.Add("Text", _table, "dtbmon"); } public void loaddulieu() {
_table = _xulydiem.gettable(); dataGridView1.DataSource = _table; buocdulieu(); } public frm_xulydiem() { InitializeComponent(); }
private void frm_xulydiem_Load(object sender, EventArgs e) { loaddulieu();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; }
private void cmd_thoat_Click_1(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn thoát không?", "Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) { this.Close(); } }
private void cmd_dau_Click_1(object sender, EventArgs e) {
this.BindingContext[_table].Position = 0; }
private void cmd_lui_Click_1(object sender, EventArgs e) {
this.BindingContext[_table].Position--; }
private void cmd_tien_Click_1(object sender, EventArgs e) lOMoAR cPSD| 60797905 {
this.BindingContext[_table].Position++; }
private void cmd_cuoi_Click_1(object sender, EventArgs e) {
int vtc = _table.Rows.Count - 1;
this.BindingContext[_table].Position = vtc; }
private void cmd_them_Click(object sender, EventArgs e) {
txt_madiem.Text = ""; txt_mahs.Text =
""; txt_tenmh.Text = ""; txt_mahk.Text
= ""; txt_diemmieng.Text = "";
txt_diem15p.Text = ""; txt_diem1tiet.Text = ""; txt_diemthi.Text = ""; txt_diemtrungbinh.Text = ""; }
private void cmd_luu_Click(object sender, EventArgs e) {
if (txt_diem15p.Text == "" || txt_diem1tiet.Text == "" || txt_diemmieng.Text == "" || txt_diemthi.Text == "" ||
txt_madiem.Text == "" || txt_mahk.Text == "" || txt_mahs.Text == "" || txt_tenmh.Text == "") {
MessageBox.Show("Thông tin điểm không hợp lệ!", "Thông báo!"); } else {
DialogResult h = MessageBox.Show("Bạn có chắc muốn thêm dữ liệu này không?",
"Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
double diemmieng = Convert.ToDouble(txt_diemmieng.Text); double
diem15phut = Convert.ToDouble(txt_diem15p.Text); double diem1tiet =
Convert.ToDouble(txt_diem1tiet.Text); double diemthi =
Convert.ToDouble(txt_diemthi.Text);
double diemtrungbinh = Math.Round(((diemmieng + diem15phut + (diem1tiet * 2) + (diemthi * 3)) / 7), 1);
txt_diemtrungbinh.Text= diemtrungbinh.ToString();
_xulydiem.luu(txt_madiem.Text, txt_mahs.Text, txt_tenmh.Text, txt_mahk.Text, txt_diemmieng.Text,
txt_diem15p.Text, txt_diem1tiet.Text, txt_diemthi.Text, txt_diemtrungbinh.Text); xoabuocdulieu(); loaddulieu();
MessageBox.Show("Thêm thông tin điểm thành công!", "Thông báo!"); } else {
MessageBox.Show("Thêm dữ liệu thất bại!", "Thông báo"); } } }
private void cmd_huy_Click(object sender, EventArgs e) {
DialogResult dialogResult = MessageBox.Show("Bạn có muốn huỷ thông tin?", "Thông báo!",
MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) {
txt_madiem.Text = ""; txt_mahs.Text =
""; txt_tenmh.Text = ""; txt_mahk.Text lOMoAR cPSD| 60797905
= ""; txt_diemmieng.Text = "";
txt_diem15p.Text = ""; txt_diem1tiet.Text = ""; txt_diemthi.Text = ""; txt_diemtrungbinh.Text = ""; } }
private void cmd_sua_Click(object sender, EventArgs e) {
if (txt_diem15p.Text == "" || txt_diem1tiet.Text == "" || txt_diemmieng.Text == "" || txt_diemthi.Text == "" ||
txt_madiem.Text == "" || txt_mahk.Text == "" || txt_mahs.Text == "" || txt_tenmh.Text == "") {
MessageBox.Show("Thông tin điểm không hợp lệ!", "Thông báo!"); } else {
DialogResult h = MessageBox.Show("Bạn có chắc muốn cập nhật dữ liệu này không?", "Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
double diemmieng = Convert.ToDouble(txt_diemmieng.Text); double
diem15phut = Convert.ToDouble(txt_diem15p.Text); double diem1tiet =
Convert.ToDouble(txt_diem1tiet.Text); double diemthi =
Convert.ToDouble(txt_diemthi.Text);
double diemtrungbinh = Math.Round(((diemmieng + diem15phut + (diem1tiet * 2) + (diemthi * 3)) / 7), 1);
txt_diemtrungbinh.Text = diemtrungbinh.ToString();
_xulydiem.sua(txt_madiem.Text, txt_mahs.Text, txt_tenmh.Text, txt_mahk.Text, txt_diemmieng.Text,
txt_diem15p.Text, txt_diem1tiet.Text, txt_diemthi.Text, txt_diemtrungbinh.Text); xoabuocdulieu(); loaddulieu();
MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo!"); } else
MessageBox.Show("Cập nhật dữ liệu không thành công!", "Thông báo!"); } }
private void cmd_xoa_Click(object sender, EventArgs e) {
DialogResult h = MessageBox.Show("Bạn có chắc muốn xoá dữ liệu này không?",
"Thông báo!", MessageBoxButtons.OKCancel); if (h == DialogResult.OK) {
_xulydiem.xoa(txt_madiem.Text, txt_mahs.Text, txt_tenmh.Text, txt_mahk.Text, txt_diemmieng.Text,
txt_diem15p.Text, txt_diem1tiet.Text, txt_diemthi.Text, txt_diemtrungbinh.Text);
xoabuocdulieu(); loaddulieu();
MessageBox.Show("Xoá dữ liệu thành công!", "Thông báo!"); } else
MessageBox.Show("Xoá dữ liệu không thành công!", "Thông báo!"); }
private void cmd_diemtb_Click(object sender, EventArgs e) {
if (txt_diem15p.Text == "" || txt_diem1tiet.Text == "" || txt_diemmieng.Text == "" || txt_diemthi.Text == "" ||
txt_madiem.Text == "" || txt_mahk.Text == "" || txt_mahs.Text == "" || txt_tenmh.Text == "") { lOMoAR cPSD| 60797905
MessageBox.Show("Thông tin điểm không hợp lệ!", "Thông báo!"); } else {
double diem15p = Convert.ToDouble(txt_diem15p.Text); double
diemmieng = Convert.ToDouble(txt_diemmieng.Text); double diem1tiet =
Convert.ToDouble(txt_diem1tiet.Text); double diemthi =
Convert.ToDouble(txt_diemthi.Text);
double diemtrungbinh = ((diem15p + diemmieng) / 2 + diem1tiet * 2 + diemthi * 3) % 5;
txt_diemtrungbinh.Text = "" + diemtrungbinh;
_xulydiem.sua(txt_madiem.Text, txt_mahs.Text, txt_tenmh.Text, txt_mahk.Text, txt_diemmieng.Text,
txt_diem15p.Text, txt_diem1tiet.Text, txt_diemthi.Text, txt_diemtrungbinh.Text);
xoabuocdulieu(); loaddulieu(); } } } }
Giao diện Form frm_hocky.cs: CODE: Class cl_hocki.cs: using System;
using System.Collections.Generic; using
System.Linq; using System.Text; using System.Threading.Tasks; using
System.Data; using System.Data.SqlClient;
using System.Data.SqlTypes; using System.Data.Sql; namespace vidu_dangnhap { internal class cl_hocki {