public void SetOrModifyTerminalProfile(TerminalProfile Profile) { if (Profile == null) { throw new ArgumentNullException(nameof(Profile), "Argument could not be null"); } using SqliteTransaction Transaction = Connection.BeginTransaction(); using SqliteCommand Command = new SqliteCommand("Select Count(*) From TerminalProfile Where Name = @Name", Connection, Transaction); Command.Parameters.AddWithValue("@Name", Profile.Name); int Count = Convert.ToInt32(Command.ExecuteScalar()); Command.CommandText = Count > 0 ? "Update TerminalProfile Set Path = @Path, Argument = @Argument, RunAsAdmin = @RunAsAdmin Where Name = @Name" : "Insert Into TerminalProfile Values (@Name,@Path,@Argument,@RunAsAdmin)"; Command.Parameters.AddWithValue("@Path", Profile.Path); Command.Parameters.AddWithValue("@Argument", Profile.Argument); Command.Parameters.AddWithValue("@RunAsAdmin", Convert.ToString(Profile.RunAsAdmin)); Command.ExecuteNonQuery(); Transaction.Commit(); }
public async Task DeleteTerminalProfile(TerminalProfile Profile) { if (Profile == null) { throw new ArgumentNullException(nameof(Profile), "Argument could not be null"); } using (SqliteCommand Command = new SqliteCommand("Delete From TerminalProfile Where Name = @Name", Connection)) { Command.Parameters.AddWithValue("@Name", Profile.Name); await Command.ExecuteNonQueryAsync().ConfigureAwait(false); } }
public void DeleteTerminalProfile(TerminalProfile Profile) { if (Profile == null) { throw new ArgumentNullException(nameof(Profile), "Argument could not be null"); } using (SqliteCommand Command = new SqliteCommand("Delete From TerminalProfile Where Name = @Name", Connection)) { Command.Parameters.AddWithValue("@Name", Profile.Name); Command.ExecuteNonQuery(); } }
public void SetTerminalProfile(TerminalProfile Profile) { if (Profile == null) { throw new ArgumentNullException(nameof(Profile), "Argument could not be null"); } using SqliteTransaction Transaction = Connection.BeginTransaction(); using SqliteCommand Command = new SqliteCommand("Insert Or Replace Into TerminalProfile Values (@Name,@Path,@Argument,@RunAsAdmin)", Connection, Transaction); Command.Parameters.AddWithValue("@Name", Profile.Name); Command.Parameters.AddWithValue("@Path", Profile.Path); Command.Parameters.AddWithValue("@Argument", Profile.Argument); Command.Parameters.AddWithValue("@RunAsAdmin", Convert.ToString(Profile.RunAsAdmin)); Command.ExecuteNonQuery(); Transaction.Commit(); }
public async Task SetOrModifyTerminalProfile(TerminalProfile Profile) { if (Profile == null) { throw new ArgumentNullException(nameof(Profile), "Argument could not be null"); } int Count = 0; using (SqliteCommand Command = new SqliteCommand("Select Count(*) From TerminalProfile Where Name = @Name", Connection)) { Command.Parameters.AddWithValue("@Name", Profile.Name); Count = Convert.ToInt32(await Command.ExecuteScalarAsync().ConfigureAwait(false)); } if (Count > 0) { using (SqliteCommand UpdateCommand = new SqliteCommand("Update TerminalProfile Set Path = @Path, Argument = @Argument, RunAsAdmin = @RunAsAdmin Where Name = @Name", Connection)) { UpdateCommand.Parameters.AddWithValue("@Name", Profile.Name); UpdateCommand.Parameters.AddWithValue("@Path", Profile.Path); UpdateCommand.Parameters.AddWithValue("@Argument", Profile.Argument); UpdateCommand.Parameters.AddWithValue("@RunAsAdmin", Convert.ToString(Profile.RunAsAdmin)); await UpdateCommand.ExecuteNonQueryAsync().ConfigureAwait(false); } } else { using (SqliteCommand AddCommand = new SqliteCommand("Insert Into TerminalProfile Values (@Name,@Path,@Argument,@RunAsAdmin)", Connection)) { AddCommand.Parameters.AddWithValue("@Name", Profile.Name); AddCommand.Parameters.AddWithValue("@Path", Profile.Path); AddCommand.Parameters.AddWithValue("@Argument", Profile.Argument); AddCommand.Parameters.AddWithValue("@RunAsAdmin", Convert.ToString(Profile.RunAsAdmin)); await AddCommand.ExecuteNonQueryAsync().ConfigureAwait(false); } } }