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; using System.Web.Mail; using System.Data.OleDb; namespace Reservation { /// /// Register form. /// Methods created or modified: ///

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.
///
public class Register : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox tbName; protected System.Web.UI.WebControls.TextBox tbMail; protected System.Web.UI.WebControls.Button btnRegister; protected System.Web.UI.WebControls.TextBox tbAddress; protected System.Web.UI.WebControls.TextBox tbCity; protected System.Web.UI.WebControls.TextBox tbZip; protected System.Web.UI.WebControls.TextBox tbRegion; protected System.Web.UI.WebControls.TextBox tbLatitude; protected System.Web.UI.WebControls.TextBox tbLongitude; protected System.Web.UI.WebControls.DropDownList ddState; protected System.Web.UI.WebControls.DropDownList ddCountry; protected System.Web.UI.WebControls.Label lblStatus; public Register() { Page.Init += new System.EventHandler(Page_Init); } /// /// Populates the form with the Reservation configuration /// private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { tbAddress.Text = Global.address; tbCity.Text = Global.city; ddState.DataSource = Global.stateAl; ddState.DataBind(); ddState.SelectedIndex = Global.stateIndex; tbZip.Text = Global.zipcode; ddCountry.DataSource = Global.countryAl; ddCountry.DataBind(); ddCountry.SelectedIndex = Global.countryIndex; tbRegion.Text = Global.region; tbLatitude.Text = Global.latitude; tbLongitude.Text = Global.longitude; } } 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 /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.btnRegister.Click += new System.EventHandler(this.OnClick); this.Load += new System.EventHandler(this.Page_Load); } #endregion /// /// Event fired when the user clicks on the Register button. /// Creates an end user account and mails the account data to the user. /// private void OnClick(object sender, System.EventArgs e) { if (tbName.Text.Length == 0) { lblStatus.Text = "Enter your name"; return; } if (tbMail.Text.Length == 0) { lblStatus.Text = "Enter your mail address"; return; } OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); OleDbTransaction odt = odc.BeginTransaction(); OleDbCommand odcmd = new OleDbCommand("select number from currentUserNo", odc, odt); OleDbDataReader odr = odcmd.ExecuteReader(); int unumber = 0; if (odr.Read()) { unumber = (int)odr["number"]; odr.Close(); odcmd.CommandText = "update currentUserNo set number=" + (unumber + 1); odcmd.ExecuteNonQuery(); } else { odr.Close(); odcmd.CommandText = "insert into currentUserNo (number) values (" + (unumber + 1) + ")"; odcmd.ExecuteNonQuery(); } string st = ddState.SelectedItem.Value; string state = ""; if (!st.Equals("N/A")) { if (Global.states.Contains(st)) state = (string)Global.states[st]; else state = (string)Global.provinces[st]; } string c = ddCountry.SelectedItem.Value; string country = (string)Global.countries[c]; odcmd.CommandText = "insert into users (id, password, type, name, mail, " + "address, city, state, zip, country, region, latitude, longitude) values ('u" + unumber + "', 'p" + unumber + "', 0, '" + tbName.Text + "', '" + tbMail.Text + "', '" + tbAddress.Text + "', '" + tbCity.Text + "', '" + state + "', '" + tbZip.Text + "', '" + country + "', '" + tbRegion.Text + "', '" + tbLatitude.Text + "', '" + tbLongitude.Text + "')"; odcmd.ExecuteNonQuery(); MailMessage mm = new MailMessage(); mm.BodyFormat = MailFormat.Text; mm.To = tbMail.Text; mm.From = "support@pagebox.net"; mm.Headers.Add("Reply-To", "support@pagebox.net"); mm.Priority = MailPriority.High; mm.Subject = "Registration information for PageBox Reservation"; mm.Body = "Hi " + tbName.Text + ",\nHere is your login information for the Reservation application on\n" + Global.url + "\nEmail address:\t" + tbMail.Text + "\nID:\tu" + unumber + "\nPassword:\tp" + unumber; SmtpMail.SmtpServer = Global.smtpServer; try { SmtpMail.Send(mm); } catch(Exception ex) { odt.Rollback(); odc.Close(); lblStatus.Text = "Notification failure: " + ex.Message; return; } odt.Commit(); odc.Close(); lblStatus.Text = "Account created: you should soon receive a mail"; } } }