protected void deleteEventsButtons_Click(object sender, EventArgs e)
 {
     Label deleteEventsLabel = new Label();
     if (deleteCalendarIdTextBox.Text == "" || eventTextBox.Text == "")
     {
         deleteEventsLabel.Text = "You have to enter data";
     }
     else
     {
         string Cid = deleteCalendarIdTextBox.Text;
         string Eid = eventTextBox.Text;
         string method = "delete";
         string type = "events";
         string token_type = Convert.ToString(Session["token_type"]);
         string access_token = Convert.ToString(Session["access_token"]);
         Dictionary<string, string> parameters = new Dictionary<string, string>();
         parameters.Add("calendarId", Cid);
         parameters.Add("eventId", Eid);
         googleCalendarAPI calendarAPI = new googleCalendarAPI(method, type, parameters, token_type, access_token);
         string result = calendarAPI.json;
         if (result.Equals("error"))
         {
             deleteEventsLabel.Text = "error";
             deleteEvents.Controls.Add(deleteEventsLabel);
             return;
         }
         deleteEventsLabel.Text = "You already delete envent";
     }
     deleteEvents.Controls.Add(deleteEventsLabel);
 }
 protected void insertEventsButton_Click(object sender, EventArgs e)
 {
     Label insertEventsLabel = new Label();
     if (idTextBox.Text == "" || summaryTextBox.Text == "" || descriptionTextBox.Text == "" || startTextBox.Text == "" || endTextBox.Text == "")
     {
         insertEventsLabel.Text = "You have to enter data";
     }
     else
     {
         string calendarId = idTextBox.Text;
         string method = "insert";
         string type = "events";
         string token_type = Convert.ToString(Session["token_type"]);
         string access_token = Convert.ToString(Session["access_token"]);
         GoogleCalendarEvent actEvent = new GoogleCalendarEvent
         {
             summary = summaryTextBox.Text,
             description = descriptionTextBox.Text,
             start = new GoogleCalendarEventTime(Convert.ToDateTime(startTextBox.Text)),
             end = new GoogleCalendarEventTime(Convert.ToDateTime(endTextBox.Text))
         };
         ASCIIEncoding encoding = new ASCIIEncoding();
         string data = JsonConvert.SerializeObject(actEvent);
         Dictionary<string, string> parameters = new Dictionary<string, string>();
         parameters.Add("calendarId", calendarId);
         googleCalendarAPI calendarAPI = new googleCalendarAPI(method, type, parameters, data, token_type, access_token);
         string result = calendarAPI.json;
         if (result.Equals("error"))
         {
             insertEventsLabel.Text = "error";
             insertEvents.Controls.Add(insertEventsLabel);
             return;
         }
         insertEventsLabel.Text = "You already insert envent";
     }
     insertEvents.Controls.Add(insertEventsLabel);
 }
    protected void listCalendarListButton_Click(object sender, EventArgs e)
    {
        string method = "list";
        string type = "calendarList";
        string token_type = Convert.ToString(Session["token_type"]);
        string access_token = Convert.ToString(Session["access_token"]);
        Label listCalendarListLabel = new Label();
        googleCalendarAPI calendarAPI = new googleCalendarAPI(method, type, token_type, access_token);
        string result = calendarAPI.json;
        if (result.Equals("error"))
        {
            listCalendarListLabel.Text = "error";
            listCalendarList.Controls.Add(listCalendarListLabel);
            return;
        }
        GoogleCalendarList calendarList = JsonConvert.DeserializeObject<GoogleCalendarList>(result);

        GridView calendarListGridView = new GridView();
        DataTable list = new DataTable();
        list.Columns.Add("Id");
        list.Columns.Add("Summary");
        for(int i = 0; i < calendarList.Items.Count; i++)
        {
            list.Rows.Add(calendarList.Items[i].ID, calendarList.Items[i].Summary);
        }
        calendarListGridView.DataSource = list;
        calendarListGridView.DataBind();

        listCalendarListLabel.Text = "calendar list is get below";

        listCalendarList.Controls.Add(listCalendarListLabel);
        listCalendarList.Controls.Add(calendarListGridView);
    }
    protected void listEventsButton_Click(object sender, EventArgs e)
    {
        Label listEventsLabel = new Label();
        if (calendarIdTextBox.Text == "")
        {
            listEventsLabel.Text = "You haven't enter id yet";
        }
        else
        {
            string calendarId = calendarIdTextBox.Text;
            string method = "list";
            string type = "events";
            string token_type = Convert.ToString(Session["token_type"]);
            string access_token = Convert.ToString(Session["access_token"]);
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("calendarId", calendarId);
            googleCalendarAPI calendarAPI = new googleCalendarAPI(method, type, parameters, token_type, access_token);
            string result = calendarAPI.json;
            if (result.Equals("error"))
            {
                listEventsLabel.Text = "error";
                listEvents.Controls.Add(listEventsLabel);
                return;
            }
            GoogleCalendarEventList EventList = JsonConvert.DeserializeObject<GoogleCalendarEventList>(result);
            listEventsLabel.Text = EventList.Summary + "'s evennts list above";

            GridView EventListGridView = new GridView();
            DataTable list = new DataTable();
            list.Columns.Add("Id");
            list.Columns.Add("Summary");
            list.Columns.Add("Description");
            list.Columns.Add("Start");
            list.Columns.Add("End");
            for (int i = 0; i < EventList.Items.Count; i++)
            {
                DateTime start = EventList.Items[i].start.date;
                DateTime end = EventList.Items[i].end.date;
                if (EventList.Items[i].start.date.Year == 1)
                {
                    start = EventList.Items[i].start.dateTime;
                    end = EventList.Items[i].end.dateTime;
                }
                list.Rows.Add(EventList.Items[i].id, EventList.Items[i].summary, EventList.Items[i].description, start, end);
            }
            EventListGridView.DataSource = list;
            EventListGridView.DataBind();
            listEvents.Controls.Add(EventListGridView);
        }
        listEvents.Controls.Add(listEventsLabel);
    }