diff --git a/Program.cs b/Program.cs index 185e898..c3ac8a1 100644 --- a/Program.cs +++ b/Program.cs @@ -170,6 +170,11 @@ class Program await ShowReportDetails(botClient, chatId, reportId, messageId); } } + else if (data != null && data.StartsWith("delete_")) + { + long reportId = long.Parse(data.Substring(7)); + await DeleteReport(botClient, chatId, reportId); + } else if (data == "back_to_list") { await ViewReports(botClient, chatId); @@ -273,6 +278,29 @@ class Program } } + private static async Task DeleteReport(ITelegramBotClient botClient, long chatId, long reportId) + { + try + { + using (var connection = new SqliteConnection("Data Source=bot.db")) + { + await connection.OpenAsync(); + var command = connection.CreateCommand(); + command.CommandText = "DELETE FROM Reports WHERE Id = @id"; + command.Parameters.AddWithValue("@id", reportId); + await command.ExecuteNonQueryAsync(); + + await botClient.SendMessage(chatId, $"Заявка #{reportId} успешно удалена."); + Log.Information($"Заявка #{reportId} удалена пользователем {chatId}."); + } + } + catch (Exception ex) + { + Log.Error($"Ошибка при удалении заявки #{reportId}: {ex.Message}"); + await botClient.SendMessage(chatId, $"Ошибка при удалении заявки #{reportId}."); + } + } + @@ -375,6 +403,10 @@ class Program InlineKeyboardButton.WithCallbackData("🟢 Закрыта", $"status_{reportId}_закрыта") }, new[] + { + InlineKeyboardButton.WithCallbackData("❌ Удалить заявку", $"delete_{reportId}") + }, + new[] { InlineKeyboardButton.WithCallbackData("Назад", "back_to_list"), InlineKeyboardButton.WithCallbackData("Главное меню", "main_menu") @@ -388,7 +420,6 @@ class Program text: newText, replyMarkup: statusButtons ); - } } } @@ -436,9 +467,9 @@ class Program var insertCommand = connection.CreateCommand(); insertCommand.CommandText = @" - INSERT INTO Reports (ChatId, Description) - VALUES (@ChatId, @Description); - "; + INSERT INTO Reports (ChatId, Description, Status) + VALUES (@ChatId, @Description, 'ожидает'); + "; insertCommand.Parameters.AddWithValue("@ChatId", chatId); insertCommand.Parameters.AddWithValue("@Description", description); @@ -452,6 +483,7 @@ class Program } } + private static async Task CreateDatabaseIfNotExists() { string connectionString = "Data Source=bot.db"; // Путь к вашей базе данных