示例#1
0
        private void B_Enrol_Click(object sender, EventArgs e)
        {
            StudentAccessLayer SAL    = new StudentAccessLayer(Session.Database);
            Student            result = MakeStudent();

            try
            {
                if (_existingStudent == null) // If not editing a student
                {
                    result.Id = SAL.InsertStudent(result);
                }
                else // Updates student ID so existing record is updated
                {
                    result.Id = _existingStudent.Id;
                    SAL.UpdateStudent(result);
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                MessageBox.Show("Student not added/updated.  There was an SQL issue: \n" + ex.Message, "SQL ERROR");
                return;
            }
            EnrolStudent ES = new EnrolStudent(result);

            ES.Show();
        }
        // Buttons

        private void B_EnrolStudent_Click(object sender, EventArgs e)
        {
            // Makes sure that only one student is selected
            if (DGV_Students.SelectedRows.Count == 1)
            {
                StudentAccessLayer SAL = new StudentAccessLayer(Session.Database);
                EnrolStudent       ES  = new EnrolStudent(SAL.GetStudentById(Convert.ToInt32(DGV_Students.SelectedRows[0].Cells[0].Value.ToString())));
                ES.Show();  // Opening enrolment form
            }
            else
            {
                MessageBox.Show("You have selected more than 1 or not students.");
            }
        }