erotik film
bodyheat full moves www xxx kajal video la figa che sborra ver video de sexo porno
Luxury replica watches
sex
asyabahis
escort antalya

** THIS SITE IS AN ARCHIVE ** - New Content is at:
BlazorHelpWebsite.com

Sep 14

Written by: Michael Washington
9/14/2010 6:52 PM  RssIcon

To demonstrate LightSwitch functionality in a real world example, I have decided to create a Student information System. Eventually this will handle attendance and grades, but, for this first installment it will simply allow you to enroll students.

image

First, let us examine how a Student Information System usually works. A Course, and a Teacher make up a Section. A Student and a Section make up an Enrollment.

An Enrollment is the “heart” of a Student Information System. A Section, and an Enrollment are for a “period of time”. Grades, Attendance, and all other elements of the Student Information System, are tied to (associated with), Enrollments.

In this article we will build the system up to Enrollments.

You can get a copy of LightSwitch from: http://www.microsoft.com/visualstudio/en-us/lightswitch

Create The Project

image

Create a new Visual Studio project.

image

Call it LightSwitchStudentInformationSystem.

Set-up The Security

image

In the Solution Explorer, right-click on Properties and select Open.

image

Select Access Control, and select Use Forms authentication.

image

Also in Access Control, create TeacherAccess and AdministrativeAccess permissions, and check Granted for debug for all permissions.

The SecurityAdministration permission is built-in and allows a user to have access to the built-in User and Roles management screens.

The TeacherAccess and AdministrativeAccess permissions will be used by custom code (created in a later tutorial) to determine what menu items a user will have access to.

image

Hit F5 to run the application.

image

You will be able to create Roles and indicate what Permission each role has.

Create an Administrators role with “Administrative Access” and a Teacher role with “Teacher Access”.

image

You will also be able to create users and assign them to Roles.

image

Create a user called TestUser. When you are debugging you are always this user. We need to add the user to the user’s table, because later we will assign Students to this user.

Close the Silverlight application, and return to Visual Studio.

Create The Tables

image

In the Solution Explorer, right-click on Data Sources and select Add Table.

image

Create a table called Subject (you click on the title at the top of the table and type to change the name), with the schema you see above.

image

Create a table called Course with the schema you see above.

Click on the Relationship button.

image

Set the criteria you see above and click OK.

image

You will see a Subject field added to the Course table that associates Course with Subject.

LightSwitch will maintain data integrity, and not allow us to delete a Subject that has associated Courses.

image

Create a table called Teacher with the schema you see above.

image

Create a table called Section with the schema you see above.

image

Click on the Relationship button.

image

Set the criteria you see above and click OK.

image

Click on the Relationship button.

image

Set the criteria you see above and click OK.

image

Click on the Computed Property button.

image

Call the field SectionDisplay and give it the Type of String.

image

In the Properties window, click on the Edit Method link.

image

Enter the following code:

 

if ((this.Course != null) && (StartDate != null) && (Teacher != null))
{
    // Set result to the desired field value
    result = String.Format("{0} ({1}) [{2} - {3}]", Course.CourseName, Teacher.UserName,
        StartDate.ToShortDateString(), ((StopDate.HasValue) ? StopDate.Value.ToShortDateString() : ""));
}

 

Save the code and close the code window (very important, otherwise you will get an error when you try to run the application).

image

Click on the name of the Section table.

image

In the Properties for the table, set SectionDisplay as the Summary Property.

We do this because when we create the Screens to display the data, we want this field to be used whenever there is a list that is only able to display one field for the table (usually a selection list).

image

Create a table called Student with the schema you see above.

image

Create a table called Enrollment with the schema you see above.

image

Click on the Relationship button.

image

Set the criteria you see above and click OK.

image

Click on the Relationship button.

image

Set the criteria you see above and click OK.

image

Click on the Computed Property button.

image

Call the field EnrollmentDisplay and give it the Type of String.

image

In the Properties window, click on the Edit Method link.

image

Enter the following code:

 

