コード例 #1
0
ファイル: NewJFrame.java プロジェクト: yangmyfly/A2
  private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    if (jButton5.getText() == "Login") {
      try {
        String username;
        char[] password;
        username = jTextField6.getText();
        password = jPasswordField1.getPassword();
        token = client.login(username, password);
        System.out.println("Thank you : " + token);
        if (!token.trim().equals("Error")) {
          loggedIn(username);
        } else {
          token = "";
          jLabel14.setText("Wrong Username Password. Please Try again.");
        }
      } catch (RemoteException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
      }

    } else {

      try {
        if (client.logout(token)) {
          notLoggedIn();
        } else {
          jLabel14.setText("Something went wrong. Please Try again.");
        }
      } catch (RemoteException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
コード例 #2
0
ファイル: NewJFrame.java プロジェクト: yangmyfly/A2
  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // This method is responsible changing the status of the order
    // to shipped.

    String errString = null; // String for displaying errors
    // SQL query result set pointer
    int rows; // Rows updated
    // SQL statement string
    HashMap map = new HashMap<String, String>();
    if (map.get("error") == "true") {

      jTextArea4.append((String) map.get("emessage"));
      jTextArea1.setText("");
    } else {
      try {
        map = client.updateOrder("" + updateOrderID, jTextField1.getText(), token);
        if (map.get("expired") == "true") {
          sessionTimeOut();
        } else {
          jTextArea4.append((String) map.get("message"));

          // execute the statement
          rows = Integer.parseInt((String) map.get("rows"));

          // if the query worked, then we display the data in TextArea 4 - BTW, its highly
          // unlikely that the row won't exist and if it does the database tables are
          // really screwed up... this should not fail if you get here, but the check (in the
          // form of the else clause) is in place anyway
          if (rows > 0) {
            jTextArea4.setText(
                "\nOrder #" + updateOrderID + " status has been changed to shipped.");

          } else {

            jTextArea4.setText("\nOrder #" + updateOrderID + " record not found.");
          } // execute check

          // Clean up the form
          jButton1.setEnabled(false);
          jButton3.setEnabled(false);
          jTextArea1.setText("");
          jTextArea2.setText("");
          jTextArea3.setText("");
          jTextField2.setText("");
          jTextField3.setText("");
          jTextField4.setText("");
          jTextField5.setText("");
        }
      } catch (RemoteException ex) {
        Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
コード例 #3
0
ファイル: NewJFrame.java プロジェクト: yangmyfly/A2
  private void getPendingOrders() {

    // This method is responsible for querying the orders database and
    // getting the list of pending orders. This are orders that have not
    // been shipped as of yet. The list of pending orders is written to
    // jTextArea1.
    try {
      // This method is responsible for querying the orders database and
      // getting the list of orders that have been shipped. The list of shipped
      // orders is written to jTextArea1.
      HashMap map = new HashMap<String, String>();
      map = client.getOrders(jTextField1.getText(), 0, token);
      if (map.get("expired") == "true") {
        sessionTimeOut();
      } else {
        // Clean up the form before we start
        jTextArea1.setText("");
        jTextArea2.setText("");
        jTextArea3.setText("");
        jTextField2.setText("");
        jTextField3.setText("");
        jTextField4.setText("");
        jTextField5.setText("");

        // Display the data in the textarea
        jTextArea1.setText("");

        if (map.get("result") != null) {
          jTextArea1.append(map.get("result") + "\n");
          jButton3.setEnabled(true);
        }

        jTextArea4.setText((String) map.get("message"));
      }
    } // getPendingOrders
    catch (RemoteException ex) {
      Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
  } // getPendingOrders
コード例 #4
0
ファイル: NewJFrame.java プロジェクト: yangmyfly/A2
  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    try {
      // This button gets the selected line of text from the
      // order list window jTextArea1. The line of text is parsed for the
      // order number. Once the order number is parsed, then the order is
      // retrieved from the orders database. The ordertabel field from the
      // record contains the name of the table that has the items that make
      // up the order. This table is opened and all the items are listed
      // in jTextArea3.

      int beginIndex; // Parsing index
      int endIndex; // Parsing index
      String msgString = null; // String for displaying non-error messages
      String orderSelection = null; // Order selected from TextArea1
      // The name of the table containing the order items
      String orderID = null; // Product ID pnemonic
      // SQL query
      HashMap map = new HashMap<String, String>();
      // this is the selected line of text
      orderSelection = jTextArea1.getSelectedText();

      // make sure its not blank
      if (orderSelection.length() > 0) {
        // get the product ID
        beginIndex = 0;
        beginIndex = orderSelection.indexOf(" # ", beginIndex);
        beginIndex = beginIndex + 3; // skip past _#_
        endIndex = orderSelection.indexOf(" :", beginIndex);
        orderID = orderSelection.substring(beginIndex, endIndex);

      } else {

        msgString = ">> Order string is blank...";
        jTextArea4.setText("\n" + msgString);
      } // Blank string check
      map = client.getOrder(orderID, jTextField1.getText(), token);
      if (map.get("expired") == "true") {
        sessionTimeOut();
      } else {
        // If an order was selected, then connect to the orderinfo database. In
        // all normal situations this would be impossible to do since the select
        // button is disabled until an order is selected... just in case the
        // check is here.
        jTextArea4.setText((String) map.get("conmessage"));
        if (map.get("error") == "true") {

          jTextArea1.append((String) map.get("quemessage"));
        } else {
          jTextField2.setText((String) map.get("firstname")); // first name
          jTextField3.setText((String) map.get("lastname")); // last name
          jTextField4.setText((String) map.get("phone")); // phone
          jTextField5.setText((String) map.get("orderdate")); // order date
          jTextArea2.setText((String) map.get("address")); // address

          // list the items on the form that comprise the order
          jTextArea3.setText((String) map.get("result"));

          // This global variable is used to update the record as shipped
          updateOrderID = Integer.parseInt((String) map.get("orderID"));

          // Update the form
          jButton1.setEnabled(true);
          jTextArea4.setText((String) map.get("quemessage"));
        }
      }
    } catch (RemoteException ex) {
      Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
    }
  }