protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
    {
        ProductsQuery   p = new ProductsQuery("p");
        CategoriesQuery c = new CategoriesQuery("c");

        p.Select(p, c.CategoryName);
        p.InnerJoin(c).On(p.CategoryID == c.CategoryID);

        if (e.PrimaryKeys != null)
        {
            p.Where(p.ProductID == (int)e.PrimaryKeys[0]);
        }
        else
        {
            // They want to add a new one, lets do a select that brings back
            // no records so that our CategoryName column (virutal) will be
            // present in the underlying record format
            p.Where(1 == 0);
        }

        Products prd = new Products();

        prd.Load(p);  // load the data (if any)

        // Assign the Entity
        e.Entity = prd;
    }
 protected virtual void OnCreateEntity(esDataSourceCreateEntityEventArgs e)
 {
     esDataSource.esDataSourceCreateEntityEventHandler handler = base.Events[evCreateEntity]
                                                                 as esDataSource.esDataSourceCreateEntityEventHandler;
     if (handler != null)
     {
         handler(this, e);
     }
 }
Esempio n. 3
0
    protected void EsDataSource1_esCreateEntity(object sender, EntitySpaces.Web.esDataSourceCreateEntityEventArgs e)
    {
        Employees entity = new Employees();

        if (e.PrimaryKeys != null)
        {
            entity.LoadByPrimaryKey((int)e.PrimaryKeys[0]);
        }

        // Assign the Entity
        e.Entity = entity;
    }
        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 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 OnCreateEntity(esDataSourceCreateEntityEventArgs e)
 {
     esDataSource.esDataSourceCreateEntityEventHandler handler = base.Events[evCreateEntity]
         as esDataSource.esDataSourceCreateEntityEventHandler;
     if (handler != null)
     {
         handler(this, e);
     }
 }