Esempio n. 1
0
        protected void addRowGeneric <T>() where T : class
        {
            IList <T> tmp       = (_container.GetPropertyByName(_propertyName) as IList <T>);
            int       maxOrdine = tmp.Count > 0 ? tmp.Max(element => ((Func <T, int>)_getter)(element)) : 0;

            T curr = _bs.Current as T;

            _bs.AddNew();
            T newCurr = _bs.Current as T;

            // handle entity connect to context
            EntityBase eb = newCurr as EntityBase;

            if (eb != null)
            {
                eb.SetCtx(_host.DataCtx);
            }

            if (curr != null)
            {
                // newCurr.ordine = maxOrdine + 1;
                ((Action <T, int>)_setter)(newCurr, maxOrdine + 1);
            }
            else
            {
                // newCurr.ordine = maxOrdine + 1;
                ((Action <T, int>)_setter)(newCurr, maxOrdine + 1);
            }
            _wes_RowEdit?.Raise(this, new RowEditEventArgs()
            {
                Data = _bs.Current, IsNew = true
            });

            gridView.MoveLast();
        }
        protected void addRowGeneric <T>() where T : class
        {
            // disable eventual filters
            gridView.ActiveFilterEnabled = false;

            T curr = _bs.Current as T;

            if (curr is IVocabularyElement)
            {
                _bs.Add(((IVocabularyElement)curr).GetFirstFree());
            }
            else
            {
                _bs.AddNew();
            }
            T newCurr = _bs.Current as T;

            // handle entity connect to context
            EntityBase eb = newCurr as EntityBase;

            if (eb != null)
            {
                eb.SetCtx(_host.DataCtx);
            }

            _wes_RowEdit?.Raise(this, new RowEditEventArgs()
            {
                Data = _bs.Current, IsNew = true
            });

            gridView.ShowEditForm();

            // this can be use for eventual cleaning after cancel, if newCurr is not the same as _bs.Current => means it was canceled in edit form
            _wes_AfterRowEdit?.Raise(this, new RowAfterEditEventArgs()
            {
                Data = newCurr, DoCancel = !ReferenceEquals(newCurr, _bs.Current)
            });

            // delete object for sure again!!
            EntityState es = _host.DataCtx.Entry(newCurr).State;

            if (!ReferenceEquals(newCurr, _bs.Current) && _host.DataCtx.Entry(newCurr).State == EntityState.Added)
            {
                deleteRowMethod.Invoke(this, new object[] { newCurr });
            }

            gridView.MoveLast();
        }