Advertisement
Guest User

Graysons App

a guest
Feb 18th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices.WindowsRuntime;
  8. using System.Threading.Tasks;
  9. using Windows.Foundation;
  10. using Windows.Foundation.Collections;
  11. using Windows.Storage;
  12. using Windows.Storage.Pickers;
  13. using Windows.UI.Xaml;
  14. using Windows.UI.Xaml.Controls;
  15. using Windows.UI.Xaml.Controls.Primitives;
  16. using Windows.UI.Xaml.Data;
  17. using Windows.UI.Xaml.Input;
  18. using Windows.UI.Xaml.Media;
  19. using Windows.UI.Xaml.Navigation;
  20.  
  21. // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
  22.  
  23. namespace App2
  24. {
  25.     public sealed partial class MainPage : Page
  26.     {
  27.         public MainPage()
  28.         {
  29.             this.InitializeComponent();
  30.         }
  31.  
  32.         public async void WriteFile()
  33.         {
  34.             StorageFile file = await Windows.Storage.DownloadsFolder.CreateFileAsync("ProgSchedule.txt");
  35.         }
  36.  
  37. #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
  38.         public static async Task<string> ReadStringFromLocalFile(string filename, int actualLine)
  39. #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
  40.         {
  41.             // reads the contents of file 'filename' in the app's local storage folder and returns it as a string
  42.             StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
  43.             File.OpenRead(filename);
  44.             string[] lines = File.ReadAllLines(filename);
  45.             string returnline = lines[actualLine];
  46.             return returnline;
  47.         }
  48.  
  49. #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
  50.         public static async Task<string> DeleteLineFromFile(string filename, int actualLine)
  51. #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
  52.         {
  53.             // reads the contents of file 'filename' in the app's local storage folder and returns it as a string
  54.             StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
  55.             File.OpenWrite(filename);
  56.             string[] lines = File.ReadAllLines(filename);
  57.             var lineCount = File.ReadAllLines(@"ProgSchedule.txt").Length;
  58.             for (int i = 0; i < lineCount; i++)
  59.             {
  60.                 if (lines[i].Equals(lines[actualLine]))
  61.                 {
  62.                     lines[i] = null;
  63.                     break;
  64.                 }
  65.             }
  66.             File.WriteAllLines(filename, lines);
  67.             return "okey dokey";
  68.         }
  69.  
  70.         private ObservableCollection<string> _items = new ObservableCollection<string>();
  71.  
  72.         public ObservableCollection<string> Items
  73.         {
  74.             get { return this._items; }
  75.         }
  76.  
  77.         protected override async void OnNavigatedTo(NavigationEventArgs e)
  78.         {
  79.             base.OnNavigatedTo(e);
  80.             File.OpenRead((@"ProgSchedule.txt"));
  81.             var lineCount = File.ReadAllLines(@"ProgSchedule.txt").Length;
  82.             for (int x = 0; x < lineCount; x++)
  83.             {
  84.                 string readline = await ReadStringFromLocalFile(@"ProgSchedule.txt", x);
  85.                 int idx = readline.LastIndexOf('|');
  86.                 string appName = readline.Substring(idx+1);
  87.                 Items.Add(appName);
  88.             }
  89.         }
  90.  
  91.  
  92.         private void Button_Click(object sender, RoutedEventArgs e)
  93.         {
  94.  
  95.         }
  96.  
  97.         private void Button_Click_1(object sender, RoutedEventArgs e)
  98.         {
  99.  
  100.         }
  101.  
  102.         private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
  103.         {
  104.  
  105.         }
  106.  
  107.         private async void Button_Click_1Async(object sender, RoutedEventArgs e)
  108.         {
  109.             int linetodelete = itemListView.SelectedIndex;
  110.             string process = await DeleteLineFromFile(@"ProgSchedule.txt", linetodelete);
  111.         }
  112.  
  113.         private async void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
  114.         {
  115.             string readline = await ReadStringFromLocalFile(@"ProgSchedule.txt", itemListView.SelectedIndex);
  116.             string[] appTime = readline.Split('"');
  117.             TimeSpan systemTime = TimeSpan.Parse(appTime[1]);
  118.             readline = readline.Substring(7);
  119.             string[] splitString = readline.Split('|');
  120.             bool ignore = false;
  121.             bool restart = false;
  122.             if (readline[0].Equals('1'))
  123.             {
  124.                 ignore = true;
  125.             }
  126.             if (readline[0].Equals('0'))
  127.             {
  128.                 ignore = false;
  129.             }
  130.             if (readline[2].Equals('1'))
  131.             {
  132.                 restart = true;
  133.             }
  134.             if (readline[2].Equals('0'))
  135.             {
  136.                 restart = false;
  137.             }
  138.             timePick.Time = systemTime;
  139.             Path.Text = splitString[2];
  140.             Name.Text = splitString[3];
  141.             isIgnore.IsOn = ignore;
  142.             isRestart.IsOn = restart;
  143.         }
  144.  
  145.         private void isRestart_Toggled(object sender, RoutedEventArgs e)
  146.         {
  147.  
  148.         }
  149.  
  150.         private void isIgnore_Toggled(object sender, RoutedEventArgs e)
  151.         {
  152.  
  153.         }
  154.  
  155.         private void Button_Click_2(object sender, RoutedEventArgs e)
  156.         {
  157.  
  158.         }
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement