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

address.setStreet(street); address.setCity(city); address.setState(state); address.setPostalCode(postalCode); address.setCountry(country);

}

}

}

Golfer

Lớp này được định nghĩa trong tập tin Golfer.cs. using System;

namespace TeeTimes

{

/// <summary>

/// Summary description for Golfer.

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

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

/// </summary> public class Golfer

{

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

public int id;

public String firstName; public String lastName; public String email; public String phone; public String username; public String password; public Address address;

Golfer cũng có vài phương thức kiến tạo: public Golfer()

{

id = 0; firstName = ""; lastName = ""; email = "";

phone = ""; username = ""; password = "";

address = new Address();

}

public Golfer(String _firstName, String _lastName, String _email, String _phone, String _streetAddress, String _city, String _state, String _postalCode, String _country, String _username, String _password)

{

firstName = _firstName; lastName = _lastName; email = _email;

phone = _phone; username = _username; password = _password; address = new Address();

address.setStreet(_streetAddress); address.setCity(_city); address.setState(_state); address.setPostalCode(_postalCode); address.setCountry(_country);

}

public Golfer(courseDataSet ds, int golferId)

{

id = 0; firstName = ""; lastName = ""; email = "";

phone = ""; username = ""; password = "";

address = new Address();

courseDataSet.golfersRow g = ds.golfers.FindByid(golferId); if (g != null)

{

id = golferId;

if (!g.IsfirstNameNull()) firstName = g.firstName; if (!g.IslastNameNull()) lastName = g.lastName; if (!g.IsemailNull())

email = g.email;

if (!g.IsphoneNull()) phone = g.phone;

if (!g.IsusernameNull()) username = g.username; if (!g.IspasswordNull()) password = g.password;

if (!g.IsstreetAddressNull()) address.setStreet(g.streetAddress); if (!g.IscityNull()) address.setCity(g.city);

if (!g.IsstateNull()) address.setState(g.state); if (!g.IspostalCodeNull())

address.setPostalCode(g.postalCode); if (!g.IscountryNull()) address.setCountry(g.country);

}

}

Các phương thức trả về giá trị: public int getId() { return id; }

public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public String getEmail() { return email; }

public String getPhone() { return phone; }

public String getUserName() { return username; } public String getPassword() { return password; } public Address getAddress() { return address; } public void setId(int _id) { id = _id; }

public void setFirstName(String _firstName) { firstName = _firstName; } public void setLastName(String _lastName) { lastName = _lastName; } public void setEmail(String _email) { email = _email; }

public void setPhone(String _phone) { phone = _phone; }

public void setUserName(String _username) { username = _username; } public void setPassword(String _password) { password = _password; }

public void setAddress(String streetAddress, String city, String state, String postalCode, String country)

{

address.setStreet(streetAddress); address.setCity(city);

address.setState(state); address.setPostalCode(postalCode); address.setCountry(country);

}

}

}

Tee

Được định nghĩa trong tập tin Tee.cs: using System;

using System.Data; namespace TeeTimes

{

/// <summary>

/// Summary description for Tee.

/// </summary> public class Tee

{

public int id;

public double slope; public int distance; public String description; public int courseId; public Hole[] holes;


public Tee()

{

}

public Tee(int _id, int _courseId, String _description, float _slope)

{

id = _id;

courseId = _courseId; description = _description; slope = _slope;

holes = null;

}

Các phương thức kiến tạo:

public Tee(courseDataSet ds, int teeId)

{

courseDataSet.teeRow t = ds.tee.FindByid(teeId); if (t != null)

{

id = teeId;

courseId = t.courseId; description = t.description; slope = t.slope;

DataView holeView = new DataView(ds.Hole); holeView.RowFilter = "teeId = "+teeId; holeView.Sort = "hole";

int cnt = 0;

holes = new Hole[holeView.Count]; foreach (DataRowView r in holeView)

{

Hole hole = new Hole(); hole.setTeeId(teeId);

int hole_handicap = Int32.Parse(r["handicap"].ToString()); int hole_length = Int32.Parse(r["length"].ToString());

int hole_hole = Int32.Parse(r["hole"].ToString());

int hole_par = Int32.Parse(r["par"].ToString()); hole.setHandicap(hole_handicap); hole.setLength(hole_length); hole.setHole(hole_hole); hole.setPar(hole_par);

holes[cnt] = hole; cnt++;

}

}

}

Các phương thức lấy và đặt giá trị: public int getId() { return id; }

public double getSlope() { return slope; } public int getDistance() { return distance; } public int getCourseId() { return courseId; }

public String getDescription() { return description; } public Hole[] getHoles() { return holes; }

public void setId(int _id) { id = _id; }

public void setSlope(double _slope) { slope = _slope; }

public void setDistance(int _distance) { distance = _distance; } public void setCourseId(int _courseId) { courseId = _courseId; }

public void setDescription(String _description) { description = _description; } public void setHoles(Hole[] _holes) { holes = _holes; }

}

}

