public SingleRecordDatabaseCellViewModel(int columnIndex, DatabaseColumnJson columnDefinition, DatabaseEntityViewModel parent, DatabaseEntity parentEntity, IDatabaseField tableField, IParameterValue parameterValue) : base(parentEntity)
    {
        ColumnIndex    = columnIndex * 2;
        CanBeNull      = columnDefinition.CanBeNull;
        IsReadOnly     = columnDefinition.IsReadOnly;
        ColumnName     = columnDefinition.Name;
        Parent         = parent;
        TableField     = tableField;
        ParameterValue = parameterValue;

        if (UseItemPicker)
        {
            AutoDispose(ParameterValue.ToObservable().Subscribe(_ => RaisePropertyChanged(nameof(OptionValue))));
        }

        if (UseFlagsPicker)
        {
            AutoDispose(ParameterValue.ToObservable().Subscribe(_ => RaisePropertyChanged(nameof(AsLongValue))));
        }

        OriginalValueTooltip =
            tableField.IsModified ? "Original value: " + parameterValue.OriginalString : null;
        AutoDispose(parameterValue.ToObservable("Value").Skip(1).SubscribeAction(_ =>
        {
            Parent.RaiseChanged(this, tableField.FieldName);
            OriginalValueTooltip =
                tableField.IsModified ? "Original value: " + parameterValue.OriginalString : null;
            RaisePropertyChanged(nameof(OriginalValueTooltip));
            RaisePropertyChanged(nameof(AsBoolValue));
            RaisePropertyChanged(nameof(IsModified));
        }));
    }
Exemple #2
0
        public DatabaseCellViewModel(DatabaseRowViewModel parent,
                                     DatabaseEntity parentEntity,
                                     IDatabaseField tableField,
                                     IParameterValue parameterValue,
                                     IObservable <bool>?cellIsVisible)
        {
            Link(tableField, tf => tf.IsModified, () => IsModified);
            ParentEntity   = parentEntity;
            Parent         = parent;
            TableField     = tableField;
            ParameterValue = parameterValue;

            if (cellIsVisible != null)
            {
                AutoDispose(cellIsVisible.Subscribe(v =>
                {
                    IsVisible = v;
                    RaisePropertyChanged(nameof(IsVisible));
                }));
            }

            AutoDispose(parameterValue.ToObservable().SubscribeAction(_ =>
            {
                if (!inConstructor)
                {
                    parent.AnyFieldModified();
                }
                OriginalValueTooltip =
                    tableField.IsModified ? "Original value: " + parameterValue.OriginalString : null;
                RaisePropertyChanged(nameof(OriginalValueTooltip));
                RaisePropertyChanged(nameof(AsBoolValue));
            }));
            inConstructor = false;
        }
        public string GenerateUpdateFieldQuery(DatabaseTableDefinitionJson table, DatabaseEntity entity,
                                               IDatabaseField field)
        {
            var    column           = table.TableColumns[field.FieldName];
            string primaryKeyColumn = table.TablePrimaryKeyColumnName;

            if (column.ForeignTable != null)
            {
                primaryKeyColumn = table.ForeignTableByName[column.ForeignTable].ForeignKey;
            }

            return
                ($"UPDATE {table.TableName} SET `{field.FieldName}` = {field.ToQueryString()} WHERE `{primaryKeyColumn}` = {entity.Key};");
        }
        public IQuery GenerateUpdateFieldQuery(DatabaseTableDefinitionJson table, DatabaseEntity entity,
                                               IDatabaseField field)
        {
            var    column           = table.TableColumns[field.FieldName];
            string primaryKeyColumn = table.TablePrimaryKeyColumnName;

            if (column.ForeignTable != null)
            {
                primaryKeyColumn = table.ForeignTableByName[column.ForeignTable].ForeignKey;
            }

            return(Queries
                   .Table(table.TableName)
                   .Where(row => row.Column <uint>(primaryKeyColumn) == entity.Key)
                   .Set(field.FieldName, field.Object)
                   .Update());
        }
Exemple #5
0
        public DatabaseCellViewModel(int columnIndex, DatabaseColumnJson columnDefinition, DatabaseEntityViewModel parent, DatabaseEntity parentEntity, IDatabaseField tableField, IParameterValue parameterValue) : base(parentEntity)
        {
            ColumnIndex    = columnIndex * 2;
            CanBeNull      = columnDefinition.CanBeNull;
            IsReadOnly     = columnDefinition.IsReadOnly;
            ColumnName     = columnDefinition.Name;
            DbColumnName   = columnDefinition.DbColumnName;
            Parent         = parent;
            TableField     = tableField;
            ParameterValue = parameterValue;

            if (UseItemPicker)
            {
                AutoDispose(ParameterValue.ToObservable().Subscribe(_ => RaisePropertyChanged(nameof(OptionValue))));
            }

            if (UseFlagsPicker)
            {
                AutoDispose(ParameterValue.ToObservable().Subscribe(_ => RaisePropertyChanged(nameof(AsLongValue))));
            }

            AutoDispose(parameterValue.ToObservable().SubscribeAction(_ =>
            {
                OriginalValueTooltip =
                    tableField.IsModified ? "Original value: " + parameterValue.OriginalString : null;
                RaisePropertyChanged(nameof(OriginalValueTooltip));
                RaisePropertyChanged(nameof(AsBoolValue));
            }));
            if (parameterValue.BaseParameter is DatabaseStringContextualParameter contextual)
            {
                var other = parent.Cells.FirstOrDefault(c => c.DbColumnName == contextual.Column);
                if (other != null)
                {
                    AutoDispose(other.ParameterValue !.ToObservable().Subscribe(_ =>
                    {
                        parameterValue.RaiseChanged();
                    }));
                }
                else
                {
                    Console.WriteLine("Couldn't find column " + contextual.Column);
                }
            }
        }
        public DatabaseCellViewModel(int columnIndex, DatabaseColumnJson columnDefinition, DatabaseEntityViewModel parent, DatabaseEntity parentEntity, IDatabaseField tableField, IParameterValue parameterValue)
        {
            ColumnIndex    = columnIndex * 2;
            CanBeNull      = columnDefinition.CanBeNull;
            IsReadOnly     = columnDefinition.IsReadOnly;
            ColumnName     = columnDefinition.DbColumnName;
            ParentEntity   = parentEntity;
            Parent         = parent;
            TableField     = tableField;
            ParameterValue = parameterValue;

            AutoDispose(parameterValue.ToObservable().SubscribeAction(_ =>
            {
                OriginalValueTooltip =
                    tableField.IsModified ? "Original value: " + parameterValue.OriginalString : null;
                RaisePropertyChanged(nameof(OriginalValueTooltip));
                RaisePropertyChanged(nameof(AsBoolValue));
            }));
        }