Ejemplo n.º 1
0
        protected void ActivateNext1MeetingButton_Click(object sender, EventArgs e)
        {
            DeleteCurrentMeeting();

            //Find the next1 meeting
            Meeting next1Meeting = db.Meetings.Where(m => m.MeetingID == 1 && m.RoomID == room.RoomID).FirstOrDefault();
            Meeting startingMeeting;

            if (next1Meeting != null)
            {
                //Create a new starting meeting
                startingMeeting = new Meeting
                {
                    MeetingID  = 0,
                    CalendarID = next1Meeting.CalendarID,
                    Name       = next1Meeting.Name,
                    StartTime  = next1Meeting.StartTime,
                    EndTime    = next1Meeting.EndTime,
                    RoomID     = room.RoomID
                };

                //Add the meeting to the db under the current meeting
                db.Meetings.Add(startingMeeting);
                db.SaveChanges();
            }
            else
            {
                //Create a new Room Available starting meeting
                startingMeeting = new Meeting
                {
                    MeetingID  = 0,
                    CalendarID = "",
                    Name       = "Room Available",
                    StartTime  = null,
                    EndTime    = null,
                    RoomID     = room.RoomID
                };
                //Add the meeting to the db under the current meeting
                db.Meetings.Add(startingMeeting);
                db.SaveChanges();

                GetExchangeWebServicesAppointments();
                SyncMeetingSuggestionsInDatabase();
            }

            //Delete the meeting that just got promoted
            if (next1Meeting != null)
            {
                db.Meetings.Remove(next1Meeting);
                db.SaveChanges();

                SyncMeetingSuggestionsInDatabase();
            }

            EnableNormalControls();



            // Automatically update calendar if no suggestions available
            if (db.Meetings.Where(m => m.RoomID == room.RoomID && m.MeetingID > 0 && m.CalendarID != "").FirstOrDefault() == null)
            {
                GetExchangeWebServicesAppointments();
                SyncMeetingSuggestionsInDatabase();
            }

            RunStartupRoutine();
        }
Ejemplo n.º 2
0
 public void AddMeetingToDB(Meeting meeting)
 {
     db.Meetings.Add(meeting);
     //db.SaveChanges();
 }
