public static string GetEnFilesUrl(Entity en) { string str = null; SysFileManagers ens = en.HisSysFileManagers; string path = BP.Sys.Glo.Request.ApplicationPath; foreach (SysFileManager file in ens) { str += "[<a href='" + path + file.MyFilePath + "' target='f" + file.OID + "' >" + file.MyFileName + "</a>]"; } return(str); }
public void Save() { Entity en = this.GetEns.GetNewEntity; if (this.PKVal != null) { en.PKVal = this.PKVal; en.RetrieveFromDBSources(); } en = this.UCEn1.GetEnData(en); this.CurrEn = en; en.Save(); this.PKVal = en.PKVal; #region 保存 实体附件 try { if (en.EnMap.Attrs.Contains("MyFileName")) { HtmlInputFile file = this.UCEn1.FindControl("file") as HtmlInputFile; if (file != null && file.Value.IndexOf(".") != -1) { BP.Sys.EnCfg cfg = new EnCfg(en.ToString()); if (System.IO.Directory.Exists(cfg.FJSavePath) == false) { System.IO.Directory.CreateDirectory(cfg.FJSavePath); } /* 如果包含这二个字段。*/ string fileName = file.PostedFile.FileName; fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1); string filePath = cfg.FJSavePath; en.SetValByKey("MyFilePath", filePath); string ext = ""; if (fileName.IndexOf(".") != -1) { ext = fileName.Substring(fileName.LastIndexOf(".") + 1); } en.SetValByKey("MyFileExt", ext); en.SetValByKey("MyFileName", fileName); en.SetValByKey("WebPath", cfg.FJWebPath + en.PKVal + "." + ext); string fullFile = filePath + "/" + en.PKVal + "." + ext; file.PostedFile.SaveAs(fullFile); file.PostedFile.InputStream.Close(); file.PostedFile.InputStream.Dispose(); file.Dispose(); System.IO.FileInfo info = new System.IO.FileInfo(fullFile); en.SetValByKey("MyFileSize", BP.DA.DataType.PraseToMB(info.Length)); if (DataType.IsImgExt(ext)) { System.Drawing.Image img = System.Drawing.Image.FromFile(fullFile); en.SetValByKey("MyFileH", img.Height); en.SetValByKey("MyFileW", img.Width); img.Dispose(); } en.Update(); } } } catch (Exception ex) { this.Alert("保存附件出现错误:" + ex.Message); } #endregion #region 保存 属性 附件 try { AttrFiles fils = en.EnMap.HisAttrFiles; SysFileManagers sfs = new SysFileManagers(en.ToString(), en.PKVal.ToString()); foreach (AttrFile fl in fils) { HtmlInputFile file = (HtmlInputFile)this.UCEn1.FindControl("F" + fl.FileNo); if (file.Value.Contains(".") == false) { continue; } SysFileManager enFile = sfs.GetEntityByKey(SysFileManagerAttr.AttrFileNo, fl.FileNo) as SysFileManager; SysFileManager enN = null; if (enFile == null) { enN = this.FileSave(null, file, en); } else { enFile.Delete(); enN = this.FileSave(null, file, en); } enN.AttrFileNo = fl.FileNo; enN.AttrFileName = fl.FileName; enN.EnName = en.ToString(); enN.Update(); } } catch (Exception ex) { this.Alert("保存附件出现错误:" + ex.Message); } #endregion }