protected void UncatalogedCatalogButton_Click(object sender, System.EventArgs e) { //Move and catalog anything in the staging area int PhotoID; DateTime PhotoDate; int PhotoWidth; int PhotoHeight; int PhotoRes; foreach (string OldFileName in System.IO.Directory.GetFiles(Server.MapPath(_FilePath + "/Uploads"))) { System.Drawing.Image OriginalImg; OriginalImg = System.Drawing.Image.FromFile(OldFileName); try { //Get the date time from the EXIF string DateString = System.Text.ASCIIEncoding.ASCII.GetString(OriginalImg.GetPropertyItem(36867).Value); string SecondHalf = DateString.Substring(DateString.IndexOf(" "), (DateString.Length - DateString.IndexOf(" "))); string FirstHalf = DateString.Substring(0, 10); FirstHalf = FirstHalf.Replace(":", "-"); PhotoDate = DateTime.Parse(FirstHalf + SecondHalf); } catch { //Damn, We couldn't retreive it PhotoDate = DateTime.Now; } //ExifDTOrig PhotoHeight = OriginalImg.Height; PhotoWidth = OriginalImg.Width; PhotoRes = (int)OriginalImg.HorizontalResolution; //We need to figure out the dimensions for the thumbnail, with a defined max int NewWidth; int NewHeight; //Preseves the aspect ratio if (PhotoWidth > PhotoHeight) { NewWidth = _ThumbnailSize; NewHeight = (int)Math.Floor((double)(((float)PhotoHeight / (float)PhotoWidth) * _ThumbnailSize)); } else { NewHeight = _ThumbnailSize; NewWidth = (int)Math.Floor((double)(((float)PhotoWidth / (float)PhotoHeight) * _ThumbnailSize)); } System.Drawing.Image NewImg; NewImg = GenerateThumbnail(OriginalImg, NewWidth, NewHeight); OriginalImg.Dispose(); //SQLString = "INSERT INTO Photos ( PhotoDate, PhotoWidth, PhotoHeight, PhotoResolution, PhotoOwner ) SELECT #" + AmericanizeDateForQuery(PhotoDate) + "#, " + PhotoWidth + ", " + PhotoHeight + ", " + PhotoRes + ", '" + _Owner + "'"; Photo newphoto = new Photo(); newphoto.PhotoDate = PhotoDate; newphoto.PhotoWidth = (short)PhotoWidth; newphoto.PhotoHeight = (short)PhotoHeight; newphoto.PhotoResolution = (short)PhotoRes; newphoto.PhotoOwner = _Owner; GDC.Photos.InsertOnSubmit(newphoto); GDC.SubmitChanges(); PhotoID = ( from photo in GDC.Photos where photo.PhotoOwner.Equals(_Owner) select photo.PhotoID ).Max(); //SQLString = "SELECT Max(PhotoID) AS MaxOfPhotoID FROM Photos WHERE PhotoOwner='" + _Owner + "'"; string NewFileName = Server.MapPath(_FilePath + "/") + PhotoID + ".jpg"; string ThumbFileName = Server.MapPath(_FilePath + "/Thumbs/") + PhotoID + ".jpg"; NewImg.Save(ThumbFileName, System.Drawing.Imaging.ImageFormat.Jpeg); NewImg.Dispose(); System.IO.File.Copy(OldFileName, NewFileName); System.IO.File.Delete(OldFileName); } BindRepeater(); GalleryAdminCatalog.Visible = true; }
partial void UpdatePhoto(Photo instance);
partial void DeletePhoto(Photo instance);
partial void InsertPhoto(Photo instance);