Ejemplo n.º 3
0
        public void SyncMeetingSuggestionsInDatabase()
        {
            // Find the current meeting
            Meeting currentMeeting = db.Meetings.Where(m => m.MeetingID == 0 && m.RoomID == room.RoomID).FirstOrDefault();
            bool    roomAvailable  = true;

            // If the database has no meeting entries
            if (currentMeeting == null)
            {
                try
                {
                    // Add a current meeting (set room to Room Available status)
                    db.Meetings.Add(new Meeting
                    {
                        CalendarID = "",
                        Name       = "Room Available",
                        MeetingID  = 0,
                        RoomID     = room.RoomID,
                        StartTime  = null,
                        EndTime    = null
                    });

                    // Save current meeting to database
                    db.SaveChanges();

                    //Update Suggestions list with EWS calendar
                    GetExchangeWebServicesAppointments();


                    // Update current Meeting to not be null
                    currentMeeting = db.Meetings.Where(m => m.MeetingID == 0 && m.RoomID == room.RoomID).FirstOrDefault();


                    // Update current Meeting to not be null
                    currentMeeting = db.Meetings.Where(m => m.MeetingID == 0 && m.RoomID == room.RoomID).FirstOrDefault();
                }
                catch (Exception ex)
                {
                    nowMeetingNameLabel.Text      = ex.ToString();
                    nowMeetingNameLabel.Font.Size = 10;
                }
            }

            // If the database has meeting entries
            if (currentMeeting != null)
            {
                // See if the room is Available
                roomAvailable = currentMeeting.Name.Equals("Room Available");

                if (roomAvailable)
                {
                    // Set the Now Div to Room Available Settings
                    //Show the room is available
                    SetNowDiv("Room Available", "", "", (room.RoomName + ":"));
                    AddNewMeetingButton.Visible       = true;
                    ClearCurrentMeetingButton.Visible = false;

                    nowInfoBox.Style.Remove("background");

                    nowInfoBox.Style.Add("background", "#007600");
                    nowInfoBox.Style.Add("background", "-webkit-gradient-webkit-gradient(linear, left top, left bottom, from(#fed403), to(#c9a800))");
                    nowInfoBox.Style.Add("background", "-moz-linear-gradient(top, #007600, #006f00))");
                    nowInfoBox.Style.Add("background", "linear-gradient(to bottom, #007600, #006f00)");
                }
                else
                {
                    // Set the Now Div to Current Meeting Settings
                    //Indicate the current Meeting
                    SetNowDiv(TruncateMyLongString(currentMeeting.Name, maxStringLength),
                              currentMeeting.StartTime.Value.ToShortTimeString(),
                              currentMeeting.EndTime.Value.ToShortTimeString(),
                              (room.RoomName + ":"));
                    if (currentMeeting.CalendarID.ToString() == "")
                    {
                        SetNowDiv(currentMeeting.Name, "", "", room.RoomName.ToString() + ":");
                    }

                    nowInfoBox.Style.Remove("background");

                    nowInfoBox.Style.Add("background", "#606060");

                    AddNewMeetingButton.Visible       = false;
                    ClearCurrentMeetingButton.Visible = true;
                }
            }

            // Meeting Suggestions - not including current meeting
            List <Meeting> meetingSuggestions = new List <Meeting>();

            meetingSuggestions = db.Meetings.Where(m => !m.MeetingID.Equals(currentMeeting.MeetingID) && m.RoomID == room.RoomID).ToList();

            // Sync up the Meeting Database with the new suggestions
            foreach (var m in db.Meetings.Where(m => m.RoomID == room.RoomID && m.MeetingID != 0))
            {
                db.Meetings.Remove(m);
            }
            //Counting index
            int index = 1;

            foreach (var m in meetingSuggestions)
            {
                // Add the new meeting with the new adjusted index
                db.Meetings.Add(new Meeting
                {
                    MeetingID  = index,
                    Name       = m.Name,
                    CalendarID = m.CalendarID,
                    RoomID     = m.RoomID,
                    StartTime  = m.StartTime,
                    EndTime    = m.EndTime
                });
                index += 1;
            }
            Meeting firstSuggestion;
            Meeting secondSuggestion;

            if (meetingSuggestions.Count >= 1)
            {
                firstSuggestion = meetingSuggestions.ElementAt(0);  //first suggestion at index = 0
            }
            else
            {
                firstSuggestion = null;
            }
            if (meetingSuggestions.Count >= 2)
            {
                secondSuggestion = meetingSuggestions.ElementAt(1); //second suggestion at index = 1
            }
            else
            {
                secondSuggestion = null;
            }

            // If a first suggestion exists
            if (firstSuggestion != null)
            {
                //Suggest the first meeting, adjusting for it's time
                if (firstSuggestion.StartTime < midnightTonight && firstSuggestion != null)
                {
                    //Indicate the next meeting suggestion
                    SetNext1Div(firstSuggestion.Name,
                                firstSuggestion.StartTime.Value.ToShortTimeString(),
                                firstSuggestion.EndTime.Value.ToShortTimeString(),
                                "Next:");
                }
                else
                {
                    //Suggest a meeting for another day
                    SetNext1Div(TruncateMyLongString(firstSuggestion.Name, maxStringLength),
                                firstSuggestion.StartTime.Value.ToShortTimeString(),
                                firstSuggestion.EndTime.Value.ToShortTimeString(),
                                "-- " + firstSuggestion.StartTime.Value.DayOfWeek.ToString() + " --");
                }
            }
            // If no first suggestion exists
            else
            {
                // Error message
                SetNext1Div("Refresh Suggestions", "", "", "");
            }

            // If a second suggestion exists
            if (secondSuggestion != null)
            {
                //Suggest the second meeting, adjusting for it's time
                if (secondSuggestion.StartTime < midnightTonight && firstSuggestion != null)
                {
                    //Indicate the next meeting suggestion
                    SetNext2Div(TruncateMyLongString(secondSuggestion.Name, maxStringLength),
                                secondSuggestion.StartTime.Value.ToShortTimeString(),
                                secondSuggestion.EndTime.Value.ToShortTimeString(),
                                "Next:");
                }
                else
                {
                    //Suggest a meeting for another day
                    SetNext2Div(secondSuggestion.Name,
                                secondSuggestion.StartTime.Value.ToShortTimeString(),
                                secondSuggestion.EndTime.Value.ToShortTimeString(),
                                "-- " + secondSuggestion.StartTime.Value.DayOfWeek.ToString() + " --");
                }
            }
            // If no second suggestion exists
            else
            {
                SetNext2Div("Refresh Suggestions", "", "", "");
            }
        }
