Exemplo n.º 1
0
        }         // proc CheckParentRelationValue

        private void CheckPrimaryKeyValue(PpsDataRow row, object value)
        {
            if (row.Table.FindRows(this, value).Where(c => c != row).FirstOrDefault() != null)
            {
                throw new ArgumentOutOfRangeException($"Value '{value}' is not unique for column '{Table.Name}.{Name}'.");
            }
        }         // proc CheckPrimaryKeyValue
Exemplo n.º 2
0
        }         // proc EndInit

        private void CheckParentRelationValue(PpsDataRow row, object value)
        {
            if (!ExistsValueInParentTable(row, value))
            {
                throw new ArgumentOutOfRangeException($"Value '{value}' does not exist in '{parentRelation.ParentColumn.Table.Name}.{parentRelation.ParentColumn.Name}'.");
            }
        }         // proc CheckParentRelationValue
Exemplo n.º 3
0
        private WeakReference <PpsMasterDataRow> referencedRow = null;        // pointer to the actual row

        /// <summary></summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        public PpsMasterDataExtendedValue(PpsDataRow row, PpsDataColumnDefinition column)
            : base(row, column)
        {
            this.environment = PpsDataSetDefinitionDesktop.GetEnvironmentFromColumn(column);

            this.masterDataTable = environment.MasterData.GetTable(
                column.Meta.GetProperty <string>("refTable", null)
                ?? throw new ArgumentNullException("refTable", "Meta attribute refTable is not definied.")
                ) ?? throw new ArgumentNullException("refTable");
        }         // ctor
        /// <summary></summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        public PpsStaticCalculated(PpsDataRow row, PpsDataColumnDefinition column)
            : base(row, column)
        {
            var code = column.Meta.GetProperty("formula", (string)null);

            // compile the code
            if (!String.IsNullOrEmpty(code))
            {
                // get lua engine
                var lua = column.Table.DataSet.Lua;
                chunk = lua.CompileChunk(code, column.Name + "-formula.lua", null);

                // register table changed, for the update
                row.Table.DataSet.DataChanged += (sender, e) => UpdateValue();
            }
        }         // ctor
Exemplo n.º 5
0
        }         // func OnColumnValueChanging

        private object CreateExtendedValue(PpsDataRow row)
        {
            var typeInfo = DataType.GetTypeInfo();

            // find the longest ctor
            var ci = (ConstructorInfo )null;
            var currentCtorLength = -1;

            foreach (var cur in typeInfo.DeclaredConstructors)
            {
                var newCtorLength = cur.GetParameters().Length;
                if (currentCtorLength < newCtorLength)
                {
                    ci = cur;
                    currentCtorLength = newCtorLength;
                }
            }

            // create the arguments array
            var parameterInfo = ci.GetParameters();
            var arguments     = new object[parameterInfo.Length];

            for (var i = 0; i < arguments.Length; i++)
            {
                var parameterType = parameterInfo[i].ParameterType;
                if (parameterType == typeof(PpsDataRow))
                {
                    arguments[i] = row;
                }
                else if (parameterType == typeof(PpsDataColumnDefinition))
                {
                    arguments[i] = this;
                }
                else if (parameterInfo[i].HasDefaultValue)
                {
                    arguments[i] = parameterInfo[i].DefaultValue;
                }
                else
                {
                    throw new ArgumentException("Unknown argument.");
                }
            }

            // initialize the value
            return(ci.Invoke(arguments));
        }         // func CreateExtendedValue
Exemplo n.º 6
0
        }         // func CreateExtendedValue

        internal void OnColumnValueChanged(PpsDataRow row, object oldValue, object value)
        {
            if (isIdentity)
            {
                row.Table.DataSet.UpdateNextId((long)value);
            }

            // update child relations
            foreach (var relation in table.Relations.Where(r => r.ParentColumn == this))
            {
                var table       = row.Table.DataSet.Tables[relation.ChildColumn.Table];
                var columnIndex = relation.ChildColumn.Index;

                if (oldValue != null && row.Table.DataSet.DeferredConstraints == null)
                {
                    foreach (var childRow in table.FindRows(relation.ChildColumn, oldValue))
                    {
                        childRow[columnIndex] = value;
                    }
                }
            }
        }         // proc OnColumnValueChanged
Exemplo n.º 7
0
 /// <summary>Create PpsDataRelatedFilterDesktop for the ICollectionViewFactory.</summary>
 /// <param name="row"></param>
 /// <param name="relation"></param>
 /// <returns></returns>
 public override PpsDataFilter CreateRelationFilter(PpsDataRow row, PpsDataTableRelationDefinition relation)
 => new PpsDataRelatedFilterDesktop(row, relation);
Exemplo n.º 8
0
 /// <summary></summary>
 /// <param name="parentRow"></param>
 /// <param name="relation"></param>
 public PpsDataRelatedFilterDesktop(PpsDataRow parentRow, PpsDataTableRelationDefinition relation)
     : base(parentRow, relation)
 {
 }         // ctor
Exemplo n.º 9
0
 /// <summary></summary>
 /// <param name="row"></param>
 /// <param name="column"></param>
 public PpsLinkedObjectExtendedValue(PpsDataRow row, PpsDataColumnDefinition column)
     : base(row, column)
 {
     this.environment = PpsDataSetDefinitionDesktop.GetEnvironmentFromColumn(column);
     this.dataset     = row.Table.DataSet as IPpsObjectBasedDataSet;
 }         // ctor
 /// <summary></summary>
 /// <param name="env"></param>
 /// <param name="row"></param>
 public PpsLuaRowEnvironment(LuaTable env, PpsDataRow row)
 {
     this.env = env;
     this.row = row;
 }         // ctor
