<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--Project save date:Tue Oct 06 15:15:41 PDT 2009--><project singleton="0"><components><node broadcast="false" compile="true" enable="false" h="47" id="1" isEnd="false" isStart="true" link="" roleId="65" selected="true" w="71" x="80" y="54"><name>start</name><displayname>Start</displayname><description/><inLines/><outLines><line fromId="1" id="1" isEnd="false" isStart="false" toId="2"><name/><displayname>Start</displayname><description/><roles><role id="65" roles="8"/></roles></line></outLines><source-import/><source-promote/><source-code autoCheckout="false" calendarValue="0" countdownValue="0" implementType="1" timer="false" timerType="CALENDAR"><![CDATA[ret=true;
for(DtoNode n:getNodes()){
      if(n.getStart().booleanValue()){
         n.setEnable(false);
         break;
      }
}]]></source-code><init-code><![CDATA[greetings="Java quiz\r\nNo time limit.";]]></init-code><expire-code/><fromRec w="6" x="109" y="94"/><toRec w="6" x="109" y="54"/></node><node broadcast="false" compile="true" enable="false" h="47" id="2" isEnd="false" isStart="false" link="" selected="false" w="71" x="220" y="244"><name>genQuestions</name><displayname>gen</displayname><description/><inLines><line fromId="1" id="1" isEnd="false" isStart="false" toId="2"><name/><displayname>Start</displayname><description/><roles><role id="65" roles="8"/></roles></line><line fromId="4" id="3" isEnd="false" isStart="false" toId="2"><name/><displayname>Next</displayname><description/><roles><role id="65" roles="8"/></roles></line></inLines><outLines><line fromId="2" id="2" isEnd="false" isStart="false" toId="4"><name/><displayname>Send2</displayname><description/><roles/></line><line fromId="2" id="4" isEnd="false" isStart="false" toId="5"><name/><displayname>Send4</displayname><description/><roles/></line></outLines><source-import><![CDATA[import java.sql.*;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import ru.goodidea.df.dictionary.factory.*;]]></source-import><source-promote><![CDATA[if(currentId.intValue()==0){
   return this.document.promote(new Integer(5));//No more questions
}
else{
   return this.document.promote(new Integer(4));//There are some questions
}]]></source-promote><source-code autoCheckout="false" calendarValue="0" countdownValue="0" implementType="0" timer="false" timerType="CALENDAR"><![CDATA[    PreparedStatement stmt = null;
    PreparedStatement stmt1 = null;
    ResultSet rset = null;
    ResultSet rset1 = null;
    Connection conn = null;
    SingleChoiceField ch=(SingleChoiceField)getFieldByName("radio"); 
    try {
      StringBuffer sb=new StringBuffer();
      if(ch.getConstraint().isVisible()){
       String ans=(String)ch.getValue();
       Field fldCurrentId=getFieldByName("currentId");
       answers.put((Integer)fldCurrentId.getValue(),ans);
       for(Integer vid:answers.keySet()){
          if(sb.length()==0){
             sb.append(vid);
          }
          else{
            sb.append(","+vid);
          }
       }
      }
      String visited=sb.toString();
      InitialContext ctx = new InitialContext();
      DataSource ds = (DataSource) ctx.lookup("java:/MySqlQuizDS");
      conn = ds.getConnection();
      stmt = conn.prepareStatement("SELECT * FROM quiz.quiz where status=1"+(visited.trim().length()==0?"":" AND ID NOT IN ("+visited+")"));
      rset = stmt.executeQuery();
      if (rset.next()) {
        question= rset.getString("question");
        currentId=rset.getInt("id");
        stmt1 = conn.prepareStatement("SELECT * FROM quiz.quiz_pos_values where quiz_id="+currentId);
        rset1=stmt1.executeQuery();
        
        HashMap<String,Object> map=((SingleChoiceComponent)ch.getComponentable()).getModel();
        map.clear();
        while(rset1.next()){
             map.put(rset1.getString("label"),rset1.getString("value"));
        }
        Field fldSession=getFieldByName("sessionNum");
        fldSession.getConstraint().setVisible(false);
        Field fldGreetings=getFieldByName("greetings");
        fldGreetings.getConstraint().setVisible(false);
        Field fldQuestion=getFieldByName("question");
        fldQuestion.getConstraint().setVisible(true);
        ch.getConstraint().setVisible(true);
      }
      else{
        Field fldGreetings=getFieldByName("greetings");
        fldGreetings.getConstraint().setVisible(true);
        Field fldQuestion=getFieldByName("question");
        fldQuestion.getConstraint().setVisible(false);
        ch.getConstraint().setVisible(false);
         stmt = conn.prepareStatement("SELECT * FROM quiz.quiz where status=1");
         rset = stmt.executeQuery();
         double cnt=0;
         int correctCnt=0;
         while(rset.next()){
            cnt++;
            int id=rset.getInt("id");
            String correctAns=rset.getString("pos_answer");
            String val=(String)answers.get(id);
            if(correctAns.trim().equalsIgnoreCase(val)){
               correctCnt++;
            }
         }
         greetings="Your result is:"+(correctCnt*100./cnt);
         currentId=0;
         for(DtoNode n:getNodes()){
            if(n.getStart().booleanValue()){
               n.setEnable(true);
               break;
            }
         }	
      }
      ret=true;
      setSendToLogin(true);
    }
    catch (Exception e) {
      e.printStackTrace();
//          throw new FinderException(e.getMessage());
    }
    finally {
      if (rset != null) {
        try {
          rset.close();
        }
        catch (SQLException ex) {
        }
      }
      if (rset1 != null) {
        try {
          rset1.close();
        }
        catch (SQLException ex) {
        }
      }

      if (stmt != null) {
        try {
          stmt.close();
        }
        catch (SQLException ex1) {
        }
      }
      if (stmt1!= null) {
        try {
          stmt1.close();
        }
        catch (SQLException ex1) {
        }
      }
      if (conn != null) {
        try {
          conn.close();
        }
        catch (SQLException ex2) {
        }
      }
    }
]]></source-code><init-code/><expire-code/><fromRec w="6" x="249" y="284"/><toRec w="6" x="249" y="244"/></node><node broadcast="false" compile="true" enable="false" h="47" id="3" isEnd="true" isStart="false" link="" selected="false" w="71" x="130" y="604"><name>results</name><displayname>Results</displayname><description/><inLines><line fromId="5" id="5" isEnd="false" isStart="false" toId="3"><name/><displayname>Finish</displayname><description/><roles><role id="65" roles="8"/></roles></line></inLines><outLines/><source-import/><source-promote/><source-code autoCheckout="false" calendarValue="0" countdownValue="0" implementType="0" timer="false" timerType="CALENDAR"><![CDATA[ret=true;]]></source-code><init-code/><expire-code/><fromRec w="6" x="159" y="644"/><toRec w="6" x="159" y="604"/></node><node broadcast="false" compile="true" enable="false" h="47" id="4" isEnd="false" isStart="false" link="" roleId="65" selected="false" w="71" x="420" y="334"><name>UI</name><displayname>UI</displayname><description/><inLines><line fromId="2" id="2" isEnd="false" isStart="false" toId="4"><name/><displayname>Send2</displayname><description/><roles/></line></inLines><outLines><line fromId="4" id="3" isEnd="false" isStart="false" toId="2"><name/><displayname>Next</displayname><description/><roles><role id="65" roles="8"/></roles></line></outLines><source-import/><source-promote/><source-code autoCheckout="true" calendarValue="0" countdownValue="60000" implementType="1" timer="true" timerType="COUNTDOWN"><![CDATA[ret=true;]]></source-code><init-code/><expire-code/><fromRec w="6" x="449" y="374"/><toRec w="6" x="449" y="334"/></node><line fromId="1" h="156" id="1" isEnd="false" isStart="false" selected="false" toId="2" w="152" x="109" y="94"><name/><displayname>Start</displayname><description/><roles><role id="65" roles="8"/></roles><posStart x="109" y="94"/><posEnd x="248" y="244"/><type>3</type><Rec1 h="6" w="6" x="0" y="0"/><Rec2 h="6" w="6" x="133" y="150"/></line><line fromId="2" h="56" id="2" isEnd="false" isStart="false" selected="false" toId="4" w="212" x="249" y="284"><name/><displayname>Send2</displayname><description/><roles/><posStart x="249" y="284"/><posEnd x="449" y="334"/><type>3</type><Rec1 h="6" w="6" x="0" y="0"/><Rec2 h="6" w="6" x="193" y="50"/></line><line fromId="4" h="176" id="3" isEnd="false" isStart="false" selected="false" toId="2" w="212" x="249" y="204"><name/><displayname>Next</displayname><description/><roles><role id="65" roles="8"/></roles><posStart x="449" y="374"/><posEnd x="249" y="244"/><type>1</type><Rec1 h="6" w="6" x="200" y="176"/><Rec2 h="6" w="6" x="0" y="40"/></line><node broadcast="false" compile="true" enable="false" h="47" id="5" isEnd="false" isStart="false" link="" roleId="65" selected="false" w="71" x="380" y="424"><name>UI</name><displayname>UI RES</displayname><description/><inLines><line fromId="2" id="4" isEnd="false" isStart="false" toId="5"><name/><displayname>Send4</displayname><description/><roles/></line></inLines><outLines><line fromId="5" id="5" isEnd="false" isStart="false" toId="3"><name/><displayname>Finish</displayname><description/><roles><role id="65" roles="8"/></roles></line></outLines><source-import/><source-promote/><source-code autoCheckout="false" calendarValue="0" countdownValue="0" implementType="1" timer="false" timerType="CALENDAR"><![CDATA[ret=true;]]></source-code><init-code><![CDATA[Field fldGreetings=getFieldByName("greetings");
fldGreetings.getModel().setLabel("Results:");
]]></init-code><expire-code/><fromRec w="6" x="409" y="464"/><toRec w="6" x="409" y="424"/></node><line fromId="2" h="146" id="4" isEnd="false" isStart="false" selected="false" toId="5" w="172" x="249" y="284"><name/><displayname>Send4</displayname><description/><roles/><posStart x="249" y="284"/><posEnd x="405" y="423"/><type>3</type><Rec1 h="6" w="6" x="0" y="0"/><Rec2 h="6" w="6" x="153" y="140"/></line><line fromId="5" h="146" id="5" isEnd="false" isStart="false" selected="false" toId="3" w="262" x="153" y="464"><name/><displayname>Finish</displayname><description/><roles><role id="65" roles="8"/></roles><posStart x="409" y="464"/><posEnd x="159" y="604"/><type>2</type><Rec1 h="6" w="6" x="256" y="0"/><Rec2 h="6" w="6" x="0" y="134"/></line></components><roles><role id="65"><name>student</name></role></roles><liveCycle><liveCycleNode id="1" value="0"><name>node</name><displayName/><docFlowFunction/></liveCycleNode><liveCycleNode id="2" value="0"><name>node</name><displayName/><docFlowFunction/></liveCycleNode></liveCycle><fields className="Wizard" type="false"><field type="NumberField"><name>sessionNum</name><label>Session Num</label><constraints editable="true" nullable="false" processable="false" required="false" visible="true"/><numberType type="0"/><value/></field><field type="StringField"><name>greetings</name><label>Results:</label><constraints editable="false" nullable="false" processable="false" required="false" visible="true"><length cols="50" rows="3" set="true" size="4000"/></constraints><value/></field><field type="StringField"><name>question</name><label>Current Question</label><constraints editable="false" nullable="false" processable="false" required="false" visible="false"><length cols="40" rows="10" set="true" size="4000"/></constraints><value/></field><field type="SingleChoiceField"><name>radio</name><label>Selection</label><constraints editable="true" nullable="false" processable="false" required="false" visible="false"/><map><item label="Label1">11</item><item label="Label0"/><item label="Label2"/></map></field><field type="NumberField"><name>currentId</name><label>currentId</label><constraints editable="true" nullable="false" processable="false" required="false" visible="false"/><numberType type="0"/><value/></field><customfield id="2"><![CDATA[private HashMap<Integer,String> answers=new HashMap<Integer,String>();]]></customfield></fields><image>C:\temp\scjp.gif</image><description>This is Java quiz project. Represents \"countdown\" feature of workflow.</description><imageIcon/></project>