コード例 #1
0
        // 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);
            }
        }
        // For inserting the marks of student in the database
        // Tables updated : Evaluation , Student_Subject
        private void Insert_Eval_Marks_Click(object sender, EventArgs e)
        {
            int subject_id = 0, student_id = 0;

            Insert_Eval_Marks_Button.Hide();
            Total_Score_label.Show();
            int final_marks = Calculate_Best_Of_Three_Marks();

            Marks_Outof_50.Show();
            Marks_Outof_50.Text = final_marks + " / 50";


            // If all marks are not inserted in all textboxes.
            if (Eval_1_Marks_txtbox.Text == "" || Eval_2_Marks_txtbox.Text == "" || Eval_3_Marks_txtbox.Text == "")
            {
                MessageBox.Show("Enter Marks of all 3 Subjects");
            }



            // If all marks are inserted in all textboxes.
            else
            {
                string commandText1 = "SELECT subject_id from Subject where subject_name = @subj_name";
                string commandText2 = "SELECT student_id from Student where student_name = @stud_name";
                string commandText3 = "INSERT into Evaluation_Marks (subject_id, student_id, eval_1_marks, eval_2_marks, eval_3_marks, final_marks) values (@subj_id , @stud_id, @eval_1_marks, @eval_2_marks, @eval_3_marks, @final_marks)";

                try
                {
                    using (SqlCommand cmd = new SqlCommand(commandText1, sqlConnection1))
                    {
                        cmd.Parameters.AddWithValue("@subj_name", SubjectComboBox.SelectedItem);
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            subject_id = reader.GetInt32(0);
                        }
                        reader.Close();
                    }

                    using (SqlCommand cmd2 = new SqlCommand(commandText2, sqlConnection1))
                    {
                        cmd2.Parameters.AddWithValue("@stud_name", StudentComboBox.SelectedItem);
                        SqlDataReader reader = cmd2.ExecuteReader();
                        while (reader.Read())
                        {
                            student_id = reader.GetInt32(0);
                        }
                        reader.Close();
                    }

                    using (SqlCommand cmd3 = new SqlCommand(commandText3, sqlConnection1))
                    {
                        cmd3.Parameters.AddWithValue("@subj_id", subject_id);
                        cmd3.Parameters.AddWithValue("@stud_id", student_id);
                        cmd3.Parameters.AddWithValue("@eval_1_marks", Eval_1_Marks_txtbox.Text);
                        cmd3.Parameters.AddWithValue("@eval_2_marks", Eval_2_Marks_txtbox.Text);
                        cmd3.Parameters.AddWithValue("@eval_3_marks", Eval_3_Marks_txtbox.Text);
                        cmd3.Parameters.AddWithValue("@final_marks", final_marks);
                        cmd3.ExecuteNonQuery();
                    }


                    Add_Inserted_And_Updated_Marks_On_Data_Grid_View(final_marks, "", student_id);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            //Insert_Marks_Of_Another_Student();
        }
コード例 #3
0
        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");
        }