protected void imagesGridView_SelectedIndexChanged(object sender, EventArgs e) { GigaGalleryWS ws = new GigaGalleryWS(); if (Session["selectedAlbumId"] == null) { return; } Img[] images = ws.GetAlbumImages((int)Session["selectedAlbumId"]); if (images == null) { this.errorLabel.Text = "Album is empty, please insert some images!"; this.errorLabel.Visible = true; return; } Img selectedImg = null; foreach (Img img in images) { if (img.ImageName == Context.Server.HtmlDecode(this.imagesGridView.SelectedRow.Cells[2].Text)) { selectedImg = img; } } if (selectedImg == null) { this.errorLabel.Text = "The selected image does not exist in this album!"; this.errorLabel.Visible = true; return; } else { string beginPath = "~\\UserImages\\"; string imagePath = selectedImg.ImageFilePath; this.selectedImagePreview.ImageUrl = beginPath + imagePath; this.selectedImagePreview.DataBind(); this.selectedImagePreview.Visible = true; this.updateDropDownParams(sender, e); } }
protected void deleteImageBtn_Click(object sender, EventArgs e) { this.errorLabel.Visible = false; GigaGalleryWS ws = new GigaGalleryWS(); if (Session["selectedAlbumId"] == null) { return; } Img[] images = ws.GetAlbumImages((int)Session["selectedAlbumId"]); if (images == null) { this.errorLabel.Text = "Album is empty, please insert some images!"; this.errorLabel.Visible = true; return; } Img selectedImg = null; foreach (Img img in images) { if (img.ImageName == Context.Server.HtmlDecode(this.imagesGridView.SelectedRow.Cells[2].Text)) { selectedImg = img; } } if (selectedImg == null) { this.errorLabel.Text = "The selected image does not exist in this album!"; this.errorLabel.Visible = true; return; } else { if (ws.DeleteImage(selectedImg)) { this.imagesGridView.DataBind(); } else { this.errorLabel.Text = "Could not delete the selected image, try again later!"; this.errorLabel.Visible = true; } string beginPath = Request.PhysicalApplicationPath + "UserImages"; string imagePath = selectedImg.ImageFilePath; // Delete physical file. if (System.IO.File.Exists(beginPath + imagePath)) { System.IO.File.Delete(beginPath + imagePath); this.imagesGridView.SelectedIndex = -1; } else { this.errorLabel.Text = "Could not delete physical file instance!"; this.errorLabel.Visible = true; this.imagesGridView.SelectedIndex = -1; this.imagesGridView.DataBind(); this.updateDropDownParams(sender, e); return; } } }
protected void changeImageNameBtn_Click(object sender, EventArgs e) { this.errorLabel.Visible = false; GigaGalleryWS ws = new GigaGalleryWS(); if (Session["selectedAlbumId"] == null) { // No album was selected. this.errorLabel.Text = "No album was selected! Please select an album!"; this.errorLabel.Visible = true; return; } Img[] images = ws.GetAlbumImages((int)Session["selectedAlbumId"]); if (images == null) { this.errorLabel.Text = "Album is empty, please insert some images!"; this.errorLabel.Visible = true; return; } Img selectedImg = null; foreach (Img img in images) { if (img.ImageName == Context.Server.HtmlDecode(this.imagesGridView.SelectedRow.Cells[2].Text)) { selectedImg = img; } } if (selectedImg == null) { this.errorLabel.Text = "The selected image does not exist in this album!"; this.errorLabel.Visible = true; return; } else { UserValidationWS validationWS = new UserValidationWS(); string newName = this.changeImageNameTB.Text.Trim(); if (validationWS.isImageNameValid(newName)) { selectedImg.ImageName = newName; bool res = false; try { res = ws.UpdateImage(selectedImg); } catch { this.errorLabel.Text = "Invalid Action!"; this.errorLabel.Visible = true; this.imagesGridView.DataBind(); this.imagesGridView.SelectedIndex = -1; return; } if (res) { this.imagesGridView.DataBind(); this.imagesGridView.SelectedIndex = -1; this.updateDropDownParams(sender, e); } else { this.errorLabel.Text = "Could not update the image name, try again later!"; this.errorLabel.Visible = true; this.imagesGridView.SelectedIndex = -1; } } else { this.errorLabel.Text = validationWS.imageNameLengthInvalidMessage(); this.errorLabel.Visible = true; this.imagesGridView.SelectedIndex = -1; return; } } }