private void buttonConfigureGoogleCalendar_Click(object sender, EventArgs e) { SettigsEmailWindow SEW = new SettigsEmailWindow(); SEW.BackColor = Color.SteelBlue; SEW.Show(); }
private void SaveButton_Click(object sender, EventArgs e) { if (File.Exists(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\myID.setting") == false) { ///OPEN WINDOW WITH CALENDAR CONFIGURATION AND SET STRING myID AddEventMassagebox message = new AddEventMassagebox(); message.Text = "Please configure calendar and try again!"; message.Show(); ///OPEN CONFIGURE SCREEN SettigsEmailWindow SEW = new SettigsEmailWindow(); SEW.Show(); this.Hide(); return; } if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxLocation.Text) || string.IsNullOrWhiteSpace(DescriptionBox.Text)) { AddEventMassagebox message = new AddEventMassagebox(); message.Text = "Please fill all the positions!"; message.Show(); } else { TextReader setid = new StreamReader(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\myID.setting"); string curID = setid.ReadLine(); string curSecret = setid.ReadLine(); string curProID = setid.ReadLine(); string curMail = setid.ReadLine(); setid.Close(); TextWriter credentials = new StreamWriter("credentials.json"); /// change project id and maybe client secret credentials.WriteLine("{\"installed\":{\"client_id\":\"" + curID + "\",\"project_id\":\"" + curProID + "\",\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"token_uri\":\"https://oauth2.googleapis.com/token\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\",\"client_secret\":\"" + curSecret + "\",\"redirect_uris\":[\"urn:ietf:wg:oauth:2.0:oob\",\"http://localhost\"]}}"); credentials.Close(); string[] Scopes = { CalendarService.Scope.Calendar }; string ApplicationName = "MyCalendar Google Calendar API"; UserCredential credential; using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; } // Create Google Calendar API service. var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); string month = MonthBox.Text; Dictionary <string, int> Months = new Dictionary <string, int>(); Months.Add("January", 1); Months.Add("February", 2); Months.Add("March", 3); Months.Add("April", 4); Months.Add("May", 5); Months.Add("June", 6); Months.Add("July", 7); Months.Add("August", 8); Months.Add("September", 9); Months.Add("October", 10); Months.Add("November", 11); Months.Add("December", 12); int M = Months[month]; int Hourint = Convert.ToInt32(HourBox.Text); int Minint = Convert.ToInt32(MinBox.Text); string month1 = MonthBox1.Text; Dictionary <string, int> Months1 = new Dictionary <string, int>(); Months1.Add("January", 1); Months1.Add("February", 2); Months1.Add("March", 3); Months1.Add("April", 4); Months1.Add("May", 5); Months1.Add("June", 6); Months1.Add("July", 7); Months1.Add("August", 8); Months1.Add("September", 9); Months1.Add("October", 10); Months1.Add("November", 11); Months1.Add("December", 12); int MM = Months1[month1]; int Hourint1 = Convert.ToInt32(HourBox1.Text); int Minint1 = Convert.ToInt32(MinBox1.Text); int RemindTime = 0; ChangeReminder(); void ChangeReminder() { if (Convert.ToBoolean(checkBoxReminder.CheckState = CheckState.Checked)) { RemindTime = 10; } } Event newEvent = new Event() { ///Id = Convert.ToString(yearBox.Text + MonthBox.Text + DayBox.Text), Summary = textBoxName.Text, Location = textBoxLocation.Text, Description = DescriptionBox.Text, Start = new EventDateTime() { DateTime = DateTime.Parse(yearBox.Text + "-" + M.ToString("D2") + "-" + DayBox.Text + "T" + Hourint.ToString("D2") + ":" + Minint.ToString("D2") + ":00-07:00"), TimeZone = "Europe/Warsaw", }, End = new EventDateTime() { DateTime = DateTime.Parse(yearBox1.Text + "-" + MM.ToString("D2") + "-" + DayBox1.Text + "T" + Hourint1.ToString("D2") + ":" + Minint1.ToString("D2") + ":00-07:00"), TimeZone = "Europe/Warsaw", }, Attendees = new EventAttendee[] { new EventAttendee() { Organizer = true, Email = curMail, ResponseStatus = "accepted" }, /// automaticly confirmed }, Reminders = new Event.RemindersData() { UseDefault = false, Overrides = new EventReminder[] { new EventReminder() { Method = "sms", Minutes = RemindTime }, } } }; String calendarId = "primary"; EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId); Event createdEvent = request.Execute(); /// CREATE NOTE WITH SAVED EVENT TextWriter eventnote = new StreamWriter(yearBox.Text + MonthBox.Text + DayBox.Text + HourBox.Text + MinBox.Text + ".mevent"); eventnote.WriteLine("E"); eventnote.WriteLine(yearBox.Text); eventnote.WriteLine(MonthBox.Text); eventnote.WriteLine(DayBox.Text); eventnote.WriteLine(HourBox.Text + ":" + MinBox.Text); eventnote.WriteLine(yearBox1.Text + "/" + MonthBox1.Text + "/" + DayBox1.Text + " " + HourBox1.Text + ":" + MinBox1.Text); if (checkBoxReminder.CheckState == CheckState.Checked) { eventnote.WriteLine("yes"); } else { eventnote.WriteLine("no"); } eventnote.WriteLine(textBoxName.Text); eventnote.WriteLine(textBoxLocation.Text); ///ADDING DESCRIPTION WITH MULTILINES for (int i = 0; i < DescriptionBox.Lines.Length; i++) { eventnote.WriteLine(DescriptionBox.Lines[i] + "\n"); } eventnote.Close(); AddEventMassagebox Message = new AddEventMassagebox(); Message.Text = "Event Added!"; Message.Show(); } }