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

📄 customerframe.java

📁 java在线商店的源代码。编写十分规范的哦
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    pnlCustomerInfo.add(txtPhone, new GridBagConstraints(6, 7, 2, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 0, 0), 106, 0));
    pnlCustomerInfo.add(txtFax, new GridBagConstraints(10, 7, 2, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 0, 0, 4), 65, 0));
    pnlCustomerInfo.add(txtEmail, new GridBagConstraints(6, 9, 6, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 6, 10, 4), 223, 0));
    pnlCustomerInfo.add(jLabel1, new GridBagConstraints(0, 1, 6, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 27, 0));
    pnlCustomerInfo.add(jLabel2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel3, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel4, new GridBagConstraints(0, 7, 3, 2, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel5, new GridBagConstraints(0, 9, 2, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(10, 6, 10, 0), 0, 0));
    pnlCustomerInfo.add(jLabel6, new GridBagConstraints(8, 7, 1, 1, 0.0, 0.0
            ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 0, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel7, new GridBagConstraints(0, 3, 5, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel8, new GridBagConstraints(0, 6, 4, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel9, new GridBagConstraints(6, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 12, 0, 0), 9, 0));
    pnlCustomerInfo.add(jLabel10, new GridBagConstraints(8, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel11, new GridBagConstraints(10, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 9, 0, 0), 0, 0));
    pnlCustomerInfo.add(lblCustomerID, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
    pnlCustomerInfo.add(jLabel12, new GridBagConstraints(0, 5, 4, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0));
    pnlMain.add(pnlOrders, new GridBagConstraints(0, 1, 1, 1, 100.0, 100.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    jScrollPane1.getViewport().add(jdbTable1);
    pnlOrders.add(jScrollPane1, BorderLayout.CENTER);
    pnlOrders.add(lblOrders, BorderLayout.NORTH);
    pnlOrders.add(pnlOrderButtons, BorderLayout.SOUTH);
    pnlOrderButtons.add(jPanel1, null);
    jPanel1.add(btnViewOrder, null);
    jPanel1.add(btnNewOrder, null);
    jPanel2.setLayout(borderLayout3);
    jPanel2.add(imageLabel1, BorderLayout.CENTER);
    jPanel2.add(pnlToolBar, BorderLayout.SOUTH);
    pnlToolBar.add(jdbNavToolBar1, new GridBagConstraints(0, 0, 4, 1, 1.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    pnlToolBar.add(btnClose, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
  }

  /**
   * We created this method to separate code to initialize database and
   * data-aware controls, which otherwise would go in the jbInit() method.
   * Note that by doing so, the properties set here are not visible to the
   * property inspector. And setting any properties via the inspector will
   * add code to jbInit() instead of here.
   * @throws Exception exception
   */
  private void initData() throws Exception {
    qdsCustomer = dm.getCustomerDataSet();
    qdsCustomer.open();
    qdsCustOrder = dm.getCustOrderDataSet();
  }


  /**
   * Class method to access the singleton instance of the class.
   * @return CustomerFrame
   */
  public static CustomerFrame getCustomerFrame() {
    if (myCustomerFrame == null)
      myCustomerFrame = new CustomerFrame();

    return myCustomerFrame;
  }

  /**
   * Method to insert a new customer record.
   * Useful for inserting records from other forms in the application.
   */
  public void newCustomer() {
    try {
      // Open the dataset if not already opened.
      qdsCustomer.open();
      // Insert a new Customer record at the end of the
      // dataset
      qdsCustomer.insertRow(false);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   *
   */

  /**
   * 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 status = qdsCustomer.getStatus();
      if ( (qdsCustomer.isEditing() || qdsCustomer.isEditingNewRow()) ||
           ((status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0)
         ) {
        int answer = JOptionPane.showConfirmDialog(this,
                                                   res.getString("CF_Save_pending_changes?"),
                                                   res.getString("CF_Save_Pending_Changes"),
                                                   JOptionPane.YES_NO_CANCEL_OPTION,
                                                   JOptionPane.QUESTION_MESSAGE);

        // Post changes and resolve them back to DB
        if (answer == JOptionPane.YES_OPTION) {
          qdsCustomer.post();

          // if there are pending changes to be resolved,
          // save the changes via the Database.saveChanges()
          // method. Then refresh the dataset.
          status = qdsCustomer.getStatus();
          if ( (status & (RowStatus.UPDATED|RowStatus.INSERTED|RowStatus.DELETED)) != 0) {
            qdsCustomer.getDatabase().saveChanges(new DataSet[] {qdsCustomer}, true);
          }
        }
        // If user chooses no, then cancel any inserts or edits
        // and refresh the dataset.
        else if (answer == JOptionPane.NO_OPTION) {
          qdsCustomer.cancel();
        }
        // If user cancels, just return
        else //if (answer == JOptionPane.CANCEL_OPTION)
          return;
      }

      // Refresh the dataset to ensure that we have updated data
      qdsCustomer.refresh();
      setVisible(false);
      dispose();

    }
    catch (Exception ex) {
      ex.printStackTrace();
      new DBExceptionDialog(this, res.getString("CF_Error"), ex, true).show();
    }
  }

  /**
   * When View Order button is clicked, show the Order Entry form
   * with the selected order as the current record.
   * @param e ActionEvent
   */
  void btnViewOrder_actionPerformed(ActionEvent e) {
    try {
      // make sure it is a valid order
      int orderID = qdsCustOrder.getInt("ID");
      if (orderID <= 0) {
        JOptionPane.showMessageDialog(this,
                                      res.getString("CF_No_order_selected"),
                                      CliffhangerApplication.MESSAGE_TITLE,
                                      JOptionPane.ERROR_MESSAGE);
        return;
      }

      // Get the OrderEntryFrame, and locate the selected order
      OrderEntryFrame frame = OrderEntryFrame.getOrderEntryFrame();
      if (frame.locateOrder(orderID)) {
        // Show the frame centered in the screen
        CliffhangerApplication.showCenteredWindow(frame, false);
      }
      else {
        JOptionPane.showMessageDialog(this,
                                      res.getString("CF_Order_not_found"),
                                      res.getString("CF_Error"),
                                      JOptionPane.ERROR_MESSAGE);
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }


  /**
   * When New Order button is clicked, show the Order Entry form
   * with a new order inserted, default the customer for the order
   * to the current customer record.
   * @param e ActionEvent
   *
   */
  void btnNewOrder_actionPerformed(ActionEvent e) {
    try {
      // post any changes first
      if (qdsCustomer.isEditing() || qdsCustomer.isEditingNewRow()) {
        qdsCustomer.post();
      }

      // make sure it is a valid order
      int customerID = qdsCustomer.getInt("ID");
      if (customerID <= 0) {
        JOptionPane.showMessageDialog(this,
                                      res.getString("CF_No_customer_selected"),
                                      CliffhangerApplication.MESSAGE_TITLE,
                                      JOptionPane.ERROR_MESSAGE);
        return;
      }

      // Get the OrderEntryFrame and show the frame centered in the screen
      OrderEntryFrame frame = OrderEntryFrame.getOrderEntryFrame();
      CliffhangerApplication.showCenteredWindow(frame, false);

      // create a new order, passing the customer ID
      // to default the customer of the new order
      // to this current customer.
      frame.newOrder(customerID);
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  /**
   * 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));
  }

}

⌨️ 快捷键说明

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