private void dgvDiem_CellValueChanged(object sender, DataGridViewCellEventArgs e) { NhapDiemSV_BE obj = new NhapDiemSV_BE(); if (dgvDiem.Rows.Count > 0) { int vt = dgvDiem.CurrentCell.RowIndex; //set diemTP obj.DiemQTHeS1 = float.Parse(dgvDiem.Rows[vt].Cells["DiemQTHeS1"].Value.ToString()); obj.DiemQTHeS2 = float.Parse(dgvDiem.Rows[vt].Cells["DiemQTHeS2"].Value.ToString()); obj.DiemTP = (float)Math.Round((obj.DiemQTHeS1 + obj.DiemQTHeS2 * 2) / 3, 1); dgvDiem.CurrentRow.Cells["DiemTP"].Value = obj.DiemTP; //set diemTBHP obj.DiemTP = float.Parse(dgvDiem.Rows[vt].Cells["DiemTP"].Value.ToString()); obj.DiemThi = float.Parse(dgvDiem.Rows[vt].Cells["DiemThi"].Value.ToString()); obj.DiemTBHP = (float)Math.Round((obj.DiemTP * 3 + obj.DiemThi * 7) / 10, 1); dgvDiem.CurrentRow.Cells["DiemTBHP"].Value = obj.DiemTBHP; // set diem chu if (obj.DiemTBHP >= 9 && obj.DiemTBHP <= 10) { obj.DiemChuTBHP = "A+"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP >= 8.5 && obj.DiemTBHP <= 8.9) { obj.DiemChuTBHP = "A"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP >= 8.0 && obj.DiemTBHP <= 8.4) { obj.DiemChuTBHP = "B+"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP >= 7.0 && obj.DiemTBHP <= 7.9) { obj.DiemChuTBHP = "B"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP >= 6.5 && obj.DiemTBHP <= 6.9) { obj.DiemChuTBHP = "C+"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP >= 5.5 && obj.DiemTBHP <= 6.4) { obj.DiemChuTBHP = "C"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP >= 4.0 && obj.DiemTBHP <= 5.4) { obj.DiemChuTBHP = "D"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } if (obj.DiemTBHP < 4.0) { obj.DiemChuTBHP = "F"; dgvDiem.CurrentRow.Cells["DiemChuTBHP"].Value = obj.DiemChuTBHP; } } }
private void GetMhByCb() { GetSVByCb(); string keyMaLop = cbMaL.SelectedValue != null?cbMaL.SelectedValue.ToString() : string.Empty; string keyMH = cbMH.SelectedValue != null?cbMH.SelectedValue.ToString() : string.Empty; string keyHocKi = cbHocKi.SelectedValue != null?cbHocKi.SelectedValue.ToString() : string.Empty; if (!string.IsNullOrEmpty(keyMaLop) && !string.IsNullOrEmpty(keyMH) && !string.IsNullOrEmpty(keyHocKi)) { DataTable dt = ndiem.GetMH(keyMH); var lst = new List <NhapDiemSV_BE>(); for (int i = 0; i < dt.Rows.Count; i++) { NhapDiemSV_BE obj = new NhapDiemSV_BE(); obj.MaMH = keyMH; lst.Add(obj); } MaMH.DataSource = ndiem.GetMH(keyMH); MaMH.DisplayMember = "MaMH"; MaMH.ValueMember = "MaMH"; MaMH.DataSource = lst; } }
private void GetSVByCb() { string key = cbMaL.SelectedValue != null?cbMaL.SelectedValue.ToString() : string.Empty; string keyMaMH = cbMH.SelectedValue != null?cbMH.SelectedValue.ToString() : string.Empty; string keyHocKi = cbHocKi.Text; if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(keyMaMH) && !string.IsNullOrEmpty(keyHocKi)) { btSave.Enabled = true; btReset.Enabled = true; DataTable dt = ndiem.GetMaSVByMaLop(key); var lst = new List <NhapDiemSV_BE>(); for (int i = 0; i < dt.Rows.Count; i++) { NhapDiemSV_BE obj = new NhapDiemSV_BE(); obj.MaSV = dt.Rows[i]["MaSV"].ToString(); obj.TenSV = dt.Rows[i]["TenSV"].ToString(); obj.MaLop = key; obj.MaMH = keyMaMH; obj.HocKi = Int32.Parse(keyHocKi.ToString()); obj.DiemQTHeS1 = 0; obj.DiemQTHeS2 = 0; obj.DiemThi = 0; obj.DiemTP = 0; obj.DiemTBHP = 0; obj.LanThi = 1; obj.DiemChuTBHP = "F"; lst.Add(obj); } dgvDiem.DataSource = lst; if (lst != null && dt.Rows.Count > 0) { lbTg.Visible = true; lbTg.Text = "có tổng số: " + dgvDiem.RowCount.ToString() + " sinh viên"; lbTg.ForeColor = Color.BlueViolet; lbTg.Font = new Font(lbTg.Font, FontStyle.Italic); } } else { DataTable dt = new DataTable(); var lst = new List <NhapDiemSV_BE>(); dgvDiem.DataSource = lst; lbTg.Visible = false; } }
private void btSave_Click(object sender, EventArgs e) { try { var lst = dgvDiem.DataSource as List <NhapDiemSV_BE>; for (int i = 0; i < lst.Count; i++) { NhapDiemSV_BE obj = new NhapDiemSV_BE(); obj.MaSV = lst[i].MaSV; obj.MaMH = lst[i].MaMH; obj.MaLop = lst[i].MaLop; obj.LanThi = lst[i].LanThi; obj.DiemChuTBHP = lst[i].DiemChuTBHP; obj.DiemQTHeS1 = lst[i].DiemQTHeS1; obj.DiemQTHeS2 = lst[i].DiemQTHeS2; obj.DiemTP = lst[i].DiemTP; obj.DiemThi = lst[i].DiemThi; obj.DiemTBHP = lst[i].DiemTBHP; obj.HocKi = lst[i].HocKi; obj.SoTietNghi = lst[i].SoTietNghi; bool check = ndiem.CheckDiemThiSV(obj.MaSV, obj.MaLop, obj.MaMH, obj.LanThi); if (!check) { ndiem.InsertDiem(obj.MaSV, obj.MaLop, obj.MaMH, obj.DiemQTHeS1, obj.DiemQTHeS2, obj.DiemThi, obj.DiemTP, obj.DiemTBHP, obj.DiemChuTBHP, obj.LanThi, obj.HocKi, obj.SoTietNghi); MessageBox.Show(" tạo điểm cho sinh viên " + obj.MaSV.Trim() + " thành công"); } else { MessageBox.Show(" điểm môn học với sinh viên có mã: " + obj.MaSV.Trim() + " này đã được nhập"); } } } catch (Exception ex) { MessageBox.Show("lỗi" + ex); } }