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

courseDataSet.bookingsRow newBooking = courseDataSet1. bookings.AddbookingsRow(courseId,golfer,dateString,time.ToString());

bookingsDataAdapter.Update(courseDataSet1,"bookings"); courseDataSet1.AcceptChanges();

TeeTime tt = new TeeTime(0, date, time, courseId, golfer); return tt;

}

FindTeeTimesByGolfer( )

Cú pháp: TeeTime[] FindTeeTimesByGolfer(int golferId) Tìm kiếm các tee time bằng cách chỉ định người chơi: [WebMethod]

public TeeTime[] FindTeeTimesByGolfer(int golferId)

{

DataView ttv = new DataView(courseDataSet1.bookings); ttv.Sort = "teeTime";

ttv.RowFilter = "golfer = '"+golferId+"'"; int nTimes = ttv.Count;

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

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

TeeTime[] teeTimes = new TeeTime[nTimes]; int cnt = 0;

foreach (DataRowView c in ttv)

{

int ttId = Int32.Parse(c["id"].ToString());

TeeTime tt = new TeeTime(courseDataSet1, ttId); teeTimes[cnt] = tt;

cnt++;

}

return teeTimes;

}

AddGolfer( )

Cú pháp: Golfer AddGolfer(String firstName, String lastName, String streetAddress, String city, String state, String postalCode, String country, String email, String phone, String username, String password)

Tạo một bảng ghi mới của người chơi. [WebMethod]

public Golfer AddGolfer(String firstName, String lastName, String streetAddress, String city, String state, String postalCode, String country, String email, String phone, String username, String password)

{

courseDataSet.golfersRow newGolfer = courseDataSet1.golfers.

AddgolfersRow(city,country,email,firstName,lastName,phone, postalCode,state,streetAddress,password,username);

golferDataAdapter.Update(courseDataSet1,"golfers"); courseDataSet1.AcceptChanges();

Golfer g = new Golfer(firstName,lastName,email,phone, streetAddress,city,state,postalCode,country,username,password);

return g;

}

FindGolferById( )

Cú pháp: Golfer FindGolferById(int golferId) Trả về Golfer từ id chỉ định:

[WebMethod]

public Golfer FindGolferById(int golferId)

{

return new Golfer(courseDataSet1,golferId);

}

ValidateLogin( )

Cú pháp: Golfer ValidateLogin(String username, String password)

Dùng để kiểm tra mật khẩu và tài khoản trong cơ sở dữ liệu Golfer [WebMethod]

public Golfer ValidateLogin(String username, String password)

{

DataView gv = new DataView(courseDataSet1.golfers); gv.RowFilter = "username = '"+username+"' AND password = '"+password+"'";

int gCount = gv.Count; Golfer g = null;

if (gCount >= 1)

{

DataRowView gr = gv[0];

int golferId = Int32.Parse(gr["id"].ToString()); g = new Golfer(courseDataSet1,golferId);

}

return g;

}

FindTeeTimesByDate( )

Cú pháp: TeeTime[] FindTeeTimesByDate(int courseId, DateTime date) Trả về một mảng các tee times:

[WebMethod]

public TeeTime[] FindTeeTimesByDate(int courseId, DateTime date)

{

DataView ttv = new DataView(courseDataSet1.bookings); ttv.Sort = "teeTime";

ttv.RowFilter = "teeDate = '"+date.ToShortDateString()+"' AND courseId = '"+courseId+"'";

int nTimes = ttv.Count;

TeeTime[] teeTimes = new TeeTime[nTimes]; int cnt = 0;

foreach (DataRowView c in ttv)

{

int ttId = Int32.Parse(c["id"].ToString());

TeeTime tt = new TeeTime(courseDataSet1, ttId); teeTimes[cnt] = tt;

cnt++;

}

return teeTimes;

}

FindTeeTimesByDateRange( )

Cú pháp: TeeTime[] FindTeeTimesByDateRange(int courseId, DateTime startDate, DateTime endDate)

Trả về một mảng các tee times trong thời gian chỉ định: [WebMethod]

public TeeTime[] FindTeeTimesByDateRange(int courseId, DateTime startDate, DateTime endDate)

{

DataView ttv = new DataView(courseDataSet1.bookings); ttv.Sort = "teeTime";

String filterText = "courseId = '"+courseId+"' AND ("; TimeSpan duration = endDate.Subtract(startDate); int nDays = duration.Days;

for (int i = 0; i <= nDays; i++)

{

if (i > 0)

filterText = filterText + " OR"; DateTime tDate = startDate.AddDays(i);

filterText = filterText+" teeDate = '"+ tDate.ToShortDateString()+"'";

}

filterText = filterText + ")"; ttv.RowFilter = filterText; int nTimes = ttv.Count;

TeeTime[] teeTimes = new TeeTime[nTimes]; int cnt = 0;

foreach (DataRowView c in ttv)

{

int ttId = Int32.Parse(c["id"].ToString());

TeeTime tt = new TeeTime(courseDataSet1, ttId); teeTimes[cnt] = tt;

cnt++;

}

return teeTimes;

}


VI. Xây dựng mức Client.

Trình khách Golf Reservation System

Trình khách Golf Reservation System chứa: một tham chiếu Web kết nối tới các dịch vụ máy chủ Web Golf Reservation System, C# Web form (.aspx.cs và .aspx).

