/// <summary> /// /// </summary> /// <param name="e"></param> protected virtual void OnEntityChanged(EntityChangedEventArgs e) { IBaseDao dao = this.Dao; if (dao == null) { throw new ArgumentException("dao is null!"); } try { switch (e.EntityChangedType) { case EntityChangedType.Add: dao.Save(e.Entity); break; case EntityChangedType.Edit: dao.Update(e.Entity); break; case EntityChangedType.Delete: dao.Delete(e.Entity); break; default: throw new NotSupportedException("invalid e.EntityChangedType"); } e.Exception = null; } catch (Exception ex) { e.Exception = ex; ExceptionProcess.ProcessWithNotify(ex); //if (this.ArchiveGridHelper.m_bThrowExceptionWhenBllError) //{ // throw; //} //else //{ // ExceptionProcess.ProcessWithNotify(ex); // //base.SearchManager.ReloadData(); //} } }
/// <summary> /// 处理位于Position位置的Entity改变后的事情(保存,更新界面) /// </summary> /// <returns></returns> public virtual bool ProcessEntityChanged(int position) { object entity = this.DisplayManager.Items[position]; if (entity == null) { throw new ArgumentException("Position is invalid!"); } EntityChangedEventArgs arg; ListChangedEventArgs arg2; switch (this.State) { case StateType.Add: arg = new EntityChangedEventArgs(EntityChangedType.Add, entity); arg2 = new ListChangedEventArgs(ListChangedType.ItemAdded, position); break; case StateType.Delete: arg = new EntityChangedEventArgs(EntityChangedType.Delete, entity); arg2 = new ListChangedEventArgs(ListChangedType.ItemDeleted, position); break; case StateType.Edit: arg = new EntityChangedEventArgs(EntityChangedType.Edit, entity); arg2 = new ListChangedEventArgs(ListChangedType.ItemChanged, position); break; default: throw new InvalidOperationException("Invalid State"); } OnEntityChanged(arg); if (arg.Exception == null) { OnListChanged(arg2); return true; } else { if (arg.Exception is InvalidUserOperationException) { // 只是提示,不刷新。而且在Dao中,不清空内部Dao数据(Clear)。 } else { DoOnFailedOperation(); } return false; } }