private void txtFind_TextChanged(object sender, EventArgs e) { // filter fields try { gridRegistration.DataSource = null; gridRegistration.DataSource = CourseEnrollmentDataAccess.filter(txtFind.Text) .Select(x => new { Id = x.Id, RegisteredDate = x.RegisteredDate, StudentID = x.RegistrationId, StudentName = x.StudentName, CourseID = x.CourseId, CourseName = x.CourseName, IsRemoved = x.IsRemoved, }).ToList(); gridRegistration.Columns["Id"].HeaderText = "ID"; gridRegistration.Columns["StudentID"].HeaderText = "Student ID"; gridRegistration.Columns["StudentName"].HeaderText = "Student Name"; gridRegistration.Columns["CourseID"].HeaderText = "Course ID"; gridRegistration.Columns["CourseName"].HeaderText = "Course Name"; gridRegistration.Columns["IsRemoved"].HeaderText = "Inactive"; } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDelete_Click(object sender, EventArgs e) { // delete registration info if (MessageBox.Show("Do you want to delete this record ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { var enrollment = new CourseEnrollment(); enrollment.Id = Convert.ToInt32(gridRegistration.SelectedRows[0].Cells[0].Value.ToString()); var result = CourseEnrollmentDataAccess.delete(enrollment); if (result == true) { MessageBox.Show("Record has been deleted successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); gridRefresh(); // call grid refresh method clearField(); // call clear field method } else { MessageBox.Show("Unable to delete record", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { return; } }
private void txtCourseId_KeyDown(object sender, KeyEventArgs e) { // Display course info if (e.KeyCode == Keys.Enter) { try { var course = new Course(); course.RefNo = txtCourseId.Text; var record = CoursesDataAccess.findCourseById(course); if (record == null) { MessageBox.Show("Course ID not found. Please check the Course-ID", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { // display course fee and course name txtCourseName.Text = record.Title; txtFee.Text = record.Fee.ToString(); // display lecturer Id and name var lecturer = CourseEnrollmentDataAccess.findCourseByCourseId(txtCourseId.Text); if (lecturer == null) { MessageBox.Show("Course lecturer details not found. Please check the course-ID", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { // display lecturer info txtLectuerId.Text = lecturer.LecturerId; txtLecturerName.Text = lecturer.LecturerName; // find student id var registration = new RegistrationIds(); registration.RegistrationId = txtRegistrationId.Text; var studentRecords = RegistrationCodesDataAccess.findStudentByRegistrationId(registration); if (studentRecords == null) { MessageBox.Show("Unable to locate student ID. Please check the registration ID", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { studentId = studentRecords.StudentId; } } } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void txt_RegistrationId_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { try { var registration = new RegistrationIds(); registration.RegistrationId = txt_RegistrationId.Text; var record = RegistrationCodesDataAccess.findStudentByRegistrationId(registration); if (record == null) { MessageBox.Show("Registration ID not found. Please check the registration ID", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { //// get parent contact no. var parentInfo = StudentDataAccess.findParentInfo(record.StudentId); if (parentInfo == null) { return; } else if (parentInfo.Mobile == null) { return; } else { parentContact = parentInfo.Pmobile; // assign phone number } var lecturerInfo = CourseEnrollmentDataAccess.findRegistrationDateByStudentId(record.RegistrationId, record.CourseId); if (lecturerInfo == null) { MessageBox.Show("Unable to locate lecturer details", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { txtStudentId.Text = record.StudentId; txtStudentName.Text = record.StudentName; txt_CourseId.Text = record.CourseId; txt_CourseName.Text = record.CourseName; txtLecturerID.Text = lecturerInfo.LecturerId; txtLecturerName.Text = lecturerInfo.LecturerName; Submit(); // call mark attendance } } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void txtRegistrationId_KeyDown(object sender, KeyEventArgs e) { // fill student name and enrolled courses in dropdown try { if (e.KeyCode == Keys.Enter) { var registrationCode = new RegistrationIds(); registrationCode.RegistrationId = txtRegistrationId.Text; var record = RegistrationCodesDataAccess.findStudentByRegistrationId(registrationCode); if (record == null) { MessageBox.Show("Registration ID not found. Please check the ID", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { txtStudentName.Text = record.StudentName; // student name gridCourses.DataSource = null; //var source = CourseEnrollmentDataAccess.findCourseByStudentId(record.StudentId).Where(x => x.IsRemoved == false); var source = CourseEnrollmentDataAccess.findCourseByStudentId(record.RegistrationId).Where(x => x.IsRemoved == false); gridCourses.DataSource = source .Select(x => new { CourseId = x.CourseId, CourseName = x.CourseName, LecturerId = x.LecturerId, LecturerName = x.LecturerName }).ToList(); gridCourses.Columns["CourseId"].HeaderText = "Course ID"; gridCourses.Columns["CourseName"].HeaderText = "Course Name"; gridCourses.Columns["LecturerId"].HeaderText = "Lecturer ID"; gridCourses.Columns["LecturerName"].HeaderText = "Lecturer Name"; // setting column width gridCourses.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void gridRefresh() { // refresh gridview try { gridRegistration.DataSource = null; gridRegistration.DataSource = CourseEnrollmentDataAccess.getEnrollements() .Select(x => new { Id = x.Id, RegisteredDate = x.RegisteredDate, StudentID = x.RegistrationId, StudentName = x.StudentName, CourseID = x.CourseId, CourseName = x.CourseName, LecturerId = x.LecturerId, LecturerName = x.LecturerName, }).ToList(); gridRegistration.Columns["Id"].HeaderText = "ID"; gridRegistration.Columns["StudentID"].HeaderText = "Student ID"; gridRegistration.Columns["StudentName"].HeaderText = "Student Name"; gridRegistration.Columns["CourseID"].HeaderText = "Course ID"; gridRegistration.Columns["CourseName"].HeaderText = "Course Name"; gridRegistration.Columns["LecturerId"].HeaderText = "Lecturer ID"; gridRegistration.Columns["LecturerName"].HeaderText = "Lecturer Name"; // setting datagrid column width gridRegistration.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; gridRegistration.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; gridRegistration.Columns[4].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; gridRegistration.Columns[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAdd_Click(object sender, EventArgs e) { // add new course registration try { // Course registration barcode var year = DateTime.Now.Year.ToString(); year = year.Substring(2); var month = DateTime.Now.Month.ToString(); var date = DateTime.Now.Day.ToString(); var hour = DateTime.Now.Hour.ToString(); var minute = DateTime.Now.Minute.ToString(); var miliseconds = DateTime.Now.Millisecond.ToString(); var RegistrationId = year + month + date + hour + minute + miliseconds; // registration id var enrollment = new CourseEnrollment(); enrollment.RegisteredDate = Convert.ToDateTime(dateRegister.Value.ToShortDateString()); enrollment.StudentId = txtStudentId.Text; enrollment.RegistrationId = RegistrationId; enrollment.StudentName = txtStudentName.Text; enrollment.CourseId = txtCourseId.Text; enrollment.CourseName = txtCourseName.Text; enrollment.LecturerId = txtLecturerId.Text; enrollment.LecturerName = txtLecturerName.Text; var result = CourseEnrollmentDataAccess.addEnrollment(enrollment); if (result == true) { MessageBox.Show("Course registration has been completed successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); gridRefresh(); // call grid refresh method var barcodeInfo = new RegistrationIds(); barcodeInfo.StudentId = txtStudentId.Text; barcodeInfo.StudentName = txtStudentName.Text; barcodeInfo.CourseId = txtCourseId.Text; barcodeInfo.CourseName = txtCourseName.Text; barcodeInfo.RegistrationId = RegistrationId; barcodeInfo.IssuedDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); barcodeInfo.IssuedBy = Username; var output = RegistrationCodesDataAccess.add(barcodeInfo); if (output == true) { // show barcode form var Barcode = new frm_CourseRegistrationCode(RegistrationId); Barcode.Show(); clearField(); // call clear field method } else { MessageBox.Show("Unable to record registraion data", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } else { MessageBox.Show("Course registration has been failed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } // var record = CourseEnrollmentDataAccess.findLastEntry(txtCourseId.Text); // if (record == null) // { // var lastEntry = 1; // lastEntry += 1; // adding 1 to last entry // var courseId = txtCourseId.Text; // RegistrationBarcodeId = courseId + lastEntry; // registration Id // } // else // { // var lastEntry = record.Id; // lastEntry += 1; // adding 1 to last entry // var courseId = txtCourseId.Text; // RegistrationBarcodeId = courseId + lastEntry; // registration Id // } // var enrollment = new CourseEnrollment(); // enrollment.RegisteredDate = Convert.ToDateTime(dateRegister.Value.ToShortDateString()); // enrollment.StudentId = txtStudentId.Text; // enrollment.RegistrationId = RegistrationBarcodeId; // enrollment.StudentName = txtStudentName.Text; // enrollment.CourseId = txtCourseId.Text; // enrollment.CourseName = txtCourseName.Text; // enrollment.LecturerId = txtLecturerId.Text; // enrollment.LecturerName = txtLecturerName.Text; // var result = CourseEnrollmentDataAccess.addEnrollment(enrollment); // if (result == true) // { // MessageBox.Show("Course registration has been completed successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); // gridRefresh(); // call grid refresh method // var barcodeInfo = new RegistrationIds(); // barcodeInfo.StudentId = txtStudentId.Text; // barcodeInfo.StudentName = txtStudentName.Text; // barcodeInfo.CourseId = txtCourseId.Text; // barcodeInfo.CourseName = txtCourseName.Text; // barcodeInfo.RegistrationId = RegistrationBarcodeId; // barcodeInfo.IssuedDate = Convert.ToDateTime(DateTime.Now.ToShortDateString()); // barcodeInfo.IssuedBy = Username; // var output = RegistrationCodesDataAccess.add(barcodeInfo); // if (output == true) // { // // show barcode form // var Barcode = new frm_CourseRegistrationCode(RegistrationBarcodeId); // Barcode.Show(); // clearField(); // call clear field method // } // else // { // MessageBox.Show("Unable to record registraion data", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // } // } // else // { // MessageBox.Show("Course registration has been failed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // } } catch (Exception ex) { MessageBox.Show("Failed : " + ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }