Lập trình web nâng cao XML - Trường CĐN Đà Lạt - 26

<header>

<title>My Tee Times</title>

</header>

<form action="controller.asp">

<section>

<header>

<title>Please Log In</title>

</header>

<view>

<description>

Có thể bạn quan tâm!

Xem toàn bộ 258 trang tài liệu này.

Log in to to view your saved Tee Times

</description>

<properties>

<property description="Username">

<input type="text" name="username" mandatory="yes" />

</property>

<property description="Password">

<input type="text" name="password" mandatory="yes" />

</property>

<property>

<input type="hidden" name="submitted" value="true" />

<input type="hidden" name="view" value="viewMyTeeTimes" />

</property>

</properties>

</view>

</section>

</form>

<form action="controller.asp">

<section>

<header>

<title>Register</title>

</header>

<view>

<description>

If you do not yet have a username and password, please provide the information below to become a registered user.

</description>

<properties>

<property description="Choose a username">

<input type="text" name="username" mandatory="yes" />

</property>

<property description="Choose a Password">

<input type="text" name="password" mandatory="yes" />

</property>

<property description="First Name">

<input type="text" name="firstName" mandatory="yes" />

</property>

<property description="Last Name">

<input type="text" name="lastName" mandatory="yes" />

</property>

<property description="Address">

<input type="text" name="streetAddress" mandatory="yes" />

</property>

<property description="City">

<input type="text" name="city" mandatory="yes" />

</property>

<property description="State">

<input type="text" name="state" mandatory="yes" />

</property>

<property description="Postal Code">

<input type="text" name="postalCode" mandatory="yes" />

</property>

<property description="Country">

<input type="text" name="country" mandatory="yes" />

</property>

<property description="email">

<input type="text" name="email" mandatory="yes" />

</property>

<property description="Telephone">

<input type="text" name="phone" mandatory="yes" />

<input type="hidden" name="submitted" value="true" />

</property>

<property>

<input type="hidden" name="view" value="register" />

</property>

</properties>

</view>

</section>

</form>

</document> register.aspx.cs

namespace TeeTimesClient.content

