Пример #1
0
 private void AddRecipient(Recipient recipient)
 {
     Recipients.Add(recipient);
 }
Пример #2
0
 public void AddRecipient(string recipient)
 {
     Recipients.Add(recipient);
 }
        /// <summary>
        /// Uses the current category selection and creates the list of recipients accordingly
        /// </summary>
        /// <param name="recipientsType">The category of recipients to use</param>
        private void CreateRecipientsList(MessageRecipientsTypes recipientsType)
        {
            // Reset the recipients list
            Recipients.Clear();

            // Create the list of students
            switch (recipientsType)
            {
            case MessageRecipientsTypes.Students:
                // Adding a 'send to every student' option if the user has relevent permissions
                if (CanSendToEveryone)
                {
                    Recipients.Add(EVERYONE_OPTION, "כל התלמידים");
                }

                // Add every active student in the school
                _schoolData.Persons.Where(person => !person.User.isDisabled && person.isStudent).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Parent:
                // Add every parent in the school
                _schoolData.Persons.Where(person => !person.User.isDisabled && person.isParent).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Teachers:
                // Add a 'send to management' option if the user has relevent permissions
                if (CanSendToEveryone)
                {
                    Recipients.Add(EVERYONE_OPTION, "כל המורים");
                }

                // Add the teachers
                _schoolData.Persons.Where(person => !person.User.isDisabled && person.isTeacher).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Management:
                // Add a 'send to management' option if the user has relevent permissions
                if (CanSendToEveryone)
                {
                    Recipients.Add(EVERYONE_OPTION, "כל ההנהלה");
                }

                // Add the secretaries and principal
                _schoolData.Persons.Where(person => !person.User.isDisabled && (person.isPrincipal || person.isSecretary)).ToList()
                .ForEach(person => Recipients.Add(person.personID, person.firstName + " " + person.lastName));
                break;

            case MessageRecipientsTypes.Class:
                // Add every class in the school
                _schoolData.Classes.ToList().ForEach(schoolClass => Recipients.Add(schoolClass.classID, schoolClass.className));
                break;

            case MessageRecipientsTypes.Everyone:
                Recipients.Add(EVERYONE_OPTION, "כל בית הספר");
                break;

            default:
                throw new ArgumentException("Invalid recipient type!");
            }
        }
Пример #4
0
 public void AddRecipient(RecipientData recipient)
 {
     Recipients.Add(RockEmailMessageRecipient.CreateAnonymous(recipient.To, recipient.MergeFields));
 }
Пример #5
0
        private void send_btn_Click(object sender, EventArgs e)
        {
            if (trigger == "lecturers")
            {
                Outlook.Application outlookApp = new Outlook.Application();
                MailItem            mailItem   = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
                mailItem.Subject    = guna2TextBox1.Text;
                mailItem.Body       = guna2TextBox2.Text;
                mailItem.Importance = OlImportance.olImportanceNormal;
                Recipients oRecips = mailItem.Recipients;

                //if attachment button is clicked
                if (button3Clicked == true)
                {
                    button3Clicked = false;
                    if (attachment.FileName.Length > 0)
                    {
                        MySqlCommand command = new MySqlCommand("SELECT lecturer_email FROM lecturer_info", databaseConnection);
                        command.Connection = databaseConnection;
                        DataSet          dataset = new DataSet();
                        MySqlDataAdapter adp     = new MySqlDataAdapter(command);
                        adp.Fill(dataset);

                        foreach (DataTable table in dataset.Tables)
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                foreach (object item in row.ItemArray)
                                {
                                    Recipient oRecip = oRecips.Add((string)item);
                                    oRecip.Resolve();
                                }
                            }
                        }
                    }
                    mailItem.Attachments.Add(attachment.FileName, OlAttachmentType.olByValue, 1, attachment.FileName);
                    oRecips = null;
                }

                mailItem.Send();
                showSuccess("Message has been sent successfully!");
            }
            else
            {
                Outlook.Application outlookApp = new Outlook.Application();
                MailItem            mailItem   = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
                mailItem.Subject    = guna2TextBox1.Text;
                mailItem.Body       = guna2TextBox2.Text;
                mailItem.Importance = OlImportance.olImportanceNormal;
                Recipients oRecips = mailItem.Recipients;

                //if attachment button is clicked
                if (button3Clicked == true)
                {
                    button3Clicked = false;
                    if (attachment.FileName.Length > 0)
                    {
                        MySqlCommand command = new MySqlCommand("SELECT student_email FROM student_info WHERE intake_id='" + trigger + "'", databaseConnection);
                        command.Connection = databaseConnection;
                        DataSet          dataset = new DataSet();
                        MySqlDataAdapter adp     = new MySqlDataAdapter(command);
                        adp.Fill(dataset);

                        foreach (DataTable table in dataset.Tables)
                        {
                            foreach (DataRow row in table.Rows)
                            {
                                foreach (object item in row.ItemArray)
                                {
                                    Recipient oRecip = oRecips.Add((string)item);
                                    oRecip.Resolve();
                                }
                            }
                        }
                    }
                    mailItem.Attachments.Add(attachment.FileName, OlAttachmentType.olByValue, 1, attachment.FileName);
                    oRecips = null;
                }

                mailItem.Send();
                showSuccess("Message has been sent successfully!");
            }
        }
