public PurchaseAttachGridViewModel(IQueryable <PurchaseItem> _models, IAttachFileInfoRepository _attachFileInfoRepository) { foreach (var p in _models) { AttachFileInfo _file = _attachFileInfoRepository.GetAttachByObj(p.AttachObjID, "PurchaseItems").FirstOrDefault() ?? new AttachFileInfo(); rows.Add(new PurchaseAttachGridRowModel(p, _file)); } }
public int Delete(AttachFileInfo model) { if (model.Enable == true) { model.Enable = false; _context.SaveChanges(); return(1); } return(-1); }
public AttachGridRowModel(AttachFileInfo model) { cell = new string[8]; cell[0] = model.ObjID; cell[1] = model.ObjType; cell[2] = model.FilePath; cell[3] = model.FileName; cell[4] = model.FileType; cell[5] = model.FileSize.ToString(); cell[6] = model.CreateTime.ToString("yyyy-MM-dd"); cell[7] = model.Creator; }
public ActionResult Service_FileDownLoad(string ObjID, string ObjType, string FileName, string FileType) { try { AttachFileInfo _model = _attachFileInfoRepository.GetAttachModel(ObjID, ObjType, FileName, FileType); string _url = Server.MapPath("~") + _model.FilePath + _model.FileName + "." + _model.FileType; //return File(_url, "text/plain",_model.FileName); //返回file return(File(new FileStream(_url, FileMode.Open), "text/plain", _model.FileName + "." + _model.FileType)); //返回FileStream } catch (Exception ex) { LogRecord("附件下载", ex.InnerException == null ? ex.Message : ex.InnerException.InnerException == null ? ex.Message : ex.InnerException.InnerException.ToString()); return(Json(new { Code = -1, Message = "附件下载失败!" }, JsonRequestBehavior.AllowGet)); } }
public PurchaseAttachGridRowModel(PurchaseItem _item, AttachFileInfo model) { cell = new string[13]; cell[0] = model.ObjID ?? ""; cell[1] = model.ObjType ?? ""; cell[2] = _item.PartNumber ?? ""; cell[3] = _item.Name ?? ""; cell[4] = _item.Specification ?? ""; cell[5] = _item.Material ?? ""; cell[6] = _item.Quantity.ToString() ?? ""; cell[7] = model.FilePath ?? ""; cell[8] = model.FileName ?? ""; cell[9] = model.FileType ?? ""; cell[10] = model.FileSize.ToString(); cell[11] = model.CreateTime.ToString("yyyy-MM-dd"); cell[12] = model.Creator ?? ""; }
public JsonResult Service_DelAttach(string ObjID, string ObjType, string FileName, string FileType) { try { AttachFileInfo _model = _attachFileInfoRepository.GetAttachModel(ObjID, ObjType, FileName, FileType); if (_model.Creator != GetCurrentUser()) { return(Json(new { Code = -1 }, JsonRequestBehavior.AllowGet)); } else { _attachFileInfoRepository.Delete(_model); } return(Json(new { Code = 1 }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogRecord("附件删除", ex.InnerException == null? ex.Message: ex.InnerException.InnerException == null ? ex.Message: ex.InnerException.InnerException.ToString()); return(Json(new { Code = -1, Message = "附件删除失败!" }, JsonRequestBehavior.AllowGet)); } }
public int Save(AttachFileInfo model) { AttachFileInfo _attach = _context.AttachFileInfos.Where(t => t.ObjID == model.ObjID && t.ObjType == model.ObjType && t.FileName == model.FileName && t.FileType == model.FileType).FirstOrDefault(); if (_attach == null) { model.CreateTime = DateTime.Now; model.Enable = true; _context.AttachFileInfos.Add(model); } else { //_attach.FileStream = model.FileStream; _attach.Creator = model.Creator; _attach.CreateTime = DateTime.Now; _attach.FileSize = _attach.FileSize; _attach.Enable = true; } _context.SaveChanges(); return(1); }
public JsonResult Service_FileUpload(string ObjID, string ObjType, string FolderName, IEnumerable <HttpPostedFileBase> Files) { try { #region 创建文件夹 string filePath = Server.MapPath(string.Format("~/{0}/{1}/{2}", "Upload", ObjType, FolderName)); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } #endregion foreach (HttpPostedFileBase _file in Files) { #region 保存文件 string fileName = _file.FileName.Substring(0, _file.FileName.LastIndexOf('.')); //if (fileName.IndexOf('+') > 0) //{ // return Json(new { Code = -99, Message = "Error:文件名包含特殊字符(如:'+')" }, JsonRequestBehavior.AllowGet); //} string ImportFilePath = Path.Combine(filePath, _file.FileName); if (System.IO.File.Exists(ImportFilePath)) { ImportFilePath = Path.Combine(filePath, _file.FileName.Substring(0, _file.FileName.LastIndexOf('.')) + "(" + DateTime.Now.ToString("yyMMddHHmmss") + ")" + _file.FileName.Substring(_file.FileName.LastIndexOf('.'), _file.FileName.Length - _file.FileName.LastIndexOf('.'))); fileName = fileName + "(" + DateTime.Now.ToString("yyMMddHHmmss") + ")"; } _file.SaveAs(ImportFilePath); #endregion #region 文件转成流并格式化 AttachFileInfo af = new AttachFileInfo(); //string timeStamp = ""; #region 获取文件流并转化为btye[] Stream fs = _file.InputStream; Byte[] btye1 = new byte[fs.Length]; fs.Read(btye1, 0, Convert.ToInt32(fs.Length)); fs.Close(); #endregion //#region 获取时间戳 //TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); //timeStamp = Convert.ToInt64(ts.TotalSeconds).ToString() + btye1.Length.ToString(); //#endregion //af.EmbedID = timeStamp; //if (fileName.IndexOf('+') > 0) //{ // fileName = fileName.Replace("+", "%2B"); //} af.FileName = fileName; af.FileStream = new byte[1]; af.FileType = _file.FileName.Split('.')[1]; af.Creator = GetCurrentUser(); af.ObjID = ObjID; af.ObjType = ObjType; af.FileSize = Math.Round(Convert.ToDouble(btye1.Length * 1.0 / (1024 * 1024)), 2); af.FilePath = @"\Upload\" + ObjType + @"\" + FolderName + @"\"; _attachFileInfoRepository.Save(af); #endregion } return(Json(new { Code = 1, Message = "OK" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogRecord("附件上传", ex.InnerException == null ? ex.Message : ex.InnerException.InnerException == null ? ex.Message : ex.InnerException.InnerException.ToString()); return(Json(new { Code = -1, Message = "附件上传失败!" }, JsonRequestBehavior.AllowGet)); } }