/// <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); } } }
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"; } }
private void btfFirst_Click(object sender, RoutedEventArgs e) { BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); var student = BLL.FirstStudent(); if (student != null) { RefreshUI(student); } }
private void btnDeleteClick(object sender, RoutedEventArgs e) { var messageDialog = new Windows.UI.Popups.MessageDialog("Are you sure you want to delete this Student Record?"); messageDialog.Commands.Add(new UICommand("Yes", (command) => { BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); var studentToDelete = BLL.GetStudentById(currentDisplayId); BLL.DeleteStudent(studentToDelete); var student = BLL.PreviousStudent(); RefreshUI(student); })); messageDialog.Commands.Add(new UICommand("No", (command) => {})); messageDialog.DefaultCommandIndex = 1; messageDialog.ShowAsync(); }
/// <summary> /// Invoked when application execution is being suspended. Application state is saved /// without knowing whether the application will be terminated or resumed with the contents /// of memory still intact. /// </summary> /// <param name="sender">The source of the suspend request.</param> /// <param name="e">Details about the suspend request.</param> private void OnSuspending(object sender, SuspendingEventArgs e) { var deferral = e.SuspendingOperation.GetDeferral(); //TODO: Save application state and stop any background activity // Sae the student details before suspending. BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); BLL.PersistStudents(); //RemoveFile(); //this.PersistStudents(); // Save the searches BusinessLayer.ISearchBLL searchBll = new BusinessLayer.SearchBLL((App.Current as App).GetSearchRepository()); searchBll.SaveSearches(); deferral.Complete(); }
/// <summary> /// Handles the Register button Click event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Register_Click(object sender, RoutedEventArgs e) { // Place code here to register the Student // Instantiate the Business Layer to process the input. BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); string msg = string.Empty; try { GetFormValues(); // If the key field in Student is 0, we're adding a new student, otherwise we're editing a student if (student.Id == 0) { // Add the student record to the datastore (Student Repository) BLL.AddStudent(student); msg = string.Format("{0} {1} has been added as a student", student.Firstname, student.Surname); } else { // Update the student. BLL.UpdateStudent(student); msg = string.Format("{0} {1} has been Updated.", student.Firstname, student.Surname); } // Reset the panel to accept a new Student entry this.ResetForm(); // Set confirmation message. this.lblConfirmMsg.Text = msg; } catch (RequiredDetailsNotEnteredException eNoData) { this.lblErrorMessage.Text = eNoData.Message; } catch (DateOfBirthException eDob) { this.lblErrorMessage.Text = eDob.Message; } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="args">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(MainPage), args.Arguments)) { throw new Exception("Failed to create initial page"); } } // Call the loadstudents method. BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); BLL.LoadStudents(); BusinessLayer.ISearchBLL searchBll = new BusinessLayer.SearchBLL((App.Current as App).GetSearchRepository()); searchBll.LoadSearches(); // Ensure the current window is active Window.Current.Activate(); }
/// <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); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="args">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs args) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); if (args.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(MainPage), args.Arguments)) { throw new Exception("Failed to create initial page"); } } // Call the loadstudents method. BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); BLL.LoadStudents(); // Ensure the current window is active Window.Current.Activate(); }
private void btfFirst_Click(object sender, RoutedEventArgs e) { BusinessLayer.IStudentBLL BLL = new BusinessLayer.StudentBLL((App.Current as App).GetRepository()); var student = BLL.FirstStudent(); if (student != null) RefreshUI(student); }