将每个contact的birthday添加为appointment提醒。
具体讲就是查找每个contact的birthday,然后以contact的firstname's birthday为主题存储一条appointment信息。
实现:
1. 点击 add菜单项
2. 使用OutlookSession对象,查找所有有效生日信息的contact集合ContactCollection。
DateTime invalidDate = DateTime.FromFileTimeUtc(0);
string invalidDateStr = invalidDate.Date.ToString("d", System.Globalization.DateTimeFormatInfo.CurrentInfo) +
" " + invalidDate.TimeOfDay.ToString();
string query = "[Birthday] <> " + invalidDateStr;
ContactCollection contacts = outlooksession.Contacts.Items.Restrict(query);
3. 将查询出的contact的birthday、firsname,以及所在OutlookSession作为参数传递给private AddToCalendar方法。
4.AddToCalendar:若不存在重复主题就新建一个Appointment对象进行添加
判断是否存在重复主题:
AppointmentCollection appts = outlooksession.Appointments.Items.Restrict(String.Format("[Subject] = \"{0}\"", apptSubject));
。。。 。。。
Appointment appointment = new Appointment();
appointment.Subject = apptSubject;
appointment.AllDayEvent = true;
// Setup a yearly recurrence
appointment.RecurrencePattern.RecurrenceType = RecurrenceType.Yearly;
appointment.RecurrencePattern.MonthOfYear = (Month)bDay.Month;
appointment.RecurrencePattern.DayOfMonth = bDay.Day;
//This would fill the RecurrencePatternStartDate too.
appointment.Start = DateTime.Today;
appointment.ReminderMinutesBeforeStart = 120;
outlooksession.Appointments.Items.Add(appointment);
ps:
1. DateTime..::.FromFileTimeUtc 方法: 将指定的 Windows 文件时间转换为等效的 UTC 时间。
Windows 文件时间是一个 64 位值,它表示自协调世界时 (UTC) 公元 (C.E.) 1601 年 1 月 1 日午夜 12:00 以来已经过的间隔数(以 100 纳秒为一个间隔)。Windows 使用文件时间记录应用程序创建、访问或写入文件的时间。
so:FromFileTimeUtc (0),返回的就是 1601 年 1 月 1 日午夜 12:00这一原点时间。
日期部分: invalidDate.Date.ToString("d", System.Globalization.DateTimeFormatInfo.CurrentInfo)
时间部分: invalidDate.TimeOfDay.ToString();
关于时间格式的。ToString()可以参考:http://msdn.microsoft.com/zh-cn/library/8tfzyc64.aspx
2.POOM 和 OutlookSession
POOM: 是基于微软COM技术的一套针对手机个人信息管理的COM接口库。通过它可以访问PocketOutlook中的所有服务,而访问这些服务都是从OutlookSession对象开始的。
关于POOM的详细介绍可以参考:
http://bbs.wince.cn/dv_rss.asp?s=xhtml&boardid=9&id=1829&page=1
OutlookSession:是取得PocketOutlook中所有信息的一个对象,通过它可以获得操作PocketOutlook所提供的所有操作。
需要添加对Microsoft.WindowsMobile.PocketOutlook.dll程序集的引用,并在code中使用Using引入这个命名空间。
.net Compact Framework中关于OutlookSession的相关内容可以参考
http://doc.itstrike.cn/Home/Article/.Net-Compact-Framework-Getting-Started-4
3. String.Formate(string ,object) ,其中string 参数用来指定格式,object是被转换的对象。
有关系统定义的 转换格式请参考:
-
有关 Format、AppendFormat 等方法以及 WriteLine 的某些重载所支持的复合格式设置功能的更多信息,请参见 复 合格式化。
-
有关数值格式说明符的更多信息,请参见 标 准数字格式字符串 和 自 定义数字格式字符串。
-
有关日期和时间格式说明符的更多信息,请参见 标 准 DateTime 格式字符串 和 自 定义 DateTime 格式字符串。
-
有关枚举格式说明符的更多信息,请参见 枚 举格式字符串。