Verwaltung und Programmierung


Anhang F. Net.Data-Beispielmakro

Diese Beispielmakroanwendung zeigt eine Liste von Mitarbeiternamen an, aus der der Anwendungsbenutzer zusätzliche Informationen zu einem bestimmten Mitarbeiter abrufen kann, indem er den Namen des Mitarbeiters in der Liste auswählt. Das Makro verwendet die SQL-Sprachumgebung, um die Tabelle EMPLOYEE nach den Mitarbeiternamen und Informationen zu einem bestimmten Mitarbeiter abzufragen.

Das Makro verwendet eine Kopfdatei, die den DEFINE-Block für das Makro enthält.

Abbildung 32 zeigt das Beispielmakro. Abbildung 33 zeigt die Kopfdatei.

Abbildung 32. Beispielmakro

%{************************ Sample Macro *****************************
*   FileName = sqlsamp1.dtw                                         * 
*   Description:                                                    *
*     This Net.Data macro queries...                                *
*         - The EMPLOYEE table to create a selection list of        *
*           employees for display at a browser                      *
*         - The EMPLOYEE table to obtain additional information     *
*           about an individual employee                            *
*                                                                   *
********************************************************************%}
%{***************************************************************************
*   Include for global DEFINEs -                                            *
****************************************************************************%}
%INCLUDE "sqlsamp1.hti"
%}
%{****************************************************************************
*  Function:  queryDB              Language Environment: SQL                *
*  Description: Queries the table designated by the variable myTable and    *
*  creates a selection list from the result.  The value of the variable     *
*  myTable is specified in the include file sqlsamp1.hti.                   *
****************************************************************************%}
%FUNCTION(DTW_SQL) queryDB() {
 SELECT FIRSTNME FROM EMPLOYEE
%MESSAGE {
    -204:  {<p><b>ERROR -204: Table EMPLOYEE not found. </b> </p>
           %} : exit
    +default: "WARNING $(RETURN_CODE)" : continue
    -default: "Unexpected ERROR $(RETURN_CODE)" : exit
%}
 
%REPORT {
<select name="emp_name">
   %ROW{
<option>$(V1)</option>
%}
</select>
%}
%}
 
%{****************************************************************************
*  Function: fname         Language Environment: SQL                         *
*  Description: Queries the table designated by the variable myTable for     *
*               additional information about the employee identified by the  *
*               variable emp_name.                                           *
******************************************************************************%}
%FUNCTION(DTW_SQL) fname(){
SELECT FIRSTNME, PHONENO, JOB FROM EMPLOYEE WHERE FIRSTNME='$(emp_name)'
%MESSAGE {
  -204: "Error -204: Table not found "
  -104: "Error -104: Syntax error"
   100: "Warning 100: No records" : continue
  +default: "Warning $(RETURN_CODE)" : continue
  -default: "Unexpected SQL error" : exit
%}
%}
 
%{*********************************************************************
*  HTML block: INPUT            Title: Dynamic Query Selection              *
*                                                                     *
*  Description: Queries the EMPLOYEE table to create a selection list *
*               of the employees for display at the browser           *
**********************************************************************%}
   %HTML(INPUT){
<html>
<head>
<title>Generate Employee Selection List</title>
</head>
<body>
<h3>$(exampleTitle)</h3>
<p>This example queries a table and uses the result to create
a selection list using a <em>%REPORT</em> block. </p>
<hr />
<form method="post" action="report">
@queryDB()
<input type="submit" value="Select Employee" />
</form>
<hr />
</body>
</html>
%}
%{***************************************************************************
*  HTML block:    REPORT                                                    *
*  Description: Queries the EMPLOYEE table to obtain additional information *
*               about an individual employee                                *
****************************************************************************%}
%HTML(REPORT){
<html>
<head>
<title>Obtain Employee Information</title>
</head>
<body>
<h3>You selected employee name = $(emp_name)</h3>
<p>Here is the information for that employee:
<pre>
@fname()
</pre></p>
<hr /><a href="input">Return to previous page</a>
</body>
</html>
%}
 
%{     End of Net.Data macro 1 %}
 

Abbildung 33. Kopfdatei

===========================================================================
%{**************************** Include File *********************************
*   FileName = sqlsamp1.hti                                                 *
*   Description:                                                            *
*     This include file provides global DEFINEs for the sqlsamp1.dtw        *
*     Net.Data macro.                                                       *
****************************************************************************%}
%define {
    emp_name   =""
    reposition = sign
 exampleTitle = "Sample Macro"
    %}
 
%{     End of include file  %}


[ Seitenanfang | Vorherige Seite | Nächste Seite ]