예제 #1
0
		void UpdateSubjects()
		{
			using (_ujc = new UniversityEntities())
			{
				_subjects = (from subj in _ujc.University_Subject
							 select subj).ToList();
				RaisePropertyChanged("Subjects");
			}
		}
예제 #2
0
		private void DeleteStudentFromDB(University_Student obj)
		{
			_ujc = new UniversityEntities();

			var removestud = _ujc.University_Student.Single((s) => s.Student_ID == SelectedStudent.Student_ID);
			_ujc.University_Student.Remove(removestud);
			_ujc.SaveChanges();
			UpdateStudentsList();	
		}
예제 #3
0
		private void UpdateStudent(object parameter)
		{
			using (_ujc = new UniversityEntities())
			{
				//try
				{
					University_Student tmp = _ujc.University_Student.Single((st) => st.Student_ID == SelectedStudent.Student_ID);
					tmp.First_Name = StudentName;
					tmp.Last_Name = StudentLastName;
					tmp.Birthday = StudentBirthdate;
					tmp.Email = StudentEmail;
					if (StudentPhoto!=null)
					{
						tmp.Photo = ImageToByte(StudentPhoto);
					}
					else tmp.Photo = ImageToByte(new BitmapImage(new Uri(@"G:\Универ\GoogleDrive_oldan\Bionic Final Project\UniversityJournal\UniversityJournal\bin\Debug\no_img.jpg")));
					_ujc.SaveChanges();
					UpdateStudentsList();
					CloseCommand();
					
				}
				//catch
				{
				}
			}
		}
예제 #4
0
		void GetCurrentSubjects(University_Group obj)
		{
			if (obj != null)
			{
				using (_ujc = new UniversityEntities())
				{
					var _teach = _ujc.University_Group.Where(s => s.Group_ID == obj.Group_ID).FirstOrDefault();
					CurrentSubjects = new ObservableCollection<University_Subject>(_teach.University_Subject.ToList());
				}
			}
		}
예제 #5
0
		void GetCurrentStudents(University_Group obj)
		{
			if (obj!=null)
			{
				using (_ujc = new UniversityEntities())
				{
					var _studs = _ujc.University_Group.Where(gr => gr.Group_ID == obj.Group_ID).FirstOrDefault();
					Students = new ObservableCollection<University_Student>(_studs.University_Student.ToList());
				}
			}
		}
예제 #6
0
		private void AddSubjectFromList(University_Subject obj)
		{
			using (_ujc = new UniversityEntities())
			{
				var currsubj = _ujc.University_Subject.Where(s => s.Subject_ID == obj.Subject_ID).FirstOrDefault();
				var currgroup = _ujc.University_Group.Where(t => t.Group_ID == SelectedGroup.Group_ID).FirstOrDefault();
				currgroup.University_Subject.Add(currsubj);
				_ujc.SaveChanges();
				GetCurrentSubjects(SelectedGroup);
				GetAllSubjects();
			}
		}
예제 #7
0
		private void RemoveStudentFromGroup(University_Student obj)
		{
			using (_ujc = new UniversityEntities())
			{
				var currstud = _ujc.University_Student.Where(s => s.Student_ID == obj.Student_ID).FirstOrDefault();
				var currgroup = _ujc.University_Group.Where(t => t.Group_ID == SelectedGroup.Group_ID).FirstOrDefault();
				currgroup.University_Student.Remove(currstud);
				_ujc.SaveChanges();
				GetAllStudents();
				GetCurrentStudents(SelectedGroup);
			}
		}
예제 #8
0
		private void UpdateSchedule()
		{
			using (_ujc=new UniversityEntities())
			{
				
				UpdateDaySchedule("Monday", ref _mondayLessons);
				UpdateDaySchedule("Tuesday", ref _tuesdayLessons);
				UpdateDaySchedule("Wednesday", ref _wednesdayLessons);
				UpdateDaySchedule("Thursday", ref _thursdayLessons);
				UpdateDaySchedule("Friday", ref _fridayLessons);
				RaisePropertyChanged("MondayLessons");
				RaisePropertyChanged("TuesdayLessons");
				RaisePropertyChanged("WednesdayLessons");
				RaisePropertyChanged("ThursdayLessons");
				RaisePropertyChanged("FridayLessons");
				
				
			}
		}
예제 #9
0
		public void Refresh()
		{
			
			FilterList = new ObservableCollection<University_Group>();
			FilterList.Add(new University_Group() { Group_Name = "ALL", Group_ID = 65536 });

			using (_ujc = new UniversityEntities())
			{
				foreach (var gr in _ujc.University_Group.Select(s => s).ToList())
				{
					FilterList.Add(gr);
				}
				SelectedFilter = FilterList[0];
			}
			UpdateSchedule();
			
		}