Ejemplo n.º 4
0
 public void RemoveMeetingFromDB(Meeting meeting)
 {
     db.Meetings.Remove(meeting);
     //db.SaveChanges();
 }
Ejemplo n.º 5
0
        public void GetExchangeWebServicesAppointments()
        {
            _service = CreateExchangeService();

            if (_service.Url != null)
            {
                // Initialize values for the start and end times, and the number of appointments to retrieve.
                DateTime  startDate = DateTime.Now;
                DateTime  endDate   = startDate.AddYears(1);
                const int NUM_APPTS = 6;

                // Initialize the calendar folder object with only the folder ID.
                CalendarFolder calendar = CalendarFolder.Bind(_service, WellKnownFolderName.Calendar, new PropertySet());

                // Set the start and end time and number of appointments to retrieve.
                CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);

                // Limit the properties returned to the appointment's subject, start time, and end time.
                cView.PropertySet = new PropertySet(AppointmentSchema.Subject,
                                                    AppointmentSchema.Start,
                                                    AppointmentSchema.End);

                // Retrieve a collection of appointments by using the calendar view.
                FindItemsResults <Appointment> appointments = calendar.FindAppointments(cView);

                //Check if there are appointments
                if (appointments != null)
                {
                    // Find current meeting in database
                    Meeting currentMeeting = db.Meetings.Where(m => m.MeetingID == 0 && m.RoomID == room.RoomID).FirstOrDefault();

                    List <Appointment> inactivatedMeetings = new List <Appointment>();

                    // If meetings exist in the database
                    if (currentMeeting != null)
                    {
                        // Find appointments that are not activated
                        foreach (var a in appointments)
                        {
                            // If the selected appointment does not match the current meeting
                            if (!a.Id.Equals(currentMeeting.MeetingID))
                            {
                                inactivatedMeetings.Add(a);
                            }

                            //Save the attendees
                            //TODO: reactivate this SaveInactivatedEmployeesToDatabase(a,_service);
                        }
                        //TODO: try this
                        //SaveInactivatedEmployeesToDatabase(appointments.ElementAt(0), _service);

                        // Suggestion Counter
                        int index = 1;

                        //first delete the meeting suggestions (ID's > 0) already in database
                        foreach (var m in db.Meetings.Where(m => m.RoomID == room.RoomID && m.MeetingID != 0))
                        {
                            db.Meetings.Remove(m);
                        }

                        // Add the inactivated meetings to the Meetings database
                        foreach (var a in inactivatedMeetings)
                        {
                            try
                            {
                                // Add meeting using appointment details
                                AddMeetingToDB(new Meeting
                                {
                                    MeetingID  = index,
                                    Name       = TruncateMyLongString(a.Subject, 50),
                                    StartTime  = a.Start,
                                    EndTime    = a.End,
                                    CalendarID = a.Id.ToString(),
                                    RoomID     = room.RoomID
                                });

                                // Save database changes
                                db.SaveChanges();
                            }
                            // Catch errors adding meetings to database from EWS
                            catch (Exception ex)
                            {
                                nowMeetingNameLabel.Text      = ex.ToString();
                                nowMeetingNameLabel.Font.Size = 10;
                            }
                            // Increment index
                            index += 1;
                        }
                    }
                }
                // If no appointments are returned from EWS write out error in Now Div
                if (appointments == null)
                {
                    nowInfoBoxDescriptionLabel.Text = "Could not access Exchange Calendar";
                }
            }
        }