Пример #6
0
 private void NewMail_NewReceipient(object sender, NewReceipientEventArgs e)
 {
     Recipients.Add(e.Recipient);
 }
Пример #7
0
 public void enviaCorreo(ObservableCollection <Entidad> _olBCCRecipients, string _recipient, string _subject, string _body)
 {
     try
     {
         char[] chArray = new char[1] {
             ';'
         };
         // ISSUE: variable of a compiler-generated type
         Microsoft.Office.Interop.Outlook.Application instance = (Microsoft.Office.Interop.Outlook.Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("0006F03A-0000-0000-C000-000000000046")));
         // ISSUE: reference to a compiler-generated field
         enviaCorreo.c
         if (EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer0.\u003C\u003Ep__Site1 == null)
         {
             // ISSUE: reference to a compiler-generated field
             EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer0.\u003C\u003Ep__Site1 = CallSite <Func <CallSite, object, _MailItem> > .Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.ConvertExplicit, typeof(_MailItem), typeof(EnviarCorreo)));
         }
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated method
         // ISSUE: variable of a compiler-generated type
         _MailItem mailItem = EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer0.\u003C\u003Ep__Site1.Target((CallSite)EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer0.\u003C\u003Ep__Site1, instance.CreateItem(OlItemType.olMailItem));
         // ISSUE: variable of a compiler-generated type
         Inspector getInspector = mailItem.GetInspector;
         bool      flag         = true;
         string    str1         = "";
         // ISSUE: variable of a compiler-generated type
         Recipients recipients = mailItem.Recipients;
         using (IEnumerator <Entidad> enumerator = _olBCCRecipients.GetEnumerator())
         {
             while (((IEnumerator)enumerator).MoveNext())
             {
                 Entidad current = enumerator.Current;
                 if (string.IsNullOrEmpty(current.get_ENTC_EMail()))
                 {
                     flag = false;
                     str1 = str1 + "* " + current.get_ENTC_NomCompleto() + Environment.NewLine;
                 }
                 else
                 {
                     string[] strArray = current.get_ENTC_EMail().Split(chArray);
                     if (strArray != null && strArray.Length != 0)
                     {
                         foreach (string str2 in strArray)
                         {
                             if (!string.IsNullOrEmpty(str2.Trim()))
                             {
                                 // ISSUE: reference to a compiler-generated method
                                 // ISSUE: variable of a compiler-generated type
                                 Recipient recipient = recipients.Add(str2.Trim());
                                 recipient.Type = 3;
                                 // ISSUE: reference to a compiler-generated method
                                 recipient.Resolve();
                             }
                         }
                     }
                 }
             }
         }
         if (!flag)
         {
             int num = (int)Dialogos.MostrarMensajeInformacion("Entidades sin Email", "A las siguientes Entidad no fueron incluidos para el envio de este correo por no tener un Email (Ver Detalles).", str1);
         }
         // ISSUE: reference to a compiler-generated method
         // ISSUE: variable of a compiler-generated type
         Recipient recipient1 = recipients.Add(_recipient.Trim());
         // ISSUE: reference to a compiler-generated method
         recipient1.Resolve();
         mailItem.Subject  = _subject;
         mailItem.HTMLBody = _body + mailItem.HTMLBody;
         // ISSUE: reference to a compiler-generated method
         mailItem.Display((object)true);
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show("Error durante el proceso del Envío del Correo: " + ex.Message, "Error Interno", MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
 }
