using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Data.OleDb; namespace Reservation { /// /// Location Web service. /// Called by peer Reservation instances. ///

Copyright (c) 2002 Alexis Grandemange
/// Mail: alexis.grandemange@pagebox.net

///
This program is free software; you can redistribute it and/or
	/// modify it under the terms of the GNU Lesser General Public
	/// License as published by the Free Software Foundation; version
	/// 2.1 of the License.
	/// This library is distributed in the hope that it will be useful,
	/// but WITHOUT ANY WARRANTY; without even the implied warranty of
	/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	/// GNU Lesser General Public License for more details.
	/// A copy of the GNU Lesser General Public License lesser.txt should be
	/// included in the distribution.
///
[WebService(Namespace="Reservation")] public class Location : System.Web.Services.WebService { public Location() { //CODEGEN: This call is required by the ASP.NET Web Services Designer InitializeComponent(); } #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { } #endregion /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { } /// /// Returns available slots on a given date. Called by Search.aspx. /// /// An array of TimeEntry or null /// date [WebMethod] public TimeEntry[] Available(DateTime dt) { ArrayList al = new ArrayList(); TimeEntry[] rc = null; OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); OleDbCommand odcmd = new OleDbCommand( "select * from resources where id='available ' and time=" + dt.ToFileTime(), odc); OleDbDataReader odr = odcmd.ExecuteReader(); if (odr.Read()) { process(al, odr, "h800", (short)8, (short)0); process(al, odr, "h830", (short)8, (short)30); process(al, odr, "h900", (short)9, (short)0); process(al, odr, "h930", (short)9, (short)30); process(al, odr, "h1000", (short)10, (short)0); process(al, odr, "h1030", (short)10, (short)30); process(al, odr, "h1100", (short)11, (short)0); process(al, odr, "h1130", (short)11, (short)30); process(al, odr, "h1200", (short)12, (short)0); process(al, odr, "h1230", (short)12, (short)30); process(al, odr, "h1300", (short)13, (short)0); process(al, odr, "h1330", (short)13, (short)30); process(al, odr, "h1400", (short)14, (short)0); process(al, odr, "h1430", (short)14, (short)30); process(al, odr, "h1500", (short)15, (short)0); process(al, odr, "h1530", (short)15, (short)30); process(al, odr, "h1600", (short)16, (short)0); process(al, odr, "h1630", (short)16, (short)30); process(al, odr, "h1700", (short)17, (short)0); process(al, odr, "h1730", (short)17, (short)30); process(al, odr, "h1800", (short)18, (short)0); process(al, odr, "h1830", (short)18, (short)30); rc = (TimeEntry[])al.ToArray(Type.GetType("Reservation.TimeEntry")); } odr.Close(); odc.Close(); return rc; } /// /// Method invoked by Available. /// If resource available at col hour, adds an entry to al. /// /// Array filled with TimeEntry /// Datareader on resource(available) /// Column name - h800 to h1830 /// Hour /// Number of minutes private void process(ArrayList al, OleDbDataReader odr, string col, short hour, short minutes) { short h = (short)odr[col]; if (h > 0) { TimeEntry te = new TimeEntry(); te.hour = hour; te.minutes = minutes; al.Add(te); } } /// /// Called by a new Reservation to notify its existence. /// /// Status /// URL of the PageBox Location.asmx /// Address (street...) /// City /// For United States and Canada, for instance CA /// Zip code /// Country name /// For instance Europe /// NDDD:MM.MMM /// WDDD:MM.MMM [WebMethod] public Entry Notify(string url, string address, string city, string state, string zip, string country, string region, string latitude, string longitude) { Location.populate(url, address, city, state, zip, country, region, latitude, longitude); Entry en = new Entry(); en.url = Global.url; en.address = Global.address; en.city = Global.city; en.state = Global.state; en.zip = Global.zipcode; en.country = Global.country; en.region = Global.region; en.latitude = Global.latitude; en.longitude = Global.longitude; return en; } /// /// Called by Application.Refresh and Notify. /// Updates the applications table. /// /// URL of the PageBox Location.asmx /// Address (street...) /// City /// For United States and Canada, for instance CA /// Zip code /// Country name /// For instance Europe /// NDDD:MM.MMM /// WDDD:MM.MMM public static void populate(string url, string address, string city, string state, string zip, string country, string region, string latitude, string longitude) { OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); OleDbCommand odcmd = new OleDbCommand("select address from applications where url='" + url + "'", odc); OleDbDataReader odr = odcmd.ExecuteReader(); if (odr.Read()) { odr.Close(); odcmd.CommandText = "update applications set address='" + address + "', city='" + city + "', state='" + state + "', zip='" + zip + "', country='" + country + "', region='" + region + "', latitude='" + latitude + "', longitude='" + longitude + "', time=" + DateTime.Now.ToFileTime() + " where url='" + url + "'"; odcmd.ExecuteNonQuery(); } else { odr.Close(); odcmd.CommandText = "insert into applications (url, address, city, state, zip, " + "country, region, latitude, longitude, time) values ('" + url + "', '" +address + "', '" + city + "', '" + state + "', '" + zip + "', '" + country + "', '" + region + "', '" + latitude + "', '" + longitude + "', " + DateTime.Now.ToFileTime() + ")"; odcmd.ExecuteNonQuery(); } odc.Close(); } /// /// Should be called by a Reservation instance when it is removed. /// Status /// URL of the PageBox Location.asmx /// [WebMethod] public string Unnotify(string url) { OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); OleDbCommand odcmd = new OleDbCommand("delete from applications where url='" + url + "'", odc); odcmd.ExecuteNonQuery(); odc.Close(); return "OK"; } } /* Commented because also defined in LocationProxy. public class TimeEntry { public short hour; public short minutes; } public class Entry { public string url; public string address; public string city; public string state; public string zip; public string country; public string region; public string latitude; public string longitude; } */ }