MainForm.cs
上传用户:linger1010
上传日期:2008-12-08
资源大小:561k
文件大小:2k
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.WindowsMobile.PocketOutlook;
- namespace AccessingContacts
- {
- public partial class MainForm : Form
- {
- OutlookSession m_outlookSession;
- public MainForm()
- {
- InitializeComponent();
- m_outlookSession = new OutlookSession();
- m_refreshContacts();
- }
- private void m_refreshContacts()
- {
- m_lstContacts.Items.Clear();
- try
- {
- foreach(Contact c in m_outlookSession.Contacts.Items)
- {
- ListViewItem item = new ListViewItem(
- new string[] {
- c.FileAs,
- c.MobileTelephoneNumber,
- c.HomeTelephoneNumber,
- c.BusinessTelephoneNumber,
- c.Email1Address
- });
- m_lstContacts.Items.Add(item);
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(
- String.Format("Error: {0}", ex.Message),
- "Refresh",
- MessageBoxButtons.OK,
- MessageBoxIcon.Hand,
- MessageBoxDefaultButton.Button1);
- }
- }
- private void m_mnuNew_Click(object sender, EventArgs e)
- {
- try
- {
- Contact c = m_outlookSession.Contacts.Items.AddNew();
- c.ShowDialog();
- }
- catch(Exception ex)
- {
- MessageBox.Show(
- String.Format("Error: {0}", ex.Message),
- "New",
- MessageBoxButtons.OK,
- MessageBoxIcon.Hand,
- MessageBoxDefaultButton.Button1);
- }
- }
- private void m_mnuDetails_Click(object sender, EventArgs e)
- {
- if(m_lstContacts.SelectedIndices.Count == 0)
- return;
- int activeIndex = m_lstContacts.SelectedIndices[0];
- Contact activeContact = m_outlookSession.Contacts.Items[activeIndex];
- activeContact.ShowDialog();
- }
- private void m_lstContacts_ItemActivate(object sender, EventArgs e)
- {
- m_mnuDetails_Click(sender, e);
- }
- private void MainForm_Activated(object sender, EventArgs e)
- {
- m_refreshContacts();
- }
- }
- }