public EditSmallWindow(ObjectType ot)
 {
     InitializeComponent();             //Конструктор окна в случае создания доп параметра системы
     deleteButton.IsEnabled = false;
     if (ot == ObjectType.EventType)
     {
         Title = "Создать достижение";
         EventType t = new EventType();
         currentObject = (Object)t;
     }
     else if (ot == ObjectType.StudentStatus)
     {
         Title = "Создать статус студента";
         StudentStatus t = new StudentStatus();
         currentObject = (Object)t;
     }
     else if (ot == ObjectType.GroupLevel)
     {
         Title = "Создать уровень группы";
         GroupLevel t = new GroupLevel();
         currentObject = (Object)t;
     }
     else if (ot == ObjectType.GroupType)
     {
         Title = "Создать тип группы";
         GroupType t = new GroupType();
         currentObject = (Object)t;
     }
     else
     {
         currentObject = null;
     }
 }
        private void InitializeData()         //Обнуление данных
        {
            Name       = "";
            Id         = -1;
            TeacherIds = new List <int>();
            StudentIds = new List <int>();
            RealHours  = -1;
            PlanHours  = -1;

            Color = new SolidColorBrush();
            Type  = new GroupType();
            Level = new GroupLevel();
        }
        /// <summary>
        /// Метод-обработчик эвента удаления расписания.
        /// Обрабатывает результат окна подтверждения.
        /// </summary>
        void DeleteWindow_CallBack(bool confirm)
        {
            if (confirm == false)
            {
                return;
            }
            if (currentObject is EventType)
            {
                EventType t  = (EventType)currentObject;
                int       id = t.Id;
                MTSystem.deleteEventType(t);

                List <Student> l = MTSystem.LoadStudentsWithAchievementId(id);
                if (l[0] != null)
                {
                    for (int i = 0; i < l.Count; i++)
                    {
                        l[i].deleteAchievement(l[i].findAchievementById(t.Id));
                        MTSystem.SaveStudent(l[i]);
                    }
                }

                if (MTSystem.DeleteEventType(id))
                {
                    MessageBox.Show("Удаление успешно");
                }
                SaveWindowDataEvent(ObjectType.EventType);
                Close();
            }
            else if (currentObject is StudentStatus)
            {
                StudentStatus t  = (StudentStatus)currentObject;
                int           id = t.Id;
                MTSystem.deleteStudentStatus(t);
                if (MTSystem.DeleteStudentStatus(id))
                {
                    MessageBox.Show("Удаление успешно");
                }
                SaveWindowDataEvent(ObjectType.StudentStatus);
                Close();
            }
            else if (currentObject is GroupLevel)
            {
                GroupLevel t  = (GroupLevel)currentObject;
                int        id = t.Id;
                MTSystem.deleteGroupLevel(t);
                if (MTSystem.DeleteGroupLevel(id))
                {
                    MessageBox.Show("Удаление успешно");
                }
                for (int i = 0; i < MTSystem.GroupsCount; i++)
                {
                    if (MTSystem.getGroup(i).Level.Id == id)
                    {
                        MTSystem.getGroup(i).Level.Clear();
                    }
                }
                SaveWindowDataEvent(ObjectType.GroupLevel);
                Close();
            }
            else if (currentObject is GroupType)
            {
                GroupType t  = (GroupType)currentObject;
                int       id = t.Id;
                MTSystem.deleteGroupType(t);
                for (int i = 0; i < MTSystem.GroupsCount; i++)
                {
                    if (MTSystem.getGroup(i).Type.Id == id)
                    {
                        MTSystem.getGroup(i).Type.Clear();
                    }
                }
                if (MTSystem.DeleteGroupType(id))
                {
                    MessageBox.Show("Удаление успешно");
                }
                SaveWindowDataEvent(ObjectType.GroupType);
                Close();
            }
            else
            {
                MessageBox.Show("Ошибка!");
            }
            Close();
        }
        /// <summary>
        /// Метод-callback для кнопки сохранения (создания) расписания
        /// </summary>
        void saveButton_Click(object sender, RoutedEventArgs e)
        {
            if (nameBox.Text == "")
            {
                MessageBox.Show("Название не может быть пустым!");
                return;
            }
            if (currentObject is EventType)
            {
                EventType t = (EventType)currentObject;
                t.Name = nameBox.Text;
                if (t.IsValid())
                {
                    if (MTSystem.SaveEventType(t))
                    {
                        MessageBox.Show("Достижение сохранено!");
                    }
                }

                else
                {
                    MTSystem.CreateEventType(t);
                    t.Id = MTSystem.GetLastInsertId("eventtypes");
                    MTSystem.addEventType(t);
                    MessageBox.Show("Достижение создано!");
                }
                SaveWindowDataEvent(ObjectType.EventType);
                Close();
            }
            else if (currentObject is StudentStatus)
            {
                StudentStatus t = (StudentStatus)currentObject;
                t.Name = nameBox.Text;
                if (t.IsValid())
                {
                    MTSystem.SaveStudentStatus(t);
                }
                else
                {
                    MTSystem.CreateStudentStatus(t);
                    t.Id = MTSystem.GetLastInsertId("statuses");
                    MTSystem.addStudentStatus(t);
                }
                SaveWindowDataEvent(ObjectType.StudentStatus);
                Close();
            }
            else if (currentObject is GroupLevel)
            {
                GroupLevel t = (GroupLevel)currentObject;
                t.Name = nameBox.Text;
                if (t.IsValid())
                {
                    MTSystem.SaveGroupLevel(t);
                }
                else
                {
                    MTSystem.CreateGroupLevel(t);
                    t.Id = MTSystem.GetLastInsertId("grouplevels");
                    MTSystem.addGroupLevel(t);
                }
                SaveWindowDataEvent(ObjectType.GroupLevel);
                Close();
            }
            else if (currentObject is GroupType)
            {
                GroupType t = (GroupType)currentObject;
                t.Name = nameBox.Text;
                if (t.IsValid())
                {
                    MTSystem.SaveGroupType(t);
                }
                else
                {
                    MTSystem.CreateGroupType(t);
                    t.Id = MTSystem.GetLastInsertId("grouptypes");
                    MTSystem.addGroupType(t);
                }
                SaveWindowDataEvent(ObjectType.GroupType);
                Close();
            }
            else
            {
                MessageBox.Show("Ошибка!");
            }
        }
		/// <summary>
		/// Метод-callback для кнопки сохранения/создания объекта.
		/// </summary>
		void saveButton_Click(object sender, RoutedEventArgs e)
		{
			if(currentObject is Teacher)
			{
				if(CheckDataBoxes(ObjectType.Teacher))
				{
					int flag = 0;
					Teacher t = (Teacher) currentObject;
					t.Login = infoBlock3.Text;
					t.Pass = infoBlock5.Text;
					t.Name = infoBlock2.Text;
					
					if(!t.IsValid())
					{
						if(MTSystem.CheckLogin(infoBlock3.Text))
						{
							MessageBox.Show("Логин уже зарегистрирован!");
							return;
						}
						MTSystem.CreateClient((User)t);
						t.Id = MTSystem.GetLastInsertId("users");
						MTSystem.addTeacher(t);
						flag = 1;
					}
					// Алгоритмы сохранения данных без дублирования
					int count = 0;
					List<int> groups = new List<int>();
					for(int i = 0; i<t.GroupIdsCount; i++) groups.Add(t.getGroupId(i));
				
					t.ClearGroupIds();
					
					for(int i = 0; i<infoBigGrid.Items.Count; i++) 
						t.addGroupId(Convert.ToInt32(((SampleGrid)infoBigGrid.Items[i]).P1));
					
					for(int i = 0; i<groups.Count; i++)
					{
						for(int j = 0; j<t.GroupIdsCount; j++)
						{
							if(groups[i] == t.getGroupId(j))
							{
								count++;
								break;
							}
						}
						if(count == 0) // Если старая группа не найдена в новых, то ее удалили
						{
							Group g = MTSystem.findGroupById(groups[i]);
							g.deleteTeacherId(t.Id);
							MTSystem.SaveGroup(g);
						}
						count = 0;
					}
					
					for(int i = 0; i<t.GroupIdsCount; i++)
					{
						for(int j = 0; i<groups.Count; j++)
						{
							if(t.getGroupId(i) == groups[j])
							{
								count++;
								break;
							}
						}
						if(count == 0) // Если новая группа не найдена в старых, то ее добавили
						{
							Group g = MTSystem.findGroupById(t.getGroupId(i));
							g.addTeacherId(t.Id);
							MTSystem.SaveGroup(g);
						}
						count = 0;
					}
					
					if(MTSystem.SaveClient((User)t))
					{
						if(flag == 1)
							MessageBox.Show("Преподаватель создан успешно!");
						else
							MessageBox.Show("Преподаватель сохранен!");
					}
					else
					{
						if(flag == 1)
							MessageBox.Show("Ошибка при создании!");
						else
							MessageBox.Show("Ошибка при сохранении!");
					}
					
					SaveWindowDataEvent(ObjectType.Teacher);
					Close();
				}
			}
			else if(currentObject is Admin)
			{
				
				if(CheckDataBoxes(ObjectType.Admin))
				{
					Admin t = (Admin) currentObject;
					t.Login = infoBlock3.Text;
					t.Pass = infoBlock5.Text;
					t.Name = infoBlock2.Text;
					if(t.IsValid())
					{
						if(MTSystem.SaveClient((User)t))
							MessageBox.Show("Администратор сохранен!");
						else
							MessageBox.Show("Ошибка сохранения!");
					}
					else
					{
						MTSystem.CreateClient((User)t);
						MessageBox.Show("Администратор создан успешно!");
					}
						
					SaveWindowDataEvent(ObjectType.Admin);
					Close();
				}
			}
			else if(currentObject is Group)
			{
				if(CheckDataBoxes(ObjectType.Group))
				{
					Group t = (Group) currentObject;
					t.Name = infoBlock2.Text;
					t.PlanHours = Convert.ToInt32(infoBlock3.Text);
					int flag = 0;
					if(cbBlock4.SelectedItem.ToString() == "Не выбрано")
					{
						GroupType grouptype = new GroupType();
						grouptype.Id = 0;
						grouptype.Name = "Не выбрано";
						t.Type = grouptype;
					}
					else t.Type = MTSystem.findGroupTypeByName(cbBlock4.SelectedItem.ToString());
					t.Color.Color = groupColorPicker.SelectedColor;
					if(cbBlock7.SelectedItem.ToString() == "Не выбрано")
					{
						GroupLevel grouplevel = new GroupLevel();
						grouplevel.Id = 0;
						grouplevel.Name = "Не выбрано";
						t.Level = grouplevel;
					}
					else t.Level = MTSystem.findGroupLevelByName(cbBlock7.SelectedItem.ToString());
					
					if(!t.IsValid())
					{
						MTSystem.CreateGroup(t);
						t.Id = MTSystem.GetLastInsertId("groups");
						MTSystem.addGroup(t);
						flag = 1;
					}
					
					// Алгоритмы сохранения данных без дублирования
					List<int> teachers = new List<int>();
					for(int i = 0; i<t.TeachersCount; i++) teachers.Add(t.getTeacherId(i));
					
					int count = 0;
					
					List<int> students = new List<int>();
					for(int i = 0; i<t.StudentsCount; i++) students.Add(t.getStudentId(i));
					
					t.ClearStudentIds();
					for(int i = 0; i<infoBigGrid.Items.Count; i++)
					{
						SampleGrid sg = (SampleGrid) infoBigGrid.Items[i];
						Student s = sg.toStudent();
						if(sg.P5 == "Ходит")
						{
							if(!s.checkGroupId(t.Id))
							{
								s.addGroupId(t.Id);
								MTSystem.SaveStudent(s);
							}
						}
						else
						{
							if(s.checkGroupId(t.Id))
							{
								s.deleteGroupId(t.Id);
								MTSystem.SaveStudent(s);
							}
						}
						t.addStudentId(s.Id);
					}
					
					for(int i = 0; i<students.Count; i++)
					{
						for(int j = 0; j<t.StudentsCount; j++)
						{
							if(students[i] == t.getStudentId(j))
							{
								count = 1;
								break;
							}
						}
						if(count == 0)
						{
							Student s = MTSystem.LoadStudent(students[i]);
							if(s != null)
							{
								if(s.checkGroupId(t.Id))
								{
									s.deleteGroupId(t.Id);
									MTSystem.SaveStudent(s);
								}
							}
						}
						count = 0;
					}
					t.ClearTeacherIds();
					
					for(int i = 0; i<infoSmallGrid.Items.Count; i++)
						t.addTeacherId(Convert.ToInt32(((SampleGrid)infoSmallGrid.Items[i]).P1));
					
					for(int i = 0; i<teachers.Count; i++)
					{
						for(int j = 0; j<t.TeachersCount; j++)
						{
							if(teachers[i] == t.getTeacherId(j))
							{
								count++;
								break;
							}
						}
						if(count == 0) // Если старый препод не найден в новых, то его удалили
						{
							MTSystem.findTeacherById(teachers[i]).deleteGroupId(t.Id);
						}
						count = 0;
					}
					
					for(int i = 0; i<t.TeachersCount; i++)
					{
						for(int j = 0; j<teachers.Count; j++)
						{
							if(t.getTeacherId(i) == teachers[j]) 
							{
								count++;
								break;
							}
						}
						if(count == 0) // Если новый препод не найден в старых, то его добавили
						{
							MTSystem.findTeacherById(t.getTeacherId(i)).addGroupId(t.Id);
						}
						count = 0;
					}
					
					if(MTSystem.SaveGroup(t))
					{
						if(flag == 1)
							MessageBox.Show("Группа создана успешно!");
						else
							MessageBox.Show("Группа сохранена!");
					}
					else
					{
						if(flag == 1)
							MessageBox.Show("Ошибка при создании!");
						else
							MessageBox.Show("Ошибка при сохранении!");
					}
					SaveWindowDataEvent(ObjectType.Group);
					Close();
				}
			
			}
			else if(currentObject is Student)
			{
				if(CheckDataBoxes(ObjectType.Student))
				{
					Student t = (Student) currentObject;
					t.FullName = infoBlock2.Text;
					t.Age = Convert.ToInt32(infoBlock3.Text);
					if(cbBlock4.SelectedItem.ToString() == "Не выбрано")
					{
						StudentStatus status = new StudentStatus();
						status.Id = 0;
						status.Name = "Не выбрано";
						t.Status = status;
					}
					else t.Status = MTSystem.findStudentStatusByName(cbBlock4.SelectedItem.ToString());
					int flag = 0;
					if(!t.IsValid())
					{
						MTSystem.CreateStudent(t);
						t.Id = MTSystem.GetLastInsertId("students");
						flag = 1;
					}
						// Алгоритмы сохранения данных без дублирования
					List<int> groups = new List<int>();
					for(int i = 0; i<t.GroupIdsCount; i++) groups.Add(t.getGroupId(i));
					
					t.ClearGroupIds();
					for(int i = 0; i<infoBigGrid.Items.Count; i++)
					{
						t.addGroupId(Convert.ToInt32(((SampleGrid)infoBigGrid.Items[i]).P1));
					}
					int count = 0;
					for(int i = 0; i<t.GroupIdsCount; i++)
					{
						for(int j = 0; i<groups.Count; j++)
						{
							if(t.getGroupId(i) == groups[j])
							{
								count++;
								break;
							}
						}
						if(count == 0) // Если новая группа не найдена в старых, то ее добавили
						{
							Group g = MTSystem.findGroupById(t.getGroupId(i));
							if(!g.checkStudentId(t.Id))
							{
								g.addStudentId(t.Id);
								MTSystem.SaveGroup(g);
							}
						}
						count = 0;
					}
					
					t.ClearAchievements();
					for(int i = 0; i<infoSmallGrid.Items.Count; i++)
					{
						Achievement a = new Achievement();
						a.Type = Convert.ToInt32(((SampleGrid)infoSmallGrid.Items[i]).P1);
						if(((SampleGrid)infoSmallGrid.Items[i]).P3 == "Участвовал") a.Place = 0;
						else a.Place = Convert.ToInt32(((SampleGrid)infoSmallGrid.Items[i]).P3);
						t.addAchievement(a);
					}
					
					if(MTSystem.SaveStudent(t))
					{
						if(flag == 1)
							MessageBox.Show("Ученик создан успешно!");
						else
							MessageBox.Show("Ученик сохранен!");
					}
					else
					{
						if(flag == 1)
							MessageBox.Show("Ошибка при создании!");
						else
							MessageBox.Show("Ошибка при сохранении!");
					}
					SaveWindowDataEvent(ObjectType.Student);
					Close();
				}
			}
		}
Exemple #6
0
 public static bool SaveGroupLevel(GroupLevel u)
 {
     return(mysql.SaveGroupLevel(u));
 }
Exemple #7
0
 public static void CreateGroupLevel(GroupLevel u)
 {
     mysql.CreateGroupLevel(u);
 }
Exemple #8
0
 public static bool deleteGroupLevel(GroupLevel gr)
 {
     return(GroupLevels.Remove(gr));
 }
Exemple #9
0
 public static void addGroupLevel(GroupLevel gr)
 {
     GroupLevels.Add(gr);
 }