// -------------------------------------------------------------------------------- // Name: SaveData // Abstract: Get the data off the form and save it to the database // -------------------------------------------------------------------------------- private boolean SaveData() { boolean blnResult = false; try { // Make a suitcase for moving data udtTeamType udtNewTeam = new CUserDataTypes().new udtTeamType(); // Load suitcase with data from the form udtNewTeam.intTeamID = 0; // Don't know it yet so set to 0 udtNewTeam.strTeam = m_txtTeam.getText(); udtNewTeam.strMascot = m_txtMascot.getText(); // We are busy CUtilities.SetBusyCursor(this, true); // Try to save the data blnResult = CDatabaseUtilities.AddTeamToDatabase(udtNewTeam); // Did it work? if (blnResult == true) { // Yes, save the new team ID m_intNewTeamID = udtNewTeam.intTeamID; } } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } finally { // We are no longer busy CUtilities.SetBusyCursor(this, false); } return blnResult; }
// -------------------------------------------------------------------------------- // Name: Initialize // Abstract: Default constructor // -------------------------------------------------------------------------------- public void Initialize() { try { int intHeight = 170; int intWidth = 282; // Title setTitle("Add Team"); // Size setSize(intWidth, intHeight); // Java is x, y centric // Center screen CUtilities.CenterOwner(this); // No resize setResizable(false); // Very important or programs will not close properly // Exit appllication on close; does not work on JDialog setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); } catch (Exception excError) { // Save log to disk CUtilities.WriteLog(excError); } }
// -------------------------------------------------------------------------------- // Name: IsValidData // Abstract: Check all the data and warn the user if it's bad // -------------------------------------------------------------------------------- private boolean IsValidData() { // Assume data is good easier to code that way boolean blnIsValidData = true; try { String strErrorMessage = "Please correct the following error(s):\n"; // Trim all textboxes CUtilities.TrimAllFormTextBoxes(this); // Team if (m_txtTeam.getText().equals("") == true) { strErrorMessage += "-Team cannot be blank\n"; blnIsValidData = false; } // Mascot if (m_txtMascot.getText().equals("") == true) { strErrorMessage += "-Mascot cannot be blank\n"; blnIsValidData = false; } // Bad data if (blnIsValidData == false) { CMessageBox.Show(this, strErrorMessage, getTitle() + " Error", enuIconType.Warning); } } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } return blnIsValidData; }
// -------------------------------------------------------------------------------- // Name: AddControls // Abstract: Add all the controls to the frame // -------------------------------------------------------------------------------- public void AddControls() { try { // Clear the layout manager so we can manually size and position controls CUtilities.ClearLayoutManager(this); // Add a label to dialog and save the label to m_lblTeam m_lblTeam = CUtilities.AddLabel(this, "Team:*", 25, 20); // Add a textbox and save it to m_txtTeam m_txtTeam = CUtilities.AddTextBox(this, 20, 80, 20, 185, 50); // Add a label to the frame m_lblMascot = CUtilities.AddLabel(this, "Mascot:*", 55, 20); // Add a textbox and save it to m_txtTeam m_txtMascot = CUtilities.AddTextBox(this, 50, 80, 20, 185, 50); m_lblRequiredFieldLabel = CUtilities.AddRequiredFieldLabel(this, 70, 75); // add button and save to m_btnOK m_btnOK = CUtilities.AddButton(this, this, "OK", 100, 25, 30, 110); // Add button and save to m_btnCancel m_btnCancel = CUtilities.AddButton(this, this, "Cancel", 100, 150, 30, 110); } catch (Exception excError) { // Save log to disk CUtilities.WriteLog(excError); } }
// -------------------------------------------------------------------------------- // Name: GetResult // Abstract: Get result flag indicating if the edit was successful. // -------------------------------------------------------------------------------- public boolean GetResult() { try { } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } return m_blnResult; }
// -------------------------------------------------------------------------------- // Name: Paint // Abstract: Override the paint event to draw grid marks // -------------------------------------------------------------------------------- public void paint(Graphics g) { super.paint(g); try { // CUtilities.DrawGridMarks( this, g ); } catch (Exception excError) { // Display error message CUtilities.WriteLog(excError); } }
// -------------------------------------------------------------------------------- // Name: btnCancel_Click // Abstract: Hide the form // -------------------------------------------------------------------------------- public void btnCancel_Click() { try { // Hide form this.setVisible(false); } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } }
// -------------------------------------------------------------------------------- // Name: actionPerformed // Abstract: Event handler for control click events // -------------------------------------------------------------------------------- @Override public void actionPerformed(ActionEvent aeSource) { try { // // btnopenDatabaseConnection if (aeSource.getSource() == m_btnOK) btnOK_Click(); else if (aeSource.getSource() == m_btnCancel) btnCancel_Click(); } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } }
// -------------------------------------------------------------------------------- // Name: DAddTeam // Abstract: parametrized constructor // -------------------------------------------------------------------------------- public DAddTeam(JDialog dlgParent) { super(dlgParent, true); // true = modal try { // initialize the frame Initialize(); // Add controls to the frame AddControls(); } catch (Exception excError) { // Save log to disk CUtilities.WriteLog(excError); } }
// -------------------------------------------------------------------------------- // Name: GetNewTeamInformation // Abstract: Get the new team information from the form. // -------------------------------------------------------------------------------- public udtTeamType GetNewTeamInformation() { udtTeamType udtTeam = null; try { udtTeam = new CUserDataTypes().new udtTeamType(); udtTeam.intTeamID = m_intNewTeamID; udtTeam.strTeam = m_txtTeam.getText(); udtTeam.strMascot = m_txtMascot.getText(); } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } return udtTeam; }
// -------------------------------------------------------------------------------- // Name: btnOK_Click // Abstract: Add the team to the database // -------------------------------------------------------------------------------- public void btnOK_Click() { try { // Is the form data good? if (IsValidData() == true) { // Did it save to the database if (SaveData() == true) { // Yes, success m_blnResult = true; // Yes, all done setVisible(false); } } } catch (Exception excError) { // log and display errors CUtilities.WriteLog(excError); } }