public void populateBillCategoryValues() {
    try {

      Connection con = Main.dbConnection;
      if (!con.isValid(0)) {
        con = Main.reconnect();
      }
      billCategoryValues = FXCollections.observableArrayList();
      PreparedStatement stmt =
          con.prepareStatement(
              "select distinct bill_category from point_name order by bill_category");
      ResultSet rs = stmt.executeQuery();
      while (rs.next()) {
        if (billCategoryValues != null && !billCategoryValues.contains(rs.getString(1)))
          billCategoryValues.add(rs.getString(1).toLowerCase());
      }
      billCategoryTF.setItems(billCategoryValues);
      new AutoCompleteComboBoxListener<>(billCategoryTF);
    } catch (SQLException e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    } catch (Exception e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    }
  }
  private boolean productExistsInCategory(String name, String category) {
    try {

      Connection con = Main.dbConnection;
      if (!con.isValid(0)) {
        con = Main.reconnect();
      }
      String query =
          "select count(*) from products where lower(name)=? and lower(bill_category)=? and product_id<>?";
      PreparedStatement stmt = con.prepareStatement(query);
      stmt.setString(1, name.toLowerCase());
      stmt.setString(2, category.toLowerCase());
      stmt.setLong(3, productRow.getProductId());
      ResultSet rs = stmt.executeQuery();
      if (rs.next()) {
        if (rs.getInt(1) > 0) return true;
      }
    } catch (SQLException e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    } catch (Exception e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    }
    return false;
  }
  public void populateProdTypeValues() {
    try {

      Connection con = Main.dbConnection;
      if (!con.isValid(0)) {
        con = Main.reconnect();
      }
      productTypeValues.clear();
      PreparedStatement stmt =
          con.prepareStatement(
              "select value, code, seq, lov_lookup_id from lov_lookup where code='PRODUCT_TYPE' order by seq");
      ResultSet rs = stmt.executeQuery();
      while (rs.next()) {
        productTypeValues.add(rs.getString(1));
      }
      typeTF.getItems().addAll(productTypeValues);
    } catch (SQLException e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    } catch (Exception e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    }
  }
  @FXML
  void updateAdminDetails(ActionEvent event) {
    try {
      TextField mobileNum = new TextField();
      TextField agencyName = new TextField();
      TextField addr = new TextField();

      Connection con = Main.dbConnection;
      if (!con.isValid(0)) {
        con = Main.reconnect();
      }
      String query =
          "select company_name,company_mobile,company_addr from admin_login where username ='******' ";
      PreparedStatement stmt = con.prepareStatement(query);
      //			stmt.setString(1, HawkerLoginController.loggedInHawker.getPointName());
      ResultSet rs = stmt.executeQuery();
      if (rs.next()) {
        agencyName.setText(rs.getString(1));
        mobileNum.setText(rs.getString(2));
        addr.setText(rs.getString(3));
      }
      rs.close();
      stmt.close();

      Dialog<ButtonType> deleteWarning = new Dialog<ButtonType>();
      deleteWarning.setTitle("Update Admin Details");
      deleteWarning.setHeaderText("Update admin details below.");
      ButtonType saveButtonType = new ButtonType("Save", ButtonData.OK_DONE);
      deleteWarning.getDialogPane().getButtonTypes().addAll(saveButtonType, ButtonType.CANCEL);

      GridPane grid = new GridPane();
      grid.setHgap(10);
      grid.setVgap(10);
      grid.setPadding(new Insets(20, 150, 10, 10));

      grid.add(new Label("Agency Name"), 0, 0);
      grid.add(new Label("Mobile"), 0, 1);
      grid.add(new Label("Address"), 0, 2);
      grid.add(agencyName, 1, 1);
      grid.add(mobileNum, 1, 0);
      grid.add(addr, 1, 2);
      deleteWarning.getDialogPane().setContent(grid);
      Optional<ButtonType> result = deleteWarning.showAndWait();
      if (result.isPresent() && result.get() == saveButtonType) {
        PreparedStatement updateStmt =
            con.prepareStatement(
                "update admin_login set company_name=?, company_mobile=?, company_addr=?");
        updateStmt.setString(1, agencyName.getText());
        updateStmt.setString(2, mobileNum.getText());
        updateStmt.setString(3, addr.getText());
        updateStmt.executeUpdate();
      }
    } catch (SQLException e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    } catch (Exception e) {

      Main._logger.debug("Error :", e);
      e.printStackTrace();
    }
  }
  @FXML
  private void changePasswordClicked(ActionEvent evt) {
    TextInputDialog changePwdDialog = new TextInputDialog();
    changePwdDialog.setTitle("Change password");
    changePwdDialog.setHeaderText(
        "Please enter the new password. \nPassword must be atleast 5 characters long.");
    // changePwdDialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK,
    // ButtonType.CANCEL);
    final Button btOk = (Button) changePwdDialog.getDialogPane().lookupButton(ButtonType.OK);
    btOk.addEventFilter(
        ActionEvent.ACTION,
        event -> {
          if (changePwdDialog.getEditor().getText().isEmpty()
              || changePwdDialog.getEditor().getText().length() < 5) {
            Notifications.create()
                .title("Empty password")
                .text(
                    "Password cannot be left empty and must be more than 5 characters. Try again.")
                .hideAfter(Duration.seconds(5))
                .showError();
            event.consume();
          }
        });
    Optional<String> result = changePwdDialog.showAndWait();
    if (result.isPresent()) {
      try {

        Connection con = Main.dbConnection;
        if (!con.isValid(0)) {
          con = Main.reconnect();
        }
        String deleteString = "update admin_login set password =? where username='******'";
        PreparedStatement deleteStmt = con.prepareStatement(deleteString);
        deleteStmt.setString(1, changePwdDialog.getEditor().getText());

        deleteStmt.executeUpdate();
        con.commit();

        Notifications.create()
            .title("Password updated")
            .text("Password was successfully updated. Please login again!")
            .hideAfter(Duration.seconds(5))
            .showInformation();
        logoutClicked(new ActionEvent());
      } catch (SQLException e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
        Notifications.create()
            .hideAfter(Duration.seconds(5))
            .title("Delete failed")
            .text("Delete request of hawker bill has failed")
            .showError();
      } catch (IOException e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      } catch (Exception e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      }
    }
  }