public void CopyPhoto_FromOldAlbum_ToNewAlbum(string old_photo_url, Guid album_ID, int photo_sortOrder, string photo_author, string photo_camera_model) { Guid new_photoID = Guid.NewGuid(); String new_photo_name = string.Format("{0}.jpg", new_photoID); //create album folder string copyTo_path = string.Format(@"{0}\{1}\{2}", new_album_path, album_ID, new_photo_name); string photo_tb_folder = string.Format(@"{0}\{1}\tb\{2}", new_album_path, album_ID, new_photo_name); //<----------------------------copy old photo to new album--------------------------> Dictionary<string, string[]> model_dictionary = new Dictionary<string, string[]>(); model_dictionary.Add("Nikon D1H", new string[] { "NikonD1", "Nikon D100" }); model_dictionary.Add("NikonD1", new string[] { "Nikon D1H", "Nikon D100" }); model_dictionary.Add("D100", new string[] { "Nikon D1H", "NikonD1" }); if (!File.Exists(old_photo_url)) { if (model_dictionary.ContainsKey(photo_camera_model)) { string[] model_arr = model_dictionary[photo_camera_model]; string check_path = ""; foreach (string model in model_arr) { check_path = old_photo_url.Replace(photo_camera_model, model); if (File.Exists(check_path)) { old_photo_url = check_path; } } } } System.IO.File.Copy(old_photo_url, copyTo_path); System.Threading.Thread.Sleep(2000); //using (FileStream fs = new FileStream(old_photo_url, FileMode.Open, FileAccess.ReadWrite)) //{ using (Image Image = Image.FromFile(old_photo_url)) { //<----------------------------generate Thumbnail for photo --------------------------> //Image Image = new Image.FromFile(old_photo_url); //<----------------------------copy old photo to new album--------------------------> System.IO.File.Copy(old_photo_url, photo_tb_folder); System.Threading.Thread.Sleep(2000); Size ThumbnailSize = new Size(285, 285); Image Image2 = ResizeImage(Image, ThumbnailSize, null, null, CropOption.FillTheArea); SaveJPGWithCompressionSetting(Image2, photo_tb_folder, 100); Image2.Dispose(); Image.Dispose(); } //} //<----------------------------save new album photo --------------------------> AlbumPhoto new_AlbumPhoto = new AlbumPhoto { PhotoID = new_photoID, AlbumID = album_ID, PhotoName = new_photo_name, SortOrder = photo_sortOrder, CreateDate = DateTime.Now, CreatedBy = "admin", UpdateDate = DateTime.Now, UpdatedBy = "admin" }; // Add the new object to the Orders collection. HKSPA_ms_db.AlbumPhotos.InsertOnSubmit(new_AlbumPhoto); // Submit the change to the database. try { HKSPA_ms_db.SubmitChanges(); } catch (Exception e) { returnResult += string.Format("[Insert new photos] Error of {0}. RowID: {1} \r\n", e.Message.ToString(), rowID); file.WriteLine(string.Format("[Insert new photos] Error of {0}. RowID: {1} \r\n", e.Message.ToString(), rowID)); // Make some adjustments. // ... // Try again. HKSPA_ms_db.SubmitChanges(); } if (photo_sortOrder == 1) { SetAlbumCover(album_ID, new_photoID); } //<----------------------------save new album photo info --------------------------> insert_photo_info(old_photo_url, new_photoID, photo_author, photo_camera_model); }
partial void UpdateAlbumPhoto(AlbumPhoto instance);
partial void DeleteAlbumPhoto(AlbumPhoto instance);
partial void InsertAlbumPhoto(AlbumPhoto instance);