Ejemplo n.º 1
0
        private void btnSubjectsDeserialize_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Inserting a new file will delete all the old data from the Database", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "JSON | *.json";
            openFileDialog.Title  = "Select JSON file";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                var            jsonFile = File.ReadAllText(openFileDialog.FileName);
                List <Subject> subjects = new List <Subject>();
                subjects = JsonConvert.DeserializeObject <List <Subject> >(jsonFile);

                try
                {
                    interpretor.DeleteSubjects();
                    Console.WriteLine(subjects.Count.ToString());
                    foreach (Subject subject in subjects)
                    {
                        interpretor.AddSubject(subject, null);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                btnSubjectsShow.PerformClick();
            }
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (tbName.Text.Length == 0 && tbCredits.Text.Length == 0)
            {
                return;
            }

            Subject subject = new Subject(tbName.Text, Int32.Parse(tbCredits.Text));

            interpretor.AddSubject(subject, subjects);
            ClearAdd();
            DisplaySubjects();
        }