Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            MaskedTextBox[] goalBoxesHome = { Goals1Home, Goals2Home, Goals3Home, Goals4Home, Goals5Home, Goals6Home, Goals7Home, Goals8Home, Goals9Home, Goals10Home, Goals11Home };
            MaskedTextBox[] goalBoxesAway = { Goals1Away, Goals2Away, Goals3Away, Goals4Away, Goals5Away, Goals6Away, Goals7Away, Goals8Away, Goals9Away, Goals10Away, Goals11Away };
            totalHome.Text = sumOfGoals(goalBoxesHome).ToString();

            totalAway.Text = sumOfGoals(goalBoxesAway).ToString();

            try
            {
                if (!matchDateBox.MaskCompleted || !matchTimeBox.MaskCompleted || competitionID.SelectedItem == null || homeTeamComboBox.SelectedItem == null || awayTeamComboBox.SelectedItem == null)
                {
                    MessageBox.Show("Please don't leave empty boxes");
                    return;
                }
                if (MessageBox.Show("Add this match?", "Match Database", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (!connectionWithDatabase.isConnected())
                    {
                        connectionWithDatabase.OpenConnection();
                    }
                    long matchID = connectionWithDatabase.AddMatch(matchDateBox, matchTimeBox, competitionID, homeTeamComboBox, awayTeamComboBox, Winner(totalHome, totalAway));
                    for (int i = 0; i < 11; i++)
                    {
                        connectionWithDatabase.addGoalsToPlayer(homeTeamComboBox, i, int.Parse(goalBoxesHome[i].Text), matchID);
                        connectionWithDatabase.addGoalsToPlayer(awayTeamComboBox, i, int.Parse(goalBoxesAway[i].Text), matchID);
                    }
                }
            }
            catch (Exception es)
            {
                MessageBox.Show("Error 404 in adding Team. Check DataBaseConnection \r\n" + es.Message + "\r\n" + es.InnerException.Message);
            }
            finally
            {
                connectionWithDatabase.CloseConnection();
            }
        }