Пример #8
0
        public async Task <bool> LoadExtendedDataAsync(IProgress <Document> e, CancellationToken cancellationToken)
        {
            if (IsLoadedFromDb != true)
            {
                return(true);                        //its not from the database so nothing to load
            }
            List <Document> docs = new List <Document>();

            using (SqlConnection connection = new SqlConnection(TransmitalManager.connString))
            {
                string     query   = string.Format(SqlScripts.GetTransmittalFiles, Id);
                SqlCommand command = new SqlCommand(query, connection);
                await connection.OpenAsync();

                //***** Load recipients *****
                using (SqlDataReader reader = await command.ExecuteReaderAsync())
                {
                    while (await reader.ReadAsync())
                    {
                        Document file = new Document(reader);// TransmitalManager.LoadDocument(reader);
                        e?.Report(file);
                        docs.Add(file);
                        if (cancellationToken.IsCancellationRequested)
                        {
                            reader.Close();
                            connection.Close();
                            return(false);
                        }
                    }
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    connection.Close();
                    return(false);
                }

                //***** Get Recipients *****
                query   = string.Format(SqlScripts.GetTransmitalRecipients, Id);
                command = new SqlCommand(query, connection);

                using (SqlDataReader reader = await command.ExecuteReaderAsync())
                {
                    while (await reader.ReadAsync())
                    {
                        int       Id   = (int)reader["RecipientId"];
                        Recipient file = Recipient.AllRecipients.FirstOrDefault(t => t.Id == Id);
                        if (file != null)
                        {
                            Recipients.Add(file);
                        }

                        if (cancellationToken.IsCancellationRequested)
                        {
                            reader.Close();
                            connection.Close();
                            return(false);
                        }
                    }
                }
            }

            ExtendedDataLoaded = true;
            return(true);
        }
Пример #9
0
 //A simple constructor for the most common use-case
 public EmailMessage(string recipient, string title, string body)
 {
     Recipients.Add(recipient);
     Title = title;
     Body  = body;
 }
