示例#1
0
        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);
            }
        }