Để kết nối tới dịch vụ Web GolfCourseService do ứng dụng máy chủ Golf Reservation System, mà có thể cư trú bất cứ nơi đâu cung cấp trên Internet hay mạng địa phương bạn nhu cầu để tạo ra một sự tham chiếu Web. Một sự tham chiếu Web cung cấp lớp và những định nghĩa phương thức Web sẵn có từ những dịch vụ nó chứa và làm cho doanh nghiệp đó là những đối tượng và những phương pháp sẵn có tới dự án trong .NET Studio, điều này đơn giản như cung cấp một URL tới dịch vụ web, mà lần lượt lặp lại qua dữ liệu WSDL kết quả và tạo ra tất cả các mẩu cần thiết cho sự sử dụng .NET Studio.

Các bước tạo có thể được liệt kê như sau:

// localhost is the name of the computer hosting the Golf Reservation

//System Server

// First, create a protected reference to a GolfCourse object

// making it available to instances of this class, and assign

// the url variable `id' to a local variable, `_id' protected localhost.GolfCourse gc;

string _id = Request.QueryString.Get("id");

// Next, instantiate the GolfCourseService localhost.GolfCourseService gs = new localhost.GolfCourseService();

// Pass the local _id variable to the GetCourseDetail Web method and assign

// the result local GolfCourse gc. gc = gs.GetCourseDetail(_id);

Các mã lệnh của trình khách được liệt kê như sau: Mã Web Form:

Tập tin đầu tiên chúng ta xem xét là CoureDetail.aspx. Truy cập thông qua URL như

sau:


http://localhost/TeeTimes/courseDetail.aspx?id=10001 Các khai báo cần thiết cho trình khách là:

using System;

using System.Collections;

using System.ComponentModel; using System.Data;

using System.Drawing; using System.Web;

using System.Web.SessionState; using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

Mã lệnh này được tự động sinh ra bởi Visual Studio . NET namespace TeeTimesClient.content

{ public class courseDetail : System.Web.UI.Page

{

// provide a GolfCourse object to each instance protected localhost.GolfCourse gc;

public courseDetail()

{

Page.Init += new System.EventHandler(Page_Init);

}


private void Page_Init(object sender, EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

// InitializeComponent();

}

#region Web Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}

Và chỉ dẫn <%@ Page>

<%@ Page language="c#" Codebehind="courseDetail.aspx.cs" Auto EventWireup="false" Inherits="TeeTimesClient.content.courseDetail" %>

CourseDetail.aspx: Cung cấp một chỉ định XML với mô hình XSLT:

<document>

<header>

<title>Course Detail</title>

</header>

<section>

<header>

<title>Course Detail</title>

</header>

...

</section>

</document>

CourseSearch aspx Cung cấp một biểu mẫu hỏi người sử dụng các thông số tìm 1

CourseSearch aspx Cung cấp một biểu mẫu hỏi người sử dụng các thông số tìm 2

CourseSearch.aspx: Cung cấp một biểu mẫu hỏi người sử dụng các thông số tìm kiếm

<%@ Page %>

<document>

<header>

<title>Search For A Golf Course Near You</title>

</header>

<form action="controller.asp">

<section>

<header>

<title>Course Search</title>

</header>

<view>

<properties>

<property description="Course Name">

<input type="text" name="name" />

</property>

<property description="City">

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

</property>

<property description="State">

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

</property>

<property description="Country">

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

</property>

<property description="Postal Code">

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

</property>

<property>

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

</property>

</properties>

</view>

</section>

</form>

</document> CourseSearchResult.aspx.cs namespace TeeTimesClient

{

public class CourseSearchResult : System.Web.UI.Page

{

protected localhost.GolfCourse[] results;

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

{

// instantiate the GolfCourseService Web service localhost.GolfCourseService gs = new localhost.GolfCourseService();

// prepare the variables for calling FindGeneric String[] fields = new String[5];

String[] values = new String[5];

// populate the fields and values arrays fields[0] = "name";

string nameValue = Request.QueryString.Get("name");

// if the value is null, set to `*'

if (nameValue == null || nameValue == "")

nameValue = "*"; values[0] = nameValue;

fields[1] = "city";

string cityValue = Request.QueryString.Get("city"); if (cityValue == null || cityValue == "")

cityValue = "*"; values[1] = cityValue;

fields[2] = "state";

string stateValue = Request.QueryString.Get("state"); if (stateValue == null || stateValue == "")

stateValue = "*"; values[2] = stateValue; fields[3] = "country";

string countryValue = Request.QueryString.Get("country"); if (countryValue == null || countryValue == "") countryValue = "*";

values[3] = countryValue; fields[4] = "postalCode";

string postalCodeValue = Request.QueryString.Get("postalCode"); if (postalCodeValue == null || postalCodeValue == "")

postalCodeValue = "*"; values[4] = postalCodeValue;

results = gs.FindGeneric(fields, values);

}

CourseSearchResult.aspx:

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

<document>

<header>

<title>Course Search Results</title>

<description>

</description>

</header>

<section>

<header>

<title>Search Results</title>

</header>

<courseList>

// for each Golf Course, provide id and general information

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

<courseListItem>

<name>

<%= results[i].name %>

</name>

<id>

<%= results[i].id %>

</id>

<city>

<%= results[i].address.city %>

</city>

<state>

<%= results[i].address.state %>

</state>

</courseListItem>

<% } %>

</courseList>

</section>

</document>

login aspx Page language c Codebehind login aspx cs AutoEventWireup false Inherits TeeTimesClient 3

login.aspx

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

<document>

Xem tất cả 258 trang.

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