Exemple #1
0
    public static string ExportActionToAppoinment(Neos.Data.Action action)
    {
        string message = string.Empty;
        try
        {
            if (action.ContactID.HasValue)
            {
                string emailContact = string.Empty;
                List<CompanyContactTelephone> contactInfoList =
                    new CompanyContactTelephoneRepository().GetContactInfo(action.ContactID.Value);
                foreach (CompanyContactTelephone item in contactInfoList)
                {
                    if (item.Type == "E")
                    {
                        emailContact = item.Tel;
                        break;
                    }
                }
                //ParamUser currentUser = SessionManager.CurrentUser;
                if (!string.IsNullOrEmpty(emailContact))
                {
                    DateTime today = DateTime.Now;
                    string fileName = WebConfig.AbsoluteExportDirectory + "\\ExportAppointment";
                    fileName += today.Hour.ToString() + "-" + today.Minute.ToString() + "-" + today.Second.ToString() + ".vcs";

                    StreamWriter writer = new StreamWriter(fileName);
                    writer.WriteLine("BEGIN:VCALENDAR");
                    writer.WriteLine(@"PRODID:-//Microsoft Corporation//Outlook MIMEDIR//EN");
                    writer.WriteLine("VERSION:1.0");
                    writer.WriteLine("BEGIN:VEVENT");

                    //Start and End Date in YYYYMMDDTHHMMSSZ format
                    if (action.Hour.HasValue)
                        today = action.Hour.Value;
                    else
                        today = today.AddDays(1);

                    writer.WriteLine("DTSTART:" + today.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));
                    writer.WriteLine("DTEND:" + today.AddHours(1).ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"));

                    string subject = action.TypeActionLabel + "-" + action.CompanyName + "-" + action.CandidateFullName;
                    writer.WriteLine("LOCATION:" + action.LieuRDV);
                    writer.WriteLine("CATEGORIES:" + subject);
                    writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + action.DescrAction);
                    writer.WriteLine("SUMMARY:" + subject);
                    writer.WriteLine("PRIORITY:3");
                    writer.WriteLine("END:VEVENT");
                    writer.WriteLine("END:VCALENDAR");
                    writer.Close();

                    //Send email
                    MailMessage mail = new MailMessage();
                    //mail.To.Add(new MailAddress("*****@*****.**"));
                    mail.To.Add(new MailAddress(emailContact));
                    mail.Subject = action.TypeActionLabel + "-"
                        + action.CompanyName + "-" + action.CandidateFullName;
                    mail.Attachments.Add(new Attachment(fileName));
                    SendMail(mail);
                    mail.Dispose();
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                }
                else
                {
                    message = ResourceManager.GetString("messageExportActionNotHaveEmail");
                }
            }
        }
        catch (System.Exception ex)
        {
            message = ex.Message;
        }
        if(message == string.Empty)
        {
            message = ResourceManager.GetString("messageExportActionSuccessfull");
        }
        return message;
    }
Exemple #2
0
    public static bool ExportActionToOutlook(Page page, Neos.Data.Action action)
    {
        string message = string.Empty;
        try
        {
            //First thing you need to do is add a reference to Microsoft Outlook 11.0 Object Library. Then, create new instance of Outlook.Application object:
            Microsoft.Office.Interop.Outlook.Application outlookApp =
                new Microsoft.Office.Interop.Outlook.Application();

            //Next, create an instance of AppointmentItem object and set the properties:
            Microsoft.Office.Interop.Outlook.AppointmentItem oAppointment =
                (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(
                    Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);

            oAppointment.Subject = action.TypeActionLabel + "-" + action.CompanyName + "-" + action.CandidateFullName;
            oAppointment.Body = action.DescrAction;
            oAppointment.Location = action.LieuRDV;

            // Set the start date
            //if(action.DateAction.HasValue)
            //    oAppointment.Start = action.DateAction.Value;
            // End date
            if (action.Hour.HasValue)
            {
                oAppointment.Start = action.Hour.Value;
            }
            // Set the reminder 15 minutes before start
            oAppointment.ReminderSet = true;
            oAppointment.ReminderMinutesBeforeStart = 15;

            //Setting the sound file for a reminder:
            oAppointment.ReminderPlaySound = true;
            //set ReminderSoundFile to a filename.

            //Setting the importance:
            //use OlImportance enum to set the importance to low, medium or high
            oAppointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;

            /* OlBusyStatus is enum with following values:
            olBusy
            olFree
            olOutOfOffice
            olTentative
            */
            oAppointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;

            //Finally, save the appointment:
            // Save the appointment
            //oAppointment.Save();

            // When you call the Save () method, the appointment is saved in Outlook.

            //string recipientsMail = string.Empty;
            //foreach (ListItem item in listEmail.Items)
            //{
            //    if (recipientsMail == string.Empty)
            //    {
            //        recipientsMail += item.Value;
            //    }
            //    else
            //    {
            //        recipientsMail += "; " + item.Value;
            //    }
            //}
            if (action.ContactID.HasValue)
            {
                string emailContact = string.Empty;
                List<CompanyContactTelephone> contactInfoList =
                    new CompanyContactTelephoneRepository().GetContactInfo(action.ContactID.Value);
                foreach (CompanyContactTelephone item in contactInfoList)
                {
                    if (item.Type == "E")
                    {
                        emailContact = item.Tel;
                        break;
                    }
                }
                //ParamUser currentUser = SessionManager.CurrentUser;
                if (!string.IsNullOrEmpty(emailContact))
                {
                    //oAppointment.RequiredAttendees = "*****@*****.**";
                    //oAppointment.OptionalAttendees = "*****@*****.**";
                    // Another useful method is ForwardAsVcal () which can be used to send the Vcs file via email.
                    Microsoft.Office.Interop.Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();

                    mailItem.To = emailContact;
                    mailItem.Send();
                    //oAppointment.Send();
                }
                else
                {
                    message = ResourceManager.GetString("messageExportActionNotHaveEmail");
                }
            }
        }
        catch (System.Exception ex)
        {
            message = ex.Message;
        }
        if (message != string.Empty)
        {
            string script1 = "<script type=\"text/javascript\">";

            script1 += " alert(\"" + message + "\")";
            script1 += " </script>";

            if (!page.ClientScript.IsClientScriptBlockRegistered("redirectUser"))
                page.ClientScript.RegisterStartupScript(page.GetType(), "redirectUser", script1);
            return false;
        }
        else
        {
            return true;
        }
    }