/// <summary> /// Return the recipe image /// </summary> public static string GetImage(int ID) { //Instantiate sql params object Blogic myBL = new Blogic(); string FileName; FileName = "../RecipeImageUpload/noimageavailable.gif"; IDataReader dr = myBL.GetRecipeImageFileNameForUpdate(ID); dr.Read(); if (dr["RecipeImage"] != DBNull.Value) { FileName = "../RecipeImageUpload/" + (string)dr["RecipeImage"]; } dr.Close(); myBL = null; return FileName; }
//Handle the delete button click event public void Delete_Recipes(object sender, DataGridCommandEventArgs e) { if ((e.CommandName == "Delete")) { TableCell iIdNumber2 = e.Item.Cells[0]; TableCell iIRecipename = e.Item.Cells[1]; #region Delete Recipe Image //Delete the recipe image if the recipe has an image. //Instantiate sql params object Blogic FetchData = new Blogic(); try { IDataReader dr = FetchData.GetRecipeImageFileNameForUpdate(int.Parse(iIdNumber2.Text)); dr.Read(); if (dr["RecipeImage"] != DBNull.Value) { System.IO.File.Delete(Server.MapPath(GetRecipeImage.ImagePath + dr["RecipeImage"].ToString())); } dr.Close(); } catch { } FetchData = null; #endregion //Refresh cached data Caching.PurgeCacheItems("MainCourse_RecipeCategory"); Caching.PurgeCacheItems("Ethnic_RecipeCategory"); Caching.PurgeCacheItems("RecipeCategory_SideMenu"); Caching.PurgeCacheItems("Newest_RecipesSideMenu_"); //Instantiate delete recipe object RecipeInfo DelRecipe = new RecipeInfo(); DelRecipe.ID = int.Parse(iIdNumber2.Text); //Perform delete recipe DelRecipe.Delete(); DelRecipe = null; //Redirect to confirm delete page strURLRedirect = "confirmdel.aspx?catname=" + iIRecipename.Text + "&mode=del"; Server.Transfer(strURLRedirect); } }
private void Page_Init(Object sender, EventArgs e) { //Instantiate sql params object Blogic myBL = new Blogic(); int ID = (int)Util.Val(Request.QueryString["id"]); string FileName = ""; try { IDataReader dr = myBL.GetRecipeImageFileNameForUpdate(ID); dr.Read(); if (dr["RecipeImage"] != DBNull.Value) { FileName = (string)dr["RecipeImage"]; } dr.Close(); } catch { //Redirect to image not found. //1 = pagenotfound.aspx Util.PageRedirect(1); } string Directory = Server.MapPath("~/RecipeImageUpload/"); string path = Directory + FileName; int roundedDia = 30; using (System.Drawing.Image imgin = System.Drawing.Image.FromFile(path)) { System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imgin.Width, imgin.Height); Graphics g = Graphics.FromImage(bitmap); g.Clear(Color.White); Brush brush = new System.Drawing.TextureBrush(imgin); FillRoundedRectangle(g, new Rectangle(0, 0, imgin.Width, imgin.Height), roundedDia, brush); // done with drawing dispose graphics object. g.Dispose(); // Stream Image to client. Response.Clear(); Response.ContentType = "image/pjpeg"; bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); Response.End(); //dispose bitmap object. bitmap.Dispose(); //Release allocated memory myBL = null; Util = null; } }