Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices.WindowsRuntime;
- using System.Threading.Tasks;
- using Windows.Foundation;
- using Windows.Foundation.Collections;
- using Windows.Storage;
- using Windows.Storage.Pickers;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Controls.Primitives;
- using Windows.UI.Xaml.Data;
- using Windows.UI.Xaml.Input;
- using Windows.UI.Xaml.Media;
- using Windows.UI.Xaml.Navigation;
- // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
- namespace App2
- {
- public sealed partial class MainPage : Page
- {
- public MainPage()
- {
- this.InitializeComponent();
- }
- public async void WriteFile()
- {
- StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("ProgSchedule.txt");
- }
- #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
- public static async Task<string> ReadStringFromLocalFile(string filename, int actualLine)
- #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
- {
- // reads the contents of file 'filename' in the app's local storage folder and returns it as a string
- StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
- File.OpenRead(filename);
- string[] lines = File.ReadAllLines(filename);
- string returnline = lines[actualLine];
- return returnline;
- }
- #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
- public static async Task<string> DeleteLineFromFile(string filename, int actualLine)
- #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
- {
- // reads the contents of file 'filename' in the app's local storage folder and returns it as a string
- StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
- File.OpenWrite(filename);
- string[] lines = File.ReadAllLines(filename);
- var lineCount = File.ReadAllLines(@"ProgSchedule.txt").Length;
- for (int i = 0; i < lineCount; i++)
- {
- if (lines[i].Equals(lines[actualLine]))
- {
- lines[i] = null;
- break;
- }
- }
- File.WriteAllLines(filename, lines);
- return "okey dokey";
- }
- private ObservableCollection<string> _items = new ObservableCollection<string>();
- public ObservableCollection<string> Items
- {
- get { return this._items; }
- }
- protected override async void OnNavigatedTo(NavigationEventArgs e)
- {
- base.OnNavigatedTo(e);
- File.OpenRead((@"ProgSchedule.txt"));
- var lineCount = File.ReadAllLines(@"ProgSchedule.txt").Length;
- for (int x = 0; x < lineCount; x++)
- {
- string readline = await ReadStringFromLocalFile(@"ProgSchedule.txt", x);
- int idx = readline.LastIndexOf('|');
- string appName = readline.Substring(idx+1);
- Items.Add(appName);
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- }
- private void Button_Click_1(object sender, RoutedEventArgs e)
- {
- }
- private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- }
- private async void Button_Click_1Async(object sender, RoutedEventArgs e)
- {
- int linetodelete = itemListView.SelectedIndex;
- string process = await DeleteLineFromFile(@"ProgSchedule.txt", linetodelete);
- }
- private async void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- string readline = await ReadStringFromLocalFile(@"ProgSchedule.txt", itemListView.SelectedIndex);
- string[] appTime = readline.Split('"');
- TimeSpan systemTime = TimeSpan.Parse(appTime[1]);
- readline = readline.Substring(7);
- string[] splitString = readline.Split('|');
- bool ignore = false;
- bool restart = false;
- if (readline[0].Equals('1'))
- {
- ignore = true;
- }
- if (readline[0].Equals('0'))
- {
- ignore = false;
- }
- if (readline[2].Equals('1'))
- {
- restart = true;
- }
- if (readline[2].Equals('0'))
- {
- restart = false;
- }
- timePick.Time = systemTime;
- Path.Text = splitString[2];
- Name.Text = splitString[3];
- isIgnore.IsOn = ignore;
- isRestart.IsOn = restart;
- }
- private void isRestart_Toggled(object sender, RoutedEventArgs e)
- {
- }
- private void isIgnore_Toggled(object sender, RoutedEventArgs e)
- {
- }
- private void Button_Click_2(object sender, RoutedEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement