protected DataTable GetRoomTypePictures(int roomType) { DataTable dt = new DataTable(); RoomType_Image image = new RoomType_Image(); image.RoomType_ID = roomType; dt = image.SelectAll(); return(dt); }
protected DataTable GetRoomTypeImages(int roomTypeId) { RoomType_Image img = new RoomType_Image(); img.RoomType_ID = roomTypeId; DataTable dt = img.SelectAll(); return(dt); }
protected void imagesList_DeleteCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e) { int id = (int)imagesList.DataKeys[e.Item.ItemIndex]; RoomType_Image img = new RoomType_Image(); img.Image_ID = id; img.SelectOne(); string imagePath = Server.MapPath(img.ImagePath.ToString()); string thumbnailPath = Server.MapPath(img.ThumbnailPath.ToString()); File.Delete(imagePath); File.Delete(thumbnailPath); if (img.Delete()) { this.lblUploadResult.Text = "Deleted Successfully !"; } else { this.lblUploadResult.Text = "Error in Delete !!"; } BindDataList(Int32.Parse(this.hidRoomTypeId.Value)); }
protected void btnUpload_Click(object sender, EventArgs e) { if (upldImage.HasFile) { try { RoomType_Image image = new RoomType_Image(); image.RoomType_ID = Int32.Parse(this.hidRoomTypeId.Value); image.RoomType_OnlineID = Int32.Parse(this.hidRoomTypeOnlineId.Value); string uploadedFilePath = upldImage.PostedFile.FileName; // This gets the full file path on the client's machine ie: c:\test\myfile.txt string uploadedFileName = Path.GetFileName(uploadedFilePath); // use the System.IO Path.GetFileName method to get specifics about the file without needing to parse the path as a string Int32 intFileSize = upldImage.PostedFile.ContentLength; string strContentType = upldImage.PostedFile.ContentType; string extension = Path.GetExtension(uploadedFilePath); image.ImageName = uploadedFileName; // use the System.IO Path.GetFileName method to get specifics about the file without needing to parse the path as a string image.ImageSize = intFileSize; image.ImageLength = intFileSize; image.ImageType = strContentType; //TODO:Check if the file is of valid extensions Image img = Image.FromStream(upldImage.PostedFile.InputStream); image.ImageHeight = img.Height; image.ImageWidth = img.Width; image.ImagePath = "~/Images/RoomTypes/" + uploadedFileName; string imageFile = uploadedFileName; upldImage.PostedFile.SaveAs(Path.Combine(Server.MapPath("~/Images/RoomTypes"), imageFile)); byte[] bytUpfile = imageToByteArray(img); image.Image = bytUpfile; var ratio = (double)100 / img.Height; int imageHeight = (int)(img.Height * ratio); int imageWidth = (int)(img.Width * ratio); Image.GetThumbnailImageAbort dCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback); Image thumbnailImg = img.GetThumbnailImage(imageWidth, imageHeight, dCallback, IntPtr.Zero); image.ThumbnailHeight = thumbnailImg.Height; image.ThumbnailWidth = thumbnailImg.Width; image.ThumbnailPath = "~/Images/RoomTypes/Thumbnail/" + uploadedFileName; thumbnailImg.Save(Path.Combine(Server.MapPath("~/Images/RoomTypes/Thumbnail"), imageFile), ImageFormat.Jpeg); byte[] bytThumbNail = imageToByteArray(thumbnailImg); image.Thumbnail = bytThumbNail; thumbnailImg.Dispose(); image.CreatedUser = Utility.GetUserIdFromUserName(HttpContext.Current.User.Identity.Name); image.CreatedDate = Utility.GetSqlDateTimeFromDateTime(DateTime.Now); image.LastModifiedDate = Utility.GetSqlDateTimeFromDateTime(DateTime.Now); image.LastModifiedUser = Utility.GetUserIdFromUserName(HttpContext.Current.User.Identity.Name); if (image.Insert()) { this.lblUploadResult.Text = "Uploaded " + image.ImageName.ToString(); } else { this.lblUploadResult.Text = "Error!! Could not upload " + image.ImageName.ToString(); } BindDataList(Int32.Parse(this.hidRoomTypeId.Value)); lblUploadResult.Text = "Upload Success. File was uploaded and saved to the database."; } catch (Exception err) { lblUploadResult.Text = "The file was not updloaded because the following error happened: <br>" + err.ToString(); } } else { lblUploadResult.Text = "No File Uploaded because none was selected."; } }