Esempio n. 1
0
        //Change Type Details Button Clicked
        private void btnSet_Click(object sender, EventArgs e)
        {
            //Validation
            //Description Empty
            if (txtDescription.Text.Equals(""))
            {
                MessageBox.Show("Please enter in a Description", "Field Empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtDescription.Focus();
                picDescError.Visible = true;
                return;
            }
            //Hides Description Error pic
            picDescError.Visible = false;
            //Default Descrip Text
            if (txtDescription.Text.Equals("Enter a Description"))
            {
                String       strMessage = "Are you sure you wish to add this default description?\n\n" + txtDescription.Text;
                DialogResult diaRes     = MessageBox.Show(strMessage, "Is this Description ok?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (diaRes == DialogResult.No)
                {
                    txtDescription.Focus();
                    return;
                }
            }

            //Rate must be numeric
            decimal parsedValue;

            if (!decimal.TryParse(txtRate.Text, out parsedValue))
            {
                MessageBox.Show("This is a numeric only field", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRate.Focus();
                picRateError.Visible = true;
                return;
            }
            //Rate must be >0
            if (parsedValue <= 0)
            {
                MessageBox.Show("The rate must be greater than €0", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRate.Focus();
                picRateError.Visible = true;
                return;
            }
            //Rate empty
            if (txtRate.Text.Equals(""))
            {
                MessageBox.Show("Please enter in a Rate", "Field Empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRate.Focus();
                picRateError.Visible = true;
                return;
            }
            picRateError.Visible = false;
            //End Validation



            //Instantiate instance variables with values from form controls
            newKennelType.setType(cboType.Text.Substring(0, 2));
            newKennelType.setDescription(txtDescription.Text);
            newKennelType.setRate(Convert.ToDouble(txtRate.Text));

            try
            {
                //Update Kennels Type table
                newKennelType.updateKennelType();

                //Display confirmation message
                MessageBox.Show("Kennel Type Changed", "Confirmation",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("Kennel Type was not changed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //Reset UI
                cboType.Items.Clear();
                fillTypes();
                picDescError.Visible  = false;
                picRateError.Visible  = false;
                cboType.SelectedIndex = 0;
                txtDescription.Text   = "Enter a description";
                txtRate.Text          = "Enter a rate";
            }
        }
Esempio n. 2
0
        //SetType Button Click Handler
        private void btnSet_Click(object sender, EventArgs e)
        {
            //Validation

            //TextBox Type Empty - Displays Message, Focuses on Type text box, displays error icon next to text box and returns
            if (txtType.Text.Equals(""))
            {
                MessageBox.Show("Please enter in a Type", "Field Empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtType.Focus();
                picErrorType.Visible = true;
                return;
            }
            //Hides Error icon once past Type text box
            picErrorType.Visible = false;

            //Description empty - Displays Message, Focuses on Type text box, displays error icon next to text box and returns
            if (txtDescription.Text.Equals(""))
            {
                MessageBox.Show("Please enter in a Description", "Field Empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtDescription.Focus();
                picDescError.Visible = true;
                return;
            }
            //Hides Error icon once past Description text box
            picDescError.Visible = false;

            //Rate empty - - Displays Message, Focuses on Type text box, displays error icon next to text box and returns
            if (txtRate.Text.Equals(""))
            {
                MessageBox.Show("Please enter in a Rate", "Field Empty",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRate.Focus();
                picRateError.Visible = true;
                return;
            }
            //Rate Not numeric value
            Double parsedValue;

            if (!Double.TryParse(txtRate.Text, out parsedValue))
            {
                MessageBox.Show("This is a number only field", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRate.Focus();
                picRateError.Visible = true;
                return;
            }
            //Rate less than 0
            if (parsedValue < 0)
            {
                MessageBox.Show("Number less than €0 is not valid", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRate.Focus();
                picRateError.Visible = true;
                return;
            }
            //Hides Error Icon once conditions met
            picRateError.Visible = false;
            //End Validation



            //Instantiate instance variables with values from form controls
            newKennelType.setType(txtType.Text);
            newKennelType.setDescription(txtDescription.Text);
            newKennelType.setRate(Convert.ToDouble(txtRate.Text));


            //Insert Kennel Type
            try {
                //Method from KennelTypes Class
                newKennelType.insKennelType();
                //Display confiemation message
                MessageBox.Show("Kennel Type Set", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("Kennel Type not added", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //End inserting new Kennel Type

            //Reset UI
            txtType.Text         = "";
            txtDescription.Text  = "";
            txtRate.Text         = "0.00";
            picErrorType.Visible = false;
            picRateError.Visible = false;
            picDescError.Visible = false;
            txtType.Focus();
        } //End SetType Button Click Handler