/// <summary> /// 文件重命名 /// </summary> public void ReName(string id) { var msg = new ModJsonResult(); try { BllSysFileAttach Back = new BllSysFileAttach(); var Model = Back.LoadData(id); if (Model != null) { Model.NameOld = Request["FileName"].ToString(); int result = Back.Update(Model); if (result > 0) { msg.success = true; } else { msg.success = false; msg.msg = "操作失败"; } } } catch (Exception ex) { msg.msg = "操作失败:" + ex.Message; } WriteJsonToPage(msg.ToString()); }
/// <summary> /// 附件下载 /// </summary> /// <param name="mod"></param> public ActionResult FileDownInfo() { var msg = new ModJsonResult(); //主键 var Id = (Request["Id"] == null ? "" : Request["Id"]); BllSysFileAttach Back = new BllSysFileAttach(); var Model = Back.LoadData(Id); if (Model != null) { string filePath = Model.FilePath; string fileName = Model.NameOld; string extions = Model.Extension; filePath = Server.MapPath(filePath); if (System.IO.File.Exists(filePath) == true) { FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName + extions)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } } return(new EmptyResult()); }
/// <summary> /// 删除 /// </summary> public void DeleteData(string id) { var msg = new ModJsonResult(); try { BllSysFileAttach Back = new BllSysFileAttach(); var Model = Back.LoadData(id); if (Model != null) { string path = Model.FilePath; //文件路径 string savepath = System.Web.HttpContext.Current.Server.MapPath(path); string ContractId = Model.KeyId; //关联合同ID string code = Model.ModelCode; int result = Back.Delete(id); if (result > 0) { msg.success = true; if (System.IO.File.Exists(savepath)) { System.IO.File.Delete(savepath);//删除文件 } switch (code) { case "InCome": //收入合同 case "OutCome": //支付合同 var list = Back.QueryToAll().Where(p => p.KeyId == ContractId).ToList(); if (list.Count == 0) { var temp = new BllContractInOut().LoadData(ContractId); if (temp != null) { temp.HasFileAttach = false; new BllContractInOut().Update(temp); } } break; } } else { msg.success = false; msg.msg = "操作失败"; } } } catch (Exception ex) { msg.msg = "操作失败:" + ex.Message; } WriteJsonToPage(msg.ToString()); }