7. PROPUESTA FINAL DEL PROYECTO
7.3 ESTRATEGIAS
♦ ResScript.wmls - The scripting file
♦ Restaurant.wml - The main menu file to select the category
♦ South.wml - Link file to select items of the South Indian dishes category
♦ Soft.wml - Link file to select items of Soft Drinks category
Application Work Flow
The main file is Restaurant.wml, which shows three items:
♦ South Indian (South.wml)
♦ Soft Drink (Soft.wml)
♦ Snacks (Snacks.wml)
After you click a particular item, the system calls the corresponding WML file and shows the item related to that category.
Figure 2-6 shows the flow of data in the files.
Figure 2-6: Flow diagram of the Restaurant application
Application Description
Listing 2-5 shows the code for Restaurant.wml. The main menu file shows a menu containing three links for three categories.
Listing 2-5: Restaurant.wml
// © 2001 Dreamtech Software India Inc. // All Rights Reserved1.<?xml version="1.0"?>
2.<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- WML prolog–declaration of file type and version> 3.<wml>
<!-- declaration of a new deck> 4.<head>
5.<meta http-equiv="Cache-Control" content="max-age=time" forua="true"/> <!-- meta tag to define the content and cache settings>
6.</head>
7.<card id="card1">
<!-- declaration of a new card> 8.<onevent type="onenterbackward">
9.<go href="ResScript.wmls#Initialize()" />
<!-- declaration of an event for navigation and calling of> <!-- function from the script file>
10. </onevent>
<!-- end of event declaration>
11. <p align="center"><b> Taj Palace </b>
<!-- declaration of a new paragraph to display heading> 12. </p>
<!-- end of paragraph>
13. <p align="left">Select a Category:
<!-- declaration of a new paragraph to display selection> <!— category>
14. </p>
15. <p align="left" mode="nowrap">
<!-- declaration of a new paragraph to define table> 16. <table align="left" columns="1">
<!-- declaration of a table> 17. <tr>
<!-- declaration of a new row>
18. <td><a href="South.wml">South Indian</a></td>
<!-- declaration of a new column having link to south.wml> 19. </tr>
<!-- end of a row> 20. <tr>
<!-- declaration of a new row >
21. <td><a href="Soft.wml">Soft Drink</a></td>
<!-- declaration of a new column having link to soft.wml> 22. </tr>
<!-- end of row> 23. <tr>
<!-- declaration of a new row>
24. <td><a href="Snacks.wml">Snacks</a></td> 25. </tr> <!-- end of row> 26. </table> <!-- end of table> 27. </p> 28. </card> <!-- end of card> 29. </wml> <!-- end of wml>
Code description
♦ Lines 1–2: WML Prolog♦ Line 7: Defining the first card named card1
♦ Line 8: Event declared (trapping the click event)
♦ Line 9: Specifying the navigation link to the initialize function of the ResScript.wmls script file
♦ Line 10: Event closed
♦ Lines11–12: Paragraph declaration to display Taj Palace in center
♦ Lines 13–15: Paragraph to display selection of category
♦ Lines 16–26: Creation of table with one column and three rows, each row containing the link to a new category. After you select the link, navigation takes you to a new file
♦ Lines 27–29: Closing tags
Code output
Figure 2-7 shows the output of Restaurant.wml.
Figure 2-7: Output screen of the file Restaurant.wml
Listing 2-6 shows the code for South.wml. This file shows the items belonging to the South Indian category. The user can select an item from the list. The price of that item is passed as a parameter to the function Func1 of the script file ResScript.wmls.
Listing 2-6: South.wml
// © 2001 Dreamtech Software India Inc. // All Rights Reserved1. <?xml version="1.0"?>
2. <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- WML prolog–declaration of file type and version> 3. <wml>
<!-- declaration of a new deck> 4. <head>
5. <meta http-equiv="Cache-Control" content="max-age=time" forua="true"/> <!-- meta tag to define the content and cache settings>
6. </head>
7. <card id="card1">
<!-- declaration of a new card> 8. <onevent type="onenterforward"> <!-- declaration of a new event> 9. <refresh>
<!-- refreshing the variable> 10.<setvar name="var1" value="1.00" />
<!-- declaration of a variable and initialising it> 11.</refresh>
12.</onevent>
13.<do type="accept">
<!-- declaration of an event>
14.<go href="ResScript.wmls#Func1($var1)" />
<!-- declaration of navigation to script file to > <!-- call the function funcl with parameter> 15.</do>
<!-- end of event> 16.<p>
<!-- declaration a new paragraph> 17.<select name="var1">
<!-- declaration of a select list>
18. <option value="23.00">Onion pancake 23.00</option> 19. <option value="15.00">Rice pancake 15.00</option> 20. <option value="15.00">Rice ball 15.00</option> 21. <option value="10.00">Cheese pancake 10.00</option> 22. <option value="30.00">Mixed stew 30.00</option> 23. <option value="20.00">Rice doughnut 20.00</option>
<!--options of select list>
24. </select> <!-- end of select list> 25. </p> <!-- end of paragraph> 26. </card> 27. <!-- end of card> 28. </wml> 29. <!-- end of deck>
Code description
♦ Lines 1–2: WML Prolog♦ Lines 3–5: Meta tag on head
♦ Line 6: End of the head tag
♦ Line7: Defining the first card named card1
♦ Line 8: Event declared (trapping the click event)
♦ Line 9: Specifying the navigation link to initialize the function of the ResScript.wmls script file
♦ Line 10: Defining a variable var1 and initializing it to 1
♦ Line 11: End of the refresh tag
♦ Line 12: Event closed
♦ Lines 13–15: Calling the function Func1 from ResScript.wmls with the value of variable var1 on select option
♦ Line 16: New paragraph
♦ Lines 17–23: Creating the selection list having items belonging to the South Indian category
♦ Lines 24–29: Closing tags
Code output
Figure 2-8: Output screen ofSouth.wml
Listing 2-7 shows the code for Soft.wml. This file shows the items belonging to the Soft Drinks category and selects an item from the list. The price of that item is passed as a parameter to the function func1 of the script file ResScript.wmls.
Listing 2-7: Soft.wml
// © 2001 Dreamtech Software India Inc. // All Rights Reserved
1.<?xml version="1.0"?>
2.<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- WML prolog–declaration of file type and version> 3.<wml>
<!-- declaration of a new deck> 4.<head>
5.<meta http-equiv="Cache-Control" content="max-age=time" forua="true"/> <!-- meta tag to define the content and cache settings >
6.</head>
7.<card id="card1">
<!-- declaration of a new card> 8.<onevent type="onenterforward"> <!-- declaration of a new event> 9.<refresh>
<!-- refreshing the variables>
10. <setvar name="var1" value="1.00" />
<!-- declaring a variable and setting the initial value> 11. </refresh>
<!-- end of refresh> 12. </onevent>
<!-- end of event declaration> 13. <do type="accept">
<!-- declaration of action event>
14. <go href="ResScript.wmls#Func1($var1)" />
<!-- declaration of action to call the function from> <!-- script file with a parameter>
15. </do>
<!-- end of action tag> 16. <p>
<!-- declaration of a new paragraph> 17. <select name="var1">
<!-- declaration of a select list>
18. <option value="40.00">Cold Coffee 40.00</option> 19. <option value="20.00">Coffee 20.00</option> 20. <option value="20.00">Cold Drink 20.00</option> 21. <option value="10.00">Tea 10.00</option>
22. <option value="50.00">Cold Coffee with ice-cream 50.00</option> <!-- options of select list>
<!-- end of select list> 24. </p> <!-- end of paragraph> 25. </card> <!-- end of card> 26. </wml> <!-- end of deck>
Code description
♦ Lines 1–2: WML Prolog♦ Lines 3–5: Meta tag on head
♦ Line 7: Defining the first card named card1
♦ Line 8: Event declared (trapping the click event)
♦ Line 9: Specifying the navigation link to initialize function of the ResScript.wmls script file
♦ Line 10: Defining a variable var1 and initializing it to 1
♦ Line 12: Event closed
♦ Lines 13–15: Calling the function func1 from ResScript.wmls with the value of variable var1 on select option
♦ Line 16: New paragraph
♦ Lines 17–23: Creating the selection list containing items belonging to the Soft Drinks category
♦ Lines 24–26: Closing tags
Figure 2-9 shows the output of Soft.wml.
Figure 2-9: Output screen of Soft.wml
Listing 2-8 shows the output for Snacks.wml. This file shows the items belonging to the Snacks category . The user can select an item from the list. The price of that item is passed on as a parameter to the function Func1 of the script file ResScript.wmls.
Listing 2-8: Snacks.wml
// © 2001 Dreamtech Software India Inc. // All Rights Reserved1.<?xml version="1.0"?>
2.<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<!-- WML prolog–declaration of file type and version> 3.<wml>
<!-- declaration of a deck> 4.<head>
5.<meta http-equiv="Cache-Control" content="max-age=time" forua="true"/> <!-- meta tag to define the content and cache settings > 6.</head>
7.<card id="card1">
<!-- declaration of a card> 8.<onevent type="onenterforward">
<!-- declaration of an event> 9.<refresh>
<!-- refereshing the variable>
10. <setvar name="var1" value="1.00" />
<!-- declaration of a variable and storing initial value> 11. </refresh>
12. </onevent>
<!-- end of event declaration > 13. <do type="accept">
<!-- declaration of an action>
14. <go href="ResScript.wmls#Func1($var1)" />
<!-- declaration of an action and calling the function > <!-- from script file>
15. </do> 16. <p>
<!-- declaration of a new paragraph to display > <!-- select list>
17. <select name="var1">
<!-- declaration of a select list>
18. <option value="40.00">Cutlet 40.00</option> 19. <option value="30.00">Cheese Fry 30.00</option> 20. <option value="20.00">Bread Pakora 20.00</option> 21. <option value="25.00">Mix. Veg. Pakora 25.00</option> 22. <option value="30.00">Onion Pakora 30.00</option>
<!-- list items> 23. </select>
<!-- end of select list> 24. </p> <!-- end of paragraph> 25. </card> <!-- end of card> 26. </wml> <!-- end of deck>
Code description
♦ Lines 1–2: WML Prolog♦ Lines 3–5: Meta tag on head
♦ Line 7: Defining the first card named card1
♦ Line 8: Event declared (trapping the click event)
♦ Line 9: Specifying the navigation link to initialize the function of the ResScript.wmls script file
♦ Line 10: Defining a variable var1 and initializing it to 1
♦ Line 12: Event closed
♦ Lines 13–15: Calling the function func1 from ResScript.wmls with the value of variable var1 on select option
♦ Line 16: New paragraph
♦ Lines 17–23: Creating the selection list containing items belonging to the Snacks category
♦ Lines 24–26: Closing tags
Code output
Figure 2-10: Output screen of snacks.wml
Listing 2-9 shows the code for ResScripts.wmls. The script file has two functions. Func1 is called from three link files to calculate the amount of the bill, and the function Initialize is called from the restaurant file to set the initial value of the browser variable TotalAmount to 0.
Listing 2-9: ResScripts.wmls
// © 2001 Dreamtech Software India Inc. // All Rights Reserved1.extern function Func1(Price){ // declaration of function funcl 2.var ITEM="0";
// declaring a new ITEM variable and setting to 0 3.var TAmount=WMLBrowser.getVar("TotalAmount");
// declaring a new TAmount variable and setting it to // the value of variable TotalAmount
4.ITEM = Dialogs.prompt("Enter Quantity", ITEM);
// declaring a dialog to take input from user 5.var Amount = ITEM * Lang.parseFloat(Price);
// declaring a new Amount variable and setting it to Price 6.TAmount = TAmount + Amount;
// adding amount to TAmount 7.WMLBrowser.refresh();
// refresh the browser
8.ITEM = Dialogs.prompt("Your Total Bill", TAmount);
// declaring a dialog to display amount on screen 9.WMLBrowser.setVar("TotalAmount",TAmount);
// setting the variable TotalAmount to TAmount 10. WMLBrowser.go("Restaurant.wml#card1 ");
// setting the navigation to restaurant’s card1 11. }
// declaration of function initialize 12. extern function Initialize()
13. {
14. WMLBrowser.setVar("TotalAmount","0.00");
// setting the variable TotalAmount to 0 }
Code description
This is a script file, the function of which is to calculate the amount and generate the bill accordingly. The main calculations are done through this file. The following breakdown shows the functioning of this file in detail:
♦ Line 1: Defining the first function named Func1, which takes price as parameter
♦ Line 2: Defining a variable ITEM and initializing it to 0
♦ Line 3: Reading the browser variable TotalAmount and storing the result into local variable TAmount
♦ Line 4: Showing a prompt on-screen and accepting the value for quantity and storing it in the variable ITEM
♦ Line 5: Calculating the amount by multiplying the ITEM quantity with price received as parameter
♦ Line 6: Adding the amount calculated to TAmount variable
♦ Line 7: Refreshing the browser
♦ Line 8: Displaying the bill amount on browser
♦ Line 9: Setting the value of browser variable TotalAmount to local variable TAmount
♦ Line 10: Taking navigation control back to main Restaurent.wml files’s card1
♦ Line 11: Function closed
♦ Line 12: Defining of second function named Initialize, which takes no parameter
♦ Line 13: Sets the browser variable TotalAmount to 0. This function is called when the application starts functioning