Пример #1
0
        private static void getOutlookInstance(RecurrencePattern oPattern, DateTime instanceDate, ref AppointmentItem ai)
        {
            //First check if this is not yet an exception
            try {
                ai = oPattern.GetOccurrence(instanceDate);
            } catch { }
            if (ai == null)
            {
                //The Outlook API is rubbish as the date argument is how it exists NOW (not OriginalDate).
                //If this has changed >1 in Google then there's no way of knowing what it might be!

                Exceptions oExcps = null;
                try {
                    oExcps = oPattern.Exceptions;
                    for (int e = 1; e <= oExcps.Count; e++)
                    {
                        Microsoft.Office.Interop.Outlook.Exception oExcp = null;
                        try {
                            oExcp = oExcps[e];
                            if (oExcp.OriginalDate.Date == instanceDate.Date)
                            {
                                try {
                                    log.Debug("Found Outlook exception for " + instanceDate);
                                    if (exceptionIsDeleted(oExcp))
                                    {
                                        log.Debug("This exception is deleted.");
                                        break;
                                    }
                                    else
                                    {
                                        ai = oExcp.AppointmentItem;
                                        break;
                                    }
                                } catch (System.Exception ex) {
                                    MainForm.Instance.Logboxout(ex.Message);
                                    MainForm.Instance.Logboxout("If this keeps happening, please restart OGCS.");
                                    break;
                                } finally {
                                    OutlookCalendar.ReleaseObject(oExcp);
                                }
                            }
                        } finally {
                            oExcp = (Microsoft.Office.Interop.Outlook.Exception)OutlookCalendar.ReleaseObject(oExcp);
                        }
                    }
                } finally {
                    oExcps = (Exceptions)OutlookCalendar.ReleaseObject(oExcps);
                }
                if (ai == null)
                {
                    log.Warn("Unable to find Outlook exception for " + instanceDate);
                }
            }
        }
        public void GetAllCalendarItems()
        {
            Microsoft.Office.Interop.Outlook.Application oApp = null;
            NameSpace  mapiNamespace        = null;
            MAPIFolder CalendarFolder       = null;
            Items      outlookCalendarItems = null;

            oApp                 = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace        = oApp.GetNamespace("MAPI");;
            CalendarFolder       = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;

            foreach (AppointmentItem item in outlookCalendarItems)
            {
                if (item.IsRecurring)
                {
                    RecurrencePattern rp   = item.GetRecurrencePattern();
                    DateTime          date = DateTime.Now;

                    DateTime        first = new DateTime((int)date.Year, (int)date.Month, (int)date.Day, item.Start.Hour, item.Start.Minute, 0);
                    DateTime        last  = new DateTime((int)date.Year, (int)date.Month, (int)date.Day);
                    AppointmentItem recur = null;

                    for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
                    {
                        try
                        {
                            recur = rp.GetOccurrence(cur);
                            //MessageBox.Show(recur.Subject + " -> " + cur.ToLongDateString());
                        }
                        catch
                        { }
                    }
                }
                else
                {
                    Guna2Panel panel = new Guna2Panel();
                    panel.BackColor = Color.White;
                    panel.Size      = new Size(1080, 50);
                    Guna2HtmlLabel message = new Guna2HtmlLabel();
                    message.Text      = item.Subject + " --> " + item.Start.ToLongDateString();
                    message.Font      = new Font("SegoeUI", 10);
                    message.Location  = new Point(0, 15);
                    message.ForeColor = Color.FromArgb(71, 69, 94);
                    panel.Controls.Add(message);

                    //flowLayoutPanel3.Controls.Add(panel);
                    //MessageBox.Show(item.Subject + " -> " + item.Start.ToLongDateString());
                }
            }
        }
