private void toolStripButtonAddModel_Click(object sender, EventArgs e) { var newName = this.toolStripComboBoxModels.Text; if (string.IsNullOrWhiteSpace(newName)) { MessageBox.Show("Must define a name for the new model.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var namesDic = this.toolStripComboBoxModels.Items .Cast <FormSendEmailConfigData.EmailModelData>() .Where(m => m.Name != null) .ToDictionary(m => m.Name); FormSendEmailConfigData.EmailModelData model; if (namesDic.ContainsKey(newName)) { if (MessageBox.Show( string.Format("Replace the model {0}", newName), "Replace model?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } model = namesDic[newName]; } else { if (this.configData == null) { this.configData = new FormSendEmailConfigData(); } if (this.configData.EmailModels == null) { this.configData.EmailModels = new FormSendEmailConfigData.EmailModelsData(); } if (this.configData.EmailModels.Items == null) { this.configData.EmailModels.Items = new List <FormSendEmailConfigData.EmailModelData>(); } model = new FormSendEmailConfigData.EmailModelData(); model.Name = newName; this.configData.EmailModels.Items.Add(model); this.toolStripComboBoxModels.Items.Add(model); } model.HtmlContent = this.textBoxHtmlContent.Text; model.TextContent = this.textBoxTextContent.Text; model.Title = this.textBoxSubject.Text; }
public FormSendEmail(FormSendEmailConfigData configData, EmailData[] emailData) { this.InitializeComponent(); this.configData = configData; this.emailData = emailData; this.checkedListBoxClients.Items.AddRange(emailData); this.propertyGridFilter.SelectedObject = this.filterObject = new FilterObject(); this.toolStripComboBoxModels.Items.AddRange(configData.EmailModels.Items.ToArray()); this.textBoxSubject.Enter += textBox_Enter_RecordLastFocus; this.textBoxTextContent.Enter += textBox_Enter_RecordLastFocus; this.textBoxHtmlContent.Enter += textBox_Enter_RecordLastFocus; }