using System; using System.Collections; using BP.DA; using BP.Difference; using BP.En; namespace BP.Sys { /// /// 附件数据存储 - 属性 /// public class FrmAttachmentDBAttr : EntityMyPKAttr { /// /// 附件 /// public const string FK_FrmAttachment = "FK_FrmAttachment"; /// /// 附件标识 /// public const string NoOfObj = "NoOfObj"; /// /// 主表 /// public const string FK_MapData = "FK_MapData"; /// /// RefPKVal /// public const string RefPKVal = "RefPKVal"; /// /// 流程ID /// public const string FID = "FID"; /// /// 文件名称 /// public const string FileName = "FileName"; /// /// 文件扩展 /// public const string FileExts = "FileExts"; /// /// 文件大小 /// public const string FileSize = "FileSize"; /// /// 保存到 /// public const string FileFullName = "FileFullName"; /// /// 记录日期 /// public const string RDT = "RDT"; /// /// 记录人 /// public const string Rec = "Rec"; /// /// 记录人名字 /// public const string RecName = "RecName"; /// /// 所在部门 /// public const string FK_Dept = "FK_Dept"; /// /// 所在部门名称 /// public const string FK_DeptName = "FK_DeptName"; /// /// 类别 /// public const string Sort = "Sort"; /// /// 备注 /// public const string MyNote = "MyNote"; /// /// 节点ID /// public const string NodeID = "NodeID"; /// /// 是否锁定行 /// public const string IsRowLock = "IsRowLock"; /// /// 上传的GUID /// public const string UploadGUID = "UploadGUID"; /// /// Idx /// public const string Idx = "Idx"; /// /// 保存方式 /// public const string AthSaveWay = "AthSaveWay"; } /// /// 附件数据存储 /// public class FrmAttachmentDB : EntityMyPK { #region 属性 /// /// 类别 /// public string Sort { get { return this.GetValStringByKey(FrmAttachmentDBAttr.Sort); } set { this.SetValByKey(FrmAttachmentDBAttr.Sort, value); } } /// /// 记录日期 /// public string RDT { get { string str = this.GetValStringByKey(FrmAttachmentDBAttr.RDT); return str.Substring(5, 11); } set { this.SetValByKey(FrmAttachmentDBAttr.RDT, value); } } /// /// 文件 /// public string FileFullName { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FileFullName); } set { string str = value; str = str.Replace("~", "-"); str = str.Replace("'", "-"); str = str.Replace("*", "-"); this.SetValByKey(FrmAttachmentDBAttr.FileFullName, str); } } /// /// 上传GUID /// public string UploadGUID { get { return this.GetValStringByKey(FrmAttachmentDBAttr.UploadGUID); } set { this.SetValByKey(FrmAttachmentDBAttr.UploadGUID, value); } } /// /// 附件路径 /// public string FilePathName { get { return this.FileFullName.Substring(this.FileFullName.LastIndexOf('/') + 1); } } /// /// 附件名称 /// public string FileName { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FileName); } set { string str = value; str = str.Replace("~", "-"); str = str.Replace("'", "-"); str = str.Replace("*", "-"); this.SetValByKey(FrmAttachmentDBAttr.FileName, str); string fileExt = str.Substring(str.LastIndexOf('.') + 1); //后缀名. this.SetValByKey(FrmAttachmentDBAttr.FileExts, fileExt); } } /// /// 附件扩展名 /// public string FileExts { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FileExts); } set { string val = value.Replace(".", ""); string[] words = { "asp", "jsp", "do", "php", "msi", "bat", "exe", "sql" }; val = val.ToLower(); foreach (var item in words) { if (val.Contains(item) && val.Length == item.Length) throw new Exception("err@非法的文件格式."); } } } /// /// 相关附件 /// public string FK_FrmAttachment { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FK_FrmAttachment); } set { this.SetValByKey(FrmAttachmentDBAttr.FK_FrmAttachment, value); if (DataType.IsNullOrEmpty(this.FK_MapData) == true) throw new Exception("err@错误:请首先给FK_MapData赋值.."); //获取最后"_"的位置 string val = value.Replace(this.FK_MapData + "_", ""); this.SetValByKey(FrmAttachmentDBAttr.NoOfObj, val); } } /// /// 主键值 /// public string RefPKVal { get { return this.GetValStringByKey(FrmAttachmentDBAttr.RefPKVal); } set { this.SetValByKey(FrmAttachmentDBAttr.RefPKVal, value); } } /// /// 工作ID. /// public Int64 FID { get { return this.GetValInt64ByKey(FrmAttachmentDBAttr.FID); } set { this.SetValByKey(FrmAttachmentDBAttr.FID, value); } } /// /// MyNote /// public string MyNote { get { return this.GetValStringByKey(FrmAttachmentDBAttr.MyNote); } set { this.SetValByKey(FrmAttachmentDBAttr.MyNote, value); } } /// /// 记录人 /// public string Rec { get { return this.GetValStringByKey(FrmAttachmentDBAttr.Rec); } set { this.SetValByKey(FrmAttachmentDBAttr.Rec, value); } } /// /// 记录人名称 /// public string RecName { get { return this.GetValStringByKey(FrmAttachmentDBAttr.RecName); } set { this.SetValByKey(FrmAttachmentDBAttr.RecName, value); } } /// /// 所在部门 /// public string FK_Dept { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FK_Dept); } set { this.SetValByKey(FrmAttachmentDBAttr.FK_Dept, value); } } /// /// 所在部门名称 /// public string FK_DeptName { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FK_DeptName); } set { this.SetValByKey(FrmAttachmentDBAttr.FK_DeptName, value); } } /// /// 附件编号 /// public string FK_MapData { get { return this.GetValStringByKey(FrmAttachmentDBAttr.FK_MapData); } set { this.SetValByKey(FrmAttachmentDBAttr.FK_MapData, value); } } public void setFK_MapData(string val) { this.SetValByKey(FrmAttachmentDBAttr.FK_MapData, val); } /// /// 文件大小 /// public float FileSize { get { return this.GetValFloatByKey(FrmAttachmentDBAttr.FileSize); } set { this.SetValByKey(FrmAttachmentDBAttr.FileSize, value / 1024); } } /// /// 是否锁定行? /// public bool IsRowLock { get { return this.GetValBooleanByKey(FrmAttachmentDBAttr.IsRowLock); } set { this.SetValByKey(FrmAttachmentDBAttr.IsRowLock, value); } } /// /// 显示顺序 /// public int Idx { get { return this.GetValIntByKey(FrmAttachmentDBAttr.Idx); } set { this.SetValByKey(FrmAttachmentDBAttr.Idx, value); } } /// /// 附件扩展名 /// public int NodeID { get { return this.GetValIntByKey(FrmAttachmentDBAttr.NodeID); } set { this.SetValByKey(FrmAttachmentDBAttr.NodeID, value); } } /// /// 附件类型 /// public AttachmentUploadType HisAttachmentUploadType { get { if (this.MyPK.Contains("_") && this.MyPK.Length < 32) return AttachmentUploadType.Single; else return AttachmentUploadType.Multi; } } #endregion #region 构造方法 /// /// 附件数据存储 /// public FrmAttachmentDB() { } /// /// 附件数据存储 /// /// public FrmAttachmentDB(string mypk) { this.setMyPK(mypk); this.Retrieve(); } /// /// EnMap /// public override Map EnMap { get { if (this._enMap != null) return this._enMap; Map map = new Map("Sys_FrmAttachmentDB", "附件数据存储"); map.IndexField = FrmAttachmentDBAttr.RefPKVal; map.AddMyPK(); map.AddTBString(FrmAttachmentDBAttr.FK_MapData, null, "FK_MapData", true, false, 1, 100, 20); map.AddTBString(FrmAttachmentDBAttr.FK_FrmAttachment, null, "附件主键", true, false, 1, 500, 20); map.AddTBString(FrmAttachmentDBAttr.NoOfObj, null, "附件标识", true, false, 0, 50, 20); map.AddTBString(FrmAttachmentDBAttr.RefPKVal, null, "实体主键", true, false, 0, 50, 20); map.AddTBInt(FrmAttachmentDBAttr.FID, 0, "FID", true, false); map.AddTBInt(FrmAttachmentDBAttr.NodeID, 0, "节点ID", true, false); map.AddTBString(FrmAttachmentDBAttr.Sort, null, "类别", true, false, 0, 200, 20); map.AddTBString(FrmAttachmentDBAttr.FileFullName, null, "文件路径", true, false, 0, 700, 20); map.AddTBString(FrmAttachmentDBAttr.FileName, null, "名称", true, false, 0, 500, 20); map.AddTBString(FrmAttachmentDBAttr.FileExts, null, "扩展", true, false, 0, 50, 20); map.AddTBFloat(FrmAttachmentDBAttr.FileSize, 0, "文件大小", true, false); map.AddTBDateTime(FrmAttachmentDBAttr.RDT, null, "记录日期", true, false); map.AddTBString(FrmAttachmentDBAttr.Rec, null, "记录人", true, false, 0, 50, 20); map.AddTBString(FrmAttachmentDBAttr.RecName, null, "记录人名字", true, false, 0, 50, 20); map.AddTBString(FrmAttachmentDBAttr.FK_Dept, null, "所在部门", true, false, 0, 50, 20); map.AddTBString(FrmAttachmentDBAttr.FK_DeptName, null, "所在部门名称", true, false, 0, 50, 20); map.AddTBStringDoc(FrmAttachmentDBAttr.MyNote, null, "备注", true, false); map.AddTBInt(FrmAttachmentDBAttr.IsRowLock, 0, "是否锁定行", true, false); //顺序. map.AddTBInt(FrmAttachmentDBAttr.Idx, 0, "排序", true, false); //这个值在上传时候产生. map.AddTBString(FrmAttachmentDBAttr.UploadGUID, null, "上传GUID", true, false, 0, 500, 20); map.AddTBAtParas(3000); //增加参数属性. this._enMap = map; return this._enMap; } } /// /// 生成文件. /// /// private string MakeFullFileFromFtp() { string pathOfTemp = BP.Difference.SystemConfig.PathOfTemp; if (System.IO.Directory.Exists(pathOfTemp) == false) System.IO.Directory.CreateDirectory(pathOfTemp); string tempFile = pathOfTemp + System.Guid.NewGuid() + "." + this.FileExts; // string tempFile = BP.Difference.SystemConfig.PathOfTemp + + this.FileName; try { if (System.IO.File.Exists(tempFile) == true) System.IO.File.Delete(tempFile); } catch { // tempFile = BP.Difference.SystemConfig.PathOfTemp + System.Guid.NewGuid() + this.FileName; } FtpConnection conn = new FtpConnection(BP.Difference.SystemConfig.FTPServerIP, BP.Difference.SystemConfig.FTPServerPort, SystemConfig.FTPUserNo, BP.Difference.SystemConfig.FTPUserPassword); conn.GetFile(this.FileFullName, tempFile, false, System.IO.FileAttributes.Archive); return tempFile; } public string DoDown() { return "执行成功."; } /// /// 重写 /// /// protected override bool beforeInsert() { return base.beforeInsert(); } protected override void afterDelete() { //判断删除excel数据提取的数据 if (string.IsNullOrWhiteSpace(this.FK_FrmAttachment)) return; FrmAttachment ath = new FrmAttachment(this.FK_FrmAttachment); try { // @于庆海需要翻译. if (ath.AthSaveWay == BP.Sys.AthSaveWay.IISServer) System.IO.File.Delete(this.FileFullName); if (ath.AthSaveWay == BP.Sys.AthSaveWay.FTPServer) { FtpConnection ftpconn = new FtpConnection(BP.Difference.SystemConfig.FTPServerIP, BP.Difference.SystemConfig.FTPServerPort, SystemConfig.FTPUserNo, BP.Difference.SystemConfig.FTPUserPassword); string fullName = this.FileFullName; ftpconn.DeleteFile(fullName); } } catch (Exception ex) { BP.DA.Log.DebugWriteError(ex.Message); } base.afterDelete(); } #endregion /// /// 获得临时文件 /// /// public string GenerTempFile(AthSaveWay saveWay = BP.Sys.AthSaveWay.IISServer) { if (saveWay == BP.Sys.AthSaveWay.IISServer) return this.FileFullName; if (saveWay == BP.Sys.AthSaveWay.FTPServer) return this.MakeFullFileFromFtp(); if (saveWay == BP.Sys.AthSaveWay.DB) throw new Exception("@尚未处理存储到db里面的文件."); throw new Exception("@尚未处理存储到db里面的文件."); } /// /// 向下移動 /// public void DoDownTabIdx() { this.DoOrderDown(FrmAttachmentDBAttr.RefPKVal, this.RefPKVal, FrmAttachmentDBAttr.FK_FrmAttachment, this.FK_FrmAttachment, FrmAttachmentDBAttr.Idx); } /// /// 向上移動 /// public void DoUpTabIdx() { this.DoOrderUp(FrmAttachmentDBAttr.RefPKVal, this.RefPKVal, FrmAttachmentDBAttr.FK_FrmAttachment, this.FK_FrmAttachment, FrmAttachmentDBAttr.Idx); // this.DoOrderUp(FrmAttachmentDBAttr.FK_MapData, this.FK_MapData, FrmAttachmentDBAttr.Idx); } } /// /// 附件数据存储s /// public class FrmAttachmentDBs : EntitiesMyPK { #region 构造 /// /// 附件数据存储s /// public FrmAttachmentDBs() { } /// /// 附件数据存储s /// /// s public FrmAttachmentDBs(string fk_mapdata, string pkval) { this.Retrieve(FrmAttachmentDBAttr.FK_MapData, fk_mapdata, FrmAttachmentDBAttr.RefPKVal, pkval); } /// /// 得到它的 Entity /// public override Entity GetNewEntity { get { return new FrmAttachmentDB(); } } #endregion #region 为了适应自动翻译成java的需要,把实体转换成List. /// /// 转化成 java list,C#不能调用. /// /// List public System.Collections.Generic.IList ToJavaList() { return (System.Collections.Generic.IList)this; } /// /// 转化成list /// /// List public System.Collections.Generic.List Tolist() { System.Collections.Generic.List list = new System.Collections.Generic.List(); for (int i = 0; i < this.Count; i++) { list.Add((FrmAttachmentDB)this[i]); } return list; } #endregion 为了适应自动翻译成java的需要,把实体转换成List. } }