www.pudn.com > PPC_Weather.rar > Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PPC_Weather.webService;
using System.IO;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Forms;
namespace PPC_Weather
{
public partial class Form1 : Form
{
string sms = string.Empty;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try {
string file = App.GetAppPath() + "\\pic\\Save.xml";
if (File.Exists(file))
{
OperateXML opt = new OperateXML();
Weather weather = opt.XMLDeserialize(file);
this.weatherBindingSource.DataSource = weather;
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
}
private void menuItem1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.txtCity.Text.Trim()))
{
MessageBox.Show("城市不能为空!");
return;
}
Cursor.Current = Cursors.WaitCursor;
this.Text = " 正在更新...";
try {
WeatherWebService weatherService = new WeatherWebService();
Weather weather = weatherService.getWeatherbyCity(this.txtCity.Text.Trim());
this.weatherBindingSource.DataSource = weather;
this.Save(weather);
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}
this.Text = " 天气预报";
Cursor.Current = Cursors.Default;
}
///
/// 保存
///
private void Save(Weather weather) {
OperateXML opt = new OperateXML();
opt.SerializeSave(weather);
}
private void weatherBindingSource_BindingComplete(object sender, BindingCompleteEventArgs e)
{
this.pictureBoxURL2.Visible = !(this.pictureBoxURL1.PicUrl == this.pictureBoxURL2.PicUrl);
}
private void menuItem3_Click(object sender, EventArgs e)
{
SmsMessage sms = new SmsMessage(); //Microsoft.WindowsMobile.PocketOutlook名字空间里的短信类,
sms.Body = GetSmsContent(); //添加短信正文
ChooseContactDialog dialog = new ChooseContactDialog(); //Microsoft.WindowsMobile.Forms名字空间里联系人类
if (dialog.ShowDialog() == DialogResult.OK)
{
sms.To.Add(new Recipient(dialog.SelectedContact.MobileTelephoneNumber)); //将联系的移动号码,指定要发送的号码
}
else {
return;
}
sms.RequestDeliveryReport = false; //发送成功以后不发送送达通知
Cursor.Current = Cursors.WaitCursor;
try
{
sms.Send();
MessageBox.Show("短信发送成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1);
}
catch (Exception err)
{
MessageBox.Show(err.Message, "错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
Cursor.Current = Cursors.Default;
}
///
/// 获取短信内容
///
///
private string GetSmsContent() {
if (string.IsNullOrEmpty(sms)) {
Weather weather = this.weatherBindingSource.DataSource as Weather;
if (weather != null) {
StringBuilder builder = new StringBuilder();
builder.Append("中央气象台");
builder.Append(weather.PublishDate);
builder.Append("发布:");
builder.Append(weather.City);
builder.Append(weather.Date_today);
builder.Append(weather.Weather_today);
builder.Append(weather.Temp_today);
builder.Append(weather.Wind_today);
builder.Append(";");
builder.Append(weather.Date_tomorrow);
builder.Append(weather.Weather_tomorrow);
builder.Append(weather.Temp_tomorrow);
builder.Append(weather.Wind_tomorrow);
builder.Append(";");
builder.Append(weather.Date_dayofTMR);
builder.Append(weather.Weather_dayofTMR);
builder.Append(weather.Temp_dayofTMR);
builder.Append(weather.Wind_dayofTMR);
builder.Append(";");
sms = builder.ToString();
return sms;
}
}
return sms;
}
private void menuItem4_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}