Пример #1
0
        public List <Soway.Query.Entity.IQueryTable> GetTables()
        {
            var result = new List <Soway.Query.Entity.IQueryTable>();

            if (models.Count == 0)
            {
                models.Clear();
                var view = new Soway.Model.View.AutoViewFactory(this.Con, this.ConFac).CreateDefaultListView(Global.ModeMode);
                view.Filter = "[SW_SYS_MODEL].MODEL_TYPE<>'" + System.Convert.ToString((int)ModelType.Enum) + "'";

                Soway.Model.Context.ListViewQueryContext cxt = new Context.ListViewQueryContext(this.Con, this.ConFac);
                var list = cxt.Query(view, 0, 0);

                foreach (var i in list.CurrentResult)
                {
                    Soway.Query.Entity.IQueryTable model = new Soway.Query.Entity.IQueryTable();
                    model.ShowName = i.ObjectProxy["Name"].ToString();
                    model.DBName   = i.ObjectProxy["DataTableName"].ToString();

                    models.Add(model, i.ObjectProxy.ID);

                    result.Add(model);
                    // models.Add(model);
                }
            }
            result.AddRange(models.Keys.ToArray());
            return(result);
        }
Пример #2
0
        public List <Soway.Query.Entity.IQueryColumn> GetColumns(Soway.Query.Entity.IQueryTable Table)
        {
            var table = Table;
            var proxy = new SqlServer.dbContext(this.Con, this.ConFac).GetDetail(Global.ModeMode, models[table]);


            var Model = new ModelHelper(this.ConFac).GetFromProxy(proxy) as Model;
            List <IQueryColumn> result = new List <IQueryColumn>();

            GetQueryModel(Model).Columns.ForEach(p => result.Add(p));
            return(result);
        }
Пример #3
0
        public List <Soway.Query.JoinTable> GetCanJoinedTables(Soway.Query.Entity.IQueryTable Table,
                                                               Soway.Query.JoinQueryType JoinType)
        {
            var list  = new List <Soway.Query.JoinTable>();
            var proxy = new SqlServer.dbContext(this.Con, this.ConFac).GetDetail(Global.ModeMode, models[Table]);
            var Model = new ModelHelper(this.ConFac).GetFromProxy(proxy) as Model;

            if (JoinType == Soway.Query.JoinQueryType.Items || JoinType == Soway.Query.JoinQueryType.All)
            {
                foreach (var relation in Model.Relations)
                {
                    var codition = new Soway.Query.JoinCondition(SqlServer.SqlHelper.GetKeyCol(
                                                                     Model), relation.TargetColumn);
                    var JoinTable = new Soway.Query.JoinTable();
                    JoinTable.Conditions.Add(codition);
                    JoinTable.LeftTable = new Soway.Query.SelectedTable()
                    {
                        Table = Table
                    };
                    if (relation.RelationType == RelationType.Many2One || relation.RelationType == RelationType.One2Many)
                    {
                        JoinTable.RightTable = new Soway.Query.SelectedTable()
                        {
                            Table = GetTable(relation.RelationTable)
                        }
                    }
                    ;
                    else
                    {
                        JoinTable.RightTable = new Soway.Query.SelectedTable()
                        {
                            Table = new Soway.Query.Entity.IQueryTable()
                            {
                                DBName   = relation.RelationTable,
                                ShowName = relation.RelationTable
                            }
                        }
                    };
                    list.Add(JoinTable);
                }
            }
            if (JoinType == Soway.Query.JoinQueryType.Parent || JoinType == Soway.Query.JoinQueryType.All)
            {
                relationView.Filter = "[SW_SYS_RELATION].[SW_SYS_RELATION_TABLE]='" + Table.DBName + "'";

                var result = new Soway.Model.Context.ListViewQueryContext(this.Con, ConFac)
                             .Query(relationView, 0, 0);

                foreach (var item in result.CurrentResult)
                {
                    Relation relation =
                        new ModelHelper(this.ConFac).GetFromProxy(new Soway.Model.SqlServer.dbContext(this.Con, this.ConFac).GetDetail(relatoinModel, item.ObjectProxy.ID, true));

                    var codition = new Soway.Query.JoinCondition(relation.TargetColumn,
                                                                 SqlServer.SqlHelper.GetKeyCol(Model));
                    var JoinTable = new Soway.Query.JoinTable();
                    JoinTable.Conditions.Add(codition);
                    JoinTable.LeftTable = new Soway.Query.SelectedTable()
                    {
                        Table = Table
                    };
                    JoinTable.RightTable = new Soway.Query.SelectedTable()
                    {
                        Table = GetTable(
                            Model.DataTableName)
                    };
                    list.Add(JoinTable);
                }

                foreach (var property in Model.Properties.Where(p => p.Model != null &&
                                                                p.IsMultiMap == false && p.PropertyType == PropertyType.BusinessObject && p.IsArray == false))
                {
                    var codition = new Soway.Query.JoinCondition(
                        property.DBName,
                        SqlServer.SqlHelper.GetKeyCol(
                            property.Model));
                    var JoinTable = new Soway.Query.JoinTable();
                    JoinTable.Conditions.Add(codition);
                    JoinTable.LeftTable = new Soway.Query.SelectedTable()
                    {
                        Table = Table
                    };
                    JoinTable.RightTable = new Soway.Query.SelectedTable()
                    {
                        Table = GetTable(property.Model.DataTableName)
                    };
                    list.Add(JoinTable);
                }
            }

            return(list);
        }