void readSheetData() { var range = $"A:E"; var request = service.Spreadsheets.Values.Get(SpreadsheetId, range); try { var response = request.Execute(); var values = response.Values; if (values != null && values.Count > 0) { foreach (var row in values) { string dateParsed = dateParse(row[1].ToString()); NewProject newProj = new NewProject(row[0].ToString(), dateParsed, row[2].ToString(), row[3].ToString(), row[4].ToString()); if (!pubProjList.Contains(newProj)) { pubProjList.Add(newProj); } } } } catch { MessageBox.Show("No internet connection :("); } }
//Saving & reading data (txt) bool SaveToTxt(NewProject newProj) { string dateParsed = dateParse(newProj.deadline); string desc = newProj.title + "|" + dateParsed + "|" + newProj.privacy + "|" + newProj.description + "|" + newProj.publicationDate; using (StreamWriter sw = new StreamWriter("data.txt", true)) { sw.WriteLine(desc); sw.Close(); } return(true); }
//Remove items void RemovePublicProject(NewProject selectedProj) { pubProjList.Remove(selectedProj); inProgressProjectsList.Remove(selectedProj.title); var range = $"!A1:E"; var requestBody = new ClearValuesRequest(); var deleteRequest = service.Spreadsheets.Values.Clear(requestBody, SpreadsheetId, range); deleteRequest.Execute(); ImportListToSheets(); }
void RemovePrivateProject(NewProject selectedProj) { privProjList.Remove(selectedProj); inProgressProjectsList.Remove(selectedProj.title); using (FileStream fs = new FileStream("data.txt", FileMode.Truncate)) { } using (StreamWriter sw = new StreamWriter("data.txt", true)) { foreach (NewProject newProj in privProjList) { string desc = newProj.title + "|" + newProj.deadline + "|" + newProj.privacy + "|" + newProj.description + "|" + newProj.publicationDate; sw.WriteLine(desc); } } }
internal void ReadData() { privProjList.Clear(); using (StreamReader sr = new StreamReader("data.txt")) { string line; while ((line = sr.ReadLine()) != null) { string[] par = line.Split('|'); NewProject newProj = new NewProject(par[0], par[1], par[2], par[3], par[4]); if (!privProjList.Contains(newProj)) { privProjList.Add(newProj); } } } }
void saveProjectToSheet(NewProject newProj) { var range = $"A:E"; var valueRange = new ValueRange(); var objectList = new List <object>() { newProj.title, newProj.deadline, newProj.privacy, newProj.description, newProj.publicationDate }; valueRange.Values = new List <IList <object> > { objectList }; var appendRequest = service.Spreadsheets.Values.Append(valueRange, SpreadsheetId, range); appendRequest.ValueInputOption = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.USERENTERED; var appendResponse = appendRequest.Execute(); }
//Add new item private void acceptBtn_Click(object sender, RoutedEventArgs e) { bool isActual = false; bool isAllData = false; isAllData = checkTextboxes(isAllData); if (isAllData == true) { string publicationDate = DateTime.Now.ToString("dd-MM-yyy").ToString(); DateTime?selectedDate = deadlineTxt.SelectedDate; string formatted = selectedDate.Value.ToString("dd-MM-yyy", System.Globalization.CultureInfo.InvariantCulture); NewProject newProj = new NewProject(titleTxt.Text, formatted, privacyCmb.Text, descriptionTxt.Text, publicationDate); if (privacyCmb.Text == "Public") { pubProjList.Add(newProj); publicList.ItemsSource = null; publicList.ItemsSource = pubProjList; saveProjectToSheet(newProj); DateTime actualDate = DateTime.Parse(date); DateTime deadlineDate = DateTime.Parse(deadlineTxt.SelectedDate.ToString()); isActual = checkDate(false, actualDate, deadlineDate); if (isActual == true) { inProgressProjectsList.Add(newProj.title); } else { } inProgressList.ItemsSource = null; inProgressList.ItemsSource = inProgressProjectsList; } else if (privacyCmb.Text == "Private") { privProjList.Add(newProj); privateList.ItemsSource = null; privateList.ItemsSource = privProjList; SaveToTxt(newProj); DateTime actualDate = DateTime.Parse(date); DateTime deadlineDate = DateTime.Parse(deadlineTxt.SelectedDate.ToString()); isActual = checkDate(false, actualDate, deadlineDate); if (isActual == true) { inProgressProjectsList.Add(newProj.title); } else { } inProgressList.ItemsSource = null; inProgressList.ItemsSource = inProgressProjectsList; } } else { MessageBox.Show("Fill all textboxes!"); } }