예제 #1
0
        public static string GetString(params object[] columns)
        {
            var sb = new SeperatedBuilder();

            sb.Add(columns);

            return(sb.ToString());
        }
예제 #2
0
        void MapColumns(IEnumerable <ColumnBase> columns)
        {
            if (!_handledIdentity)
            {
                _handledIdentity = true;
                if (_bp.From == null)
                {
                    throw new NotImplementedException("Must have an Entity - did you forget to set the From");
                }
                if (_bp.From.PrimaryKeyColumns == null || _bp.From.PrimaryKeyColumns.Length == 0)
                {
                    throw new NotImplementedException("Entity must have a primary key");
                }

                if (_bp.From.PrimaryKeyColumns.Length == 1)
                {
                    _idColumn = _bp.From.PrimaryKeyColumns[0];
                }
                else
                {
                    _idColumn = new TextColumn("id").BindValue(() =>
                    {
                        var x = new SeperatedBuilder();
                        foreach (var item in _bp.From.PrimaryKeyColumns)
                        {
                            x.Add(DataItem.FixValueTypes(item.Value));
                        }
                        return(x.ToString());
                    });
                    Columns.Add(_bp.From.PrimaryKeyColumns);
                    Columns.Add(_idColumn);
                    IgnoreUpdateOf(_idColumn);
                }
            }
            foreach (var column in columns)
            {
                string name = column.Caption;
                if (column == _idColumn)
                {
                    name = "id";
                }
                name = NameFixer.fixName(name);
                var orgName = name;
                int i       = 1;
                while (_colsPerKey.ContainsKey(name))
                {
                    name = orgName + (i++).ToString();
                }
                var cv = new ColumnInViewModel(name, () => column.Value, v =>
                {
                    Caster.Cast(column, v, new setValueForColumn());
                }, column);
                _colMap.Add(column, cv);
                _colsPerKey.Add(name, cv);
                _columns.Add(cv);
                Columns.Add(column);
            }
        }
예제 #3
0
        public void MapColumn(ColumnBase column, string name = null)
        {
            if (!_handledIdentity)
            {
                _handledIdentity = true;
                if (_bp.From == null)
                {
                    throw new NotImplementedException("Must have an Entity - did you forget to set the From");
                }
                if (_bp.From.PrimaryKeyColumns == null || _bp.From.PrimaryKeyColumns.Length == 0)
                {
                    throw new NotImplementedException("Entity must have a primary key");
                }

                if (_bp.From.PrimaryKeyColumns.Length == 1)
                {
                    _idColumn = _bp.From.PrimaryKeyColumns[0];
                }
                else
                {
                    _idColumn = new TextColumn("id").BindValue(() =>
                    {
                        var x = new SeperatedBuilder();
                        foreach (var item in _bp.From.PrimaryKeyColumns)
                        {
                            x.Add(DataItem.FixValueTypes(item.Value));
                        }
                        return(x.ToString());
                    });
                    Columns.Add(_bp.From.PrimaryKeyColumns);
                    Columns.Add(_idColumn);
                    IgnoreUpdateOf(_idColumn);
                }
            }
            if (name == null)
            {
                if (UseClassMemberName)
                {
                    if (column.Entity != null)
                    {
                        foreach (var item in column.Entity.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            if (item.GetValue(column.Entity) == column)
                            {
                                name = item.Name;
                            }
                        }
                    }
                    else
                    {
                        foreach (var item in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            if (item.GetValue(this) == column)
                            {
                                name = item.Name;
                            }
                        }
                    }
                    if (name != null)
                    {
                        if (name.Length > 1)
                        {
                            name = name[0].ToString().ToLower() + name.Substring(1);
                        }
                        if (name.Length == 1)
                        {
                            name = name.ToLower();
                        }
                    }
                    if (column.Entity != null && column.Entity != From)
                    {
                        foreach (var item in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            if (item.GetValue(this) == column.Entity)
                            {
                                name = item.Name + "_" + name;
                                name = name[0].ToString().ToLower() + name.Substring(1);
                            }
                        }
                    }
                }
                if (name == null)
                {
                    name = column.Caption;
                    if (NameFixer.HasHebrewInIt(name) && !string.IsNullOrEmpty(column.Name) && UseNameInsteadOfCaptionForHebrew)
                    {
                        name = column.Name;
                    }
                    name = SeparateWordsAndCasing(name);
                }
            }

            if (column == _idColumn)
            {
                name = "id";
            }

            name = NameFixer.fixName(name);
            var orgName = name;
            int i       = 1;

            while (_colsPerKey.ContainsKey(name.ToUpper()))
            {
                name = orgName + (i++).ToString();
            }
            var cv = new ColumnInViewModel(name, () => column.Value, v =>
            {
                Caster.Cast(column, v, new setValueForColumn());
            }, column);

            _colMap.Add(column, cv);
            _colsPerKey.Add(name.ToUpper(), cv);
            _columns.Add(cv);
            Columns.Add(column);
        }