/// <summary>
        /// Binds <see cref="IColumns"/> to <see cref="ValidationPlaceholder"/>.
        /// </summary>
        /// <param name="source">The source <see cref="IColumns"/>.</param>
        /// <param name="bindings">The bindings to determine whether the <see cref="ValidationPlaceholder"/> is active.</param>
        /// <returns>The row binding object.</returns>
        public static RowBinding <ValidationPlaceholder> BindToValidationPlaceholder(this IColumns source, params RowBinding[] bindings)
        {
            source.VerifyNotNull(nameof(source));

            source = source.Seal();

            var result = new RowBinding <ValidationPlaceholder>(onSetup: (v, p) =>
            {
                if (bindings != null && bindings.Length > 0)
                {
                    var containingElements = new UIElement[bindings.Length];
                    for (int i = 0; i < containingElements.Length; i++)
                    {
                        containingElements[i] = bindings[i].GetSettingUpElement();
                    }
                    v.Setup(containingElements);
                }
            }, onRefresh: null, onCleanup: (v, p) =>
            {
                v.Cleanup();
            });
            var input = result.BeginInput(new ValueChangedTrigger <ValidationPlaceholder>(source, result));

            foreach (var column in source)
            {
                input.WithFlush(column, (r, v) => true);
            }
            return(input.EndInput());
        }
        private void ExpandColumns(IColumns columns, TreeNode node)
        {
            if (HasBlankNode(node))
            {
                foreach (IColumn column in columns)
                {
                    TreeNode n = new TreeNode(column.Name);
                    n.Tag = new NodeData(NodeType.COLUMN, column);

                    if (!column.IsInPrimaryKey)
                    {
                        n.SelectedImageIndex = n.ImageIndex = 10;
                    }
                    else
                    {
                        n.SelectedImageIndex = n.ImageIndex = 26;
                    }

                    node.Nodes.Add(n);

                    if (column.ForeignKeys.Count > 0)
                    {
                        TreeNode nn = new TreeNode("ForeignKeys");
                        nn.Tag = new NodeData(NodeType.FOREIGNKEYS, column.ForeignKeys);
                        nn.SelectedImageIndex = nn.ImageIndex = 11;
                        n.Nodes.Add(nn);
                        nn.Nodes.Add(this.BlankNode);
                    }
                }
            }
        }
示例#3
0
        /// <summary>
        /// Setup the flushing operation.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="valueBagGetter">The delegate to get column value bag.</param>
        /// <returns>This row input for fluent coding.</returns>
        public RowInput <T> WithFlush(Column column, Func <T, ColumnValueBag> valueBagGetter)
        {
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }
            if (valueBagGetter == null)
            {
                throw new ArgumentNullException(nameof(valueBagGetter));
            }

            VerifyNotSealed();
            _target = _target.Union(column);
            _flushFuncs.Add((rowPresenter, element) =>
            {
                if (valueBagGetter == null)
                {
                    return(false);
                }
                var value = valueBagGetter(element)[column];
                if (object.Equals(rowPresenter[column], value))
                {
                    return(false);
                }
                rowPresenter[column] = value;
                return(true);
            });
            return(this);
        }