{

public class register : System.Web.UI.Page

{

protected localhost.Golfer newGolfer;

private void Page_Load(object sender, System.EventArgs e)

{

localhost.GolfCourseService gs = new localhost.GolfCourseService();

// Get all values from the Request.QueryString object

string usernameValue = Request.QueryString.Get("username"); string passwordValue = Request.QueryString.Get("password"); string firstNameValue = Request.QueryString.Get("firstName"); string lastNameValue = Request.QueryString.Get("lastName");

string streetAddressValue = Request.QueryString.Get ("streetAddress");

string cityValue = Request.QueryString.Get("city"); string stateValue = Request.QueryString.Get("state");

string postalCodeValue = Request.QueryString.Get("postalCode"); string countryValue = Request.QueryString.Get("country");

string emailValue = Request.QueryString.Get("email"); string phoneValue = Request.QueryString.Get("phone");

// Add a new golfer to the database

newGolfer = gs.AddGolfer(firstNameValue,lastNameValue, streetAddressValue,cityValue,stateValue,postalCodeValue, countryValue,emailValue,phoneValue,usernameValue,passwordValue);

}

register.aspx:

<%@ Page language="c#" Codebehind="register.aspx.cs" AutoEventWireup="false" Inherits="TeeTimesClient.content.register" %>

<document>

<header>

<title>My Tee Times</title>

</header>

<section>

<header>

<title>Thank You for Registering</title>

</header>

<view>

<description>

Thanks for registering

<%= newGolfer.firstName%>

- Now that you are a registered user, you can set up Tee Times with any of our partner Golf Courses.

</description>

</view>

</section>

</document>

scheduleTeeTime.aspx.cs - Build a registration and insert it into the database namespace TeeTimesClient.content

{

public class scheduleTeeTime : System.Web.UI.Page

{

protected localhost.TeeTime tt; protected localhost.Golfer golfer; protected localhost.GolfCourse gc;

private void Page_Load(object sender, System.EventArgs e)

{

localhost.GolfCourseService gs = new localhost.GolfCourseService();

int courseIdValue = Int32.Parse(Request.

QueryString.Get("courseId"));

int golferIdValue = Int32.Parse(Request.QueryString.Get ("golferId"));

System.DateTime dateValue = System.DateTime.Parse (Request.QueryString.Get("teeTime"));

// AddTeeTime requires two System.DateTime objects

// The first is parsed for the date, the second for the time

tt = gs.AddTeeTime(courseIdValue,golferIdValue,dateValue,dateValue); golfer = gs.FindGolferById(golferIdValue);

gc = gs.GetCourseDetail(Request.QueryString.Get("courseid"));

}

scheduleTeeTime.aspx


<%@ Page language="c#" Codebehind="scheduleTeeTime.aspx.cs" AutoEventWireup="false" Inherits="TeeTimesClient.content. scheduleTeeTime" %>

<document>

<header>

<title>My Tee Times</title>

</header>

<section>

<header>

<title>Tee Time Scheduled</title>

</header>

<description>

Thank you for registering a tee time. The detail of your registration is below.

</description>

<teeTimeDetail>

<golfer>

<name>

<%= golfer.firstName %>

<%= golfer.lastName %>

</name>

</golfer>

<course>

<id>

<%= gc.id %>

</id>

<name>

<%= gc.name %>

</name>

</course>

<date>

<%= tt.date.ToShortDateString() %>

</date>

<time>

<%= tt.time.ToShortTimeString() %>

</time>

</teeTimeDetail>

</section>

</document> viewMyTeeTimes.aspx.cs namespace TeeTimesClient.content

{

public class viewMyTeeTimes : System.Web.UI.Page

{

protected localhost.TeeTime[] tt; protected localhost.Golfer golfer; protected localhost.GolfCourse gc; protected bool redirect = false;

// Provide the GolfCourseService to instances

protected localhost.GolfCourseService gs = new localhost.

GolfCourseService();

private void Page_Load(object sender, System.EventArgs e)

{

string usernameValue = Request.QueryString.Get("username"); string passwordValue = Request.QueryString.Get("password"); golfer = gs.ValidateLogin(usernameValue,passwordValue);

// if ValidateLogin returns a null reference, set

// boolean redirect to true if (golfer == null) {

redirect = true;

} else {

int golferIdValue = golfer.id;

tt = gs.FindTeeTimesByGolfer(golferIdValue);

}

}

viewMyTeeTimes.aspx.cs: Provides a list of registered tee times for a validated user.

<%@ Page language="c#" Codebehind="viewMyTeeTimes.aspx.cs" AutoEventWireup="false" Inherits="TeeTimesClient.content. viewMyTeeTimes" %>

<document>

<header>

<title>My Tee Times</title>

</header>

<section>

<header>

<title>My Tee Times</title>

</header>

<view>

<description>

<%

if (redirect)

Response.Write("Your username and password failed validation. If you feel this is an error, please try logging in again. If you are not yet a registered user, please click 'My Tee Times' above and complete our registration Form.");

else

Response.Write("Your registered Tee Times Are Listed Below");

%>

</description>

<% if (!redirect) {%>

<myTeeTimes>

<% for (int i=0; i<tt.Length;i++) { %>

<myTeeTime>

<course>

<courseId>

<%= tt[i].courseId%>

</courseId>

<% gc = gs.GetCourseDetail(tt[i].courseId.ToString()); %>

<name>

<%= gc.name %>

</name>

</course>

<teeTime>

<date>

<%= tt[i].date.ToShortDateString() %>

</date>

<time>

<%= tt[i].time.ToShortTimeString() %>

</time>

</teeTime>

</myTeeTime>

<% } %>

</myTeeTimes>

<% } %>

</view>

</section>

</document>

viewTeeTimes aspx cs Retrieves valid TeeTimes given a courseID It also returns a valid user if the 1

viewTeeTimes.aspx.cs: Retrieves valid TeeTimes given a courseID. It also returns a valid user if the username and password validate.


namespace TeeTimesClient.content

{

public class viewTeeTimes : System.Web.UI.Page

{

protected localhost.TeeTime[] tt; protected localhost.Golfer golfer; protected localhost.GolfCourse gc; protected int selectedYear; protected int selectedMonth; protected int selectedDay; protected bool redirect = false;

private void Page_Load(object sender, System.EventArgs e)

{

localhost.GolfCourseService gs = new localhost.GolfCourseService(); string usernameValue = Request.QueryString.Get("username"); string passwordValue = Request.QueryString.Get("password");

string courseIdString = Request.QueryString.Get("courseId"); golfer = gs.ValidateLogin(usernameValue,passwordValue);

if (golfer == null) { redirect = true;

} else {

int golferIdValue = golfer.id;

}

// FindTeeTimesByDate requires the Course Id value to

// be cast as an Int

int courseIdValue = Int32.Parse(courseIdString);

selectedYear = Int32.Parse(Request.QueryString.Get("year"));

selectedMonth = Int32.Parse(Request.QueryString.Get("month")); selectedDay = Int32.Parse(Request.QueryString.Get("day"));

System.DateTime dateValue = System.DateTime.Parse (Request.QueryString.Get("month")+"/"

+Request.QueryString.Get("day")+"/"

+Request.QueryString.Get("year"));

tt = gs.FindTeeTimesByDate(courseIdValue,dateValue); gc = gs.GetCourseDetail(courseIdString);

}

viewTeeTimes.aspx: Iterates over an array of TeeTimes for a specific GolfCourse . If a valid Golfer is not provided, append a <noRegister> node to the XML. Also, if a TeeTime is already registered, append a taken node to the XML.


<%@ Page language="c#" Codebehind="viewTeeTimes.aspx.cs" AutoEventWireup="false" Inherits="TeeTimesClient.content. viewTeeTimes" %>

<document>

<header>

<title>My Tee Times</title>

</header>

<section>

<header>

<title>Select a Tee Time</title>

</header>

<view>

<description>

<%

<!--- redirect will be true if the username and password provided to ViewTeeTimes.aspx.cs

failed validation --->

if (redirect)

Response.Write("Your username and password failed validation. If you feel this is an error, please try logging in again. If you are not yet a registered user, please click 'My Tee Times' above and complete our registration Form.");

else

Response.Write("Please choose a tee time from the list below");

%>

</description>

<TeeTimes>

<courseId>

<%=gc.id%>

</courseId>

<% if (redirect) {

<!---If redirect is true, append noRegister node---> Response.Write("<noRegister/>");

} else {

<!---Otherwise, provide the golferId---> Response.Write("<golferId>"+golfer.id+"</golferId>");

}

%>

<%

System.DateTime thisTeeTime = new System.DateTime (selectedYear,selectedMonth,selectedDay,8,0,0,0);

System.DateTime lastTeeTime = new System.DateTime (selectedYear,selectedMonth,selectedDay,17,0,0,0);

int taken = 0;

while(thisTeeTime.CompareTo(lastTeeTime) != 0)

{

thisTeeTime = thisTeeTime.AddHours(.5);

%>

<teeTime>

<TeeTimesystemDate>

<%=thisTeeTime.ToString()%>

</TeeTimesystemDate>

<date>

<%= thisTeeTime.ToShortDateString() %>

</date>

<time>

<%= thisTeeTime.ToShortTimeString() %>

</time>

<%

for(int i=0;i<tt.Length;i++)

{

<!---Compare this TeeTime to the TeeTime in this loop iteration of the TeeTimes array tt. If they are equal,

the TeeTime is already registered for, append a taken node to the XML --->

string myTime = thisTeeTime.ToShortTimeString(); string takenTime = tt[i].time.ToShortTimeString();

if (myTime.Equals(takenTime))

{

%>

` <taken />

<%

}

}

%>

</teeTime>

<%

}

%>

</TeeTimes>

</view>

</section>

</document>

Xem tất cả 258 trang.

Ngày đăng: 19/11/2023
Trang chủ Tài liệu miễn phí