protected void EsDataSource1_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e) { EmployeesCollection coll = new EmployeesCollection(); // Assign the esDataSourcSelectEvenArgs Collection property e.Collection = coll; }
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); } }
private void SetTotalRowCount(esDataSourceSelectEventArgs e) { // Set TotalRowCount if we can if (e.Arguments.RetrieveTotalRowCount && this.totalRowCount > 0) { e.Arguments.TotalRowCount = this.totalRowCount; } }
private void CalculatePageSizeAndNumber(esDataSourceSelectEventArgs e) { // Calc PageSize/PageNumber if (e.Arguments.MaximumRows > 0) { e.PageSize = e.Arguments.MaximumRows; e.PageNumber = (int)((e.Arguments.StartRowIndex / e.Arguments.MaximumRows) + 1); } }
protected virtual void OnPostSelect(esDataSourceSelectEventArgs e) { esDataSource.esDataSourceSelectEventHandler handler = base.Events[evPostSelect] as esDataSource.esDataSourceSelectEventHandler; if (handler != null) { handler(this, e); } }
private void PerformAutoLogic(esDataSourceSelectEventArgs e) { esDynamicQuery query = e.Query != null ? e.Query : e.Collection.es.Query; IDynamicQuerySerializableInternal iQuery = query as IDynamicQuerySerializableInternal; if (this.autoPaging) { query.es.PageNumber = e.PageNumber; query.es.PageSize = e.PageSize; } if (this.autoSorting) { if (e.SortItems != null) { foreach (esDataSourceSortItem sortItem in e.SortItems) { esColumnMetadata col = e.Collection.es.Meta.Columns.FindByPropertyName(sortItem.Property); if (col != null) { query.OrderBy(col.Name, sortItem.Direction); } else if (sortItem.Property[0] == '<') { query.OrderBy(sortItem.Property, sortItem.Direction); } } } else { if (this.AutoPaging) { List <esColumnMetadata> pks = e.Collection.es.Meta.Columns.PrimaryKeys; if (pks != null) { foreach (esColumnMetadata pk in pks) { query.OrderBy(pk.Name, esOrderByDirection.Ascending); } } } } } if (this.autoSorting || this.AutoPaging) { if (e.Query != null) { IEntityCollection iColl = e.Collection as IEntityCollection; iColl.HookupQuery(query); } query.Load(); } }
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); } }
private void PopulateSortItems(esDataSourceSelectEventArgs e) { //----------------------------------------- // Populate the esDataSourceSortItem's //----------------------------------------- if (e.Arguments.SortExpression != null && e.Arguments.SortExpression.Length > 0) { e.SortItems = new List <esDataSourceSortItem>(); string[] entries = e.Arguments.SortExpression.Split(','); for (int i = 0; i < entries.Length; i++) { esDataSourceSortItem sortItem = new esDataSourceSortItem(); string sortEntry = entries[i].TrimEnd().TrimStart(); //------------------------------------ // Determine the Sort Direction //------------------------------------ int index = sortEntry.IndexOf(' '); if (index == -1) { sortItem.Direction = esOrderByDirection.Ascending; } else if (sortEntry.Contains(" DESC") || sortEntry.Contains(" desc") || sortEntry.Contains(" Desc")) { sortItem.Direction = esOrderByDirection.Descending; } else { sortItem.Direction = esOrderByDirection.Ascending; } //------------------------------------ // Determine the Property Name //------------------------------------ if (index == -1) { sortItem.Property = sortEntry; } else { sortItem.Property = sortEntry.Substring(0, index); } e.SortItems.Add(sortItem); } } }
protected void EsDataSource1_esSelect(object sender, EntitySpaces.Web.esDataSourceSelectEventArgs e) { ProductsQuery p = new ProductsQuery("P"); CategoriesQuery c = new CategoriesQuery("c"); // All columns from our products table and the CategoryName from the Category table, we really do not // display all of the product fields so I could have selected individual fields out of the products // table p.Select(p, c.CategoryName); p.InnerJoin(c).On(p.CategoryID == c.CategoryID); // We supply the Collection and the Query, because we're letting the grid to auto paging and // auto sorting. Otherwise, we could just load the collection ourselves and only supply the // collection e.Collection = new ProductsCollection(); e.Query = p; }
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); } }
private void FetchTotalRowCount(esDataSourceSelectEventArgs e) { esDynamicQuery query = e.Query != null ? e.Query : e.Collection.es.Query; IDynamicQuerySerializableInternal iQuery = query as IDynamicQuerySerializableInternal; if (e.Arguments.RetrieveTotalRowCount) { if (this.totalRowCount == -1) { #region Backup // // Back up everything cause we're going to restore it // List<esExpression> select = iQuery.InternalSelectColumns; List<esOrderByItem> orderBy = iQuery.InternalOrderByItems; bool countAll = query.es.CountAll; string countAllAlias = query.es.CountAllAlias; int? pageNumber = query.es.PageNumber; int? pageSize = query.es.PageSize; string lastQuery = query.es.LastQuery; EntitySpaces.Interfaces.esDynamicQuery.QueryLoadedDelegate origDelegate = query.OnLoadDelegate; #endregion // // Clear some stuff so we can make our query // iQuery.InternalSelectColumns = null; iQuery.InternalOrderByItems = null; query.es.CountAll = true; query.es.CountAllAlias = "Count"; query.es.PageNumber = null; query.es.PageSize = null; object o = query.OnLoadDelegate; try { query.OnLoadDelegate = this.OnQueryLoaded; if (query.Load()) { this.totalRowCount = Convert.ToInt32(table.Rows[0]["Count"]); } } finally { #region Restore iQuery.InternalSelectColumns = select; iQuery.InternalOrderByItems = orderBy; query.es.CountAll = countAll; query.es.CountAllAlias = countAllAlias; query.es.PageNumber = pageNumber; query.es.PageSize = pageSize; query.OnLoadDelegate = origDelegate; iQuery.LastQuery = lastQuery; #endregion Restore } } e.Arguments.TotalRowCount = this.totalRowCount; } }
private void FetchTotalRowCount(esDataSourceSelectEventArgs e) { esDynamicQuery query = e.Query != null ? e.Query : e.Collection.es.Query; IDynamicQuerySerializableInternal iQuery = query as IDynamicQuerySerializableInternal; if (e.Arguments.RetrieveTotalRowCount) { if (this.totalRowCount == -1) { #region Backup // // Back up everything cause we're going to restore it // List <esExpression> select = iQuery.InternalSelectColumns; List <esOrderByItem> orderBy = iQuery.InternalOrderByItems; bool countAll = query.es.CountAll; string countAllAlias = query.es.CountAllAlias; int? pageNumber = query.es.PageNumber; int? pageSize = query.es.PageSize; string lastQuery = query.es.LastQuery; EntitySpaces.Interfaces.esDynamicQuery.QueryLoadedDelegate origDelegate = query.OnLoadDelegate; #endregion // // Clear some stuff so we can make our query // iQuery.InternalSelectColumns = null; iQuery.InternalOrderByItems = null; query.es.CountAll = true; query.es.CountAllAlias = "Count"; query.es.PageNumber = null; query.es.PageSize = null; object o = query.OnLoadDelegate; try { query.OnLoadDelegate = this.OnQueryLoaded; if (query.Load()) { this.totalRowCount = Convert.ToInt32(table.Rows[0]["Count"]); } } finally { #region Restore iQuery.InternalSelectColumns = select; iQuery.InternalOrderByItems = orderBy; query.es.CountAll = countAll; query.es.CountAllAlias = countAllAlias; query.es.PageNumber = pageNumber; query.es.PageSize = pageSize; query.OnLoadDelegate = origDelegate; iQuery.LastQuery = lastQuery; #endregion Restore } } e.Arguments.TotalRowCount = this.totalRowCount; } }
private void PopulateSortItems(esDataSourceSelectEventArgs e) { //----------------------------------------- // Populate the esDataSourceSortItem's //----------------------------------------- if (e.Arguments.SortExpression != null && e.Arguments.SortExpression.Length > 0) { e.SortItems = new List<esDataSourceSortItem>(); string[] entries = e.Arguments.SortExpression.Split(','); for (int i = 0; i < entries.Length; i++) { esDataSourceSortItem sortItem = new esDataSourceSortItem(); string sortEntry = entries[i].TrimEnd().TrimStart(); //------------------------------------ // Determine the Sort Direction //------------------------------------ int index = sortEntry.IndexOf(' '); if (index == -1) { sortItem.Direction = esOrderByDirection.Ascending; } else if (sortEntry.Contains(" DESC") || sortEntry.Contains(" desc") || sortEntry.Contains(" Desc")) { sortItem.Direction = esOrderByDirection.Descending; } else { sortItem.Direction = esOrderByDirection.Ascending; } //------------------------------------ // Determine the Property Name //------------------------------------ if (index == -1) { sortItem.Property = sortEntry; } else { sortItem.Property = sortEntry.Substring(0, index); } e.SortItems.Add(sortItem); } } }
private void PerformAutoLogic(esDataSourceSelectEventArgs e) { esDynamicQuery query = e.Query != null ? e.Query : e.Collection.es.Query; IDynamicQuerySerializableInternal iQuery = query as IDynamicQuerySerializableInternal; if (this.autoPaging) { query.es.PageNumber = e.PageNumber; query.es.PageSize = e.PageSize; } if (this.autoSorting) { if (e.SortItems != null) { foreach (esDataSourceSortItem sortItem in e.SortItems) { esColumnMetadata col = e.Collection.es.Meta.Columns.FindByPropertyName(sortItem.Property); if(col != null) { query.OrderBy(col.Name, sortItem.Direction); } else if (sortItem.Property[0] == '<') { query.OrderBy(sortItem.Property, sortItem.Direction); } } } else { if (this.AutoPaging) { List<esColumnMetadata> pks = e.Collection.es.Meta.Columns.PrimaryKeys; if (pks != null) { foreach (esColumnMetadata pk in pks) { query.OrderBy(pk.Name, esOrderByDirection.Ascending); } } } } } if (this.autoSorting || this.AutoPaging) { if (e.Query != null) { IEntityCollection iColl = e.Collection as IEntityCollection; iColl.HookupQuery(query); } query.Load(); } }
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; } }