示例#4
0
        private bool HasError(RowPresenter rowPresenter, IColumns columns)
        {
            if (ErrorsByRow.Count == 0)
            {
                return(false);
            }

            IDataValidationErrors errors;

            if (!ErrorsByRow.TryGetValue(rowPresenter, out errors))
            {
                return(false);
            }

            for (int i = 0; i < errors.Count; i++)
            {
                var message = errors[i];
                if (message.Source.SetEquals(columns))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#5
0
        /// <summary>
        /// Setup the flushing operation.
        /// </summary>
        /// <typeparam name="TData">Data type of column.</typeparam>
        /// <param name="column">The column.</param>
        /// <param name="getValue">The delegate to return data value.</param>
        /// <returns>This row input for fluent coding.</returns>
        public RowInput <T> WithFlush <TData>(Column <TData> column, Func <T, TData> getValue)
        {
            if (column == null)
            {
                throw new ArgumentNullException(nameof(column));
            }

            VerifyNotSealed();
            _target = _target.Union(column);
            _flushFuncs.Add((p, v) =>
            {
                if (getValue == null)
                {
                    return(false);
                }
                var value = getValue(v);
                if (column.AreEqual(p.GetValue(column), value))
                {
                    return(false);
                }
                p.EditValue(column, value);
                return(true);
            });
            return(this);
        }
示例#6
0
        /// <summary>Determines whether the current columns is a proper (strict) subset of the specified columns.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The columns to compare to the current columns.</param>
        /// <returns><see langword="true"/> if the current set is a proper subset of the specified collection; otherwise, <see langword="false" />.</returns>
        public static bool IsProperSubsetOf(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            return(source.Count < other.Count ? other.ContainsAll(source) : false);
        }
示例#7
0
        /// <summary>Determines whether the current columns is a superset of a specified columns.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The columns to compare to the current columns.</param>
        /// <returns><see langword="true"/> if the current set is a superset of the specified collection; otherwise, <see langword="false" />.</returns>
        public static bool IsSupersetOf(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            return(source.Count >= other.Count ? source.ContainsAll(other) : false);
        }
示例#8
0
        /// <summary>Ensures set contain only elements that are present either in the current columns or in the specified columns, but not both.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The columns to compare to the current columns.</param>
        /// <returns>A new set if there is any modification to current sealed set; otherwise, the current set.</returns>
        public static IColumns SymmetricExcept(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            IColumns removedColumnSet = Columns.Empty;

            foreach (var column in source)
            {
                if (other.Contains(column))
                {
                    removedColumnSet = removedColumnSet.Add(column);
                    source           = source.Remove(column);
                }
            }

            foreach (var column in other)
            {
                if (removedColumnSet.Contains(column))
                {
                    source = source.Add(column);
                }
            }

            return(source);
        }
示例#9
0
        private static void AddModel(IColumns databaseObject)
        {
            string schema;

            if (mappingRuleManager.IsIncluded(databaseObject))
            {
                schema = databaseObject.Schema.ToPascalCase();

                if (!mapping.ModelNamespaces.Contains(schema))
                {
                    mapping.ModelNamespaces.Add(new ModelNamespace()
                    {
                        Name = schema
                    });
                }

                Model model = new Model()
                {
                    Namespace   = schema,
                    Name        = mappingRuleManager.TrimPrefix(databaseObject).ToPascalCase().ToSingular(),
                    Description = databaseObject.Description,
                    IsView      = databaseObject is View,
                    MappingName = databaseObject.ToString()
                };

                LoadProperties(model.Properties, databaseObject);

                mapping.ModelNamespaces[schema].Models.Add(model);
            }
        }
示例#10
0
        internal bool HasError(RowPresenter rowPresenter, IColumns source, bool isAsync)
        {
            IReadOnlyDictionary <RowPresenter, IDataValidationErrors> dictionary = isAsync ? _asyncErrorsByRow : _errorsByRow;

            if (dictionary != null)
            {
                IDataValidationErrors errors;
                if (dictionary.TryGetValue(rowPresenter, out errors))
                {
                    if (errors != null && errors.Count > 0 && HasError(rowPresenter, errors, source, !isAsync))
                    {
                        return(true);
                    }
                }
            }

            if (isAsync && rowPresenter == CurrentRow)
            {
                foreach (var asyncValidator in AsyncValidators)
                {
                    if (asyncValidator.GetFault(source) != null)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#11
0
        /// <summary>Determines whether the current columns and the specified columns contain the same elements.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The columns to compare to the current columns.</param>
        /// <returns><see langword="true"/> if the current set and the specified columns contain the same elements; otherwise, <see langword="false" />.</returns>
        public static bool SetEquals(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            return(source.Count == other.Count ? source.ContainsAll(other) : false);
        }
示例#12
0
 /// <summary>
 /// ���캯��
 /// </summary>
 /// <param name="name">��ͼ����</param>
 /// <param name="comment">��ע</param>
 public View(string name, string comment)
 {
     this.name = name;
     this.comment = comment;
     this.code = string.Empty;
     columns = null;
 }
示例#13
0
        private string name; // ����

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Ĭ�Ϲ��캯��
        /// </summary>
        public View()
        {
            this.name = string.Empty;
            this.comment = string.Empty;
            this.code = string.Empty;
            columns = null;
        }
示例#14
0
        public static void ImportChildRelations(ITable srcTab, TableDefinitionDataTable destTabs)
        {
            foreach (IForeignKey srcFK in srcTab.ForeignKeys)
            {
                if (srcTab == srcFK.PrimaryTable)   // use only childrelations
                {
                    TableDefinitionRow childTab  = destTabs.FindByTableName(srcFK.ForeignTable.Name);
                    TableDefinitionRow parentTab = destTabs.FindByTableName(srcFK.PrimaryTable.Name);
                    if ((childTab == null) || (parentTab == null))
                    {
                        return; // both tables are not included
                    }
                    String relationName =
                        parentTab.Table.DataSet.RelationDefinition.CreateUniqueRelationName(srcFK.Name, childTab.TableName, parentTab.TableName);

                    RelationDefinitionRow curRelation = parentTab.InsertNewRelation(relationName, childTab.TableName);

                    IColumns parentColums = srcFK.PrimaryColumns;
                    IColumns childColums  = srcFK.ForeignColumns;

                    FieldRelationDefinitionRow curFieldRelation = null;

                    for (int colNo = 0; colNo < parentColums.Count; colNo++)
                    {
                        curFieldRelation = curRelation.InsertNewFieldRelation(parentColums[colNo].Name, childColums[colNo].Name);
                    }
                } // if (srcTab == srcFK.PrimaryTable)   // use only childrelations
            }     // foreach (IForeignKey srcFK in srcTab.ForeignKeys)
        }
示例#15
0
        private static string GetName(IColumns databaseObject, string columnName)
        {
            if (databaseObject is Table)
            {
                var foreignKeys = (databaseObject as Table).ForeignKeys;

                foreach (ForeignKey fk in foreignKeys)
                {
                    if (fk.Columns.Count == 1 && fk.Columns[0].Name == columnName)
                    {
                        return(MappingHelper.GetPascalCase(MappingHelper.TrimId(columnName)));
                    }
                }
            }

            if (columnName.EndsWith("_Id", StringComparison.OrdinalIgnoreCase))
            {
                string referenceName = MappingHelper.TrimId(columnName);

                foreach (Table tb in database.Tables)
                {
                    if (mappingConfig.Model.TrimName(tb) == referenceName)
                    {
                        return(MappingHelper.GetPascalCase(referenceName));
                    }
                }
            }

            return(MappingHelper.GetPascalCase(columnName));
        }
示例#16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="SelectRequest" /> class. Initialise une nouvelle instance de la
 ///     classe <see cref="SelectRequest" />.
 /// </summary>
 /// <param name="nomTable">The nomTable.</param>
 internal SelectRequest(string nomTable)
     : this()
 {
     this.listeColumns   = new List <string>();
     this.PrincipalTable = new Table(nomTable);
     this.selectColumns  = new Columns(this.PrincipalTable);
     this.joins          = new Joins();
 }
示例#17
0
        private void UpdateAsyncErrors(IColumns changedColumns)
        {
            Debug.Assert(CurrentRow != null);
            var errors = GetErrors(_asyncErrorsByRow, CurrentRow);

            errors = Remove(errors, x => x.Source.Overlaps(changedColumns));
            UpdateAsyncErrors(CurrentRow, errors);
        }
示例#18
0
 public static void ImportFields(IColumns srcColumns, TableDefinitionRow destTab)
 {
     nextPkNumber = 1;
     foreach (IColumn srcCol in srcColumns)
     {
         ImportField(srcCol, destTab);
     }
 }
示例#19
0
        public Extractor(Func <object> construct, IColumns columns)
        {
            Construct  = construct;
            Columns    = columns;
            Properties = _Properties();

            Converters = Default;
        }
示例#20
0
 /// <summary>
 /// Setup the flushing operation.
 /// </summary>
 /// <param name="column">The column.</param>
 /// <param name="flush">The delegate to flush input.</param>
 /// <returns>This row input for fluent coding.</returns>
 public RowInput <T> WithFlush(Column column, Func <RowPresenter, T, bool> flush)
 {
     column.VerifyNotNull(nameof(column));
     flush.VerifyNotNull(nameof(flush));
     VerifyNotSealed();
     _target = _target.Union(column);
     _flushFuncs.Add(flush);
     return(this);
 }
示例#21
0
 private static bool ContainsAll(this IColumns source, IColumns other)
 {
     foreach (var column in other)
     {
         if (!source.Contains(column))
         {
             return(false);
         }
     }
     return(true);
 }
示例#22
0
 private static void Restore(IColumns progress, Dictionary <RowPresenter, IColumns> progressByRow, RowPresenter currentRow)
 {
     if (progress == Columns.Empty && progressByRow.ContainsKey(currentRow))
     {
         progressByRow.Remove(currentRow);
     }
     else
     {
         progressByRow[currentRow] = progress;
     }
 }
示例#23
0
 private static string GetDefaultDisplayName(IColumns sourceColumns)
 {
     if (sourceColumns.Count == 1)
     {
         return(sourceColumns.First <Column>().DisplayName);
     }
     else
     {
         return(string.Format("[{0}]", string.Join(", ", sourceColumns.Select(x => x.DisplayName))));
     }
 }
示例#24
0
        /// <summary>Ensures set contain all elements that are present in either the current columns or in the specified columns.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The collection to add elements from.</param>
        /// <returns>A new set if there is any modification to current set and current set sealed; otherwise, the current set.</returns>
        public static IColumns Union(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            foreach (var column in other)
            {
                source = source.Add(column);
            }
            return(source);
        }
 private static JsonWriter WriteColumns(this JsonWriter jsonWriter, IColumns columns)
 {
     if (columns == null)
     {
         jsonWriter.WriteNameValuePair(SOURCE, JsonValue.Null);
     }
     else
     {
         jsonWriter.WriteNameStringPair(SOURCE, columns.Serialize());
     }
     return(jsonWriter);
 }
示例#26
0
 internal void OnValueChanged(Column column)
 {
     if (IsValueChangedNotificationSuspended)
     {
         if (_pendingValueChangedColumns != null)
         {
             _pendingValueChangedColumns = _pendingValueChangedColumns.Add(column);
         }
         return;
     }
     NotifyValueChanged(column);
 }
示例#27
0
        private int CountUniqueFields(IColumns Columns)
        {
            int i = 0;

            foreach (IColumn c in Columns)
            {
                if (!c.IsNullable && c.IsInPrimaryKey)
                {
                    i++;
                }
            }
            return(i);
        }
示例#28
0
        private int CountNullableFields(IColumns Columns)
        {
            int i = 0;

            foreach (IColumn c in Columns)
            {
                if (c.IsNullable)
                {
                    i++;
                }
            }
            return(i);
        }
示例#29
0
        /// <summary>Removes the columns to ensure the set contains only columns both exist in the current columns and the specified columns.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The columns to compare to the current columns.</param>
        /// <returns>A new set of columns if there is any modification to current sealed set; otherwise, the current set.</returns>
        public static IColumns Intersect(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            foreach (var column in source)
            {
                if (!other.Contains(column))
                {
                    source = source.Remove(column);
                }
            }
            return(source);
        }
示例#30
0
        /// <summary>Determines whether the current columns overlaps with the specified columns.</summary>
        /// <param name="source">The current columns.</param>
        /// <param name="other">The columns to compare to the current columns.</param>
        /// <returns><see langword="true"/> if the current set overlaps with the specified columns; otherwise, <see langword="false" />.</returns>
        public static bool Overlaps(this IColumns source, IColumns other)
        {
            source.VerifyNotNull(nameof(source));
            other.VerifyNotNull(nameof(other));

            foreach (var column in source)
            {
                if (other.Contains(column))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#31
0
 private string GetDisplayNames(IColumns columns)
 {
     if (columns.Count == 0)
     {
         return(null);
     }
     else if (columns.Count == 1)
     {
         return(columns.Single().DisplayName);
     }
     else
     {
         return(string.Format("({0})", string.Join(", ", columns.Select(x => x.DisplayName))));
     }
 }
示例#32
0
        /// <summary>
        /// Determines whether validation error is visible.
        /// </summary>
        /// <param name="rowPresenter">The <see cref="RowPresenter"/>.</param>
        /// <param name="columns">The columns.</param>
        /// <returns><see langword="true"/> if validation error is visible, otherwise <see langword="false"/>.</returns>
        public bool IsVisible(RowPresenter rowPresenter, IColumns columns)
        {
            rowPresenter.VerifyNotNull(nameof(rowPresenter));

            if (columns == null || columns.Count == 0)
            {
                return(false);
            }

            if (_progress == null)
            {
                return(true);
            }

            return(Exists(_progress, rowPresenter, columns));
        }
示例#33
0
        private void BuildPublicAccessors(IColumns Columns)
        {
            if (Columns.Count > 0)
            {
                output.writeln("\t\t#region Public Properties");

                foreach (IColumn field in Columns)
                {
                    if (IsInColumns(field))
                    {
                        string fieldAccessor = ColumnToPropertyName(field);
                        string fieldName = ColumnToMemberVariable(field);
                        string fieldType = (field.IsInForeignKey && !field.IsInPrimaryKey ? ToPascalCase(field.ForeignKeys[0].PrimaryTable.Alias.Replace(" ", "")) : ColumnToNHibernateType(field));

                        output.writeln("");
                        //output.writeln( "\t\t/// <summary>" );

                        //foreach( string s in field.Description.Split( new char[] { '\n' } ) )
                        //{
                        //		output.writeln( "\t\t/// " + s );
                        //}
                        //output.writeln( "\t\t/// </summary>" );

                        output.write(ActiveRecordColumnAttributes(field));
                        if (field.IsNullable && IsValueType(field.LanguageType))
                            output.writeln("\t\tpublic " + fieldType + "? " + fieldAccessor + "{ get; set; }");
                        else
                            output.writeln("\t\tpublic " + fieldType + " " + fieldAccessor + "{ get; set; }");
                    }
                }
                output.writeln("\n\t\t#endregion");
            }
        }
示例#34
0
 private int CountRequiredFields(IColumns Columns)
 {
     return Columns.Count - CountNullableFields(Columns);
 }
示例#35
0
 private int CountUniqueFields(IColumns Columns)
 {
     int i = 0;
     foreach (IColumn c in Columns)
     {
         if (!c.IsNullable && c.IsInPrimaryKey)
         {
             i++;
         }
     }
     return i;
 }
示例#36
0
 private void GenerateClassTableHeader(IColumns Columns)
 {
     output.writeln("/*");
     output.writeln(" * This class maps to " + _tableName + " with the following columns:");
     foreach (IColumn field in Columns)
     {
         string propertyName = field.Name + "(" + ColumnToPropertyName(field) + ")";
         string fpname = String.Format("{0,-40}", propertyName);
         output.write(" * \t " + fpname);
         output.write("| Type:" + String.Format("{0,-10}", field.DataTypeName));
         output.write("| Len:" + String.Format("{0,-4}", field.CharacterMaxLength));
         output.write("| Nullable:" + String.Format("{0,-1}", field.IsNullable ? "T" : "F"));
         output.write("| PK:" + String.Format("{0,-1}", field.IsInPrimaryKey ? "T" : "F"));
         output.write("| FK:=" + String.Format("{0,-1}", field.IsInForeignKey ? "T" : "F"));
         output.writeln("");
     }
     output.writeln(" */");
 }
示例#37
0
 public static void ImportFields(IColumns srcColumns, TableDefinitionRow destTab)
 {
     nextPkNumber = 1;
     foreach(IColumn srcCol in srcColumns)
         ImportField(srcCol, destTab);
 }
示例#38
0
 private int CountNullableFields(IColumns Columns)
 {
     int i = 0;
     foreach (IColumn c in Columns)
     {
         if (c.IsNullable)
         {
             i++;
         }
     }
     return i;
 }
		private void ExpandColumns(IColumns columns, TreeNode node)
		{
			if(HasBlankNode(node))
			{
				foreach(IColumn column in columns)
				{
					TreeNode n = new TreeNode(column.Name);
					n.Tag = new NodeData(NodeType.COLUMN, column);

					if(!column.IsInPrimaryKey)
						n.SelectedImageIndex = n.ImageIndex = 10;
					else
						n.SelectedImageIndex = n.ImageIndex = 13;

					node.Nodes.Add(n);

					if(column.ForeignKeys.Count > 0)
					{
						TreeNode nn = new TreeNode("ForeignKeys");
						nn.Tag = new NodeData(NodeType.FOREIGNKEYS, column.ForeignKeys);
						nn.SelectedImageIndex = nn.ImageIndex = 11;
						n.Nodes.Add(nn);
						nn.Nodes.Add(this.BlankNode);
					}
				}
			}
		}
示例#40
0
 public CategoryTable(IColumns columns, IDatabase database)
 {
     this._database = database;
     this._columns = columns;
 }