private void Load_Data() { // update diem trung binh MarksOfSubject marks; string query = "SELECT name, diem_mieng, diem_15, diem_45, diem_hoc_ki, diem_trung_binh FROM subject , marks WHERE subject.id = marks.id_subject AND" + " marks.id_subject =" + subject.Id; DataTable dt = DataProvider.Instance.ExcuteQuery(query); foreach (DataRow row in dt.Rows) { marks = new MarksOfSubject(row); lbSubjectName.Text = marks.Name; lbDiemMieng.Text = marks.Diem_mieng.ToString(); lbDiem15.Text = marks.Diem_15.ToString(); lbDiem45.Text = marks.Diem_45.ToString(); lbDiemHocKi.Text = marks.Diem_hoc_ki.ToString(); update_diem_trung_binh(float.Parse(lbDiemMieng.Text), float.Parse(lbDiem15.Text) , float.Parse(lbDiem45.Text), float.Parse(lbDiemHocKi.Text)); } if (lbSubjectName.Text == "Toan") { lbSubjectName.Text = "Toán"; } else if (lbSubjectName.Text == "VatLy") { lbSubjectName.Text = "Vật Lý"; } else if (lbSubjectName.Text == "CongNghe") { lbSubjectName.Text = "Công Nghệ"; } else if (lbSubjectName.Text == "SinhHoc") { lbSubjectName.Text = "Sinh Học"; } else if (lbSubjectName.Text == "TinHoc") { lbSubjectName.Text = "Tin Học"; } else if (lbSubjectName.Text == "CongDan") { lbSubjectName.Text = "Công Dân"; } else if (lbSubjectName.Text == "NgoaiNgu") { lbSubjectName.Text = "Ngoại Ngữ"; } else if (lbSubjectName.Text == "DiaLy") { lbSubjectName.Text = "Địa Lý"; } else if (lbSubjectName.Text == "HoaHoc") { lbSubjectName.Text = "Hóa Học"; } }
private void update_diem_trung_binh(float diem_mieng, float diem_15, float diem_45, float diem_hoc_ki) { MarksOfSubject marks; // tinh diem trung binh float diem_trung_binh = (diem_mieng + diem_15 + diem_45 * 2 + diem_hoc_ki * 3) / 7; string query_update = "UPDATE marks SET diem_trung_binh=" + diem_trung_binh + "WHERE id_subject=" + subject.Id; DataTable dt = DataProvider.Instance.ExcuteQuery(query_update); // select diem trung binh string query_select = "SELECT name, diem_mieng, diem_15, diem_45, diem_hoc_ki, diem_trung_binh FROM subject , marks WHERE subject.id = marks.id_subject AND" + " marks.id_subject =" + subject.Id; DataTable dt2 = DataProvider.Instance.ExcuteQuery(query_select); foreach (DataRow row in dt2.Rows) { marks = new MarksOfSubject(row); lbDiemTrungBinh.Text = marks.Diem_trung_binh.ToString(); } }
private void data_khoiB() { MarksOfSubject marks; string query = "SELECT name, diem_mieng, diem_15, diem_45, diem_hoc_ki, diem_trung_binh FROM subject," + " marks WHERE subject.id = marks.id_subject "; DataTable dt = DataProvider.Instance.ExcuteQuery(query); List <MarksOfSubject> list_marks = new List <MarksOfSubject>(); foreach (DataRow row in dt.Rows) { marks = new MarksOfSubject(row); string subject_name = marks.Name; double diem_mieng = marks.Diem_mieng; double diem_15 = marks.Diem_15; double diem_45 = marks.Diem_45; double diem_hoc_ki = marks.Diem_hoc_ki; double diem_trung_binh = marks.Diem_trung_binh; list_marks.Add(marks); } double diem_trung_binh_Toan = 0; double diem_trung_binh_VatLy = 0; double diem_trung_binh_HoaHoc = 0; double diem_trung_binh_CongNghe = 0; double diem_trung_binh_SinhHoc = 0; double diem_trung_binh_DiaLy = 0; double diem_trung_binh_CongDan = 0; double diem_trung_binh_NgoaiNgu = 0; double diem_trung_binh_TinHoc = 0; foreach (MarksOfSubject item in list_marks) { if (item.Name == "Toan") { diem_trung_binh_Toan = item.Diem_trung_binh; } else if (item.Name == "VatLy") { diem_trung_binh_VatLy = item.Diem_trung_binh; } else if (item.Name == "HoaHoc") { diem_trung_binh_HoaHoc = item.Diem_trung_binh; } else if (item.Name == "CongNghe") { diem_trung_binh_CongNghe = item.Diem_trung_binh; } else if (item.Name == "TinHoc") { diem_trung_binh_TinHoc = item.Diem_trung_binh; } else if (item.Name == "SinhHoc") { diem_trung_binh_SinhHoc = item.Diem_trung_binh; } else if (item.Name == "DiaLy") { diem_trung_binh_DiaLy = item.Diem_trung_binh; } else if (item.Name == "CongDan") { diem_trung_binh_CongDan = item.Diem_trung_binh; } else if (item.Name == "NgoaiNgu") { diem_trung_binh_NgoaiNgu = item.Diem_trung_binh; } } double diem_khoi_B01 = diem_trung_binh_Toan + diem_trung_binh_VatLy + diem_trung_binh_SinhHoc; double diem_khoi_B02 = diem_trung_binh_Toan + diem_trung_binh_DiaLy + diem_trung_binh_SinhHoc; double diem_khoi_B03 = diem_trung_binh_Toan + diem_trung_binh_SinhHoc + diem_trung_binh_TinHoc; double diem_khoi_B04 = diem_trung_binh_Toan + diem_trung_binh_SinhHoc + diem_trung_binh_CongDan; double diem_khoi_B05 = diem_trung_binh_Toan + diem_trung_binh_SinhHoc + diem_trung_binh_HoaHoc; double diem_khoi_B08 = diem_trung_binh_Toan + diem_trung_binh_SinhHoc + diem_trung_binh_NgoaiNgu; lbB01.Text = diem_khoi_B01.ToString(); lbB02.Text = diem_khoi_B02.ToString(); lbB03.Text = diem_khoi_B03.ToString(); lbB04.Text = diem_khoi_B04.ToString(); lbB05.Text = diem_khoi_B05.ToString(); lbB08.Text = diem_khoi_B08.ToString(); }