예제 #1
0
        private void Process_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.lfcFirma.CBoxSelectedValue != null)
                {
                    using (var db = new SteinbachEntities())
                    {
                        CRMEmail mail = new CRMEmail();
                        mail.created = DateTime.Now;



                        foreach (var item in Attachments)
                        {
                            EmailAttachments Attach = new EmailAttachments();
                            Attach.CRMEmails      = mail;
                            Attach.Filename       = item.Key;
                            Attach.Path           = item.Value.Path;
                            Attach.created        = DateTime.Now;
                            Attach.AttachmentType = item.Value.AttachmentType;
                            Attach.isEmbedded     = item.Value.isEmbedded == true ? (short)1 : (short)0;

                            db.AddToEmailAttachments(Attach);
                        }


                        mail.EntryID        = oMailItem.EntryID;
                        mail.ConversationID = oMailItem.ConversationID;
                        mail.Betreff        = oMailItem.Subject;
                        mail.Absender       = oMailItem.SenderName;
                        var session = oMailItem.Session;
                        mail.Typ = oMailItem.SenderEmailType;
                        switch (oMailItem.BodyFormat)
                        {
                        case Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML:
                        {
                            mail.BodyFormat = "HTML";
                            if (html != "")
                            {
                                mail.HTMLText = html;
                            }
                            else
                            {
                                mail.HTMLText = oMailItem.HTMLBody;
                            }

                            mail.Text = oMailItem.Body;
                            break;
                        }

                        case Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain:
                        {
                            mail.BodyFormat = "PLAIN";
                            mail.Text       = oMailItem.Body;
                            break;
                        }

                        case Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText:
                        {
                            mail.BodyFormat = "RichText";
                            mail.RTF_Text   = oMailItem.RTFBody;
                            mail.Text       = oMailItem.Body;
                            break;
                        }

                        case Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatUnspecified:
                        {
                            mail.BodyFormat = "Unspecified";
                            mail.Text       = oMailItem.Body;
                            break;
                        }

                        default:
                            break;
                        }



                        mail.OutlookUsername = session.CurrentUser.Name;
                        //var user = GetActiveUser();
                        //if (user != null)
                        //{
                        //    if (user.isActive)
                        //    {
                        //        mail.id_PersonSI = user.id;
                        //    }

                        //}
                        mail.AbsenderMailAdresse = oMailItem.SenderEmailAddress;
                        mail.Datum = oMailItem.ReceivedTime;


                        mail.Empfaenger      = oMailItem.ReceivedByName;
                        mail.Empfaengerliste = oMailItem.To;
                        mail.id_Firma        = (int)lfcFirma.CBoxSelectedValue;

                        if (lfcStatus.CBoxSelectedValue != null)
                        {
                            mail.Status = (int)lfcStatus.CBoxSelectedValue;
                        }

                        if (lfcAktion.CBoxSelectedValue != null)
                        {
                            mail.Aktion = (int)lfcAktion.CBoxSelectedValue;
                        }

                        if (lfcKontakt.CBoxSelectedValue != null)
                        {
                            mail.id_Kontakt = (int)lfcKontakt.CBoxSelectedValue;
                        }



                        db.AddToCRMEmails(mail);
                        db.SaveChanges();
                        // SaveAttachment(oMailItem, mail.id);

                        // this.Close();

                        PlayStoryboard();
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Email konnte nicht zugeordnet werden." + "-" + ex.Message);
            }
        }