diff --git a/Program.cs b/Program.cs index 9baa936..2348c2f 100644 --- a/Program.cs +++ b/Program.cs @@ -562,9 +562,9 @@ class Program { await connection.OpenAsync(); var command = connection.CreateCommand(); - command.CommandText = "SELECT Id, Description, Status, Priority FROM Reports WHERE Status != 'закрыта' ORDER BY CASE Priority WHEN 'высокий' THEN 1 WHEN 'средний' THEN 2 ELSE 3 END"; + command.CommandText = "SELECT Id, Description, Status, Priority FROM Reports WHERE Status != 'закрыта'"; - var buttons = new List(); + var reports = new List<(long Id, string Description, string Status, string Priority)>(); using (var reader = await command.ExecuteReaderAsync()) { @@ -574,18 +574,29 @@ class Program string description = reader.GetString(1).Substring(0, Math.Min(20, reader.GetString(1).Length)); string status = reader.GetString(2); string priority = reader.GetString(3); - string statusEmoji = GetStatusEmoji(status); - string priorityMarker = priority.ToLower() == "высокий" ? "⚠️" : ""; - buttons.Add(new[] - { - InlineKeyboardButton.WithCallbackData( - $"{priorityMarker} #{id} - {statusEmoji} {status} - {description}...", - $"report_{id}") - }); + reports.Add((id, description, status, priority)); } } + // Сортируем заявки по приоритету + reports.Sort((x, y) => string.Compare(y.Priority, x.Priority, StringComparison.Ordinal)); + + var buttons = new List(); + + foreach (var report in reports) + { + string statusEmoji = GetStatusEmoji(report.Status); + string priorityMarker = report.Priority.ToLower() == "высокий" ? "⚠️" : ""; + + buttons.Add(new[] + { + InlineKeyboardButton.WithCallbackData( + $"{priorityMarker} #{report.Id} - {statusEmoji} {report.Status} - {report.Description}...", + $"report_{report.Id}") + }); + } + // Добавляем кнопки навигации buttons.Add(new[] { @@ -611,6 +622,7 @@ class Program + private static async Task ViewArchivedReports(ITelegramBotClient botClient, long chatId) { string connectionString = "Data Source=bot.db"; @@ -621,9 +633,9 @@ class Program { await connection.OpenAsync(); var command = connection.CreateCommand(); - command.CommandText = "SELECT Id, Description, Status, Priority FROM Reports WHERE Status = 'закрыта' ORDER BY CASE Priority WHEN 'высокий' THEN 1 WHEN 'средний' THEN 2 ELSE 3 END"; + command.CommandText = "SELECT Id, Description, Status, Priority FROM Reports WHERE Status = 'закрыта'"; - var buttons = new List(); + var reports = new List<(long Id, string Description, string Status, string Priority)>(); using (var reader = await command.ExecuteReaderAsync()) { @@ -633,18 +645,29 @@ class Program string description = reader.GetString(1).Substring(0, Math.Min(20, reader.GetString(1).Length)); string status = reader.GetString(2); string priority = reader.GetString(3); - string statusEmoji = GetStatusEmoji(status); - string priorityMarker = priority.ToLower() == "высокий" ? "⚠️" : ""; - buttons.Add(new[] - { - InlineKeyboardButton.WithCallbackData( - $"{priorityMarker} #{id} - {statusEmoji} {status} - {description}...", - $"report_{id}") - }); + reports.Add((id, description, status, priority)); } } + // Сортируем заявки по приоритету + reports.Sort((x, y) => string.Compare(y.Priority, x.Priority, StringComparison.Ordinal)); + + var buttons = new List(); + + foreach (var report in reports) + { + string statusEmoji = GetStatusEmoji(report.Status); + string priorityMarker = report.Priority.ToLower() == "высокий" ? "⚠️" : ""; + + buttons.Add(new[] + { + InlineKeyboardButton.WithCallbackData( + $"{priorityMarker} #{report.Id} - {statusEmoji} {report.Status} - {report.Description}...", + $"report_{report.Id}") + }); + } + // Добавляем кнопки навигации buttons.Add(new[] { @@ -669,6 +692,7 @@ class Program + private static async Task ShowReportDetails(ITelegramBotClient botClient, long chatId, long reportId, int messageId) { try