/// <summary> /// 在Entity操作后执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperated(OperateArgs <T> e) { switch (e.OperateType) { case OperateType.Save: e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); if (e.Entity.DetailEntities != null) { foreach (S i in e.Entity.DetailEntities) { i.MasterEntity = e.Entity; this.DetailDao.Update(e.Repository, i); } } break; case OperateType.Update: break; case OperateType.Delete: break; default: throw new InvalidOperationException("Invalid OperateType"); } }
/// <summary> /// /// </summary> /// <param name="rep"></param> /// <param name="entity"></param> public void SaveOrUpdate(IRepository rep, T entity) { // Todo: know how nhibernate to saveorupdate IVersionedEntity ve = entity as IVersionedEntity; if (ve == null) { throw new NotSupportedException("SaveOrUpdate only support IVersionedEntity!"); } OperateArgs <T> e; if (ve.Version == 0) { e = new OperateArgs <T>(rep, OperateType.Save, entity); } else { e = new OperateArgs <T>(rep, OperateType.Update, entity); } PreparingEntity(e); OnEntityOperating(e); DoSaveOrUpdate(rep, entity); OnEntityOperated(e); PreparedEntity(e); }
/// <summary> /// 在Entity操作前执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperating(OperateArgs <T> e) { base.OnEntityOperating(e); switch (e.OperateType) { case OperateType.Save: break; case OperateType.Update: break; case OperateType.Delete: throw new ArgumentException("u should not call delete in OnetoOneGenerateChildDao!"); ////if (e.Entity.Submitted) //{ // if (e.Entity.ChildEntity != null) // { // m_childDao.Delete(e.Repository, e.Entity.ChildEntity); // } //} //break; default: throw new InvalidOperationException("Invalid OperateType"); } }
/// <summary> /// 在Entity操作后执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperated(OperateArgs <T> e) { base.OnEntityOperated(e); System.Diagnostics.Debug.Assert(this.DetailMemoryDao.SavedEntities.Count == 0); System.Diagnostics.Debug.Assert(this.DetailMemoryDao.DeletedEntities.Count == 0); switch (e.OperateType) { case OperateType.Save: break; case OperateType.Update: foreach (S i in this.DetailMemoryDao.UpdatedEntities) { this.DetailDao.Update(e.Repository, i); } break; case OperateType.Delete: break; default: throw new InvalidOperationException("Invalid OperateType"); } }
/// <summary> /// 在Transaction Rollback后执行 /// </summary> /// <param name="e"></param> public override void OnTransactionRollbacked(OperateArgs <T> e) { base.OnTransactionRollbacked(e); switch (e.OperateType) { case OperateType.Save: case OperateType.Update: if (e.Entity.DetailEntities != null) { e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); foreach (S i in this.DetailMemoryDao.UpdatedEntities) { if (i.MasterEntity != null) { e.Entity.DetailEntities.Remove(i); } else { e.Entity.DetailEntities.Add(i); } } } break; case OperateType.Delete: break; default: throw new InvalidOperationException("Invalid OperateType"); } }
void AbstractEventDao_EntityOperated(object sender, OperateArgs <T> e) { foreach (EventHandler <OperateArgs> handler in m_untypedEventsEntityOperated) { handler.Invoke(sender, e); } }
/// <summary> /// 在Transaction Rollback后执行 /// </summary> /// <param name="e"></param> public override void OnTransactionRollbacked(OperateArgs <T> e) { base.OnTransactionRollbacked(e); switch (e.OperateType) { case OperateType.Save: if (e.Entity.DetailEntities != null) { foreach (S i in this.DetailMemoryDao.SavedEntities) { e.Entity.DetailEntities.Remove(i); } } break; case OperateType.Update: // add and remove it in master entity foreach (S i in this.DetailMemoryDao.SavedEntities) { e.Entity.DetailEntities.Remove(i); } foreach (S i in this.DetailMemoryDao.DeletedEntities) { e.Entity.DetailEntities.Add(i); } break; case OperateType.Delete: break; default: throw new InvalidOperationException("Invalid OperateType"); } }
private void PreparingEntity(OperateArgs <T> e) { { IOperatingEntity entity2 = e.Entity as IOperatingEntity; if (entity2 != null) { entity2.PreparingOperate(e); } } if (e.OperateType == OperateType.Delete) { IDeletableEntity entity2 = e.Entity as IDeletableEntity; if (entity2 != null && !entity2.CanBeDelete(e)) { throw new InvalidUserOperationException(entity2.ToString() + "不能删除!"); } } else if (e.OperateType == OperateType.Update) { IUpdatableEntity entity2 = e.Entity as IUpdatableEntity; if (entity2 != null && !entity2.CanBeUpdate(e)) { throw new InvalidUserOperationException(entity2.ToString() + "不能更新!"); } } else if (e.OperateType == OperateType.Save) { ISavableEntity entity2 = e.Entity as ISavableEntity; if (entity2 != null && !entity2.CanBeSave(e)) { throw new InvalidUserOperationException(entity2.ToString() + "不能添加!"); } } }
void AbstractEventDao_TransactionRollbacked(object sender, OperateArgs <T> e) { foreach (EventHandler <OperateArgs> handler in m_untypedEventsTransactionRollbacked) { handler.Invoke(sender, e); } }
public override void PreparingOperate(Feng.OperateArgs e) { if (string.IsNullOrEmpty(this.编号)) { this.编号 = PrimaryMaxIdGenerator.GetMaxId("财务_资产入库", "编号", 8, PrimaryMaxIdGenerator.GetIdYearMonth()).ToString(); } }
/// <summary> /// 在Entity操作前执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperating(OperateArgs <T> e) { base.OnEntityOperating(e); switch (e.OperateType) { case OperateType.Save: break; case OperateType.Update: System.Diagnostics.Debug.Assert(this.DetailMemoryDao.UpdatedEntities.Count == 0); break; case OperateType.Delete: IMasterEntity <T, S> masterEntity = e.Entity as IMasterEntity <T, S>; if (masterEntity != null) { if (masterEntity.DetailEntities != null) { e.Repository.Initialize(masterEntity.DetailEntities, e.Entity); foreach (S i in masterEntity.DetailEntities) { i.MasterEntity = null; this.DetailDao.Update(e.Repository, i); } } } break; default: throw new InvalidOperationException("Invalid OperateType"); } }
/// <summary> /// 在Entity操作前执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperating(OperateArgs <T> e) { base.OnEntityOperating(e); switch (e.OperateType) { case OperateType.Save: if (e.Entity.DetailEntities == null) { e.Entity.DetailEntities = new List <S>(); } foreach (S i in this.DetailMemoryDao.UpdatedEntities) { if (i.MasterEntity != null) { e.Entity.DetailEntities.Add(i); } else { e.Entity.DetailEntities.Remove(i); } } break; case OperateType.Update: e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); foreach (S i in this.DetailMemoryDao.UpdatedEntities) { if (i.MasterEntity != null) { e.Entity.DetailEntities.Add(i); } else { e.Entity.DetailEntities.Remove(i); } } break; case OperateType.Delete: if (e.Entity.DetailEntities != null) { e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); foreach (S i in e.Entity.DetailEntities) { i.MasterEntity = null; this.DetailDao.Update(e.Repository, i); } } break; default: throw new InvalidOperationException("Invalid OperateType"); } }
private void CommitTransaction(IRepository rep, OperateArgs <T> e) { if (rep.IsSupportTransaction) { OnTransactionCommitting(e); rep.CommitTransaction(); OnTransactionCommited(e); } }
///// <summary> ///// ///// </summary> ///// <param name="id"></param> ///// <returns></returns> //public static T Get(object id) //{ // using (var rep = ServiceProvider.GetService<IRepositoryFactory>().GenerateRepository<T>()) // { // return rep.Get<T>(id); // } //} #region "Prepare" private void PreparedEntity(OperateArgs <T> e) { IOperatingEntity entity2 = e.Entity as IOperatingEntity; if (entity2 != null) { entity2.PreparedOperate(e); } }
private void BeginTransaction(IRepository rep, OperateArgs <T> e) { if (rep.IsSupportTransaction) { OnTransactionBeginning(e); rep.BeginTransaction(); OnTransactionBegun(e); } }
void MasterDetailMemoryDao_EntityOperated(object sender, OperateArgs <S> e) { switch (e.OperateType) { case OperateType.Save: e.Entity.MasterEntity = m_cm.CurrentItem as T; break; } }
private void RollbackTransaction(IRepository rep, OperateArgs <T> e) { if (rep.IsSupportTransaction) { OnTransactionRollbacking(e); rep.RollbackTransaction(); OnTransactionRollbacked(e); } }
/// <summary> /// 在Entity操作后执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperated(OperateArgs <T> e) { base.OnEntityOperated(e); switch (e.OperateType) { case OperateType.Save: throw new ArgumentException("u should not call Save in OnetoOneGenerateChildDao!"); ////if (e.Entity.Submitted) //{ // if (e.Entity.ChildType != null) // { // GenerateNewChild(e.Entity); // m_childDao.Save(e.Repository, e.Entity.ChildEntity); // } //} // break; case OperateType.Update: //if (e.Entity.Submitted) { if (e.Entity.ChildType == null && e.Entity.ChildEntity == null) { } else if (e.Entity.ChildType != null && e.Entity.ChildEntity == null) { GenerateNewChild(e.Entity); this.DetailDao.Save(e.Repository, e.Entity.ChildEntity); } else if (e.Entity.ChildType == null && e.Entity.ChildEntity != null) { this.DetailDao.Delete(e.Repository, e.Entity.ChildEntity); e.Entity.ChildEntity = null; } else if (e.Entity.ChildType != e.Entity.ChildEntity.GetType() && e.Entity.ChildType != e.Entity.ChildEntity.GetType().BaseType) // maybe Proxy { this.DetailDao.Delete(e.Repository, e.Entity.ChildEntity); GenerateNewChild(e.Entity); this.DetailDao.Save(e.Repository, e.Entity.ChildEntity); } else { this.DetailDao.Update(e.Repository, e.Entity.ChildEntity); } } break; case OperateType.Delete: break; default: throw new InvalidOperationException("Invalid OperateType"); } }
/// <summary> /// 在Entity操作后执行 /// </summary> /// <param name="e"></param> public virtual void OnEntityOperated(OperateArgs <T> e) { if (EntityOperated != null) { EntityOperated(this, e); } foreach (IEventDao subDao in this.GetRelationalDaos()) { subDao.OnEntityOperated(e); } }
/// <summary> /// 增加或者修改 /// </summary> /// <param name="entity"></param> public override void SaveOrUpdate(T entity) { if (m_suspendRep == null) { using (var rep = GenerateRepository()) { IVersionedEntity ve = entity as IVersionedEntity; if (ve == null) { throw new NotSupportedException("SaveOrUpdate only support IVersionedEntity!"); } OperateArgs <T> e; if (ve.Version == 0) { e = new OperateArgs <T>(rep, OperateType.Save, entity); } else { e = new OperateArgs <T>(rep, OperateType.Update, entity); } try { BeginTransaction(rep, e); SaveOrUpdate(rep, entity); CommitTransaction(rep, e); Clear(); } catch (InvalidUserOperationException) { // 出错的时候,MemoryBll不清空 RollbackTransaction(rep, e); throw; } catch (Exception) { RollbackTransaction(rep, e); Clear(); throw; } } } else { SaveOrUpdate(m_suspendRep, entity); } }
/// <summary> /// /// </summary> /// <param name="e"></param> public virtual void OnTransactionRollbacked(OperateArgs <T> e) { if (TransactionRollbacked != null) { TransactionRollbacked(this, e); } foreach (IEventDao subDao in this.GetRelationalDaos()) { subDao.OnTransactionRollbacked(e); } }
/// <summary> /// /// </summary> /// <param name="e"></param> public virtual void OnTransactionBeginning(OperateArgs <T> e) { if (TransactionBeginning != null) { TransactionBeginning(this, e); } foreach (IEventDao subDao in this.GetRelationalDaos()) { subDao.OnTransactionBeginning(e); } }
public override void PreparingOperate(OperateArgs e) { base.PreparingOperate(e); if (e.OperateType == OperateType.Save || e.OperateType == OperateType.Update) { 非业务车辆费用 entity = e.Entity as 非业务车辆费用; if (string.IsNullOrEmpty(entity.费用项编号)) { entity.费用类别编号 = null; } else { e.Repository.Initialize(entity.费用实体, entity); entity.费用类别编号 = entity.费用实体.费用实体类型编号; if (entity.费用类别编号.HasValue && entity.费用类别编号.Value == 13) // 车辆库存加油 { entity.费用类别编号 = 12;//车辆加油 if (entity.费用归属 == 费用归属.驾驶员) { entity.费用类别编号 = 325;//业务油耗 } } } if (entity.车辆编号 == null) { if (entity.车辆费用实体 == null) { entity.车辆费用实体 = entity.费用实体 as 车辆费用实体; } else { e.Repository.Initialize(entity.车辆费用实体, entity); } entity.车辆编号 = entity.车辆费用实体 == null ? null : entity.车辆费用实体.车辆编号; } if (entity.费用归属 == 费用归属.车主 && entity.相关人编号 == null) { if (entity.车辆费用实体 == null) { entity.车辆费用实体 = entity.费用实体 as 车辆费用实体; } else { e.Repository.Initialize(entity.车辆费用实体, entity); } entity.相关人编号 = entity.车辆费用实体.车主编号; } } }
/// <summary> /// /// </summary> /// <param name="e"></param> public override void OnTransactionBegun(OperateArgs <T> e) { base.OnTransactionBegun(e); e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); if (e.Entity.DetailEntities != null) { foreach (S i in e.Entity.DetailEntities) { this.DetailDao.OnTransactionBegun(new OperateArgs <S>(e.Repository, OperateType.Update, i)); } } }
/// <summary> /// 在Transaction开始前执行 /// </summary> /// <param name="e"></param> public override void OnTransactionBeginning(OperateArgs <T> e) { base.OnTransactionBeginning(e); //e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); //if (e.Entity.DetailEntities != null) //{ // foreach (S i in e.Entity.DetailEntities) // { // this.DetailDao.OnTransactionBeginning(new OperateArgs<S>(e.Repository, OperateType.Update, i)); // } //} }
/// <summary> /// /// </summary> /// <param name="e"></param> public override void OnTransactionBegun(OperateArgs <T> e) { base.OnTransactionBegun(e); switch (e.OperateType) { case OperateType.Update: foreach (S i in this.DetailMemoryDao.UpdatedEntities) { RepositoryLockHelper.TryLock(e.Repository, i); } break; } }
/// <summary> /// /// </summary> /// <param name="rep"></param> /// <param name="entity"></param> public void Delete(IRepository rep, T entity) { OperateArgs <T> e = new OperateArgs <T>(rep, OperateType.Delete, entity); PreparingEntity(e); OnEntityOperating(e); DoDelete(rep, entity); OnEntityOperated(e); PreparedEntity(e); }
/// <summary> /// 在Entity操作前执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperating(OperateArgs <T> e) { base.OnEntityOperating(e); switch (e.OperateType) { case OperateType.Save: // Add it to master entity if (e.Entity.DetailEntities == null) { e.Entity.DetailEntities = new List <S>(); } foreach (S i in this.DetailMemoryDao.SavedEntities) { e.Entity.DetailEntities.Add(i); } break; case OperateType.Update: // add and remove it in master entity e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); foreach (S i in this.DetailMemoryDao.SavedEntities) { e.Entity.DetailEntities.Add(i); } foreach (S i in this.DetailMemoryDao.DeletedEntities) { e.Entity.DetailEntities.Remove(i); } break; case OperateType.Delete: e.Repository.Initialize(e.Entity.DetailEntities, e.Entity); if (e.Entity.DetailEntities != null) { foreach (S i in e.Entity.DetailEntities) { //System.Diagnostics.Debug.Assert(i is S, i + "should be " + typeof(S) + "type"); i.MasterEntity = null; this.DetailDao.Update(e.Repository, i); } } break; default: throw new InvalidOperationException("Invalid OperateType"); } }
/// <summary> /// 在Transaction Rollback后执行 /// </summary> /// <param name="e"></param> public override void OnTransactionRollbacked(OperateArgs <T> e) { base.OnTransactionRollbacked(e); foreach (S i in this.DetailMemoryDao.SavedEntities) { this.DetailDao.OnTransactionRollbacked(new OperateArgs <S>(e.Repository, OperateType.Save, i)); } foreach (S i in this.DetailMemoryDao.UpdatedEntities) { this.DetailDao.OnTransactionRollbacked(new OperateArgs <S>(e.Repository, OperateType.Update, i)); } foreach (S i in this.DetailMemoryDao.DeletedEntities) { this.DetailDao.OnTransactionRollbacked(new OperateArgs <S>(e.Repository, OperateType.Delete, i)); } }
/// <summary> /// 删除 /// </summary> /// <param name="entity"></param> public override void Delete(T entity) { if (m_suspendRep == null) { using (var rep = GenerateRepository()) { var e = new OperateArgs <T>(rep, OperateType.Delete, entity); try { BeginTransaction(rep, e); Delete(rep, entity); CommitTransaction(rep, e); Clear(); } //// delete will check not-null, but when in web grid, we only have id(and version) set back //catch (NHibernate.PropertyValueException) //{ // rep.RollbackTransaction(); // throw; // //LoadandDelete(entity); //} catch (InvalidUserOperationException) { // 出错的时候,MemoryBll不清空 RollbackTransaction(rep, e); throw; } catch (Exception) { RollbackTransaction(rep, e); Clear(); throw; } } } else { Delete(m_suspendRep, entity); } }
/// <summary> /// 在Entity操作前执行 /// </summary> /// <param name="e"></param> public override void OnEntityOperating(OperateArgs <T> e) { base.OnEntityOperating(e); switch (e.OperateType) { case OperateType.Save: break; case OperateType.Update: break; case OperateType.Delete: throw new ArgumentException("u should not call delete in MasterGenerateDetailDao!"); default: throw new InvalidOperationException("Invalid OperateType"); } }
public override void PreparingOperate(OperateArgs e) { base.PreparingOperate(e); if (e.OperateType == OperateType.Save || e.OperateType == OperateType.Update) { 非业务费用 entity = e.Entity as 非业务费用; if (string.IsNullOrEmpty(entity.费用项编号)) { entity.费用类别编号 = null; } else { // 当费用项变换时,要重新设置费用类别编号 entity.费用项 = EntityBufferCollection.Instance.Get<费用项>(entity.费用项编号); entity.费用类别编号 = entity.收付标志 == 收付标志.收 ? entity.费用项.收入类别 : entity.费用项.支出类别; if (!entity.费用类别编号.HasValue) { throw new InvalidUserOperationException("您选择的费用项和收付有误,请重新选择!"); } } } }
/// <summary> /// /// </summary> /// <param name="e"></param> public virtual void OnTransactionCommited(OperateArgs e) { if (TransactionCommited != null) { TransactionCommited(this, e); } foreach (IEventDao subDao in this.GetRelationalDaos()) { subDao.OnTransactionCommited(e); } }
public virtual void PreparingOperate(OperateArgs e) { }
bool IDeletableEntity.CanBeDelete(OperateArgs e) { e.Repository.Initialize(this.费用, this); if (this.费用 != null && this.费用.Count > 0) { return false; } else { return true; } }
void IOperatingEntity.PreparingOperate(OperateArgs e) { if (e.OperateType == OperateType.Save) { if (string.IsNullOrEmpty(this.编号)) { // Todo int delta = Feng.Utils.RepositoryHelper.GetRepositoryDelta(e.Repository, typeof(员工).Name); this.编号 = PrimaryMaxIdGenerator.GetMaxId("参数备案_人员单位", "编号", 6, "20", delta).ToString(); } } }
void IOperatingEntity.PreparedOperate(OperateArgs e) { }
void IOperatingEntity.PreparingOperate(OperateArgs e) { if (string.IsNullOrEmpty(this.编号) && (e.OperateType == OperateType.Save || e.OperateType == OperateType.Update)) { this.编号 = PrimaryMaxIdGenerator.GetMaxId("财务_银行存取款", "编号", 8, "Y" + PrimaryMaxIdGenerator.GetIdYearMonth(日期)).ToString(); } }
void IOperatingEntity.PreparedOperate(OperateArgs e) { if (e.OperateType == OperateType.Save || e.OperateType == OperateType.Update) { if (this.费用 != null) { e.Repository.Initialize(this.费用, this); foreach (费用 i in this.费用) { if (string.IsNullOrEmpty(i.相关人编号)) { i.相关人编号 = this.相关人编号; i.相关人 = this.相关人; } } } } }
/// <summary> /// /// </summary> /// <param name="e"></param> public virtual void OnTransactionRollbacking(OperateArgs e) { if (TransactionRollbacking != null) { TransactionRollbacking(this, e); } foreach (IEventDao subDao in this.GetRelationalDaos()) { subDao.OnTransactionRollbacking(e); } }
public virtual bool CanBeDelete(OperateArgs e) { return !(this.Submitted || this.是否作废); }
/// <summary> /// 在Entity操作前执行 /// </summary> /// <param name="e"></param> public virtual void OnEntityOperating(OperateArgs e) { if (EntityOperating != null) { EntityOperating(this, e); } foreach (IEventDao subDao in this.GetRelationalDaos()) { subDao.OnEntityOperating(e); } }