示例#1
0
        //save the phone number values
        private bool savePhoneNum()
        {
            //if both fields are blank, just ignore (don't save)
            if (txtPhoneNum.Text.Equals("") && cbPhoneType.Text.Equals(""))
            {
                return(true);
            }

            if (txtPhoneNum.Text.Equals(""))
            {
                Util.displayRequiredFieldsError("Phone Number");
                return(false);
            }

            //check if phone number is already been added
            if (phoneNumbers.Contains(txtPhoneNum.Text))
            {
                Util.displayError("You have already added this phone number.", "Duplicate Phone Number");
                return(false);
            }

            phoneNumbers.Add(Util.escape(txtPhoneNum.Text));
            phoneTypes.Add(Util.escape(cbPhoneType.Text));
            return(true);
        }
        //event handler for when the create database button is pressed
        private void btnCreateDatabase_Click(object sender, EventArgs e)
        {
            //if encrypting the database, check if the passwords are equal and display error if they don't match
            if (chkEncrypt.Checked == true && txtEnterPassword.Text.Equals(txtConfirmPassword.Text) == false)
            {
                lblError.Visible = true;
            }
            //if not encrypting the database or the passwords match, create the database
            else
            {
                //display error message and quit if error creating database
                while (Database.createDatabase() == false)
                {
                    DialogResult result = MessageBox.Show("An Unexpected Error Occurred Creating the Database. Check the Error Log for more detailed information.", "Error Creating Database", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    if (result == DialogResult.Cancel)
                    {
                        Environment.Exit(1);
                    }
                }

                //change the password (this action encrypts the database)
                if (chkEncrypt.Checked == true)
                {
                    Database.changePassword(Util.escape(txtConfirmPassword.Text));
                }
                lblError.Visible = false;
                Close();
            }
        }