public Moooyo.BiZ.Photo.Photo SavePhoto(string memberID, int holderNo, Stream file, String filename) { Moooyo.BiZ.Photo.Photo myp = new BiZ.Photo.Photo(); if (file != null && file.Length > 0 && !string.IsNullOrEmpty(filename)) { string fname = filename; string ext = fname.Substring(fname.LastIndexOf('.') + 1); string month = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString(); string nFilename = month + "_" + CBB.Security.MD5Helper.getMd5Hash(fname + memberID + DateTime.Now.ToString()) + "." + ext; myp = Moooyo.BiZ.Photo.PhotoManager.AddPhoto(memberID, (BiZ.Photo.PhotoType)holderNo, ext, fname, ext, nFilename); myp.FileName = nFilename; CBB.ImageHelper.ImageWaterMark wm = new CBB.ImageHelper.ImageWaterMark(); //打文字水印 if (CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrOn") == "true") { wm.WaterStrOn = true; wm.WaterStrMarginRight = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrMarginRight") == "" ? 5 : Int32.Parse(CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrMarginRight")); wm.WaterStrMarginBottom = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrMarginBottom") == "" ? 5 : Int32.Parse(CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrMarginBottom")); wm.WaterStrFontSize = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrFontSize"); wm.WaterStrFont = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStrFont"); wm.WaterStr = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterStr"); } //打图片水印 if (CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterPicOn") == "true") { wm.WaterPicOn = true; wm.WaterPicMarginRight = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterPicMarginRight") == "" ? 5 : Int32.Parse(CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterPicMarginRight")); wm.WaterPicMarginBottom = CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterPicMarginBottom") == "" ? 5 : Int32.Parse(CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterPicMarginBottom")); wm.WaterPicPath = System.Web.Hosting.HostingEnvironment.MapPath(CBB.ConfigurationHelper.AppSettingHelper.GetConfig("WaterPicPath")); } CBB.ImageHelper.ImageSizeType[] imagetypes; BiZ.Photo.PhotoType photoType = (BiZ.Photo.PhotoType)holderNo; if (photoType == BiZ.Photo.PhotoType.ImageContentPhoto || photoType == BiZ.Photo.PhotoType.SuoSuoContentPhoto || photoType == BiZ.Photo.PhotoType.CallForContentPhoto || photoType == BiZ.Photo.PhotoType.MemberSkinPersonalityPicture || photoType == BiZ.Photo.PhotoType.InterestSelfhoodPicture) { imagetypes = SetImageSize(800, 800, wm); } else if (photoType == BiZ.Photo.PhotoType.MemberSkinPersonalityBackgroundPicture || photoType == BiZ.Photo.PhotoType.WebsiteHome) { imagetypes = SetImageSize(1600, 1600, wm); } else { imagetypes = SetImageSize(600, 600, wm); } CBB.ImageHelper.ImageUpload upload = new CBB.ImageHelper.ImageUpload(); upload.AddImageToGridFS(nFilename, file, imagetypes); } return myp; }
/// <summary> /// 删除照片 /// </summary> /// <param name="photoID">图片编号</param> /// <returns>操作状态</returns> public static CBB.ExceptionHelper.OperationResult DeletePhoto(String photoID) { try { MongoDatabase md = MongoDBHelper.MongoDB; MongoCollection<Photo> mc = md.GetCollection<Photo>("Photos"); IMongoQuery qc = Query.And(Query.EQ("_id", ObjectId.Parse(photoID))); Photo photo = PhotoManager.GetPhoto(photoID); if (photo != null) { //删除图片文件 new CBB.ImageHelper.ImageUpload().DelImageFromGridFS(photo.FileName); } //删除图片数据 mc.Remove(qc); //删除图片文件 string filenamepart1 = photo.FileName.Substring(0, photo.FileName.LastIndexOf('.')); CBB.ImageHelper.ImageUpload imu = new CBB.ImageHelper.ImageUpload(); imu.DelImageFromGridFS(photo.FileName); imu.DelImageFromGridFS(filenamepart1 + "_s.jpg"); imu.DelImageFromGridFS(filenamepart1 + "_p.jpg"); imu.DelImageFromGridFS(filenamepart1 + "_i.jpg"); return new CBB.ExceptionHelper.OperationResult(true); } catch (CBB.ExceptionHelper.OperationException err) { throw new CBB.ExceptionHelper.OperationException( CBB.ExceptionHelper.ErrType.SystemErr, CBB.ExceptionHelper.ErrNo.DBOperationError, err); } }