예제 #1
0
        /// <summary>
        /// Handles the event when the link button for "Update Grade" is clicked.
        /// Parses the input and updates the grade for the given registration.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lnkUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string formatClearedValue = Numeric.ClearFormatting(gradeTextBox.Text, "%");

            if (Numeric.isNumeric(formatClearedValue, System.Globalization.NumberStyles.Float))
            {
                double gradeParsed = double.Parse(formatClearedValue);
                gradeParsed = gradeParsed / 100;
                if (gradeParsed >= 0 && gradeParsed <= 1)
                {
                    Registration idToBeUpdated  = constructorData.registration;
                    int          registrationID = idToBeUpdated.RegistrationId;
                    string       notes          = idToBeUpdated.Notes;
                    ServiceReference.CollegeRegistrationClient localWS = new ServiceReference.CollegeRegistrationClient();
                    localWS.updateGrade(gradeParsed, registrationID, notes);
                    frmStudent frmStudent = new frmStudent(constructorData);
                    frmStudent.MdiParent = this.MdiParent;
                    frmStudent.Show();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Grade value is out of range, please enter a value between 0 to 1.");
                }
            }
            else
            {
                MessageBox.Show("Please enter grade in decimal format between 0 and 1. Update failed.");
            }
        }
예제 #2
0
        /// <summary>
        /// Performs the appropriate operation of CollegeRegistration dependent on what type of transaction it is.
        /// </summary>
        /// <param name="transactionRecords"></param>
        private void processTransactions(IEnumerable <XElement> transactionRecords)
        {
            //Loop through each transaction and grab each child element value
            foreach (XElement node in transactionRecords)
            {
                string typeValue               = node.Element("type").Value;
                string studentNumberValue      = node.Element("student_no").Value;
                string courseNumberValue       = node.Element("course_no").Value;
                string registrationNumberValue = node.Element("registration_no").Value;
                string gradeValue              = node.Element("grade").Value;
                string notes = node.Element("notes").Value;

                //Parse numerical values
                long studentNumberParsed = long.Parse(studentNumberValue);

                //If the type is 1 (registration), then register the course for the student
                if (typeValue.Equals("1") && registrationNumberValue.Equals("*") && gradeValue.Equals("*"))
                {
                    int?courseID = (from results
                                    in db.Courses
                                    where results.CourseNumber == courseNumberValue
                                    select results.CourseId).SingleOrDefault();

                    int?studentID = (from results
                                     in db.Students
                                     where results.StudentNumber == studentNumberParsed
                                     select results.StudentId).SingleOrDefault();

                    if (studentID != null && courseID != null)
                    {
                        int course  = (int)courseID;
                        int student = (int)studentID;
                        ServiceReference.CollegeRegistrationClient localWS = new ServiceReference.CollegeRegistrationClient();
                        int returnCode = localWS.registerCourse(student, course, notes);
                        db.SaveChanges();

                        //Successful registration
                        if (returnCode == 0)
                        {
                            logData += "Successful registration for student number: " + studentNumberValue + ". Course selected: " + courseNumberValue + "\r\n";
                        }

                        //Failed Registrations
                        else if (returnCode == -100 || returnCode == -200 || returnCode == -300)
                        {
                            logData += registerError(returnCode);
                        }

                        //Unknown error when registering
                        else
                        {
                            logData += registerError(returnCode);
                        }
                    }
                }

                //If the type is 2 (grading), then update the grade
                else if (typeValue.Equals("2") && !registrationNumberValue.Equals("*") && !gradeValue.Equals("*"))
                {
                    double gradeParsed        = (double.Parse(gradeValue)) / 100;
                    long   registrationParsed = long.Parse(registrationNumberValue);

                    int?registrationID = (from results
                                          in db.Registrations
                                          where results.RegistrationNumber == registrationParsed
                                          select results.RegistrationId).SingleOrDefault();


                    //If the grade is within range
                    if (gradeParsed >= 0 && gradeParsed <= 1 && registrationID != null)
                    {
                        int registration = (int)registrationID;
                        ServiceReference.CollegeRegistrationClient localWS = new ServiceReference.CollegeRegistrationClient();

                        try
                        {
                            localWS.updateGrade(gradeParsed, registration, notes);
                            db.SaveChanges();
                            logData += "Grade " + gradeValue + " applied to student " + studentNumberValue + " for registration " + registrationNumberValue + "\r\n";
                        }
                        catch (Exception)
                        {
                            logData += "Problem with transaction: update for " + registrationNumberValue + " was unsuccessful\r\n";
                        }
                    }
                }
            }
        }