public Form_Main() { InitializeComponent(); dateTimePicker_MaxDateMissions.Value = DateTime.Now.AddMonths(1); dateTimePicker_MinDate.Value = DateTime.Now.AddDays(-4); dateTimePicker_MinDate.ValueChanged += dateTimePicker_MinDate_ValueChanged; dateTimePicker_MaxDateMissions.ValueChanged += dateTimePicker_MaxDateMissions_ValueChanged; Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox); // Thread.Sleep(5000); // Microsoft.Office.Interop.Outlook.MailItem mailItem = (Outlook.MailItem)app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); toolStripStatusLabel_Name.Text = "חובר כ: " + app.Session.CurrentUser.Name; LoadMissions(dateTimePicker_MinDate.Value, dateTimePicker_MaxDateMissions.Value); // List<string> lst = new List<string>(); // lst.Add(("*****@*****.**")); // AssignMission(DateTime.Now.AddDays(1), "בוsdfא", "asdasasd",lst); // mailItem.Subject = "This is the subject"; // mailItem.To = "*****@*****.**"; // mailItem.Body = "This is the message."; // mailItem.Importance = Outlook.OlImportance.olImportanceLow; // mailItem.Display(false); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) { /** Microsoft.Office.Interop.Excel.Application xlApp = new * Microsoft.Office.Interop.Excel.Application(); * * if (xlApp == null) * { * MessageBox.Show("Excel is not properly installed!!"); * return; * } * Workbook xlWorkBook = xlApp.Workbooks.Add(); * Worksheet xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); * xlWorkSheet.Cells[1, 1] = "Subject"; * xlWorkSheet.Cells[1, 2] = "Date"; * xlWorkSheet.Cells[1, 3] = "Start-Time"; * xlWorkSheet.Cells[1, 4] = "End-Time"; * xlWorkSheet.Cells[1, 5] = "Locatiom"; * xlWorkBook.SaveAs("TimeSheetDBMS.xls");*/ Microsoft.Office.Interop.Outlook.NameSpace ns = this.Application.GetNamespace("MAPI"); if (ns.Categories["MyCategory"] == null) { ns.Categories.Add("MyCategory", Outlook.OlCategoryColor.olCategoryColorDarkGreen, Outlook.OlCategoryShortcutKey.olCategoryShortcutKeyNone); } }
private void FindContactEmailByName(string firstName, string lastName) { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace outlookNameSpace = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = outlookNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox); Outlook.MAPIFolder contactsFolder = outlookNameSpace.GetDefaultFolder( Microsoft.Office.Interop.Outlook. OlDefaultFolders.olFolderContacts); Outlook.Items contactItems = contactsFolder.Items; try { Outlook.ContactItem contact = (Outlook.ContactItem)contactItems. Find(String.Format("[FirstName]='{0}' and " + "[LastName]='{1}'", firstName, lastName)); if (contact != null) { // return contact; contact.Display(true); } else { MessageBox.Show("The contact information was not found."); } } catch (System.Exception ex) { throw ex; } }
public AddMission(Mission m) { InitializeComponent(); Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 100, 100)); dateTimePicker_dueDate.Value = DateTime.Now.AddDays(7); this.updateMission = true; Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox); foreach (string reci in m.Recipients) { listBox_Recipients.Items.Add(reci); } this.currentMission = m; textBox_Sbuject.Text = m.Title; richTextBox_Body.Text = m.Body; dateTimePicker_dueDate.Value = m.DueDate; this.orginizer = app.Session.CurrentUser.Name; label_Title.Text = "עדכן משימה"; button_Add.Text = "עדכן"; EnableButtonsInUpdate(m.Orginizer); }
public void LoadMissions(DateTime min, DateTime max) { missions = new List <Mission>(); appointments = new List <AppointmentItem>(); if (dataGridView_Display.InvokeRequired) { dataGridView_Display.Invoke(new MethodInvoker(delegate { dataGridView_Display.Rows.Clear(); })); } else { dataGridView_Display.Rows.Clear(); } Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox); // Thread.Sleep(5000); Outlook.Folder calFolder = app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; Outlook.Items items = GetAppointmentsInRange(calFolder, dateTimePicker_MinDate.Value, dateTimePicker_MaxDateMissions.Value); // double val = 0; if (items == null) { return; } for (int i = 0; i < items.Count; i++) { Outlook.AppointmentItem item = (Outlook.AppointmentItem)items[i + 1]; if (item.Companies == "Missionator") { if (dataGridView_Display.InvokeRequired) { dataGridView_Display.Invoke(new MethodInvoker(delegate { addRows(item); })); } else { addRows(item); } } if (statusStrip_Status.InvokeRequired) { statusStrip_Status.Invoke(new MethodInvoker(delegate { toolStripProgressBar_Progress.Value = (((i + 1) * 100) / items.Count); })); } else { toolStripProgressBar_Progress.Value = (((i + 1) * 100) / items.Count); } System.Windows.Forms.Application.DoEvents(); } }
public AddMission() { InitializeComponent(); Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 100, 100)); dateTimePicker_dueDate.Value = DateTime.Now.AddDays(7); Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox); listBox_Recipients.Items.Add(app.Session.CurrentUser.Address); this.orginizer = app.Session.CurrentUser.Name; }
public bool AssignMission(Mission m) { // try // { Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox); // Thread.Sleep(5000); Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem) app.CreateItem(Outlook.OlItemType.olAppointmentItem); // string org = newAppointment.Organizer; // newAppointment.Resources = "Missionator"; newAppointment.Companies = "Missionator"; newAppointment.Start = m.DueDate.Date; newAppointment.End = m.DueDate.Date; // newAppointment.Location = "ConferenceRoom #2345"; newAppointment.RTFBody = System.Text.Encoding.UTF8.GetBytes(@" {\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} {\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red122\green122\blue192;} \qr\b\fs48" + GetRtfUnicodeEscapedString(m.Title) + @"\b0\line\line \cf2\fs36 " + DateTime.Now.ToShortDateString() + @":\line \cf1\fs24 " + GetRtfUnicodeEscapedString(m.Body.Replace("\n", @"\line")) + @"\line\line \fs20\cf3 " + GetRtfUnicodeEscapedString("נקבע מועד הגשה ל: ") + m.DueDate.ToShortDateString().Replace('/', '.') + @"\cf1\fs24\line } "); //newAppointment.RTFBody = @"{\rtf1\ansi\b "+m.Title+@"\b0.}"; //newAppointment.RTFBody += "<h2><b>" + DateTime.Now.ToShortDateString() + ":</b></h2><br/>"; //newAppointment.RTFBody += "<body>" + m.Body + "</body>"; // newAppointment.RTFBody.Replace("\n", "<br/>"); newAppointment.AllDayEvent = true; newAppointment.Subject = m.Title; string resourceBuilder = ""; foreach (string recipient in m.Recipients) { newAppointment.Recipients.Add(recipient); if (m.Recipients.IndexOf(recipient) > 0) { resourceBuilder += ","; } resourceBuilder += recipient; } newAppointment.Mileage = resourceBuilder; Outlook.Recipients sentTo = newAppointment.Recipients; //Outlook.Recipient sentInvite = null; //sentInvite = sentTo.Add("Holly Holt"); //sentInvite.Type = (int)Outlook.OlMeetingRecipientType // .olRequired; //sentInvite = sentTo.Add("David Junca "); //sentInvite.Type = (int)Outlook.OlMeetingRecipientType // .olOptional; //sentTo.ResolveAll(); newAppointment.Save(); // newAppointment.Display(true); // } // catch (Exception ex) //{ // MessageBox.Show("The following error occurred: " + ex.Message); // return false; //} return(true); }
public bool UpdateMissionDate(AppointmentItem appointment, Mission m, string update) { if (update == "" && m.DueDate == appointment.Start) { return(false); } Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); Microsoft.Office.Interop.Outlook.NameSpace ns = app.GetNamespace("MAPI"); Outlook.MAPIFolder f = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox); byte[] origText = (byte[])appointment.RTFBody; string s = System.Text.Encoding.UTF8.GetString(origText); s = s.Remove(s.LastIndexOf('}'), 1); s += @"\line\fs36\cf2 " + DateTime.Now.ToString(); if (update != "") { s += @" \line\cf1\fs24 " + GetRtfUnicodeEscapedString(update.Replace("\n", @"\line")); } if (m.DueDate != appointment.Start) { s += @" \line\line\fs20\cf3 " + GetRtfUnicodeEscapedString("נקבע מועד הגשה חדש: ") + m.DueDate.ToShortDateString().Replace('/', '.'); } s += @"\line}"; appointment.Start = m.DueDate; appointment.End = m.DueDate; // System.Buffer.BlockCopy(origText, 0, merged, 0, origText.Length); // System.Buffer.BlockCopy(newText, 0, merged, origText.Length, newText.Length); appointment.RTFBody = System.Text.Encoding.UTF8.GetBytes(s); appointment.Companies = "Missionator"; string resourceBuilder = ""; foreach (string recipient in m.Recipients) { appointment.Recipients.Add(recipient); if (m.Recipients.IndexOf(recipient) > 0) { resourceBuilder += ","; } resourceBuilder += recipient; } appointment.Mileage = resourceBuilder; Outlook.Recipients sentTo = appointment.Recipients; appointment.Save(); //Outlook.AppointmentItem newAppointment = // (Outlook.AppointmentItem) // app.CreateItem(Outlook.OlItemType.olAppointmentItem); //// string org = newAppointment.Organizer; //// newAppointment.Resources = "Missionator"; //newAppointment.Companies = "Missionator"; //newAppointment.Start = m.DueDate.Date; //newAppointment.End = m.DueDate.Date; //// newAppointment.Location = "ConferenceRoom #2345"; //newAppointment.RTFBody = System.Text.Encoding.UTF8.GetBytes(s);; //newAppointment.AllDayEvent = true; //newAppointment.Subject = m.Title; //string resourceBuilder = ""; //foreach (string recipient in m.Recipients) //{ // newAppointment.Recipients.Add(recipient); // if (m.Recipients.IndexOf(recipient) > 0) // resourceBuilder += ","; // resourceBuilder += recipient; //} //newAppointment.Resources = resourceBuilder; //Outlook.Recipients sentTo = newAppointment.Recipients; //newAppointment.Save(); return(true); }