PnnK

buggedForm

Mar 28th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using Newtonsoft.Json;
  9. using RepClasses;
  10.  
  11. namespace MainForm
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         static public List<Student> students = new List<Student>();
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void AddStudent_Click(object sender, EventArgs e)
  22.         {
  23.             var addWindow = new Form2();
  24.             addWindow.Show();
  25.         }
  26.  
  27.         private void start_Click(object sender, EventArgs e)
  28.         {
  29.             students.Clear();
  30.             if (File.Exists(@"C:\Users\thisp\Desktop\Tutoring\RepsProg\studentsData.txt"))
  31.             {
  32.                 List<Student> list = JsonConvert.DeserializeObject
  33.                     <List<Student>>(File.ReadAllText
  34.                     (@"C:\Users\thisp\Desktop\Tutoring\RepsProg\studentsData.txt"));
  35.                 foreach (Student jo in list)
  36.                 {
  37.                     students.Add(jo);
  38.                 }
  39.             }
  40.             else
  41.                 File.Create(@"C:\Users\thisp\Desktop\Tutoring\RepsProg\studentsData.txt");
  42.         }
  43.  
  44.         private void finish_Click(object sender, EventArgs e)
  45.         {
  46.             List<Student> list = new List<Student>();
  47.             foreach (Student jo in students)
  48.             {
  49.                 list.Add(jo);
  50.             }
  51.             string json = JsonConvert.SerializeObject(list, Formatting.Indented);
  52.             File.WriteAllText
  53.                 (@"C:\Users\thisp\Desktop\Tutoring\RepsProg\studentsData.txt", json);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment