예제 #1
0
파일: student.cs 프로젝트: groshik/curs
        static public void Save()
        {
            User selUser = Program.SelectUser;

            Program.SelectUser = null;
            string path          = Path.Combine(Directory.GetCurrentDirectory(), "data\\students.hav");
            string directoryPath = Path.Combine(Directory.GetCurrentDirectory(), "data");

            if (!File.Exists(path))
            {
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                FileStream fs = File.Create(path);
                fs.Close();
            }
            StudentCollection studentCollection = new StudentCollection
            {
                Students = Items ?? new List <Student>()
            };
            string   JSONString = JsonConvert.SerializeObject(studentCollection);
            FileRead JSONRead   = new FileRead();

            JSONRead.SaveJSONString(path, JSONString);
            Program.SelectUser = selUser;
        }
예제 #2
0
파일: student.cs 프로젝트: groshik/curs
        static public void Load()
        {
            User selUser = Program.SelectUser;

            Program.SelectUser = null;
            string path = Path.Combine(Directory.GetCurrentDirectory(), "data\\students.hav");

            if (File.Exists(path))
            {
                string   JSONString;
                FileRead JSONRead = new FileRead();

                JSONString = JSONRead.GetJSONString(path);
                StudentCollection studentCollection = JsonConvert.DeserializeObject <StudentCollection>(JSONString);
                Items = studentCollection.Students;
                Items.ForEach(student =>
                {
                    student.ChangeDataEvent += () =>
                    {
                        ChangeDataInListEvent?.Invoke();
                    };
                });
            }
            else
            {
                Save();
                Load();
            }
            Program.SelectUser = selUser;
        }