private PreparedStatement buildSQLr()
{
PreparedStatement result;
JDBQuery query = new JDBQuery(Common.selectedHostID, Common.sessionID);
query.clear();
query.addText(JUtility.substSchemaName(schemaName, "select * from {schema}APP_MHN"));
query.addParamtoSQL("MHN_Number=", jTextFieldMHN.getText());
query.addParamtoSQL("recorder=", jTextFieldRecorder.getText());
query.addParamtoSQL("initiator=", jTextFieldInitiator.getText());
query.addParamtoSQL("authorisor=",jTextFieldAuthorisor.getText());
if (jTextFieldComment.getText().equals("") == false)
{
query.addParamtoSQL("upper(comment) LIKE ", "%" + jTextFieldComment.getText().toUpperCase() + "%");
}
if (jTextFieldReason.getText().equals("")==false)
{
String sel = "";
if (query.getCriteriaCount()==0)
{
sel = " where ";
}
else
{
sel = " and ";
}
query.setCriterialCount(query.getCriteriaCount()+3);
query.addText(sel+"(reason1 = ? or reason2 = ? or reason3 = ?)");
query.addParameter(jTextFieldReason.getText());
query.addParameter(jTextFieldReason.getText());
query.addParameter(jTextFieldReason.getText());
}
query.addParamtoSQL("status=", jTextFieldStatus.getSelectedItem().toString());
query.addParamtoSQL("required_resource=", jTextFieldResource.getText());
if (checkBoxCreatedFrom.isSelected())
{
query.addParamtoSQL("date_created>=", JUtility.getTimestampFromDate(dateControlCreatedFrom.getDate()));
}
if (checkBoxCreatedTo.isSelected())
{
query.addParamtoSQL("date_created<=", JUtility.getTimestampFromDate(dateControlCreatedTo.getDate()));
}
if (checkBoxExpectedFrom.isSelected())
{
query.addParamtoSQL("date_expected>=", JUtility.getTimestampFromDate(dateControlExpectedFrom.getDate()));
}
if (checkBoxExpectedTo.isSelected())
{
query.addParamtoSQL("date_expected<=", JUtility.getTimestampFromDate(dateControlExpectedTo.getDate()));
}
if (checkBoxResolvedFrom.isSelected())
{
query.addParamtoSQL("date_resolved>=", JUtility.getTimestampFromDate(dateControlResolvedFrom.getDate()));
}
if (checkBoxResolvedTo.isSelected())
{
query.addParamtoSQL("date_resolved<=", JUtility.getTimestampFromDate(dateControlResolvedTo.getDate()));
}
query.appendSort(jComboBoxSortBy.getSelectedItem().toString(), jToggleButtonSequence.isSelected());
query.applyRestriction(false,"none",0);
query.bindParams();
result = query.getPreparedStatement();
return result;
}