Exemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrWhiteSpace(tbName.Text))
            {
                string  teacherString = tbName.Text;
                Teacher teacher       = new Teacher(teacherString);

                try
                {
                    interpretor.AddTeacher(teacher, teachers);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                LoadTeachers();
                Reload();
                Display();
                return;
            }

            try
            {
                string   roomName    = lbRoom.SelectedItem.ToString();
                string   subjectName = lbSubject.SelectedItem.ToString();
                string   teacherName = lbTeacher.SelectedItem.ToString();
                DateTime date        = DateTime.ParseExact(tbDate.Text, "M/d/yyyy", CultureInfo.CurrentCulture);

                Lecture lecture = new Lecture(teacherName, subjectName, roomName, date);
                try
                {
                    interpretor.AddLecture(lecture, lectures);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                CancelSelection();

                LoadTeachers();
                Reload();
                Display();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnTeachersDeserialize_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 <Teacher> teachers = new List <Teacher>();
                teachers = JsonConvert.DeserializeObject <List <Teacher> >(jsonFile);

                try
                {
                    interpretor.DeleteRooms();
                    foreach (Teacher teacher in teachers)
                    {
                        interpretor.AddTeacher(teacher, null);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                btnRoomsShow.PerformClick();
            }


            btnTeachersShow.PerformClick();
        }