// Getting evaluation modes from Database and apply to the labels public void Get_Evaluation_Modes_For_Labels() { string commandText1 = "SELECT * from Evaluation where subject_id = (SELECT subject_id FROM Subject where subject_name = @s2_name)"; try { using (SqlCommand cmd = new SqlCommand(commandText1, sqlConnection1)) { cmd.Parameters.AddWithValue("@s2_name", SubjectComboBox.SelectedItem); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Eval_1_Marks_Label.Text = "Marks for " + reader.GetString(1) + " :"; Eval_2_Marks_Label.Text = "Marks for " + reader.GetString(2) + " :"; Eval_3_Marks_Label.Text = "Marks for " + reader.GetString(3) + " :"; } reader.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Eval_1_Marks_txtbox.Clear(); Eval_2_Marks_txtbox.Clear(); Eval_3_Marks_txtbox.Clear(); }
public void Hide_Eval_And_Insert_Marks_And_Update_Marks_Code() { Eval_1_Label.Hide(); Eval_1_txtbox.Hide(); Eval_2_Label.Hide(); Eval_2_txtbox.Hide(); Eval_3_Label.Hide(); Eval_3_txtbox.Hide(); Insert_eval_mode.Hide(); Enter_Eval_Modes_Label.Hide(); Enter_Student_Marks_Label.Hide(); Eval_1_Marks_Label.Hide(); Eval_1_Marks_txtbox.Hide(); Eval_2_Marks_Label.Hide(); Eval_2_Marks_txtbox.Hide(); Eval_3_Marks_Label.Hide(); Eval_3_Marks_txtbox.Hide(); Insert_Eval_Marks_Button.Hide(); Marks_Info_Label.Hide(); Total_Score_label.Hide(); Marks_Outof_50.Hide(); Update_Eval_Marks_Button.Hide(); }
private void Eval_1_Marks_txtbox_Leave(object sender, EventArgs e) { int number; if (int.TryParse(Eval_1_Marks_txtbox.Text, out number)) { if (number < 0 || number > 25) { Eval_1_Marks_txtbox.Clear(); MessageBox.Show("Enter Between 0 and 25 only"); } } }
// Method for displaying the marks of students already entered in the database. public void Display_And_Update_Student_Marks(string stud_name) { Eval_1_Marks_Label.Show(); Eval_1_Marks_txtbox.Show(); Eval_2_Marks_Label.Show(); Eval_2_Marks_txtbox.Show(); Eval_3_Marks_Label.Show(); Eval_3_Marks_txtbox.Show(); Marks_Info_Label.Show(); Enter_Eval_Modes_Label.Hide(); Enter_Student_Marks_Label.Show(); Update_Eval_Marks_Button.Show(); Insert_Eval_Marks_Button.Hide(); Total_Score_label.Show(); Marks_Outof_50.Show(); Enter_Student_Marks_Label.Text = "Update marks of : " + stud_name; Get_Evaluation_Modes_For_Labels(); string commandText1 = "SELECT eval_1_marks, eval_2_marks, eval_3_marks, final_marks from Evaluation_Marks where student_id = (SELECT student_id from Student where student_name = @stud_name) and subject_id = (SELECT subject_id from Subject where subject_name = @subj_name)"; try { using (SqlCommand cmd = new SqlCommand(commandText1, sqlConnection1)) { cmd.Parameters.AddWithValue("@stud_name", stud_name); cmd.Parameters.AddWithValue("@subj_name", SubjectComboBox.SelectedItem); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Eval_1_Marks_txtbox.Text = reader.GetInt32(0).ToString(); Eval_2_Marks_txtbox.Text = reader.GetInt32(1).ToString(); Eval_3_Marks_txtbox.Text = reader.GetInt32(2).ToString(); Marks_Outof_50.Text = reader.GetInt32(3).ToString() + " / 50"; } reader.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// Method for displaying Textboxes and Labels for inserting marks of student. // Called from private void StudentComboBox_SelectedValueChange() , private void Insert_eval_mode_Click() and , Display_And_Update_Student_Marks(). public void Display_Textboxes_And_Labels_For_Inserting_Marks() { Eval_1_Marks_Label.Show(); Eval_1_Marks_txtbox.Show(); Eval_2_Marks_Label.Show(); Eval_2_Marks_txtbox.Show(); Eval_3_Marks_Label.Show(); Eval_3_Marks_txtbox.Show(); Insert_eval_mode.Hide(); Insert_Eval_Marks_Button.Show(); Marks_Info_Label.Show(); Enter_Eval_Modes_Label.Hide(); Enter_Student_Marks_Label.Show(); Enter_Student_Marks_Label.Text = "Enter Marks of : " + StudentComboBox.SelectedItem; Get_Evaluation_Modes_For_Labels(); }
private void Update_Eval_Marks_Button_Click(object sender, EventArgs e) { string commandText1 = "UPDATE Evaluation_Marks set eval_1_marks = @eval_1_marks , eval_2_marks = @eval_2_marks , eval_3_marks = @eval_3_marks , final_marks = @final_marks where student_id = (SELECT student_id from Student where student_name = @stud_name) and subject_id = (SELECT subject_id from Subject where subject_name = @subj_name)"; string commandText2 = "SELECT student_id from Student where student_name = @stud_name"; Total_Score_label.Show(); // Method called from Insert_Eval_And_Final_Marks.cs file int final_marks = Calculate_Best_Of_Three_Marks(); Marks_Outof_50.Show(); Marks_Outof_50.Text = final_marks + " / 50"; try { // Code for getting student_name from dataGrdView1 if dataGridView1 row is clicked. string student_id = null; string student_name; if (StudentComboBox.SelectedIndex == -1) { student_id = (string)dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value; TeacherNameLabel.Text = "Here"; //TeacherNameLabel.Text = student_id.ToString(); student_name = (string)dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value; } else { student_name = StudentComboBox.SelectedItem.ToString(); using (SqlCommand cmd = new SqlCommand(commandText2, sqlConnection1)) { cmd.Parameters.AddWithValue("@stud_name", StudentComboBox.SelectedItem); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { student_id = reader.GetInt32(0).ToString(); } reader.Close(); } } using (SqlCommand cmd = new SqlCommand(commandText1, sqlConnection1)) { cmd.Parameters.AddWithValue("@eval_1_marks", Eval_1_Marks_txtbox.Text); cmd.Parameters.AddWithValue("@eval_2_marks", Eval_2_Marks_txtbox.Text); cmd.Parameters.AddWithValue("@eval_3_marks", Eval_3_Marks_txtbox.Text); cmd.Parameters.AddWithValue("@final_marks", final_marks); cmd.Parameters.AddWithValue("@stud_name", student_name); cmd.Parameters.AddWithValue("@subj_name", SubjectComboBox.SelectedItem); cmd.ExecuteNonQuery(); } dataGridView1.Rows.Remove(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex]); dataGridView1.Refresh(); Add_Inserted_And_Updated_Marks_On_Data_Grid_View(final_marks, student_name, Int32.Parse(student_id)); // For clearing out the textboxes after update. Marks_Outof_50.ResetText(); Eval_1_Marks_txtbox.ResetText(); Eval_2_Marks_txtbox.ResetText(); Eval_3_Marks_txtbox.ResetText(); Hide_Eval_And_Insert_Marks_And_Update_Marks_Code(); } catch (Exception ex) { MessageBox.Show("Here is the problem"); } MessageBox.Show("Marks Updated Successfully"); }