Пример #10
0
        public EmailMessage(System.Net.Mail.MailMessage mailMessage)
        {
            this.Sender     = new Sender();
            this.Subject    = mailMessage.Subject;
            this.Body       = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(mailMessage.Body));
            this.IsBodyHtml = mailMessage.IsBodyHtml;
            this.Recipients = new List <EmailAddress>();
            if (mailMessage.To != null)
            {
                foreach (var to in mailMessage.To)
                {
                    Recipients.Add(new EmailAddress()
                    {
                        Address     = to.Address,
                        DisplayName = to.DisplayName,
                        SendingType = EmailSendingType.To,
                    });
                }
            }
            if (mailMessage.CC != null)
            {
                foreach (var to in mailMessage.CC)
                {
                    Recipients.Add(new EmailAddress()
                    {
                        Address     = to.Address,
                        DisplayName = to.DisplayName,
                        SendingType = EmailSendingType.CC,
                    });
                }
            }
            if (mailMessage.Bcc != null)
            {
                foreach (var to in mailMessage.Bcc)
                {
                    Recipients.Add(new EmailAddress()
                    {
                        Address     = to.Address,
                        DisplayName = to.DisplayName,
                        SendingType = EmailSendingType.BCC,
                    });
                }
            }

            if (mailMessage.From != null)
            {
                Sender = new Sender()
                {
                    Email       = mailMessage.From.Address,
                    DisplayName = mailMessage.From.DisplayName,
                };
            }

            Headers = new List <EmailMessageHeader>();
            foreach (var header in mailMessage.Headers.AllKeys)
            {
                Headers.Add(new EmailMessageHeader()
                {
                    Name  = header,
                    Value = mailMessage.Headers[header]
                });
            }
            Attachments = new List <Attachment>();
            foreach (var attachment in mailMessage.Attachments)
            {
                string content = null;
                using (var reader = new System.IO.StreamReader(attachment.ContentStream))
                {
                    content = reader.ReadToEnd();
                    var buffer = System.Text.Encoding.UTF8.GetBytes(content);
                    content = Convert.ToBase64String(buffer);
                }

                Attachments.Add(new Attachment()
                {
                    Content     = content,
                    ContentType = attachment.ContentType.Name,
                    Name        = attachment.Name
                });
            }
        }
        /// <summary>
        /// Schedules the events that are in the list
        /// </summary>
        /// <returns></returns>
        public bool Event()
        {
            try
            {
                App      = new Outlook.Application();
                accounts = App.Session.Accounts;

                try
                {
                    string           msg    = "Are you sure you want to send ?";
                    MessageBoxResult result =
                        MessageBox.Show(
                            msg,
                            "Confirmation",
                            MessageBoxButton.YesNo,
                            MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        foreach (Jobs j in Datalist)
                        {
                            sb.AppendLine("Hello Associate").AppendLine("You are assigned with a task:\n");
                            TaskItem oTask = (TaskItem)App.CreateItem(OlItemType.olTaskItem);
                            oTask.Subject = "Do It By " + j.target.ToUpper();
                            string date = _uts.Formate_date(j.day);
                            oTask.StartDate    = Convert.ToDateTime(date + "8:26 AM");
                            oTask.DueDate      = Convert.ToDateTime(date + "9:28 AM");
                            oTask.ReminderSet  = true;
                            oTask.ReminderTime = Convert.ToDateTime(date + "9:27 AM");
                            sb.AppendLine(j.task);
                            sb.AppendLine("Thank You");
                            oTask.Body = sb.ToString();
                            oTask.SchedulePlusPriority = "Medium";
                            oTask.Status = OlTaskStatus.olTaskInProgress;
                            oTask.Save();
                            sb.Length = 0;

                            //Send task
                            Recipients oRecipients = oTask.Recipients;
                            Recipient  oReceipient;
                            oReceipient      = oRecipients.Add(j.responsibility);
                            oReceipient.Type = 1;
                            oRecipients.ResolveAll();
                            oTask.Assign();

                            foreach (Account account in accounts)
                            {
                                if (j.responsibility != account.DisplayName.ToLower())
                                {
                                    oTask.Send();
                                }
                            }
                        }
                        flag = true;
                        Windows.MessageBox.Show("Events Successfully Sent", "Success", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Information);
                        //  _login.Show();
                    }
                }
                catch (System.Exception)
                {
                    flag = false;
                    MessageBox.Show(
                        "Event Scheduling Error, Invalid Name Given In Assignee!!",
                        "Error",
                        Windows.MessageBoxButton.OK,
                        Windows.MessageBoxImage.Error);
                }
            }
            catch (System.Exception)
            {
                MessageBox.Show("You Dosn't Have Microsoft Outlook Installed!!!");
            }

            return(flag);
        }
