Following is a complete listing of main.htm for your use:
<html> <script src="tutorial.js"></script> <script> function DisplayRow() { Fetch(); document.form.ID.value = ID; document.form.GivenName.value = GivenName; document.form.Surname.value = Surname; document.form.Street.value = Street; document.form.City.value = City; document.form.Phone.value = Phone; } function FetchForm() { GivenName = document.form.GivenName.value; Surname = document.form.Surname.value; Street = document.form.Street.value; City = document.form.City.value; Phone = document.form.Phone.value; } function ClickInsert() { FetchForm(); Insert(); DisplayRow(); } function ClickNext() { Next(); DisplayRow(); } function ClickPrev() { Prev(); DisplayRow(); } function ClickSync() { Synchronize(); DisplayRow(); } </script> <body onload="Connect(); DisplayRow();" > <form name="form"> <br><td> ID: </td> <td> <input type="text" name="ID" size="10"> </td> <br><td> Given Name: </td> <td> <input type="text" name="GivenName" size="15"> </td> <br><td> Surname: </td> <td> <input type="text" name="Surname" size="50"> </td> <br><td> Street: </td> <td> <input type="text" name="Street" size="20"> </td> <br><td> City: </td> <td> <input type="text" name="City" size="20"> </td> <br><td> Phone: </td> <td> <input type="text" name="Phone" size="12"> </td> <br> <br> <table> <tr> <td> <input type="button" value="Insert" onclick="ClickInsert();"> </td> <td> <input type="button" value="Next" onclick="ClickNext();"> </td> <td> <input type="button" value="Prev" onclick="ClickPrev();"> </td> </tr> <tr> <td colspan=3> <input type="button" value="Synchronize" onclick="ClickSync();"> </td> </tr> </table> </form> <a href="AG_DEVICEOS/ul_deps.htm"></a> </body> </html> |
Following is a complete listing of tutorial.js for your reference and use:
// UltraLite Tutorial var DB_mgr; var Connection; var CustomerTable; var GivenName = ""; var Surname = ""; var Street = ""; var City = ""; var Phone = ""; var ID = ""; function Connect() { var dir; var open_parms; var browser = navigator.platform; DB_mgr = CreateObject( "iAnywhere.UltraLite.DatabaseManager.Tutorial" ); if( DB_mgr == null ) { alert( "Error: cannot create database manager." ); return; } dir = DB_mgr.directory; open_parms = "con=tutorial;" + "file_name=" + dir + "\\tutorial.udb"; try { Connection = DB_mgr.reOpenConnection( "tutorial" ); if( Connection == null ) { Connection = DB_mgr.openConnection( open_parms ); } } catch( ex ) { if( DB_mgr.sqlCode != DB_mgr.SQLError.SQLE_ULTRALITE_DATABASE_NOT_FOUND ) { alert( "Error: cannot connect to database: " + ex.Message() ); return; } } try { CustomerTable = Connection.getTable( "Customer", null ); if( CustomerTable != null ) { CustomerTable.open(); } } catch( ex ) { alert( "Error: cannot open table: " + ex.Message() ); } } function Fetch() { if( CustomerTable.getRowCount() == 0 || CustomerTable.isBOF() ) { GivenName = ""; Surname = ""; Street = ""; City = ""; Phone = ""; ID = ""; return; } ID = CustomerTable.getString( CustomerTable.schema.getColumnID( "ID" ) ); GivenName = CustomerTable.getString( CustomerTable.schema.getColumnID( "GivenName" ) ); Surname = CustomerTable.getString( CustomerTable.schema.getColumnID( "Surname" ) ); Street = CustomerTable.getString( CustomerTable.schema.getColumnID( "Street" ) ); if( CustomerTable.isNull( CustomerTable.schema.getColumnID( "City" ) ) ) { City = ""; } else { City = CustomerTable.getString( CustomerTable.schema.getColumnID( "City" ) ); } if( CustomerTable.isNull( CustomerTable.schema.getColumnID( "Phone" ) ) ) { Phone = ""; } else { Phone = CustomerTable.getString( CustomerTable.schema.getColumnID( "Phone" ) ); } } function Insert() { try { CustomerTable.insertBegin(); CustomerTable.setString( CustomerTable.schema.getColumnID( "GivenName" ), GivenName ); CustomerTable.setString( CustomerTable.schema.getColumnID( "Surname" ), Surname ); CustomerTable.setString( CustomerTable.schema.getColumnID( "Street" ), Street ); if( City.length > 0 ) { CustomerTable.setString( CustomerTable.schema.getColumnID( "City" ), City ); } if( Phone.length > 0 ) { CustomerTable.setString( CustomerTable.schema.getColumnID( "Phone" ), Phone ); } CustomerTable.insert(); CustomerTable.moveLast(); } catch( ex ) { alert( "Error: cannot insert row: " + ex.Message() ); } } function Next() { if( ! CustomerTable.moveNext() ) { CustomerTable.moveLast(); } } function Prev() { if( ! CustomerTable.movePrevious() ) { CustomerTable.moveFirst(); } } function Synchronize() { var sync_parms; sync_parms = Connection.syncParms; sync_parms.setUserName( "tutorial" ); sync_parms.setPassword( "tutorial" ); sync_parms.setVersion( "tutorial" ); sync_parms.setStream( sync_parms.STREAM_TYPE_TCPIP ); try { Connection.synchronize(); } catch( ex ) { alert( "Error: cannot synchronize: " + ex.Message() ); } } |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |