예제 #1
0
        private void btnRmv_Click(object sender, EventArgs e)
        {
            //instantiate Property Object
            Property myProperty = new Property();

            myProperty.setPropId(Convert.ToInt32(txtPropID.Text));
            myProperty.setRentPerMonth(Convert.ToInt32(txtRent.Text));
            myProperty.setBedrooms(Convert.ToInt32(txtBedrooms.Text));
            myProperty.setStreet(txtAdd1.Text);
            myProperty.setTown(txtAdd2.Text);
            myProperty.setCounty(txtCounty.Text);
            myProperty.setHouseType(txtHouse.Text);
            myProperty.setOwnerId(Convert.ToInt32(txtOwnerId.Text));

            //Set Property record in table as Inactive
            myProperty.rmvProperty();

            //Display Confirmation message
            MessageBox.Show("Property Removed From System", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            txtRent.Text      = "";
            txtBedrooms.Text  = "";
            txtBathrooms.Text = "";
            txtAdd1.Text      = "";
            txtAdd2.Text      = "";
            txtCounty.Text    = "";
            txtHouse.Text     = "";
            txtOwnerId.Text   = "";
        }
        private void updProperty_Click(object sender, EventArgs e)
        {
            //Validate Data
            if (txtRent.Text.Equals("") || txtBedrooms.Text.Equals("") || txtBathrooms.Text.Equals("") || txtHouse.Text.Equals("") || txtAdd1.Text.Equals("") || txtAdd2.Text.Equals("") || txtCounty.Text.Equals("") || txtActivity.Text.Equals(""))
            {
                MessageBox.Show("All fields must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            String rent = txtRent.Text;

            foreach (char c in rent)
            {
                if (c < '0' || c > '9')
                {
                    MessageBox.Show("Rent must be numeric!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }


            if (txtActivity.Text.ToUpper() != "A" && txtActivity.Text.ToUpper() != "I")
            {
                MessageBox.Show("Activity must be A or I!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }



            //Instantiate Property Object
            Property myProps = new Property();

            if (PropertySysv2.Owner.validNumbers(txtRent.Text))
            {
                myProps.setRentPerMonth(Convert.ToInt32(txtRent.Text));
            }
            else
            {
                MessageBox.Show("Rent must be numbers only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRent.Text = "";
                txtRent.Focus();
                return;
            }


            if (PropertySysv2.Owner.validNumbers(txtBedrooms.Text))
            {
                myProps.setBedrooms(Convert.ToInt32(txtBedrooms.Text));
            }
            else
            {
                MessageBox.Show("Bedrooms must be numbers only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBedrooms.Text = "";
                txtBedrooms.Focus();
                return;
            }


            if (PropertySysv2.Owner.validNumbers(txtBathrooms.Text))
            {
                myProps.setBathrooms(Convert.ToInt32(txtBathrooms.Text));
            }
            else
            {
                MessageBox.Show("Bathrooms must be numbers only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBathrooms.Text = "";
                txtBathrooms.Focus();
                return;
            }


            if (PropertySysv2.Owner.validText(txtHouse.Text))
            {
                myProps.setHouseType(txtHouse.Text);
            }
            else
            {
                MessageBox.Show("House Type must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtHouse.Text = "";
                txtHouse.Focus();
                return;
            }


            if (PropertySysv2.Owner.validText(txtAdd1.Text))
            {
                myProps.setStreet(txtAdd1.Text);
            }
            else
            {
                MessageBox.Show("Address Line 1 must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAdd1.Text = "";
                txtAdd1.Focus();
                return;
            }

            if (PropertySysv2.Owner.validText(txtAdd2.Text))
            {
                myProps.setTown(txtAdd2.Text);
            }
            else
            {
                MessageBox.Show("Address Line 2 must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAdd2.Text = "";
                txtAdd2.Focus();
                return;
            }

            if (PropertySysv2.Owner.validText(txtCounty.Text))
            {
                myProps.setCounty(txtCounty.Text);
            }
            else
            {
                MessageBox.Show("County must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCounty.Text = "";
                txtCounty.Focus();
                return;
            }
            myProps.setActivity(txtActivity.Text);
            myProps.setOwnerId(Convert.ToInt32(txtOwnerID.Text));

            //INSERT Property record into Property Table
            myProps.updProp();

            //Display Confirmation message
            MessageBox.Show("Owner Updated In System", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            txtRent.Text      = "";
            txtBedrooms.Text  = "";
            txtBathrooms.Text = "";
            txtHouse.Text     = "";
            txtAdd1.Text      = "";
            txtAdd2.Text      = "";
            txtCounty.Text    = "";
            txtActivity.Text  = "";
            txtOwnerID.Text   = "";

            grdProperties.Visible = false;
            grpProperties.Visible = false;
            cboBeds.SelectedIndex = -1;
            cboTown.SelectedIndex = -1;
        }
        private void btnPropertyAdd_Click(object sender, EventArgs e)
        {
            //Validate Data
            if (txtRent.Text.Equals("") || txtBedroom.Text.Equals("") || txtBathroom.Text.Equals("") || txtBoxHouse.Text.Equals("") || txtBoxAdd1.Text.Equals("") || txtBoxAdd2.Text.Equals("") || txtBoxCounty.Text.Equals(""))
            {
                MessageBox.Show("All fields must be entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            String rent = txtRent.Text;

            foreach (char c in rent)
            {
                if (c < '0' || c > '9')
                {
                    MessageBox.Show("Rent must be numeric!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtRent.Text = "";
                    return;
                }
            }

            //Instantiate Property
            Property myProps = new Property();

            myProps.setPropId(Convert.ToInt32(txtPropertyID.Text));

            if (PropertySysv2.Owner.validNumbers(txtRent.Text))
            {
                myProps.setRentPerMonth(Convert.ToInt32(txtRent.Text));
            }
            else
            {
                MessageBox.Show("Rent must be numbers only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRent.Text = "";
                txtRent.Focus();
                return;
            }


            if (PropertySysv2.Owner.validNumbers(txtBedroom.Text))
            {
                if (Convert.ToInt32(txtBedroom.Text) >= 7)
                {
                    MessageBox.Show("Bedrooms can't be greater than 6", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtBedroom.Text = "";
                    txtBedroom.Focus();
                    return;
                }
                else
                {
                    myProps.setBedrooms(Convert.ToInt32(txtBedroom.Text));
                }
            }
            else
            {
                MessageBox.Show("Bedrooms must be numbers only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBedroom.Text = "";
                txtBedroom.Focus();
                return;
            }


            if (PropertySysv2.Owner.validNumbers(txtBathroom.Text))
            {
                myProps.setBathrooms(Convert.ToInt32(txtBathroom.Text));
            }
            else
            {
                MessageBox.Show("Bathrooms must be numbers only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBathroom.Text = "";
                txtBathroom.Focus();
                return;
            }


            if (PropertySysv2.Owner.validText(txtBoxHouse.Text))
            {
                myProps.setHouseType(txtBoxHouse.Text);
            }
            else
            {
                MessageBox.Show("House Type must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBoxHouse.Text = "";
                txtBoxHouse.Focus();
                return;
            }


            if (PropertySysv2.Owner.validText(txtBoxAdd1.Text))
            {
                myProps.setStreet(txtBoxAdd1.Text);
            }
            else
            {
                MessageBox.Show("Address Line 1 must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBoxAdd1.Text = "";
                txtBoxAdd1.Focus();
                return;
            }

            if (PropertySysv2.Owner.validText(txtBoxAdd2.Text))
            {
                myProps.setTown(txtBoxAdd2.Text);
            }
            else
            {
                MessageBox.Show("Address Line 2 must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBoxAdd2.Text = "";
                txtBoxAdd2.Focus();
                return;
            }

            if (PropertySysv2.Owner.validText(txtBoxCounty.Text))
            {
                myProps.setCounty(txtBoxCounty.Text);
            }
            else
            {
                MessageBox.Show("County must be letters only", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtBoxCounty.Text = "";
                txtBoxCounty.Focus();
                return;
            }



            myProps.setActivity("A");
            myProps.setOwnerId(Convert.ToInt32(txtOwnerID.Text));

            //INSERT Property into Properties Table
            myProps.regProp();

            //Display Confirmation Message
            MessageBox.Show("Property Added to System", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            txtRent.Text        = "";
            txtBedroom.Text     = "";
            txtBathroom.Text    = "";
            txtBoxHouse.Text    = "";
            txtBoxAdd1.Text     = "";
            txtBoxAdd2.Text     = "";
            txtBoxCounty.Text   = "";
            txtOwnerSearch.Text = "";

            grpOwners.Visible   = false;
            grpProperty.Visible = false;
            grdOwners.Visible   = false;

            txtPropertyID.Text = PropertySysv2.Property.getNextPropId().ToString("00000");
            txtRent.Focus();
        }