protected void AddSaveDeleteButtons() { if (loggedUsername != null) { int loggedUserId = App_Code.SqlUtilities.GetUserId(loggedUsername); App_Code.User loggedUsr = new App_Code.User(loggedUserId); App_Code.Image img = new App_Code.Image(imageId); if ((img.UploaderId == loggedUserId || loggedUsr.IsAdmin) && DeleteSaveButtonsHolder.Controls.Count < 1) { Button deleteImage = new Button(); deleteImage.ID = "DeteleImageButton"; deleteImage.Text = "Delete Image"; deleteImage.Click += DeleteImage; DeleteSaveButtonsHolder.Controls.Add(deleteImage); } if (ViewState["editedImagePath"] != null && DeleteSaveButtonsHolder.Controls.Count < 2) { Button saveImage = new Button(); saveImage.ID = "SaveImageButton"; saveImage.Click += SaveImage; saveImage.Text = "Save image"; DeleteSaveButtonsHolder.Controls.Add(saveImage); } } }
protected void EnhanceImage_Click(object sender, EventArgs e) { MLApp.MLApp matlab = new MLApp.MLApp(); matlab.Execute("cd " + Server.MapPath(MATLAB_FUNCTIONS_FOLDER)); object result = null; App_Code.Image image = App_Code.SqlUtilities.GetImage(int.Parse(Request["id"])); string[] temp = image.Path.Split('/'); string imageName = temp[temp.Length - 1]; matlab.Feval("enhance", 1, out result, Server.MapPath(image.Path), imageName, loggedUsername); object[] res = result as object[]; string resultPath = "~/Images/" + loggedUsername + "/" + (string)res[0]; System.Web.UI.WebControls.Image imageControl = (System.Web.UI.WebControls.Image)ThumbnailsHolder.Controls[1]; imageControl.ImageUrl = resultPath; if (ViewState["editedImagePath"] != null) { DeleteImage(null, null); } ViewState["editedImagePath"] = resultPath; AddSaveDeleteButtons(); }
protected void AppendThumbnailsToMainPlaceholder(object sender, EventArgs e) { App_Code.Category category = App_Code.SqlUtilities.GetCategory(categoryId); int lastAppendedImg = (int)Session["LastAppended"]; lastAppendedImg += NR_OF_APPENDED_IMGES; int appendedImage = 0; for (; category != null && appendedImage < lastAppendedImg && appendedImage < category.Images.Count; ++appendedImage) { App_Code.Image img = category.Images[appendedImage]; ImageButton currImg = new ImageButton(); currImg.ID = img.Id.ToString(); currImg.ImageUrl = img.Path; currImg.Height = 600; currImg.Width = 500; currImg.PostBackUrl = "Image.aspx?id=" + img.Id.ToString(); currImg.BorderWidth = 20; currImg.BorderColor = System.Drawing.Color.White; ThumbnailsHolder.Controls.Add(currImg); } Session["LastAppended"] = appendedImage; }
private void AddImagesToMainPlaceholder() { ContentPlaceHolder maincph = (ContentPlaceHolder)this.Master.FindControl("Main"); List <App_Code.Category> categories = App_Code.SqlUtilities.GetCategoriesNames(); foreach (App_Code.Category category in categories) { App_Code.Category categ = App_Code.SqlUtilities.GetCategory(category.Id); if (categ == null) { continue; } Panel imagesHolder = new Panel(); imagesHolder.ID = category.Name + "Holder"; imagesHolder.BorderColor = System.Drawing.Color.Black; imagesHolder.BorderWidth = 3; imagesHolder.HorizontalAlign = HorizontalAlign.Center; maincph.Controls.Add(imagesHolder); Label categName = new Label(); categName.Text = category.Name; categName.Font.Size = 15; imagesHolder.Controls.Add(categName); imagesHolder.Controls.Add(new LiteralControl("<br />")); for (int i = 0; i < categ.Images.Count && i < NR_OF_IMAGES_PER_CATEGORY; ++i) { App_Code.Image img = categ.Images[i]; ImageButton currImg = new ImageButton(); currImg.ID = category.Name + img.Id.ToString(); currImg.ImageUrl = img.Path; currImg.Height = 600; currImg.Width = 500; currImg.PostBackUrl = "Image.aspx?id=" + img.Id.ToString(); currImg.BorderWidth = 20; currImg.BorderColor = System.Drawing.Color.White; imagesHolder.Controls.Add(currImg); } } }
private void AddImage() { App_Code.Image image = new App_Code.Image(imageId); System.Web.UI.WebControls.Image imageControl = new System.Web.UI.WebControls.Image(); imageControl.ImageUrl = image.Path; imageControl.ID = imageId.ToString(); imageControl.ImageAlign = ImageAlign.Middle; ThumbnailsHolder.Controls.Add(imageControl); Label imageDescription = new Label(); imageDescription.Text = image.Description; imageDescription.Font.Bold = true; imageDescription.Font.Size = 15; ImageDescriptionHolder.Controls.Add(imageDescription); ImageDescriptionHolder.BorderWidth = 15; ImageDescriptionHolder.BorderColor = System.Drawing.Color.White; }
protected void DeleteImage(object sender, EventArgs e) { if(ViewState["editedImagePath"] != null) { string path = (string)ViewState["editedImagePath"]; File.Delete(Server.MapPath(path)); if(sender != null && e != null) { Response.Redirect(Request.Url.AbsolutePath); } } else { App_Code.Image image = new App_Code.Image(imageId); App_Code.SqlUtilities.RemoveImage(imageId); File.Delete(Server.MapPath(image.Path)); Response.Redirect("Profile.aspx"); } }
protected void SaveImage(object sender, EventArgs e) { if(loggedUsername != null) { string path = (string)ViewState["editedImagePath"]; // check if the same image has not been saved before if(App_Code.SqlUtilities.GetImageId(path) != -1) { return; } App_Code.Image img = new App_Code.Image(imageId); int userId = App_Code.SqlUtilities.GetUserId(loggedUsername); if(img.UploaderId != userId) { PageMessage.Text = "You cannot save this image as you are not the owner of it."; return; } App_Code.SqlUtilities.InsertIntoImages(loggedUsername, path, img.Description, img.City, img.Country); int imgId = App_Code.SqlUtilities.GetImageId(path); App_Code.SqlUtilities.InsertIntoEdited(imgId, userId); } }