1、淮 阴 工 学 院Mobile Computing 实验指导书编者:陈礼青计算机工程学院2011 年 6 月 30 日2目 录EXPERIMENT ONE MOBILE WEB FORM STRUCTURE .31 实验目的 .32 实验环境 .33 实验步骤 .34 实验小结 .6EXPERIMENT TWO DATA ACCESS.71 实验目的 .72 实验环境 .73 实验步骤 .74 实验小结 .12EXPERIMENT THREE VALIDATION CONTROLS .131 实验目的 .132 实验环境 .133 实验步骤 .134 实验小结 .163Experiment O
2、ne Mobile Web Form Structure1 实验目的通过本次实验掌握移动页面的设计,了解移动页面的处理过程,即如下五个步骤:(1) Initialization 初始化(2) Event Handling 事件处理(3) Device Detection 设备检测(4) Rendering 数据获取及显示(5) Cleanup 清空2 实验环境操作系统:Windows XP相关软件:Visual Studio 2005Microsoft .NET Framework 3.5Windows Mobile 6 Standard SDKMicrosoft Mobile Interne
3、t ToolkitMicrosoft Mobile Explorer Emulator3 实验步骤比较 Web 页面与 Mobile 页面的异同,如图 1.1 所示。Web Page Mobile Page图1.1 Web页面与Mobile页面的异同4其中,左图为Web页面,具体实现代码如下:ArrayList PersonList;protected void Page_Load(object sender, System.EventArgs e)for (int i=20;iWEB FORMName:Age:5右图为Mobile页面,具体实现代码如下:ArrayList PersonLis
4、t;protected void Page_Load(object sender, System.EventArgs e)for (int i=20;iMOBILE FORMName:6Age:4 实验小结通过本次实验,熟悉了移动页面的设计,掌握了移动页面的处理过程,了解了 Mobile页面和 Web 页面的异同。本次实验需提交实验报告,内容包括:Part I Experiment PurposePart II Experiment ContentPart III Experiment ProceduresPart IV Experiment Experience7Experiment Two
5、 Data Access1 实验目的 通过此次实验掌握移动页面的数据访问和相关控件进行数据绑定的过程。2 实验环境 操作系统:Windows XP相关软件:Visual Studio 2005Microsoft .NET Framework 3.5Windows Mobile 6 Standard SDKMicrosoft Mobile Internet ToolkitMicrosoft Mobile Explorer Emulator3 实验步骤 待访问的数据表的结构如表 2.1 及图 2.1 所示。 表 2.1 待访问的数据表Field Name Data Type Field Size
6、Required IndexedID AutoNumber Long Integer (Primary Key) Yes (No Duplicates)HighwayName Text 50 No NoTravelTime Text 50 No No图2.1 待访问的数据表数据访问具体实现过程如下:1) Create a new file, and enter the following code:8void Page_Load(Object sender, EventArgs e)if (!IsPostBack)/Create a connection stringstring strCon
7、n = “PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=“ + “C:Traffic.mdb;“; /Create the SQL Statementstring strSQL = “select * from TrafficInfo“; /Create a Connection objectOleDbConnection Conn = new OleDbConnection(strConn); /Create a command object using the connection objectOleDbCommand Cmd = new Ole
8、DbCommand(strSQL,Conn); /Open the DB connectionConn.Open(); /String for outputstring strOutput = “;/Create a OleDbDataReader objectOleDbDataReader Rdr;/Execute the command objects ExecuteReader method to /create a new DataReader objectRdr = Cmd.ExecuteReader(CommandBehavior.CloseConnection);/ Read a
9、ll the data in the DataReader object using a while loopwhile (Rdr.Read() / Create the output string objectstrOutput += Rdr“HighwayName“ + “ - “ + Rdr“TravelTime“ + “, “;/Display the resultOutput.Text = strOutput;9/ always call Close when done reading.Rdr.Close();/ Close the connection when done with
10、 it.Conn.Close();2) Save this file as DataAccess_CS.aspx in your test directory.3) Open your browser, and you should see a result similar to those shown below: (如图 2.2所示)图 21.1 数据访问将 List 控件与 ArrayList 对象绑定的实现过程如下:1) Create a new file, and enter the following code/Private Class declaration to /expos
11、e traffic related propertiesprivate class Traffic/Private members of the class10string strHighway, strTravelTime;/Default constructorpublic Traffic(string HighWay, string TravelTime)this.strHighway = HighWay;this.strTravelTime = TravelTime;/HighwayName read only propertypublic string HighwayNamegetr
12、eturn this.strHighway;/TravelTime read only propertypublic string TravelTimegetreturn this.strTravelTime;void Page_Load(Object sender, EventArgs e)if (!IsPostBack)/Declare a new ArrayList objectArrayList aryTraffic = new ArrayList();/Add some traffic data to the array object /in the form of the Traffic object.aryTraffic.Add(new Traffic(“I90 East“, “50 Mins“);aryTraffic.Add(new Traffic(“I90 West“, “33 Mins“);aryTraffic.Add(new Traffic(“I94 North“, “70 Mins“);aryTraffic.Add(new Traffic(“I94 South“, “40 Mins“);/Data bind the Array List object/into the List control