コード例 #1
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            //Validation
            //Calling Method to ensures no textbox is empty
            if (!checkEmptyTextBox())
            {
                return;
            }

            //Validate PPS using MemberValidation class static method
            if (!MemberValidation.isValidPPS(txtPPS.Text))
            {
                MessageBox.Show("PPS Number: " + txtPPS.Text + " invalid format! 7 Digits followed by 1 or 2 Uppercase Letters", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPPS.Text = "";
                txtPPS.Focus();
                return;
            } //End Validate PPS

            //Validate duplicate PPS MemberValidation class static method
            if (!MemberValidation.isDuplicatePPS(txtPPS.Text))
            {
                MessageBox.Show("PPS Number: " + txtPPS.Text + " is already exists", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPPS.Text = "";
                txtPPS.Focus();
                return;
            } //End validate duplicate PPS

            //Validate Surname MemberValidation class static method
            if (!MemberValidation.isValidSurname(txtSurname.Text))
            {
                MessageBox.Show("Surname '" + txtSurname.Text + "' invalid! No digits allowed!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtSurname.Text = "";
                txtSurname.Focus();
                return;
            } //End Validate Surname

            //Validate Forename MemberValidation class static method
            if (!MemberValidation.isValidForename(txtForename.Text))
            {
                MessageBox.Show("Forename '" + txtForename.Text + "' invalid! No digits allowed!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtForename.Text = "";
                txtForename.Focus();
                return;
            } //End Validate Forename

            //Validate Age MemberValidation class static method
            if (MemberValidation.calculateAge(dtpDOB.Value) < 16)
            {
                MessageBox.Show("Age must be over 16", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtpDOB.Focus();
                return;
            } //End Validate Age

            //Convert radio button value to char
            char    chrGender = ' ';
            Boolean isChecked = radMale.Checked;

            if (isChecked)
            {
                chrGender = Convert.ToChar(radMale.Text.Substring(0, 1));
            }
            else
            {
                chrGender = Convert.ToChar(radFemale.Text.Substring(0, 1));
            } //End Convert

            //Validate Phone MemberValidation class static method
            if (!MemberValidation.isValidPhone(txtPhone.Text))
            {
                MessageBox.Show("Phone '" + txtPhone.Text + "' invalid format! E.g. 083 5763489", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPhone.Text = "";
                txtPhone.Focus();
                return;
            } //End Validate Phone

            //Validate Email MemberValidation class static method
            if (!MemberValidation.isValidEmail(txtEmail.Text))
            {
                MessageBox.Show("Email '" + txtEmail.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmail.Text = "";
                txtEmail.Focus();
                return;
            } //End Validate Email

            //Validate Duplicate Email MemberValidation class static method
            if (!MemberValidation.isDuplicateEmail(txtEmail.Text))
            {
                MessageBox.Show("Email '" + txtEmail.Text + "' is already exists", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmail.Text = "";
                txtEmail.Focus();
                return;
            } //End Validate duplicate Email

            //Validate Street MemberValidation class static method
            if (!MemberValidation.isValidStreet(txtStreet.Text))
            {
                MessageBox.Show("Street '" + txtStreet.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtStreet.Text = "";
                txtStreet.Focus();
                return;
            } //End Validate County

            //Validate Town MemberValidation class static method
            if (!MemberValidation.isValidTown(txtTown.Text))
            {
                MessageBox.Show("Town '" + txtTown.Text + "' invalid! No digits allowed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTown.Text = "";
                txtTown.Focus();
                return;
            } //End Validate County

            //Validate County MemberValidation class static method
            if (!MemberValidation.isValidCounty(txtCounty.Text))
            {
                MessageBox.Show("County '" + txtCounty.Text + "' invalid! No digits allowed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCounty.Text = "";
                txtCounty.Focus();
                return;
            } //End Validate County

            //Instantiate Member object
            Members aMember = new Members();

            aMember.setMemID(Convert.ToInt32(txtMemberID.Text));
            aMember.setPpsNo(txtPPS.Text);
            aMember.setSurname(txtSurname.Text.Trim());
            aMember.setForename(txtForename.Text.Trim());
            aMember.setDOB(dtpDOB.Text);
            aMember.setGender(chrGender);
            aMember.setPhone(txtPhone.Text);
            aMember.setEmail(txtEmail.Text.Trim());
            aMember.setStreet(txtStreet.Text.Trim());
            aMember.setTown(txtTown.Text.Trim());
            aMember.setCounty(txtCounty.Text.Trim());
            aMember.setRegDate(dtpRegisterDate.Text);
            aMember.setMemStatus('A');

            //Insert Member record into member table
            aMember.regMember();

            //Display Confirmation Message
            MessageBox.Show("Member " + txtMemberID.Text + " Registered",
                            "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            txtPPS.Text           = "";
            txtSurname.Text       = "";
            txtForename.Text      = "";
            dtpDOB.Value          = DateTime.Today;
            radMale.Checked       = true;
            txtPhone.Text         = "";
            txtEmail.Text         = "";
            txtStreet.Text        = "";
            txtTown.Text          = "";
            txtCounty.Text        = "";
            dtpRegisterDate.Value = DateTime.Today;

            txtMemberID.Text = Members.getNextMemberID().ToString("0000");
            txtPPS.Focus();
        } //End of btnRegister_Click()
コード例 #2
0
        } //End grdMemberList_CellClick();

        //Update Button Event
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //Instance of Members
            Members aMember = new Members();

            //Retrieve details from this member item from DB
            aMember.getMember(Convert.ToInt32(grdMemberList.Rows[grdMemberList.CurrentCell.RowIndex].Cells[0].Value));

            //Calling Method to check empty textbox
            if (!checkEmptyTextBox())
            {
                return;
            }

            //Validate PPS
            if (!MemberValidation.isValidPPS(txtPPS.Text))
            {
                MessageBox.Show("PPS Number: " + txtPPS.Text + " invalid format! 7 Digits followed by 2 Uppercase Letters", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPPS.Text = "";
                txtPPS.Focus();
                return;
            } //End Validate PPS

            //Validate PPS only if the PPS No has changed, check for duplicate PPS in DB
            if (!aMember.getPpsNo().Equals(txtPPS.Text))
            {
                //Validate duplicate PPS
                if (!MemberValidation.isDuplicatePPS(txtPPS.Text))
                {
                    MessageBox.Show("PPS Number: " + txtPPS.Text + " is already exists", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPPS.Text = "";
                    txtPPS.Focus();
                    return;
                } //End validate duplicate PPS
            }

            //Validate Surname
            if (!MemberValidation.isValidSurname(txtSurname.Text))
            {
                MessageBox.Show("Surname '" + txtSurname.Text + "' invalid! No digits allowed!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtSurname.Text = "";
                txtSurname.Focus();
                return;
            } //End Validate Surname

            //Validate Forename
            if (!MemberValidation.isValidForename(txtForename.Text))
            {
                MessageBox.Show("Forename '" + txtForename.Text + "' invalid! No digits allowed!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtForename.Text = "";
                txtForename.Focus();
                return;
            } //End Validate Forename

            //Validate Age
            if (MemberValidation.calculateAge(dtpDOB.Value) < 16)
            {
                MessageBox.Show("Age must be over 16", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                dtpDOB.Focus();
                return;
            } //End Validate Age

            //Convert radio button value to char
            char    chrGender = ' ';
            Boolean isChecked = radMale.Checked;

            if (isChecked)
            {
                chrGender = Convert.ToChar(radMale.Text.Substring(0, 1));
            }
            else
            {
                chrGender = Convert.ToChar(radFemale.Text.Substring(0, 1));
            } //End Convert

            //Validate Phone
            if (!MemberValidation.isValidPhone(txtPhone.Text))
            {
                MessageBox.Show("Phone '" + txtPhone.Text + "' invalid format! E.g. 083 5763489", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPhone.Text = "";
                txtPhone.Focus();
                return;
            } //End Validate Phone

            //Vaidate Email
            if (!MemberValidation.isValidEmail(txtEmail.Text))
            {
                MessageBox.Show("Email '" + txtEmail.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtEmail.Text = "";
                txtEmail.Focus();
                return;
            } //End Validate Email

            //Validate only if the email has changed, check for duplicate email in DB
            if (!aMember.getEmail().Equals(txtEmail.Text))
            {
                if (!MemberValidation.isDuplicateEmail(txtEmail.Text))
                {
                    MessageBox.Show("Email '" + txtEmail.Text + "' is already exists", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtEmail.Text = "";
                    txtEmail.Focus();
                    return;
                }
            }

            //Validate Street
            if (!MemberValidation.isValidStreet(txtStreet.Text))
            {
                MessageBox.Show("Street '" + txtStreet.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtStreet.Text = "";
                txtStreet.Focus();
                return;
            }

            //Validate Town
            if (!MemberValidation.isValidTown(txtTown.Text))
            {
                MessageBox.Show("Town '" + txtTown.Text + "' invalid! No digits allowed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTown.Text = "";
                txtTown.Focus();
                return;
            }

            //Validate County
            if (!MemberValidation.isValidCounty(txtCounty.Text))
            {
                MessageBox.Show("County '" + txtCounty.Text + "' invalid! No digits allowed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCounty.Text = "";
                txtCounty.Focus();
                return;
            }

            //Update Member Details in DB
            aMember.setMemID(Convert.ToInt32(txtMemID.Text));
            aMember.setPpsNo(txtPPS.Text);
            aMember.setSurname(txtSurname.Text.Trim());
            aMember.setForename(txtForename.Text.Trim());
            aMember.setDOB(dtpDOB.Value.ToString("dd-MMM-yy"));
            aMember.setGender(chrGender);
            aMember.setPhone(txtPhone.Text.Trim());
            aMember.setEmail(txtEmail.Text.Trim());
            aMember.setStreet(txtStreet.Text.Trim());
            aMember.setTown(txtTown.Text.Trim());
            aMember.setCounty(txtCounty.Text.Trim());

            aMember.updMember(); //Update Member

            //Display Confirmation Message
            MessageBox.Show("Member Details " + txtMemID.Text + " Updated", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            grpUpdMemDetails.Visible = false;
            grdMemberList.Visible    = false;
            txtSname.Text            = "";
            txtSname.Focus();
        } //End btnUpd_Click