private void btnSaveTeam_Click(object sender, RoutedEventArgs e) { //check that all info is filled in if (!FillOK()) { MessageBox.Show("Täytä kaikki tähdellä merkityt kentät ennen tallentamista."); return; } string Nimi = $"'{txtTeamname.Text }'"; string Paikkakunta = $"'{txtLocation.Text}'"; string Seura = $"'{txtOrganization.Text}'"; string LogoURL = $"'{txtLogofile.Text}'"; //if saving new team if (string.IsNullOrWhiteSpace(txtTeamID.Text)) { string inserttablestring = "Joukkue (Nimi, Paikkakunta, Seura, LogoURL)"; string insertvaluestring = $"({Nimi}, {Paikkakunta}, {Seura}, {LogoURL})"; DBSalibandytournament.InsertIntoDB(inserttablestring, insertvaluestring); } //if updating existing team else { int JoukkueId = int.Parse(txtTeamID.Text); string updatetablestring = "Joukkue"; string updatevaluestring = $"Nimi = {Nimi}, Paikkakunta = {Paikkakunta}, Seura = {Seura}, LogoURL = {LogoURL}"; string updatewherestring = $"JoukkueId = {JoukkueId}"; DBSalibandytournament.UpdateDB(updatetablestring, updatevaluestring, updatewherestring); } Close(); teamsWindow.RefreshTeams(); }
private void btnEndGame_Click(object sender, RoutedEventArgs e) { try { //add goals to database string goaltable = "Maali (Aika, Erikoistilanne, Maalintekija, Syottaja, Joukkue, Ottelu)"; if (homegoals.Count > 0) { DBSalibandytournament.InsertIntoDB(goaltable, MakeGoalSql(homegoals, int.Parse(txtHomeId.Text))); } if (awaygoals.Count > 0) { DBSalibandytournament.InsertIntoDB(goaltable, MakeGoalSql(awaygoals, int.Parse(txtAwayId.Text))); } //add penalties to database string penaltytable = "Rangaistus (Aika, Kesto, Syy, Henkilo, Joukkue, Ottelu)"; if (homepenalties.Count > 0) { DBSalibandytournament.InsertIntoDB(penaltytable, MakePenaltySql(homepenalties, int.Parse(txtHomeId.Text))); } if (awaypenalties.Count > 0) { DBSalibandytournament.InsertIntoDB(penaltytable, MakePenaltySql(awaypenalties, int.Parse(txtAwayId.Text))); } //mark game ended DBSalibandytournament.UpdateDB("Ottelu", "Paatetty = TRUE", $"OtteluID = {gameID}"); gameStatus = true; MessageBox.Show("Ottelu on onnistuneesti päätetty."); Close(); } catch (Exception ex) { MessageBox.Show("Tapahtui virhe: " + ex.ToString()); } }
public WpfPlayereditor(WpfPlayers playerWindow) { InitializeComponent(); Teams = DBSalibandytournament.GetTeamsFromDB(); cmbTeams.ItemsSource = Teams; this.playerWindow = playerWindow; }
//fill all combobox sources private void FillCombo(int homeID, int awayID) { NumberOfPeriods = new List <string>() { "1", "2", "3" }; //0,15 minute period lenght (9 seconds) for testing purposes PeriodLenghts = new List <string>() { "0,15", "10", "15", "20" }; SpecialTeams = new List <string>() { "YV", "AV", "RL", "TM" }; cmbNumberOfPeriods.ItemsSource = NumberOfPeriods; cmbPeriodLenght.ItemsSource = PeriodLenghts; cmbErikoistilanneKoti.ItemsSource = SpecialTeams; cmbErikoistilanneVieras.ItemsSource = SpecialTeams; HomePlayers = DBSalibandytournament.GetTeamPlayersFromDB(homeID); AwayPlayers = DBSalibandytournament.GetTeamPlayersFromDB(awayID); cmbTekijaKoti.ItemsSource = HomePlayers; cmbSyottajaKoti.ItemsSource = HomePlayers; cmbKarsijaKoti.ItemsSource = HomePlayers; cmbKarsijaVieras.ItemsSource = AwayPlayers; cmbTekijaVieras.ItemsSource = AwayPlayers; cmbSyottajaVieras.ItemsSource = AwayPlayers; }
public WpfPlayereditor(WpfPlayers playerWindow, Player player) { InitializeComponent(); this.player = player; txtID.Text = player.HenkiloId.ToString(); txtLastname.Text = player.Sukunimi; txtFirstname.Text = player.Etunimi; txtBirthday.Text = player.Syntymavuosi.ToString(); txtPlayernumber.Text = player.Pelinumero.ToString(); txtPosition.Text = player.Pelipaikka; txtRole.Text = player.Rooli; cmbTeams.SelectedValue = player.JoukkueId; Teams = DBSalibandytournament.GetTeamsFromDB(); cmbTeams.ItemsSource = Teams; this.playerWindow = playerWindow; }
private string FillOK() { if (txtLastname.Text == "" || txtFirstname.Text == "" || txtPlayernumber.Text == "" || cmbTeams.SelectedValue == null) { return("Täytä kaikki tähdellä merkityt kohdat ennen tallentamista."); } bool parseok = Int32.TryParse(cmbTeams.SelectedValue.ToString(), out int TeamID); List <Player> players = DBSalibandytournament.GetTeamPlayersFromDB(TeamID); foreach (Player p in players) { if (txtPlayernumber.Text == p.Pelinumero && txtID.Text != p.HenkiloId.ToString()) { return($"Pelinumero on jo käytössä joukkueessa {cmbTeams.Text}."); } } return("ok"); }
private void btnSavePerson_Click(object sender, RoutedEventArgs e) { try { //check that all info is correctly filled in if (FillOK() != "ok") { MessageBox.Show(FillOK()); return; } string Lastname = $"'{txtLastname.Text}'"; string Firstname = $"'{txtFirstname.Text}'"; string Playernumber = $"'{txtPlayernumber.Text}'"; string Position = $"'{txtPosition.Text}'"; string Birthyear = txtBirthday.Text == "" ? "NULL" : txtBirthday.Text; string Role = $"'{txtRole.Text}'"; bool parseok = Int32.TryParse(cmbTeams.SelectedValue.ToString(), out int TeamID); //if saving new person if (string.IsNullOrWhiteSpace(txtID.Text)) { string inserttablestring = "Henkilot (Sukunimi, Etunimi, Pelinumero, Pelipaikka, Syntymavuosi, Rooli, JoukkueID)"; string insertvaluestring = $"({Lastname}, {Firstname}, {Playernumber}, {Position}, {Birthyear}, {Role}, {TeamID})"; DBSalibandytournament.InsertIntoDB(inserttablestring, insertvaluestring); playerWindow.RefreshPlayers(); } //if updating existing person else { int PersonID = int.Parse(txtID.Text); string updatetablestring = "Henkilot"; string updatevaluestring = $"Sukunimi = {Lastname}, Etunimi = {Firstname}, Pelinumero = {Playernumber}, Pelipaikka = {Position}, Syntymavuosi = {Birthyear}, Rooli = {Role}, JoukkueID = {TeamID}"; string updatewherestring = $"HenkiloID = {PersonID}"; DBSalibandytournament.UpdateDB(updatetablestring, updatevaluestring, updatewherestring); playerWindow.RefreshPlayers(); } Close(); playerWindow.RefreshPlayers(); } catch (Exception ex) { MessageBox.Show("Tapahtui virhe: " + ex.ToString()); } }
//get players by team public static List <Player> GetTeamPlayersFromDB(int teamID) { List <Player> players = new List <Player>(); string str = $"Pelaajat WHERE JoukkueID = {teamID} ORDER BY Pelinumero"; DataTable dt = DBSalibandytournament.GetViewDB(str); foreach (DataRow item in dt.Rows) { if (item[3] != null) { Player p = new Player() { HenkiloId = int.Parse(item[0].ToString()), Pelinumero = item[3].ToString() }; players.Add(p); } } return(players); }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (FillOK() != "ok") { MessageBox.Show(FillOK()); return; } //convert time textbox to the right format for SQL DateTime date = Convert.ToDateTime(txtTime.Text); string Time = $"'{date.ToString("yyyy-MM-dd HH:mm:ss")}'"; string Location = $"'{txtLocation.Text}'"; bool parseokHome = Int32.TryParse(cmbHomeTeam.SelectedValue.ToString(), out int HomeTeamID); bool parseokAway = Int32.TryParse(cmbAwayTeam.SelectedValue.ToString(), out int AwayTeamID); //if saving new game if (string.IsNullOrWhiteSpace(txtID.Text)) { string inserttablestring = "Ottelu (Aika, Paikka, Kotijoukkue, Vierasjoukkue, Paatetty)"; string insertvaluestring = $"({Time}, {Location}, {HomeTeamID}, {AwayTeamID}, FALSE)"; DBSalibandytournament.InsertIntoDB(inserttablestring, insertvaluestring); } //if updating existing game else { int GameID = int.Parse(txtID.Text); string updatetablestring = "Ottelu"; string updatevaluestring = $"Aika = {Time}, Paikka = {Location}, Kotijoukkue = {HomeTeamID}, Vierasjoukkue = {AwayTeamID}"; string updatewherestring = $"OtteluID = {GameID}"; DBSalibandytournament.UpdateDB(updatetablestring, updatevaluestring, updatewherestring); } Close(); gamesWindow.RefreshGames(); } catch (Exception ex) { MessageBox.Show("Tapahtui virhe: " + ex.ToString()); } }
public static List <Penalty> GetPenaltiesFromDB(int gameID, int teamID) { List <Penalty> penalties = new List <Penalty>(); string str = $"Rangaistus WHERE Ottelu = {gameID} AND Joukkue = {teamID} ORDER BY RangaistusID"; DataTable dt = DBSalibandytournament.GetViewDB(str); int index = 0; foreach (DataRow item in dt.Rows) { Penalty p = new Penalty() { Rangaistusnro = ++index, RangaistusID = int.Parse(item[0].ToString()), Aika = item[1].ToString(), Kesto = int.Parse(item[2].ToString()), Syy = item[3].ToString(), Henkilo = int.Parse(item[4].ToString()), Joukkue = int.Parse(item[5].ToString()), Ottelu = int.Parse(item[6].ToString()) }; penalties.Add(p); } return(penalties); }
//constructors public WpfGamestatistics(WpfGames gamesWindow, Game game) { InitializeComponent(); FillCombo(game.KotiId, game.VierasId); txtGameId.Text = game.OtteluId.ToString(); txtHometeam.Text = game.KotiNimi; txtHomeId.Text = game.KotiId.ToString(); txtAwayteam.Text = game.VierasNimi; txtAwayId.Text = game.VierasId.ToString(); CalculateTotalTime(null, null); homegoals = DBSalibandytournament.GetGoalsFromDB(game.OtteluId, game.KotiId); homepenalties = DBSalibandytournament.GetPenaltiesFromDB(game.OtteluId, game.KotiId); awaygoals = DBSalibandytournament.GetGoalsFromDB(game.OtteluId, game.VierasId); awaypenalties = DBSalibandytournament.GetPenaltiesFromDB(game.OtteluId, game.VierasId); dgHomeGoals.ItemsSource = homegoals; dgHomePenalties.ItemsSource = homepenalties; dgAwayGoals.ItemsSource = awaygoals; dgAwayPenalties.ItemsSource = awaypenalties; gameID = game.OtteluId; gameStatus = game.Paatetty; //disable all controls if game has been ended/saved DisableControls(); this.gamesWindow = gamesWindow; }
public static List <Goal> GetGoalsFromDB(int gameID, int teamID) { List <Goal> goals = new List <Goal>(); string str = $"Maali WHERE Ottelu = {gameID} AND Joukkue = {teamID} ORDER BY MaaliID"; DataTable dt = DBSalibandytournament.GetViewDB(str); int index = 0; foreach (DataRow item in dt.Rows) { Goal g = new Goal() { Maalinro = ++index, MaaliID = int.Parse(item[0].ToString()), Aika = item[1].ToString(), Erikoistilanne = item[2].ToString(), Maalintekija = int.Parse(item[3].ToString()), Syottaja = ToNullableInt(item[4].ToString()), Joukkue = int.Parse(item[5].ToString()), Ottelu = int.Parse(item[6].ToString()) }; goals.Add(g); } return(goals); }
//constructors public WpfTeameditor(WpfTeams teamsWindow) { InitializeComponent(); Teams = DBSalibandytournament.GetTeamsFromDB(); this.teamsWindow = teamsWindow; }
//methods private void FillCombo() { Teams = DBSalibandytournament.GetTeamsFromDB(); cmbHomeTeam.ItemsSource = Teams; cmbAwayTeam.ItemsSource = Teams; }
public void RefreshPlayers() { this.Players = DBSalibandytournament.GetPlayersFromDB(); dgPlayers.ItemsSource = Players; }
//constructors public WpfTeams() { InitializeComponent(); Teams = DBSalibandytournament.GetTeamsFromDB(); RefreshTeams(); }
//methods public void RefreshTeams() { this.Teams = DBSalibandytournament.GetTeamsFromDB(); dgTeams.ItemsSource = Teams; }
public void RefreshGames() { this.games = DBSalibandytournament.GetGamesFromDB(); dgGames.ItemsSource = games; }