google calendar C# window application sample(根据google代码改造)

原创 2006年05月25日 10:05:00

google calendar C# window application sample(根据google代码改造)

1.饮用 google calendar dll

2.create a new form named Form1;

3.add three textbox in this form, one for username, one for password, one for message(多行);

4.add a button in this form;

5.copy code .

 

#define USE_TRACING
#define DEBUG

using System;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Net;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Calendar;
using System.Drawing;
using System.Collections;
using System.ComponentModel;

namespace GoogleCalendarTest_HYC
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.TextBox UserName;
  private System.Windows.Forms.TextBox PassWord;
  private System.Windows.Forms.TextBox CalendarContent;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Button button1;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.CalendarContent = new System.Windows.Forms.TextBox();
   this.UserName = new System.Windows.Forms.TextBox();
   this.PassWord = new System.Windows.Forms.TextBox();
   this.label1 = new System.Windows.Forms.Label();
   this.label2 = new System.Windows.Forms.Label();
   this.button1 = new System.Windows.Forms.Button();
   this.SuspendLayout();
   //
   // CalendarContent
   //
   this.CalendarContent.Location = new System.Drawing.Point(24, 72);
   this.CalendarContent.Multiline = true;
   this.CalendarContent.Name = "CalendarContent";
   this.CalendarContent.Size = new System.Drawing.Size(720, 424);
   this.CalendarContent.TabIndex = 0;
   this.CalendarContent.Text = "";
   //
   // UserName
   //
   this.UserName.Location = new System.Drawing.Point(178, 24);
   this.UserName.Name = "UserName";
   this.UserName.TabIndex = 1;
   this.UserName.Text = "@gmail.com";
   //
   // PassWord
   //
   this.PassWord.Location = new System.Drawing.Point(378, 24);
   this.PassWord.Name = "PassWord";
   this.PassWord.PasswordChar = '*';
   this.PassWord.TabIndex = 2;
   this.PassWord.Text = "";
   //
   // label1
   //
   this.label1.Location = new System.Drawing.Point(96, 24);
   this.label1.Name = "label1";
   this.label1.Size = new System.Drawing.Size(64, 23);
   this.label1.TabIndex = 3;
   this.label1.Text = "Username:";
   //
   // label2
   //
   this.label2.Location = new System.Drawing.Point(296, 24);
   this.label2.Name = "label2";
   this.label2.Size = new System.Drawing.Size(64, 23);
   this.label2.TabIndex = 4;
   this.label2.Text = "Password:";
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(496, 24);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(136, 23);
   this.button1.TabIndex = 5;
   this.button1.Text = "Show Your Calendar";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(776, 509);
   this.Controls.Add(this.button1);
   this.Controls.Add(this.label2);
   this.Controls.Add(this.label1);
   this.Controls.Add(this.PassWord);
   this.Controls.Add(this.UserName);
   this.Controls.Add(this.CalendarContent);
   this.Name = "Form1";
   this.Text = "GoogleCalendar";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.ResumeLayout(false);

  }
  #endregion

  public const string ApplicationName = "GoogleCalendar/1.0.0"; 
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {

  }

  private void button1_Click(object sender, System.EventArgs e)
  {
   try
   {
    //
    // TODO: Add code to start application here
    //
    if(this.UserName.Text=="")
    {
     CalendarContent.Text ="Please input your username.";
     return;
    }
    if(this.PassWord.Text=="")
    {
     CalendarContent.Text ="Please input your password.";
     return;
    }
           
    string calendarURI = "http://www.google.com/calendar/feeds/"+this.UserName.Text +"/private/full";
    string userName = this.UserName.Text ;
    string passWord = this.PassWord.Text ;
           
    FeedQuery query = new FeedQuery();
    CalendarService service = new CalendarService(ApplicationName);
         
           
    if (userName != null)
    {
     service.setUserCredentials(userName, passWord);
    }
           
    GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory) service.RequestFactory;
    // temporary measure
    factory.MethodOverride = true;
           
    query.Uri = new Uri(calendarURI);
           
    EventFeed calFeed = service.Query(query);
    if (calFeed.Location != null)
    {
     CalendarContent.Text =CalendarContent.Text+"Feed Location: " + calFeed.Location.ValueString;
    }
    CalendarContent.Text =CalendarContent.Text+"User Agent: " + factory.UserAgent;

    foreach (EventEntry feedEntry in calFeed.Entries )
    {
     CalendarContent.Text =CalendarContent.Text+"";
     CalendarContent.Text =CalendarContent.Text+"Appointment: " + feedEntry.Title.Text;
     foreach (When when in feedEntry.Times)
     {
      CalendarContent.Text =CalendarContent.Text+"When: " + when.StartTime + " " + when.EndTime + " " + when.ValueString;
     }
     foreach (Where where in feedEntry.Locations)
     {
      CalendarContent.Text =CalendarContent.Text+"Where: " + where.Rel + " " + where.Label + " " + where.ValueString;
     }
     foreach (Who who in feedEntry.Participants)
     {
      CalendarContent.Text =CalendarContent.Text+"Who: " + who.Rel + " " + who.ValueString;
      if (who.Attendee_Status != null)
       CalendarContent.Text =CalendarContent.Text+"Who Status: " + who.Attendee_Status.Value;

      if (who.Attendee_Type != null)
       CalendarContent.Text =CalendarContent.Text+"Who Type: " + who.Attendee_Type.Value;
     }

     if (feedEntry.EventVisibility != null)
      CalendarContent.Text =CalendarContent.Text+"Visibility: " + feedEntry.EventVisibility.Value;

     if (feedEntry.EventTransparency != null)
      CalendarContent.Text =CalendarContent.Text+"Transparency: " + feedEntry.EventTransparency.Value;

     if (feedEntry.Status != null)
      CalendarContent.Text =CalendarContent.Text+"Status: " + feedEntry.Status.Value;

     if (feedEntry.Recurrence != null)
      CalendarContent.Text =CalendarContent.Text+"Recurrence: " + feedEntry.Recurrence.Value;

     if (feedEntry.Comments != null)
      CalendarContent.Text =CalendarContent.Text+"Comments: " + feedEntry.Comments.FeedLink.Href;

     if (feedEntry.OriginalEvent != null)
     {
      CalendarContent.Text =CalendarContent.Text+"OriginalEvent - ID: " + feedEntry.OriginalEvent.IdOriginal;
      CalendarContent.Text =CalendarContent.Text+"OriginalEvent - Href: " + feedEntry.OriginalEvent.Href;
      CalendarContent.Text =CalendarContent.Text+"OriginalEvent - startTime: " + feedEntry.OriginalEvent.OriginalStartTime.StartTime;
     }

     if (feedEntry.Reminder != null)
     {
      if (feedEntry.Reminder.Days > 0)
       CalendarContent.Text =CalendarContent.Text+"Reminder - Days: " + feedEntry.Reminder.Days.ToString();
      if (feedEntry.Reminder.Hours > 0)
       CalendarContent.Text =CalendarContent.Text+"Reminder - Hours: " + feedEntry.Reminder.Hours.ToString();
      if (feedEntry.Reminder.Minutes > 0)
       CalendarContent.Text =CalendarContent.Text+"Reminder - Minutes: " + feedEntry.Reminder.Minutes.ToString();
      if (feedEntry.Reminder.AbsoluteTime != new DateTime(1,1,1))
       CalendarContent.Text =CalendarContent.Text+"Reminder - AbsoluteTime: " + feedEntry.Reminder.AbsoluteTime;
     }
    }

    XmlTextWriter writer = new XmlTextWriter("calendar.xml", null);
    writer.Formatting = Formatting.Indented;
    writer.WriteStartDocument(false);
    if (calFeed != null)
    {
     calFeed.SaveToXml(writer);
    }
    writer.Flush();
    writer.Close();
   }
   catch
   {
    MessageBox.Show ("Error!");
   }
  }
 }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

