private PreparedStatement buildSQLr()
{
PreparedStatement result;
JDBQuery2 q2 = new JDBQuery2(Common.selectedHostID,Common.sessionID);
q2.applyWhat("*");
q2.applyFrom("{schema}VIEW_PALLET_EXPIRY");
if (jCheckBoxConfirmed.isSelected())
{
q2.applyWhere("confirmed=", 'Y');
} else
{
q2.applyWhere("confirmed=", 'N');
}
if (jTextFieldSSCC.getText().equals("") == false)
{
q2.applyWhere("sscc = ", jTextFieldSSCC.getText());
}
if (textFieldMHN.getText().equals("") == false)
{
q2.applyWhere("mhn_number = ", textFieldMHN.getText());
}
if (jTextFieldMaterial.getText().equals("") == false)
{
q2.applyWhere("material = ", jTextFieldMaterial.getText());
}
if (jTextFieldCustomer.getText().equals("") == false)
{
q2.applyWhere("customer_id=", jTextFieldCustomer.getText());
}
if (jTextFieldBatch.getText().equals("") == false)
{
q2.applyWhere("batch_number like ", jTextFieldBatch.getText());
}
if (jTextFieldProcessOrder.getText().equals("") == false)
{
q2.applyWhere("process_order = ", jTextFieldProcessOrder.getText());
}
if (jTextFieldLocation.getText().equals("") == false)
{
q2.applyWhere("location_id = ", jTextFieldLocation.getText());
}
if (jTextFieldEAN.getText().equals("") == false)
{
q2.applyWhere("EAN = ", jTextFieldEAN.getText());
}
if (jTextFieldDespatch_No.getText().equals("") == false)
{
q2.applyWhere("DESPATCH_NO = ", jTextFieldDespatch_No.getText());
}
if (jTextFieldVariant.getText().equals("") == false)
{
q2.applyWhere("variant = ", jTextFieldVariant.getText());
}
if (((JDBMHNDecisions) comboBoxDecisions.getSelectedItem()).getDecision().equals("") == false)
{
q2.applyWhere("decision = ", ((JDBMHNDecisions) comboBoxDecisions.getSelectedItem()).getDecision());
}
q2.applyWhere("uom=", ((JDBUom) jComboBoxUOM.getSelectedItem()).getInternalUom());
q2.applyWhere("status=", ((String) jComboBoxPalletStatus.getSelectedItem()).toString());
if (jCheckBoxQuantity.isSelected())
{
if (jFormattedTextFieldQuantity.getText().equals("") == false)
{
q2.applyWhere("quantity=", JUtility.stringToBigDecimal(jFormattedTextFieldQuantity.getText().toString()));
}
}
if (jCheckBoxDOMFrom.isSelected())
{
q2.applyWhere("date_of_manufacture>=", JUtility.getTimestampFromDate(domDateFrom.getDate()));
}
if (jCheckBoxDOMTo.isSelected())
{
q2.applyWhere("date_of_manufacture<=", JUtility.getTimestampFromDate(domDateTo.getDate()));
}
if (jCheckBoxExpiryFrom.isSelected())
{
q2.applyWhere("expiry_date>=", JUtility.getTimestampFromDate(expiryDateFrom.getDate()));
}
if (jCheckBoxExpiryTo.isSelected())
{
q2.applyWhere("expiry_date<=", JUtility.getTimestampFromDate(expiryDateTo.getDate()));
}
if (jCheckBoxCreatedFrom.isSelected())
{
q2.applyWhere("date_created>=", JUtility.getTimestampFromDate(createdDateFrom.getDate()));
}
if (jCheckBoxCreatedTo.isSelected())
{
q2.applyWhere("date_created<=", JUtility.getTimestampFromDate(createdDateTo.getDate()));
}
if (jCheckBoxUpdatedFrom.isSelected())
{
q2.applyWhere("date_updated>=", JUtility.getTimestampFromDate(updatedDateFrom.getDate()));
}
if (jCheckBoxUpdatedFrom.isSelected())
{
q2.applyWhere("date_updated<=", JUtility.getTimestampFromDate(updatedDateTo.getDate()));
}
if (textFieldUserCreated.getText().equals("") == false)
{
q2.applyWhere("created_by_user_id = ", textFieldUserCreated.getText());
}
if (textFieldUserUpdated.getText().equals("") == false)
{
q2.applyWhere("updated_by_user_id = ", textFieldUserUpdated.getText());
}
Integer i;
try
{
i = Integer.valueOf(jFormattedTextFieldQuantity.getText());
q2.applyWhere("quantity=", i);
} catch (Exception e)
{
}
q2.applySort(jComboBoxSortBy.getSelectedItem().toString(), jToggleButtonSequence.isSelected());
q2.applyRestriction(jCheckBoxLimit.isSelected(), jSpinnerLimit.getValue());
q2.applySQL();
result = q2.getPreparedStatement();
return result;
}