示例#1
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Create an instance of Outlook Application class
            Outlook.Application outlookApp = new Outlook.Application();

            // Create an instance of AppointmentItem object and set the properties:
            Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem);

            oAppointment.Subject  = "subject of appointment";
            oAppointment.Body     = "body text of appointment";
            oAppointment.Location = "Appointment location";

            // Set the start date and end dates
            oAppointment.Start = Convert.ToDateTime("01/22/2010 10:00:00 AM");
            oAppointment.End   = Convert.ToDateTime("01/22/2010 2:00:00 PM");

            // Save the appointment
            oAppointment.Save();

            // Send the appointment
            Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
            mailItem.To = "*****@*****.**";
            mailItem.Send();
        }
示例#2
0
        private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            e.Handled = true;
            Boolean status;

            if (lvCompanyName.SelectedItem == null)
            {
                MessageBox.Show("Please enter Company name or use Outlook for your personal schedule");
                return;
            }

            ComboBoxItem typeItem = (ComboBoxItem)cbType.SelectedItem;

            String type = "";

            if (cbType.SelectedIndex != -1)
            {
                type = typeItem.Content.ToString();
            }
            String   meetingDate = dateOfMetting.Text;
            String   startTime   = cbStartTime.Text;
            String   endTime     = cbEndTime.Text;
            Customer customer    = (Customer)lvCompanyName.SelectedItem;

            // Schedule schedule = new Schedule();
            _Schedule.CustomerID   = customer.CustomerId;
            _Schedule.Type         = type;
            _Schedule.ScheduleDate = DateTime.Parse(meetingDate);
            _Schedule.StartTime    = startTime;
            _Schedule.EndTime      = endTime;
            _Schedule.SalesRepId   = Convert.ToInt32(Application.Current.Resources["UserName"]);

            Outlook._Application _app;
            try
            {
                _app = (Outlook.Application)Marshal.GetActiveObject("Outlook.Application");
            }
            // catch (System.Runtime.InteropServices.COMException ex)
            catch (Exception)
            {
                //MessageBox.Show("Outlook is not opened under Administrator, close OUtlook and click OK." + ex.Message, "Message", MessageBoxButton.OK, MessageBoxImage.Information);
                _app = new Outlook.Application();
            }
            try
            {
                Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)_app.CreateItem(Outlook.OlItemType.olAppointmentItem);
                oAppointment.Subject     = _Schedule.Subject;
                oAppointment.Body        = _Schedule.Note;
                oAppointment.Start       = Convert.ToDateTime(meetingDate + " " + startTime);
                oAppointment.End         = Convert.ToDateTime(meetingDate + " " + endTime);
                oAppointment.Importance  = Outlook.OlImportance.olImportanceHigh;
                oAppointment.ReminderSet = true;
                oAppointment.ReminderMinutesBeforeStart = 30;
                oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
                oAppointment.Save();
                if (type == "Face To Face")
                {
                    Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
                    mailItem.To = customer.Email;
                    mailItem.Send();
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                MessageBox.Show("Error sending email" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            try
            {
                db = new Database();
                if (!db.CheckAppointment(_Schedule))
                {
                    db.AddAppointment(_Schedule);
                }
                else
                {
                    MessageBox.Show("You have an appointment at" + _Schedule.ScheduleDate + " between " + _Schedule.StartTime +
                                    " and " + _Schedule.EndTime + "\n Please select another date and time.", "Add Appointment", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            MessageBox.Show("Your Appointment successfully registered!!", "Add Appointment", MessageBoxButton.OK, MessageBoxImage.Information);
            this.Close();

            //refresh the list
            var             calendar     = new Calendar();
            List <Schedule> scheduleList = db.GetAllAppointment();

            calendar.lvShowWorkDay.Items.Clear();
            foreach (Schedule s in scheduleList)
            {
                calendar.lvShowWorkDay.Items.Add(s);
            }
            var mainWin = Application.Current.Windows.Cast <Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;

            mainWin.frTest.Refresh();
        }