public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
        {
            esDataSourceSelectEventArgs e = null;

            try
            {
                e = new esDataSourceSelectEventArgs();

                e.Arguments  = arguments;
                e.Collection = this.owner.Collection;

                this.OnPreSelect(e);

                if (e.Cancel)
                {
                    return;
                }

                this.CalculatePageSizeAndNumber(e);
                this.SetTotalRowCount(e);
                this.PopulateSortItems(e);

                //this.OnPreSelect(e);

                this.OnSelect(e);

                this.PerformAutoLogic(e);

                this.FetchTotalRowCount(e);

                this.OnPostSelect(e);

                if (e.Collection != null)
                {
                    this.owner.Collection = e.Collection;
                }
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType  = esDataSourceEventType.Select;
                exArgs.SelectArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }
            }
            finally
            {
                callback(e.Collection);
            }
        }
 protected virtual void OnException(esDataSourceExceptionEventArgs e)
 {
     esDataSource.esDataSourceExceptionEventHandler handler = base.Events[evException]
                                                              as esDataSource.esDataSourceExceptionEventHandler;
     if (handler != null)
     {
         handler(this, e);
     }
 }
    protected void EsDataSource1_esException(object sender, EntitySpaces.Web.esDataSourceExceptionEventArgs e)
    {
        this.Response.Write("ERROR");
        this.Response.Write("<BR><hr>");
        this.Response.Write(e.TheException.Message);
        this.Response.Write(e.SelectArgs.Query.es.LastQuery);
        this.Response.Write("<hr><br><br>");

        e.ExceptionWasHandled = true;
    }
        protected override System.Collections.IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            esDataSourceSelectEventArgs e = null;

            try
            {
                e = new esDataSourceSelectEventArgs();

                e.Arguments  = arguments;
                e.Collection = this.owner.Collection;

                this.OnPreSelect(e);

                if (e.Cancel)
                {
                    return(null);
                }

                this.CalculatePageSizeAndNumber(e);
                this.SetTotalRowCount(e);
                this.PopulateSortItems(e);

                //this.OnPreSelect(e);
                this.OnSelect(e);

                this.PerformAutoLogic(e);

                this.FetchTotalRowCount(e);

                this.OnPostSelect(e);

                return(e.Collection);
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType  = esDataSourceEventType.Select;
                exArgs.SelectArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }

                return(null);
            }
        }
        public override void Delete(System.Collections.IDictionary keys, System.Collections.IDictionary oldValues, DataSourceViewOperationCallback callback)
        {
            esDataSourceDeleteEventArgs e = null;

            try
            {
                if (keys != null && keys.Count > 0)
                {
                    e           = new esDataSourceDeleteEventArgs();
                    e.Keys      = keys;
                    e.OldValues = oldValues;

                    this.OnPreDelete(e);
                    if (e.Cancel)
                    {
                        return;
                    }

                    // Find the proper esEntity and set it's values
                    object[] pks = new object[keys.Count];

                    int index = 0;
                    foreach (object value in keys.Values)
                    {
                        pks[index++] = value;
                    }

                    esDataSourceCreateEntityEventArgs ce = new esDataSourceCreateEntityEventArgs();
                    ce.PrimaryKeys = pks;
                    this.OnCreateEntity(ce);

                    esEntity entity = ce.Entity;
                    e.Entity = entity;

                    //this.OnPreDelete(e);

                    e.EventWasHandled = false;
                    this.OnDelete(e);

                    if (!e.EventWasHandled)
                    {
                        entity.MarkAsDeleted();
                        entity.Save();

                        this.OnDataSourceViewChanged(EventArgs.Empty);
                    }

                    this.OnPostDelete(e);
                }
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType  = esDataSourceEventType.Delete;
                exArgs.DeleteArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }
            }
            finally
            {
                callback(1, null);
            }
        }
        public override void Insert(System.Collections.IDictionary values, DataSourceViewOperationCallback callback)
        {
            esDataSourceInsertEventArgs e = null;

            try
            {
                e        = new esDataSourceInsertEventArgs();
                e.Values = values;

                this.OnPreInsert(e);
                if (e.Cancel)
                {
                    return;
                }

                esDataSourceCreateEntityEventArgs ce = new esDataSourceCreateEntityEventArgs();
                this.OnCreateEntity(ce);

                esEntity entity = ce.Entity;
                e.Entity = entity;

                if (entity != null)
                {
                    entity.SetProperties(values);
                }

                //this.OnPreInsert(e);

                e.EventWasHandled = false;
                this.OnInsert(e);

                if (!e.EventWasHandled)
                {
                    entity.Save();
                    this.OnDataSourceViewChanged(EventArgs.Empty);
                }

                e.EventWasHandled = false;
                this.OnPostInsert(e);
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType  = esDataSourceEventType.Insert;
                exArgs.InsertArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }
            }
            finally
            {
                callback(1, null);
            }
        }
 protected virtual void OnException(esDataSourceExceptionEventArgs e)
 {
     esDataSource.esDataSourceExceptionEventHandler handler = base.Events[evException]
         as esDataSource.esDataSourceExceptionEventHandler;
     if (handler != null)
     {
         handler(this, e);
     }
 }
        public override void Delete(System.Collections.IDictionary keys, System.Collections.IDictionary oldValues, DataSourceViewOperationCallback callback)
        {
            esDataSourceDeleteEventArgs e = null;

            try
            {
                if (keys != null && keys.Count > 0)
                {
                    e = new esDataSourceDeleteEventArgs();
                    e.Keys = keys;
                    e.OldValues = oldValues;

                    this.OnPreDelete(e);
                    if (e.Cancel)
                        return;

                    // Find the proper esEntity and set it's values
                    object[] pks = new object[keys.Count];

                    int index = 0;
                    foreach (object value in keys.Values)
                    {
                        pks[index++] = value;
                    }

                    esDataSourceCreateEntityEventArgs ce = new esDataSourceCreateEntityEventArgs();
                    ce.PrimaryKeys = pks;
                    this.OnCreateEntity(ce);

                    esEntity entity = ce.Entity;
                    e.Entity = entity;

                    //this.OnPreDelete(e);

                    e.EventWasHandled = false;
                    this.OnDelete(e);

                    if (!e.EventWasHandled)
                    {
                        entity.MarkAsDeleted();
                        entity.Save();

                        this.OnDataSourceViewChanged(EventArgs.Empty);
                    }

                    this.OnPostDelete(e);
                }
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType = esDataSourceEventType.Delete;
                exArgs.DeleteArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }
            }
            finally
            {
                callback(1, null);
            }
        }
        public override void Insert(System.Collections.IDictionary values, DataSourceViewOperationCallback callback)
        {
            esDataSourceInsertEventArgs e = null;

            try
            {
                e = new esDataSourceInsertEventArgs();
                e.Values = values;

                this.OnPreInsert(e);
                if (e.Cancel)
                    return;

                esDataSourceCreateEntityEventArgs ce = new esDataSourceCreateEntityEventArgs();
                this.OnCreateEntity(ce);

                esEntity entity = ce.Entity;
                e.Entity = entity;

                if (entity != null)
                {
                    entity.SetProperties(values);
                }

                //this.OnPreInsert(e);

                e.EventWasHandled = false;
                this.OnInsert(e);

                if (!e.EventWasHandled)
                {
                    entity.Save();
                    this.OnDataSourceViewChanged(EventArgs.Empty);
                }

                e.EventWasHandled = false;
                this.OnPostInsert(e);
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType = esDataSourceEventType.Insert;
                exArgs.InsertArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }
            }
            finally
            {
                callback(1, null);
            }
        }
        public override void Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
        {
            esDataSourceSelectEventArgs e = null;

            try
            {
                e = new esDataSourceSelectEventArgs();

                e.Arguments = arguments;
                e.Collection = this.owner.Collection;

                this.OnPreSelect(e);

                if (e.Cancel)
                    return;

                this.CalculatePageSizeAndNumber(e);
                this.SetTotalRowCount(e);
                this.PopulateSortItems(e);

                //this.OnPreSelect(e);
                
                this.OnSelect(e);

                this.PerformAutoLogic(e);

                this.FetchTotalRowCount(e);

                this.OnPostSelect(e);

                if (e.Collection != null)
                {
                    this.owner.Collection = e.Collection;
                }
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType = esDataSourceEventType.Select;
                exArgs.SelectArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }
            }
            finally
            {
                callback(e.Collection);
            }
        }
        protected override System.Collections.IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
        {
            esDataSourceSelectEventArgs e = null;

            try
            {
                e = new esDataSourceSelectEventArgs();

                e.Arguments = arguments;
                e.Collection = this.owner.Collection;

                this.OnPreSelect(e);

                if (e.Cancel)
                    return null;

                this.CalculatePageSizeAndNumber(e);
                this.SetTotalRowCount(e);
                this.PopulateSortItems(e);

                //this.OnPreSelect(e);
                this.OnSelect(e);

                this.PerformAutoLogic(e);

                this.FetchTotalRowCount(e);

                this.OnPostSelect(e);

                return e.Collection;
            }
            catch (Exception ex)
            {
                esDataSourceExceptionEventArgs exArgs = new esDataSourceExceptionEventArgs(ex);
                exArgs.EventType = esDataSourceEventType.Select;
                exArgs.SelectArgs = e;

                try
                {
                    this.OnException(exArgs);
                }
                catch { }

                if (!exArgs.ExceptionWasHandled)
                {
                    throw;
                }

                return null;
            }
        }