From e808cae59c9d4ee10f4ef57a1f67a565aa0f600f Mon Sep 17 00:00:00 2001 From: Professional Date: Wed, 19 Mar 2025 23:06:45 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BF=D0=BE=D0=BF=D1=8B?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 64 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 20 deletions(-) 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