Example #1
0
        private void txtCourseId_KeyDown(object sender, KeyEventArgs e)
        {
            // find course name
            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    var course = new Course();
                    course.RefNo = txtCourseId.Text;

                    var record = CoursesDataAccess.findCourseById(course);


                    if (record.RefNo == null)
                    {
                        MessageBox.Show("Course-ID not found", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else if (record.IsRemoved == true)
                    {
                        // Detect inactive student id
                        MessageBox.Show("Inactive Course-ID found", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                    else
                    {
                        // fill course name textfield
                        txtCourseName.Text = record.Title;

                        gridLecturer.DataSource = null;
                        var source = LecturerCoursesDataAccess.findLectuerersByCourseId(txtCourseId.Text);

                        gridLecturer.DataSource = source.Select(x => new
                        {
                            LecturerId   = x.LecturerId,
                            LecturerName = x.LecturerName
                        }).ToList();

                        gridLecturer.Columns["LecturerId"].HeaderText   = "Lecturer ID";
                        gridLecturer.Columns["LecturerName"].HeaderText = "Lecturer Name";

                        // setting data grid column width
                        gridLecturer.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed : " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void gridRegistration_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            // fill fields
            try
            {
                // activate manage tab
                metroTabControl1.SelectedTab = tab_Registration;

                txtStudentId.Text    = gridRegistration.SelectedRows[0].Cells[2].Value.ToString();
                txtStudentName.Text  = gridRegistration.SelectedRows[0].Cells[3].Value.ToString();
                txtCourseId.Text     = gridRegistration.SelectedRows[0].Cells[4].Value.ToString();
                txtCourseName.Text   = gridRegistration.SelectedRows[0].Cells[5].Value.ToString();
                txtLecturerId.Text   = gridRegistration.SelectedRows[0].Cells[6].Value.ToString();
                txtLecturerName.Text = gridRegistration.SelectedRows[0].Cells[7].Value.ToString();

                // fill lecturer grid
                gridLecturer.DataSource = null;
                var source = LecturerCoursesDataAccess.findLectuerersByCourseId(txtCourseId.Text);

                gridLecturer.DataSource = source.Select(x => new
                {
                    LecturerId   = x.LecturerId,
                    LecturerName = x.LecturerName
                }).ToList();

                gridLecturer.Columns["LecturerId"].HeaderText   = "Lecturer ID";
                gridLecturer.Columns["LecturerName"].HeaderText = "Lecturer Name";

                // setting data grid column width
                gridLecturer.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed : " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }