/// <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();
				}
			}
		}
Example #2
0
 public static bool SaveGroupType(GroupType u)
 {
     return(mysql.SaveGroupType(u));
 }
Example #3
0
 public static bool deleteGroupType(GroupType gr)
 {
     return(GroupTypes.Remove(gr));
 }
Example #4
0
 public static void CreateGroupType(GroupType u)
 {
     mysql.CreateGroupType(u);
 }
Example #5
0
 public static void addGroupType(GroupType gr)
 {
     GroupTypes.Add(gr);
 }