示例#1
0
 /*
  * Event Handler for Client Confirmed Text Box- Leave event
  * If user try to change term without pressing 'Proceed' Button
  */
 private void ClientConfirmedTextBox_Leave(object sender, EventArgs e)
 {
     if (ProceedButton.Enabled == false && ConfirmedTerm.ToString() != ClientConfirmedTextBox.Text)
     {
         MessageBox.Show("Confirmed Term changed from " + ConfirmedTerm.ToString() + " to " + ClientConfirmedTextBox.Text + "\n Press 'Proceed' to confirm this changes", "Term Changed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         ProceedButton.Enabled = true;
     }
 }
示例#2
0
        /*
         * Event Handler for Confirm Button
         * -Validating FUll Name, Telephone Number, Email Address
         * -
         */
        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            StreamWriter FileWriter;
            string       DynamicMessage;

            if (ProceedButton.Enabled == true)
            {
                MessageBox.Show("Please Confirm the Term by pressing Proceed button before confirming the membership");
            }
            else
            {
                if (NotNullValue(FullNameTextBox.Text, 1))
                {
                    //Full Name Regular Express Validation
                    //One Word is mandatory which includes Capital and small Letters
                    if (!Regex.IsMatch(FullNameTextBox.Text, @"^[A-Z a-z]*([A-Z a-z]*)+$"))
                    {
                        MessageBox.Show("Please enter valid name", "Invalid Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        FullNameTextBox.Focus();
                        FullNameTextBox.SelectAll();
                    }
                    else
                    {
                        if (NotNullValue(TelephoneTextBox.Text, 2))
                        {
                            //Telephone Number Reguar Expression Validation
                            //Grouping of 3 Number followed by space(not mandatory), then Next 3 numbers followed by space and then last 4 digits
                            if (!Regex.IsMatch(TelephoneTextBox.Text, @"^(\(?\d{3}\)*\s?\d{3}\s?\d{4})$"))
                            {
                                MessageBox.Show("Please enter valid telephone Number", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                TelephoneTextBox.Focus();
                                TelephoneTextBox.SelectAll();
                            }
                            else
                            {
                                if (NotNullValue(EmailTextBox.Text, 3))
                                {
                                    //Email Validation by Regular Expression
                                    bool CorrectEmail = Regex.IsMatch(EmailTextBox.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);

                                    if (!CorrectEmail)
                                    {
                                        MessageBox.Show("Please enter valid email address", "Invalid Email Address", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        EmailTextBox.Focus();
                                        EmailTextBox.SelectAll();
                                    }
                                    else
                                    {
                                        //If all the detais are correct, providing popup
                                        DynamicMessage = "Provided Details are as below:";
                                        DynamicMessage = DynamicMessage + "\n\nMembership Details :";
                                        DynamicMessage = DynamicMessage + "\nMembership ID      : " + MembershipIDLabel.Text;
                                        DynamicMessage = DynamicMessage + "\nConfirmed Term     : " + ConfirmedTerm.ToString();
                                        DynamicMessage = DynamicMessage + "\nMembership Fees  : " + ConfirmedTermTotal.ToString();
                                        DynamicMessage = DynamicMessage + "\n\nPersonal Details :";
                                        DynamicMessage = DynamicMessage + "\nFull Name              : " + FullNameTextBox.Text;
                                        DynamicMessage = DynamicMessage + "\nTelephone No.      : " + TelephoneTextBox.Text;
                                        DynamicMessage = DynamicMessage + "\nEmail ID                 : " + EmailTextBox.Text;
                                        DynamicMessage = DynamicMessage + "\n\nDo you want to cofirm the Membership Details?";

                                        //Yes No Popup  Display decision
                                        DialogResult DR = MessageBox.Show(DynamicMessage, "Do you want to Continue?", MessageBoxButtons.YesNo);
                                        if (DR == DialogResult.Yes)
                                        {
                                            try
                                            {
                                                //Saving details of membership to the Database File
                                                FileWriter = File.AppendText(DatabaseFileName);
                                                FileWriter.WriteLine(MembershipIDLabel.Text);
                                                FileWriter.WriteLine(JoinDayLabel.Text);
                                                FileWriter.WriteLine(FullNameTextBox.Text);
                                                FileWriter.WriteLine(TelephoneTextBox.Text);
                                                FileWriter.WriteLine(EmailTextBox.Text);
                                                FileWriter.WriteLine(ConfirmedTerm.ToString());
                                                FileWriter.WriteLine(ConfirmedTermTotal.ToString("N2"));
                                                FileWriter.Close();
                                                //closing File Writer

                                                if (SummaryButton.Enabled == false)
                                                {
                                                    SummaryButton.Enabled = true;
                                                }
                                                if (SearchButton.Enabled == false)
                                                {
                                                    SearchButton.Enabled = true;
                                                }

                                                //Confirmation Message
                                                DynamicMessage = "Hello, " + FullNameTextBox.Text + "!. Welcome Aboard. :) \n Your Membership ID is : " + MembershipIDLabel.Text;
                                                MessageBox.Show(DynamicMessage, "Membership Confirmed", MessageBoxButtons.OK, MessageBoxIcon.Information);

                                                MembershipDetailsGroupBox.Visible = false;
                                                //Clearing Fields
                                                TermTextBox.Text =
                                                    ClientConfirmedTextBox.Text               =
                                                        PricePerMonthLabel.Text               =
                                                            PriceFullTermLabel.Text           =
                                                                PriceNextTermLabel.Text       =
                                                                    FullNameTextBox.Text      =
                                                                        TelephoneTextBox.Text =
                                                                            EmailTextBox.Text = "";
                                                //Enabling Buttons
                                                SearchButton.Enabled        =
                                                    SummaryButton.Enabled   =
                                                        TermTextBox.Enabled =
                                                            ClientConfirmedTextBox.Enabled = true;
                                            }
                                            catch (Exception ex)
                                            {
                                                // Display an error message.
                                                MessageBox.Show(ex.Message);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        /*
         * Event handler for Proceed Button
         * -Generating Membership ID
         * -Enabling user input fields such as Email and Full Name
         * -Calculating Total Fees for provided input in Client Confirmed Textbox
         */
        private void ProceedButton_Click(object sender, EventArgs e)
        {
            Random RandomNumberGenerator = new Random();

            if (ClientConfirmedTextBox.Text == "")
            {
                MessageBox.Show("Term can not be Blank. Please enter input in months", "Blank Entry not allowed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClientConfirmedTextBox.Focus();
                ClientConfirmedTextBox.SelectAll();
            }
            else
            {
                try
                {
                    ConfirmedTerm = int.Parse(ClientConfirmedTextBox.Text);
                    if (ConfirmedTerm < 0)
                    {
                        MessageBox.Show("Please Enter Positive Number", "Negative Number not Allowed in Terms", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        ClientConfirmedTextBox.Focus();
                        ClientConfirmedTextBox.SelectAll();
                    }
                    else if (ConfirmedTerm == 0)
                    {
                        MessageBox.Show("Term can not be Zero. Please enter valid input", "Zero Terms not allowed in Terms", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        ClientConfirmedTextBox.Focus();
                        ClientConfirmedTextBox.SelectAll();
                    }
                    else
                    {
                        SearchButton.Enabled  = false;
                        SummaryButton.Enabled = false;
                        ProceedButton.Enabled = false;

                        //Checking if user has provided details from mentioned results
                        if (ConfirmedTerm.ToString() == TermTextBox.Text)
                        {
                            ConfirmedTermTotal = EnquiredPrice;
                        }
                        else if (ConfirmedTerm == NextMonth)
                        {
                            ConfirmedTermTotal = SuggestedPrice;
                        }
                        else
                        {
                            //Calculating Final Term Total based on user input
                            ConfirmedTermTotal = CalculateTotalFees(ConfirmedTerm);
                        }


                        int MembershipNumber = RandomNumberGenerator.Next(1, 999999);

                        //Randomly generating Membership ID until we get unique
                        //-Comparing it with file to check if generated ID exists in file
                        while (MembershipIdExists(MembershipNumber.ToString("D6"), false, false))
                        {
                            MembershipNumber = RandomNumberGenerator.Next(1, 999999);
                        }

                        MembershipIDLabel.Text = MembershipNumber.ToString("D6");
                        JoinDayLabel.Text      = DateTime.Now.ToShortDateString();

                        MembershipDetailsGroupBox.Visible = true;
                        FullNameTextBox.Focus();
                    }
                }
                catch
                {
                    MessageBox.Show("Invalid input provided for Terms. Please provide number", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TermTextBox.Focus();
                    TermTextBox.SelectAll();
                }
            }
        }