예제 #10
0
		private void DeleteLessonFromSchedule(Schedule parameter)
		{
			using (_ujc = new UniversityEntities())
			{
				var _delLes = _ujc.University_Schedule.Where(s => s.Lesson_ID == parameter.Lesson_ID).FirstOrDefault();
				_ujc.University_Schedule.Remove(_delLes);
				_ujc.SaveChanges();
			}
			UpdateSchedule();
		}
예제 #11
0
		private void AddLessonToSchedule(object parameter)
		{
			using (_ujc = new UniversityEntities())
			{
				var _newLes = new University_Schedule();
				_newLes.Day_of_week = SelectedDay;
				_newLes.LessonNo = SelectedLessonNo;
				_newLes.Group_ID = SelectedGroup.Group_ID;
				_newLes.Subject_ID = SelectedSubject.Subject_ID;
				_newLes.Teacher_ID = SelectedTeacher.Teacher_ID;
				_ujc.University_Schedule.Add(_newLes);
				_ujc.SaveChanges();
			}
			SelectedLessonNo = 0;
			RaisePropertyChanged("SelecteLessonNo");
			SelectedDay = null;
			OnSelectedLessonNo();
			UpdateSchedule();
			
		}
예제 #12
0
		private void OnSelectedSubject()
		{
			if (!string.IsNullOrEmpty(SelectedDay) && SelectedLessonNo > 0 && SelectedLessonNo < 5 && SelectedGroup != null&& SelectedSubject!=null)
			{
				using (_ujc = new UniversityEntities())
				{
					var _ss = _ujc.University_Subject.Where(s => s.Subject_ID == SelectedSubject.Subject_ID).FirstOrDefault();
					var _exclTchrID = _ujc.University_Schedule
						.Where(s=>s.Day_of_week==SelectedDay)
						.Where(s=>s.LessonNo==SelectedLessonNo)
						.Select(s => s.Teacher_ID);
					var _possTchrID = _ss.University_Teacher.Select(s => s.Teacher_ID);
					var _availTchrID = _possTchrID.Except(_exclTchrID);
					Teachers = new ObservableCollection<University_Teacher>();
					foreach (var id in _availTchrID)
					{
						Teachers.Add(_ujc.University_Teacher.Where(tch => tch.Teacher_ID == id).FirstOrDefault());
					}
				}
			}
		}
예제 #13
0
		private void OnSelectedGroup()
		{
			if (!string.IsNullOrEmpty(SelectedDay) 
				&& SelectedLessonNo > 0 
				&& SelectedLessonNo < 5 
				&& SelectedGroup != null)
			{
				using (_ujc = new UniversityEntities())
				{
					var _selgr = _ujc.University_Group
						.Where(s => s.Group_ID == SelectedGroup.Group_ID).FirstOrDefault();
					var _subjs = _selgr.University_Subject.ToList();
					GroupSubjects = new ObservableCollection<University_Subject>(_subjs);
				}
			}
		}
예제 #14
0
		private void OnSelectedLessonNo()
		{
			if (!string.IsNullOrEmpty(SelectedDay)&&SelectedLessonNo>0&&SelectedLessonNo<5)
			{
				using (_ujc = new UniversityEntities())
				{
					AvailableGroups = new ObservableCollection<University_Group>();
					var _exclgrID = _ujc.University_Schedule
						.Where(s=>s.Day_of_week.Equals(SelectedDay))
						.Where(s=>s.LessonNo==SelectedLessonNo)
						.Select(s=>s.Group_ID);
					var _allgrID = _ujc.University_Group
						.Select(s=>s.Group_ID);
					var _availgrID = _allgrID.Except(_exclgrID);
					foreach (var id in _availgrID)
					{
						AvailableGroups.Add(_ujc.University_Group.Where(gr => gr.Group_ID == id).FirstOrDefault());
					}
					
				}
			}
		}
예제 #15
0
		private void EditGroupFromDB(University_Group obj)
		{
			try
			{
				using (_ujc = new UniversityEntities())
				{
					var _group = _ujc.University_Group.Where(s => s.Group_ID == obj.Group_ID).FirstOrDefault();
					_group.Group_Name = GroupNameEdit;
					_ujc.SaveChanges();
			
				}
			}
			catch { }
			finally
			{
				RefreshIt();
			}
		}
