public frmThaoTacHoc(string id1, string id2) { _id1 = id1; _id2 = id2; InitializeComponent(); hc = new HocController(); //Xử lý mã Môn DataTable mm = sqlHelper.Query("SELECT MaMon FROM MonHoc"); List <DataRow> list = mm.AsEnumerable().ToList(); for (int i = 0; i < list.Count; i++) { ComboboxItem item = new ComboboxItem(); item.Text = list[i].ItemArray[0].ToString(); item.Value = list[i].ItemArray[0].ToString(); cbMaMon.Items.Add(item); } //Xử lý mã HocSinh DataTable mhs = sqlHelper.Query("SELECT MaHS FROM HocSinh"); List <DataRow> list1 = mhs.AsEnumerable().ToList(); for (int i = 0; i < list1.Count; i++) { ComboboxItem item1 = new ComboboxItem(); item1.Text = list1[i].ItemArray[0].ToString(); item1.Value = list1[i].ItemArray[0].ToString(); cbMaHS.Items.Add(item1); } if (id1 == null || id2 == null) { cbMaMon.Enabled = true; cbMaHS.Enabled = true; groupBox1.Visible = false; picAvtat.Visible = false; return; } Hoc h = new Hoc(); h = hc.GetData(id1, id2); txtDiemTK.Text = h.DiemTongKet; for (int i = 0; i < list.Count; i++) { if (h.MaMH == list[i].ItemArray[0].ToString()) { cbMaMon.SelectedIndex = i; h.MaMH = cbMaMon.Text; break; } } for (int i = 0; i < list1.Count; i++) { if (h.MaHS == list1[i].ItemArray[0].ToString()) { cbMaHS.SelectedIndex = i; h.MaHS = cbMaHS.Text; break; } } //string s = string.Format("SELECT * FROM HocSinh where MaHS={0}", id1); //DataTable dtIF = sqlHelper.Query(s); HocSinh hsif = new HocSinh(); Controller.HocSinhController hscf = new Controller.HocSinhController(); hsif = hscf.GetData(h.MaHS); string NS = DateTime.Parse(hsif.NgaySinh).Date.ToString() + DateTime.Parse(hsif.NgaySinh).Month.ToString() + DateTime.Parse(hsif.NgaySinh).Year.ToString(); lblTen.Text = "Họ Tên: " + hsif.HoTen; lblTuoi.Text = "Ngày Sinh: " + NS; try { if (hsif.GioiTinh == "False") { lblGioiTinh.Text = "Giới Tính: Nam"; picAvtat.Image = Image.FromFile(Application.StartupPath + "\\Resources\\user1600.png"); } else if (hsif.GioiTinh == "True") { lblGioiTinh.Text = "Giới Tính: Nữ"; picAvtat.Image = Image.FromFile(Application.StartupPath + "\\Resources\\nanny-icon.png"); } } catch { } }
public frmThaoTacHS(string id) { InitializeComponent(); _ID = id; hsc = new Controller.HocSinhController(); HocSinh hs = new HocSinh(); //Xử lý mã lớp DataTable dt = sqlHelper.Query("SELECT Malop FROM Lop"); List <DataRow> list = dt.AsEnumerable().ToList(); for (int i = 0; i < list.Count; i++) { ComboboxItem item = new ComboboxItem(); item.Text = list[i].ItemArray[0].ToString(); item.Value = list[i].ItemArray[0].ToString(); cbClass.Items.Add(item); } if (id == null) { txtMaHS.Enabled = true; return; } hs = hsc.GetData(id); txtMaHS.Text = hs.MaHS; txtHoTen.Text = hs.HoTen; DateTime _NgaySinh = (Convert.ToDateTime(hs.NgaySinh)); dtNgaySinh.Value = _NgaySinh; if (hs.GioiTinh == "Nam") { ckNam.Checked = true; } else if (hs.GioiTinh == "Nữ") { ckNu.Checked = true; } txtTenBo.Text = hs.TenBo; txtTenMe.Text = hs.TenMe; txtQueQuan.Text = hs.QueQuan; lblTen.Text = hs.HoTen; string gt = null; if (hs.GioiTinh == "Nam") { gt = "Nam"; } else if (hs.GioiTinh == "Nữ") { gt = "Nữ"; } lblGoiTinh.Text = gt; int tuoi = DateTime.Now.Year - _NgaySinh.Year; lblTuoi.Text = tuoi.ToString() + " Tuổi"; for (int i = 0; i < list.Count; i++) { if (hs.MaLop == list[i].ItemArray[0].ToString()) { cbClass.SelectedIndex = i; } } if (gt == "Nam") { picAvta.Image = Image.FromFile(Application.StartupPath + "\\Resources\\user1600.png"); } else { picAvta.Image = Image.FromFile(Application.StartupPath + "\\Resources\\nanny-icon.png"); } }