command.CommandText="SELECT logs_db_path FROM app_settings LIMIT 1";
SqliteDataReaderreader=command.ExecuteReader();
while(reader.Read())
{
returnreader["logs_db_path"].ToString();
}
returngetDefaultPathAppLogs();
}
publicstaticvoidCreateLogsTable()
{
SqliteCommandcommand=newSqliteCommand();
command.Connection=logsDb;
command.CommandText="CREATE TABLE IF NOT EXISTS logs_actions (id INTEGER PRIMARY KEY, name TEXT NOT NULL)";
command.ExecuteNonQuery();
command.CommandText="INSERT OR IGNORE INTO logs_actions (id, name) VALUES (0, 'Выполнение');";
command.ExecuteNonQuery();
command.CommandText="CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, date TEXT NOT NULL, action INTEGER NOT NULL, message TEXT NOT NULL, FOREIGN KEY(action) REFERENCES logs_actions(id));";
command.CommandText="CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, login TEXT NOT NULL UNIQUE, password TEXT NOT NULL, role_id INTEGER NOT NULL, FOREIGN KEY(role_id) REFERENCES roles(id));";
command.ExecuteNonQuery();
// Если таблица пуста - добавить пользователя по умолчанию
command.CommandText="SELECT COUNT(*) FROM users";
if(Convert.ToInt32(command.ExecuteScalar())==0)
{
command.CommandText="INSERT INTO users (login, password, role_id) VALUES ('admin', @password, 1);";