Exemple #1
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (gameStatus == false)
     {
         MessageBoxResult result = MessageBox.Show("Ottelua ei ole päätetty (maaleja ja rangaistuksia ei ole tallennettu). Jos suljet ikkunan, tiedot menetetään. Haluatko varmasti sulkea ikkunan?", "Varoitus", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
         if (result == MessageBoxResult.No)
         {
             e.Cancel = true;
         }
     }
     gamesWindow.RefreshGames();
 }
Exemple #2
0
 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());
     }
 }