private void SignPlayer(object sender, MouseButtonEventArgs e) { if (FreePlayersGrid.SelectedIndex > 0) { PlayerDetail win2 = new PlayerDetail(databaseName, 0 - coaches.ElementAt(FreePlayersGrid.SelectedIndex).IdCoach, false); win2.ShowDialog(); AddPlayersToGrid(); } /*int training, teamId, reputation, salary, budget; * string nick, date; * if (FreePlayersGrid.SelectedIndex >= 0) * { * using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=.\" + databaseName + ";")) * { * conn.Open(); * SQLiteCommand command = new SQLiteCommand("select nick, training from coach where id_coach=" + coaches.ElementAt(FreePlayersGrid.SelectedIndex).IdCoach + ";", conn); * SQLiteDataReader reader = command.ExecuteReader(); * reader.Read(); * nick = reader.GetString(0); * training = reader.GetInt32(1); * reader.Close(); * command = new SQLiteCommand("select id_team, date from info;", conn); * reader = command.ExecuteReader(); * reader.Read(); * teamId = reader.GetInt32(0); * date = reader.GetString(1); * reader.Close(); * command = new SQLiteCommand("select reputation, budget from team where id_team=" + teamId + ";", conn); * reader = command.ExecuteReader(); * reader.Read(); * reputation = reader.GetInt32(0); * budget = reader.GetInt32(1); * reader.Close(); * if (training > reputation + 10) * { * MessageBox.Show("Trenér nemá zájem hrát ve vašem týmu", "Podpis smlouvy", MessageBoxButton.OK); * } else if (budget < 0){ * MessageBox.Show("Nemáte dostatek financí na podpis hráče.", "Podpis smlouvy", MessageBoxButton.OK); * } else * { * salary = 1000 + (int)((reputation * training - 3600) * 0.765); * MessageBoxResult result = MessageBox.Show("Chystáte se podepsat smlouvu s trenérem " + nick + ". Jeho smlouva je na rok za " + salary + "$ měsíčně. Chcete smlouvu podepsat?", "Podpis smlouvy", MessageBoxButton.YesNo); * if (result == MessageBoxResult.Yes) * { * int year = int.Parse(date.Remove(4, 6)); * year++; * date = year.ToString() + date.Remove(0, 4); * int playerValue = (salary * 100 / 3); * playerValue = playerValue / 100; * playerValue = playerValue * 100; * command = new SQLiteCommand("update coach set id_team=" + teamId + ", contractEnd='" + date +"', value=" + playerValue + ", salary=" + salary + " where id_coach=" + coaches.ElementAt(FreePlayersGrid.SelectedIndex).IdCoach + ";", conn); * command.ExecuteReader(); * } * } * } * * }*/ //AddPlayersToGrid(); }
private void SignPlayer(object sender, MouseButtonEventArgs e) { DataGrid d = (DataGrid)sender; if (d.SelectedIndex > -1) { List <Player> l = (List <Player>)d.ItemsSource; if (l.ElementAt(d.SelectedIndex).IdPlayer != 0) { PlayerDetail win2 = new PlayerDetail(databaseName, l.ElementAt(d.SelectedIndex).IdPlayer); win2.ShowDialog(); } } }