Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
                }
            }
        }
Esempio n. 3
0
        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());
        }
Esempio n. 4
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);
                }
            }
        }
Esempio n. 5
0
        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>");
            }
        }
Esempio n. 6
0
        public JSONBooking[][] Return(string Date, string Resource, string lesson)
        {
            hapConfig config = hapConfig.Current;

            HAP.BookingSystem.BookingSystem bs = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date));
            Booking b = new HAP.BookingSystem.BookingSystem(DateTime.Parse(Date)).getBooking(Resource, lesson)[0];

            XmlDocument   doc = HAP.BookingSystem.BookingSystem.BookingsDoc;
            List <string> newlesson = new List <string>(); bool go = false;

            foreach (Lesson l in config.BookingSystem.Lessons)
            {
                if (b.Lesson.StartsWith(l.Name))
                {
                    go = true;
                }
                if (go)
                {
                    newlesson.Add(l.Name);
                }
                if (l.Name == lesson)
                {
                    go = false;
                }
            }
            doc.SelectSingleNode("/Bookings/Booking[@date='" + DateTime.Parse(Date).ToShortDateString() + "' and @lesson[contains(., '" + lesson + "')] and @room='" + Resource + "']").Attributes["lesson"].Value = string.Join(", ", newlesson.ToArray());
            b.Lesson = string.Join(", ", newlesson.ToArray()); // update b.Lesson to reflect what just went into the XML above (ready for booking rules)

            HAP.BookingSystem.BookingSystem.BookingsDoc = doc;
            try
            {
                BookingRules.Execute(b, hapConfig.Current.BookingSystem.Resources[b.Room], bs, BookingRuleType.Return, false);
            }
            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); }

            if (config.SMTP.Enabled)
            {
                iCalGenerator.GenerateCancel(b, DateTime.Parse(Date));
                if (config.BookingSystem.Resources[b.Room].EmailAdmins)
                {
                    iCalGenerator.GenerateCancel(b, DateTime.Parse(Date), true);
                }
            }
            return(LoadRoom(Date, Resource));
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
        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());
        }
Esempio n. 9
0
        public static object Execute(Booking b, Resource r, BookingSystem bs, BookingRuleType brt, bool isRemoveEvent)
        {
            BookingRules br = new BookingRules();
            object       o  = null;

            foreach (BookingRule rule in br)
            {
                if (brt != rule.Type)
                {
                    continue;
                }

                bool matched = rule.ExecuteRule(b, r, bs, brt, isRemoveEvent, out o);
                if (matched && rule.StopProcessing)
                {
                    break;
                }
            }
            return(o);
        }
Esempio n. 10
0
 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();
             }
         }
     }
 }
Esempio n. 11
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));
        }
