0% found this document useful (0 votes)
3 views3 pages

Code

The document is a C# Windows Forms application for managing student classes and student details. It includes functionalities for adding, updating, and deleting classes and students, as well as displaying student information based on selected classes. The application uses data binding to connect UI elements with the underlying data model for seamless data management.

Uploaded by

kiencac11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Code

The document is a C# Windows Forms application for managing student classes and student details. It includes functionalities for adding, updating, and deleting classes and students, as well as displaying student information based on selected classes. The application uses data binding to connect UI elements with the underlying data model for seamless data management.

Uploaded by

kiencac11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;

namespace thihetmon
{
public partial class frmLopSinhVien : Form
{
public frmLopSinhVien()
{
InitializeComponent();
}
QLDDataContext dt = new QLDDataContext();
private void frmLopSinhVien_Load(object sender, EventArgs e)
{
cboLop.DisplayMember = "tenLop";
cboLop.ValueMember = "malop";
cboLop.DataSource = dt.Lop_SelectAll();
txtMaLop.DataBindings.Clear();
txtMaLop.DataBindings.Add("Text", cboLop.DataSource, "maLop");
txtTenLop.DataBindings.Clear();
txtTenLop.DataBindings.Add("Text", cboLop.DataSource, "tenLop");

}
Boolean adLop = false;
private void button1_Click(object sender, EventArgs e)
{
txtMaLop.Text = "";
txtTenLop.Text = "";
txtMaLop.Enabled = true;
txtMaLop.Focus();
adLop = true;
}

private void button2_Click(object sender, EventArgs e)


{
if (adLop)
{
dt.Lop_insert(txtMaLop.Text, txtTenLop.Text);
txtMaLop.Enabled = false;
adLop = false;
}
else
{
dt.Lop_update(txtMaLop.Text, txtTenLop.Text);
}
frmLopSinhVien_Load(sender, e);

private void button3_Click(object sender, EventArgs e)


{
dt.Lop_delete(cboLop.SelectedValue.ToString());
frmLopSinhVien_Load(sender, e);
}
private void BindStudentDetails()
{
txtMaSV.DataBindings.Clear();
txtMaSV.DataBindings.Add("Text", dtgSinhVien.DataSource, "maSV");

txtHoTen.DataBindings.Clear();
txtHoTen.DataBindings.Add("Text", dtgSinhVien.DataSource, "hoTen");

dateTimeNgaySinh.DataBindings.Clear();
dateTimeNgaySinh.DataBindings.Add("Text", dtgSinhVien.DataSource,
"ngaySinh");

txtGioiTinh.DataBindings.Clear();
txtGioiTinh.DataBindings.Add("Text", dtgSinhVien.DataSource, "gioiTinh");

txtNoiSinh.DataBindings.Clear();
txtNoiSinh.DataBindings.Add("Text", dtgSinhVien.DataSource, "noiSinh");

txtDanToc.DataBindings.Clear();
txtDanToc.DataBindings.Add("Text", dtgSinhVien.DataSource, "danToc");
}
private void txtGioiTinh_Format(object sender, ConvertEventArgs e)
{
if (e.DesiredType == typeof(string))
{
e.Value = (int)e.Value == 1 ? "Nữ" : "Nam";
}
}

private void cboLop_SelectedIndexChanged(object sender, EventArgs e)


{
if (cboLop.SelectedValue != null)
{
var maLop = cboLop.SelectedValue.ToString();
var sinhVienList = dt.SinhVien_SelectMaLop(maLop).ToList();

var sinhVienDisplayList = sinhVienList.Select(sv => new


{
sv.maSV,
sv.hoTen,
sv.ngaySinh,
gioiTinh = sv.gioiTinh == 1 ? "Nữ" : "Nam",
sv.noiSinh,
sv.danToc
}).ToList();

dtgSinhVien.DataSource = sinhVienDisplayList;
BindStudentDetails();
}
}

Boolean adSV = false;


private void btnAddSV_Click(object sender, EventArgs e)
{
txtMaSV.Text = "";
txtHoTen.Text = "";
dateTimeNgaySinh.Text = "";
txtGioiTinh.Text = "";
txtNoiSinh.Text = "";
txtDanToc.Text = "";
txtMaSV.Enabled = true;
txtMaSV.Focus();
adSV = true;
}

private void btnSaveSV_Click(object sender, EventArgs e)


{
if (adSV)
{
dt.SinhVien_Isnert(txtMaSV.Text, txtHoTen.Text, dateTimeNgaySinh.Value,
Convert.ToInt16(txtGioiTinh.Text), txtNoiSinh.Text, txtDanToc.Text, txtMaLop.Text);
adSV = false;
txtMaSV.Enabled = false;
cboLop_SelectedIndexChanged(sender,e);
}
else
{
dt.SinhVien_Update(txtMaSV.Text, txtHoTen.Text, dateTimeNgaySinh.Value,
Convert.ToInt16(txtGioiTinh.Text), txtNoiSinh.Text, txtDanToc.Text);
cboLop_SelectedIndexChanged(sender, e);
}
}

private void btnDeleteSV_Click(object sender, EventArgs e)


{
dt.SinhVien_delete(txtMaSV.Text);
cboLop_SelectedIndexChanged(sender, e);
}

private void txtSearch_TextChanged(object sender, EventArgs e)


{
dtgSinhVien.DataSource = dt.SinhViens.Where(x =>
x.hoTen.Contains(txtSearch.Text)).ToList();
txtMaSV.DataBindings.Clear();
txtMaSV.DataBindings.Add("Text", dtgSinhVien.DataSource, "maSV");
txtHoTen.DataBindings.Clear();
txtHoTen.DataBindings.Add("Text", dtgSinhVien.DataSource, "hoTen");
dateTimeNgaySinh.DataBindings.Clear();
dateTimeNgaySinh.DataBindings.Add("Text", dtgSinhVien.DataSource,
"ngaySinh");
txtGioiTinh.DataBindings.Clear();
txtGioiTinh.DataBindings.Add("Text", dtgSinhVien.DataSource, "gioiTinh");
txtNoiSinh.DataBindings.Clear();
txtNoiSinh.DataBindings.Add("Text", dtgSinhVien.DataSource, "noiSinh");
txtDanToc.DataBindings.Clear();
txtDanToc.DataBindings.Add("Text", dtgSinhVien.DataSource, "danToc");
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy