Exemplo n.º 1
0
        private void Add()
        {
            var context = new TeacherVM(departments.ToArray());
            var wind    = new NewTeacher()
            {
                DataContext = context
            };

            wind.ShowDialog();
            if (wind.DialogResult == true)
            {
                bool res = false;
                if (context.Teacher != null)
                {
                    res = RequestToDataBase.Instance.requestInsertIntoTeacher(context.Teacher);
                }
                if (context.Teacher.DepartmentTwo != null && context.Teacher.PostTwo != null)
                {
                    res = RequestToDataBase.Instance.requestInsertIntoTeacherDepartmentTwo(context.Teacher) || res;
                }
                if (res)
                {
                    ClassTeacher.Clear();
                    foreach (var value in RequestToDataBase.Instance.ReadTeachers())
                    {
                        ClassTeacher.Add(value);
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void Remove()
 {
     if (Index >= 0)
     {
         var teacher = ClassTeacher[Index];
         var list    = new List <int>();
         var element = ClassTeacher.Where(c => c.CodeOfTeacher == teacher.CodeOfTeacher).Select(t => t.CodeOfTeacher);
         foreach (var item in element)
         {
             list.Add(item);
         }
         if (list.Count == 2)
         {
             if (RequestToDataBase.Instance.requestDeleteFromTeacherAndDepartments(ClassTeacher, Index))
             {
                 ClassTeacher.Clear();
                 foreach (var value in RequestToDataBase.Instance.ReadTeachers())
                 {
                     ClassTeacher.Add(value);
                 }
             }
         }
         else
         {
             if (RequestToDataBase.Instance.requestDeleteFromTeacher(ClassTeacher, Index))
             {
                 ClassTeacher.Clear();
                 foreach (var value in RequestToDataBase.Instance.ReadTeachers())
                 {
                     ClassTeacher.Add(value);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        private void Load()
        {
            string         pathToCsv      = "";
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Файл csv|*.csv";
            if (openFileDialog.ShowDialog() == true)
            {
                pathToCsv = openFileDialog.FileName;
            }
            if (File.Exists(pathToCsv))
            {
                char[] delimiters = new char[] { ';' };
                using (StreamReader reader = new StreamReader(pathToCsv, System.Text.Encoding.Default))
                {
                    while (true)
                    {
                        string line = reader.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        string[] parts = line.Split(delimiters);
                        bool     exist = false;
                        foreach (var teacher in ClassTeacher)
                        {
                            if (teacher.FIO.Equals(parts[0].Trim(' ')) && (teacher.Department.NameOfDepartment.Equals(parts[4].Trim(' '))))
                            {
                                exist = true;
                            }
                        }
                        if (!exist)
                        {
                            Department Department = null;
                            foreach (var dep in departments)
                            {
                                if (dep.NameOfDepartment.Equals(parts[4].Trim(' ')))
                                {
                                    Department = dep;
                                }
                            }
                            if (Department != null)
                            {
                                Teacher teacher = new Teacher
                                {
                                    FIO           = parts[0].Trim(' '),
                                    Post          = parts[1].Trim(' '),
                                    Mail          = parts[2].Trim(' '),
                                    IsReadLecture = Convert.ToBoolean(parts[3]),
                                    Department    = Department
                                };

                                if (RequestToDataBase.Instance.requestInsertIntoTeacher(teacher))
                                {
                                    ClassTeacher.Add(teacher);
                                }

                                if (parts.Length == 6)
                                {
                                    Department DepartmentTwo = null;
                                    foreach (var dep in departments)
                                    {
                                        if (dep.NameOfDepartment.Equals(parts[5].Trim(' ')))
                                        {
                                            DepartmentTwo = dep;
                                        }
                                    }
                                    if (DepartmentTwo != null)
                                    {
                                        teacher.DepartmentTwo = DepartmentTwo;
                                        if (RequestToDataBase.Instance.requestInsertIntoTeacherDepartmentTwo(teacher))
                                        {
                                            ClassTeacher.Clear();
                                            foreach (var value in RequestToDataBase.Instance.ReadTeachers())
                                            {
                                                ClassTeacher.Add(value);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }