private void saveCategory() throws SQLException {
        //Remember the category ID.
        clsCategoryDetail mCategoryDetail = this.pCategoryDetail;
        //Check whether fields are filled correctly.
        if (checkFieldsForSaving(false)) {
            switch (this.pStatus) {
                case New:
                    //Check whether category already exists.
                    if (this.pModel.checkCategoryExists(txtCategoryName.getText(), getArea())) {
                        JOptionPane.showMessageDialog(this, "The category already exists.", "Error", JOptionPane.ERROR_MESSAGE);
                    } else {
                        //Create the new category.
                        clsCategoryDetail mNewCategory = new clsCategoryDetail();
                        mNewCategory.setID_Categories_ParentCategory(getParentID());
                        mNewCategory.setCategoryName(txtCategoryName.getText());
                        mNewCategory.setArea(getArea());
                        //Save the new category.
                        int mIDCategory = this.pModel.saveNewCategory(mNewCategory);
                        //Check saving status.
                        if (mIDCategory > 0) {
                            //Set the status to view.
                            this.pStatus = enmStatus.View;
                            //Set the enabled status of the controls.
                            setControls();
                            //Reload the categories.
                            loadCategories();
                            //Select the newly created category.
                            selectCategory(mIDCategory);
                        } else {
                            JOptionPane.showMessageDialog(this, "Error saving the new category.", "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                    break;
                case Edit:
                    //Create the modified category.
                    clsCategoryDetail mModifiedCategory = new clsCategoryDetail();
                    mModifiedCategory.setID(this.pCategoryDetail.getID());
                    
                    //If category was changed.
                    String mCategoryNameOld = this.pCategoryDetail.getCategoryName();
                    String mCategoryNameNew = txtCategoryName.getText();
                    
                    //Check whether category already exists.
                    if (!mCategoryNameOld.equals(mCategoryNameNew)) {
                        if (this.pModel.checkCategoryExists(txtCategoryName.getText(), getArea())) {
                            JOptionPane.showMessageDialog(this, "The category already exists.", "Error", JOptionPane.ERROR_MESSAGE);
                            //Leave switch.
                            break;
                        } else {
                            //Add changed category name to newly created modified category.
                            mModifiedCategory.setCategoryName(txtCategoryName.getText());
                        }
                    }
                    
                    //Add changed parent category to newly created modified category.
                    mModifiedCategory.setID_Categories_ParentCategory(getParentID());
                    
                    //Save the modified category.
                    if (this.pModel.saveModifiedCategory(mModifiedCategory)) {
                        //Set the status to view.
                        this.pStatus = enmStatus.View;
                        //Set the enabled status of the controls.
                        setControls();
                        //Reload the categories.
                        loadCategories();
                        //Select the modified category.
                        selectCategory(mCategoryDetail.getID());
                    } else {
                        JOptionPane.showMessageDialog(this, "Error saving the modified category.", "Error", JOptionPane.ERROR_MESSAGE);
                    }
                    break;
            }
        }
    }