using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using Microsoft.WindowsMobile.Status;
namespace Gps_demo
{
public partial class Form3 : Form
{
private Timer SyncTimer = null;
public Form3()
{
InitializeComponent();
SetUpNotifications();
}
private void menuItem1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private ArrayList stateList = new ArrayList();
public void SetUpNotifications() {
SystemState s;
// Monitor for ActiveSync Connection
s = new SystemState(SystemProperty.CradlePresent);
s.Changed += new ChangeEventHandler(ChangeOccurred);
stateList.Add(s);
// Monitor for GPRS Connection
s = new SystemState(SystemProperty.PhoneGprsCoverage);
s.Changed += new ChangeEventHandler(ChangeOccurred);
stateList.Add(s);
//Monitor for Network Connection (eg. WIFI)
s = new SystemState(SystemProperty.ConnectionsNetworkCount);
s.Changed += new ChangeEventHandler(ChangeOccurred);
stateList.Add(s);
UpdateConnectionState();
}
public void ChangeOccurred(object sender, ChangeEventArgs args) {
SystemState state = (SystemState)sender;
UpdateConnectionState();
}
public void UpdateConnectionState() {
// Set the check boxes based on the current state of the networks
activesync.Checked = Convert.ToBoolean(SystemState.GetValue(SystemProperty.CradlePresent));
gprs.Checked = Convert.ToBoolean(SystemState.GetValue(SystemProperty.PhoneGprsCoverage));
wifi.Checked = Convert.ToBoolean(SystemState.GetValue(SystemProperty.ConnectionsNetworkCount));
}
private void btnSync_Click(object sender, EventArgs e)
{
Sync();
}
private void Sync() {
// Sync
MessageBox.Show("synchornization开始执行");
//
// //
// Insert Sync Code Here //
// //
//
label1.Text = "同步完成";
}
public void SyncTimerEvent(object unused, EventArgs notused) {
Sync();
}
private void button1_Click(object sender, EventArgs e)
{
this.SyncTimer = new Timer();
this.SyncTimer.Interval = 5000;
this.SyncTimer.Enabled = false;
this.SyncTimer.Tick += new EventHandler(SyncTimerEvent);
if (chkTimer.Checked)
this.SyncTimer.Enabled = true;
else
this.SyncTimer.Enabled = false;
}
private void chkTimer_CheckStateChanged(object sender, EventArgs e)
{
this.SyncTimer = new Timer();
this.SyncTimer.Interval = 5000;
this.SyncTimer.Enabled = false;
this.SyncTimer.Tick += new EventHandler(SyncTimerEvent);
if (chkTimer.Checked)
{ this.SyncTimer.Enabled = true; }
else
{ this.SyncTimer.Enabled = false; }
}
}
}