Пример #3
0
        private static AppointmentItem getOutlookInstance(RecurrencePattern oPattern, DateTime instanceDate)
        {
            //First check if this is not yet an exception
            AppointmentItem ai = null;

            try {
                ai = oPattern.GetOccurrence(instanceDate);
            } catch { }
            if (ai == null)
            {
                //The Outlook API is rubbish as the date argument is how it exists NOW (not OriginalDate).
                //If this has changed >1 in Google then there's no way of knowing what it might be!

                foreach (Microsoft.Office.Interop.Outlook.Exception oExp in oPattern.Exceptions)
                {
                    if (oExp.OriginalDate.Date == instanceDate.Date)
                    {
                        try {
                            log.Debug("Found Outlook exception for " + instanceDate);
                            if (exceptionIsDeleted(oExp))
                            {
                                log.Debug("This exception is deleted.");
                                return(null);
                            }
                            else
                            {
                                return(oExp.AppointmentItem);
                            }
                        } catch (System.Exception ex) {
                            MainForm.Instance.Logboxout(ex.Message);
                            MainForm.Instance.Logboxout("If this keeps happening, please restart OGCS.");
                            break;
                        }
                    }
                }
                if (ai == null)
                {
                    log.Warn("Unable to find Outlook exception for " + instanceDate);
                }
            }
            return(ai);
        }
