Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        protected override void OnDayRender(TableCell cell, CalendarDay day)
        {
            base.OnDayRender(cell, day);
            int dotw = 0;

            switch (DateTime.Now.DayOfWeek)
            {
            case DayOfWeek.Monday: dotw = -1; break;

            case DayOfWeek.Tuesday: dotw = -2; break;

            case DayOfWeek.Wednesday: dotw = -3; break;

            case DayOfWeek.Thursday: dotw = -4; break;

            case DayOfWeek.Friday: dotw = -5; break;
            }
            if (day.IsWeekend || (day.Date < DateTime.Now.AddDays(dotw)))
            {
                cell.Visible = false;
            }
            else if (day.Date > DateTime.Now.AddDays(dotw) && day.Date.AddDays(1) < DateTime.Now)
            {
                cell.Controls.Clear();
            }
            else
            {
                string s = Terms.isTerm(day.Date);
                if (s == "invalid" || ((DateTime.Now.AddDays(this.maxday) < day.Date) && !isAdmin))
                {
                    cell.Controls.Clear();
                    cell.Controls.Add(new LiteralControl(day.DayNumberText));
                }
                else
                {
                    cell.Controls.Clear();
                    cell.Controls.Add(new LiteralControl(string.Format("<a target=\"_top\" href=\"./#" + day.Date.ToShortDateString() + "\" id=\"" + day.Date.ToShortDateString().Replace('/', '-') + "\">" + day.DayNumberText + "</a>")));
                    HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(day.Date.Date);
                    cell.CssClass += " " + s;
                    LiteralControl lc = new LiteralControl("<div class=\"QuickView\">");
                    foreach (Resource resource in config.BookingSystem.Resources.Values)
                    {
                        if (resource.Enabled)
                        {
                            lc.Text += "<div>";
                            foreach (Lesson lesson in config.BookingSystem.Lessons)
                            {
                                lc.Text += string.Format("<span class=\"{0}\" title=\"{1} {2}: {0}\"></span>", (!bs.isStatic(resource.Name, lesson.Name) && bs.islessonFree(resource.Name, lesson.Name)) ? "free" : "booked", lesson.Name, resource.Name);
                            }
                            lc.Text += "</div>";
                        }
                    }
                    lc.Text += "</div>";
                    cell.Controls.AddAt(0, lc);
                }
            }
        }