using System; using System.Collections; using BP.DA; namespace BP.En { /// /// 属性列表 /// public class EntityNoNameAttr { #region 基本属性. /// /// 名称 /// public const string Name = "Name"; /// /// 编号 /// public const string No = "No"; /// /// 名称简称 /// public const string NameOfS = "NameOfS"; /// /// 查询的关键字(系统字段) /// public const string SKeyWords = "SKeyWords"; /// /// 参数字段(系统字段) /// public const string AtPara = "AtPara"; #endregion 基本属性. #region 附件属性. public const string MyFilePath = "MyFilePath"; public const string MyFileName = "MyFileName"; public const string MyFileExt = "MyFileExt"; public const string MyFileH = "MyFileH"; public const string MyFileW = "MyFileW"; public const string MyFileSize = "MyFileSize"; public const string WebPath = "WebPath"; public const string MyFileNum = "MyFileNum"; #endregion 附件属性. } /// /// 具有编号名称的基类实体 /// abstract public class EntityNoName : Entity { #region 提供的属性 public override string PK { get { return "No"; } } /// /// 编号 /// public string No { get { return this.GetValStringByKey(EntityNoNameAttr.No); } set { this.SetValByKey(EntityNoNameAttr.No, value); } } /// /// 名称 /// public string Name { get { return this.GetValStringByKey(EntityNoNameAttr.Name); } set { this.SetValByKey(EntityNoNameAttr.Name, value); } } public void setName(string val) { this.SetValByKey(EntityNoNameAttr.Name, val); } /// /// 生成一个编号 /// public string GenerNewNo { get { return this.GenerNewNoByKey("No"); } } #endregion #region 构造函数 /// /// /// public EntityNoName() { } /// /// 通过编号得到实体。 /// /// 编号 public EntityNoName(string _no) { if (_no == null || _no == "") throw new Exception(this.EnDesc + "@对表[" + this.EnDesc + "]进行查询前必须指定编号。"); this.No = _no; if (this.Retrieve() == 0) { throw new Exception("@没有" + this._enMap.PhysicsTable + ", No = " + No + "的记录。"); } } #endregion #region 业务逻辑处理 /// /// 检查名称的问题. /// /// protected override bool beforeInsert() { if (this.No.Trim().Length == 0) { if (this.EnMap.ItIsAutoGenerNo) this.No = this.GenerNewNo; else //throw new Exception("@没有给[" + this.EnDesc + "]ClassID=[" + this.ClassID + "]Name=[" + this.Name + "]设置编号,不能执行插入."); throw new Exception("没有给当前操作设置编号和名称,保存失败。"); } //if (this.EnMap.IsAllowRepeatName == false) //{ // if (this.PKCount == 1) // { // if (this.ExitsValueNum("Name", this.Name) >= 1) // throw new Exception("@插入失败[" + this.EnMap.EnDesc + "] 编号[" + this.No + "]名称[" + Name + "]重复."); // } //} return base.beforeInsert(); } protected override bool beforeUpdate() { //if (this.EnMap.IsAllowRepeatName == false) //{ // if (this.PKCount == 1) // { // if (this.ExitsValueNum("Name", this.Name) >= 2) // throw new Exception("@更新失败[" + this.EnMap.EnDesc + "] 编号[" + this.No + "]名称[" + Name + "]重复."); // } //} return base.beforeUpdate(); } public override int Save() { /*如果包含编号。 */ if (this.IsExits) { return this.Update(); } else { if (this.EnMap.ItIsAutoGenerNo && this.EnMap.GetAttrByKey("No").UIIsReadonly) this.No = this.GenerNewNo; this.Insert(); return 0; } } #endregion } /// /// 具有编号名称的基类实体s /// abstract public class EntitiesNoName : Entities { #region 查询. /// /// 查询全部 /// /// public override int RetrieveAllFromDBSource() { QueryObject qo = new QueryObject(this); qo.addOrderBy("No"); return qo.DoQuery(); } public override int RetrieveAll() { return base.RetrieveAll("No"); } #endregion 查询. #region 构造高级方法. /// /// 将对象添加到集合尾处,如果对象已经存在,则不添加. /// /// 要添加的对象 /// 返回添加到的地方 public virtual int AddEntity(Entity entity) { foreach (Entity en in this) { if (en.GetValStrByKey("No") == entity.GetValStrByKey("No")) return 0; } return this.InnerList.Add(entity); } /// /// 根据位置取得数据 /// public new EntityNoName this[int index] { get { return (EntityNoName)this.InnerList[index]; } } /// /// 构造 /// public EntitiesNoName() { } #endregion 构造高级方法. } }