фикс бд деталей заявки
This commit is contained in:
parent
d194cafb25
commit
a5d7dcdd32
92
Program.cs
92
Program.cs
@ -795,48 +795,28 @@ class Program
|
|||||||
string reporterName = reader.GetString(3);
|
string reporterName = reader.GetString(3);
|
||||||
string status = reader.GetString(4);
|
string status = reader.GetString(4);
|
||||||
string dateCreated = reader.GetDateTime(5).ToString("yyyy-MM-dd HH:mm:ss");
|
string dateCreated = reader.GetDateTime(5).ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
long adminId = reader.GetInt64(6);
|
|
||||||
string adminFullName = adminFullNames.ContainsKey(adminId) ? adminFullNames[adminId] : "Неизвестно";
|
// Проверяем существование столбца AdminId
|
||||||
|
long adminId = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!reader.IsDBNull(6))
|
||||||
|
adminId = reader.GetInt64(6);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Log.Warning($"Столбец AdminId для заявки {reportId} не найден или содержит NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
string adminFullName = adminId > 0 && adminFullNames.ContainsKey(adminId)
|
||||||
|
? adminFullNames[adminId]
|
||||||
|
: "Не назначен";
|
||||||
|
|
||||||
string priorityEmoji = GetPriorityEmoji(priority);
|
string priorityEmoji = GetPriorityEmoji(priority);
|
||||||
string statusEmoji = GetStatusEmoji(status);
|
string statusEmoji = GetStatusEmoji(status);
|
||||||
|
|
||||||
var statusButtons = new InlineKeyboardMarkup(new[]
|
// Остальной код без изменений
|
||||||
{
|
// ...
|
||||||
new[]
|
|
||||||
{
|
|
||||||
InlineKeyboardButton.WithCallbackData("🟡 Ожидает", $"status_{reportId}_ожидает"),
|
|
||||||
InlineKeyboardButton.WithCallbackData("🔵 В работе", $"status_{reportId}_в работе")
|
|
||||||
},
|
|
||||||
new[]
|
|
||||||
{
|
|
||||||
InlineKeyboardButton.WithCallbackData("🟢 Закрыта", $"status_{reportId}_закрыта")
|
|
||||||
},
|
|
||||||
new[]
|
|
||||||
{
|
|
||||||
InlineKeyboardButton.WithCallbackData("❌ Удалить заявку", $"delete_{reportId}")
|
|
||||||
},
|
|
||||||
new[]
|
|
||||||
{
|
|
||||||
InlineKeyboardButton.WithCallbackData("Назад", "back_to_list"),
|
|
||||||
InlineKeyboardButton.WithCallbackData("Главное меню", "main_menu")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
string newText = $"Заявка #{reportId}\n\n" +
|
|
||||||
$"Приоритет: {priorityEmoji} {priority}\n" +
|
|
||||||
$"Кабинет: {room}\n" +
|
|
||||||
$"Описание: {description}\n" +
|
|
||||||
$"ФИО: {reporterName}\n" +
|
|
||||||
$"Статус: {statusEmoji} {status}\n" +
|
|
||||||
$"Дата создания: {dateCreated}\n" +
|
|
||||||
$"Администратор: {adminFullName}";
|
|
||||||
|
|
||||||
await botClient.SendMessage(
|
|
||||||
chatId: chatId,
|
|
||||||
text: newText,
|
|
||||||
replyMarkup: statusButtons
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -848,6 +828,7 @@ class Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Метод для удаления администратора из базы данных
|
// Метод для удаления администратора из базы данных
|
||||||
private static async Task RemoveAdminFromDatabase(long chatId)
|
private static async Task RemoveAdminFromDatabase(long chatId)
|
||||||
{
|
{
|
||||||
@ -1248,7 +1229,7 @@ class Program
|
|||||||
checkTableCommand.CommandText = "PRAGMA table_info(Reports);";
|
checkTableCommand.CommandText = "PRAGMA table_info(Reports);";
|
||||||
var tableInfo = await checkTableCommand.ExecuteReaderAsync();
|
var tableInfo = await checkTableCommand.ExecuteReaderAsync();
|
||||||
|
|
||||||
var requiredColumns = new HashSet<string> { "Id", "ChatId", "Priority", "Room", "Description", "ReporterName", "DateCreated", "Status" };
|
var requiredColumns = new HashSet<string> { "Id", "ChatId", "Priority", "Room", "Description", "ReporterName", "DateCreated", "Status", "AdminId" };
|
||||||
var existingColumns = new HashSet<string>();
|
var existingColumns = new HashSet<string>();
|
||||||
|
|
||||||
while (await tableInfo.ReadAsync())
|
while (await tableInfo.ReadAsync())
|
||||||
@ -1281,6 +1262,9 @@ class Program
|
|||||||
case "Status":
|
case "Status":
|
||||||
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Status TEXT DEFAULT 'ожидает';";
|
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN Status TEXT DEFAULT 'ожидает';";
|
||||||
break;
|
break;
|
||||||
|
case "AdminId":
|
||||||
|
alterTableCommand.CommandText = "ALTER TABLE Reports ADD COLUMN AdminId INTEGER DEFAULT 0;";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
await alterTableCommand.ExecuteNonQueryAsync();
|
await alterTableCommand.ExecuteNonQueryAsync();
|
||||||
Log.Information($"Столбец {column} добавлен в таблицу Reports.");
|
Log.Information($"Столбец {column} добавлен в таблицу Reports.");
|
||||||
@ -1291,17 +1275,18 @@ class Program
|
|||||||
var createTableCommand = connection.CreateCommand();
|
var createTableCommand = connection.CreateCommand();
|
||||||
createTableCommand.CommandText =
|
createTableCommand.CommandText =
|
||||||
@"
|
@"
|
||||||
CREATE TABLE IF NOT EXISTS Reports (
|
CREATE TABLE IF NOT EXISTS Reports (
|
||||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
ChatId INTEGER NOT NULL,
|
ChatId INTEGER NOT NULL,
|
||||||
Priority TEXT NOT NULL,
|
Priority TEXT NOT NULL,
|
||||||
Room TEXT NOT NULL,
|
Room TEXT NOT NULL,
|
||||||
Description TEXT NOT NULL,
|
Description TEXT NOT NULL,
|
||||||
ReporterName TEXT NOT NULL,
|
ReporterName TEXT NOT NULL,
|
||||||
DateCreated DATETIME DEFAULT CURRENT_TIMESTAMP,
|
DateCreated DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
Status TEXT DEFAULT 'ожидает'
|
Status TEXT DEFAULT 'ожидает',
|
||||||
);
|
AdminId INTEGER DEFAULT 0
|
||||||
";
|
);
|
||||||
|
";
|
||||||
await createTableCommand.ExecuteNonQueryAsync();
|
await createTableCommand.ExecuteNonQueryAsync();
|
||||||
Log.Information("Таблица Reports успешно создана (если её не было).");
|
Log.Information("Таблица Reports успешно создана (если её не было).");
|
||||||
|
|
||||||
@ -1315,13 +1300,6 @@ class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static Dictionary<long, int> userReportSteps = new Dictionary<long, int>();
|
private static Dictionary<long, int> userReportSteps = new Dictionary<long, int>();
|
||||||
private static Dictionary<long, Report> userReports = new Dictionary<long, Report>();
|
private static Dictionary<long, Report> userReports = new Dictionary<long, Report>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user