public ActionResult Data_DB_Image() { string[] keys = this.Request.Form.AllKeys; string page = this.Request.Form["page"]; string rows = this.Request.Form["rows"]; string where = this.Request.Form["where"]; string order = this.Request.Form["order"]; int _page = 0, _rows = 0; int.TryParse(page, out _page); int.TryParse(rows, out _rows); if (_page == 0) { _page = 1; } if (_rows == 0) { _rows = 20; } BLL.DB_Image dal = new BLL.DB_Image(); List <NModel.DB_Image> inModel = new List <NModel.DB_Image>(); inModel = dal.GetSortAndWherePagerList(_page, _rows, order, where); NModel.PageData <NModel.DB_Image> outModel = BLL.Fun.SetJsonData <NModel.DB_Image>(inModel); dal.Close(); return(View(outModel)); }
public ActionResult Edit_DB_Image() { this.Response.ContentType = "text/plain"; NModel.DB_Image model = new NModel.DB_Image(); BLL.DB_Image dal = new BLL.DB_Image(); String JsonStr = ""; bool isGet = Tool.NStr.PostForSetVal <NModel.DB_Image>(ref model, ref JsonStr, ""); // 下面代码编写 if (isGet && !string.IsNullOrEmpty(model.Image_Name) && !string.IsNullOrEmpty(model.Image_Url) && (model.Image_Category_ID > 0) ) { //取默认值 model.Image_EditTime = DateTime.Parse(DateTime.Now.ToString("s")); bool isEdit = dal.Edit(model) > 0 ? true : false; string msg = dal.ErrorMsg; if (!string.IsNullOrEmpty(msg)) { msg = "原因:" + msg; } if (isEdit) { this.Response.Write(Tool.NMsg.SetMsg("修改成功", "1")); this.Response.End(); } else { this.Response.Write(Tool.NMsg.SetMsg("修改失败" + msg, "0")); this.Response.End(); } } else { this.Response.Write(Tool.NMsg.SetMsg("提交失败", "0")); this.Response.End(); } dal.Close(); return(View()); }
public ActionResult Del_All_DB_Image() { BLL.DB_Image bll = new BLL.DB_Image(); long delNumber = bll.DelAll(); Tool.NImage.DelFile(UploadFileController.DFPath); if (delNumber > 0) { this.Response.Write(Tool.NMsg.SetMsg("删除成功", "1")); this.Response.End(); } else { this.Response.Write(Tool.NMsg.SetMsg("删除失败", "0")); this.Response.End(); } bll.Close(); return(View()); }
public ActionResult Del_DB_Image() { this.Response.ContentType = "text/plain"; string delList = this.Request.Form["delList[]"]; if (!string.IsNullOrEmpty(delList)) { string[] arrStr = delList.Split(','); int[] delIntArr = Tool.NTool.ArrayToAll <int, string>(arrStr); if (Tool.NTool.IsArrNULL <int>(delIntArr)) { int[] delOkImage = new int[delIntArr.Length]; string[] delImage = new string[delIntArr.Length]; BLL.DB_Image dal = new BLL.DB_Image(); int lt = 0, dt = 0; foreach (int it in delIntArr) { NModel.DB_Image cdi = dal.GetModel(it); if (cdi != null && !string.IsNullOrEmpty(cdi.Image_Url)) { delImage[lt] = UploadFileController.DFPath + cdi.Image_Url; bool isdelOk = Tool.NImage.DelImage(delImage[lt]); if (isdelOk) { delOkImage[dt] = it; dt++; } lt++; } } long long_Result = dal.DelList(delIntArr); if (long_Result > 0) { this.Response.Write(Tool.NMsg.SetMsg(string.Format("删除成功!总共删除{0}条", long_Result), "1")); this.Response.End(); } else { this.Response.Write(Tool.NMsg.SetMsg("删除失败!", "0")); this.Response.End(); } dal.Close(); } else { this.Response.Write(Tool.NMsg.SetMsg("提交失败!", "0")); this.Response.End(); } } else { this.Response.Write(Tool.NMsg.SetMsg("提交失败!", "0")); this.Response.End(); } return(View()); }
public ActionResult Item_db_image() { BLL.DB_Image dal = new BLL.DB_Image(); string pagenum = this.Request.Form["pagenum"]; string numPerPage = this.Request.Form["numPerPage"]; string dbimagetype = this.Request.Form["dbimagetype"]; string dbimagedate = this.Request.Form["dbimagedate"]; string dbimagename = this.Request.Form["dbimagename"]; string where = "", order = "Image_addtime desc"; if (string.IsNullOrEmpty(numPerPage)) { numPerPage = "20"; } if (string.IsNullOrEmpty(pagenum)) { pagenum = "1"; } int _dbimagetype = 0; int.TryParse(dbimagetype, out _dbimagetype); where += " 1=1 "; if (_dbimagetype > 0) { where += string.Format(" and Image_Category_ID={0} ", _dbimagetype); } if (_dbimagetype == -1) { where += string.Format(" and Image_Category_ID>{0} ", 0); } if (!string.IsNullOrEmpty(dbimagedate)) { where += string.Format(" and ( CONVERT(varchar(100), Image_addtime, 23)=''{0}'' )", dbimagedate); } if (!string.IsNullOrEmpty(dbimagename)) { where += string.Format(" and Image_name like ''%{0}%''", dbimagename); } string _where = Server.UrlDecode(this.Request.QueryString["nwhere"] + ""); bool HasOneEqOne = !((_where + "").Trim().Length <= 3); bool IsOneEqOne = ((where + "").Trim().Length <= 3); if (IsOneEqOne && !string.IsNullOrEmpty(_where) && HasOneEqOne) { _where = this.Server.UrlDecode(_where); where = _where; } else { _where = where; } NModel.PageData <NModel.DB_Image> PD = new NModel.PageData <NModel.DB_Image>() { NumPerPage = numPerPage, PageNum = pagenum, TotalPage = dal.GetWhereListTotal(where), Where = where, OrderField = order }; dal.Close(); return(View(PD)); }
public ActionResult Item_db_img_dialog() { BLL.DB_Image dal = new BLL.DB_Image(); string pagenum = this.Request.Form["pagenum"]; string numPerPage = this.Request.Form["numPerPage"]; string dbimagetype = this.Request.Form["dbimagetype"]; string dbimagedate = this.Request.Form["dbimagedate"]; string dbimagename = this.Request.Form["dbimagename"]; string db_image_type = this.Request.QueryString["db_image_type"]; string selectid = this.Request.QueryString["selectid"]; if (!string.IsNullOrEmpty(selectid)) { dbimagetype = selectid; } if (!string.IsNullOrEmpty(db_image_type)) { dbimagetype = db_image_type; } string where = "", order = "Image_addtime desc"; if (string.IsNullOrEmpty(numPerPage)) { numPerPage = "20"; } if (string.IsNullOrEmpty(pagenum)) { pagenum = "1"; } int _dbimagetype = 0; int.TryParse(dbimagetype, out _dbimagetype); where += " 1=1 "; if (_dbimagetype > 0) { where += string.Format(" and Image_Category_ID={0} ", _dbimagetype); } if (!string.IsNullOrEmpty(dbimagedate)) { where += string.Format(" and ( CONVERT(varchar(100), Image_addtime, 23)=''{0}'' )", dbimagedate); } if (!string.IsNullOrEmpty(dbimagename)) { where += string.Format(" and Image_name like ''%{0}%''", dbimagename); } NModel.PageData <NModel.DB_Image> PD = new NModel.PageData <NModel.DB_Image>() { NumPerPage = numPerPage, PageNum = pagenum, TotalPage = dal.GetWhereListTotal(where), Where = where, OrderField = order }; dal.Close(); return(View(PD)); }
public ActionResult UploadHeadCut() { BLL.DB_Img_Category dal = new BLL.DB_Img_Category(); System.Drawing.Image img = null; //进行裁剪 System.Drawing.Bitmap bmpCrop = null; BLL.DB_Image dal_di = new BLL.DB_Image(); NModel.DB_Img_Category c_dic = new NModel.DB_Img_Category(); try { Response.ContentType = "text/plain"; String _img = Request.Form["img"]; string oldPath = Server.MapPath(uploadPath) + "\\" + _img.Trim(); //新图片路径 string newimg = "small_" + DateTime.Now.ToString("hhmmssfff") + _img; ; String newPath = Server.MapPath(uploadPath) + "\\" + newimg; //设置截取的坐标和大小 int x = 0, y = 20, width = 200, height = 2400; string _x = Request.Form["x"]; string _y = Request.Form["y"]; string _w = Request.Form["w"]; string _h = Request.Form["h"]; int.TryParse(_x, out x); int.TryParse(_y, out y); int.TryParse(_w, out width); int.TryParse(_h, out height); //计算新的文件名,在旧文件名后加_new //定义截取矩形 System.Drawing.Rectangle cropArea = new System.Drawing.Rectangle(x, y, width, height); //要截取的区域大小 //加载图片 img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(System.IO.File.ReadAllBytes(oldPath))); //判断超出的位置否 if ((img.Width < x + width) || img.Height < y + height) { Response.Write("截取的区域超过了图片本身的高度、宽度."); img.Dispose(); return(View()); } //定义Bitmap对象 System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(img); //进行裁剪 bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat); //保存成新文件 string dffpath = this.Server.MapPath(UFPath); bool Has = System.IO.Directory.Exists(dffpath); if (!Has) { System.IO.Directory.CreateDirectory(dffpath); } string thumbnail_id = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string file_id = DateTime.Now.ToString("yyyyMMdd"); string AllFilePath = dffpath; string allPath = this.Server.MapPath(DictFilePath); string ALLDFPath = this.Server.MapPath(DFPath); string cid = this.Request.QueryString["cid"]; int count = Request.Files.Count; long _cid = 0; long.TryParse(cid, out _cid); string size = "0x0"; { if (_cid > 0) { c_dic = dal.GetModel(_cid); if (c_dic != null && !string.IsNullOrEmpty(c_dic.Img_category_Folder)) { file_id = c_dic.Img_category_Folder; } if (c_dic != null && !string.IsNullOrEmpty(c_dic.Img_category_Size)) { size = c_dic.Img_category_Size; } } // original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream); //system.Drawing.Image.FromFile(ph) string[] sz = size.Split(';'); string[] fr = file_id.Split(';'); if (fr != null && fr.Length <= 10 && sz != null && sz.Length <= 10) { for (int i = 0; i < fr.Length; i++) { bool _Has = System.IO.Directory.Exists(ALLDFPath + "/" + fr[i]); if (!_Has) { System.IO.Directory.CreateDirectory(ALLDFPath + "/" + fr[i]); } string[] xy = sz[i].Split('x'); int.TryParse(xy[0], out x); int.TryParse(xy[1], out y); string savepath = "/" + fr[i] + "/" + newimg; string ap = ALLDFPath + savepath; dal_di.DelByBelongsID(BLL.Fun.Current_Login_DB_User().User_ID); string delImagepath = ""; NModel.DB_Image cdi = dal_di.GetModelByBelongsID(BLL.Fun.Current_Login_DB_User().User_ID); if (cdi != null && !string.IsNullOrEmpty(cdi.Image_Url)) { delImagepath = UploadFileController.DFPath + cdi.Image_Url; bool isdelOk = Tool.NImage.DelImage(delImagepath); } bmpCrop.Save(ap.Trim()); var user = BLL.Fun.Current_Login_DB_User(); NModel.DB_Image c_di = new NModel.DB_Image(); c_di.Image_AddTime = DateTime.Parse(DateTime.Now.ToString("s")); c_di.Image_EditTime = DateTime.Parse(DateTime.Now.ToString("s")); c_di.Image_Category_ID = _cid; c_di.Image_SortNo = 1; c_di.Image_Status = 1; c_di.Image_Size = sz[i]; c_di.Image_Operate = 1; c_di.Image_Url = savepath; c_di.Image_Belongs_ID = long.Parse(user.User_ID + ""); c_di.Image_Name = user.User_Name; bool isadd = dal_di.Add(c_di) > 0 ? true : false; if (isadd) { BLL.DB_User bll = new BLL.DB_User(); NModel.DB_User user_model = new NModel.DB_User(); user_model.User_HeadImg = "/upload/" + imgPath + "" + savepath; bll.EditFree(user_model, (long)user.User_ID); bll.Close(); Response.Write("/upload/" + imgPath + "" + savepath); } else { Response.Write("/content/web/img/noerr.png"); } } } } } catch (Exception ex) { } finally { if (dal != null) { dal.Close(); } if (dal_di != null) { dal_di.Close(); } //释放对象 if (img != null) { img.Dispose(); } if (bmpCrop != null) { bmpCrop.Dispose(); } } return(View()); }
public ActionResult UploadFile() { Response.Clear(); System.Drawing.Image thumbnail_image = null; System.Drawing.Image original_image = null; System.Drawing.Bitmap final_image = null; System.Drawing.Graphics graphic = null; MemoryStream ms = null; try { string dffpath = this.Server.MapPath(UFPath); bool Has = System.IO.Directory.Exists(dffpath); if (!Has) { System.IO.Directory.CreateDirectory(dffpath); } // Get the data HttpPostedFileBase jpeg_image_upload = Request.Files["image"]; if (jpeg_image_upload == null) { jpeg_image_upload = Request.Files["file"]; } string type = this.Request.QueryString["type"]; string cid = this.Request.QueryString["cid"]; int count = Request.Files.Count; // Retrieve the uploaded image string thumbnail_id = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string file_id = DateTime.Now.ToString("yyyyMMdd"); string AllFilePath = dffpath; string allPath = this.Server.MapPath(DictFilePath); string ALLDFPath = this.Server.MapPath(DFPath); long _cid = 0; long.TryParse(cid, out _cid); string size = "0x0"; int x = 0, y = 0; //jpeg_image_upload.FileName string extName = System.IO.Path.GetExtension(jpeg_image_upload.FileName); switch (extName.ToLower()) { case ".jpg": case ".png": case ".jpeg": case ".gif": case ".pdf": case ".txt": case ".zip": case ".rar": case ".doc": break; default: return(View()); } string mine = type; switch (mine) { case "img": { BLL.DB_Img_Category dal = new BLL.DB_Img_Category(); NModel.DB_Img_Category c_dic = new NModel.DB_Img_Category(); if (_cid > 0) { c_dic = dal.GetModel(_cid); if (c_dic != null && !string.IsNullOrEmpty(c_dic.Img_category_Folder)) { file_id = c_dic.Img_category_Folder; } if (c_dic != null && !string.IsNullOrEmpty(c_dic.Img_category_Size)) { size = c_dic.Img_category_Size; } } // original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream); //system.Drawing.Image.FromFile(ph) string[] sz = size.Split(';'); string[] fr = file_id.Split(';'); if (fr != null && fr.Length <= 10 && sz != null && sz.Length <= 10) { for (int i = 0; i < fr.Length; i++) { bool _Has = System.IO.Directory.Exists(ALLDFPath + "/" + fr[i]); if (!_Has) { System.IO.Directory.CreateDirectory(ALLDFPath + "/" + fr[i]); } string[] xy = sz[i].Split('x'); int.TryParse(xy[0], out x); int.TryParse(xy[1], out y); string lastName = System.IO.Path.GetExtension(jpeg_image_upload.FileName); string savepath = "/" + fr[i] + "/" + thumbnail_id + "" + lastName; ; string ap = ALLDFPath + savepath; original_image = System.Drawing.Image.FromStream(jpeg_image_upload.InputStream); if (x == 0 && y == 0) { jpeg_image_upload.SaveAs(ap); } else { Tool.NImage.MakeThumbnail(original_image, ap, x, y, "Cut"); } BLL.DB_Image dal_di = new BLL.DB_Image(); NModel.DB_Image c_di = new NModel.DB_Image(); c_di.Image_AddTime = DateTime.Parse(DateTime.Now.ToString("s")); c_di.Image_EditTime = DateTime.Parse(DateTime.Now.ToString("s")); c_di.Image_Category_ID = _cid; c_di.Image_SortNo = 1; c_di.Image_Status = 1; c_di.Image_Size = sz[i]; c_di.Image_Operate = 1; c_di.Image_Url = savepath; c_di.Image_Name = System.IO.Path.GetFileNameWithoutExtension(jpeg_image_upload.FileName); bool isadd = dal_di.Add(c_di) > 0 ? true : false; if (isadd) { Response.Write(Tool.NMsg.SetMsg("" + savepath + "", "1")); Response.End(); } else { Response.Write(Tool.NMsg.SetMsg("上传失败", "0")); Response.End(); } dal.Close(); dal_di.Close(); } } } break; default: { BLL.DB_File dal_di = new BLL.DB_File(); NModel.DB_File c_di = new NModel.DB_File(); BLL.DB_File_Category dal = new BLL.DB_File_Category(); if (_cid > 0) { NModel.DB_File_Category _c_di = dal.GetModel(_cid); if (_c_di != null && !string.IsNullOrEmpty(c_di.File_Category_Folder)) { file_id = _c_di.File_Category_Folder; } //if (c_dic != null && !string.IsNullOrEmpty(c_dic.File_Category_Size)) //{ // size = c_dic.File_Category_Size; //} } //string[] sz = size.Split(';'); string[] fr = file_id.Split(';'); if (fr != null && fr.Length <= 10) { for (int i = 0; i < fr.Length; i++) { bool _Has = System.IO.Directory.Exists(allPath + "/" + fr[i]); if (!_Has) { System.IO.Directory.CreateDirectory(allPath + "/" + fr[i]); } string lastName = System.IO.Path.GetExtension(jpeg_image_upload.FileName); string savepath = "/" + fr[i] + "/" + thumbnail_id + "" + lastName; ; string ap = allPath + savepath; /// 保存文件 jpeg_image_upload.SaveAs(ap); c_di.File_AddTime = DateTime.Parse(DateTime.Now.ToString("s")); c_di.File_EditTime = DateTime.Parse(DateTime.Now.ToString("s")); c_di.File_Cty_ID = _cid; c_di.File_SortNo = 1; c_di.File_Status = 1; c_di.File_Size = jpeg_image_upload.ContentLength + ""; c_di.File_Operate = 1; c_di.File_URL = savepath; c_di.File_Name = System.IO.Path.GetFileNameWithoutExtension(jpeg_image_upload.FileName); bool isadd = dal_di.Add(c_di) > 0 ? true : false; if (isadd) { // var img= info["response"]; Response.Write(Tool.NMsg.SetMsg("" + savepath + "", "1")); Response.End(); } else { Response.Write(Tool.NMsg.SetMsg("上传失败", "0")); Response.End(); } } } dal_di.Close(); dal.Close(); } break; } Response.StatusCode = 200; } catch { // If any kind of error occurs return a 500 Internal Server error Response.StatusCode = 500; Response.Write("{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to open input stream.\"}, \"id\" : \"id\"}"); // Response.End(); } finally { // Clean up if (final_image != null) { final_image.Dispose(); } if (graphic != null) { graphic.Dispose(); } if (original_image != null) { original_image.Dispose(); } if (thumbnail_image != null) { thumbnail_image.Dispose(); } if (ms != null) { ms.Close(); } // Response.End(); } return(View()); }