コード例 #1
0
        public static DiarioImpreso GetDiario(int?id)
        {
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand    command    = connection.CreateCommand();

            connection.Open();
            command.CommandText = "Select * from DiarioImpreso where DiarioId = @id";
            command.Parameters.AddWithValue("@id", id);
            SqlDataReader reader = command.ExecuteReader();
            DiarioImpreso diario = new DiarioImpreso();

            while (reader.Read())
            {
                diario.DiarioID = (int)reader["DiarioID"];
                diario.Nombre   = reader["Nombre"] as string;
            }
            return(diario);
        }
コード例 #2
0
        public static IEnumerable <DiarioImpreso> GetDiarios()
        {
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand    command    = connection.CreateCommand();

            connection.Open();
            command.CommandText = "Select *from DiarioImpreso";
            SqlDataReader        reader  = command.ExecuteReader();
            List <DiarioImpreso> diarios = new List <DiarioImpreso>();

            while (reader.Read())
            {
                DiarioImpreso diario = new DiarioImpreso();
                diario.DiarioID = (int)reader["DiarioID"];
                diario.Nombre   = reader["Nombre"] as string;
                diarios.Add(diario);
            }
            return(diarios);
        }
コード例 #3
0
 public ActionResult Edit(DiarioImpreso diario)
 {
     try
     {
         bool success = DiarioRepository.UpdateDiario(diario);
         if (success)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     catch
     {
         return(View());
     }
 }
コード例 #4
0
        public static bool UpdateDiario(DiarioImpreso diario)
        {
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand    command    = connection.CreateCommand();

            command.CommandText = @"update DiarioImpreso set Nombre = @nombre where DiarioID = @diarioID";
            command.Parameters.AddWithValue("@nombre", diario.Nombre);
            command.Parameters.AddWithValue("@diarioID", diario.DiarioID);
            connection.Open();
            int result = command.ExecuteNonQuery();

            connection.Close();
            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #5
0
        public static bool InsertDiario(DiarioImpreso diario)
        {
            SqlConnection connection = new SqlConnection(ConnectionString);
            SqlCommand    command    = connection.CreateCommand();

            command.CommandText = @"insert into DiarioImpreso(Nombre)
                                    values(@nombre)";
            command.Parameters.AddWithValue("@nombre", diario.Nombre);
            connection.Open();
            int result = command.ExecuteNonQuery();

            connection.Close();
            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }