//write to journal async void JournalEntry(JournalEntry entry) { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; // create the file and append StorageFile journalFile; string fileText = ","; try { journalFile = await storageFolder.GetFileAsync("journal.txt"); fileText = await Windows.Storage.FileIO.ReadTextAsync(journalFile); } catch (Exception myE) { string message = myE.Message; journalFile = await storageFolder.CreateFileAsync("journal.txt"); } string jLine; jLine = entry.mood + "," + entry.activity + "," + entry.dateTime; //, lets me use split method easily await Windows.Storage.FileIO.WriteTextAsync(journalFile, fileText + jLine + System.Environment.NewLine); //test // tbTest.Text= tbTest.Text + jLine + System.Environment.NewLine; }
private void createJournalEntry() { JournalEntry entry = new JournalEntry(); int index = _moodList.FindIndex(item => item.name.Equals(mood)); //finds if any item in the mood list, has a property that equals the property specified entry.mood =_moodList[index].image; //if it does, it sets the image path as the image path defined in the list index = _activityList.FindIndex(item => item.name.Equals(activity)); entry.activity = _activityList[index].image; entry.dateTime = DateTime.Now; //add to list _previousEntries.Insert(0,entry); //adds it to the top JournalEntry(entry); //adds journal to entry file for storage updateJournal(); ptMain.SelectedIndex = 2; //moves to previous entries page }
void AddToJournal(String text) { char[] charSeperators = new char[] { ' ', ',' ,'\n'}; string[] words = text.Split(charSeperators,StringSplitOptions.RemoveEmptyEntries); //splits up based on , for(int i = 0; i < words.Length; i+=4) { //create a new entry if ((i + 4) < words.Length) { JournalEntry entry = new JournalEntry(); entry.mood = words[i]; entry.activity = words[i + 1]; string date = words[i + 2]+" "+words[i+3]; entry.dateTime = Convert.ToDateTime(date); _previousEntries.Add(entry); } } _previousEntries.Reverse(); //does this so it displays the most recent at the top }
private void Mood_Tapped(object sender, TappedRoutedEventArgs e) { Image curr = (Image)sender; //change text //show other grid gdMood.Visibility = Visibility.Collapsed; //sets the grid to not visible gdActivity.Visibility = Visibility.Visible; //raises the activity grid //get mood type //get activity type //get date //write to file JournalEntry entry = new JournalEntry(); //another class that stores journal entries mood = curr.Name; //curr.name "happy" //change text block ResourceCandidate r1 = ResourceManager.Current.MainResourceMap.GetValue("Resources/entryPageAlt", ResourceContext.GetForCurrentView()); //pulls from resource file tbMood.Text = r1.ValueAsString; }