예제 #16
0
		private void SaveNewTeacherToDB(object obj)
		{
			try
			{
				using (_ujc = new UniversityEntities())
				{
					University_Teacher _teach = new University_Teacher();
					_teach.First_Name = Tname;
					_teach.Last_Name = Tlname;
					_teach.Birthday = Tbdate;
					_teach.Email = Temail;
					if (Tphoto != null)
					{
						_teach.Photo = ImageToByte(Tphoto);
					}
					_teach.Login = Tlogin;
					_teach.Password = Tpwd;

					_ujc.University_Teacher.Add(_teach);
					_ujc.SaveChanges();

				}
			}
			catch { }
			finally
			{
				EditEnabled = false;
				AddButtonName = "Add New...";
				_addNewTeacher = new Command<object>(AddNewTeacherToDB);
				RaisePropertyChanged("AddNewTeacher");
				BlockGrid = true;
				RefreshIt();
			}
			
		}
예제 #17
0
		private void AddNewGroupToDB(string obj)
		{
			try
			{
				using (_ujc = new UniversityEntities())
				{
					University_Group _group = new University_Group();
					_group.Group_Name = obj;
					_ujc.University_Group.Add(_group);
					_ujc.SaveChanges();
				}
			}
			catch { }
			finally
			{
				RefreshIt();
			}
		
		}
예제 #18
0
		private void SaveEditedTeacherToDB(University_Teacher obj)
		{
			try
			{
				using (_ujc = new UniversityEntities())
				{
					var _teach = _ujc.University_Teacher.Where(s => s.Teacher_ID == SelectedTeacher.Teacher_ID).Single();
					_teach.First_Name = Tname;
					_teach.Last_Name = Tlname;
					_teach.Birthday = Tbdate;
					_teach.Email = Temail;
					if (Tphoto != null)
					{
						_teach.Photo = ImageToByte(Tphoto);
					}
					_teach.Login = Tlogin;
					_teach.Password = Tpwd;
		
					_ujc.SaveChanges();
				}
			}
			finally
			{
				EditEnabled = false;
				EditButtonName = "Edit";
				_editTeacher = new Command<University_Teacher>(EditTeacherFromDB, (S) => SelectedTeacher != null);
				RaisePropertyChanged("EditTeacher");
				AllowAddButton = true;
				BlockGrid = true;
				RefreshIt();
			}
		}
예제 #19
0
		private void AddStudentToGroup (University_Student parameter)
		{
			
			using (_ujc = new UniversityEntities())
			{
				var _selstud = _ujc.University_Student.Where(s=>s.Student_ID == parameter.Student_ID).FirstOrDefault();
				var _group = _ujc.University_Group.Where(gr => gr.Group_ID == SelectedGroup.Group_ID).FirstOrDefault();
				_group.University_Student.Add(_selstud);
				_ujc.SaveChanges();
			}
			GetAllStudents();
			GetCurrentStudents(SelectedGroup);

		}
예제 #20
0
		private void DeleteTeacherFromDB(University_Teacher obj)
		{
			try
			{
				using (_ujc = new UniversityEntities())
				{
					var _teach = _ujc.University_Teacher.Where(s => s.Teacher_ID == obj.Teacher_ID).FirstOrDefault();
					_ujc.University_Teacher.Remove(_teach);
					_ujc.SaveChanges();
				}
			}
			finally
			{
				RefreshIt();
			}
			
		}
예제 #21
0
		private void UpdateGroupList()
		{
			using (_ujc = new UniversityEntities())
			{
				var tmp = (from gr in _ujc.University_Group
						   select gr).ToList();
				_groups = new ObservableCollection<University_Group>(tmp);
				RaisePropertyChanged("Groups");
			}
		}
예제 #22
0
		private void RemoveSubjectFromList(University_Subject obj)
		{
			using (_ujc = new UniversityEntities())
			{
				var currsubj = _ujc.University_Subject.Where(s => s.Subject_ID == obj.Subject_ID).FirstOrDefault();
				var currteach = _ujc.University_Teacher.Where(t => t.Teacher_ID == SelectedTeacher.Teacher_ID).FirstOrDefault();
				currteach.University_Subject.Remove(currsubj);
				_ujc.SaveChanges();
				GetCurrentSubjects(SelectedTeacher);
				GetAllSubjects();
			}
		}
예제 #23
0
		void GetAllSubjects()
		{
			using (_ujc = new UniversityEntities())
			{
				if (CurrentSubjects != null && SelectedGroup != null)
				{
					var tmpData = _ujc.University_Subject.ToList();
					var teach = _ujc.University_Group.Where(e => e.Group_ID == SelectedGroup.Group_ID).FirstOrDefault();
					var exclData = teach.University_Subject.ToList();
					var res = tmpData.Except(exclData).ToList();
					AllSubjects = new ObservableCollection<University_Subject>(res);
				}
			}
		}
