private void OKActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_OKActionPerformed
    // the tabbed pane
    final int item = 0;
    final int additional = 1;
    final int prodandsel = 2;

    // get data from dialog text field
    String name = nameTF.getText().trim();
    String itemcode = itemCodeTF.getText().trim();
    String buyingprice = buyingPriceTF.getText().trim();
    String saleprice = salePriceTF.getText().trim();
    String comment = commentTA.getText();
    String primary = PrimaryTF.getText().trim();
    String secondary = SecondaryTF.getText().trim();
    String category = categoryTF.getText().trim();
    String length, width, height, volume;
    Integer intvolume, intlength, intwidth, intheight;
    String measurement = MeasurementTF.getText().trim();
    String producer = (String) ProducerCoB.getSelectedItem();
    String secondarythirdmeasurement = SecondaryThirdMeasurementTF.getText().trim();
    String third = ThirdTF.getText().trim();

    // make sure the required fields are not null
    if (itemcode.equals("")) {
      JOptionPane.showMessageDialog(
          null, "Please insert the Item Code Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(item);
      itemCodeTF.requestFocusInWindow();
      return;
    }

    if (category.equals("")) {
      JOptionPane.showMessageDialog(
          null, "Please insert the Category Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(item);
      categoryTF.requestFocusInWindow();
      return;
    }

    if (name.equals("")) {
      JOptionPane.showMessageDialog(
          null, "Please insert the Name Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(item);
      nameTF.requestFocusInWindow();
      return;
    }

    if (buyingprice.equals("")) {
      JOptionPane.showMessageDialog(
          null,
          "Please insert the Buying Price Text " + "Field!",
          "Warning",
          JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(item);
      buyingPriceTF.requestFocusInWindow();
      return;
    }
    int intbuyingprice = Integer.parseInt(buyingprice);

    if (saleprice.equals("")) {
      JOptionPane.showMessageDialog(
          null, "Please insert the Sale Price Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(item);
      salePriceTF.requestFocusInWindow();
      return;
    }
    int intsaleprice = Integer.parseInt(saleprice);

    // if user fill the volume
    if (VolumeCheckBox.isSelected()) {
      volume = VolumeTF.getText().trim();
      if (volume.equals("")) {
        JOptionPane.showMessageDialog(
            null, "Please insert the Volume Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
        ItemTabbedPane.setSelectedIndex(additional);
        VolumeTF.requestFocusInWindow();
        return;
      }
      intvolume = Integer.parseInt(volume);
      intlength = null;
      intwidth = null;
      intheight = null;
    } else {
      length = LengthTF.getText().trim();
      if (length.equals("")) {
        JOptionPane.showMessageDialog(
            null, "Please insert the Length Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
        ItemTabbedPane.setSelectedIndex(additional);
        LengthTF.requestFocusInWindow();
        return;
      }
      width = WidthTF.getText().trim();
      if (width.equals("")) {
        JOptionPane.showMessageDialog(
            null, "Please insert the Width Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
        ItemTabbedPane.setSelectedIndex(additional);
        WidthTF.requestFocusInWindow();
        return;
      }
      height = HeightTF.getText().trim();
      if (height.equals("")) {
        JOptionPane.showMessageDialog(
            null, "Please insert the Height Text Field!", "Warning", JOptionPane.WARNING_MESSAGE);
        ItemTabbedPane.setSelectedIndex(additional);
        HeightTF.requestFocusInWindow();
        return;
      }
      intlength = Integer.parseInt(length);
      intwidth = Integer.parseInt(width);
      intheight = Integer.parseInt(height);
      intvolume = intlength * intwidth * intheight;
    }

    if (primary.equals("")) {
      JOptionPane.showMessageDialog(
          null,
          "Please insert the Primary Measurement " + "Text Field!",
          "Warning",
          JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(additional);
      PrimaryTF.requestFocusInWindow();
      return;
    }

    if (secondary.equals("")) {
      JOptionPane.showMessageDialog(
          null,
          "Please insert the Secondary Measurement " + "Text Field!",
          "Warning",
          JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(additional);
      SecondaryTF.requestFocusInWindow();
      return;
    }

    if (measurement.equals("")) {
      JOptionPane.showMessageDialog(
          null,
          "Please insert the Measurement " + "Text Field!",
          "Warning",
          JOptionPane.WARNING_MESSAGE);
      ItemTabbedPane.setSelectedIndex(additional);
      MeasurementTF.requestFocusInWindow();
      return;
    }

    // check if it is the valid name
    String oldname = (String) table.getModel().getValueAt(row, 2);
    if (!st.UpdateValidName(oldname, name)) {
      JOptionPane.showMessageDialog(
          null, "The name is already used by other item! ", "Warning", JOptionPane.WARNING_MESSAGE);
      return;
    }

    boolean result =
        st.updateItem(
            itemindex,
            category,
            name,
            itemcode,
            comment,
            intbuyingprice,
            intsaleprice,
            intlength,
            intwidth,
            intheight,
            intvolume,
            primary,
            secondary,
            measurement,
            producer,
            third,
            secondarythirdmeasurement,
            null);

    // error editing item data
    if (!result) {
      JOptionPane.showMessageDialog(
          null,
          "Error editing item data! See log file " + "for detail!",
          "Warning",
          JOptionPane.WARNING_MESSAGE);
    } else {
      // update the seller item
      result = sellerdb.insertItemSeller((DefaultListModel) LsSel.getModel(), name);

      // error editing item data
      if (!result) {
        JOptionPane.showMessageDialog(
            null,
            "Error inserting item suplier data! See log file " + "for detail!",
            "Warning",
            JOptionPane.WARNING_MESSAGE);
      }
    }

    // release the resources
    dispose();
  } // GEN-LAST:event_OKActionPerformed