コード例 #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            //  Instantiate the business layer and inject the repository.
            BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository());
            //  Get the student Id passed as the parameter.
            long parameterId = 0;

            if (e.Parameter != null && e.Parameter != string.Empty)
            {
                parameterId = (long)e.Parameter;
                //  Get the student record
                student = BLL.GetStudentById(parameterId);
            }
            else
            {
                student = new BusinessEntities.Student();
            }

            if (student != null)
            {
                //  Set the form values to display the student record.
                SetFormValues();

                //  Set the button descriptions to Save and Cancel, make the Cancel button visible.
                this.RegisterStudent.Content = "Save";
            }
        }
        /// <summary>
        /// Reads in the parameter passed to this page and uses it to load
        /// the Student to display on this page.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository());

            BusinessEntities.Student student = (BusinessEntities.Student)e.Parameter;

            if (student != null && student.Id != 0)
            {
                //  We do this here, not because we have the full student record we need, but because
                //  eventually we'll be passing an Id instead of the student itself, so the logic is
                //  right for now.
                BusinessEntities.Student result = BLL.GetStudent(student.Firstname, student.Surname);

                //  Now move the results to the fields.
                RefreshUI(result);
            }
            else
            {
                student = BLL.FirstStudent();
                if (student != null)
                {
                    RefreshUI(student);
                }
            }
        }
        private void RefreshUI(BusinessEntities.Student student)
        {
            //  Bind he form to the student record
            this.StudentEntry.DataContext = student;

            //  Preserve Id of current Item being displayed
            currentDisplayId = student.Id;

            //  refresh the UI components with the student data.
            //this.txtFirstName.Text = student.Firstname;
            //this.txtSurname.Text = student.Surname;
            //this.txtDoB.Text = student.DOB.ToString();
            //this.cbYearOfStudy.SelectedIndex = ((int)student.YearOfStudy - 1);
            //this.txtCourseTitle.Text = student.Course;

            //this.txtAddress.Text = student.Address.Address1;
            //this.txtTown.Text = student.Address.Town;
            //this.txtCounty.Text = student.Address.County;
            //this.txtPostCode.Text = student.Address.PostCode;

            //this.txtPhoneHome.Text = student.Contact.HomePhone;
            //this.txtPhoneMobile.Text = student.Contact.MobilePhone;
            //this.txtEmailHome.Text = student.Contact.HomeEmail;
            //this.txtEmailStudent.Text = student.Contact.StudentEmail;
        }
コード例 #4
0
        /// <summary>
        /// Initialises the Register Student form.
        /// </summary>
        /// <remarks>
        /// Move this to a helper class so that the code is separate.
        /// Referencing the items on the form is not obvious to me
        /// at the moment, MUST investigate this further.
        /// </remarks>
        private void ResetForm()
        {
            student = new Student();
            this.StudentEntry.DataContext = student;

            //this.txtFirstNameInput.Text = string.Empty;
            //this.txtSurnameInput.Text = string.Empty;
            //this.txtDoBInput.Text = string.Empty;
            //this.txtCourseTitleInput.Text = string.Empty;
            //this.txtAddressInput.Text = string.Empty;
            //this.txtTownInput.Text = string.Empty;
            //this.txtCountyInput.Text = string.Empty;
            //this.txtPostCodeInput.Text = string.Empty;

            //this.cbYearOfStudyInput.SelectedIndex = 0;
            //this.txtPhoneHomeInput.Text = string.Empty;
            //this.txtPhoneMobileInput.Text = string.Empty;
            //this.txtEmailHomeInput.Text = string.Empty;
            //this.txtEmailStudentInput.Text = string.Empty;

            this.currentStudentId = 0;
        }