⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderentryframe.java

📁 java在线商店的源代码。编写十分规范的哦
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  }

  /**
   * Before closing the window, check for any pending changes, and prompt user
   * if there are changes pending. Note that we need to both check if there is
   * anything to Post, and to check if there is anything to resolve.
   *
   * @param e WindowEvent
   *
   */
  void this_windowClosing(WindowEvent e) {
    try {
      int orderStatus = qdsOrder.getStatus();
      int orderItemStatus = qdsOrderItem.getStatus();

      // determine if datasets are in edit or insert mode and
      // needs to be posted.
      boolean needsPosting = (qdsOrder.isEditing() ||
                              qdsOrder.isEditingNewRow() ||
                              qdsOrderItem.isEditing() ||
                              qdsOrderItem.isEditingNewRow());
      // determine if datasets have pending inserts or updates and
      // need to be resolved.
      boolean needsResolving = (((orderStatus & RowStatus.UPDATED) != 0) ||
                                ((orderStatus & RowStatus.INSERTED) != 0) ||
                                ((orderItemStatus & RowStatus.UPDATED) != 0) ||
                                ((orderItemStatus & RowStatus.INSERTED) != 0));

      if (needsPosting || needsResolving) {
        int answer = JOptionPane.showConfirmDialog(this,
                                                   res.getString("OEF_Save_pending_changes?"),
                                                   res.getString("OEF_Save_Pending_Changes"),
                                                   JOptionPane.YES_NO_CANCEL_OPTION,
                                                   JOptionPane.QUESTION_MESSAGE);
        // Post changes and resolve them back to DB
        if (answer == JOptionPane.YES_OPTION) {
          saveUpdates();
        }
        // If user chooses no, then cancel any inserts or edits
        // and refresh the dataset.
        else if (answer == JOptionPane.NO_OPTION) {
          cancelUpdates();
        }
        // If user cancels, just return
        else //if (answer == JOptionPane.CANCEL_OPTION)
          return;
      }

      setVisible(false);
      dispose();

    }
    catch (Exception ex) {
      ex.printStackTrace();
      new DBExceptionDialog(this, res.getString("OEF_Error"), ex, true).show();
    }
  }
  /**
   * Method to save the inserts or changes made to the order and order item
   * dataset.
   */
  private void saveUpdates() {
    try {
      if (qdsOrder.isEditing() || qdsOrder.isEditingNewRow()) {
        qdsOrder.post();
      }
      if (qdsOrderItem.isEditing() || qdsOrderItem.isEditingNewRow()) {
        qdsOrderItem.post();
      }
      qdsOrder.getDatabase().saveChanges(new DataSet[] {qdsOrder, qdsOrderItem, qdsProduct}, true);

      // Refresh the Product dataset to get the latest StockQty for products.
      qdsProduct.refresh();
    }
    catch (Exception ex) {
      ex.printStackTrace();
      new DBExceptionDialog(this, res.getString("OEF_Error"), ex, true).show();
    }
  }

  /**
   * Method to cancel the inserts or changes made to the order and order item
   * dataset.
   */
  private void cancelUpdates() {
    try {
      // Cancel any edits or inserts
      qdsOrderItem.cancel();
      qdsOrder.cancel();

      int orderStatus = qdsOrder.getStatus();

      if ((orderStatus & RowStatus.UPDATED) != 0) {
        // refetch this row if it was an update
        qdsOrder.refetchRow(qdsOrder);
      }
      else if ((orderStatus & RowStatus.INSERTED) != 0) {
        // refresh the whole dataset if it was an insert
        qdsOrder.refresh();
        qdsOrder.last();
      }

      int orderItemStatus = qdsOrderItem.getStatus();
      if (((orderItemStatus & RowStatus.UPDATED) != 0) ||
          ((orderItemStatus & RowStatus.INSERTED) != 0)) {
        // refetch the orderItem dataset if modified
        qdsOrderItem.refresh();
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  /**
   * When the Save button is clicked, save the changes in the master-detail
   * relationship between Orders and OrderItem datasets. Post edits before
   * calling resolving changes to the database.
   *
   * @param e ActionEvent
   *
   */
  void btnSave_actionPerformed(ActionEvent e) {
    saveUpdates();
  }

  /**
   * When the Cancel button is clicked, cancel any pending changes made to both
   * Orders and OrderItem datasets.
   *
   * @param e ActionEvent
   *
   */
  void btnCancel_actionPerformed(ActionEvent e) {
    cancelUpdates();
  }

  /**
   * When Close button is clicked, call this frame's windowClosing event handler
   * to properly handle all dataset pending updates.
   *
   * @param e ActionEvent
   *
   */
  void btnClose_actionPerformed(ActionEvent e) {
    // close this Window
    this.this_windowClosing(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
  }

  /**
   * When the Save Ship To button is clicked, save the Ship To information of
   * the current order to the current Customer record.
   *
   * @param e ActionEvent
   *
   */
  void btnSaveShipTo_actionPerformed(ActionEvent e) {
    saveShipToInfo();
  }

  /**
   * Save the Ship To information of the current order record to the
   * Customer record.
   * Note: This method also resolves the changes to the database.
   */
  void saveShipToInfo() {
    try {
      int customerID = qdsOrder.getInt("CUSTOMERID");
      DataRow locateRow = new DataRow(qdsCustomer, "ID");
      locateRow.setInt("ID", customerID);
      if (qdsCustomer.locate(locateRow, Locate.FIRST)) {
        qdsCustomer.editRow();
        qdsCustomer.setString("SHIPNAME",       qdsOrder.getString("SHIPNAME"));
        qdsCustomer.setString("SHIPADDR1",      qdsOrder.getString("SHIPADDR1"));
        qdsCustomer.setString("SHIPADDR2",      qdsOrder.getString("SHIPADDR2"));
        qdsCustomer.setString("SHIPCITY",       qdsOrder.getString("SHIPCITY"));
        qdsCustomer.setString("SHIPSTATE",      qdsOrder.getString("SHIPSTATE"));
        qdsCustomer.setString("SHIPPOSTALCODE", qdsOrder.getString("SHIPPOSTALCODE"));
        qdsCustomer.setString("SHIPCOUNTRY",    qdsOrder.getString("SHIPCOUNTRY"));
        qdsCustomer.post();
        //qdsCustomer.saveChanges(qdsCustomer);
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
      new DBExceptionDialog(this, res.getString("OEF_Error"), ex, true).show();
    }
  }

  /**
   * When the Find Customer button is clicked, Use the FindOrderCustomer dialog
   * to find a customer for this Order record.
   *
   * @param e ActionEvent
   *
   */
  void btnFindCustomer_actionPerformed(ActionEvent e) {
    FindOrderCustomer dialog = new FindOrderCustomer((Frame)this, res.getString("OEF_Find_Customer"), true);
    try {
      //Center the dialog
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension dialogSize = dialog.getSize();
      if (dialogSize.height > screenSize.height)
        dialogSize.height = screenSize.height;
      if (dialogSize.width > screenSize.width)
        dialogSize.width = screenSize.width;
      dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
      dialog.show();
      if (dialog.getResult() == FindOrderCustomer.OK) {
        // use the selected customer for the order
        qdsOrder.editRow();
        qdsOrder.setInt("CUSTOMERID", dialog.getCustomerID());
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    finally {
      dialog.dispose();
    }
  }

  /**
   * When the New Customer button is clicked, Use the AddCustomerDlg dialog to
   * create a new customer for this Order record.
   *
   * @param e ActionEvent
   *
   */
  void btnNewCustomer_actionPerformed(ActionEvent e) {
    AddCustomerDlg dialog = new AddCustomerDlg((Frame)this, res.getString("OEF_Add_Customer"), true);
    try {
      //Center the window
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension dialogSize = dialog.getSize();
      if (dialogSize.height > screenSize.height)
        dialogSize.height = screenSize.height;
      if (dialogSize.width > screenSize.width)
        dialogSize.width = screenSize.width;
      dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
      dialog.show();
      if (dialog.getResult() == AddCustomerDlg.OK) {
        // use the selected customer
        qdsOrder.editRow();
        qdsOrder.setInt("CUSTOMERID", dialog.getCustomerID());
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
    finally {
      dialog.dispose();
    }
  }

  /**
   * When the Add Item button is clicked, insert a new OrderItem record.
   *
   * @param e ActionEvent
   *
   */
  void btnAddOrderItem_actionPerformed(ActionEvent e) {
    try {
      qdsOrderItem.insertRow(false);
    }
    catch (DataSetException ex) {
      ex.printStackTrace();
    }
  }

  /**
   * When the Delete Item button is clicked, delete the current OrderItem record.
   *
   * @param e ActionEvent
   * return  void
   */
  void btnRemoveOrderItem_actionPerformed(ActionEvent e) {
    try {
      qdsOrderItem.deleteRow();
    }
    catch (DataSetException ex) {
      ex.printStackTrace();
    }
  }

  /**
   * If the payment method is COD, blank out the CC Num field
   *
   * @param e ItemEvent
   * return  void
   */
  void cboPayMethod_itemStateChanged(ItemEvent e) {
    if (cboPayMethod.getSelectedItem() != null &&
        cboPayMethod.getSelectedItem().toString().compareTo(res.getString("OEF_COD")) == 0) {
      txtCreditCardNum.setText("");
    }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -