Beispiel #1
0
        } //End Cell Click Event

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //Instance of Book
            Books aBook = new Books();

            //Validate input
            //Calling method to check all fields must not be empty
            if (!checkEmptyBox())
            {
                return;
            } //End Validate all fields

            //Validate ISBN format
            if (!BookValidation.isValidISBN(txtISBN.Text))
            {
                MessageBox.Show("Book ISBN: '" + txtISBN.Text + "' invalid", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtISBN.Text = "";
                txtISBN.Focus();
                return;
            } //End Validate ISBN

            //Validate Class No
            if (!BookValidation.isValidClassNo(txtClassNo.Text))
            {
                MessageBox.Show("Class No: '" + txtClassNo.Text + "' invalid format (Format: 005-CAY)", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtClassNo.Text = "";
                txtClassNo.Focus();
                return;
            } //End Validate ClassNo

            //Validate Title
            if (!BookValidation.isValidTitle(txtTitle.Text))
            {
                MessageBox.Show("Book Title: '" + txtTitle.Text + "' invalid! Alphanumeric Values Only", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTitle.Text = "";
                txtTitle.Focus();
                return;
            } //End Validate Title

            //Validate Author
            if (!BookValidation.isValidAuthor(txtAuthor.Text))
            {
                MessageBox.Show("Author: '" + txtAuthor.Text + "' invalid! Alphabets Only", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAuthor.Text = "";
                txtAuthor.Focus();
                return;
            } //End Validate Author

            //Validate Price
            if (!BookValidation.isValidPrice(txtPrice.Text))
            {
                MessageBox.Show("Price: '" + txtPrice.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice.Text = "";
                txtPrice.Focus();
                return;
            } //End Validate Price

            //Validate NoPages
            if (!BookValidation.isValidNoPages(txtPages.Text))
            {
                MessageBox.Show("Pages '" + txtPages.Text + "' invalid! Only digits allowed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPages.Text = "";
                txtPages.Focus();
                return;
            } //End Validate Pages

            //Validate PubName
            if (!BookValidation.isValidPubName(txtPName.Text))
            {
                MessageBox.Show("Publisher Name: '" + txtPName.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPName.Text = "";
                txtPName.Focus();
                return;
            } //End Validate PubName

            //Validate YearPublish
            if (!BookValidation.isValidYearPublished(txtYearPub.Text))
            {
                MessageBox.Show("Year Published: '" + txtYearPub.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtYearPub.Text = "";
                txtYearPub.Focus();
                return;
            } //End Validate Year Publish

            //Validate Year Range
            if (!BookValidation.isValidYearRange(txtYearPub.Text))
            {
                MessageBox.Show("Invalid Year Entered!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtYearPub.Text = "";
                txtYearPub.Focus();
                return;
            } //End Validate Year Range

            //Update Book Details in Book File
            aBook.setBookID(Convert.ToInt32(txtBookID.Text));
            aBook.setISBN(txtISBN.Text.Trim());
            aBook.setClassNo(txtClassNo.Text.ToString());

            //Check if the subject has changed
            if (cmbSubject.SelectedItem.Equals(strSubjectName))
            {
                //No change then get subject code
                aBook.setSubjectCode(Books.getSubjectCode(cmbSubject.SelectedItem.ToString()));
            }

            aBook.setSubjectCode(strSubjectCode);
            aBook.setTitle(txtTitle.Text);
            aBook.setAuthor(txtAuthor.Text);
            aBook.setEdition(Convert.ToInt32(nudEdition.Value));
            aBook.setPrice(Convert.ToDouble(txtPrice.Text));
            aBook.setPage(Convert.ToInt32(txtPages.Text));
            aBook.setPubName(txtPName.Text);

            //Check if the country has changed
            if (cmbCountry.SelectedItem.Equals(strCountryName))
            {
                //If no change get country code
                aBook.setCountry(Books.getCountryCode(cmbCountry.SelectedItem.ToString()));
            }

            aBook.setCountry(strCountryCode);
            aBook.setYearPub(txtYearPub.Text);

            //Update
            aBook.updBook();

            //Display Confirmation message
            MessageBox.Show("Book " + txtBookID.Text + " Details Updated", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            grdBookList.Visible = false;
            grpBookInfo.Visible = false;
            txtSTitle.Text      = "";
            txtSTitle.Focus();
        } //End Update
        } //End form load event

        private void btnRegister_Click(object sender, EventArgs e)
        {
            //Validate Input
            //Calling method to check all fields must not be empty
            if (!checkEmptyBox())
            {
                return;
            }

            //Validate ISBN format
            if (!BookValidation.isValidISBN(txtISBN.Text))
            {
                MessageBox.Show("Book ISBN: '" + txtISBN.Text + "' invalid", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtISBN.Text = "";
                txtISBN.Focus();
                return;
            } //End Validate ISBN

            //Validate Class No
            if (!BookValidation.isValidClassNo(txtClassNo.Text))
            {
                MessageBox.Show("Class No: '" + txtClassNo.Text + "' invalid format (Format: 005-CAY)", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtClassNo.Text = "";
                txtClassNo.Focus();
                return;
            } //End Validate ClassNo

            //Validate Title
            if (!BookValidation.isValidTitle(txtTitle.Text))
            {
                MessageBox.Show("Book Title: '" + txtTitle.Text + "' invalid! Alphanumeric Values Only", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtTitle.Text = "";
                txtTitle.Focus();
                return;
            } //End Validate Title

            //Validate Author
            if (!BookValidation.isValidAuthor(txtAuthor.Text))
            {
                MessageBox.Show("Author: '" + txtAuthor.Text + "' invalid! Alphabets Only", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtAuthor.Text = "";
                txtAuthor.Focus();
                return;
            } //End Validate Author

            //Validate Price
            if (!BookValidation.isValidPrice(txtPrice.Text))
            {
                MessageBox.Show("Price: '" + txtPrice.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPrice.Text = "";
                txtPrice.Focus();
                return;
            } //End Validate Price

            //Validate NoPages
            if (!BookValidation.isValidNoPages(txtPages.Text))
            {
                MessageBox.Show("Pages '" + txtPages.Text + "' invalid! Only digits allowed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPages.Text = "";
                txtPages.Focus();
                return;
            } //End Validate Pages

            //Validate PubName
            if (!BookValidation.isValidPubName(txtPName.Text))
            {
                MessageBox.Show("Publisher Name: '" + txtPName.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtPName.Text = "";
                txtPName.Focus();
                return;
            } //End Validate PubName

            //Validate YearPublish
            if (!BookValidation.isValidYearPublished(txtYearPub.Text))
            {
                MessageBox.Show("Year Published: '" + txtYearPub.Text + "' invalid!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtYearPub.Text = "";
                txtYearPub.Focus();
                return;
            } //End Validate Year Publish

            //Validate Year Range
            if (!BookValidation.isValidYearRange(txtYearPub.Text))
            {
                MessageBox.Show("Invalid Year Entered!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtYearPub.Text = "";
                txtYearPub.Focus();
                return;
            } //End Validate Year Range

            //Initiate Book Object
            Books aBook = new Books();

            aBook.setBookID(Convert.ToInt32(txtBookID.Text));
            aBook.setISBN(txtISBN.Text.Trim());
            aBook.setClassNo(txtClassNo.Text);
            aBook.setTitle(txtTitle.Text.Trim());
            aBook.setSubjectCode(strSubjectCode);
            aBook.setAuthor(txtAuthor.Text.Trim());
            aBook.setEdition(Convert.ToInt32(nudEdition.Value));
            aBook.setPrice(Convert.ToDouble(txtPrice.Text.Trim()));
            aBook.setPage(Convert.ToInt32(txtPages.Text.Trim()));
            aBook.setPubName(txtPName.Text.Trim());
            aBook.setCountry(strCountryCode);
            aBook.setYearPub(txtYearPub.Text);
            aBook.setPurcDate(Convert.ToString(DateTime.Today.ToString("dd-MMM-yyy")));
            aBook.setBookStatus('A');

            //Insert Book Record into Books Table
            aBook.regBook();

            //Display confirmation message
            MessageBox.Show("Book " + txtBookID.Text + " is Registered", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //Reset UI
            txtISBN.Text             = "";
            txtClassNo.Text          = "";
            txtTitle.Text            = "";
            cmbSubject.SelectedIndex = -1;
            txtAuthor.Text           = "";
            nudEdition.Value         = 0;
            txtPrice.Text            = "";
            txtPages.Text            = "";
            txtPName.Text            = "";
            cmbCountry.SelectedIndex = -1;
            txtYearPub.Text          = "";

            txtBookID.Text = Books.getNextBookID().ToString("0000");
            txtISBN.Focus();
        } //End Button Event