Esempio n. 12
0
        public bool ExecuteRule(Booking b, Resource r, BookingSystem bs, BookingRuleType brt, bool IsRemoveEvent, out object objo)
        {
            bool good = true;

            objo = null;
            foreach (BookingCondition con in Conditions)
            {
                switch (con.MasterOperation)
                {
                case BookingConditionOperation.And:
                    good = good && con.IsConditionMet(b, r, bs);
                    break;

                case BookingConditionOperation.Or:
                    good = good || con.IsConditionMet(b, r, bs);
                    break;
                }
            }
            if (good)
            {
                #region ProcessRule
                foreach (string a in this.Actions)
                {
                    try
                    {
                        if (a.ToLower().StartsWith("bookcharging(") || a.ToLower().StartsWith("bookunavailable("))
                        {
                            string   reason     = "";
                            string   c          = "";
                            int      repeat     = 1;
                            string[] conditions = null;
                            if (a.ToLower().StartsWith("bookcharging("))
                            {
                                conditions = a.Remove(0, "bookcharging(".Length).TrimStart(new char[] { '(' }).TrimEnd(new char[] { ')' }).Split(new char[] { ',' });
                                c          = a.Remove(0, "bookcharging(".Length).TrimEnd(new char[] { ')' });
                                reason     = "CHARGING";
                            }
                            else if (a.ToLower().StartsWith("bookunavailable("))
                            {
                                conditions = a.Remove(0, "bookunavailable(".Length).TrimStart(new char[] { '(' }).TrimEnd(new char[] { ')' }).Split(new char[] { ',' });
                                c          = a.Remove(0, "bookunavailable(".Length).TrimEnd(new char[] { ')' });
                                reason     = "UNAVAILABLE";
                            }

                            if (conditions.Length == 2)
                            {
                                c      = conditions[0];
                                repeat = Convert.ToInt32(BookingCondition.processCondition(conditions[1], b, r, bs));
                            }

                            object o = BookingCondition.processCondition(c, b, r, bs);
                            if (o is Booking)
                            {
                                Booking     ob     = o as Booking;
                                XmlDocument doc    = HAP.BookingSystem.BookingSystem.BookingsDoc;
                                hapConfig   config = hapConfig.Current;
                                if (!IsRemoveEvent)
                                {
                                    string lastlesson = (ob.Lesson.Contains(',') ? ob.Lesson.Split(new char[] { ',' }).Last() : ob.Lesson);
                                    int    index2     = config.BookingSystem.Lessons.FindIndex(l => l.Name == lastlesson);

                                    for (int x = 0; x < Math.Abs(repeat); x++)
                                    {
                                        int period = (repeat > 0) ? index2 + x : index2 - x;
                                        if (index2 < config.BookingSystem.Lessons.Count - x)
                                        {
                                            XmlElement node = doc.CreateElement("Booking");
                                            node.SetAttribute("date", b.Date.ToShortDateString());
                                            node.SetAttribute("lesson", config.BookingSystem.Lessons[period].Name);
                                            node.SetAttribute("room", b.Room);
                                            if (r.Type == ResourceType.Laptops)
                                            {
                                                node.SetAttribute("ltroom", "--");
                                                node.SetAttribute("ltheadphones", b.LTHeadPhones.ToString());
                                            }
                                            node.SetAttribute("username", "systemadmin");
                                            node.SetAttribute("uid", b.uid);
                                            node.SetAttribute("name", reason);
                                            doc.SelectSingleNode("/Bookings").AppendChild(node);
                                        }
                                    }
                                }
                                else
                                {
                                    string lastlesson = (ob.Lesson.Contains(',') ? ob.Lesson.Split(new char[] { ',' }).Last() : ob.Lesson);
                                    int    index2     = config.BookingSystem.Lessons.FindIndex(l => l.Name == lastlesson);
                                    for (int x = 0; x < Math.Abs(repeat); x++)
                                    {
                                        int period = (repeat > 0) ? index2 + x : index2 - x;
                                        if (index2 < config.BookingSystem.Lessons.Count - x)
                                        {
                                            if (doc.SelectSingleNode("/Bookings/Booking[@date='" + b.Date.ToShortDateString() + "' and @lesson='" + config.BookingSystem.Lessons[period].Name + "' and @room='" + b.Room + "' and @uid='" + b.uid + "']") != null)
                                            {
                                                doc.SelectSingleNode("/Bookings").RemoveChild(doc.SelectSingleNode("/Bookings/Booking[@date='" + b.Date.ToShortDateString() + "' and @lesson='" + config.BookingSystem.Lessons[period].Name + "' and @room='" + b.Room + "' and @uid='" + b.uid + "']"));
                                            }
                                        }
                                    }
                                }
                                HAP.BookingSystem.BookingSystem.BookingsDoc = doc;
                            }
                        }
                        else if (a.ToLower().StartsWith("book("))
                        {
                            string c = a.Remove(0, "book(".Length).TrimEnd(new char[] { ')' });
                            object o = BookingCondition.processCondition(c, b, r, bs);
                            if (o is Booking)
                            {
                                Booking     ob  = o as Booking;
                                XmlDocument doc = HAP.BookingSystem.BookingSystem.BookingsDoc;
                                if (!IsRemoveEvent)
                                {
                                    XmlElement node = doc.CreateElement("Booking");
                                    node.SetAttribute("date", b.Date.ToShortDateString());
                                    node.SetAttribute("lesson", ob.Lesson);
                                    node.SetAttribute("room", b.Room);
                                    if (r.Type == ResourceType.Laptops)
                                    {
                                        node.SetAttribute("ltroom", "--");
                                        node.SetAttribute("ltheadphones", b.LTHeadPhones.ToString());
                                    }
                                    else if (r.Type == ResourceType.Equipment)
                                    {
                                        node.SetAttribute("equiproom", b.EquipRoom);
                                    }
                                    node.SetAttribute("room", b.Room);
                                    node.SetAttribute("uid", b.uid);
                                    node.SetAttribute("username", b.Username);
                                    node.SetAttribute("name", b.Name);
                                    node.SetAttribute("count", b.Count.ToString());
                                    doc.SelectSingleNode("/Bookings").AppendChild(node);
                                }
                                else
                                {
                                    if (doc.SelectSingleNode("/Bookings/Booking[@date='" + b.Date.ToShortDateString() + "' and @lesson='" + ob.Lesson + "' and @room='" + b.Room + "' and @uid='" + b.uid + "']") != null)
                                    {
                                        doc.SelectSingleNode("/Bookings").RemoveChild(doc.SelectSingleNode("/Bookings/Booking[@date='" + b.Date.ToShortDateString() + "' and @lesson='" + ob.Lesson + "' and @room='" + b.Room + "' and @uid='" + b.uid + "']"));
                                    }
                                }
                                HAP.BookingSystem.BookingSystem.BookingsDoc = doc;
                            }
                        }
                        else if (a.ToLower().StartsWith("busy("))
                        {
                            string reason = a.Remove(0, "busy(".Length).TrimEnd(new char[] { ')' });
                            b.Name   = reason;
                            b.Static = true;
                            objo     = b;
                        }
                    }
                    catch (Exception ex)
                    {
                        HAP.Web.Logging.EventViewer.Log("BookingSystem.BookingRule", "Failed Action: " + Actions[0] + "\n\n" + ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
                    }
                }
                #endregion
                return(true);
            }
            return(false);
        }
Esempio n. 13
0
        public static object processCondition(string Condition, Booking b, Resource r, BookingSystem bs)
        {
            int    x = 0; bool bo = false; bool negative = false;
            string condition2 = Condition;

            if (Condition.StartsWith("-"))
            {
                negative   = true;
                condition2 = Condition.Remove(0, 1);
            }

            object ret = null;

            if (condition2.ToLower().StartsWith("resource."))
            {
                ret = processCondition(r, condition2.Remove(0, "resource.".Length));
            }
            else if (condition2.ToLower().StartsWith("booking."))
            {
                ret = processCondition(b, condition2.Remove(0, "booking.".Length));
            }
            else if (condition2.ToLower().StartsWith("bookingsystem."))
            {
                ret = processCondition(bs, condition2.Remove(0, "bookingsystem.".Length));
            }
            else if (condition2.ToLower().StartsWith("user."))
            {
                ret = processCondition(HttpContext.Current.User, condition2.Remove(0, "user.".Length));
            }
            else if (condition2.ToLower().StartsWith("datetime.now"))
            {
                ret = processCondition(DateTime.Now, condition2.Remove(0, "datetime.now.".Length));
            }

            if (ret != null)
            {
                if (negative == true)
                {
                    return(0 - Convert.ToInt32(ret));
                }
                return(ret);
            }

            if (int.TryParse(Condition, out x))
            {
                return(x);
            }
            else if (bool.TryParse(Condition, out bo))
            {
                return(bo);
            }
            else
            {
                return(Condition);
            }
        }
Esempio n. 14
0
        public bool IsConditionMet(Booking b, Resource r, BookingSystem bs)
        {
            try
            {
                object comp1 = processCondition(Condition1, b, r, bs), comp2 = processCondition(Condition2, b, r, bs);

                switch (Operation)
                {
                case BookingConditionOperation.Equals:
                    return(comp1.Equals(comp2));

                case BookingConditionOperation.GT:
                    if (comp1 is int)
                    {
                        return((int)comp1 > int.Parse(comp2.ToString()));
                    }
                    else if (comp1 is DateTime)
                    {
                        return((DateTime)comp1 > DateTime.Parse(comp2.ToString()));
                    }
                    return(false);

                case BookingConditionOperation.GTE:
                    if (comp1 is int)
                    {
                        return((int)comp1 >= int.Parse(comp2.ToString()));
                    }
                    else if (comp1 is DateTime)
                    {
                        return((DateTime)comp1 >= DateTime.Parse(comp2.ToString()));
                    }
                    return(false);

                case BookingConditionOperation.LT:
                    if (comp1 is int)
                    {
                        return((int)comp1 < int.Parse(comp2.ToString()));
                    }
                    else if (comp1 is DateTime)
                    {
                        return((DateTime)comp1 < DateTime.Parse(comp2.ToString()));
                    }
                    return(false);

                case BookingConditionOperation.LTE:
                    if (comp1 is int)
                    {
                        return((int)comp1 <= int.Parse(comp2.ToString()));
                    }
                    else if (comp1 is DateTime)
                    {
                        return((DateTime)comp1 <= DateTime.Parse(comp2.ToString()));
                    }
                    return(false);

                case BookingConditionOperation.Not:
                    return(comp1.Equals(comp2) ? false : true);

                case BookingConditionOperation.Null:
                    return(comp1 == null);

                case BookingConditionOperation.NotNull:
                    return(comp1 != null);
                }
            }
            catch { }

            return(false);
        }