package oracle.otnsamples.sqlj.itersubclass;
import oracle.sqlj.runtime.Oracle; import sqlj.runtime.profile.RTResultSet;
import sqlj.runtime.Scrollable;
import java.util.Vector;
class SubOrderIter extends OrderIter {
public SubOrderIter(RTResultSet rs) throws Exception{ super(rs); }
public void getOrdersAndCommission(String empName,float commPercent) throws Exception { float totalOrder=0; float commission=0;
while (this.next()){
totalOrder=totalOrder + this.ORDER_TOTAL().floatValue(); }
commission =totalOrder *commPercent;
this.display(totalOrder, commission,empName); }
public void display(float totalOrder,float commission,String empName){ IterSubclassOrdersFrame orderframe = new IterSubclassOrdersFrame(); try{ orderframe.show(); orderframe.setStatus("Getting orders of employee");
this.first(); do { Vector row =new Vector();
row.addElement(this.ORDER_ID()); row.addElement(this.FIRST_NAME()+" "+this.LAST_NAME()); row.addElement(this.ORDER_MODE()); row.addElement(this.ORDER_TOTAL());
orderframe.tableModel.insertRow(row); } while (this.next()); orderframe.setTitle("Order Details and Commission for "+empName);
orderframe.labelTotal.setText("Order Total : $"+totalOrder); orderframe.labelCommission.setText("Commission Amount : $"+commission); orderframe.setStatus("Order details selected"); } catch(Exception e){ orderframe.setStatus(e.toString()); } } }
public class IterSubclassSample { static IterSubclassEmpFrame gui;
public IterSubclassSample() { try { gui = new IterSubclassEmpFrame();
gui.show(); gui.setStatus("Connecting to database...");
Oracle.connect( getClass(),"../../../../Connection.properties");
} catch(Exception e){ System.out.println("Error connecting to database "+e); System.exit(1); } }
public static void main(String[] args) { try{
IterSubclassSample iter = new IterSubclassSample();
gui.setStatus("Getting sales representatives data");
iter.getSalesRepresentatives(); } catch(Exception e){ gui.setStatus(e.toString()); } }
public void getSalesRepresentatives() throws Exception {
EmpIter empList;
Integer empid=null; String empfname=null,emplname=null,deptname=null; Float commission=null;
while ( true ) {
if (empList.endFetch()) break;
Vector row =new Vector(); row.addElement(empid); row.addElement(" "+empfname +" "+emplname); row.addElement(deptname); row.addElement(commission);
gui.tableModel.insertRow(row); } empList.close(); gui.setStatus("Select a sales representative"); }
public static void getOrders(int repID,String empName,float commPercent) { SubOrderIter orderList; try {
orderList.getOrdersAndCommission(empName,commPercent);
orderList.close(); } catch(Exception e){ gui.setStatus(e.toString()); } }
public static void exitApplication() { try { Oracle.close(); System.exit(1); } catch(Exception e){ gui.setStatus("Error closing application "+e.toString()); } } }
|