Windows Mobile 5.0 SDk Demo 分析 ——1 BirthdayToCalendar

功能:
    将每个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是被转换的对象。

      有关系统定义的 转换格式请参考:


 

 

 

 

转载于:https://www.cnblogs.com/wanghuijunshiwo/archive/2010/02/04/1663518.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值