public JSONBooking[][] RemoveBooking(string Date, JSONBooking booking, string i) { HAP.Data.SQL.WebEvents.Log(DateTime.Now, "BookingSystem.Remove", ((HAP.AD.User)Membership.GetUser()).UserName, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version, HttpContext.Current.Request.UserHostName, "Removing " + booking.Name); HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); Booking b = bs.getBooking(booking.Room, booking.Lesson)[int.Parse(i)]; try { BookingRules.Execute(b, hapConfig.Current.BookingSystem.Resources[b.Room], bs, BookingRuleType.Booking, true); } catch (Exception ex) { HAP.Web.Logging.EventViewer.Log("Booking System JSON API", ex.ToString() + "\nMessage:\n" + ex.Message + "\nStack Trace:\n" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); } try { if (!string.IsNullOrEmpty(b.uid) && hapConfig.Current.SMTP.Enabled) { iCalGenerator.GenerateCancel(b, DateTime.Parse(Date)); if (hapConfig.Current.BookingSystem.Resources[booking.Room].EmailAdmins) { iCalGenerator.GenerateCancel(b, DateTime.Parse(Date), true); } } } catch (Exception ex) { HAP.Web.Logging.EventViewer.Log("Booking System JSON API", ex.ToString() + "\nMessage:\n" + ex.Message + "\nStack Trace:\n" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error); } XmlDocument doc = HAP.BookingSystem.BookingSystem.BookingsDoc; XmlNodeList nodes = doc.SelectNodes("/Bookings/Booking[@date='" + DateTime.Parse(Date).ToShortDateString() + "' and @lesson[contains(., '" + booking.Lesson + "')] and @room='" + booking.Room + "']"); doc.SelectSingleNode("/Bookings").RemoveChild(nodes[int.Parse(i)]); HAP.BookingSystem.BookingSystem.BookingsDoc = doc; return(LoadRoom(Date, booking.Room)); }
public JSONBooking[][] LoadResource(string StartDate, string EndDate, string Resource) { List <JSONBooking[]> bookings = new List <JSONBooking[]>(); DateTime start = DateTime.Parse(StartDate); DateTime end = DateTime.Parse(EndDate); foreach (DateTime day in EachDay(start, end)) { HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(day); List <JSONBooking> js = new List <JSONBooking>(); foreach (Lesson lesson in hapConfig.Current.BookingSystem.Lessons) { DateTime d = day.Date.AddHours(lesson.StartTime.Hour).AddMinutes(lesson.StartTime.Minute).AddSeconds(lesson.StartTime.Second); DateTime d2 = day.Date.AddHours(lesson.EndTime.Hour).AddMinutes(lesson.EndTime.Minute).AddSeconds(lesson.EndTime.Second); foreach (Booking b in bs.getBooking(Resource, lesson.Name)) { JSONBooking j = new JSONBooking(b); j.Date = d.ToString("yyyy-MM-ddTHH:mm:ssZ"); j.Date2 = d2.ToString("yyyy-MM-ddTHH:mm:ssZ"); if (b.Resource.Type == ResourceType.Loan) { j.Lesson = lesson.Name; } js.Add(j); } } bookings.Add(js.ToArray()); } WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json; return(bookings.ToArray()); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; hapConfig config = hapConfig.Current; if (context.Request.QueryString["op"] == "getBookings") { DateTime date = DateTime.Parse(context.Request.QueryString["d"]); HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(date); string format = "{0}:{1}:{2}:{3}"; List <string> bookings = new List <string>(); foreach (Resource br in config.BookingSystem.Resources.Values) { foreach (Lesson l in config.BookingSystem.Lessons) { foreach (Booking b in bs.getBooking(br.Name, l.Name)) { bookings.Add(string.Format(format, b.Lesson, b.Name, b.Room, b.Username == "Not Booked" ? "" : b.User.Notes)); } } } context.Response.Write(string.Join("\n", bookings.ToArray())); } else if (context.Request.QueryString["op"] == "getTimes") { foreach (Lesson l in config.BookingSystem.Lessons) { context.Response.Write(string.Format("{0},{1},{2}\n", l.Name, l.StartTime, l.EndTime)); } } }
protected override void RenderContents(HtmlTextWriter writer) { hapConfig config = hapConfig.Current; HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(Date); writer.WriteLine("<div class=\"lessoncol\" style=\"border-left-width: 1px;\">"); writer.Write("<h2>"); writer.Write("Lesson"); writer.WriteLine("</h2>"); bool alt = false; foreach (Lesson les in config.BookingSystem.Lessons) { writer.Write("<div{0}>", alt ? " class=\"alt\"" : ""); writer.Write(les.Name); writer.WriteLine("</div>"); alt = !alt; } writer.WriteLine("</div>"); alt = false; foreach (Resource res in config.BookingSystem.Resources.Values) { string Room = res.Name; writer.WriteLine("<div class=\"lessoncol\">"); writer.Write("<h2>"); writer.Write(res.Name); writer.WriteLine("</h2>"); foreach (Lesson lesson in config.BookingSystem.Lessons) { foreach (Booking b in bs.getBooking(Room, lesson.Name)) { string lessonname = b.Name; if (lessonname.Length > 17) { lessonname = lessonname.Remove(17) + "..."; } if (lessonname.Length > 16 && b.Static) { lessonname = lessonname.Remove(14) + "..."; } if (b.Name == "FREE") { writer.Write("<div{0}>FREE</div>", alt ? " class=\"alt\"" : ""); } else { writer.Write("<div{2}><span>{0}<i>with {1}</i></span></div>", lessonname, b.User.Notes, alt ? " class=\"alt\"" : ""); } alt = !alt; } } alt = false; writer.Write("</div>"); } }
public JSONBooking[][] Load(string StartDate, string EndDate) { List <JSONBooking[]> bookings = new List <JSONBooking[]>(); DateTime start = DateTime.Parse(StartDate); DateTime end = DateTime.Parse(EndDate); foreach (DateTime day in EachDay(start, end)) { HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(day); List <JSONBooking> js = new List <JSONBooking>(); foreach (Lesson lesson in hapConfig.Current.BookingSystem.Lessons) { DateTime d = day.Date.AddHours(lesson.StartTime.Hour).AddMinutes(lesson.StartTime.Minute).AddSeconds(lesson.StartTime.Second); DateTime d2 = day.Date.AddHours(lesson.EndTime.Hour).AddMinutes(lesson.EndTime.Minute).AddSeconds(lesson.EndTime.Second); int a = 0; foreach (Resource r in hapConfig.Current.BookingSystem.Resources.Values) { if (isVisible(r.ShowTo, r.HideFrom)) { foreach (Booking b in bs.getBooking(r.Name, lesson.Name)) { JSONBooking j = new JSONBooking(b); j.Date = d.AddSeconds(a).ToString("yyyy-MM-ddTHH:mm:ssZ"); j.Date2 = d2.ToString("yyyy-MM-ddTHH:mm:ssZ"); if (b.Resource.Type == ResourceType.Loan) { j.Lesson = lesson.Name; } if (b.Name == "CHARGING" || b.Name == "UNAVAILABLE") { js.Add(j); break; } js.Add(j); } } a++; } } bookings.Add(js.ToArray()); } WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json; return(bookings.ToArray()); }
public JSONBooking[][] LoadRoom(string Date, string Resource) { Resource = HttpUtility.UrlDecode(Resource, System.Text.Encoding.Default).Replace("%20", " "); List <JSONBooking[]> bookings = new List <JSONBooking[]>(); HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); foreach (Lesson lesson in hapConfig.Current.BookingSystem.Lessons) { List <JSONBooking> js = new List <JSONBooking>(); foreach (Booking b in bs.getBooking(Resource, lesson.Name)) { object result = null; JSONBooking j = null; if (b.Name == "FREE") { result = BookingRules.Execute(b, hapConfig.Current.BookingSystem.Resources[Resource], bs, BookingRuleType.PreProcess, false); if (result != null) { j = new JSONBooking((Booking)result); } } if (j == null) { j = new JSONBooking(b); } if (b.Resource.Type == ResourceType.Loan) { j.Lesson = lesson.Name; } if (b.Name == "CHARGING" || b.Name == "UNAVAILABLE") { js.Add(j); break; } js.Add(j); } bookings.Add(js.ToArray()); } WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json; return(bookings.ToArray()); }
protected void Page_Load(object sender, EventArgs e) { Response.ExpiresAbsolute = DateTime.Now; bs = new HAP.BookingSystem.BookingSystem(); config = hapConfig.Current; if (Page.FindControl(Room) != null && Page.FindControl(Room) is Panel) { Panel room = Page.FindControl(Room) as Panel; room.Visible = true; if (Room.Contains('_')) { foreach (string s in Room.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries)) { Repeater r = room.FindControl(s) as Repeater; List <Booking> bookings = new List <Booking>(); foreach (Lesson lesson in config.BookingSystem.Lessons) { foreach (Booking b in bs.getBooking(s, lesson.Name)) { bookings.Add(b); } } r.DataSource = bookings.ToArray(); r.DataBind(); } } else { foreach (Control c in room.Controls) { if (c.GetType() == typeof(Repeater)) { Repeater r = c as Repeater; List <Booking> bookings = new List <Booking>(); foreach (Lesson lesson in config.BookingSystem.Lessons) { foreach (Booking b in bs.getBooking(Room, lesson.Name)) { bookings.Add(b); } } r.DataSource = bookings.ToArray(); r.DataBind(); } } } } else { roomlabel.Text = Room; defaultview.Visible = true; foreach (Control c in defaultview.Controls) { if (c.GetType() == typeof(Repeater)) { Repeater r = c as Repeater; List <Booking> bookings = new List <Booking>(); foreach (Lesson lesson in config.BookingSystem.Lessons) { foreach (Booking b in bs.getBooking(Room, lesson.Name)) { bookings.Add(b); } } r.DataSource = bookings.ToArray(); r.DataBind(); } } } }
public JSONBooking[][] Book(string Date, JSONBooking booking) { HAP.Data.SQL.WebEvents.Log(DateTime.Now, "BookingSystem.Book", ((HAP.AD.User)Membership.GetUser()).UserName, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version, HttpContext.Current.Request.UserHostName, "Booking " + booking.Name); try { HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)); if (booking.Static) { if (!bs.isStatic(booking.Room, booking.Lesson)) { bs.addStaticBooking(new Booking { Name = booking.Name, Lesson = booking.Lesson, Username = booking.Username, Room = booking.Room, Day = bs.DayNumber }); } else { throw new Exception("Static Booking Already Exists for period " + booking.Lesson + " with resource " + booking.Room); } } else { hapConfig config = hapConfig.Current; if (!config.BookingSystem.Resources[booking.Room].CanShare) { // if bookings can't be shared, need to check here that booking doesn't already exist Booking[] existing = bs.getBooking(booking.Room, booking.Lesson); if (existing[0] != null && !existing[0].Static && existing[0].Name != "FREE") { throw new Exception("Booking Already Exists for period " + booking.Lesson + " with resource " + booking.Room); } } XmlDocument doc = HAP.BookingSystem.BookingSystem.BookingsDoc; XmlElement node = doc.CreateElement("Booking"); node.SetAttribute("date", DateTime.Parse(Date).ToShortDateString()); node.SetAttribute("lesson", booking.Lesson); if (config.BookingSystem.Resources[booking.Room].Type == ResourceType.Laptops) { node.SetAttribute("ltroom", booking.LTRoom); node.SetAttribute("ltheadphones", booking.LTHeadPhones.ToString()); } else if (config.BookingSystem.Resources[booking.Room].Type == ResourceType.Equipment || config.BookingSystem.Resources[booking.Room].Type == ResourceType.Loan) { node.SetAttribute("equiproom", booking.EquipRoom); } node.SetAttribute("room", booking.Room); node.SetAttribute("uid", booking.Username + DateTime.Now.ToString(iCalGenerator.DateFormat)); node.SetAttribute("username", booking.Username); node.SetAttribute("count", booking.Count.ToString()); node.SetAttribute("name", booking.Name); if (booking.Count >= 0) { node.SetAttribute("count", booking.Count.ToString()); } if (!string.IsNullOrWhiteSpace(booking.Notes)) { node.SetAttribute("notes", booking.Notes); } doc.SelectSingleNode("/Bookings").AppendChild(node); HAP.BookingSystem.BookingSystem.BookingsDoc = doc; Booking[] b1 = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)).getBooking(booking.Room, booking.Lesson); Booking b = b1[b1.Length - 1]; if (config.SMTP.Enabled) { iCalGenerator.Generate(b, DateTime.Parse(Date)); if (config.BookingSystem.Resources[b.Room].EmailAdmins) { iCalGenerator.Generate(b, DateTime.Parse(Date), true); } } BookingRules.Execute(b, config.BookingSystem.Resources[b.Room], new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)), BookingRuleType.Booking, false); } } catch (Exception e) { HAP.Web.Logging.EventViewer.Log(HttpContext.Current.Request.RawUrl, e.ToString() + "\nMessage:\n" + e.Message + "\n\nStack Trace:\n" + e.StackTrace, System.Diagnostics.EventLogEntryType.Error); } return(LoadRoom(Date, booking.Room)); }