Пример #4
0
        public static void DeleteEventOutlook(CancelMeetingRoomForm data)
        {
            try
            {
                Application app = new Application();

                MAPIFolder        calendar      = app.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
                Items             calendarItems = calendar.Items;
                AppointmentItem   item          = calendarItems["Test Appointment"] as AppointmentItem;
                RecurrencePattern pattern       = item.GetRecurrencePattern();
                AppointmentItem   itemDelete    = pattern.GetOccurrence(new DateTime(2006, 6, 28, 8, 0, 0));

                if (itemDelete != null)
                {
                    itemDelete.Delete();
                }
            }
            catch (System.Exception)
            {
            }
        }
 private static AppointmentItem getOutlookInstance(RecurrencePattern oPattern, DateTime instanceDate) {
     //First check if this is not yet an exception
     AppointmentItem ai = null;
     try {
         ai = oPattern.GetOccurrence(instanceDate);
     } catch { }
     if (ai == null) {
         //The Outlook API is rubbish as the date argument is how it exists NOW (not OriginalDate). 
         //If this has changed >1 in Google then there's no way of knowing what it might be!
         
         foreach (Microsoft.Office.Interop.Outlook.Exception oExp in oPattern.Exceptions) {
             if (oExp.OriginalDate.Date == instanceDate.Date) {
                 try {
                     log.Debug("Found Outlook exception for " + instanceDate);
                     if (exceptionIsDeleted(oExp)) {
                         log.Debug("This exception is deleted.");
                         return null;
                     } else {
                         return oExp.AppointmentItem;
                     }
                 } catch (System.Exception ex) {
                     MainForm.Instance.Logboxout(ex.Message);
                     MainForm.Instance.Logboxout("If this keeps happening, please restart OGCS.");
                     break;
                 }
             }
         }
         if (ai == null) log.Warn("Unable to find Outlook exception for " + instanceDate);
     }
     return ai;
 }
        private static void UpdateOutlookAppointment(AppointmentItem appointment, string mtg_id, MeetingRequest request, bool reload_pattern = false)
        {
            int mrbs_id = -1;

            int.TryParse(mtg_id.Substring(0, mtg_id.IndexOf(";")), out mrbs_id);

            // appointment.Subject = request.Description;

            if ((appointment.RecurrenceState != OlRecurrenceState.olApptMaster) || (appointment.EntryID == ""))
            {
                appointment.Start = request.Start;
                appointment.End   = request.End;
            }

            appointment.Location = String.Format("{0} - {1}", Database.GetAreaNameByRoomId(request.RoomId), Database.GetRoomNameById(request.RoomId));

            if (request.RepeatTypeId > 0)
            {
                RecurrencePattern pattern;

                if (reload_pattern)
                {
                    appointment.ClearRecurrencePattern();
                }

                pattern = appointment.GetRecurrencePattern();

                switch (request.RepeatTypeId)
                {
                case 1:
                    pattern.RecurrenceType = OlRecurrenceType.olRecursDaily;
                    pattern.Interval       = 1;
                    break;

                case 2:
                    char[] rev = request.RepeatWeeklyCode.ToCharArray();

                    pattern.RecurrenceType = OlRecurrenceType.olRecursWeekly;
                    pattern.Interval       = request.RepeatNumberOfWeeks;
                    pattern.DayOfWeekMask  = (OlDaysOfWeek)Convert.ToInt32(new string(request.RepeatWeeklyCode.ToCharArray().Reverse().ToArray()), 2);
                    break;

                case 3:
                    if (request.RepeatMonthlyByWeekday)
                    {
                        pattern.RecurrenceType = OlRecurrenceType.olRecursMonthNth;
                        pattern.Interval       = 1;
                        pattern.DayOfWeekMask  = (OlDaysOfWeek)((int)Math.Pow(2, request.RepeatWeekdayOfMonth));
                        pattern.Instance       = request.RepeatWeekdaysOfMonth;
                    }
                    else
                    {
                        pattern.RecurrenceType = OlRecurrenceType.olRecursMonthly;
                        pattern.Interval       = 1;
                        pattern.DayOfMonth     = request.RepeatDayOfMonth;
                    }
                    break;

                case 4:
                    pattern.RecurrenceType = OlRecurrenceType.olRecursYearly;
                    break;
                }

                pattern.Duration         = (request.End - request.Start).Minutes;
                pattern.EndTime          = request.RepeatEnd.Date + request.End.TimeOfDay;
                pattern.NoEndDate        = false;
                pattern.PatternStartDate = request.Start;
                pattern.PatternEndDate   = request.RepeatEnd + request.End.TimeOfDay;
                pattern.StartTime        = request.Start;
            }

            try
            {
                appointment.UserProperties.Add("MJ-MRBS-ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
            }
            catch (UnauthorizedAccessException)
            {
                //appointment.UserProperties.Add("MJ-MRBS-ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
            }

            appointment.UserProperties["MJ-MRBS-ID"].Value = mtg_id;
            if (!appointment.Body.Contains("has been linked to a reservation in MRBS."))
            {
                appointment.Body += String.Format("\n\n\n***** This {0} has been linked to a reservation in MRBS. To change the {0} location, you must use the Modify Reservation button in the ribbon. *****", appointment.MeetingStatus == OlMeetingStatus.olNonMeeting ? "appointment" : "meeting");
            }

            appointment.Save();
            if (request.RepeatTypeId > 0)
            {
                RecurrencePattern pattern   = appointment.GetRecurrencePattern();
                List <Entry>      entries   = Database.GetAllEntries(mrbs_id);
                List <Entry>      conflicts = Database.FindConflicts(request, mrbs_id);

                foreach (Entry conflict in conflicts)
                {
                    DateTime start_time = Database.UnixTimeStampToDateTime(conflict.start_time);

                    AppointmentItem item = pattern.GetOccurrence(start_time);
                    item.Delete();
                }

                foreach (Entry entry in entries)
                {
                    try
                    {
                        DateTime        start_time = Database.UnixTimeStampToDateTime(entry.start_time);
                        AppointmentItem item       = pattern.GetOccurrence(start_time);
                        item.UserProperties.Add("MJ-MRBS-ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
                        item.UserProperties["MJ-MRBS-ID"].Value = String.Format("{0};{1}", entry.id, entry.ical_uid);
                        item.Save();
                    }
                    catch { }
                }

                appointment.Save();
            }
        }
        private void loadCalenderEvents()
        {
            calender_events_table.ColumnCount     = 8;
            calender_events_table.Columns[0].Name = "Subject";
            calender_events_table.Columns[1].Name = "Organizer";
            calender_events_table.Columns[2].Name = "Location";

            calender_events_table.Columns[3].Name = "StartTime";
            //Styling
            calender_events_table.Columns["StartTime"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //
            calender_events_table.Columns[4].Name = "EndTime";
            //Styling
            calender_events_table.Columns["EndTime"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //
            calender_events_table.Columns[5].Name = "StartDate";
            //Styling
            calender_events_table.Columns["StartDate"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //
            calender_events_table.Columns[6].Name = "EndDate";
            //Styling
            calender_events_table.Columns["EndDate"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //
            calender_events_table.Columns[7].Name = "AllDayEvent";
            //Styling
            calender_events_table.Columns["AllDayEvent"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            //

            //Styling
            for (int i = 3; i <= 7; i++)
            {
                calender_events_table.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                calender_events_table.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            Microsoft.Office.Interop.Outlook.Application oApp = null;
            NameSpace  mapiNamespace        = null;
            MAPIFolder CalendarFolder       = null;
            Items      outlookCalendarItems = null;

            oApp                 = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace        = oApp.GetNamespace("MAPI");;
            CalendarFolder       = mapiNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;

            foreach (AppointmentItem item in outlookCalendarItems)
            {
                if (item.IsRecurring)
                {
                    RecurrencePattern rp   = item.GetRecurrencePattern();
                    DateTime          date = DateTime.Now;

                    DateTime        first = new DateTime((int)date.Year, (int)date.Month, (int)date.Day, item.Start.Hour, item.Start.Minute, 0);
                    DateTime        last  = new DateTime((int)date.Year, (int)date.Month, (int)date.Day);
                    AppointmentItem recur = null;

                    for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
                    {
                        try
                        {
                            recur = rp.GetOccurrence(cur);
                            //MessageBox.Show(recur.Subject + " -> " + cur.ToLongDateString());
                            int             rowID = calender_events_table.Rows.Add();
                            DataGridViewRow row   = calender_events_table.Rows[rowID];
                            row.Cells["Subject"].Value   = recur.Subject;
                            row.Cells["Organizer"].Value = recur.Organizer;
                            if (recur.Location == null)
                            {
                                row.Cells["Location"].Value = "Not Set";
                            }
                            else
                            {
                                row.Cells["Location"].Value = recur.Location;
                            }
                            row.Cells["StartTime"].Value   = recur.Start.TimeOfDay.ToString();
                            row.Cells["EndTime"].Value     = recur.End.TimeOfDay.ToString();
                            row.Cells["StartDate"].Value   = recur.Start.Date.ToShortDateString();
                            row.Cells["End Date"].Value    = recur.End.Date.ToShortDateString();
                            row.Cells["AllDayEvent"].Value = recur.AllDayEvent;
                        }
                        catch
                        { }
                    }
                }
                else
                {
                    int             rowID = calender_events_table.Rows.Add();
                    DataGridViewRow row   = calender_events_table.Rows[rowID];
                    row.Cells["Subject"].Value   = item.Subject;
                    row.Cells["Organizer"].Value = item.Organizer;
                    if (item.Location == null)
                    {
                        row.Cells["Location"].Value = "Not Set";
                    }
                    else
                    {
                        row.Cells["Location"].Value = item.Location;
                    }
                    row.Cells["StartTime"].Value   = item.Start.TimeOfDay.ToString();
                    row.Cells["EndTime"].Value     = item.End.TimeOfDay.ToString();
                    row.Cells["StartDate"].Value   = item.Start.Date.ToShortDateString();
                    row.Cells["EndDate"].Value     = item.End.Date.ToShortDateString();
                    row.Cells["AllDayEvent"].Value = item.AllDayEvent;
                }
            }

            calender_events_table.Columns[0].HeaderText = "Subject";
            calender_events_table.Columns[1].HeaderText = "Organizer";
            calender_events_table.Columns[2].HeaderText = "Location";
            calender_events_table.Columns[3].HeaderText = "Start Time";
            calender_events_table.Columns[4].HeaderText = "End Time";
            calender_events_table.Columns[5].HeaderText = "Start Date";
            calender_events_table.Columns[6].HeaderText = "End Date";
            calender_events_table.Columns[7].HeaderText = "All Day Event";

            DataGridViewImageColumn viewBtn   = new DataGridViewImageColumn();
            DataGridViewImageColumn deleteBtn = new DataGridViewImageColumn();

            viewBtn.Name        = "view_btn";
            viewBtn.HeaderText  = "";
            viewBtn.Image       = Resources.view;
            viewBtn.ImageLayout = DataGridViewImageCellLayout.Zoom;
            calender_events_table.Columns.Insert(8, viewBtn);

            deleteBtn.Name        = "delete_btn";
            deleteBtn.HeaderText  = "";
            deleteBtn.Image       = Resources.delete;
            deleteBtn.ImageLayout = DataGridViewImageCellLayout.Zoom;
            calender_events_table.Columns.Insert(9, deleteBtn);
            //Set Column Width
            for (int i = 0; i <= 7; i++)
            {
                DataGridViewColumn tt_id_col = calender_events_table.Columns[i];
                if (i == 0)
                {
                    tt_id_col.Width = 230;
                }
                else if (i == 1)
                {
                    tt_id_col.Width = 160;
                }
                else if (i == 2)
                {
                    tt_id_col.Width = 100;
                }
                else if (i == 3)
                {
                    tt_id_col.Width = 80;
                }
                else if (i == 4)
                {
                    tt_id_col.Width = 80;
                }
                else if (i == 5)
                {
                    tt_id_col.Width = 80;
                }
                else if (i == 6)
                {
                    tt_id_col.Width = 80;
                }
                else if (i == 7)
                {
                    tt_id_col.Width = 110;
                }
            }
        }