protected virtual async Task SaveGame() { date = DateTime.Now; timer1.Enabled = false; //label2.Text = @"Все планеты расставлены верно"; //label2.Visible = false; var command = new SqlCommand("UPDATE [Records] set Time = @Time where Name = @Name", await MainFrm.GetSqlConnection()); var command1 = new SqlCommand("UPDATE [Records] set Date = @Date where Name = @Name", await MainFrm.GetSqlConnection()); TimeSpan t = TimeSpan.FromSeconds(_gameDurationSec); command.Parameters.AddWithValue("Time", t); command1.Parameters.AddWithValue("Date", date); command.Parameters.AddWithValue("Name", MainFrm.UserId); command1.Parameters.AddWithValue("Name", MainFrm.UserId); await command.ExecuteNonQueryAsync(); await command1.ExecuteNonQueryAsync(); //Close(); //Может что-то важное закоментил!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
private async void SaveName(string newName) { var existingName = await _mainForm.GetName(newName); if (existingName == null) { using var sqlConnection = await MainFrm.GetSqlConnection(); var command = new SqlCommand("INSERT INTO [Records] (Name) VALUES (@newName)", sqlConnection); command.Parameters.AddWithValue("newName", newName); await command.ExecuteNonQueryAsync(); await _mainForm.LoadName(); Close(); } else { label2.Text = @"Такое имя уже есть!"; } }
private async void Defeat() { for (int i = 0; i <= 4; i++) { if (((earthHorizontal > asteroidsHorizontal[i] - 60)) && ((earthVertical > asteroidsVertical[i] - 60) && (earthVertical < asteroidsVertical[i] + asteroidsHeightWidth[i]))) { if ((earthHorizontal < asteroidsHorizontal[i] + asteroidsHeightWidth[i])) { earth = "objectOff.png"; timer1.Enabled = false; DialogResult dialog = new DialogResult(); dialog = MessageBox.Show("Хочешь попробовать сыграть ещё?", "Твои очки: " + score, MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { score = 0; earthHorizontal = 30; earthVertical = 280; AsteroidsGenerate(i); earth = "Earth.png"; label1.Text = "Очки: " + score.ToString(); for (i = 0; i <= 4; i++) { asteroidAlive[i] = false; } timer1.Enabled = true; } if (dialog == DialogResult.No) { var command = new SqlCommand("UPDATE [Records] set Points = @Score where Name = @Name", await MainFrm.GetSqlConnection()); command.Parameters.AddWithValue("Score", score); command.Parameters.AddWithValue("Name", MainFrm.UserId); if (score >= 2) { var command1 = new SqlCommand("UPDATE [Records] set Level = @level where Name = @Name", await MainFrm.GetSqlConnection()); command1.Parameters.AddWithValue("level", 2); command1.Parameters.AddWithValue("Name", MainFrm.UserId); } if (score > 0) { var command2 = new SqlCommand("UPDATE [Records] set Level= @level where Name = @Name", await MainFrm.GetSqlConnection()); command2.Parameters.AddWithValue("level", 1); command2.Parameters.AddWithValue("Name", MainFrm.UserId); await command2.ExecuteNonQueryAsync(); } if (score >= 5) { var command3 = new SqlCommand("UPDATE [Records] set Level = @level where Name = @Name", await MainFrm.GetSqlConnection()); command3.Parameters.AddWithValue("level", 3); command3.Parameters.AddWithValue("Name", MainFrm.UserId); await command3.ExecuteNonQueryAsync(); } if (score == 0) { var command4 = new SqlCommand("UPDATE [Records] set Level = @level where Name = @Name", await MainFrm.GetSqlConnection()); command4.Parameters.AddWithValue("level", 0); command4.Parameters.AddWithValue("Name", MainFrm.UserId); await command4.ExecuteNonQueryAsync(); } if (score >= 10) { var command3 = new SqlCommand("UPDATE [Records] set Level = @level where Name = @Name", await MainFrm.GetSqlConnection()); command3.Parameters.AddWithValue("level", 4); command3.Parameters.AddWithValue("Name", MainFrm.UserId); await command3.ExecuteNonQueryAsync(); } await command.ExecuteNonQueryAsync(); Close(); } } } } }