Hole

Định nghĩa trong tập tin Hole.cs: using System;

namespace TeeTimes

{

/// <summary>

/// Summary description for Hole Class

/// </summary> public class Hole

{

public int id; public int teeId;

public int handicap; public int length; public int hole; public int par; public Hole()

{

id = 0;

teeId = 0;

handicap = 0;

length = 0;

hole = 0;

par = 0;

}

public Hole(int _id, int _teeId, int _handicap, int _length, int _hole, int _par)

{

id = _id;

teeId = _teeId; handicap = _handicap; length = _length;

hole = _hole;

par = _par;

}

public int getId() { return id; }

public int getTeeId() { return teeId; }

public int getHandicap() { return handicap; } public int getLength() { return length; } public int getHole() { return hole; }

public int getPar() { return par; } public void setId(int _id) { id = _id; }

public void setTeeId(int _teeId) { teeId = _teeId; }

public void setHandicap(int _handicap) { handicap = _handicap; } public void setLength (int _length) { length = _length; }

public void setHole (int _hole) { hole = _hole; } public void setPar (int _par) { par = _par; }

}

}

TeeTime using System;

namespace TeeTimes

{

/// <summary>

/// Summary description for TeeTime.

/// </summary> public class TeeTime

{

public int id;

public DateTime date; public DateTime time; public int courseId; public int golfer; public TeeTime()

{

id = 0;

date = System.DateTime.Now; time = System.DateTime.Now; courseId = 0;

golfer = 0;

}

public TeeTime(int _id, DateTime _date, DateTime _time, int _courseId, int _golfer)

{

id = _id;

date = _date; time = _time;

courseId = _courseId; golfer = _golfer;

}

Phương thức kiến tạo:

public TeeTime(courseDataSet ds, int ttId)

{

id = 0;

date = System.DateTime.Now; time = System.DateTime.Now; courseId = 0;

golfer = 0;

courseDataSet.bookingsRow tt = ds.bookings.FindByid(ttId); if (tt != null)

{

id = ttId;

if (!tt.IscourseIdNull()) courseId = tt.courseId; if (!tt.IsgolferNull()) golfer = tt.golfer;

if (!tt.IsteeDateNull())

date = DateTime.Parse(tt.teeDate); if (!tt.IsteeTimeNull())

time = DateTime.Parse(tt.teeTime);

}

}

public int getId() { return id; }

public DateTime getDate() { return date; } public DateTime getTime() { return time; } public int getCourseId() { return courseId; } public int getGolfer() { return golfer; } public void setId(int _id) { id = _id; }

public void setDate(DateTime _date) { date = _date; } public void setTime(DateTime _time) { time = _time; }

public void setCourseId(int _courseId) { courseId = _courseId; } public void setGolfer(int _golfer) { golfer = _golfer; }

}

}

Address

Address.cs: The Address utility class. using System;

namespace TeeTimes

{

/// <summary>

/// Summary description for Address.

/// </summary> public class Address

{

public String street; public String city; public String state;

public String postalCode; public String country; public Address()

{

street = ""; city = "";

state = ""; postalCode = ""; country = "";

}

public String getStreet() { return street; } public String getCity() { return city; } public String getState() { return state; }

public String getPostalCode() { return postalCode; } public String getCountry() { return country; }

public void setStreet(String _street){ street = _street; } public void setCity(String _city){ city = _city; }

public void setState(String _state){ state = _state; }

public void setPostalCode(StringpostalCode){ postalCode = _postalCode; } public void setCountry(String _country){ country = _country; }

}

}

Dịch vụ Web XML GolfCourseService Các phương thức hỗ trợ:

FindAll( )

Cú pháp: GolfCourse[] FindAll()

