public void initializeEmailList()
        {//reads from the email file (if it exists and populates the emailAddresses list
            emailAddress curemail = new emailAddress();

            if (File.Exists(Directory.GetCurrentDirectory() + "/emailList.txt"))
            {
                try
                {
                    using (StreamReader sr = new StreamReader("emailList.txt"))
                    {
                        string   line          = sr.ReadToEnd();
                        string[] strSeparators = new string[] { "\r\n" };
                        string[] emails        = line.Split(strSeparators, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < (emails.Length - 1); i = i + 3)
                        {
                            Add(emails[i], emails[i + 1], emails[i + 2]);
                        }
                        // emailListBox.DataSource = emails;

                        // for (int i = 0; i < emails.Length; i++) emailList.Add(emails[i]);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("emailList.txt could not be read.");
                    MessageBox.Show(e.Message);
                }
            }
            else
            {
                File.Create(Directory.GetCurrentDirectory() + "/emailList.txt");
                // emailListBox.DataSource = null;
            }
        }
        // Function for adding a new emailAddress with permissions to emailList
        // NOTE : This version uses boolean inputs for canSendCommands and notifyWithUpdates
        //        and should be the main version of the Add function that is used in the forms.
        public void Add(string address, bool canSendCommands, bool notifyWithUpdates)
        {
            // Local emailAddress variable
            emailAddress curEmail = new emailAddress();

            curEmail.address           = address;
            curEmail.canSendCommands   = canSendCommands;
            curEmail.notifyWithUpdates = notifyWithUpdates;

            // Add emailAddress to emailList
            emailList.Add(curEmail);
        }
        private void AddButton_Click(object sender, EventArgs e)
        {
            // Create new email entry for list
            emailAddress newEmail = new emailAddress();

            // create mail entry form and pass newEmail reference
            EmailInput emailInput = new EmailInput();

            emailInput.ShowDialog(ref newEmail);

            // Process new entry if newEmail != null
            if (newEmail.address != null)
            {
                parentForm.home.email.emailAddresses.Add(newEmail.address, newEmail.canSendCommands, newEmail.notifyWithUpdates);
                emailListBox.DataSource = parentForm.home.email.emailAddresses.getAllEmailAddresses();
            }
        }
Example #4
0
        public void ShowDialog(ref emailAddress cur_email)
        {
            // Assign cur_email to local parameters
            textBox1.Text = cur_email.address; // uncomment if you want current email address to appear in first text box
            notificationsCheckBox.Checked = cur_email.notifyWithUpdates;
            commandsCheckBox.Checked      = cur_email.canSendCommands;
            loc_email = cur_email;

            // Hide current email address if it is null
            if (loc_email.address == null)
            {
                label2.Visible   = false;
                textBox1.Visible = false;
            }

            // Display and activate this form
            this.ShowDialog();

            // Return parameters
            cur_email = loc_email;
        }
        private void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                emailAddress selectedEmail = parentForm.home.email.emailAddresses.emailList[emailListBox.SelectedIndex];

                string            message = "Are you sure you would like to delete " + '\u0022' + selectedEmail.address + '\u0022' + " from your list of approved email addresses?";
                string            caption = "Confirm Email Deletion";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;

                result = MessageBox.Show(message, caption, buttons);

                if (result == DialogResult.Yes)
                {
                    parentForm.home.email.emailAddresses.RemoveAt(emailListBox.SelectedIndex);
                    emailListBox.DataSource = parentForm.home.email.emailAddresses.getAllEmailAddresses();
                }
            }
            catch
            {
                MessageBox.Show("There are no emails to delete!");
            }
        }
        private void EditButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Create new email entry for list
                emailAddress curEmail = parentForm.home.email.emailAddresses.emailList[emailListBox.SelectedIndex];
                emailAddress newEmail = curEmail;

                // create mail entry form and pass newEmail reference
                EmailInput emailInput = new EmailInput();
                emailInput.ShowDialog(ref newEmail);

                // Process new entry if newEmail != curEmail
                if ((newEmail.address != curEmail.address) || (newEmail.canSendCommands != curEmail.canSendCommands) || (newEmail.notifyWithUpdates != curEmail.notifyWithUpdates))
                {
                    //string message = "Are you sure you would like to edit " + curEmail + " to " + newEmail + "?";
                    //string caption = "Confirm Email Edit";
                    //MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    //DialogResult result;

                    //result = MessageBox.Show(message, caption, buttons);

                    //if (result == DialogResult.Yes)
                    //{

                    //emailList.emailList[emailListBox.SelectedIndex] = newEmail;
                    parentForm.home.email.emailAddresses.emailList[emailListBox.SelectedIndex] = newEmail;
                    emailListBox.DataSource = parentForm.home.email.emailAddresses.getAllEmailAddresses();
                    //}
                }
            }
            catch
            {
                MessageBox.Show("There are no emails to edit!");
            }
        }