基于Windows Mobile 5.0的掌上天气预报设计

  基于Windows Mobile 5.0的掌上天气预报设计

概述:描述一个基于Windows mobile 5.0的天气预报程序设计过程;

开发工具:Visual studio 2005(C#/)Windows Mobile 5.0 Pocket PC SDK/WM6 模拟器;

试用机型:多普达 D600

关键字:.NET CF,PPC, WebService,Windows mobile, 天气预报

   下载安装程序:PocketWeatherInstall.cab 
   下载  源代码:PocketWeather.rar 

      
总的来说,使用.NET Compact Framework 设计程序还是比较容易入手的,本文就在设计过程中碰到的几个问题做一个简要说明。


1.     
天气接口

采用一个网上免费的Web服务,来源www.WebXml.com.cn,使用非常方便,调用getWeatherbyCityName返回一个string数组,包含相关天气信息。   

string city = this.lblCurrentCity.Text.Trim();

PocketWeather.cn.com.webxml.www.WeatherWebService Weather =

new PocketWeather.cn.com.webxml.www.WeatherWebService();

string[] info = Weather.getWeatherbyCityName(city);


2.     
获取程序运行路径

PPC获取当前程序路径还比较麻烦:

public static string GetApplicationDirectory()

  {

       return System.IO.Path.GetDirectoryName(

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

   }


3.     
保存用户设置

将用户设置信息保存在一个DataSet中,然后存储为本地XML文件:

DataSet ds = new DataSet("LastWeather");          

            DataTable tabLast = new DataTable("Weather");

            tabLast.Columns.Add("KeyStr", typeof(string));

            tabLast.Columns.Add("Content", typeof(string));

            DataRow row = tabLast.NewRow();

            row["KeyStr"] = "lblTodayWeather";

            row["Content"] = this.lblTodayWeather.Text;

            tabLast.Rows.Add(row);          

            row = tabLast.NewRow();

            row["KeyStr"] = "LastModifyTime";

            row["Content"] = SystemConfig.LastModifyTime;

            tabLast.Rows.Add(row);

            ds.Tables.Add(tabLast);

            ds.WriteXml(SystemConfig.GetApplicationDirectory() + """Last.xml");

读取时从XML文件获取DataSet,然后再读取数据。

     DataSet ds = new DataSet();

     ds.ReadXml(SystemConfig.GetApplicationDirectory() + """Last.xml");

     DataTable tabSetting = ds.Tables["Weather"];

     DataRow[] rows = tabSetting.Select("KeyStr='lblTodayWeather'");

     if (rows.Length != 0)

     {

             this.lblTodayWeather.Text = rows[0]["Content"].ToString();

      }            

       rows = tabSetting.Select("KeyStr='LastModifyTime'");

       if (rows.Length != 0)

       {

              SystemConfig.LastModifyTime = rows[0]["Content"].ToString();

       } 


4.
输入法面板:

当弹出输入法面板是会挡住一些用户控件,感觉很不好,处理办法就是将控件放在一个Panel中,设置Panel的AutoScroll属性为True,在面板状态改变时同时改变Panel的尺寸。

private Microsoft.WindowsCE.Forms.InputPanel m_inp

= new Microsoft.WindowsCE.Forms.InputPanel();

public FormOpetion()

        {

            InitializeComponent();

            this.m_inp.EnabledChanged += new EventHandler(m_inp_EnabledChanged);

        }

        void m_inp_EnabledChanged(object sender, EventArgs e)

        {

            m_panel.Size = m_inp.VisibleDesktop.Size;          

        }
 
 5.
对话框问题:

程序在打开一个对话框时,如果切换到其他程序,然后在系统运行程序列表中会看到两项记录,应该避免这种情况;解决办法就是在程序激活和停用时修改窗口标题:

private void FormOpetion_Deactivate(object sender, EventArgs e)

        {

            this.Text = "";

        }

        private void FormOpetion_Activated(object sender, EventArgs e)

        {

            this.Text = "设置";

        }

6.其他:

还应该考虑在屏幕旋转时,要重新调整控件的位置。

界面:


posted @ 2007-10-30 11:22  seabluescn  阅读(2792)  评论(4编辑  收藏  举报