public string IdSToNameOfSpec(int idS) { string nameOfFaculty; using (UMESContext UMES = new UMESContext()) { nameOfFaculty = UMES.Knu.Where(p => p.Id == idS).ToList()[0].NameOfSpecialization; } return(nameOfFaculty); }
public int NameOfSpecToIdS(string nameOfFaculty) { int IdS = 0; using (UMESContext UMES = new UMESContext()) { IdS = UMES.Knu.Where(p => p.NameOfSpecialization == nameOfFaculty).ToList()[0].Id; } return(IdS); }
public MainWindow() { InitializeComponent(); using (UMESContext UMES = new UMESContext()) { if (UMES.Knu.ToList().Count == 0) { UMES.Knu.Add(new SpecializationOfFaculties { Id = 1, NameOfSpecialization = "Радіотехніка", SpecializationOfFaculty = "Радіотехніка, електронні пристрої" }); UMES.Knu.Add(new SpecializationOfFaculties { Id = 2, NameOfSpecialization = "Кібернетика", SpecializationOfFaculty = "Кібернетика, комп'ютерні мережі" }); } else if (UMES.Knu.ToList().Count == 1) { UMES.Knu.Add(new SpecializationOfFaculties { Id = 2, NameOfSpecialization = "Кібернетика", SpecializationOfFaculty = "Кібернетика, комп'ютерні мережі" }); } UMES.SaveChanges(); var k = UMES.FacultyOfKnu.ToList(); if (UMES.FacultyOfKnu.ToList().Count == 0) { UMES.FacultyOfKnu.Add(new FacultyOfKnu { Id = 1, NameOfFaculty = "ФРЕКС", AdvancedPlacement = "фізика", NumberOfFacultyMembers = 1594, NumberOfFacultyStudents = 4837, IdS = 1 }); UMES.FacultyOfKnu.Add(new FacultyOfKnu { Id = 2, NameOfFaculty = "ФКНК", AdvancedPlacement = "програмування", NumberOfFacultyMembers = 1154, NumberOfFacultyStudents = 3592, IdS = 2 }); } else if (UMES.FacultyOfKnu.ToList().Count == 1) { UMES.FacultyOfKnu.Add(new FacultyOfKnu { Id = 2, NameOfFaculty = "ФКНК", AdvancedPlacement = "програмування", NumberOfFacultyMembers = 1154, NumberOfFacultyStudents = 3592, IdS = 2 }); } UMES.SaveChanges(); var listOfSpec = UMES.Knu.Select(p => p.NameOfSpecialization).ToList(); ID_OfSpec_Combobox.ItemsSource = listOfSpec; } }
private void Query_button_Click(object sender, RoutedEventArgs e) { if (GetSpec.IsChecked == true) { foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Hidden; } if (FormatMatch(ID_Textbox.Text)) { using (UMESContext UMES = new UMESContext()) { var specList = UMES.Knu.Where(p => p.Id == uint.Parse(ID_Textbox.Text)).ToList(); foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Visible; if (i.DisplayIndex >= 3) { break; } } Table.ItemsSource = specList; } } else if (ID_Textbox.Text == "") { using (UMESContext UMES = new UMESContext()) { var specList = UMES.Knu.ToList(); foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Visible; if (i.DisplayIndex >= 3) { break; } } Table.ItemsSource = specList; } } else { MessageBox.Show("Invalid enter, please try again"); } } else if (AddSpec.IsChecked == true) { List <string> textboxToString = new List <string>(); textboxToString.Add(ID_Textbox.Text); textboxToString.Add(NameOfSpec_Textbox.Text); textboxToString.Add(SpecOfFac_Textbox.Text); if (FormatMatch(textboxToString)) { SpecializationOfFaculties addSpec = new SpecializationOfFaculties(); addSpec.Id = int.Parse(textboxToString[0]); addSpec.NameOfSpecialization = textboxToString[1]; addSpec.SpecializationOfFaculty = textboxToString[2]; using (UMESContext UMES = new UMESContext()) { UMES.Knu.Add(addSpec); UMES.SaveChanges(); MessageBox.Show("1 specialization was added"); } } } else if (ChangeSpec.IsChecked == true) { List <string> textboxToString = new List <string>(); textboxToString.Add(ID_Textbox.Text); textboxToString.Add(NameOfSpec_Textbox.Text); textboxToString.Add(SpecOfFac_Textbox.Text); foreach (var i in textboxToString) { if (!(FormatMatch(i) || i == "")) { textboxToString = null; break; } } if (ID_Textbox.Text != "") { if (textboxToString != null) { using (UMESContext UMES = new UMESContext()) { SpecializationOfFaculties changedSpec = new SpecializationOfFaculties(); var specForChange = UMES.Knu.Where(p => p.Id == int.Parse(textboxToString[0])).ToList()[0]; changedSpec.Id = int.Parse(textboxToString[0]); if (textboxToString[1] != "") { changedSpec.NameOfSpecialization = textboxToString[1]; } else { changedSpec.NameOfSpecialization = specForChange.NameOfSpecialization; } if (textboxToString[2] != "") { changedSpec.SpecializationOfFaculty = textboxToString[2]; } else { changedSpec.SpecializationOfFaculty = specForChange.SpecializationOfFaculty; } UMES.Knu.Remove(specForChange); UMES.Knu.Add(changedSpec); UMES.SaveChanges(); MessageBox.Show("1 specialization was chenged"); } } else { MessageBox.Show("Invalid enter in some of teaxtbox"); } } else { MessageBox.Show("Enter ID for changing specialization"); } } else if (DelSpec.IsChecked == true) { if (FormatMatch(ID_Textbox.Text)) { using (UMESContext UMES = new UMESContext()) { var removeSpec = UMES.Knu.Where(p => p.Id == int.Parse(ID_Textbox.Text)).ToList(); UMES.Knu.Remove(removeSpec[0]); UMES.SaveChanges(); } MessageBox.Show("1 specialization was deleted"); } else { MessageBox.Show("Invalid enter ID, please try again"); } } }
private void Query_Button_Click(object sender, RoutedEventArgs e) { if (GetFac.IsChecked == true) { foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Hidden; } if (ID_CheckBox.IsChecked == true && Spec_CheckBox.IsChecked == false) { if (FormatMatch(ID_Textbox.Text)) { using (UMESContext UMES = new UMESContext()) { var facultyList = UMES.FacultyOfKnu.Where(p => p.Id == uint.Parse(ID_Textbox.Text)).ToList(); foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Visible; if (i.DisplayIndex >= 4) { break; } } Table.ItemsSource = facultyList; } } else { MessageBox.Show("Invalid enter, please try again"); } } else if (ID_CheckBox.IsChecked == false && Spec_CheckBox.IsChecked == true) { using (UMESContext UMES = new UMESContext()) { var facultyList = UMES.FacultyOfKnu.Join(UMES.Knu, p => p.IdS, c => c.Id, (p, c) => new { p.Id, p.NameOfFaculty, p.AdvancedPlacement, p.NumberOfFacultyMembers, p.NumberOfFacultyStudents, c.NameOfSpecialization }); foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Visible; if (i.DisplayIndex >= 5) { break; } } Table.ItemsSource = facultyList.Where(p => p.NameOfSpecialization == ID_OfSpec_Combobox.SelectedItem.ToString()).ToList(); } } else if (ID_CheckBox.IsChecked == true && Spec_CheckBox.IsChecked == true) { if (FormatMatch(ID_Textbox.Text)) { using (UMESContext UMES = new UMESContext()) { var facultyList = UMES.FacultyOfKnu.Join(UMES.Knu, p => p.IdS, c => c.Id, (p, c) => new { p.Id, p.NameOfFaculty, p.AdvancedPlacement, p.NumberOfFacultyMembers, p.NumberOfFacultyStudents, c.NameOfSpecialization }); foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Visible; if (i.DisplayIndex >= 5) { break; } } Table.ItemsSource = facultyList.Where(p => p.Id == byte.Parse(ID_Textbox.Text)).Where(p => p.NameOfSpecialization == ID_OfSpec_Combobox.SelectedItem.ToString()).ToList(); } } else { MessageBox.Show("Invalid ID enter, please try again"); } } else { using (UMESContext UMES = new UMESContext()) { var facultyList = UMES.FacultyOfKnu.Join(UMES.Knu, p => p.IdS, c => c.Id, (p, c) => new { p.Id, p.AdvancedPlacement, p.NameOfFaculty, p.NumberOfFacultyMembers, p.NumberOfFacultyStudents, c.NameOfSpecialization, c.SpecializationOfFaculty }); foreach (DataGridTextColumn i in Table.Columns) { i.Visibility = Visibility.Visible; if (i.DisplayIndex >= 6) { break; } } Table.ItemsSource = facultyList.ToList(); } } } else if (AddFac.IsChecked == true) { if (ID_CheckBox.IsChecked == true) { int helpX = 0; List <string> textboxToString = new List <string>(); textboxToString.Add(ID_Textbox.Text); textboxToString.Add(FacultyName_TextBox.Text); textboxToString.Add(MainSubj_TextBox.Text); textboxToString.Add(NumbOfLect_Textbox.Text); textboxToString.Add(NumbOfStud_TextBox.Text); textboxToString.Add(ID_OfSpec_Combobox.SelectedItem.ToString()); if (FormatMatch(textboxToString)) { FacultyOfKnu addNewFaculty = new FacultyOfKnu(); addNewFaculty.Id = int.Parse(textboxToString[0]); addNewFaculty.NameOfFaculty = textboxToString[1]; addNewFaculty.AdvancedPlacement = textboxToString[2]; addNewFaculty.NumberOfFacultyMembers = int.Parse(textboxToString[3]); addNewFaculty.NumberOfFacultyStudents = int.Parse(textboxToString[4]); using (UMESContext UMES = new UMESContext()) { helpX = (UMES.Knu.Where(p => p.NameOfSpecialization == ID_OfSpec_Combobox.SelectedItem.ToString()).ToList())[0].Id; addNewFaculty.IdS = helpX; UMES.FacultyOfKnu.Add(addNewFaculty); UMES.SaveChanges(); } MessageBox.Show("You add 1 new faculty"); } else { MessageBox.Show("Invalid enter, please try again"); } } else if (Spec_CheckBox.IsChecked == true) { List <string> textboxToString = new List <string>(); textboxToString.Add(FacultyName_TextBox.Text); textboxToString.Add(MainSubj_TextBox.Text); textboxToString.Add(NumbOfLect_Textbox.Text); textboxToString.Add(NumbOfStud_TextBox.Text); textboxToString.Add(ID_OfSpec_Combobox.SelectedItem.ToString()); if (FormatMatch(textboxToString)) { FacultyOfKnu addNewFaculty = new FacultyOfKnu(); addNewFaculty.NameOfFaculty = textboxToString[0]; addNewFaculty.AdvancedPlacement = textboxToString[1]; addNewFaculty.NumberOfFacultyMembers = int.Parse(textboxToString[2]); addNewFaculty.NumberOfFacultyStudents = int.Parse(textboxToString[3]); using (UMESContext UMES = new UMESContext()) { int helpX = 0; int IdS = NameOfSpecToIdS(textboxToString[4]); addNewFaculty.IdS = IdS; var id = UMES.FacultyOfKnu.ToList(); helpX = id.Last().Id; addNewFaculty.Id = ++helpX; UMES.FacultyOfKnu.Add(addNewFaculty); UMES.SaveChanges(); } MessageBox.Show("You add 1 new faculty"); } else { MessageBox.Show("Invalid enter in some of teaxtbox"); } } } else if (ChangeFac.IsChecked == true) { if (ID_CheckBox.IsChecked == true) { int helpX = 0; List <string> textboxToString = new List <string>(); textboxToString.Add(ID_Textbox.Text); textboxToString.Add(FacultyName_TextBox.Text); textboxToString.Add(MainSubj_TextBox.Text); textboxToString.Add(NumbOfLect_Textbox.Text); textboxToString.Add(NumbOfStud_TextBox.Text); foreach (var i in textboxToString) { if (!(FormatMatch(i) || i == "")) { textboxToString = null; break; } } if (textboxToString != null) { using (UMESContext UMES = new UMESContext()) { if (int.TryParse(ID_Textbox.Text, out helpX)) { FacultyOfKnu changeDataOfFaculty = new FacultyOfKnu(); var facForChange = (UMES.FacultyOfKnu.Where(p => p.Id == int.Parse(textboxToString[0])).ToList())[0]; changeDataOfFaculty.Id = int.Parse(textboxToString[0]); if (textboxToString[1] != "") { changeDataOfFaculty.NameOfFaculty = textboxToString[1]; } else { changeDataOfFaculty.NameOfFaculty = facForChange.NameOfFaculty; } if (textboxToString[2] != "") { changeDataOfFaculty.AdvancedPlacement = textboxToString[2]; } else { changeDataOfFaculty.AdvancedPlacement = facForChange.AdvancedPlacement; } if (textboxToString[3] != "") { changeDataOfFaculty.NumberOfFacultyMembers = int.Parse(textboxToString[3]); } else { changeDataOfFaculty.NumberOfFacultyMembers = facForChange.NumberOfFacultyMembers; } if (textboxToString[4] != "") { changeDataOfFaculty.NumberOfFacultyStudents = int.Parse(textboxToString[3]); } else { changeDataOfFaculty.NumberOfFacultyStudents = facForChange.NumberOfFacultyStudents; } if (ID_OfSpec_Combobox.SelectedItem != null) { changeDataOfFaculty.IdS = NameOfSpecToIdS(ID_OfSpec_Combobox.SelectedItem.ToString()); } else { changeDataOfFaculty.IdS = facForChange.IdS; } UMES.FacultyOfKnu.Remove(facForChange); UMES.FacultyOfKnu.Add(changeDataOfFaculty); UMES.SaveChanges(); MessageBox.Show("Faculty indormation was changed"); } else { MessageBox.Show("Invalid ID enter "); } } } else { MessageBox.Show("Invalid enter in some of teaxtbox"); } } else { MessageBox.Show("Please enter ID_Checkbox"); } } else if (DelFac.IsChecked == true) { if (ID_CheckBox.IsChecked == true) { if (FormatMatch(ID_Textbox.Text)) { using (UMESContext UMES = new UMESContext()) { var removeFaculty = UMES.FacultyOfKnu.Where(p => p.Id == int.Parse(ID_Textbox.Text)).ToList(); UMES.FacultyOfKnu.Remove(removeFaculty[0]); UMES.SaveChanges(); } MessageBox.Show("You delete 1 faculty "); } else { MessageBox.Show("Invalid enter ID, please try again"); } } else if (Spec_CheckBox.IsChecked == true) { if (ID_OfSpec_Combobox.SelectedItem != null) { using (UMESContext UMES = new UMESContext()) { int idS = NameOfSpecToIdS(ID_OfSpec_Combobox.SelectedItem.ToString()); foreach (var i in UMES.FacultyOfKnu.Where(p => p.IdS == idS).ToList()) { UMES.FacultyOfKnu.Remove(i); } UMES.SaveChanges(); } } else { MessageBox.Show("Please, enter \"Спеціалізація факультета\""); } } } }