Пример #12
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="communication">The communication.</param>
        private void ShowDetail(Rock.Model.Communication communication)
        {
            Recipients.Clear();

            if (communication != null)
            {
                this.AdditionalMergeFields = communication.AdditionalMergeFields.ToList();
                lTitle.Text = (communication.Subject ?? "New Communication").FormatAsHtmlTitle();

                foreach (var recipient in new CommunicationRecipientService(new RockContext())
                         .Queryable("PersonAlias.Person.PhoneNumbers")
                         .Where(r => r.CommunicationId == communication.Id))
                {
                    Recipients.Add(new Recipient(recipient.PersonAlias.Person, recipient.Status, recipient.StatusNote, recipient.OpenedClient, recipient.OpenedDateTime));
                }
            }
            else
            {
                communication = new Rock.Model.Communication()
                {
                    Status = CommunicationStatus.Transient
                };
                lTitle.Text = "New Communication".FormatAsHtmlTitle();

                int?personId = PageParameter("Person").AsIntegerOrNull();
                if (personId.HasValue)
                {
                    communication.IsBulkCommunication = false;
                    var person = new PersonService(new RockContext()).Get(personId.Value);
                    if (person != null)
                    {
                        Recipients.Add(new Recipient(person, CommunicationRecipientStatus.Pending, string.Empty, string.Empty, null));
                    }
                }
            }

            CommunicationId = communication.Id;

            MediumEntityTypeId = communication.MediumEntityTypeId;
            BindMediums();

            MediumData = communication.MediumData;
            MediumData.Add("Subject", communication.Subject);

            if (communication.Status == CommunicationStatus.Transient && !string.IsNullOrWhiteSpace(GetAttributeValue("DefaultTemplate")))
            {
                var template = new CommunicationTemplateService(new RockContext()).Get(GetAttributeValue("DefaultTemplate").AsGuid());

                // If a template guid was passed in, it overrides any default template.
                string templateGuid = PageParameter("templateGuid");
                if (!string.IsNullOrEmpty(templateGuid))
                {
                    var guid = new Guid(templateGuid);
                    template = new CommunicationTemplateService(new RockContext()).Queryable().Where(t => t.Guid == guid).FirstOrDefault();
                }

                if (template != null && template.MediumEntityTypeId == MediumEntityTypeId)
                {
                    foreach (ListItem item in ddlTemplate.Items)
                    {
                        if (item.Value == template.Id.ToString())
                        {
                            item.Selected = true;
                            GetTemplateData(template.Id, false);
                        }
                        else
                        {
                            item.Selected = false;
                        }
                    }
                }
            }

            cbBulk.Checked = communication.IsBulkCommunication;

            MediumControl control = LoadMediumControl(true);

            if (control != null && CurrentPerson != null)
            {
                control.InitializeFromSender(CurrentPerson);
            }

            dtpFutureSend.SelectedDateTime = communication.FutureSendDateTime;

            ShowStatus(communication);
            ShowActions(communication);
        }
Пример #13
0
 /// <summary>Initializes a new <see cref="EncryptionOptions"/> object with the given recipients.</summary>
 public EncryptionOptions(params PrimaryKey[] recipients)
 {
   foreach(PrimaryKey recipient in recipients) Recipients.Add(recipient);
 }
        public void Send(System.Net.Mail.MailMessage message)
        {
            if (!OutlookIsRunning)
            {
                LaunchOutlook();
            }
            Recipients oRecips = null;
            Recipient  oRecip  = null;
            MailItem   oMsg    = null;

            try
            {
                _myApp = new Application();

                oMsg = (MailItem)_myApp.CreateItem(OlItemType.olMailItem);

                oMsg.HTMLBody = message.Body;
                oMsg.Subject  = message.Subject;
                oRecips       = oMsg.Recipients;


                foreach (var email in message.To)
                {
                    oRecip = oRecips.Add(email.Address);
                }

                foreach (var email in message.CC)
                {
                    oMsg.CC += string.Concat(email, ";");
                }

                var filenames = Attach(message.Attachments, oMsg);
                oRecip?.Resolve();
                oMsg.Send();

                _mapiNameSpace = _myApp.GetNamespace("MAPI");

                DeleteTempFiles(filenames);
                Thread.Sleep(5000);
            }
            finally
            {
                if (oRecip != null)
                {
                    Marshal.ReleaseComObject(oRecip);
                }
                if (oRecips != null)
                {
                    Marshal.ReleaseComObject(oRecips);
                }
                if (oMsg != null)
                {
                    Marshal.ReleaseComObject(oMsg);
                }
                if (_mapiNameSpace != null)
                {
                    Marshal.ReleaseComObject(_mapiNameSpace);
                }
                if (_myApp != null)
                {
                    Marshal.ReleaseComObject(_myApp);
                }
            }
        }
