Beispiel #1
0
        //Send message and shows summary
        private void btnPublish_Click(object sender, EventArgs e)
        {
            string textMsg = "";

            string message = textBoxMsg.Text;

            textBoxMsg.Clear();

            // MessageBox.Show("Message sent with success...");
            textMsg += "Summary: \n";
            textMsg += "Email addresses: \n";

            //send message to emails on the list
            foreach (var item in emailToPublish)
            {
                SendViaEmail em = new SendViaEmail(item);
                em.Subscribe(pb);
                pb.publishmsg(message);
                textMsg += item + "\n";
            }
            textMsg += "Mobile numbers: \n";

            //send message to the mobile phones in the list
            foreach (var mobile in phoneToPublish)
            {
                SendViaMobile mb = new SendViaMobile(mobile);
                mb.Subscribe(pb);
                pb.publishmsg(message);
                textMsg += mobile + "\n";
            }
            //show summary
            MessageBox.Show(textMsg);
        }
        //Subscribe and Check if informations are valid and it already exists in the list
        private void btnSubscribe_Click(object sender, EventArgs e)
        {
            //constist email format
            TestConsist();

            //valid if the e-mail and phone are checked
            if (checkBoxEmail.Checked == true && checkBoxMobile.Checked == true)
            {
                if ((EmailOk) && (PhoneOK))
                {
                    SendViaEmail  sendEmail  = new SendViaEmail(textBoxEmail.Text);
                    SendViaMobile sendMobile = new SendViaMobile(textBoxPhone.Text);

                    //verify if they are in the lists
                    ContainsListEmail = ContainsEmail(textBoxEmail.Text);
                    ContainsListPhone = ContainsPhone(textBoxPhone.Text);

                    //if no contains in the list, so include them and clear textboxes to accept new values
                    if (!ContainsListEmail && !ContainsListPhone)
                    {
                        sendEmail.AddEmailList();
                        sendMobile.AddMobileList();
                        MessageBox.Show("Subscribed." + "\n" +
                                        "Email add: " + textBoxEmail.Text + "\n" + "Phone add: " + textBoxPhone.Text);
                        textBoxEmail.Clear();
                        textBoxPhone.Clear();
                    }
                    //if contains show warning message
                    else if ((ContainsListEmail) || (ContainsListPhone))
                    {
                        MessageBox.Show("It is already in the list.....");
                    }
                }
            }
            // if choose only email/ check it is valid and if contain in the list
            else if (checkBoxEmail.Checked == true && checkBoxMobile.Checked == false)
            {
                if (EmailOk)
                {
                    SendViaEmail sendEmail = new SendViaEmail(textBoxEmail.Text);
                    ContainsListEmail = ContainsEmail(textBoxEmail.Text);

                    if (!ContainsListEmail)
                    {
                        sendEmail.AddEmailList();
                        MessageBox.Show("Subscribed." + "\n" + "Email add : " + textBoxEmail.Text);
                        textBoxEmail.Clear();
                    }
                    else
                    {
                        MessageBox.Show("It is already in the list.....");
                    }
                }
                //else
                //{
                //    MessageBox.Show("Invalid email address");
                //}
            }
            // if choose only phone/ check it is valid and if contain in the list
            else if (checkBoxEmail.Checked == false && checkBoxMobile.Checked == true)
            {
                if (PhoneOK)
                {
                    SendViaMobile sendMobile = new SendViaMobile(textBoxPhone.Text);
                    ContainsListPhone = ContainsPhone(textBoxPhone.Text);
                    if (!ContainsListPhone)
                    {
                        sendMobile.AddMobileList();
                        MessageBox.Show("Subscribed." + "\n" + "Phone add : " + textBoxPhone.Text);
                        textBoxPhone.Clear();
                    }
                    else
                    {
                        MessageBox.Show("It is already in the list.....");
                    }
                }
                //else
                //{
                //    MessageBox.Show("Invalid phone number");
                //}
            }
            //if do not choose anything shows a warning
            else
            {
                MessageBox.Show("Choose one.....");
            }
        }
        //Unsubscribe and Check if informations are valid and it is not exists in the list
        private void btnUnsubscribe_Click(object sender, EventArgs e)
        {
            TestConsist();
            if (checkBoxEmail.Checked == true && checkBoxMobile.Checked == true)
            {
                if ((EmailOk) && (PhoneOK))
                {
                    SendViaEmail  sendEmail  = new SendViaEmail(textBoxEmail.Text);
                    SendViaMobile sendMobile = new SendViaMobile(textBoxPhone.Text);

                    ContainsListEmail = ContainsEmail(textBoxEmail.Text);
                    ContainsListPhone = ContainsPhone(textBoxPhone.Text);


                    if (ContainsListEmail && ContainsListPhone)
                    {
                        sendEmail.RemoveEmailList();

                        MessageBox.Show("Unsubscribed" + "\n"
                                        + "Email Removed: " + textBoxEmail.Text + "\n" + "Phone Remove: " + textBoxPhone.Text);

                        textBoxEmail.Clear();
                        textBoxPhone.Clear();
                    }
                    else if ((!ContainsListEmail) || (!ContainsListPhone))
                    {
                        MessageBox.Show("There are not in the list.....");
                    }
                }
            }
            else if (checkBoxEmail.Checked == true && checkBoxMobile.Checked == false)
            {
                if (EmailOk)
                {
                    SendViaEmail sendEmail = new SendViaEmail(textBoxEmail.Text);
                    ContainsListEmail = ContainsEmail(textBoxEmail.Text);

                    if (ContainsListEmail)
                    {
                        sendEmail.RemoveEmailList();
                        textBoxEmail.Clear();
                    }
                    else
                    {
                        MessageBox.Show("It is not in the list.....");
                    }
                }
                //else
                //{
                //    MessageBox.Show("Invalid email address");
                //}
            }
            else if (checkBoxEmail.Checked == false && checkBoxMobile.Checked == true)
            {
                if (PhoneOK)
                {
                    SendViaMobile sendMobile = new SendViaMobile(textBoxPhone.Text);
                    ContainsListPhone = ContainsPhone(textBoxPhone.Text);

                    if (ContainsListPhone)
                    {
                        sendMobile.RemoveMobileList();
                        textBoxPhone.Clear();
                    }
                    else
                    {
                        MessageBox.Show("It is not in the list.....");
                    }
                }
                //else
                //{
                //    MessageBox.Show("Invalid phone number");
                //}
            }
            else
            {
                MessageBox.Show("You need to choose somenting.....");
            }
        }