/* * Obsluga dodawania kolejnosci. */ public static void changeOrder(long idCompetition, long idEvent, int points) { var db = new appDBEntities(); if (idCompetition == 0) { MessageBox.Show(string.Format("Error: idCompetition = {0}, idEvent = {1}", idCompetition, idEvent)); } else { EventCompetitions c = (from EventCompetitions in db.EventCompetitions where EventCompetitions.CompetitionID == idCompetition && EventCompetitions.EventID == idEvent select EventCompetitions).First(); if (c.Order == null) { c.Order = 0; c.Order = c.Order + points; } else { c.Order = c.Order + points; } try { db.SaveChanges(); // MessageBox.Show(string.Format("Deleting participant with ID = {0} from EventID = {1}", idParticipant, idEvent)); } catch (Exception f) { Console.WriteLine(f); // Provide for exceptions. } } }
public static void dbSaveChanges(appDBEntities db) { try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } }
} //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
/* * Funkcja wypelnia liste startowa zawodnikami przypisanymi do danych zawodow. */ public static void fillStartOrder(int gender) { using (var dt = new appDBEntities()) { var query = from c in dt.EventParticipants join t2 in dt.Participant on c.ParticipantID equals t2.id join t3 in dt.Sex on t2.Sex equals t3.id join t4 in dt.Club on t2.Club equals t4.id where c.EventID == MainWindow._event && t2.Sex == gender select new { c.id, c.ParticipantID, t2.Surname, t2.Name, t3.SexName, t2.BirthYear, t4.ClubName, t2.RegTime }; /* TO DO LIST * POBIERZ LISTE ZAWODNIKOW Z WYBRANYCH ZAWODOW * DODAJ ZAWODNIKOW DO TABELI STARTORDERS * WYPELNIJ SERIE/TORY STARTOWE WG WZORU */ foreach (var a in query) { StartOrders newItem = new StartOrders { FKevent = MainWindow._event, FKeventParticipant = a.id, FKcompetition = MainWindow._competition, FKParticipant = a.ParticipantID, EntryTime = a.RegTime }; //Dodaj dt.StartOrders.Add(newItem); } try { dt.SaveChanges(); // MessageBox.Show(string.Format("Deleting participant with ID = {0} from EventID = {1}", idParticipant, idEvent)); } 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. } } }
/* * Funkcja czysci poprzednia liste startowa. */ public static void clearStartOrder(int gender) { var db = new appDBEntities(); var deleteStartOrder = from StartOrders in db.StartOrders join t2 in db.Participant on StartOrders.FKParticipant equals t2.id where StartOrders.FKevent == MainWindow._event && StartOrders.FKcompetition == MainWindow._competition && t2.Sex == gender select StartOrders; foreach (var StartOrders in deleteStartOrder) { db.StartOrders.Remove(StartOrders); } try { db.SaveChanges(); } catch (Exception f) { Console.WriteLine(f); } }
/* * Usuwa zawodnika z danej imprezy. Usuwany jest zawodnik ktory zostal zaznaczony w prawym oknie AddDeleteParticipantsWindow. */ public static void deleteParticipantFromEvent(long idParticipant, long idEvent) { var db = new appDBEntities(); var deleteParticipantInEvent = from EventParticipants in db.EventParticipants where EventParticipants.ParticipantID == idParticipant && EventParticipants.EventID == idEvent select EventParticipants; foreach (var EventParticipants in deleteParticipantInEvent) { db.EventParticipants.Remove(EventParticipants); } try { db.SaveChanges(); MessageBox.Show(string.Format("Deleting participant with ID = {0} from EventID = {1}", idParticipant, idEvent)); } catch (Exception f) { Console.WriteLine(f); // Provide for exceptions. } }
///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