FindAll( ) trả về một mảng các đối tượng GolfCourse. Phương thức này gọi đến một danh sách hoàn chỉnh tất cả các khóa học được tào tạo bởi hệ thống.

[WebMethod]

public GolfCourse[] FindAll()

{

int nCourses = courseDataSet1.course.Count; GolfCourse[] golfCourses = new GolfCourse[nCourses]; int cnt = 0;

foreach (courseDataSet.courseRow c in courseDataSet1.course)

{

GolfCourse gc = new GolfCourse(c); golfCourses[cnt] = gc;

cnt++;

}

return golfCourses;

}

FindGeneric( )

Cú pháp: GolfCourse[] FindGeneric(String[] fields, String[] values) FindGeneric( ) cài đặt một truy vấn linh hoạt vào trong cơ sở dữ liệu khóa học. [WebMethod]

public GolfCourse[] FindGeneric(String[] fields, String[] values)

{

DataView cv = new DataView(courseDataSet1.course); cv.Sort = "name";

String filterString = "";

for (int x = 0; x < fields.Length; x++)

{

if (x >= 1)

{

filterString += " AND";

}

filterString += " "+fields[x]+" LIKE '"+values[x]+"'";

}

cv.RowFilter = filterString; int nCourses = cv.Count;

GolfCourse[] golfCourses = new GolfCourse[nCourses]; int cnt = 0;

foreach (DataRowView c in cv)

{

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

GolfCourse gc = new GolfCourse(courseDataSet1, gcId); golfCourses[cnt] = gc;

cnt++;

}

return golfCourses;

}

GetCourseDetail( )

Cú pháp: GolfCourse GetCourseDetail(String id) Trả về chi tiết của một khóa học:

[WebMethod]

public GolfCourse GetCourseDetail(String id)

{

int cid = Int32.Parse(id);

GolfCourse gc = new GolfCourse(courseDataSet1,cid); return gc;

}

AddCourse( )

Cú pháp: GolfCourse AddCourse(String name, String description, String price, String streetAddress, String city, String state, String postalCode, String country, String telephone)

Tạo một khóa học mới trong cơ sở dữ liệu các khóa học: [WebMethod]

public GolfCourse AddCourse(String name, String description, String price, String streetAddress, String city, String state, String postalCode, String country, String telephone)

{

courseDataSet.courseRow newCourse = courseDataSet1.course.

AddcourseRow(city,country,description,name, postalCode,price,state,streetAddress,telephone);

courseDataAdapter.Update(courseDataSet1,"course"); courseDataSet1.AcceptChanges();

GolfCourse gc = new GolfCourse(newCourse); return gc;

}

AddTee( )

Cú pháp: GolfCourse AddTee(int courseId, String description, float slope Tạo một tee mới

[WebMethod]

public GolfCourse AddTee(int courseId, String description, float slope)

{

courseDataSet.teeRow newTee = courseDataSet1.tee.AddteeRow(courseId,description,0,slope);

teeDataAdapter.Update(courseDataSet1,"tee"); courseDataSet1.AcceptChanges();

GolfCourse gc = new GolfCourse(courseDataSet1, courseId); return gc;

}

AddHole( )

Cú pháp: GolfCourse AddHole(int teeId, int handicap, int length, int hole, int par) thêm một bảng ghi lỗ mới vào cơ sở dữ liệu lỗ:

[WebMethod]

public GolfCourse AddHole(int teeId, int handicap, int length, int hole, int par)

{

courseDataSet.HoleRow newHole = courseDataSet1.Hole.AddHoleRow (handicap,length,teeId,hole,par); holeDataAdapter.Update(courseDataSet1,"Hole"); courseDataSet1.AcceptChanges();

courseDataSet.teeRow tr = courseDataSet1.tee.FindByid(teeId); int courseId = tr.courseId;

GolfCourse gc = new GolfCourse(courseDataSet1, courseId); return gc;

}

AddTeeTime( )

cú pháp: TeeTime AddTeeTime(int courseId, int golfer, DateTime date, DateTime time) Tạo một bảng ghi tee time mới:

[WebMethod]

public TeeTime AddTeeTime(int courseId, int golfer, DateTime date, DateTime time)

{

String dateString = date.ToShortDateString();

Xem toàn bộ nội dung bài viết ᛨ

..... Xem trang tiếp theo?
⇦ Trang trước - Trang tiếp theo ⇨

Ngày đăng: 19/11/2023