public List<ProgramDTO> GetPrograms() { var programList = new List<ProgramDTO>(); using (var sqlConnection = new SqlConnection(connectionString)) { var sqlCommand = new SqlCommand { Connection = sqlConnection, CommandText = @"SELECT * FROM Programs ORDER BY ProgramName" }; sqlConnection.Open(); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { var dto = new ProgramDTO() { ProgramId = Convert.ToInt32(reader["ProgramId"]), ProgramName = reader["ProgramName"].ToString(), Language = reader["Language"].ToString(), Path = reader["Path"].ToString(), Comments = reader["Comments"].ToString(), PrimaryUser = reader["PrimaryUser"].ToString(), Status = reader["Status"].ToString(), Notes = reader["Notes"].ToString(), Developer = reader["Developer"].ToString(), InProduction = reader["InProduction"] != DBNull.Value && Convert.ToBoolean(reader["InProduction"]), }; programList.Add(dto); } } return programList; }
public void AddProgram(ProgramDTO dto) { using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(@"INSERT INTO Programs (ProgramName, Language, Path, Comments, PrimaryUser, Status, Notes, Developer, InProduction) VALUES (@ProgramName, @Language, @Path, @Comments, @PrimaryUser, @Status, @Notes, @Developer, @InProduction)"); conn.Open(); command.CommandType = CommandType.Text; command.Connection = conn; command.Parameters.AddWithValue("@ProgramName", dto.ProgramName); command.Parameters.AddWithValue("@Language", dto.Language); command.Parameters.AddWithValue("@Path", dto.Path); command.Parameters.AddWithValue("@Comments", dto.Comments); command.Parameters.AddWithValue("@PrimaryUser", dto.PrimaryUser); command.Parameters.AddWithValue("@Status", dto.Status); command.Parameters.AddWithValue("@Notes", dto.Notes); command.Parameters.AddWithValue("@Developer", dto.Developer); command.Parameters.AddWithValue("@InProduction", dto.InProduction); command.ExecuteNonQuery(); // UsageLogger.LogThis(command); } }
public void EditProgramInformation(ProgramDTO dto) { using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(@"UPDATE Programs SET Comments = @Comments, PrimaryUser = @PrimaryUser, Status = @Status, Notes = @Notes, Developer = @Developer, InProduction = @InProduction WHERE ProgramId = @ProgramId"); cmd.CommandType = CommandType.Text; cmd.Connection = connection; cmd.Parameters.AddWithValue("@Comments", dto.Comments); cmd.Parameters.AddWithValue("@PrimaryUser", dto.PrimaryUser); cmd.Parameters.AddWithValue("@Status", dto.Status); cmd.Parameters.AddWithValue("@Notes", dto.Notes); cmd.Parameters.AddWithValue("@Developer", dto.Developer); cmd.Parameters.AddWithValue("@InProduction", dto.InProduction); cmd.Parameters.AddWithValue("@ProgramId", dto.ProgramId); connection.Open(); cmd.ExecuteNonQuery(); UsageLogger.LogThis(cmd); } }
private void AddProgram() { AddingProgram = true; Program = new ProgramDTO() { Comments = "", Notes = "", Language = "C#", Developer = Environment.UserName }; }