/// <summary> /// Open MailChimpCampaign form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCancel_Click(object sender, EventArgs e) { if (!ValidateXMLSettings()) { this.Close(); } else { Cursor.Current = Cursors.WaitCursor; try { ConstantContactCampaign nexmoForm = new ConstantContactCampaign(); nexmoForm.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor.Current = Cursors.Default; } } }
/// <summary> /// Save Nexmo Settings and MailChimp Settings in settings.xml /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; try { if (ValidateFields()) { XmlDocument doc = new XmlDocument(); XmlElement settings = doc.CreateElement(string.Empty, "settings", string.Empty); doc.AppendChild(settings); XmlElement nexmo = doc.CreateElement(string.Empty, "nexmo", string.Empty); settings.AppendChild(nexmo); XmlElement api = doc.CreateElement(string.Empty, "api", string.Empty); XmlText nexmoApi = doc.CreateTextNode(txtNexmoAPI.Text.Trim().ToString()); api.AppendChild(nexmoApi); nexmo.AppendChild(api); XmlElement secretKey = doc.CreateElement(string.Empty, "secret-key", string.Empty); XmlText key = doc.CreateTextNode(txtNexmoSecretKey.Text.Trim().ToString()); secretKey.AppendChild(key); nexmo.AppendChild(secretKey); XmlElement fromNumber = doc.CreateElement(string.Empty, "from-number", string.Empty); XmlText number = doc.CreateTextNode(FromNumber.Trim().ToString()); fromNumber.AppendChild(number); nexmo.AppendChild(fromNumber); //--Constant Contact XmlElement constantContact = doc.CreateElement(string.Empty, "constantcontact", string.Empty); settings.AppendChild(constantContact); XmlElement constantContactAPI = doc.CreateElement(string.Empty, "api", string.Empty); XmlText apiText = doc.CreateTextNode(txtConstantContactAPI.Text.Trim().ToString()); constantContactAPI.AppendChild(apiText); constantContact.AppendChild(constantContactAPI); XmlElement constantContactToken = doc.CreateElement(string.Empty, "access-token", string.Empty); XmlText tokenText = doc.CreateTextNode(txtConstantContactToken.Text.Trim().ToString()); constantContactToken.AppendChild(tokenText); constantContact.AppendChild(constantContactToken); doc.Save(FileName); System.Security.AccessControl.FileSecurity fsec = System.IO.File.GetAccessControl(FileName); fsec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule("Everyone", System.Security.AccessControl.FileSystemRights.Modify, System.Security.AccessControl.AccessControlType.Allow)); System.IO.File.SetAccessControl(FileName, fsec); ConstantContactCampaign nexmoForm = new ConstantContactCampaign(); nexmoForm.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Cursor.Current = Cursors.Default; } }