コード例 #1
0
  /**
   * Creates a new <code>AccountingEntryDialog</code> to let the user edit an existing entry.
   *
   * @param parent This dialog's parent frame.
   * @param modal Whether this dialog should be modal or not.
   * @param dbcon A connection to the database where the accounting information is stored.
   * @param ID The ID of the entry to be edited.
   * @see salssuite.server.module.AccountingModule#buildDatabase
   */
  public AccountingEntryDialog(java.awt.Frame parent, boolean modal, Connection dbcon, int ID) {
    this(parent, modal, dbcon);
    this.ID = ID;

    // overwrite default values loaded in other constructor
    try {
      ResultSet entry = stmt.executeQuery("SELECT * FROM accounting " + "WHERE id = " + ID);
      entry.next();

      date = entry.getString("date");
      String[] dateParts = Util.parseDateString(date);
      dayInput.setText(dateParts[2]);
      monthInput.setText(dateParts[1]);
      yearInput.setText(dateParts[0]);

      time = entry.getString("time");
      String[] timeParts = Util.parseTimeString(time);
      hourInput.setText(timeParts[0]);
      minutesInput.setText(timeParts[1]);
      secondsInput.setText(timeParts[2]);

      outgoInput.setText(entry.getString("outgo").replaceAll("-", ""));
      incomeInput.setText(entry.getString("income"));
      descriptionInput.setText(entry.getString("description"));
    } catch (SQLException e) {
      JOptionPane.showMessageDialog(
          this,
          "Fehler bei der Kommunikation mit der" + " Datenbank",
          "Netzwerkfehler",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
      return;
    }

    setTitle("Eintrag bearbeiten");
    outgoInput.requestFocus();
  }
コード例 #2
0
  /**
   * Sets the order represented by this component. The visual representation is done accordingly.
   *
   * @param orderID The order to be represented.
   * @param companyID The company which has ordered something.
   */
  public void setOrder(int orderID, int companyID) {

    this.orderID = orderID;

    try {

      // fetch data from the database
      ResultSet order = stmt.executeQuery("SELECT * FROM orders WHERE " + "id = " + orderID);
      order.next();

      // do visual representation
      IDDisplay.setText("" + orderID);
      companyInput.setText("" + order.getInt("companyId"));
      String[] date = Util.parseDateString(order.getString("date"));
      String[] time = Util.parseTimeString(order.getString("time"));

      if (!(date == null) && !(time == null)) {
        dayInput.setText(date[2]);
        monthInput.setText(date[1]);
        yearInput.setText(date[0]);
        hourInput.setText(time[0]);
        minuteInput.setText(time[1]);
      }

      if (order.getInt("processed") == 1) isOrderProcessedCheckbox.setSelected(true);
      else isOrderProcessedCheckbox.setSelected(false);

      if (order.getInt("paid") == 1) isOrderPaidCheckbox.setSelected(true);
      else isOrderPaidCheckbox.setSelected(false);

      // process the wares belonging to this order
      ResultSet orderedWares =
          stmt.executeQuery(
              "SELECT wareId, pieces FROM"
                  + " orderParts WHERE orderId = "
                  + orderID
                  + " ORDER BY (wareId)");

      while (orderedWares.next()) {

        Statement stmt2 = client.getDatabaseConnection().createStatement();
        ResultSet ware =
            stmt2.executeQuery(
                "SELECT name FROM goods " + "WHERE id = " + orderedWares.getInt("wareId"));
        ware.next();

        // new entry for ware display
        String wareEntry = "";
        wareEntry += orderedWares.getInt("wareId") + " // ";
        wareEntry += ware.getString("name") + " // ";
        wareEntry += orderedWares.getInt("pieces");

        wareListModel.addElement(wareEntry);
      }

    } catch (SQLException e) {
      JOptionPane.showMessageDialog(
          client,
          "Fehler bei der Kommunikation" + "mit der Datenbank.",
          "Netzwerkfehler",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
      return;
    }

    // update total numbers
    updateTotalNumbers();
  }