public void UpdateCommand(DtoCommand dtocommand) { string sql = "UPDATE `commands` " + "SET `name`= @name,`usage`= @usage,`description`= @description " + "WHERE `id` = @id"; using (MySqlConnection conn = Sqlconnection()) { try { using (MySqlCommand command = new MySqlCommand(sql, conn)) { command.Parameters.AddWithValue("@id", dtocommand.Id); command.Parameters.AddWithValue("@name", dtocommand.Name); command.Parameters.AddWithValue("@usage", dtocommand.Usage); command.Parameters.AddWithValue("@description", dtocommand.Description); command.ExecuteNonQuery(); } } catch (Exception e) { Console.WriteLine(e); throw new Exception(e.Message); } } }
public void AddCommand(ICommand model) { DtoCommand DALobj = new DtoCommand() { Id = model.Id, Name = model.Name, Description = model.Description, Usage = model.Usage }; _dalClass.AddCommand(DALobj); }
/// <summary> /// Gets commands table from db. /// </summary> public List <DtoCommand> GetCommands() { List <DtoCommand> objList = new List <DtoCommand>(); DtoCommand dtoCommand; string sql = "SELECT `id`, `name`, `usage`, `description` from commands"; using (MySqlConnection conn = Sqlconnection()) { try { using (MySqlCommand query = new MySqlCommand(sql, conn)) { using (MySqlDataReader reader = query.ExecuteReader()) { while (reader.Read()) { dtoCommand = new DtoCommand() { Id = reader.GetInt32(0), Name = reader.GetString(1), Usage = reader.GetInt32(2), Description = reader.GetString(3) }; objList.Add(dtoCommand); } return(objList); } } } catch (Exception e) { Console.WriteLine(e); throw new Exception(e.Message); } } }
/// <summary> /// executes an 'insert into' query on to database /// </summary> /// <param name="dtocommand"></param> public void AddCommand(DtoCommand dtocommand) { string sql = "INSERT INTO `commands` (`name`, `usage`, `description`) " + "VALUES (@name, @usage, @description)"; using (MySqlConnection conn = Sqlconnection()) { try { using (MySqlCommand command = new MySqlCommand(sql, conn)) { command.Parameters.AddWithValue("@name", dtocommand.Name); command.Parameters.AddWithValue("@usage", dtocommand.Usage); command.Parameters.AddWithValue("@description", dtocommand.Description); command.ExecuteNonQuery(); } } catch (Exception e) { Console.WriteLine(e); throw new Exception(e.Message); } } }
public object Response(Response response) { // start from this position since standard fields (status, session ID) has been already parsed int offset = 5; DtoCommand command = new DtoCommand(); if (response == null) { return command; } // operation specific fields command.PayloadStatus = (PayloadStatus)BinaryParser.ToByte(response.Data.Skip(offset).Take(1).ToArray()); offset += 1; if (OperationMode == OperationMode.Asynchronous) { command.Content = new List<DtoRecord>(); while (command.PayloadStatus != PayloadStatus.NoRemainingRecords) { switch (command.PayloadStatus) { case PayloadStatus.ResultSet: DtoRecord record = new DtoRecord(); int contentLength = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; record.Content = response.Data.Skip(offset).Take(contentLength).ToArray(); offset += contentLength; record.Version = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; record.Type = (ORecordType)BinaryParser.ToByte(response.Data.Skip(offset).Take(1).ToArray()); offset += 1; ((List<DtoRecord>)command.Content).Add(record); break; case PayloadStatus.PreFetched: // TODO: break; default: break; } command.PayloadStatus = (PayloadStatus)BinaryParser.ToByte(response.Data.Skip(offset).Take(1).ToArray()); offset += 1; } } else { DtoRecord record; int contentLength; switch (command.PayloadStatus) { case PayloadStatus.NullResult: command.Content = null; break; case PayloadStatus.SingleRecord: record = new DtoRecord(); contentLength = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; record.Content = response.Data.Skip(offset).Take(contentLength).ToArray(); offset += contentLength; record.Version = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; record.Type = (ORecordType)BinaryParser.ToByte(response.Data.Skip(offset).Take(1).ToArray()); offset += 1; command.Content = record; break; case PayloadStatus.SerializedResult: contentLength = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; command.Content = response.Data.Skip(offset).Take(contentLength).ToArray(); offset += contentLength; break; case PayloadStatus.RecordCollection: command.Content = new List<DtoRecord>(); int recordsCount = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; for (int i = 0; i < recordsCount; i++) { record = new DtoRecord(); contentLength = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; record.Content = response.Data.Skip(offset).Take(contentLength).ToArray(); offset += contentLength; record.Version = BinaryParser.ToInt(response.Data.Skip(offset).Take(4).ToArray()); offset += 4; record.Type = (ORecordType)BinaryParser.ToByte(response.Data.Skip(offset).Take(1).ToArray()); offset += 1; ((List<DtoRecord>)command.Content).Add(record); } break; default: break; } } return command; }