public bool addMediaLibrary(MediaLibrary_Model c, string User_Account, out long newID) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { var hm = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == c.ProductID); var ExistPImg = hm.CMS_StockKey.MediaLibrary.FirstOrDefault(r => r.PrimaryImage == true); MediaLibrary newMedia = new MediaLibrary { ProductID = c.ProductID, StockKeyID = hm.StockKeyID, HMNUM = c.HMNUM, SerialNum = c.SerialNum, ImgName = c.ImgName, MediaType = c.MediaType, fileFormat = c.fileFormat, fileSize = c.fileSize, fileWidth = c.fileWidth, fileHeight = c.fileHeight, Description = c.Description, CreateOn = DateTime.Now, CreateBy = User_Account, CloudStatusID = 1, PrimaryImage = ExistPImg == null ? true : false }; db.MediaLibrary.Add(newMedia); int eVal = db.SaveChanges(); newID = newMedia.MediaID; return(eVal > 0); } }
/// <summary> /// 该方法是addMediaLibrary的扩展,用于在SKUOrder页面直接添加的图像后,新增了一步图像-SKU-关系的逻辑。 /// CreateDate:2014年1月24日16:29:56。 /// </summary> /// <param name="c"></param> /// <param name="User_Account"></param> /// <param name="SKUID"></param> /// <param name="newID"></param> /// <returns></returns> public bool addMediaLibraryWithSKURelation(MediaLibrary_Model c, string User_Account, long SKUID, out long newID) { using (PermaisuriCMSEntities db = new PermaisuriCMSEntities()) { var hm = db.CMS_HMNUM.FirstOrDefault(h => h.ProductID == c.ProductID);//hm不可能为空 var ExistPImg = hm.CMS_StockKey.MediaLibrary.FirstOrDefault(r => r.PrimaryImage == true); MediaLibrary newMedia = new MediaLibrary { ProductID = c.ProductID, HMNUM = c.HMNUM, StockKeyID = hm.StockKeyID, SerialNum = c.SerialNum, ImgName = c.ImgName, MediaType = c.MediaType, fileFormat = c.fileFormat, fileSize = c.fileSize, fileWidth = c.fileWidth, fileHeight = c.fileHeight, Description = c.Description, CreateOn = DateTime.Now, CreateBy = User_Account, CloudStatusID = 1, PrimaryImage = ExistPImg == null?true:false }; db.MediaLibrary.Add(newMedia); //好吧,多查询一次应该不会死....2014年2月14日14:18:57 var IsExistPM = db.SKU_Media_Relation.FirstOrDefault(s => s.SKUID == SKUID && s.PrimaryImage == true); SKU_Media_Relation newModel = new SKU_Media_Relation { MediaID = newMedia.MediaID, SKUID = SKUID, PrimaryImage = IsExistPM == null?true:false }; db.SKU_Media_Relation.Add(newModel); int eVal = db.SaveChanges(); newID = newMedia.MediaID; return(eVal > 0); } }
/// <summary> /// 目前都是用这个方法. /// Change1:新增从SKUOrder页面上传之后,需要做的相关逻辑的操作(关联当前SKU)2014年1月24日16:05:24 /// </summary> /// <param name="context"></param> /// <param name="statuses"></param> private void UploadWholeFile(HttpContext context, List <FilesStatus> statuses) { Image imgInfo = null; try { string cookis = context.Request[ConfigurationManager.AppSettings["userInfoCookiesKey"]]; var serializer = new JavaScriptSerializer(); string decCookies = CryptTools.Decrypt(cookis); User_Profile_Model userInfo = serializer.Deserialize(decCookies, typeof(User_Profile_Model)) as User_Profile_Model; MediaServices mSvr = new MediaServices(); var ProductID = context.Request.Form["ProductID"]; //根据HMNUM拼凑当前需要存储的文件夹路径 var HMNUM = context.Request.Form["HMNUM"]; var curStorageRoot = Path.Combine(StorageRoot, HMNUM) + "/";//当前HM#图像的存储总地址 // ReqIndicator, 0:默认,1:HMNUM页面 2:SKUOrdr页面 var strIndicator = context.Request.Form["ReqIndicator"]; int ReqIndicator = 0; int.TryParse(strIndicator, out ReqIndicator); long SKUID = 0; if (ReqIndicator == 2) { var strWPID = context.Request.Form["SKUID"]; long.TryParse(strWPID, out SKUID); } //如果这些路径不存在,则创建之。 if (!Directory.Exists(curStorageRoot)) { Directory.CreateDirectory(curStorageRoot); } for (int i = 0; i < context.Request.Files.Count; i++) { var file = context.Request.Files[i]; var SerialNum = context.Request.Form["SerialNum"].Split(',')[i]; //用户标识当前HM关联图像的序列值,给前端重命名的时候使用! var imgSize = context.Request.Form["imgSize"].Split(',')[i]; //该图像多大,比如100MB var rename = context.Request["rename"].Split(',')[i]; //获取客户端重命名的名称 var extension = Path.GetExtension(file.FileName); //获取图像扩展名 var fullPath = curStorageRoot + rename + extension; var thumbPath = curStorageRoot + rename + "_th" + extension; file.SaveAs(fullPath); // SendSmallImage(fullPath, thumbPath, 160); SamllImageGengeratedFixedHW(fullPath, thumbPath, 200, 200); //Save image infor to database imgInfo = Image.FromFile(fullPath); long newID = 0; var newMedia = new MediaLibrary_Model { ProductID = Convert.ToInt64(ProductID), HMNUM = HMNUM, SerialNum = Convert.ToInt32(SerialNum), ImgName = rename, MediaType = 1, fileFormat = extension, fileSize = imgSize, fileWidth = imgInfo.Width, fileHeight = imgInfo.Height, Description = "" }; if (ReqIndicator == 2) { mSvr.addMediaLibraryWithSKURelation(newMedia, userInfo.User_Account, SKUID, out newID); } else { mSvr.addMediaLibrary(newMedia, userInfo.User_Account, out newID); } imgInfo.Dispose(); //string fullName = Path.GetFileName(file.FileName); //备注:newID即指 新增的MediaID statuses.Add(new FilesStatus(rename + extension, file.ContentLength, fullPath, newID, HMNUM)); } } catch (Exception ex) { if (imgInfo != null) { imgInfo.Dispose(); } NBCMSLoggerManager.Error("UploadWholeFile"); NBCMSLoggerManager.Error(ex.Message); NBCMSLoggerManager.Error(ex.StackTrace); NBCMSLoggerManager.Error(ex.Source); } }