Exemplo n.º 11
0
        private object value         = null; // id to the master data row

        /// <summary></summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        protected PpsDataRowObjectExtendedValue(PpsDataRow row, PpsDataColumnDefinition column)
            : base(row, column)
        {
        }         // ctor
Exemplo n.º 12
0
 /// <summary>Row was changed.</summary>
 /// <param name="table"></param>
 /// <param name="row"></param>
 protected internal virtual void OnTableRowChanged(PpsDataTable table, PpsDataRow row)
 => InvokeEventHandler("OnTableRowChanged", table, row);
Exemplo n.º 13
0
        }         // proc OnColumnValueChanged

        private bool ExistsValueInParentTable(PpsDataRow row, object value)
        {
            var parentTable = row.Table.DataSet.Tables[parentRelation.ParentColumn.Table];

            return(parentTable.FindRows(parentRelation.ParentColumn, value).FirstOrDefault() != null);
        }         // func ExistsValueInParentTable
Exemplo n.º 14
0
        }         // proc CheckPrimaryKeyValue

        /// <summary>Gets called if a value is changing.</summary>
        /// <param name="row"></param>
        /// <param name="flag"></param>
        /// <param name="oldValue"></param>
        /// <param name="value"></param>
        internal bool OnColumnValueChanging(PpsDataRow row, PpsDataColumnValueChangingFlag flag, object oldValue, ref object value)
        {
            var initial = false;

            switch (flag)
            {
            case PpsDataColumnValueChangingFlag.SetValue:
                var ret = true;

                if (IsRelationColumn)                         // check value contraint
                {
                    row.ClearParentRowCache(this);

                    if (value != null)
                    {
                        var t = row.Table.DataSet.DeferredConstraints;
                        if (t == null)
                        {
                            CheckParentRelationValue(row, value);
                        }
                        else
                        {
                            t.Register(new Action <PpsDataRow, object>(CheckParentRelationValue), "Foreign key constraint failed.", row, value);
                        }
                    }
                }
                if (IsExtended)
                {
                    // check for a internal interface to set a generic value
                    if (oldValue is IPpsDataRowSetGenericValue v)
                    {
                        ret   = v.SetGenericValue(initial, value);
                        value = oldValue;                                 // reset old value
                    }
                    else if (initial)
                    {
                        value = oldValue;
                    }
                    else
                    {
                        throw new NotSupportedException($"It is not allowed to change this extended column ({Table.Name}.{Name}).");
                    }
                }
                if (IsPrimaryKey)                         // check unique
                {
                    var t = row.Table.DataSet.DeferredConstraints;
                    if (t == null)
                    {
                        CheckPrimaryKeyValue(row, value);
                    }
                    else
                    {
                        t.Register(new Action <PpsDataRow, object>(CheckPrimaryKeyValue), "Primary key contraint failed.", row, value);
                    }
                }
                return(ret);

            case PpsDataColumnValueChangingFlag.Initial:

                if (isIdentity && value == null)                         // automatic value
                {
                    value = row.Table.DataSet.GetNextId();
                }
                else if (IsExtended)                         // is extended
                {
                    oldValue = CreateExtendedValue(row);
                }

                if (value != null)
                {
                    initial = true;
                    goto case PpsDataColumnValueChangingFlag.SetValue;
                }
                else
                {
                    value = oldValue;
                }

                return(true);

            default:
                return(true);
            }
        }         // func OnColumnValueChanging
Exemplo n.º 15
0
 /// <summary></summary>
 /// <param name="row"></param>
 /// <param name="column"></param>
 public PpsObjectExtendedValue(PpsDataRow row, PpsDataColumnDefinition column)
     : base(row, column)
 {
     this.environment = PpsDataSetDefinitionDesktop.GetEnvironmentFromColumn(column);
     this.dataset     = (row.Table.DataSet as IPpsObjectBasedDataSet) ?? throw new ArgumentException("Dataset does not implement IPpsObjectBasedDataSet.");
 }         // ctor
Exemplo n.º 16
0
 /// <summary>Property of an extend value was changed.</summary>
 /// <param name="row"></param>
 /// <param name="columnName"></param>
 /// <param name="value"></param>
 /// <param name="propertyName"></param>
 protected internal virtual void OnTableColumnExtendedValueChanged(PpsDataRow row, string columnName, object value, string propertyName)
 => InvokeEventHandler("OnTableColumnExtendedValueChanged", row, columnName, value, propertyName);
Exemplo n.º 17
0
 /// <summary></summary>
 /// <param name="parentRow"></param>
 /// <param name="childRow"></param>
 public PpsDataTableForeignKeyRestrictionException(PpsDataRow parentRow, PpsDataRow childRow)
     : base("row", "row", $"Row {parentRow} is referenced by {childRow}.")
 {
     this.parentRow = parentRow;
     this.childRow  = childRow;
 }         // ctor
Exemplo n.º 18
0
 /// <summary></summary>
 /// <param name="row"></param>
 /// <param name="column"></param>
 public PpsDataRowExtentedValue(PpsDataRow row, PpsDataColumnDefinition column)
 {
     this.row    = row;
     this.column = column;
 }         // ctor