protected void Page_Load(object sender, System.EventArgs e) { switch (this.DoType) { case "DelGradeEns": Entity enGrade = BP.DA.ClassFactory.GetEns(this.EnsName).GetNewEntity; enGrade.PKVal = this.RefPK; enGrade.Delete(); this.WinClose(); return; case "DownFile": Entity enF = BP.DA.ClassFactory.GetEn(this.EnName); enF.PKVal = this.Request.QueryString["PK"]; enF.Retrieve(); string pPath = enF.GetValStringByKey("MyFilePath") + "\\" + enF.PKVal + "." + enF.GetValStringByKey("MyFileExt"); BP.PubClass.DownloadFile(pPath, enF.GetValStringByKey("MyFileName")); this.WinClose(); return; default: break; } switch (this.GetActionType) { case ActionType.DeleteFile: SysFileManager sysfile = new SysFileManager(int.Parse(this.Request.QueryString["OID"])); sysfile.Delete(); break; case ActionType.PrintEnBill: string className = this.Request.QueryString["MainEnsName"]; Entity en = ClassFactory.GetEns(className).GetNewEntity; try { en.PKVal = this.Request.QueryString["PK"]; en.Retrieve(); } catch { en.PKVal = this.Request.QueryString[en.PK]; en.Retrieve(); } //this.GenerRptByPeng(en); break; default: throw new Exception("do error" + this.GetActionType); } this.WinClose(); }
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 }