public JsonResult ImportEdit(string keyValue, bool ck, SevenSEntity model) { var success = true; var message = "修改成功"; try { var user = OperatorProvider.Provider.Current(); if (ck) { FileInfoBLL fileInfoBLL = new FileInfoBLL(); var fileList = fileInfoBLL.GetFilesByRecIdNew(keyValue).OrderBy(x => x.CreateDate).ToList(); var fileListold = fileInfoBLL.GetFilesByRecIdNew(model.ID); for (int i = 0; i < fileList.Count; i++) { if (i > 0) { fileInfoBLL.DeleteFile(keyValue, fileList[i].FileName, fileList[i].FilePath); } else { fileList[i].RecId = model.ID; fileInfoBLL.SaveFormEmergency(fileList[i].FileId, fileList[i]); } } for (int i = 0; i < fileListold.Count; i++) { fileInfoBLL.DeleteFile(fileListold[i].RecId, fileListold[i].FileName, fileListold[i].FilePath); } model.CREATEUSERID = user.UserId; model.CREATEUSERNAME = user.UserName; ebll.SaveForm(model.ID, model); } else { var one = ebll.GetSevenSEntity(model.ID); one.Name = model.Name; ebll.SaveSevenSEntity(one); } } catch (Exception ex) { success = false; message = ex.Message; } return(Json(new AjaxResult { type = success ? ResultType.success : ResultType.error, message = HttpUtility.JavaScriptStringEncode(message) })); }
public JsonResult DeleteItem(string id) { var success = true; var message = "删除成功"; try { var user = OperatorProvider.Provider.Current(); FileInfoBLL fileInfoBLL = new FileInfoBLL(); var fileList = fileInfoBLL.GetFilesByRecIdNew(id); for (int i = 0; i < fileList.Count; i++) { fileInfoBLL.DeleteFile(fileList[i].RecId, fileList[i].FileName, Server.MapPath(fileList[i].FilePath)); } ebll.DeleteItem(id); } catch (Exception ex) { success = false; message = ex.Message; } return(Json(new AjaxResult { type = success ? ResultType.success : ResultType.error, message = HttpUtility.JavaScriptStringEncode(message) })); }
public ActionResult RemoveFile(string fileName, string recId) { FileInfoBLL fileBll = new FileInfoBLL(); FileInfoEntity entity = fileBll.GetEntity(recId, fileName); int res = 0; if (entity != null) { res = fileBll.DeleteFile(recId, fileName, Server.MapPath(entity.FilePath)); } return(res > 0 ? Success("操作成功。") : Error("操作失败")); }
public JsonResult ImportEditPush(string keyvalue) { var success = true; var message = string.Empty; try { FileInfoBLL fileInfoBLL = new FileInfoBLL(); string newFilePath = ""; if (this.Request.Files.Count == 0) { throw new Exception("请上传文件"); } var file = this.Request.Files[0]; string fileName = System.IO.Path.GetFileName(file.FileName); //if (!fileName.Contains(".pdf")) //{ // throw new Exception("请检查文件格式!"); //} var fileListold = fileInfoBLL.GetFilesByRecIdNew(keyvalue); for (int i = 0; i < fileListold.Count; i++) { fileInfoBLL.DeleteFile(fileListold[i].RecId, fileListold[i].FileName, fileListold[i].FilePath); } string fileGuid = Guid.NewGuid().ToString(); long filesize = file.ContentLength; string FileEextension = Path.GetExtension(fileName); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string dir = string.Format("~/Resource/{0}/{1}", "Emergency", uploadDate); string newFileName = fileGuid + FileEextension; newFilePath = dir + "/" + newFileName; if (!Directory.Exists(Server.MapPath(dir))) { Directory.CreateDirectory(Server.MapPath(dir)); } FileInfoEntity fileInfoEntity = new FileInfoEntity(); if (!System.IO.File.Exists(Server.MapPath(newFilePath))) { //保存文件 file.SaveAs(Server.MapPath(newFilePath)); //文件信息写入数据库 fileInfoEntity.Create(); fileInfoEntity.FolderId = "Emergency"; fileInfoEntity.FileId = fileGuid; fileInfoEntity.RecId = keyvalue; fileInfoEntity.FileName = fileName; fileInfoEntity.FilePath = dir + "/" + newFileName; fileInfoEntity.FileSize = (Math.Round(decimal.Parse(filesize.ToString()) / decimal.Parse("1024"), 2)).ToString();//文件大小(kb) fileInfoEntity.FileExtensions = FileEextension; fileInfoEntity.FileType = FileEextension.TrimStart('.'); fileInfoBLL.SaveForm("", fileInfoEntity); } message = fileInfoEntity.FileName; } catch (Exception ex) { success = false; message = HttpUtility.JavaScriptStringEncode(ex.Message); } return(Json(new { success, message })); }