public static void showCompetitionList(DataGrid competitionDataGrid, long _event) { try { competitionDataGrid.ItemsSource = null; } catch (Exception f) { Console.WriteLine(f); // Provide for exceptions. } using (var dt = new appDBEntities()) { var query = from c in dt.Competitions where !(from o in dt.EventCompetitions where o.EventID == MainWindow._event select o.CompetitionID).Contains(c.id) select new { c.CompetitionName, c.id }; var data = query.ToList(); competitionDataGrid.ItemsSource = data; // foreach (object str in data) // eventParticipantsDataGrid.Items.Add(str); dt.Dispose(); } }
/* * Wyswietlanie listy konkurencji zapisanych w bazie danych. */ public static void showCompetitions(DataGrid competitionsDataGrid) { cleanDataGrid(competitionsDataGrid); using (var db = new appDBEntities()) { var query = from c in db.Competitions select new { c.id, c.CompetitionName }; var data = query.ToList(); competitionsDataGrid.ItemsSource = data; db.Dispose(); } }
/* * Wyswietlanie listy klubow zapisanych w bazie danych. */ public static void showClubs(DataGrid clubsDataGrid) { cleanDataGrid(clubsDataGrid); using (var db = new appDBEntities()) { var query = from c in db.Club join regions in db.Regions on c.ClubRegion equals regions.id select new { c.id, c.ClubName, regions.RegionName }; var data = query.ToList(); clubsDataGrid.ItemsSource = data; db.Dispose(); } }
/* * Wyswietlanie listy wydarzen zapisanych w bazie danych. */ public static void showEvents(DataGrid eventsDataGrid) { cleanDataGrid(eventsDataGrid); using (var db = new appDBEntities()) { var query = from c in db.Events join regions in db.Regions on c.EventRegion equals regions.id join nations in db.Nation on c.EventNation equals nations.id select new { c.id, c.EventName, c.EventPlace, c.EventDate, regions.RegionName, nations.NationName }; var data = query.ToList(); eventsDataGrid.ItemsSource = data; db.Dispose(); } }
/* * Wyswietlanie list zawodnikow zapisanych w bazie danych. */ public static void showParticipants(DataGrid participantsDataGrid) { cleanDataGrid(participantsDataGrid); using (var db = new appDBEntities()) { var query = from c in db.Participant join gender in db.Sex on c.Sex equals gender.id join club in db.Club on c.Club equals club.id join nation in db.Nation on c.Nationality equals nation.id select new { c.id, c.Surname, c.Name, gender.SexName, c.City, c.BirthYear, club.ClubName, c.RegTime, nation.NationName }; var data = query.ToList(); participantsDataGrid.ItemsSource = data; db.Dispose(); } }
/* * Wyswietlanie listy uczestnikow przypisanych do aktualnie wybranych zawodow. */ public static void showParticipants(DataGrid participantDataGrid) { using (var dt = new appDBEntities()) { var query = from c in dt.Participant join t2 in dt.Club on c.Club equals t2.id join t3 in dt.Sex on c.Sex equals t3.id join t4 in dt.Nation on c.Nationality equals t4.id // where c.EventID == MainWindow._event select new { c.id, c.Surname, c.Name, t3.SexName, c.BirthYear, t2.ClubName, c.City, c.RegTime, t4.NationName }; var data = query.ToList(); participantDataGrid.ItemsSource = data; // foreach (object str in data) // eventParticipantsDataGrid.Items.Add(str); dt.Dispose(); } }
/* * Wypełnienie ComboBoxa konkurencjami przypisanymi do danych zawodow */ static public void fillCompetitionComboBox(System.Windows.Controls.ComboBox comboBox, long _event) { using (var db = new appDBEntities()) { var query = from c in db.EventCompetitions join com in db.Competitions on c.CompetitionID equals com.id where c.EventID == _event orderby c.Order //descending select com.CompetitionName; var data = query.ToList(); foreach (string str in data) { comboBox.Items.Add(str); } db.Dispose(); } }
} //end funkcji addEvent /// EVENTS ///CLUBS static public void addClub( TextBox ClubNameTextBox, ComboBox ClubRegionComboBox) { // Konwersja danych znajdujacych sie w polach wypelnianych przez uzytkownika. string _ClubName = ClubNameTextBox.Text; long _ClubRegion = long.Parse(ClubRegionComboBox.SelectedValuePath.ToString()); string _ClubRegion1 = ClubRegionComboBox.Text; // Zapisanie wartosci do bazy danych. using (var db = new appDBEntities()) { Club newItem = new Club { ClubName = ClubNameTextBox.Text, ClubRegion = _ClubRegion }; try { //Obsluga bazy danych. db.Club.Add(newItem); db.SaveChanges(); db.Dispose(); } catch (Exception e) { Console.WriteLine(e); MessageBox.Show(string.Format("Error - {0}", e), "Information", MessageBoxButton.OK, MessageBoxImage.Information); } //Wyswietlenie komunikatu o poprawnosci wprowadzonych danych. string inf = string.Format("Club added :\n{0}\nRegion: {1}", newItem.ClubName, _ClubRegion1); MessageBox.Show(inf, "Information", MessageBoxButton.OK, MessageBoxImage.Information); //Czyszczenie pol wypelnianych przez uzytkownika. ClubNameTextBox.Text = null; ClubRegionComboBox.Text = null; } //end using }//end funkcji addClub
/* * Wyswietlanie list startowych dla danej konkurencji. */ public static void showStartOrder(DataGrid dataGrid, int gender, int competition) { browseDataBase.cleanDataGrid(dataGrid); try { using (var db = new appDBEntities()) { var query = from c in db.StartOrders join participant in db.Participant on c.FKParticipant equals participant.id join sex in db.Sex on participant.Sex equals sex.id join club in db.Club on participant.Club equals club.id where c.FKevent == MainWindow._event && c.FKcompetition == competition && participant.Sex == gender // where c.EventID == MainWindow._event select new { participant.Surname, participant.Name, sex.SexName, participant.BirthYear, club.ClubName, c.Heat, c.Track, c.EntryTime }; var query1 = query.OrderBy(c => c.Heat).ThenBy(c => c.Track); var data = query1.ToList(); dataGrid.ItemsSource = data; db.Dispose(); } } catch (Exception f) { Console.WriteLine(f); // Provide for exceptions. } }
/* * Przypisanie zaznaczonego zawodnika do aktualnie wybranych zawodow. */ public static void addParticipantToEvent(long idParticipant, long idEvent) { using (var db = new appDBEntities()) { EventParticipants newItem = new EventParticipants { EventID = idEvent, ParticipantID = idParticipant, }; try { db.EventParticipants.Add(newItem); db.SaveChanges(); db.Dispose(); MessageBox.Show(string.Format("Adding participant with ID = {0} to EventID = {1}", idParticipant, idEvent)); } catch (Exception f) { Console.WriteLine(f); // Provide for exceptions. } } }
public static void showEventCompetition(DataGrid eventCompetitionDataGrid, long _event) { try { eventCompetitionDataGrid.ItemsSource = null; } catch (Exception f) { Console.WriteLine(f); // Provide for exceptions. } using (var dt = new appDBEntities()) { var query = from c in dt.EventCompetitions join t2 in dt.Competitions on c.CompetitionID equals t2.id where c.EventID == MainWindow._event orderby c.Order //descending select new { t2.CompetitionName, c.CompetitionID, c.Order }; var data = query.ToList(); eventCompetitionDataGrid.ItemsSource = data; dt.Dispose(); } }
///EVENT static public void addEvent( TextBox EventNameTextBox, TextBox EventPlaceTextBox, TextBox EventDateYearTextBox, TextBox EventDateMonthTextBox, TextBox EventDateDayTextBox, ComboBox EventNationComboBox, ComboBox EventRegionComboBox) { // Wypełnienie comboboxa //fillComboBoxes.fillRegionComboBox(EventRegionComboBox, MainWindow._event); // Konwersja danych znajdujacych sie w polach wypelnianych przez uzytkownika. int _EventDateYear = int.Parse(EventDateYearTextBox.Text); int _EventDateMonth = int.Parse(EventDateMonthTextBox.Text); int _EventDateDay = int.Parse(EventDateDayTextBox.Text); long _NationName = long.Parse(EventNationComboBox.SelectedValuePath.ToString()); string _NationName1 = EventNationComboBox.Text; // long _RegionName = long.Parse(RegionNameComboBox.SelectedValuePath.ToString()); string _EventName = EventNameTextBox.Text; string _EventPlace = EventPlaceTextBox.Text; long _EventRegion = long.Parse(EventRegionComboBox.SelectedValuePath.ToString()); string _EventRegion1 = EventRegionComboBox.Text; string _Date = DateFormat(EventDateYearTextBox, EventDateMonthTextBox, EventDateDayTextBox); //Sprawdzenie poprawnosci wprowadzaonych danych przez uzytkownika. if (checkIsDataCorrectFuture(_EventDateDay, _EventDateMonth, _EventDateYear, _Date)) { // Zapisanie wartosci do bazy danych. using (var db = new appDBEntities()) { Events newItem = new Events { EventName = EventNameTextBox.Text, EventPlace = EventPlaceTextBox.Text, EventDate = _Date, EventNation = _NationName, EventRegion = _EventRegion }; try { //Obsluga bazy danych. db.Events.Add(newItem); db.SaveChanges(); db.Dispose(); } catch (Exception e) { Console.WriteLine(e); MessageBox.Show(string.Format("Error - {0}", e), "Information", MessageBoxButton.OK, MessageBoxImage.Information); } //Wyswietlenie komunikatu o poprawnosci wprowadzonych danych. string inf = string.Format("Event added :\n{0}\nPlace: {1}\nDate: {2}\nNation: {3}\nRegion: {4}", newItem.EventName, newItem.EventPlace, newItem.EventDate, _NationName1, _EventRegion1); MessageBox.Show(inf, "Information", MessageBoxButton.OK, MessageBoxImage.Information); //Czyszczenie pol wypelnianych przez uzytkownika. EventDateYearTextBox.Text = "YYYY"; EventDateMonthTextBox.Text = "MM"; EventDateDayTextBox.Text = "DD"; EventNationComboBox.Text = null; EventNameTextBox.Text = null; EventPlaceTextBox.Text = null; EventRegionComboBox.Text = null; } //end using } //end if else { MessageBox.Show("Write a correct date.", "Error!", MessageBoxButton.OK, MessageBoxImage.Information); } //end else } //end funkcji addEvent
static public void addParticipant( TextBox ParticipantSurnameTextBox, TextBox ParticipantNameTextBox, TextBox ParticipantCityTextBox, TextBox ParticipantBirthYearTextBox, TextBox ParticipantBirthMonthTextBox, TextBox ParticipantBirthDayTextBox, ComboBox sexNameComboBox, ComboBox clubNameComboBox, ComboBox nationNameComboBox, TextBox ParticipantRegTimeMinTextBox, TextBox ParticipantRegTimeSecTextBox, TextBox ParticipantRegTimeCentTextBox) { // Konwersja danych znajdujacych sie w polach wypelnianych przez uzytkownika. int _BirthYear = int.Parse(ParticipantBirthYearTextBox.Text); int _BirthMonth = int.Parse(ParticipantBirthMonthTextBox.Text); int _BirthDay = int.Parse(ParticipantBirthDayTextBox.Text); long _sex = long.Parse(sexNameComboBox.SelectedValuePath.ToString()); long _clubName = long.Parse(clubNameComboBox.SelectedValuePath.ToString()); long _nationName = long.Parse(nationNameComboBox.SelectedValuePath.ToString()); string _nationName1 = nationNameComboBox.Text; string _clubName1 = clubNameComboBox.Text; string _sex1 = sexNameComboBox.Text; string _regTime = participantRegTime(ParticipantRegTimeMinTextBox, ParticipantRegTimeSecTextBox, ParticipantRegTimeCentTextBox); //Sprawdzenie poprawnosci wprowadzaonych danych przez uzytkownika. if (checkIsDataCorrect(_BirthDay, _BirthMonth, _BirthYear, _regTime)) { // Zapisanie wartosci do bazy danych. using (var db = new appDBEntities()) { Participant newItem = new Participant { Surname = ParticipantSurnameTextBox.Text, Name = ParticipantNameTextBox.Text, BirthDay = _BirthYear, BirthMonth = _BirthMonth, BirthYear = _BirthDay, City = ParticipantCityTextBox.Text, Sex = _sex, Club = _clubName, Nationality = _nationName, RegTime = _regTime }; //Obsluga bazy danych. db.Participant.Add(newItem); db.SaveChanges(); db.Dispose(); //Wyswietlenie komunikatu o poprawnosci wprowadzonych danych. string inf = string.Format("Participant added :\n{0} {1}\n\nSex: {2}, Birth: {3}-{4}-{5},\nCity: {6}, Club: {7}, Nation: {8}\nEntry Time: {9}", newItem.Surname, newItem.Name, _sex1, newItem.BirthDay, newItem.BirthMonth, newItem.BirthYear, newItem.City, _clubName1, _nationName1, _regTime); MessageBox.Show(inf, "Information", MessageBoxButton.OK, MessageBoxImage.Information); //Czyszczenie pol wypelnianych przez uzytkownika. ParticipantBirthYearTextBox.Text = "YYYY"; ParticipantBirthMonthTextBox.Text = "MM"; ParticipantBirthDayTextBox.Text = "DD"; sexNameComboBox.Text = null; clubNameComboBox.Text = null; nationNameComboBox.Text = null; ParticipantNameTextBox.Text = null; ParticipantSurnameTextBox.Text = null; ParticipantRegTimeMinTextBox.Text = "mm"; ParticipantRegTimeSecTextBox.Text = "ss"; ParticipantRegTimeCentTextBox.Text = "cccc"; ParticipantCityTextBox.Text = null; } //end using } //end if else { MessageBox.Show("Write a correct birth date.", "Error!", MessageBoxButton.OK, MessageBoxImage.Information); } //end else } //end funkcji addParticipant