/// <summary> /// 裁剪图片并保存 /// </summary> public bool cropSaveAs(string fileName, string newFileName, int maxWidth, int maxHeight, int cropWidth, int cropHeight, int X, int Y) { string fileExt = SFUtils.GetFileExt(fileName); //文件扩展名,不含“.” if (!IsImage(fileExt)) { return(false); } string newFileDir = SFUtils.GetMapPath(newFileName.Substring(0, newFileName.LastIndexOf(@"/") + 1)); //检查是否有该路径,没有则创建 if (!Directory.Exists(newFileDir)) { Directory.CreateDirectory(newFileDir); } try { string fileFullPath = SFUtils.GetMapPath(fileName); string toFileFullPath = SFUtils.GetMapPath(newFileName); return(Thumbnail.MakeThumbnailImage(fileFullPath, toFileFullPath, 180, 180, cropWidth, cropHeight, X, Y)); } catch { return(false); } }
private bool DoEdit(int _id) { bool result = false; BLL.article bll = new BLL.article(); Model.article model = bll.GetModel(_id); //model.channel_id = this.channel_id; //model.category_id = SFUtils.StrToInt(ddlCategoryId.SelectedValue, 0); model.call_index = txtCallIndex.Text.Trim(); model.title = txtTitle.Text.Trim(); model.link_url = txtLinkUrl.Text.Trim(); //model.img_url = txtImgUrl.Text; model.seo_title = txtSeoTitle.Text.Trim(); model.seo_keywords = txtSeoKeywords.Text.Trim(); model.seo_description = txtSeoDescription.Text.Trim(); //内容摘要提取内容前255个字符 if (string.IsNullOrEmpty(txtZhaiyao.Text.Trim())) { model.zhaiyao = SFUtils.DropHTML(txtContent.Value, 255); } else { model.zhaiyao = SFUtils.DropHTML(txtZhaiyao.Text, 255); } model.content = txtContent.Value; model.sort_id = SFUtils.StrToInt(txtSortId.Text.Trim(), 99); model.click = int.Parse(txtClick.Text.Trim()); model.status = SFUtils.StrToInt(rblStatus.SelectedValue, 0); model.is_msg = 0; model.is_top = 0; model.is_red = 0; model.is_hot = 0; model.is_slide = 0; if (cblItem.Items[0].Selected == true) { model.is_msg = 1; } if (cblItem.Items[1].Selected == true) { model.is_top = 1; } if (cblItem.Items[2].Selected == true) { model.is_red = 1; } if (cblItem.Items[3].Selected == true) { model.is_hot = 1; } if (cblItem.Items[4].Selected == true) { model.is_slide = 1; } model.add_time = SFUtils.StrToDateTime(txtAddTime.Text.Trim()); model.update_time = DateTime.Now; model.fields = SetFieldValues(this.channel_id); //扩展字段赋值 #region 保存相册==================== //检查是否有自定义图片 //if (txtImgUrl.Text.Trim() == "") //{ // model.img_url = hidFocusPhoto.Value; //} if (model.albums != null) { model.albums.Clear(); } string[] albumArr = Request.Form.GetValues("hid_photo_name"); string[] remarkArr = Request.Form.GetValues("hid_photo_remark"); if (albumArr != null) { List <Model.article_albums> ls = new List <Model.article_albums>(); for (int i = 0; i < albumArr.Length; i++) { string[] imgArr = albumArr[i].Split('|'); int img_id = SFUtils.StrToInt(imgArr[0], 0); if (imgArr.Length == 3) { if (!string.IsNullOrEmpty(remarkArr[i])) { ls.Add(new Model.article_albums { id = img_id, article_id = _id, original_path = imgArr[1], thumb_path = imgArr[2], remark = remarkArr[i] }); } else { ls.Add(new Model.article_albums { id = img_id, article_id = _id, original_path = imgArr[1], thumb_path = imgArr[2] }); } } } model.albums = ls; } #endregion #region 保存附件==================== if (model.attach != null) { model.attach.Clear(); } string[] attachIdArr = Request.Form.GetValues("hid_attach_id"); string[] attachFileNameArr = Request.Form.GetValues("hid_attach_filename"); string[] attachFilePathArr = Request.Form.GetValues("hid_attach_filepath"); string[] attachFileSizeArr = Request.Form.GetValues("hid_attach_filesize"); string[] attachPointArr = Request.Form.GetValues("txt_attach_point"); if (attachIdArr != null && attachFileNameArr != null && attachFilePathArr != null && attachFileSizeArr != null && attachPointArr != null && attachIdArr.Length > 0 && attachFileNameArr.Length > 0 && attachFilePathArr.Length > 0 && attachFileSizeArr.Length > 0 && attachPointArr.Length > 0) { List <Model.article_attach> ls = new List <Model.article_attach>(); for (int i = 0; i < attachFileNameArr.Length; i++) { int attachId = SFUtils.StrToInt(attachIdArr[i], 0); int fileSize = SFUtils.StrToInt(attachFileSizeArr[i], 0); string fileExt = SFUtils.GetFileExt(attachFilePathArr[i]); int _point = SFUtils.StrToInt(attachPointArr[i], 0); ls.Add(new Model.article_attach { id = attachId, article_id = _id, file_name = attachFileNameArr[i], file_path = attachFilePathArr[i], file_size = fileSize, file_ext = fileExt, point = _point, }); } model.attach = ls; } #endregion #region 保存会员组价格============== //List<Model.user_group_price> priceList = new List<Model.user_group_price>(); //for (int i = 0; i < rptPrice.Items.Count; i++) //{ // int hidPriceId = 0; // if (!string.IsNullOrEmpty(((HiddenField)rptPrice.Items[i].FindControl("hidePriceId")).Value)) // { // hidPriceId = Convert.ToInt32(((HiddenField)rptPrice.Items[i].FindControl("hidePriceId")).Value); // } // int hidGroupId = Convert.ToInt32(((HiddenField)rptPrice.Items[i].FindControl("hideGroupId")).Value); // decimal _price = Convert.ToDecimal(((TextBox)rptPrice.Items[i].FindControl("txtGroupPrice")).Text.Trim()); // priceList.Add(new Model.user_group_price { id = hidPriceId, article_id = _id, group_id = hidGroupId, price = _price }); //} //model.group_price = priceList; #endregion if (bll.Update(model)) { AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改" + this.channel_name + "频道内容:" + model.title); //记录日志 result = true; } return(result); }
/// <summary> /// 文件上传方法 /// </summary> /// <param name="postedFile">文件流</param> /// <param name="isThumbnail">是否生成缩略图</param> /// <param name="isWater">是否打水印</param> /// <returns>上传后文件信息</returns> public string fileSaveAs(HttpPostedFile postedFile, bool isThumbnail, bool isWater) { try { string fileExt = SFUtils.GetFileExt(postedFile.FileName); //文件扩展名,不含“.” int fileSize = postedFile.ContentLength; //获得文件大小,以字节为单位 string fileName = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf(@"\") + 1); //取得原文件名 string newFileName = SFUtils.GetRamCode() + "." + fileExt; //随机生成新的文件名 string newThumbnailFileName = "thumb_" + newFileName; //随机生成缩略图文件名 string upLoadPath = GetUpLoadPath(); //上传目录相对路径 string fullUpLoadPath = SFUtils.GetMapPath(upLoadPath); //上传目录的物理路径 string newFilePath = upLoadPath + newFileName; //上传后的路径 string newThumbnailPath = upLoadPath + newThumbnailFileName; //上传后的缩略图路径 //检查文件扩展名是否合法 if (!CheckFileExt(fileExt)) { return("{\"status\": 0, \"msg\": \"不允许上传" + fileExt + "类型的文件!\"}"); } //检查文件大小是否合法 if (!CheckFileSize(fileExt, fileSize)) { return("{\"status\": 0, \"msg\": \"文件超过限制的大小啦!\"}"); } //检查上传的物理路径是否存在,不存在则创建 if (!Directory.Exists(fullUpLoadPath)) { Directory.CreateDirectory(fullUpLoadPath); } //保存文件 postedFile.SaveAs(fullUpLoadPath + newFileName); /* * //如果是图片,检查图片是否超出最大尺寸,是则裁剪 * if (IsImage(fileExt) && (this.siteConfig.imgmaxheight > 0 || this.siteConfig.imgmaxwidth > 0)) * { * Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newFileName, * this.siteConfig.imgmaxwidth, this.siteConfig.imgmaxheight); * } * //如果是图片,检查是否需要生成缩略图,是则生成 * if (IsImage(fileExt) && isThumbnail && this.siteConfig.thumbnailwidth > 0 && this.siteConfig.thumbnailheight > 0) * { * Thumbnail.MakeThumbnailImage(fullUpLoadPath + newFileName, fullUpLoadPath + newThumbnailFileName, * this.siteConfig.thumbnailwidth, this.siteConfig.thumbnailheight, "Cut"); * } * //如果是图片,检查是否需要打水印 * if (IsWaterMark(fileExt) && isWater) * { * switch (this.siteConfig.watermarktype) * { * case 1: * WaterMark.AddImageSignText(newFilePath, newFilePath, * this.siteConfig.watermarktext, this.siteConfig.watermarkposition, * this.siteConfig.watermarkimgquality, this.siteConfig.watermarkfont, this.siteConfig.watermarkfontsize); * break; * case 2: * WaterMark.AddImageSignPic(newFilePath, newFilePath, * this.siteConfig.watermarkpic, this.siteConfig.watermarkposition, * this.siteConfig.watermarkimgquality, this.siteConfig.watermarktransparency); * break; * } * } */ //处理完毕,返回JOSN格式的文件信息 return("{\"status\": 1, \"msg\": \"上传文件成功!\", \"name\": \"" + fileName + "\", \"path\": \"" + newFilePath + "\", \"thumb\": \"" + newThumbnailPath + "\", \"size\": " + fileSize + ", \"ext\": \"" + fileExt + "\"}"); } catch { return("{\"status\": 0, \"msg\": \"上传过程中发生意外错误!\"}"); } }