/// <summary> /// 更新附件备注 /// </summary> /// <param name="attachenmt"></param> /// <returns></returns> public string UpdAttachment(T_Attachment attachenmt) { string msg = string.Empty; bool result = new AttachmentSvc().UpdAttachment(attachenmt.A_GUID, attachenmt.FileName, attachenmt.FileRemark); if (result) { msg = General.Resource.Common.Success; } else { msg = General.Resource.Common.Failed; } return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}" , result.ToString().ToLower(), msg)); }
/// <summary> /// 删除记录的所有附件 /// </summary> /// <param name="id">收款纪录标识</param> /// <returns></returns> public string DelAttachment(string id) { bool result = new AttachmentSvc().DelAttachment(id); string msg = string.Empty; if (result) { msg = General.Resource.Common.Success; } else { msg = General.Resource.Common.Failed; } return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}" , result.ToString().ToLower(), msg)); }
/// <summary> /// 下载附件 /// </summary> /// <param name="id"></param> /// <returns></returns> public string DownLoadFile(string id) { try { AttachmentSvc attSv = new AttachmentSvc(); List <T_Attachment> ent = attSv.GetAttachment(id); var entity = ent[0]; //从数据库查找 System.IO.File.WriteAllBytes(System.Web.HttpContext.Current.Request.MapPath("/") + "img/temp/" + id + entity.FileName, entity.FlieData); return((id + entity.FileName).ToString()); } catch { return(""); } }
public ActionResult GetFile(string fn) { Response.Cache.SetOmitVaryStar(true); var filePath = StringUtility.XBase64Decode(fn); filePath = AttachmentSvc.GetFullPath(filePath); if (!System.IO.File.Exists(filePath)) { return(HttpNotFound("-File Not Found-")); } var fileExt = Path.GetExtension(filePath); var fileContentType = AttachmentSvc.GetFileContentType(fileExt); return(File(filePath, fileContentType)); }
/// <summary> /// 修改附件名称 /// </summary> /// <param name=""></param> /// <returns></returns> /// <remarks>hdy 2017/03/09 create</remarks> public string UpdHaveFileUpload(T_Attachment form) { bool result = false; string msg = string.Empty; result = new AttachmentSvc().UpdHaveFileUpload(form); if (result) { msg = General.Resource.Common.Success; } else { msg = General.Resource.Common.Failed; } return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}" , result.ToString().ToLower(), msg)); }
/// <summary> /// 上传图片 /// </summary> /// <param name="frGuid"></param> /// <returns></returns> /// <remarks>liujf 2016/05/05 create</remarks> public ActionResult FileUpload(string frGuid, string TempFileNameFirst) { var files = Request.Files; ExceResult res = new ExceResult(); //获取当前时间戳 string CreateDate = GetDetailDate(); if (files != null && files.Count > 0) { ControllerContext.HttpContext.Request.ContentEncoding = Encoding.GetEncoding("UTF-8"); ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8"); ControllerContext.HttpContext.Response.Charset = "UTF-8"; //写入数据流 Stream fileStream = files[0].InputStream; byte[] fileDataStream = new byte[files[0].ContentLength]; fileStream.Read(fileDataStream, 0, files[0].ContentLength); //写入数据 for (int iFile = 0; iFile < files.Count; iFile++) { T_Attachment entity = new T_Attachment(); entity.A_GUID = Guid.NewGuid().ToString(); entity.FileName = TempFileNameFirst + CreateDate; entity.FileType = files[0].ContentType; entity.FR_GUID = frGuid; entity.FlieData = fileDataStream; bool rResult = new AttachmentSvc().AddAttachment(entity); if (rResult) { res.success = true; } else { res.success = false; res.msg = "保存附件异常"; } } } return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(res))); }
public async Task <ActionResult> AdvertEdit(Advert model) { if (model.EndTime != null && model.EndTime < model.StartTime) { ModelState.AddModelError("EndTime", "结束时间不能小于开始时间"); } var result = new JsonModel(); // 数据有误 if (!ModelState.IsValid) { result.GetError(ModelState); return(Json(result)); } var operationType = OperationType.Insert; var operationTitle = "添加广告"; if (model.Id > 0) { var advert = await AdvertRepository.GetByIdAsync(model.Id); if (advert == null) { result.message = string.Format("找不到id为{0}的广告!", model.Id); result.statusCode = 300; return(Json(result)); } operationType = OperationType.Insert; operationTitle = "编辑广告"; } await AdvertRepository.SaveAsync(model); await AttachmentSvc.BoundAttachment(model.Id, model.ImgUrl, model.MetaContent); await LogRepository.Insert(TableSource.Adverts, operationType, operationTitle, model.Id); result.Data = model; result.message = "保存成功!"; return(Json(result)); }
/// <summary> /// 上传图片 /// </summary> /// <param name="fileData">上传文件</param> /// <param name="guid"></param> /// <param name="folder"></param> /// <returns></returns> //[AcceptVerbs(HttpVerbs.Post)] public ActionResult Upload(HttpPostedFileBase fileData, string guid, string folder) { DelAttachment(guid); if (fileData != null) { try { ControllerContext.HttpContext.Request.ContentEncoding = Encoding.GetEncoding("UTF-8"); ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8"); ControllerContext.HttpContext.Response.Charset = "UTF-8"; //写入数据流 Stream fileStream = fileData.InputStream; byte[] fileDataStream = new byte[fileData.ContentLength]; fileStream.Read(fileDataStream, 0, fileData.ContentLength); //写入数据 T_Attachment entity = new T_Attachment(); entity.A_GUID = Guid.NewGuid().ToString(); entity.FileName = fileData.FileName; entity.FileType = fileData.ContentType; entity.FR_GUID = guid; entity.FlieData = fileDataStream; entity.FileRemark = ""; bool rResult = new AttachmentSvc().AddAttachment(entity); return(Content(rResult.ToString())); } catch (Exception ex) { return(Content("false")); } } else { return(Content("false")); } }
public async Task <ActionResult> Edit(AdPosition model) { ModelState.Remove("ViewName"); var result = new JsonModel(); // 数据有误 if (!ModelState.IsValid) { result.GetError(ModelState); return(Json(result)); } var operationType = OperationType.Insert; var operationTitle = "添加广告位"; if (model.Id != 0) { var adPos = await AdPositionRepository.GetByIdAsync(model.Id); if (adPos == null) { result.message = "记录不存在了"; return(Json(result)); } operationType = OperationType.Update; operationTitle = "修改广告位"; } model.ViewName = string.Format("_{0}", model.Code); await AdPositionRepository.SaveAsync(model); await LogRepository.Insert(TableSource.Users, operationType, operationTitle, model.Id); await AttachmentSvc.BoundAttachment(model.Id, model.ImgUrl); result.Data = model; result.message = "保存成功!"; return(Json(result)); }
public JsonResult BatchUpload(TableSource src, long srcId = 0, int type = 0, int width = 100, int height = 100) { var postedFile = Request.Files["Filedata"]; var table = new Hashtable(); if (null != postedFile && postedFile.ContentLength > 0) { var oAtt = new Attachment { Descript = "", Source = src, SourceId = 0, CreateUserId = User.UserModel.UserId, CreateUserName = User.UserModel.UserName, FilePath = "", }; if (AttachmentSvc.Save(postedFile, oAtt)) { LogRepository.Insert(TableSource.Attachments, OperationType.Insert, oAtt.Id); } table.Add("id", oAtt.Id); table.Add("imgPath", AttachmentSvc.GetPicUrl(oAtt.Id, width, height)); table.Add("imgPathOriginal", AttachmentSvc.GetPicUrl(oAtt.Id)); table.Add("name", oAtt.Name); table.Add("time", oAtt.UpdateTime.ToDisplayDateTime()); table.Add("size", oAtt.FileSizeStr); table.Add("type", type); table.Add("statusCode", JsonModelCode.Succ); } else { table.Add("statusCode", JsonModelCode.Error); table.Add("message", "上传失败"); } return(Json(table)); }