2012-05-31 3 views
1

ZK에서 새로운 점은 Query Stament 결과의 행이있는 GRID를 만들고 싶습니다.ZK를 사용하여 그리드에서 쿼리의 결과를 표시하는 방법?

<window title="REPORTE IMPRESION" border="normal"> 
    <zscript><![CDATA[ 
    import java.sql.*; 
    void submit() { 
     //load driver and get a database connetion 
     Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
     Connection conn = DriverManager.getConnection(
       "jdbc:sqlserver://127.0.0.1;databaseName=Reports", "sa", "sa"); 
     PreparedStatement stmt = null; 
     try { 
      stmt = conn 
        .prepareStatement("select s.ID, s.NOMBRE, c.FECHA, c.PAG, c.TOTAL, c.PAG * 3.3 as TOTAL_PAGAR, c.PAG * 2.67 as Impresion, (c.PAG * 2.67)+(c.PAG * 3.3) as R FROM C_Sucursal s, Corte c where s.CLAVE=c.CLAVE and c.FECHA=?"); 

      //insert what end user entered into database table 
      stmt.setString(1, fecha.getContext()); 
      //execute the statement and Put the result in a ResultSet 
      PreparedStatement consulta1 = stmt; 
      ResultSet result1 = consulta1.executeQuery(); 
      int i=0; 
      while(result1.next()){ 
          //Here i need to put the result in a row! 
       System.out.println(result1.getObject(i)); 
       i++; 
      } 

     } finally { //cleanup 
      if (stmt != null) { 
       try { 
        stmt.close(); 
       } catch (SQLException ex) { 
        log.error(ex); //log and ignore 
       } 
      } 
      if (conn != null) { 
       try { 
        conn.close(); 
       } catch (SQLException ex) { 
        log.error(ex); //log and ignore 
       } 
      } 
     } 
    } 
]]> 
    </zscript> 
    <div apply="org.zkoss.bind.BindComposer"> 
     <borderlayout sclass="complex-layout" height="580px"> 
      <north size="120px" border="0"> 
       <div> 
        <image sclass="complex-layout-header-img" 
         src="/images/bb.png" /> 
       </div> 
      </north> 
      <!-- Content --> 
      <center> 
       <div> 
        <hlayout> 
         <label sclass="hightlight"> 
          Fecha del Corte 
         </label> 
        </hlayout> 
        <datebox id="fecha" width="150px" 
         format="dd-MM-yyyy" /> 
        <button label="submit" onClick="submit()" /> 
        <grid> 
         <columns menupopup="auto"> 
          <column label="ID" sort="auto" /> 
          <column label="SUCURSAL" sort="auto" /> 
          <column label="PAGINAS" sort="auto" /> 
          <column label="EDO_CUENTA" sort="auto" /> 
          <column label="TOTAL A PAGAR" sort="auto" /> 
          <column label="IMPRESION" sort="auto" /> 
          <column label="ENVIO" sort="auto" /> 
         </columns> 
        </grid> 
       </div> 
      </center> 
      <south size="40px" border="0" 
       style="background: none repeat scroll 0 0 ;"> 
       <toolbar mold="panel" align="center"> 
        DERECHOS RESERVADOS 
       </toolbar> 
      </south> 
     </borderlayout> 
    </div> 
</window> 

어떻게 그리드의 행에 쿼리의 결과를 넣을 수 있습니다 :

이 내 코드인가? 도움!

나는 결승전을 치고 결과는 내가 행에 넣어야 할 것이지만 결과를 어떻게 내놓을 지 모른다.

답변

1

그리드에 ID를 지정하고 메서드에 전달하면 전달되는 메서드에서 Grid 개체를 사용하고 데이터를 표시하는 데 필요한 행을 만들 수 있습니다. 당신이 당신의 함수를 호출 할 때,

submit(myGrid); 

하자 말 그것에 "에는 myGrid"에

<grid id="myGrid"> 
    <columns menupopup="auto"> 
    <column label="ID" sort="auto" /> 
    <column label="SUCURSAL" sort="auto" /> 
    <column label="PAGINAS" sort="auto" /> 
    <column label="EDO_CUENTA" sort="auto" /> 
    <column label="TOTAL A PAGAR" sort="auto" /> 
    <column label="IMPRESION" sort="auto" /> 
    <column label="ENVIO" sort="auto" /> 
    </columns> 
</grid> 

통과, 당신은 당신을 위해 그리드에 결과를 추가하는 작업을 개인 방법이 있고, 당신의 말 결과가 "Data"라는 개체에 래핑 된 경우 다음 데이터가 표에 표시됩니다.

private void displayResult(Grid myGrid, List<Data> data) 
{ 

    Rows rows = new Rows(); 
    rows.setParent(programGrid);  

    for(Data d : data) 
    { 
     Label idLabel = new Label(d.getID()); 
     Label sucursalLabel = new Label(d.getSucursal()); 
     Label paginasLabel = new Label(d.getPaginas()); 
     .... etc ... 

     Row row = new Row();  

     idLabel.setParent(row); 
     sucursalLabel.setParent(row); 
     paginasLabel.setParent(row); 
     .... etc ... 

     row.setParent(rows); 
    } 
} 
관련 문제