using System; using System.Collections; using System.Data; using BP.DA; using BP.En; using BP.Web; using Newtonsoft.Json; namespace BP.Sys { /// /// 实体版本号属性 /// public class EnVerAttr : EntityMyPKAttr { /// /// 实体类 /// public const string FrmID = "FrmID"; /// /// 关联主键 /// public const string RefPK = "RefPK"; /// /// 实体类名称 /// public const string Name = "Name"; /// /// 主键值 /// public const string PKValue = "PKValue"; /// /// 版本号 /// public const string EnVer = "EnVer"; /// /// 说明 /// public const string MyNote = "MyNote"; /// /// 记录人 /// public const string RecNo = "RecNo"; /// /// 记录人名字 /// public const string RecName = "RecName"; /// /// 记录日期 /// public const string RDT = "RDT"; public const string EnPKValue = "EnPKValue"; /// /// DBJSON /// public const string DBJSON = "DBJSON"; } /// /// 实体版本号 /// public class EnVer : EntityMyPK { #region 方法. /// /// 创建新版本 /// /// public static string NewVer(Entity myen) { string frmID = myen.ToString(); string frmName = myen.EnDesc; string pkval = myen.PKVal.ToString(); // 获得最大的版本号. int maxVer = DBAccess.RunSQLReturnValInt("SELECT MAX(EnVer) as Num FROM Sys_EnVer WHERE FrmID='" + frmID + "' AND EnPKValue='" + pkval + "'", 0); //最大版本号>1,存在历史版本,获取上一个版本的数据 string oldStr = ""; EnVer oldVer = null; if (maxVer >0) { string mypk = frmID + "_" + pkval + "_" + (maxVer); oldVer = new EnVer(); oldVer.MyPK = mypk; if (oldVer.RetrieveFromDBSources() != 0) { oldStr = DBAccess.GetBigTextFromDB("Sys_EnVer", "MyPK", mypk, EnVerAttr.DBJSON); } if (oldStr.Equals(myen.ToJson())) return ""; } //创建实体. EnVer ev = new EnVer(); ev.RecNo = WebUser.No; ev.RecName = WebUser.Name; ev.RDT = DataType.CurrentDateTime; ev.FrmID = frmID; ev.EnPKValue = pkval; ev.MyNote = ""; ev.Name = frmName; ev.Ver = maxVer + 1; //设置版本号. ev.MyPK= ev.FrmID + "_"+ ev.EnPKValue + "_"+ ev.Ver; ev.Insert(); //执行插入. //存储数据JSON DBAccess.SaveBigTextToDB(myen.ToJson(), "Sys_EnVer", "MyPK", ev.MyPK, EnVerAttr.DBJSON); return "版本创建成功."; } #endregion 方法. #region 属性 public string DBJSON { get { return this.GetValStrByKey(EnVerAttr.DBJSON); } set { this.SetValByKey(EnVerAttr.DBJSON, value); } } /// /// 实体类名称 /// public string Name { get { return this.GetValStrByKey(EnVerAttr.Name); } set { this.SetValByKey(EnVerAttr.Name, value); } } public string EnPKValue { get { return this.GetValStrByKey(EnVerAttr.EnPKValue); } set { this.SetValByKey(EnVerAttr.EnPKValue, value); } } /// /// 版本号 /// public int Ver { get { return this.GetValIntByKey(EnVerAttr.EnVer); } set { this.SetValByKey(EnVerAttr.EnVer, value); } } /// /// 修改人 /// public string RecNo { get { return this.GetValStrByKey(EnVerAttr.RecNo); } set { this.SetValByKey(EnVerAttr.RecNo, value); } } public string RecName { get { return this.GetValStrByKey(EnVerAttr.RecName); } set { this.SetValByKey(EnVerAttr.RecName, value); } } public string MyNote { get { return this.GetValStrByKey(EnVerAttr.MyNote); } set { this.SetValByKey(EnVerAttr.MyNote, value); } } public string FrmID { get { return this.GetValStrByKey(EnVerAttr.FrmID); } set { this.SetValByKey(EnVerAttr.FrmID, value); } } /// /// 修改日期 /// public string RDT { get { return this.GetValStrByKey(EnVerAttr.RDT); } set { this.SetValByKey(EnVerAttr.RDT, value); } } /// /// 主键值 /// public string PKValue { get { return this.GetValStrByKey(EnVerAttr.PKValue); } set { this.SetValByKey(EnVerAttr.PKValue, value); } } #endregion #region 构造函数 /// /// 实体版本号 /// public EnVer() { } public EnVer(string mypk) { this.setMyPK(mypk); this.Retrieve(); } #endregion #region 重写方法 public override UAC HisUAC { get { UAC uac = new UAC(); uac.OpenForSysAdmin(); uac.IsDelete = false; uac.IsInsert = false; uac.IsUpdate = false; return uac; } } /// /// Map /// public override Map EnMap { get { if (this._enMap != null) return this._enMap; Map map = new Map("Sys_EnVer", "实体版本号"); map.EnDBUrl = new DBUrl(DBUrlType.AppCenterDSN); //连接到的那个数据库上. (默认的是: AppCenterDSN ) map.AddMyPK(); map.AddTBString(EnVerAttr.FrmID, null, "实体类", true, true, 1, 50, 20, true); map.AddTBString(EnVerAttr.Name, null, "实体名", true, true, 0, 100, 30, true); map.AddTBString(EnVerAttr.EnPKValue, null, "主键值", true, true, 0, 40, 100); map.AddTBInt(EnVerAttr.EnVer, 0, "版本号", true, true); map.AddTBString(EnVerAttr.RecNo, null, "修改人账号", true, true, 0, 100, 30); map.AddTBString(EnVerAttr.RecName, null, "修改人名称", true, true, 0, 100, 30); //需要存储二进制文件. //map.AddTBString(EnVerAttr.DBJSON, null, "数据JSON", true, true, 0, 4000, 30); map.AddTBString(EnVerAttr.MyNote, null, "备注", true, true, 0, 100, 30); map.AddTBDateTime(EnVerAttr.RDT, null, "创建日期", true, true); RefMethod rm = new RefMethod(); rm.Title = "快照"; rm.ClassMethodName = this.ToString() + ".ShowVer"; rm.RefMethodType = RefMethodType.RightFrameOpen; map.AddRefMethod(rm); //数据. map.AddDtl(new EnVerDtls(), EnVerAttr.RefPK, null, DtlEditerModel.DtlSearch, null); map.DTSearchKey = "RDT"; map.DTSearchWay = DTSearchWay.ByDateTime; map.DTSearchLabel = "日期"; this._enMap = map; return this._enMap; } } #endregion public string ShowVer() { return "/WF/CCBill/OptComponents/DataVer.htm?FrmID=" + this.FrmID + "&WorkID=" + this.EnPKValue; } protected override bool beforeInsert() { return base.beforeInsert(); } protected override void afterDelete() { //删除数据. EnVerDtls dtls = new EnVerDtls(); dtls.Delete(EnVerDtlAttr.RefPK, this.MyPK); base.afterDelete(); } } /// ///实体版本号s /// public class EnVers : EntitiesMyPK { /// /// 得到一个新实体 /// public override Entity GetNewEntity { get { return new EnVer(); } } /// /// 实体版本号集合 /// public EnVers() { } #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((EnVer)this[i]); } return list; } #endregion 为了适应自动翻译成java的需要,把实体转换成List. } }