import java.awt.*; import java.util.Vector; // You will need to add input fields for any // fields you have that are different from mine. // This is a simple issue of laying out input // widgets. public class UserInterface extends Panel { private GridBagLayout layout; private Label idLabel; private TextField idValue; private Label fNameLabel; private TextField fNameValue; private Label lNameLabel; private TextField lNameValue; private Label emailLabel; private TextField emailValue; private GlobalResources global; public UserInterface(GlobalResources g) { global = g; layout = new GridBagLayout(); setLayout(layout); idLabel = new Label("Customer ID"); layout.setConstraints(idLabel, global.defineLayoutConstraints(0,1,2,1, 0,0,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(idLabel); idValue = new TextField(); layout.setConstraints(idValue, global.defineLayoutConstraints(2,1,2,1, 1,1,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(idValue); fNameLabel = new Label("First Name"); layout.setConstraints(fNameLabel, global.defineLayoutConstraints(0,2,2,1, 0,0,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(fNameLabel); fNameValue = new TextField(); layout.setConstraints(fNameValue, global.defineLayoutConstraints(2,2,2,1, 1,1,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(fNameValue); lNameLabel = new Label("Last Name"); layout.setConstraints(lNameLabel, global.defineLayoutConstraints(0,3,2,1, 0,0,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(lNameLabel); lNameValue = new TextField(); layout.setConstraints(lNameValue, global.defineLayoutConstraints(2,3,2,1, 0,0,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(lNameValue); emailLabel = new Label("E-Mail Address"); layout.setConstraints(emailLabel, global.defineLayoutConstraints(0,4,2,1, 0,0,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(emailLabel); emailValue = new TextField(); layout.setConstraints(emailValue, global.defineLayoutConstraints(2,4,2,1, 0,0,1,1, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH, 5,5,5,5)); add(emailValue); } // You will need to edit this so that every // input widget you add is registered in the WHERE clause. public String getWhereClause() { String whereClause = ""; if (fNameValue.getText().length() > 0) { whereClause = "WHERE FirstName LIKE '%" + fNameValue.getText() + "%'"; } if (lNameValue.getText().length() > 0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND LastName LIKE '%" + lNameValue.getText() + "%'"; } else { whereClause = "WHERE LastName LIKE '%" + lNameValue.getText() + "%'"; } } if (emailValue.getText().length() >0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND Email LIKE '%" + emailValue.getText() + "%'"; } else { whereClause = "WHERE Email LIKE '%" + emailValue.getText() + "%'"; } } if (idValue.getText().length() >0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND CustomerID LIKE '%" + idValue.getText() + "%'"; } else { whereClause = "WHERE CustomerID LIKE '%" + idValue.getText() + "%'"; } } return whereClause; } // This is the same process as creating the WHERE clause // and you will need to change it to reflect your own fields public String getSetClause() { String setClause = ""; if (fNameValue.getText().length() > 0) { setClause = "SET FirstName = '" + fNameValue.getText() + "'"; } if (lNameValue.getText().length() > 0) { if (setClause.length() > 0) { setClause = setClause + " , LastName = '" + lNameValue.getText() + "'"; } else { setClause = "SET LastName = '" + lNameValue.getText() + "'"; } } if (emailValue.getText().length() >0) { if (setClause.length() > 0) { setClause = setClause + " , Email = '" + emailValue.getText() + "'"; } else { setClause = "SET Email = '" + emailValue.getText() + "'"; } } if (idValue.getText().length() >0) { if (setClause.length() > 0) { setClause = setClause + " , CustomerID = '" + idValue.getText() + "'"; } else { setClause = "SET CustomerID = '" + idValue.getText() + "'"; } } return setClause; } // Another one of the same. This time it is for "=" not "LIKE" SQL public String getWhereClauseExact() { String whereClause = ""; if (fNameValue.getText().length() > 0) { whereClause = "WHERE FirstName = '" + fNameValue.getText() + "'"; } if (lNameValue.getText().length() > 0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND LastName = '" + lNameValue.getText() + "'"; } else { whereClause = "WHERE LastName = '" + lNameValue.getText() + "'"; } } if (emailValue.getText().length() >0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND Email = '" + emailValue.getText() + "'"; } else { whereClause = "WHERE Email = '" + emailValue.getText() + "'"; } } if (idValue.getText().length() >0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND CustomerID = '" + idValue.getText() + "'"; } else { whereClause = "WHERE CustomerID = '" + idValue.getText() + "'"; } } return whereClause; } // Yup, another one you need to chnage. public String createWhereClauseExact(String s) { String row = s; Vector v = global.parsePipeDelimitedLine(row); String whereClause = ""; if (((String) v.elementAt(0)).length() > 0) { whereClause = "WHERE FirstName = '" + (String) v.elementAt(0) + "'"; } if (((String) v.elementAt(1)).length() > 0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND LastName = '" +(String) v.elementAt(1) + "'"; } else { whereClause = "WHERE LastName = '" + (String) v.elementAt(1) + "'"; } } if (((String) v.elementAt(2)).length() > 0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND Email = '" + (String) v.elementAt(2) + "'"; } else { whereClause = "WHERE Email = '" + (String) v.elementAt(2) + "'"; } } if (((String) v.elementAt(3)).length() > 0) { if (whereClause.length() > 0) { whereClause = whereClause + " AND CustomerID = '" + (String) v.elementAt(3) + "'"; } else { whereClause = "WHERE CustomerID = '" + (String) v.elementAt(3) + "'"; } } return whereClause; } // Just add our own fields to the string...make sure they are // in the correct order! public void setUserInputFieldValues(Vector v) { idValue.setText((String) v.elementAt(0)); fNameValue.setText((String) v.elementAt(1)); lNameValue.setText((String) v.elementAt(2)); emailValue.setText((String) v.elementAt(3)); } // Just add our own fields to the string...make sure they are // in the correct order! public String getUserInputFieldValues() { return idValue.getText() + "|" + fNameValue.getText() + "|" + lNameValue.getText() + "|" + emailValue.getText(); } // Just add our own fields to the string...make sure they are // in the correct order! public String getInsertFieldList() { return "(CustomerID, FirstName, LastName, Email)"; } // Just add our own fields to the string...make sure they are // in the correct order! public String getInsertValueList() { return " VALUES ('" + fNameValue.getText() + "','" + fNameValue.getText() + "','" + emailValue.getText() + "','" + idValue.getText() + "')"; } }