예제 #24
0
		void UpdateTeachersList()
		{
			using (_ujc = new UniversityEntities())
			{
				_teachers = (from teac in _ujc.University_Teacher
							 select teac).ToList();
				RaisePropertyChanged("Teachers");
			}
		}
예제 #25
0
		private void GetAllStudents()
		{
			AllAvailableStudents = new ObservableCollection<University_Student>();
			using(_ujc = new UniversityEntities())
			{
				var _allStuds = _ujc.University_Student.Select(s => s);
				foreach(var stud in _allStuds)
				{
					if (stud.University_Group.Count==0)
					{
						AllAvailableStudents.Add(stud);
					}
				}
			}
		}
예제 #26
0
//CONSTRUCTOR
		public GroupVM()
		{
			_deleteGroup = new Command<University_Group>(DeleteGroupFromDB, s => s != null);
			_editGroup = new Command<University_Group>(EditGroupFromDB, s => s != null
				&& !string.IsNullOrWhiteSpace(GroupNameEdit));
			_addNewGroup = new Command<string>(AddNewGroupToDB,
				s =>
				{	
					if (!string.IsNullOrWhiteSpace(s))
						using(_ujc=new UniversityEntities())
						{
							var cnt=_ujc.University_Group.Where(gr => gr.Group_Name == s).ToList().Count;
							return !(cnt > 0);
						}
					return false;
				});
			_addSubject = new Command<University_Subject>(AddSubjectFromList,
				s => SelectedGroup != null && s != null
				);
			_removeSubject = new Command<University_Subject>(RemoveSubjectFromList,
				s => SelectedGroup != null && s != null);

			_addStudents = new Command<University_Student>(AddStudentToGroup, s => SelectedGroup != null && s != null);
			_removeStudents = new Command<University_Student>(RemoveStudentFromGroup, s => SelectedGroup != null && s != null);

			RefreshIt();
		}
예제 #27
0
		void UpdateStudentsList()
		{
			using (_ujc = new UniversityEntities())
			{
				if (!string.IsNullOrEmpty(SearchString))
				{
					_students = new List<University_Student>();
					Regex _sp = new Regex(SearchString+"{1}",RegexOptions.IgnoreCase);
					var _tmp = _ujc.University_Student.Select(s => s);
					foreach (var it in _tmp)
					{
						if (_sp.IsMatch(it.Last_Name)||_sp.IsMatch(it.First_Name))
						{
							_students.Add(it);
						}
					}
				}
				else
				{
					//_students = new List<University_Student>();
					_students = _ujc.University_Student
						//	.Where(s => s.Last_Name.Contains(SearchString))
					.Select(s => s)
					.ToList();
				}
				//_students.AddRange(
				//	_ujc.University_Student
				//	.Where(s => s.First_Name.Contains(SearchString))
				//	.ToList()
				//	);
					//(from stud in _ujc.University_Student

					//		 select stud).ToList();
				RaisePropertyChanged("Students");
			}
		}
예제 #28
0
//Command Methods
		private void DeleteGroupFromDB(University_Group obj)
		{
			try
			{
				using (_ujc = new UniversityEntities())
					{
						var _group = _ujc.University_Group.Where(s => s.Group_ID == obj.Group_ID).FirstOrDefault();
						_ujc.University_Group.Remove(_group);
						_ujc.SaveChanges();
					}
			}
		
			finally
			{
				RefreshIt();
			}
		}
예제 #29
0
		private void AddStudent(object parameter)
		{
			using (_ujc = new UniversityEntities())
			{
				try
				{
					University_Student tmp = new University_Student();
					tmp.First_Name = StudentName;
					tmp.Last_Name = StudentLastName;
					tmp.Birthday = StudentBirthdate;
					tmp.Email = StudentEmail;
					if (StudentPhoto == null)
						tmp.Photo = null;
					else
						tmp.Photo = ImageToByte(StudentPhoto);
					_ujc.University_Student.Add(tmp);
					_ujc.SaveChanges();
					UpdateStudentsList();
					CloseCommand();
				}
				catch { }
			}
		}
예제 #30
0
		private void EditSubjectFromDB(University_Subject obj)
		{
			using (_ujc = new UniversityEntities())
			{
				var subj = _ujc.University_Subject.Where(s => s.Subject_ID == obj.Subject_ID).FirstOrDefault();
				if (subj != null)
				{
					subj.Subject_Name = CurrentSubject;
					_ujc.SaveChanges();
				}
				UpdateSubjects();
			}
		}