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

📄 datamodule1.java

📁 java在线商店的源代码。编写十分规范的哦
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
   * @param readWriteRow ReadWriteRow
   * @param dataSetException DataSetException
   * @param errorResponse ErrorResponse
   * @throws DataSetException datasetexception
   *
   */
  void orderDataSet_updateError(DataSet dataSet, ReadWriteRow readWriteRow, DataSetException dataSetException, ErrorResponse errorResponse) throws DataSetException{
    showErrorMsg(dataSetException.getMessage());
  }




  // OrderItem DataSet EditEvents


  /**
   * Before inserting a new OrderItem record, post the Order dataset
   * if a new record is being inserted.
   * @param dataSet DataSet
   * @throws Exception exception
   *
   */
  void orderItemDataSet_inserting(DataSet dataSet) throws Exception{
    // Do not allow inserts if the corresponding Order record
    // STATUS value is Fullfilled.
    String status = orderDataSet.getString("STATUS");
    if (status.compareTo(res.getString("DM_Fulfilled")) == 0) {
      // Show the message dialog here because there is
      // no error event handler for inserting event errors.
      JOptionPane.showMessageDialog(CliffhangerApplication.getMostRecentFrame(),
                                    res.getString("DM_Cannot_modify_order"),
                                    res.getString("DM_Error"),
                                    JOptionPane.ERROR_MESSAGE);
      throw new VetoException(res.getString("DM_Cannot_modify_order"));
    }

    // Post order dataset first
    if (orderDataSet.isEditingNewRow()) {
      orderDataSet.post();
    }
  }


  /**
   * The adding event occurs after the inserted record is posted.
   * Before an orderItem is added, check the quantity on hand in the
   * Product dataset and subtract the quantity for this order item.
   * @param dataSet DataSet
   * @param readWriteRow ReadWriteRow
   * @throws Exception exception
   *
   */
  void orderItemDataSet_adding(DataSet dataSet, ReadWriteRow readWriteRow) throws Exception{
    validateOrderItemRow();

    int productID  = readWriteRow.getInt("PRODUCTID");
    int orderedQty = readWriteRow.getInt("QTY");

    // Update the product StockQty by the amount ordered
    subtractProductStockQty(productID, orderedQty);
  }

  /**
   * The updating event occurs after the modified record is posted.
   * When an orderItem is being updated, do the following:
   * <UL>
   * <LI>1. Determine if the productID has changed
   *    <P>
   *    - subtract qty from new product
   *    <P>
   *    - replace qty of old product
   * <LI>2. Determine if the quantity has changed
   *    <P>
   *    - replace or subtract from product
   * </UL>
   * @param dataSet DataSet
   * @param readWriteRow ReadWriteRow
   * @param readRow ReadRow
   * @throws Exception exception
   *
   */

  void orderItemDataSet_updating(DataSet dataSet, ReadWriteRow readWriteRow, ReadRow readRow) throws Exception{
    validateOrderItemRow();

    int oldProductID  = readRow.getInt("PRODUCTID");
    int oldOrderedQty = readRow.getInt("QTY");
    int newProductID  = readWriteRow.getInt("PRODUCTID");
    int newOrderedQty = readWriteRow.getInt("QTY");

    if (oldProductID != newProductID) {
      subtractProductStockQty(newProductID, newOrderedQty);
      subtractProductStockQty(oldProductID, -oldOrderedQty);
    }
    else {
      if (newOrderedQty != oldOrderedQty)
        subtractProductStockQty(newProductID, newOrderedQty - oldOrderedQty);
    }
  }


  /**
   * The deleting event occurs before a record is deleted.
   * Confirm delete with the user, and update stock quantity.
   * @param dataSet DataSet
   * @throws Exception exception
   *
   */
  void orderItemDataSet_deleting(DataSet dataSet) throws Exception{
    // Prompt the user to confirm delete.
    confirmDelete(res.getString("DM_Delete_this_order"));

    // Do not allow edits if the corresponding Order record
    // STATUS value is Fulfilled.
    String status = orderDataSet.getString("STATUS");
    if (status.compareTo(res.getString("DM_Fulfilled")) == 0) {
      // Show the message dialog here because there is
      // no error event handler for modifying event errors.
      JOptionPane.showMessageDialog(CliffhangerApplication.getMostRecentFrame(),
                                    res.getString("DM_Cannot_modify_order"),
                                    res.getString("DM_Error"),
                                    JOptionPane.ERROR_MESSAGE);
      throw new VetoException(res.getString("DM_Cannot_modify_order"));
    } else {
      // When an orderItem is being deleted, replace the qty of the product.
      int productID  = dataSet.getInt("PRODUCTID");
      int orderedQty = dataSet.getInt("QTY");
      subtractProductStockQty(productID, -orderedQty);
    }
  }


  /**
   * Method to prompt the user to confirm before deleting a record.
   * This raises an exception if the user cancels.
   * Call this method from the deleting event handler.
   * @param message String
   * @throws Exception exception
   *
   */
  private void confirmDelete(String message) throws Exception {
    // Prompt the user to confirm delete.
    int answer = JOptionPane.showConfirmDialog(CliffhangerApplication.getMostRecentFrame(),
                                               message,
                                               res.getString("DM_Confirm"),
                                               JOptionPane.YES_NO_OPTION,
                                               JOptionPane.QUESTION_MESSAGE);

    if (answer == JOptionPane.NO_OPTION) {
      throw new VetoException(res.getString("DM_Delete_canceled"));
    }
  }


  /**
   * Event handler for modifying event. Make sure that the orderDataSet's
   * Stutus column is not "Fulfilled" before allowing the orderItemDataSet
   * to be modified.
   * @param dataSet DataSet
   * @throws Exception exception
*
   */
  void orderItemDataSet_modifying(DataSet dataSet) throws Exception{
    // Do not allow edits if the corresponding Order record
    // STATUS value is Fulfilled.
    String status = orderDataSet.getString("STATUS");
    if (status.compareTo(res.getString("DM_Fulfilled")) == 0) {
      // Show the message dialog here because there is
      // no error event handler for modifying event errors.
      JOptionPane.showMessageDialog(CliffhangerApplication.getMostRecentFrame(),
                                    res.getString("DM_Cannot_modify_order"),
                                    res.getString("DM_Error"),
                                    JOptionPane.ERROR_MESSAGE);
      throw new VetoException(res.getString("DM_Cannot_modify_order"));
    }
  }


  /**
   * When canceling an edit or insert, clear the messages from
   * all status bar controls
   * @param dataSet DataSet
   * @throws Exception exception
   *
   */
  void orderItemDataSet_canceling(DataSet dataSet) throws Exception{
    dataSet.clearStatus();
  }


  /**
   * Event handler to calculate the values for all the calculated columns
   * for the OrderItem dataset.
   * @param readRow ReadRow
   * @param dataRow DataRow
   * @param boolean1 boolean
   * @throws DataSetException datasetexception
   *
   */
  void orderItemDataSet_calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) throws DataSetException{
    // Calculate the Extended Qty for OrderItems
    double extPrice = readRow.getInt("QTY") * readRow.getDouble("SALEPRICE");
    dataRow.setDouble("EXTENDEDPRICE", extPrice);

    // Lookup the product Name for the OrderItem
    String productName = lookupProductName(readRow.getInt("PRODUCTID"));
    dataRow.setString("PRODUCTNAME", productName);
  }

  /**
   * Method to lookup the Product Name given the ProductID.
   * @param productID int
   * @return String
   */
  private String lookupProductName(int productID) {
    String productName = new String("");
    try {
      // Define a DataRow to hold the productID to look for
      // the Product Dataset, and another to hold the row
      // of product data that we find.
      productDataSet.open();
      DataRow lookupRow = new DataRow(productDataSet, "ID");
      DataRow productRow = new DataRow(productDataSet, new String[] {"NAME"} );

      lookupRow.setInt("ID", productID);

      if (productDataSet.lookup(lookupRow, productRow, Locate.FIRST)) {
        productName = productRow.getString("NAME");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    };
    return productName;
  }


  /**
   * Event handler to calculate the aggregate columns for the
   * orderItem DataSet when an row is added.
   * @param readRow ReadRow
   * @param readWriteRow ReadWriteRow
   * @throws DataSetException datasetexception
   *
   */
  void orderItemDataSet_calcAggAdd(ReadRow readRow, ReadWriteRow readWriteRow) throws DataSetException{
    calcAggregate(readRow, readWriteRow);
  }


  /**
   * Event handler to calculate the aggregate columns for the
   * orderItem DataSet when an row is deleted.
   * @param readRow ReadRow
   * @param readWriteRow ReadWriteRow
   * @throws DataSetException datasetexception
   *
   */
  void orderItemDataSet_calcAggDelete(ReadRow readRow, ReadWriteRow readWriteRow) throws DataSetException{
    calcAggregate(readRow, readWriteRow);
  }



  /**
   * Method to calculate the aggregate columns
   * called by calcAggAdd and calcAggDelete.
   * @param readRow ReadRow
   * @param readWriteRow ReadWriteRow
   * @throws DataSetException datasetexception
*
   */
  void calcAggregate(ReadRow readRow, ReadWriteRow readWriteRow) throws DataSetException {
    double subTotal = readRow.getDouble("SUBTOTAL");
    // Calculate the Tax on the SubTotal
    double tax = subTotal * TAXPERCENT;
    readWriteRow.setDouble("TAX", tax);
    // Calculate the Shipping on the SubTotal
    double shipping = subTotal * SHIPPERCENT;
    readWriteRow.setDouble("SHIPPING", shipping);
    // Calculate the AmtDue
    double amtPaid = orderDataSet.getDouble("AMTPAID");
    readWriteRow.setDouble("AMTDUE", ((subTotal + tax + shipping) - amtPaid));
  }


  /**
   * Event handler to calculate the values for all the calculated columns
   * for the Orders dataset.
   * @param readRow ReadRow
   * @param dataRow DataRow
   * @param boolean1 boolean
   * @throws DataSetException datasetexception
   *
   */
  void orderDataSet_calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) throws DataSetException{
    // Lookup the CustomerName for the current Order
    String custName = lookupCustomerName(readRow.getInt("CUSTOMERID"));
    dataRow.setString("CUSTOMERNAME", custName);
  }


  /**
   * Method to lookup the CustomerName given the customerID
   * This method also formats the name, taking care of the
   * middle initial.
   * @param customerID int
   * @return String
   */
  private String lookupCustomerName(int customerID) {
    String customerName = new String("");
    try {

⌨️ 快捷键说明

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