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.Data.OleDb; namespace Reservation { /// /// Offer 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 Offer : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox H800; protected System.Web.UI.WebControls.TextBox H900; protected System.Web.UI.WebControls.TextBox H1000; protected System.Web.UI.WebControls.TextBox H1100; protected System.Web.UI.WebControls.TextBox H1200; protected System.Web.UI.WebControls.TextBox H1300; protected System.Web.UI.WebControls.TextBox H1400; protected System.Web.UI.WebControls.TextBox H1500; protected System.Web.UI.WebControls.TextBox H1600; protected System.Web.UI.WebControls.TextBox H1700; protected System.Web.UI.WebControls.TextBox H1800; protected System.Web.UI.WebControls.TextBox H830; protected System.Web.UI.WebControls.TextBox H930; protected System.Web.UI.WebControls.TextBox H1030; protected System.Web.UI.WebControls.TextBox H1130; protected System.Web.UI.WebControls.TextBox H1230; protected System.Web.UI.WebControls.TextBox H1330; protected System.Web.UI.WebControls.TextBox H1430; protected System.Web.UI.WebControls.TextBox H1530; protected System.Web.UI.WebControls.TextBox H1630; protected System.Web.UI.WebControls.TextBox H1730; protected System.Web.UI.WebControls.TextBox H1830; protected System.Web.UI.WebControls.Button btnUpdate; protected System.Web.UI.WebControls.Button btnReset; protected System.Web.UI.WebControls.Label lblMonth; protected System.Web.UI.WebControls.Label lblStatus; protected System.Web.UI.WebControls.DropDownList ddResource; protected System.Web.UI.WebControls.Button btnSet; protected System.Web.UI.WebControls.Button btnZero; protected System.Web.UI.WebControls.Calendar CalOffer; protected System.Web.UI.WebControls.Label lblDay; /// /// Logged user /// private string userid; public Offer() { Page.Init += new System.EventHandler(Page_Init); } /// /// Checks if the user is logged with an employee user id. /// Calls bindResources the first time. /// private void Page_Load(object sender, System.EventArgs e) { userid = (string)Context.Session["userid"]; if (userid == null) { Context.Session.Add("from", "Offer.aspx"); Context.Response.Redirect("Login.aspx"); return; } short type = (short)Context.Session["type"]; if (type < 2) { Context.Session.Add("status", "Log-in with a employee user id"); Context.Session.Add("from", "Offer.aspx"); Context.Response.Redirect("Login.aspx"); return; } if (!IsPostBack) { OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); bindResources(odc); odc.Close(); } } /// /// Populates the DropDown resource list from the users table. /// /// Database connection private void bindResources(OleDbConnection odc) { OleDbCommand odcmd = new OleDbCommand("select id from users where type=2 and deltime=0", odc); OleDbDataReader odr = odcmd.ExecuteReader(); ArrayList al = new ArrayList(); while (odr.Read()) { al.Add(odr["id"]); } odr.Close(); al.Add("available "); al.Add("total "); al.Add("booked "); ddResource.DataSource = al; ddResource.DataBind(); for (int i = 0; i < al.Count; ++ i) { string u = ((string)al[i]).TrimEnd(new char[] { ' ' }); if (u.Equals(userid)) { ddResource.SelectedIndex = i; break; } } } /// /// Populates the schedule table from the resource table. /// /// Database connection /// User selected on the DropDown list /// Day selected on the calendar private void bind(OleDbConnection odc, string id, DateTime dt) { OleDbCommand odcmd = new OleDbCommand("select * from resources where id='" + id.PadRight(10, ' ') + "' and time=" + dt.ToFileTime(), odc); OleDbDataReader odr = odcmd.ExecuteReader(); int mt = 0; if (odr.Read()) { H800.Text = "" + odr["h800"]; H830.Text = "" + odr["h830"]; H900.Text = "" + odr["h900"]; H930.Text = "" + odr["h930"]; H1000.Text = "" + odr["h1000"]; H1030.Text = "" + odr["h1030"]; H1100.Text = "" + odr["h1100"]; H1130.Text = "" + odr["h1130"]; H1200.Text = "" + odr["h1200"]; H1230.Text = "" + odr["h1230"]; H1300.Text = "" + odr["h1300"]; H1330.Text = "" + odr["h1330"]; H1400.Text = "" + odr["h1400"]; H1430.Text = "" + odr["h1430"]; H1500.Text = "" + odr["h1500"]; H1530.Text = "" + odr["h1530"]; H1600.Text = "" + odr["h1600"]; H1630.Text = "" + odr["h1630"]; H1700.Text = "" + odr["h1700"]; H1730.Text = "" + odr["h1730"]; H1800.Text = "" + odr["h1800"]; H1830.Text = "" + odr["h1830"]; mt += (short)odr["h800"]; mt += (short)odr["h830"]; mt += (short)odr["h900"]; mt += (short)odr["h930"]; mt += (short)odr["h1000"]; mt += (short)odr["h1030"]; mt += (short)odr["h1100"]; mt += (short)odr["h1130"]; mt += (short)odr["h1200"]; mt += (short)odr["h1230"]; mt += (short)odr["h1300"]; mt += (short)odr["h1330"]; mt += (short)odr["h1400"]; mt += (short)odr["h1430"]; mt += (short)odr["h1500"]; mt += (short)odr["h1530"]; mt += (short)odr["h1600"]; mt += (short)odr["h1630"]; mt += (short)odr["h1700"]; mt += (short)odr["h1730"]; mt += (short)odr["h1800"]; mt += (short)odr["h1830"]; } else { H800.Text = "0"; H830.Text = "0"; H900.Text = "0"; H930.Text = "0"; H1000.Text = "0"; H1030.Text = "0"; H1100.Text = "0"; H1130.Text = "0"; H1200.Text = "0"; H1230.Text = "0"; H1300.Text = "0"; H1330.Text = "0"; H1400.Text = "0"; H1430.Text = "0"; H1500.Text = "0"; H1530.Text = "0"; H1600.Text = "0"; H1630.Text = "0"; H1700.Text = "0"; H1730.Text = "0"; H1800.Text = "0"; H1830.Text = "0"; } odr.Close(); lblDay.Text = "" + (mt / 2); DateTime dtFirst = new DateTime(dt.Year, dt.Month, 1); int m = 1, y = 1; if (dt.Month == 12) { m = 1; y = dt.Year + 1; } else { m = dt.Month + 1; y = dt.Year; } DateTime dtLast = new DateTime(y, m, 1); odcmd.CommandText = "select * from resources where id='" + id.PadRight(10, ' ') + "' and time>=" + dtFirst.ToFileTime() + " and time<" + dtLast.ToFileTime(); odr = odcmd.ExecuteReader(); mt = 0; while(odr.Read()) { mt += (short)odr["h800"]; mt += (short)odr["h830"]; mt += (short)odr["h900"]; mt += (short)odr["h930"]; mt += (short)odr["h1000"]; mt += (short)odr["h1030"]; mt += (short)odr["h1100"]; mt += (short)odr["h1130"]; mt += (short)odr["h1200"]; mt += (short)odr["h1230"]; mt += (short)odr["h1300"]; mt += (short)odr["h1330"]; mt += (short)odr["h1400"]; mt += (short)odr["h1430"]; mt += (short)odr["h1500"]; mt += (short)odr["h1530"]; mt += (short)odr["h1600"]; mt += (short)odr["h1630"]; mt += (short)odr["h1700"]; mt += (short)odr["h1730"]; mt += (short)odr["h1800"]; mt += (short)odr["h1830"]; } odr.Close(); lblMonth.Text = "" + (mt / 2); } 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.ddResource.SelectedIndexChanged += new System.EventHandler(this.OnResSelect); this.btnSet.Click += new System.EventHandler(this.OnSet); this.btnZero.Click += new System.EventHandler(this.OnZero); this.btnUpdate.Click += new System.EventHandler(this.OnUpdate); this.btnReset.Click += new System.EventHandler(this.OnReset); this.CalOffer.SelectionChanged += new System.EventHandler(this.OnCalSelect); this.Load += new System.EventHandler(this.Page_Load); } #endregion /// /// Event fired when the user clicks on the set button. /// Set all schedule table entries. /// private void OnSet(object sender, System.EventArgs e) { H800.Text = "1"; H830.Text = "1"; H900.Text = "1"; H930.Text = "1"; H1000.Text = "1"; H1030.Text = "1"; H1100.Text = "1"; H1130.Text = "1"; H1200.Text = "1"; H1230.Text = "1"; H1300.Text = "1"; H1330.Text = "1"; H1400.Text = "1"; H1430.Text = "1"; H1500.Text = "1"; H1530.Text = "1"; H1600.Text = "1"; H1630.Text = "1"; H1700.Text = "1"; H1730.Text = "1"; H1800.Text = "1"; H1830.Text = "1"; } /// /// Event fired when the user clicks on the set button. /// Unset all schedule table entries. /// private void OnZero(object sender, System.EventArgs e) { H800.Text = "0"; H830.Text = "0"; H900.Text = "0"; H930.Text = "0"; H1000.Text = "0"; H1030.Text = "0"; H1100.Text = "0"; H1130.Text = "0"; H1200.Text = "0"; H1230.Text = "0"; H1300.Text = "0"; H1330.Text = "0"; H1400.Text = "0"; H1430.Text = "0"; H1500.Text = "0"; H1530.Text = "0"; H1600.Text = "0"; H1630.Text = "0"; H1700.Text = "0"; H1730.Text = "0"; H1800.Text = "0"; H1830.Text = "0"; } /// /// Checks schedule content. /// /// false if the schedule is invalid private bool validate() { if (!H800.Text.Equals("0") && !H800.Text.Equals("1")) { lblStatus.Text = "8h time invalid; enter 0 or 1"; return false; } if (!H830.Text.Equals("0") && !H830.Text.Equals("1")) { lblStatus.Text = "8h30 time invalid; enter 0 or 1"; return false; } if (!H900.Text.Equals("0") && !H900.Text.Equals("1")) { lblStatus.Text = "9h time invalid; enter 0 or 1"; return false; } if (!H930.Text.Equals("0") && !H930.Text.Equals("1")) { lblStatus.Text = "9h30 time invalid; enter 0 or 1"; return false; } if (!H1000.Text.Equals("0") && !H1000.Text.Equals("1")) { lblStatus.Text = "10h time invalid; enter 0 or 1"; return false; } if (!H1030.Text.Equals("0") && !H1030.Text.Equals("1")) { lblStatus.Text = "10h30 time invalid; enter 0 or 1"; return false; } if (!H1100.Text.Equals("0") && !H1100.Text.Equals("1")) { lblStatus.Text = "11h time invalid; enter 0 or 1"; return false; } if (!H1130.Text.Equals("0") && !H1130.Text.Equals("1")) { lblStatus.Text = "11h30 time invalid; enter 0 or 1"; return false; } if (!H1200.Text.Equals("0") && !H1200.Text.Equals("1")) { lblStatus.Text = "12h time invalid; enter 0 or 1"; return false; } if (!H1230.Text.Equals("0") && !H1230.Text.Equals("1")) { lblStatus.Text = "12h30 time invalid; enter 0 or 1"; return false; } if (!H1300.Text.Equals("0") && !H1300.Text.Equals("1")) { lblStatus.Text = "13h time invalid; enter 0 or 1"; return false; } if (!H1330.Text.Equals("0") && !H1330.Text.Equals("1")) { lblStatus.Text = "13h30 time invalid; enter 0 or 1"; return false; } if (!H1400.Text.Equals("0") && !H1400.Text.Equals("1")) { lblStatus.Text = "14h time invalid; enter 0 or 1"; return false; } if (!H1430.Text.Equals("0") && !H1430.Text.Equals("1")) { lblStatus.Text = "14h30 time invalid; enter 0 or 1"; return false; } if (!H1500.Text.Equals("0") && !H1500.Text.Equals("1")) { lblStatus.Text = "15h time invalid; enter 0 or 1"; return false; } if (!H1530.Text.Equals("0") && !H1530.Text.Equals("1")) { lblStatus.Text = "15h30 time invalid; enter 0 or 1"; return false; } if (!H1600.Text.Equals("0") && !H1600.Text.Equals("1")) { lblStatus.Text = "8h time invalid; enter 0 or 1"; return false; } if (!H1630.Text.Equals("0") && !H1630.Text.Equals("1")) { lblStatus.Text = "16h30 time invalid; enter 0 or 1"; return false; } if (!H1700.Text.Equals("0") && !H1700.Text.Equals("1")) { lblStatus.Text = "17h time invalid; enter 0 or 1"; return false; } if (!H1730.Text.Equals("0") && !H1730.Text.Equals("1")) { lblStatus.Text = "17h30 time invalid; enter 0 or 1"; return false; } if (!H1800.Text.Equals("0") && !H1800.Text.Equals("1")) { lblStatus.Text = "18h time invalid; enter 0 or 1"; return false; } if (!H1830.Text.Equals("0") && !H1830.Text.Equals("1")) { lblStatus.Text = "18h30 time invalid; enter 0 or 1"; return false; } return true; } /// /// Updates total, available and booked entries of the resource tables /// /// Database connection /// Database transaction /// User selected on the DropDown list /// Date /// null in case of success, reason otherwise private string buildTotal(OleDbConnection odc, OleDbTransaction odt, string id, DateTime dt) { long ticks = dt.ToFileTime(); OleDbCommand odcmd = new OleDbCommand( "select * from resources where id <> 'total ' and id <> 'available ' and " + "id <> 'booked ' and id <> '" + id.PadRight(10, ' ') + "' and time=" + ticks, odc, odt); OleDbDataReader odr = odcmd.ExecuteReader(); ArrayList al = new ArrayList(); int h800 = int.Parse(H800.Text); int h830 = int.Parse(H830.Text); int h900 = int.Parse(H900.Text); int h930 = int.Parse(H930.Text); int h1000 = int.Parse(H1000.Text); int h1030 = int.Parse(H1030.Text); int h1100 = int.Parse(H1100.Text); int h1130 = int.Parse(H1130.Text); int h1200 = int.Parse(H1200.Text); int h1230 = int.Parse(H1230.Text); int h1300 = int.Parse(H1300.Text); int h1330 = int.Parse(H1330.Text); int h1400 = int.Parse(H1400.Text); int h1430 = int.Parse(H1430.Text); int h1500 = int.Parse(H1500.Text); int h1530 = int.Parse(H1530.Text); int h1600 = int.Parse(H1600.Text); int h1630 = int.Parse(H1630.Text); int h1700 = int.Parse(H1700.Text); int h1730 = int.Parse(H1730.Text); int h1800 = int.Parse(H1800.Text); int h1830 = int.Parse(H1830.Text); while (odr.Read()) { h800 += (short)odr["h800"]; h830 += (short)odr["h830"]; h900 += (short)odr["h900"]; h930 += (short)odr["h930"]; h1000 += (short)odr["h1100"]; h1030 += (short)odr["h1030"]; h1100 += (short)odr["h1100"]; h1130 += (short)odr["h1130"]; h1200 += (short)odr["h1200"]; h1230 += (short)odr["h1230"]; h1300 += (short)odr["h1300"]; h1330 += (short)odr["h1330"]; h1400 += (short)odr["h1400"]; h1430 += (short)odr["h1430"]; h1500 += (short)odr["h1500"]; h1530 += (short)odr["h1530"]; h1600 += (short)odr["h1600"]; h1630 += (short)odr["h1630"]; h1700 += (short)odr["h1700"]; h1730 += (short)odr["h1730"]; h1800 += (short)odr["h1800"]; h1830 += (short)odr["h1830"]; } odr.Close(); int a800 = h800; int a830 = h830; int a900 = h900; int a930 = h930; int a1000 = h1000; int a1030 = h1030; int a1100 = h1100; int a1130 = h1130; int a1200 = h1200; int a1230 = h1230; int a1300 = h1300; int a1330 = h1330; int a1400 = h1400; int a1430 = h1430; int a1500 = h1500; int a1530 = h1530; int a1600 = h1600; int a1630 = h1630; int a1700 = h1700; int a1730 = h1730; int a1800 = h1800; int a1830 = h1830; odcmd.CommandText = "select * from resources where id='booked ' and time=" + ticks; odr = odcmd.ExecuteReader(); if (odr.Read()) { string date = dt.Month + "/" + dt.Day + "/" + dt.Year; a800 -= (short)odr["h800"]; if (a800 < 0) { odr.Close(); return "Invalid change: not enough resources at 8h on " + date; } a830 -= (short)odr["h830"]; if (a830 < 0) { odr.Close(); return "Invalid change: not enough resources at 8h30 on " + date; } a900 -= (short)odr["h900"]; if (a900 < 0) { odr.Close(); return "Invalid change: not enough resources at 9h on " + date; } a930 -= (short)odr["h930"]; if (a930 < 0) { odr.Close(); return "Invalid change: not enough resources at 9h30 on " + date; } a1000 -= (short)odr["h1000"]; if (a1000 < 0) { odr.Close(); return "Invalid change: not enough resources at 10h on " + date; } a1030 -= (short)odr["h1030"]; if (a1030 < 0) { odr.Close(); return "Invalid change: not enough resources at 10h30 on " + date; } a1100 -= (short)odr["h1100"]; if (a1100 < 0) { odr.Close(); return "Invalid change: not enough resources at 11h on " + date; } a1130 -= (short)odr["h1130"]; if (a1130 < 0) { odr.Close(); return "Invalid change: not enough resources at 11h30 on " + date; } a1200 -= (short)odr["h1200"]; if (a1200 < 0) { odr.Close(); return "Invalid change: not enough resources at 12h on " + date; } a1230 -= (short)odr["h1230"]; if (a1230 < 0) { odr.Close(); return "Invalid change: not enough resources at 12h30 on " + date; } a1300 -= (short)odr["h1300"]; if (a1300 < 0) { odr.Close(); return "Invalid change: not enough resources at 13h on " + date; } a1330 -= (short)odr["h1330"]; if (a1330 < 0) { odr.Close(); return "Invalid change: not enough resources at 13h30 on " + date; } a1400 -= (short)odr["h1400"]; if (a1400 < 0) { odr.Close(); return "Invalid change: not enough resources at 14h on " + date; } a1430 -= (short)odr["h1430"]; if (a1430 < 0) { odr.Close(); return "Invalid change: not enough resources at 14h30 on " + date; } a1500 -= (short)odr["h1500"]; if (a1500 < 0) { odr.Close(); return "Invalid change: not enough resources at 15h on " + date; } a1530 -= (short)odr["h1530"]; if (a1530 < 0) { odr.Close(); return "Invalid change: not enough resources at 15h30 on " + date; } a1600 -= (short)odr["h1600"]; if (a1600 < 0) { odr.Close(); return "Invalid change: not enough resources at 16h on " + date; } a1630 -= (short)odr["h1630"]; if (a1630 < 0) { odr.Close(); return "Invalid change: not enough resources at 16h30 on " + date; } a1700 -= (short)odr["h1700"]; if (a1700 < 0) { odr.Close(); return "Invalid change: not enough resources at 17h on " + date; } a1730 -= (short)odr["h1730"]; if (a1730 < 0) { odr.Close(); return "Invalid change: not enough resources at 17h30 on " + date; } a1800 -= (short)odr["h1800"]; if (a1800 < 0) { odr.Close(); return "Invalid change: not enough resources at 18h on " + date; } a1830 -= (short)odr["h1830"]; if (a1830 < 0) { odr.Close(); return "Invalid change: not enough resources at 18h30 on " + date; } } odr.Close(); odcmd.CommandText = "select * from resources where id='total ' and time=" + ticks; odr = odcmd.ExecuteReader(); if (odr.Read()) { odr.Close(); odcmd.CommandText = "update resources set h800=" + h800 + ", h830=" + h830 + ", h900=" + h900 + ", h930=" + h930 + ", h1000=" + h1000 + ", h1030=" + h1030 + ", h1100=" + h1100 + ", h1130=" + h1130 + ", h1200=" + h1200 + ", h1230=" + h1230 + ", h1300=" + h1300 + ", h1330=" + h1330 + ", h1400=" + h1400 + ", h1430=" + h1430 + ", h1500=" + h1500 + ", h1530=" + h1530 + ", h1600=" + h1600 + ", h1630=" + h1630 + ", h1700=" + h1700 + ", h1730=" + h1730 + ", h1800=" + h1800 + ", h1830=" + h1830 + " where id='total ' and time=" + ticks; odcmd.ExecuteNonQuery(); } else { odr.Close(); odcmd.CommandText = "insert into resources (id, time, h800, h830, h900, h930," + "h1000, h1030, h1100, h1130, h1200, h1230, h1300, h1330, h1400, h1430, h1500," + "h1530, h1600, h1630, h1700, h1730, h1800, h1830) values ('total', " + ticks + ", " + h800 + ", " + h830 + ", " + h900 + ", " + h930 + ", " + h1000 + ", " + h1030 + ", " + h1100 + ", " + h1130 + ", " + h1200 + ", " + h1230 + ", " + h1300 + ", " + h1330 + ", " + h1400 + ", " + h1430 + ", " + h1500 + ", " + h1530 + ", " + h1600 + ", " + h1630 + ", " + h1700 + ", " + h1730 + ", " + h1800 + ", " + h1830 + ")"; odcmd.ExecuteNonQuery(); } odcmd.CommandText = "select * from resources where id='available ' and time=" + ticks; odr = odcmd.ExecuteReader(); if (odr.Read()) { odr.Close(); odcmd.CommandText = "update resources set h800=" + a800 + ", h830=" + a830 + ", h900=" + a900 + ", h930=" + a930 + ", h1000=" + a1000 + ", h1030=" + a1030 + ", h1100=" + a1100 + ", h1130=" + a1130 + ", h1200=" + a1200 + ", h1230=" + a1230 + ", h1300=" + a1300 + ", h1330=" + a1330 + ", h1400=" + a1400 + ", h1430=" + a1430 + ", h1500=" + a1500 + ", h1530=" + a1530 + ", h1600=" + a1600 + ", h1630=" + a1630 + ", h1700=" + a1700 + ", h1730=" + a1730 + ", h1800=" + a1800 + ", h1830=" + a1830 + " where id='available ' and time=" + ticks; odcmd.ExecuteNonQuery(); } else { odr.Close(); odcmd.CommandText = "insert into resources (id, time, h800, h830, h900, h930," + "h1000, h1030, h1100, h1130, h1200, h1230, h1300, h1330, h1400, h1430, h1500," + "h1530, h1600, h1630, h1700, h1730, h1800, h1830) values ('available', " + ticks + ", " + a800 + ", " + a830 + ", " + a900 + ", " + a930 + ", " + a1000 + ", " + a1030 + ", " + a1100 + ", " + a1130 + ", " + a1200 + ", " + a1230 + ", " + a1300 + ", " + a1330 + ", " + a1400 + ", " + a1430 + ", " + a1500 + ", " + a1530 + ", " + a1600 + ", " + a1630 + ", " + a1700 + ", " + a1730 + ", " + a1800 + ", " + a1830 + ")"; odcmd.ExecuteNonQuery(); } return null; } /// /// Event fired when the user clicks on the Update button. /// Calls validate, buildsTotal and bind. /// private void OnUpdate(object sender, System.EventArgs e) { ListItem li = ddResource.SelectedItem; string id = li.Value; if (!validate()) return; OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); OleDbTransaction odt = odc.BeginTransaction(); SelectedDatesCollection sdc = CalOffer.SelectedDates; IEnumerator ie = sdc.GetEnumerator(); string msg = null; DateTime dt = DateTime.Today; bool isFirst = true; while(ie.MoveNext()) { DateTime dsel = (DateTime)ie.Current; if (isFirst) { dt = dsel; isFirst = false; } long ticks = dsel.ToFileTime(); OleDbCommand odcmd = new OleDbCommand("select * from resources where id='" + id.PadRight(10, ' ') + "' and time=" + ticks, odc, odt); OleDbDataReader odr = odcmd.ExecuteReader(); if (odr.Read()) { odr.Close(); odcmd.CommandText = "update resources set h800=" + H800.Text + ", h830=" + H830.Text + ", h900=" + H900.Text + ", h930=" + H930.Text + ", h1000=" + H1000.Text + ", h1030=" + H1030.Text + ", h1100=" + H1100.Text + ", h1130=" + H1130.Text + ", h1200=" + H1200.Text + ", h1230=" + H1230.Text + ", h1300=" + H1300.Text + ", h1330=" + H1330.Text + ", h1400=" + H1400.Text + ", h1430=" + H1430.Text + ", h1500=" + H1500.Text + ", h1530=" + H1530.Text + ", h1600=" + H1600.Text + ", h1630=" + H1630.Text + ", h1700=" + H1700.Text + ", h1730=" + H1730.Text + ", h1800=" + H1800.Text + ", h1830=" + H1830.Text + " where id='" + id.PadRight(10, ' ') + "' and time=" + ticks; odcmd.ExecuteNonQuery(); } else { odr.Close(); odcmd.CommandText = "insert into resources (id, time, h800, h830, h900, h930," + "h1000, h1030, h1100, h1130, h1200, h1230, h1300, h1330, h1400, h1430, h1500," + "h1530, h1600, h1630, h1700, h1730, h1800, h1830) values ('" + id + "', " + ticks + ", " + H800.Text + ", " + H830.Text + ", " + H900.Text + ", " + H930.Text + ", " + H1000.Text + ", " + H1030.Text + ", " + H1100.Text + ", " + H1130.Text + ", " + H1200.Text + ", " + H1230.Text + ", " + H1300.Text + ", " + H1330.Text + ", " + H1400.Text + ", " + H1430.Text + ", " + H1500.Text + ", " + H1530.Text + ", " + H1600.Text + ", " + H1630.Text + ", " + H1700.Text + ", " + H1730.Text + ", " + H1800.Text + ", " + H1830.Text + ")"; odcmd.ExecuteNonQuery(); } if ((msg = buildTotal(odc, odt, id, dsel)) != null) { odt.Rollback(); lblStatus.Text = msg; break; } } if (msg == null) odt.Commit(); bind(odc, id, dt); odc.Close(); } /// /// Event fired when the user clicks on the Rest button. /// Restores the schedule from the database (before an update). /// Calls bind. /// private void OnReset(object sender, System.EventArgs e) { DateTime dt = DateTime.Today; if (CalOffer.SelectedDates.Count > 0) dt = CalOffer.SelectedDates[0]; ListItem li = ddResource.SelectedItem; string id = li.Value; OleDbConnection odc = new OleDbConnection(Global.connectionString); odc.Open(); bind(odc, id, dt); odc.Close(); } /// /// Event fired when the user selects a day on the calendar. /// Calls Reset. /// private void OnCalSelect(object sender, System.EventArgs e) { OnReset(sender, e); } /// /// Called when the user selects a resource on the DropDown list. /// Calls Reset. /// private void OnResSelect(object sender, System.EventArgs e) { if (ddResource.SelectedItem.Text.Equals("total ") || ddResource.SelectedItem.Text.Equals("available ") || ddResource.SelectedItem.Text.Equals("booked ")) { H800.Enabled = false; H830.Enabled = false; H900.Enabled = false; H930.Enabled = false; H1000.Enabled = false; H1030.Enabled = false; H1100.Enabled = false; H1130.Enabled = false; H1200.Enabled = false; H1230.Enabled = false; H1300.Enabled = false; H1330.Enabled = false; H1400.Enabled = false; H1430.Enabled = false; H1500.Enabled = false; H1530.Enabled = false; H1600.Enabled = false; H1630.Enabled = false; H1700.Enabled = false; H1730.Enabled = false; H1800.Enabled = false; H1830.Enabled = false; btnSet.Enabled = false; btnZero.Enabled = false; btnUpdate.Enabled = false; btnReset.Enabled = false; } else { H800.Enabled = true; H830.Enabled = true; H900.Enabled = true; H930.Enabled = true; H1000.Enabled = true; H1030.Enabled = true; H1100.Enabled = true; H1130.Enabled = true; H1200.Enabled = true; H1230.Enabled = true; H1300.Enabled = true; H1330.Enabled = true; H1400.Enabled = true; H1430.Enabled = true; H1500.Enabled = true; H1530.Enabled = true; H1600.Enabled = true; H1630.Enabled = true; H1700.Enabled = true; H1730.Enabled = true; H1800.Enabled = true; H1830.Enabled = true; btnSet.Enabled = true; btnZero.Enabled = true; btnUpdate.Enabled = true; btnReset.Enabled = true; } OnReset(sender, e); } } }