private void MoveSellerActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_MoveSellerActionPerformed
    JButton button = (JButton) evt.getSource();

    if (button.getName().equals("toRight")) {
      sellerdb.moveSellerItem(AvSel, LsSel);
    } else if (button.getName().equals("toLeft")) {
      sellerdb.moveSellerItem(LsSel, AvSel);
    }
  } // GEN-LAST:event_MoveSellerActionPerformed
  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
  /** Creates new form AddSellerDialog */
  public EditItemDialog(java.awt.Frame parent, boolean modal, JTable table, Connection conn) {
    super(parent, modal);
    this.conn = conn;
    initComponents();

    GuiHelper.setOnCenter((Window) this);

    this.table = table;

    row = table.getSelectedRow();

    item_code = (String) table.getModel().getValueAt(row, 0);

    // set data on dialog text field
    itemCodeTF.setText(item_code);
    nameTF.setText((String) table.getModel().getValueAt(row, 2));
    categoryTF.setText((String) table.getModel().getValueAt(row, 1));

    // just use plain number instead the currency format
    NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("id", "id"));
    try {
      buyingPriceTF.setText((nf.parse((String) table.getModel().getValueAt(row, 3))).toString());
      salePriceTF.setText((nf.parse((String) table.getModel().getValueAt(row, 4))).toString());
    } catch (java.text.ParseException pe) {
      pe.printStackTrace();
    }

    commentTA.setText((String) table.getModel().getValueAt(row, 6));

    // if length field is null, then deselect the detail size of checkbox
    if (((Integer) table.getModel().getValueAt(row, 8)).intValue() == 0) {
      DetailSizeCheckBoxActionPerformed(null);
      VolumeTF.setText(((Integer) table.getModel().getValueAt(row, 11)).toString());
    }
    // if length, width, height field are not null, then deselect the volume checkbox
    else {
      VolumeCheckBoxActionPerformed(null);
      LengthTF.setText(((Integer) table.getModel().getValueAt(row, 8)).toString());
      WidthTF.setText(((Integer) table.getModel().getValueAt(row, 9)).toString());
      HeightTF.setText(((Integer) table.getModel().getValueAt(row, 10)).toString());
      VolumeTF.setText(((Integer) table.getModel().getValueAt(row, 11)).toString());
    }

    PrimaryTF.setText((String) table.getModel().getValueAt(row, 12));
    MeasurementTF.setText(((Integer) table.getModel().getValueAt(row, 13)).toString());
    SecondaryTF.setText((String) table.getModel().getValueAt(row, 14));
    SecondaryThirdMeasurementTF.setText(
        ((Integer) table.getModel().getValueAt(row, 17)).toString());
    ThirdTF.setText((String) table.getModel().getValueAt(row, 18));

    producerdb = new ProducerDB(conn);
    producerdb.initializeComboBoxProducer(ProducerCoB);
    ProducerCoB.setSelectedItem((String) table.getModel().getValueAt(row, 15));

    sellerdb = new SellerDB(conn);
    sellerdb.initializeSellerItem(listModel);
    sellerdb.initializeSuplierForItem(
        itemsellerModel, (String) table.getModel().getValueAt(row, 2));
    sellerdb.harmonizeSellerItem(listModel, itemsellerModel);

    st = new InventoryDB(conn);

    st.initializeComboBox(WarehouseCB, "warehouse");

    getRootPane().setDefaultButton(OK);

    itemindex = st.getItemIndex(item_code);

    // select warehousecombo box programmatically so quantity and expired date is set up
    WarehouseCB.setSelectedIndex(0);

    QuantityTB.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  }