示例#1
0
        private void button_deleteTemplate_Click(object sender, EventArgs e)
        {
            string templateName = comboBox_Templates.Text;
            var    template     = emailTemplates.Where(x => x.TemplateName.Equals(templateName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (template == null)
            {
                MessageBox.Show($"No template found '{templateName}'");
                return;
            }
            else
            {
                string       msg          = "Are you sure you wish to delete the template?";
                DialogResult dialogResult = MessageBox.Show(msg, "Delete Template", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    emailTemplates.Remove(template);
                    CDOHelper.SaveObjectToJsonCDO("AutomatedEmailTemplates.json", emailTemplates);

                    comboBox_Templates.Items.Clear();
                    comboBox_Templates.Items.AddRange(emailTemplates.Select(x => x.TemplateName).ToArray());

                    MessageBox.Show("Template Deleted");
                }
                else if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string templateName = comboBox_Templates.Text;
            var    template     = emailTemplates.Where(x => x.TemplateName.Equals(templateName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (template == null)
            {
                string       msg          = "This looks like a new template; do you want to continue creating a new template?";
                DialogResult dialogResult = MessageBox.Show(msg, "New Template", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    template = new AutomatedEmailTemplate()
                    {
                        TemplateName = templateName,
                        Email        = new EmailMessageWcmSignatureRequest()
                    };
                }
                else if (dialogResult == DialogResult.No)
                {
                    return;
                }
            }
            else
            {
                emailTemplates.Remove(template);
            }


            //update template with current textboxes
            template.Email.FromFullName    = EmailFromName_textBox.Text;
            template.Email.FromTitle       = EmailFromTitle_textBox.Text;
            template.Email.FromPhoneNumber = EmailFromPhone_textBox.Text;
            template.Email.FromAddress     = EmailFromEmailAddr_textBox.Text;

            template.Email.ToAddresses  = string.IsNullOrEmpty(EmailToAddreses_textBox.Text) ? new List <string>() : EmailToAddreses_textBox.Text.Split(',').Select(x => x.Trim()).ToList();
            template.Email.CcAddresses  = string.IsNullOrEmpty(EmailCcAddreses_textBox.Text) ? new List <string>() : EmailCcAddreses_textBox.Text.Split(',').Select(x => x.Trim()).ToList();
            template.Email.BccAddresses = string.IsNullOrEmpty(EmailBccAddreses_textBox.Text) ? new List <string>() : EmailBccAddreses_textBox.Text.Split(',').Select(x => x.Trim()).ToList();

            template.Email.MessageSubject = EmailSubject_textBox.Text;
            template.Email.MessageBody    = EmailBody_richTextBox.Text;

            emailTemplates.Add(template);

            CDOHelper.SaveObjectToJsonCDO("AutomatedEmailTemplates.json", emailTemplates);

            comboBox_Templates.Items.Clear();
            comboBox_Templates.Items.AddRange(emailTemplates.Select(x => x.TemplateName).ToArray());

            MessageBox.Show("Template updated");
        }