private void btnAdd_Click(object sender, EventArgs e) { LOPHOC lophoc = new LOPHOC { MaLop = Int32.Parse(txtIDClass.Text), SiSo = Int32.Parse(txtNumberOfStudent.Text), LopTruong = Int32.Parse(txtClassPresident.Text), GVQuanLy = Int32.Parse(txtIDTeacher.Text), NamBatDau = Convert.ToDateTime(dateTimePicker1.Text), NamKetThuc = Convert.ToDateTime(dateTimePicker2.Text) }; QLHSDataContext context = new QLHSDataContext(); context.LOPHOCs.InsertOnSubmit(lophoc); context.SubmitChanges(); context.Dispose(); this.Close(); }
private void btnUpdate_Click(object sender, EventArgs e) { QLHSDataContext context = new QLHSDataContext(); var student = (from HocSinh in context.HOCSINHs where HocSinh.MaHocSinh == Int32.Parse(txtIDStudent.Text) select HocSinh).FirstOrDefault(); if (student != null) { student.MaLop = Int32.Parse(txtIDClass.Text); student.NgaySinh = Convert.ToDateTime(dateTimePicker1.Text); student.TenHocSinh = txtFullName.Text; student.GioiTinh = txtSex.Text; context.SubmitChanges(); } context.Dispose(); this.Close(); }
private void btnUpdate_Click(object sender, EventArgs e) { QLHSDataContext context = new QLHSDataContext(); var Class = (from LopHoc in context.LOPHOCs where LopHoc.MaLop.ToString() == txtIDClass.Text select LopHoc).FirstOrDefault(); if (Class != null) { Class.SiSo = Int32.Parse(txtNumberOfStudent.Text); Class.LopTruong = Int32.Parse(txtClassPresident.Text); Class.GVQuanLy = Int32.Parse(txtIDTeacher.Text); Class.NamBatDau = Convert.ToDateTime(dateTimePicker1.Text); Class.NamKetThuc = Convert.ToDateTime(dateTimePicker2.Text); context.SubmitChanges(); } context.Dispose(); this.Close(); }
private void btnDeleteClass_Click(object sender, EventArgs e) { QLHSDataContext context = new QLHSDataContext(); var Class = (from LopHoc in context.LOPHOCs where LopHoc.MaLop == Int32.Parse(txtClass.Text) select LopHoc).FirstOrDefault(); var students = (from student in context.HOCSINHs where student.MaLop == Int32.Parse(txtClass.Text) select student).ToList(); if (students.Count > 0) { context.HOCSINHs.DeleteAllOnSubmit(students); context.SubmitChanges(); } if (Class != null) { context.LOPHOCs.DeleteOnSubmit(Class); context.SubmitChanges(); clearListClass(); showListClass(); txtClass.Text = ""; if (txtClass.Text != string.Empty) { var Class1 = context.LOPHOCs.Where(lh => lh.MaLop == Int32.Parse(txtClass.Text)).ToList(); if (Class1.Count == 0) { lbError.Show(); btnDeleteClass.Enabled = false; btnUpdateClass.Enabled = false; btnShowListStudent.Enabled = false; } } else { lbError.Hide(); } } context.Dispose(); }
private void txtStudent_TextChanged(object sender, EventArgs e) { QLHSDataContext context = new QLHSDataContext(); ConditionToEnableBtn(); if (txtClass.Text != string.Empty) { var Class = context.LOPHOCs.Where(lh => lh.MaLop == Int32.Parse(txtClass.Text)).ToList(); if (Class.Count == 0) { lbError.Show(); btnDeleteClass.Enabled = false; btnUpdateClass.Enabled = false; btnShowListStudent.Enabled = false; } } else { lbError.Hide(); } context.Dispose(); }
private void btnDeleteStudent_Click(object sender, EventArgs e) { if (context == null) { context = new QLHSDataContext(); } var Student = (from HocSinh in context.HOCSINHs where HocSinh.MaHocSinh == Int32.Parse(txtStudent.Text) select HocSinh).FirstOrDefault(); if (Student != null) { context.HOCSINHs.DeleteOnSubmit(Student); context.SubmitChanges(); clearListStudent(); showListStudent(); txtStudent.Text = ""; if (txtStudent.Text != string.Empty) { var Student1 = context.HOCSINHs.Where(hs => hs.MaHocSinh.ToString() == txtStudent.Text); if (Student1.Count() == 0) { btnDeleteStudent.Enabled = false; btnUpdateStudent.Enabled = false; lbError.Hide(); } else { lbError.Show(); } } else { lbError.Hide(); } } context.Dispose(); }