if ((Student != null) && (Section != null) && (StartDate != null))
{
	// Set result to the desired field value
	result = String.Format("{0} ({1}) [{2} {3}]", Student.DisplayName,
	this.Section.Teacher.UserName,
	Section.Course.CourseName, StartDate.ToShortDateString());
}

 

Save the code and close the code window.

image

Click on the name of the Enrollment table.

image

In the Properties for the table, set EnrollmentDisplay as the Summary Property.

image

Next, click on StartDate and then click “Include in Unique Index”. Repeat the steps for the Section and Student fields.

The reason we do this, is to prevent a duplicate enrollment. Normally a primary key would be set on the database table to prevent data from being saved that would violate business rules (a student cannot have two enrollments in the same section that start on the same day).

With LightSwitch, you simply add the fields, to the Unique Index, that should not be duplicated.

image

Save and Build Solution.

Create Screens

image

In the Solution Explorer, right-click on Screens and select Add Screen…

image

Select Editable Grid Screen, and select Students for Screen Data, and click OK.

image

Select Editable Grid Screen, and select Teachers for Screen Data, and click OK.

image

Select List and Details Screen, and select Subjects for Screen Data.

Select Subject Details and Subject Courses for Additional Data to Include, and click OK.

image

Select List and Details Screen, and select Courses for Screen Data.

Select Course Details and Course Sections for Additional Data to Include, and click OK.

image

Select List and Details Screen, and select Sections for Screen Data.

Select Section Details and Section Enrollments for Additional Data to Include, and click OK.

image

Your Solution Explorer should resemble the image above.

Enter Data

image

Hit F5 to run the application.

image

Enter some Students.

image

Remember, you will need to click the Save button in the upper left-hand corner to save the data.

image

Enter Teachers by using the user name.

Ensure you create a Teacher named TestUser (you will need it later).

image

Enter Subjects.

image

Enter Courses. Notice you will be able to use the button to select a Subject.

image

Enter Sections. Notice you will be able to use the button to select a Course and a Teacher.

image

On the Section screen, you will be able to enter Enrollments.

image

You will be able to select a Student using the button.

Create enrollments for TestUser that begin before the current date (you will need them later).

Note: You will notice that it is possible to create an Enrollment that does not match the valid dates for the Section. We will show how you can add code to prevent this in a future article in this series. However, with LightSwitch you never HAVE to write code, so it is an option to simply enter only valid data.

Home Page To Show Teachers Their Currently Enrolled Students

As the final task for this tutorial, we will create a Home Page for Teachers that shows them the students that are currently enrolled in their sections.

See the tutorial: A LightSwitch Home Page for instructions on creating a Home Page that shows the Name of the current user, and how to set the screen as the Startup Screen.

image

When you make the changes, and you run the application, it should look like the image above.

image

In the screen designer, click the Add Data Item… button.

image

Select Queries then Enrollments (SelectAll).

image

Select Edit Query next to EnrollmentCollection.

image

The Edit Query screen will show.

image

Create a filter for the StartDate.

Select Global for the Value Type.

image

This will allow you to select Today for the value.

image

Continue to add conditions to the filter as seen above.

When you add the criteria for Teacher, you will be able to navigate to it.

image

Select Parameter.

image

Select Add New…

image

Enter Teacher for the Parameter name.

image

Click on Back to HomePage, to return to the screen designer.

image

Click on the Teacher parameter.

image

In the Properties, select Name for the Parameter Value.

image

You will see a line connecting the Teacher parameter to the Name.

image

Add the EnrolmentCollection to the screen.

image

It will add it as a DataGrid, click on it and change it to a List.

image

Right-Click on the Command Bar and select delete. The Command Bar section will still show, but all the buttons inside it will be deleted.

image

When you run the application it will show the currently enrolled students for the Teacher.

You can download the source code here:

http://silverlight.adefwebserver.com/files/LightSwitch/LightSwitchStudentInformationSystem_Part1.zip 

 

The LightSwitch Student Information System Series

Microsoft Visual Studio is a registered trademark of Microsoft Corporation / LightSwitch is a registered trademark of Microsoft Corporation