C#调用google earth 参考代码4

1)增加鼠标滚轮支持,可以实现放大、缩小。此功能利用上一篇提供的HookAPI.dll实现 2)读取PlaceMarks(Google Earth界面中的位置)并显示、隐藏 ...

C#调用google earth 参考代码2

展示如何调用Windows API将GoogleEarth的界面隐藏掉,并将GoogleEarth的地图显示在自定义的窗体上。废话少说,直接上代码。 : // 功能:GE实例(二) 2:...

Google Calendar Sync

  • 2011-03-03 09:28
  • 685KB
  • 下载

Google Sample MVP Android架构蓝图

Google Sample MVPAndroid架构蓝图目前Android主流的开发架构:原生开发(MVC),MVP,MVVM等 今天简单的说一下我对于Android架构的了解和对Google MV...

google calendar sync 0.9.4.1版

  • 2013-04-24 00:13
  • 1.11MB
  • 下载

cas源码改造-添加验证码(com.google.code.kaptcha)

下载的cas源码中有很多模块,只有cas-server-core,cas-server-webapp 工程是需要的,其它的都是一些插件根据需求使用,使用源码构建自己的工程。 父工程的打包插件使用i...

Tea Google Calendar

  • 2007-05-24 21:16
  • 103KB
  • 下载

google calendar 农历生日提醒

  • 2012-10-16 22:31
  • 1.09MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)