コード例 #1
0
  /** Отображает данные о товаре по выбранному в списке идентификатору */
  protected void showProductData() {
    try {
      // забираем значение, выбранное в списке
      // идентификаторов товаров
      Integer productId = (Integer) comboId.getSelectedItem();
      if (productId != null) {
        // получаем товар по идентификатору
        Product product1 =
            new Product(
                productId,
                txtDescription.getText(),
                Float.parseFloat(txtRate.getText()),
                Integer.parseInt(txtQuantity.getText()),
                5);
        List<Product> product = (List<Product>) client.showProductData(product1);

        //	List<Product> product = productDAO.getProductById(productId);
        // заполняем текстовые поля значениями
        // параметров товара
        for (int i = 0; i < product.size(); i++) {
          txtId.setText(String.valueOf(product.get(i).getId()));
          txtDescription.setText(product.get(i).getDescription());
          txtRate.setText(String.valueOf(product.get(i).getRate()));
          txtQuantity.setText(String.valueOf(product.get(i).getQuantity()));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      //	JOptionPane.showMessageDialog(this, e.getMessage());
    }
  }
コード例 #2
0
  /** Добавляет новый товар на основе данных текстовых полей */
  protected void addProduct() {
    try {
      // создаем новый объект-товар
      // на основе данных диалога
      Product product =
          new Product(
              Integer.parseInt(txtId.getText()),
              txtDescription.getText(),
              Float.parseFloat(txtRate.getText()),
              Integer.parseInt(txtQuantity.getText()),
              1);
      // сохраняем товар в БД

      client.addProduct(product);

      //	productDAO.addProduct(product);
      // обновляем список идентификаторов
      refreshIdList();
      // устанавливаем текущим добавленный товар
      comboId.setSelectedItem(Integer.parseInt(txtId.getText()));
    } catch (Exception e) {
      e.printStackTrace();
      //	JOptionPane.showMessageDialog(this, e.getMessage());
    }
  }
コード例 #3
0
  private void refreshIdList() {
    try {
      // получаем список идентификаторов
      List<Integer> productIds = (List<Integer>) client.refreshIdList();

      // List<Integer> productIds = productDAO.getProductIds();
      // очищаем список
      comboId.removeAllItems();
      // заполняем список полученными данными
      for (Integer productId : productIds) {
        comboId.addItem(productId);
      }
    } catch (Exception e) {
      e.printStackTrace();
      //		JOptionPane.showMessageDialog(this, e.getMessage());
    }
  }
コード例 #4
0
  /** Обновляет информацию о товаре на основе данных текстовых полей */
  protected void updateProduct() {
    try {
      // формируем объект-товар
      // на основе данных диалога
      Product product =
          new Product(
              Integer.parseInt(txtId.getText()),
              txtDescription.getText(),
              Float.parseFloat(txtRate.getText()),
              Integer.parseInt(txtQuantity.getText()),
              2);
      // обновляем данные о товаре в БД

      client.updateProduct(product);

      //	productDAO.setProduct(product);
    } catch (Exception e) {
      e.printStackTrace();
      //	JOptionPane.showMessageDialog(this, e.getMessage());
    }
  }
コード例 #5
0
  /** Удаляет выбранный товар */
  protected void removeProduct() {
    try {
      // удаляем товар из БД
      Product product =
          new Product(
              Integer.parseInt(txtId.getText()),
              txtDescription.getText(),
              Float.parseFloat(txtRate.getText()),
              Integer.parseInt(txtQuantity.getText()),
              3);

      client.removeProduct(product);

      //	productDAO.removeProduct(
      //	Integer.parseInt(txtId.getText()));
      // обновляем список идентификаторов товаров
      refreshIdList();
      // отображаем данные по первому товару в списке
      showProductData();
    } catch (Exception e) {
      e.printStackTrace();
      //	JOptionPane.showMessageDialog(this, e.getMessage());
    }
  }