public static BE.PhotoGallery[] SelectAll(string Catagory) { ArrayList photoGallerys = new ArrayList(); BE.PhotoGallery photoGallery; string SQLQuery = "SELECT * FROM [PhotoGallery] where Catagory= @Catagory"; SqlCommand command = new SqlCommand(); command.CommandText = SQLQuery; command.Parameters.AddWithValue("@Catagory", Catagory); SqlDataReader reader = SQLHelper.ExecuteReader(command); while (reader.Read()) { photoGallery = new BE.PhotoGallery(); photoGallery.Id = Convert.ToInt32(reader["Id"]); photoGallery.Title = Convert.ToString(reader["Title"]); photoGallery.Thumbnails = Convert.ToString(reader["Thumbnails"]); photoGallery.NormalPicture = Convert.ToString(reader["NormalPicture"]); photoGallery.Publish = Convert.ToString(reader["Publish"]); photoGallery.Catagory = Convert.ToInt32(reader["Catagory"]); photoGallerys.Add(photoGallery); } reader.Close(); reader.Dispose(); return((BE.PhotoGallery[])photoGallerys.ToArray(typeof(BE.PhotoGallery))); }
public static BE.PhotoGallery Select(Int32 Id) { BE.PhotoGallery photoGallery = new BE.PhotoGallery(); string SQLQuery = "SELECT * FROM [PhotoGallery] WHERE [Id]=@Id "; SqlCommand command = new SqlCommand(); command.CommandText = SQLQuery; command.Parameters.AddWithValue("@Id", Id); SqlDataReader reader = SQLHelper.ExecuteReader(command); reader.Read(); photoGallery.Id = Convert.ToInt32(reader["Id"]); photoGallery.Title = Convert.ToString(reader["Title"]); photoGallery.Thumbnails = Convert.ToString(reader["Thumbnails"]); photoGallery.NormalPicture = Convert.ToString(reader["NormalPicture"]); photoGallery.Publish = Convert.ToString(reader["Publish"]); photoGallery.Catagory = Convert.ToInt32(reader["Catagory"]); reader.Close(); reader.Dispose(); return(photoGallery); }
private static void AddParameters(SqlCommand command, BE.PhotoGallery photoGallery) { command.Parameters.AddWithValue("@Id", photoGallery.Id); command.Parameters.AddWithValue("@Title", photoGallery.Title); command.Parameters.AddWithValue("@Thumbnails", photoGallery.Thumbnails); command.Parameters.AddWithValue("@NormalPicture", photoGallery.NormalPicture); command.Parameters.AddWithValue("@Publish", photoGallery.Publish); command.Parameters.AddWithValue("@Catagory", photoGallery.Catagory); }
public static bool Update(BE.PhotoGallery photoGallery) { string SQLQuery = "UPDATE [PhotoGallery] SET Id = @Id, Title= @Title, Thumbnails= @Thumbnails, NormalPicture= @NormalPicture, Publish= @Publish, Catagory= @Catagory WHERE [Id]=@Id "; SqlCommand command = new SqlCommand(); command.CommandText = SQLQuery; AddParameters(command, photoGallery); return(Convert.ToBoolean(SQLHelper.ExecuteNonQuery(command))); }
public static bool Insert(BE.PhotoGallery photoGallery) { string SQLQuery = "INSERT INTO [PhotoGallery] ( id,title,thumbnails,normalPicture,publish,catagory ) VALUES (@id, @title, @thumbnails, @normalPicture, @publish, @catagory)"; SqlCommand command = new SqlCommand(); command.CommandText = SQLQuery; AddParameters(command, photoGallery); return(Convert.ToBoolean(SQLHelper.ExecuteNonQuery(command))); }
public static bool Save(BE.PhotoGallery photoGallery) { bool IsAffected = false; if (photoGallery.State == BE.RowState.Added) { IsAffected = Insert(photoGallery); } else if (photoGallery.State == BE.RowState.Modified) { IsAffected = Update(photoGallery); } else if (photoGallery.State == BE.RowState.Deleted) { IsAffected = Delete(photoGallery.Id); } return(IsAffected); }