Пример #15
0
 public void enviaCorreo(bool _enviar, string _recipient, List <string> _olCCrecipients, string _subject, string _body)
 {
     try
     {
         char[] chArray = new char[1] {
             ';'
         };
         string[] strArray = (string[])null;
         // ISSUE: variable of a compiler-generated type
         Microsoft.Office.Interop.Outlook.Application instance = (Microsoft.Office.Interop.Outlook.Application)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("0006F03A-0000-0000-C000-000000000046")));
         // ISSUE: reference to a compiler-generated field
         if (EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer6.\u003C\u003Ep__Site7 == null)
         {
             // ISSUE: reference to a compiler-generated field
             EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer6.\u003C\u003Ep__Site7 = CallSite <Func <CallSite, object, _MailItem> > .Create(Microsoft.CSharp.RuntimeBinder.Binder.Convert(CSharpBinderFlags.ConvertExplicit, typeof(_MailItem), typeof(EnviarCorreo)));
         }
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated method
         // ISSUE: variable of a compiler-generated type
         _MailItem mailItem = EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer6.\u003C\u003Ep__Site7.Target((CallSite)EnviarCorreo.\u003CenviaCorreo\u003Eo__SiteContainer6.\u003C\u003Ep__Site7, instance.CreateItem(OlItemType.olMailItem));
         // ISSUE: variable of a compiler-generated type
         Inspector getInspector = mailItem.GetInspector;
         // ISSUE: variable of a compiler-generated type
         Recipients recipients = mailItem.Recipients;
         foreach (string olCcrecipient in _olCCrecipients)
         {
             if (!string.IsNullOrEmpty(olCcrecipient))
             {
                 // ISSUE: reference to a compiler-generated method
                 // ISSUE: variable of a compiler-generated type
                 Recipient recipient = recipients.Add(olCcrecipient);
                 recipient.Type = 2;
                 // ISSUE: reference to a compiler-generated method
                 recipient.Resolve();
             }
         }
         if (!string.IsNullOrEmpty(_recipient))
         {
             strArray = _recipient.Split(chArray);
         }
         if (strArray != null && strArray.Length != 0)
         {
             foreach (string Name in strArray)
             {
                 // ISSUE: reference to a compiler-generated method
                 // ISSUE: variable of a compiler-generated type
                 Recipient recipient = recipients.Add(Name);
                 recipient.Type = 1;
                 // ISSUE: reference to a compiler-generated method
                 recipient.Resolve();
             }
         }
         mailItem.Subject  = _subject;
         mailItem.HTMLBody = _body + mailItem.HTMLBody;
         if (_enviar)
         {
             // ISSUE: reference to a compiler-generated method
             mailItem.Send();
         }
         else
         {
             // ISSUE: reference to a compiler-generated method
             mailItem.Display((object)true);
         }
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show("Error durante el proceso del Envío del Correo: " + ex.Message, "Error Interno", MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
     Thread.Sleep(10000);
 }
Пример #16
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            int    strTag         = Convert.ToInt16(txtTag.Text);
            string strJob         = txtJob.Text;
            string strTool        = txtTool.Text;
            string strInitiator   = cmbInitiator.Text;
            string strDept        = cmbDept.Text;
            string strSpec        = txtSpec.Text;
            string strCondition   = txtCondition.Text;
            string strDefect      = cmbDefect.Text;
            string strCause       = cmbCause.Text;
            string strDisposition = cmbDisposition.Text;
            //  string strDisposition = cmbDisposition.Text;

            bool bCar = chkCar.Checked;

            int strRework = 0;

            if (txtRework == null)
            {
                strRework = 0;
            }
            else
            {
                //  strRework = Convert.ToInt16(txtRework.Text);
                strRework = 0;
            }


            int    strInstance     = Convert.ToInt16(txtInstance.Text);
            int    strScrap        = Convert.ToInt16(txtScrap.Text);
            string strVendor       = txtVendor.Text;
            string strInstructions = txtInstructions.Text;
            string strComments     = txtComments.Text;



            DateTime dtInspection   = dtpInspection.Value.Date;
            DateTime dtReinspection = dtpReinspection.Value.Date;

            var db = new TestEntities();

            tblRedTag rt    = db.tblRedTags.Find(strTag);
            Job       check = db.Jobs.Find(strJob);

            if (rt != null)
            {
                DialogResult dialogResult = MessageBox.Show("This Tag ID Already Exists. Update?", "Tag Exists!", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    if (check != null)
                    {
                        rt.ID           = strTag;
                        rt.JOB          = strJob;
                        rt.Detail       = strTool;
                        rt.Initiator    = strInitiator;
                        rt.Dept         = strDept;
                        rt.Spec         = strSpec;
                        rt.Condition    = strCondition;
                        rt.Date         = dtInspection;
                        rt.Defect       = strDefect;
                        rt.Cause        = strCause;
                        rt.Instructions = strInstructions;
                        rt.Comment      = strComments;
                        rt.Reinspection = dtReinspection;
                        rt.Cost         = strRework;
                        rt.InstanceCost = strInstance;
                        rt.ScrapCost    = strScrap;
                        rt.VendorPO     = strVendor;


                        try
                        {
                            //   db.tblRedTags(rt)
                            db.SaveChanges();
                            bool bEmail  = true;
                            Team jobTeam = db.Teams.Find(strJob);

                            if (jobTeam != null)
                            {
                                bEmail = true;
                                string strSubject = "Red Tag # " + strTag + " Updated";
                                string strBody    = "A red tag has been updated. <br> You are receiving this email because you are part of the job team. <br><br><b>THIS IS A TEST OF THE WIPVIEWER RED TAG EMAIL SYSTEM.</b> <br><br>";
                                strBody += "<br>Here is some information about the Tag: <br>Tag Number: " + strTag + "<br>Job Number: " + strJob + "<br>Tool #: " + strTool + "<br>Initiator: " + strInitiator + "<br>Department #: " + strDept;


                                Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

                                MailItem eMail = (MailItem)oApp.CreateItem(OlItemType.olMailItem);


                                Recipients oRecips = (Recipients)eMail.Recipients;
                                eMail.Subject    = strSubject;
                                eMail.Body       = strBody;
                                eMail.Importance = OlImportance.olImportanceLow;

                                eMail.BodyFormat = OlBodyFormat.olFormatHTML;



                                if (jobTeam.ProgramManager != null)
                                {
                                    Recipient oRecip = (Recipient)oRecips.Add("*****@*****.**");
                                }


                                if (jobTeam.Processor != null)
                                {
                                    //eMail.To = "*****@*****.**";

                                    Recipient oRecip = (Recipient)oRecips.Add("*****@*****.**");
                                }


                                if (jobTeam.BuildLeader != null)
                                {
                                    Recipient oRecip = (Recipient)oRecips.Add("*****@*****.**");
                                }

                                eMail.HTMLBody = strBody;


                                eMail.Send();
                            }

                            else
                            {
                                bEmail = false;
                            }


                            if (bEmail == true)
                            {
                                MessageBox.Show("Success. Email Sent");
                            }

                            else
                            {
                                MessageBox.Show("Red Tag created, but no Team for job present. No Email sent.");
                            }
                        }

                        catch (System.Exception ex)
                        { }
                    }

                    else
                    {
                        MessageBox.Show("That Job Does not exist. You may have your formatting wrong. In WipViewer, Jobs are always formatted 'XXXX9999 / 9'. If you have any questions, please contact Jacob Rotary");
                    }
                }
                else
                {
                }
            }

            else
            {
                if (check != null)
                {
                    tblRedTag rt2 = new tblRedTag();


                    rt2.ID           = strTag;
                    rt2.JOB          = strJob;
                    rt2.Detail       = strTool;
                    rt2.Initiator    = strInitiator;
                    rt2.Dept         = strDept;
                    rt2.Spec         = strSpec;
                    rt2.Condition    = strCondition;
                    rt2.Date         = dtInspection;
                    rt2.Defect       = strDefect;
                    rt2.Cause        = strCause;
                    rt2.Instructions = strInstructions;
                    rt2.Comment      = strComments;
                    rt2.Reinspection = dtReinspection;
                    rt2.Cost         = strRework;
                    rt2.InstanceCost = strInstance;
                    rt2.ScrapCost    = strScrap;
                    rt2.VendorPO     = strVendor;
                    rt2.Disposition  = strDisposition;
                    rt2.CAR          = Convert.ToString(bCar);



                    try
                    {
                        db.tblRedTags.Add(rt2);
                        db.SaveChanges();
                        bool bEmail  = true;
                        Team jobTeam = db.Teams.Find(strJob);

                        if (jobTeam != null)
                        {
                            bEmail = true;
                            string strSubject = "New Red Tag created for " + strJob + " IGNORE THIS - ITS A TEST EMAIL";
                            string strBody    = "A new red tag has been created. <br> You are receiving this email because you are part of the job team. <br><br><b>THIS IS A TEST OF THE WIPVIEWER RED TAG EMAIL SYSTEM.</b> <br><br>";
                            strBody += "<br>Here is some information about the Tag: <br>Tag Number: " + strTag + "<br>Job Number: " + strJob + "<br>Tool #: " + strTool + "<br>Initiator: " + strInitiator + "<br>Department #: " + strDept;


                            Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

                            MailItem eMail = (MailItem)oApp.CreateItem(OlItemType.olMailItem);


                            Recipients oRecips = (Recipients)eMail.Recipients;
                            eMail.Subject    = strSubject;
                            eMail.Body       = strBody;
                            eMail.Importance = OlImportance.olImportanceLow;

                            eMail.BodyFormat = OlBodyFormat.olFormatHTML;



                            if (jobTeam.ProgramManager != null)
                            {
                                Recipient oRecip = (Recipient)oRecips.Add("*****@*****.**");
                            }


                            if (jobTeam.Processor != null)
                            {
                                //eMail.To = "*****@*****.**";

                                Recipient oRecip = (Recipient)oRecips.Add("*****@*****.**");
                            }


                            if (jobTeam.BuildLeader != null)
                            {
                                Recipient oRecip = (Recipient)oRecips.Add("*****@*****.**");
                            }

                            eMail.HTMLBody = strBody;


                            eMail.Send();
                        }

                        else
                        {
                            bEmail = false;
                        }


                        if (bEmail == true)
                        {
                            MessageBox.Show("Success. Email Sent");
                        }

                        else
                        {
                            MessageBox.Show("Red Tag created, but no Team for job present. No Email sent.");
                        }
                    }

                    //catch (System.Exception ex)
                    // { }

                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.TraceInformation("Property: {0} Error: {1}",
                                                       validationError.PropertyName,
                                                       validationError.ErrorMessage);
                            }
                        }
                    }
                }

                else
                {
                    MessageBox.Show("That Job Does not exist. You may have your formatting wrong. In WipView, Jobs are always formatted 'XXXX9999 / 9'. If you have any questions, please contact Jacob Rotary");
                }
            }
        }
Пример #17
0
 public void AddRecipient(MailRecipient recipient)
 => Recipients.Add(recipient);