Beispiel #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);
        }
Beispiel #2
0
        protected override void ImplementBusinessLogic()
        {
            var view       = new Soway.Model.View.AutoViewFactory(this.Info.AppSqlCon, this).GetView(this.Opt.ViewId);
            var queryModel = new Soway.Model.Query.QueryFactory(this.Info.AppSqlCon, this).GetQueryModel(view);

            this.ReturnData.Cols = new List <QueryCol>();
            foreach (var col in queryModel.Columns)
            {
                var item = new QueryCol()
                {
                    Name    = col.ShowName,
                    ID      = col.ID,
                    PrpType = col.DataType,
                    ModelId = col.ModelId,
                    States  = col.States
                };
                item.CompareTypes = new List <CompareOpItem>();
                foreach (var compare in QueryCache.GetCompareType(this.Info.AppSqlCon, col.DataType))
                {
                    item.CompareTypes.Add(new CompareOpItem()
                    {
                        ID   = compare.ID.ToString(),
                        Name = compare.ShowName
                    });
                }

                item.QueryTypes = new List <QueryType>();

                foreach (var select in QueryCache.GetSelectedType(this.Info.AppSqlCon, col.DataType))
                {
                    item.QueryTypes.Add(new QueryType()
                    {
                        ID   = select.ID.ToString(),
                        Name = select.Show,
                    });
                }
                this.ReturnData.Cols.Add(item);
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Source">模型</param>
        /// <param name="ModelSqlCon">存储模型的数据库</param>
        /// <param name="DataBaseSqlCon">要创建的数据库的</param>
        public void InstallModules(IModuleSource Source,
                                   SqlCon ModelSqlCon, SqlCon DataBaseSqlCon)
        {
            ConnectionType ConnectionType = ConnectionType.AppSys;

            if (ModelSqlCon.ToString() == DataBaseSqlCon.ToString())
            {
                ConnectionType = ConnectionType.AppSys;
            }
            else
            {
                ConnectionType = ConnectionType.Current;
            }

            //System.Diagnostics.Trace.WriteLine("MODEL:"+ModelSqlCon.ToString());
            //System.Diagnostics.Trace.WriteLine("CON:"+ModelSqlCon.ToString());
            var modelDb      = new SqlServer.dbContext(ModelSqlCon, this.ConFac);
            var DataDb       = new SqlServer.dbContext(DataBaseSqlCon, this.ConFac);
            var modelMode    = Global.ModeMode;
            var moduleMode   = Global.ModuleMode;
            var viewMode     = Global.ViewMode;
            var relationMode = Global.RelationModel;


            List <IObjectProxy>   insertItems = new List <IObjectProxy>();
            ModelSqlServerFactory sqlFac      = new ModelSqlServerFactory(Source);
            var viewFac = new Soway.Model.View.AutoViewFactory(ModelSqlCon, this.ConFac);
            Dictionary <object, System.Data.IDbCommand> commands = new Dictionary <object, System.Data.IDbCommand>();

            Dictionary <object, System.Data.IDbCommand> relationsCommands = new Dictionary <object, System.Data.IDbCommand>();
            var helper  = new ModelHelper(this.ConFac);
            var modules = Source.GetModules();

            CreateDataBase(DataBaseSqlCon);

            foreach (var module in modules.Distinct())
            {
                module.SqlCon = DataBaseSqlCon;
                IObjectProxy moduleproxy = new ObjectProxy(moduleMode, this.ConFac);
                helper.SetProxy(ref moduleproxy, module);

                if (modelDb.IsExits(moduleproxy) == true)
                {
                }
                else
                {
                    insertItems.Add(moduleproxy);
                }

                foreach (var model in Source.GetModels(module))
                {
                    IObjectProxy proxy = new ObjectProxy(modelMode, this.ConFac, LoadType.Complete);
                    helper.SetProxy(ref proxy, model);
                    if (modelDb.IsExits(proxy) == false)
                    {
                        insertItems.Add(proxy);
                    }
                    if (model.ModelType != ModelType.Enum)
                    {
                        var command = sqlFac.GerateCreateSql(model);
                        if (commands.ContainsKey(model))
                        {
                            commands[model] = command;
                        }
                        else
                        {
                            commands.Add(model, command
                                         );
                        }
                        foreach (var relation in model.Relations)
                        {
                            if (relationsCommands.ContainsKey(relation) == false)
                            {
                                relationsCommands.Add(relation, sqlFac.GetRelationSql(relation));
                            }
                        }
                        var itemView = viewFac.CreateDefaultItemView(model);
                        itemView.ConnectionType = ConnectionType;
                        IObjectProxy itemViewProxy = new ObjectProxy(viewMode, this.ConFac);
                        var          view          = viewFac.CreateDefaultListView(model);
                        IObjectProxy viewProxy     = new ObjectProxy(viewMode, this.ConFac);
                        view.ConnectionType = ConnectionType;
                        helper.SetProxy(ref itemViewProxy, itemView);
                        insertItems.Add(itemViewProxy);
                        helper.SetProxy(ref viewProxy, view);
                        insertItems.Add(viewProxy);
                    }
                }
            }



            //创建表
            foreach (var command in commands)

            {
                DataDb
                .Excute(command.Value as System.Data.SqlClient.SqlCommand);
            }

            foreach (var command in relationsCommands)

            {
                DataDb
                .Excute(command.Value as System.Data.SqlClient.SqlCommand);
            }
            //插入数据
            Soway.Data.Graphic.Graphic <IObjectProxy> proxyMaps = new Data.Graphic.Graphic <IObjectProxy>();
            foreach (var item in insertItems)
            {
                proxyMaps.Add(item);
                foreach (var ob in item.Model.Properties)
                {
                    if (item[ob] is IObjectProxy)
                    {
                        proxyMaps.AddEdge(item[ob] as IObjectProxy, item);
                    }
                }
            }

            while (proxyMaps.Nodes.Count > 0)
            {
                var ob = proxyMaps.GetTopNode();
                if (ob == null)
                {
                    ob = proxyMaps.Nodes[0].Data;
                }
                proxyMaps.Remove(ob);
                if (modelDb.IsExits(ob) == false)
                {
                    modelDb.Create(ob);
                }
                else
                {
                }
            }
        }
Beispiel #4
0
        public Soway.Model.App.Application CreatApp(Soway.Model.App.Application App)
        {
            var dbContext = new Soway.Model.SqlServer.ObjectContext <Soway.Model.App.Application>
                                (this.Con, this.ConFac);
            //1 创建应用

            var newApp = dbContext.Create(App);

            //2 创建应用系统库

            new Soway.Model.Manage.SqlServerModuleInstaller(this.ConFac).InstallModules
                (new Soway.Model.AssemblyModuleSource(
                    new Model.AssemblyModelFactory(typeof(Soway.Model.App
                                                          .Application))), App.SysCon, App.SysCon);


            new Soway.Model.Manage.SqlServerModuleInstaller(this.ConFac).InstallModules
                (new Soway.Model.AssemblyModuleSource(
                    new Model.AssemblyModelFactory(typeof(SOWAY.ORM.AUTH.AuthorizedUser))), App.SysCon, App.SysCon);
            //3 连接应用用户

            SOWAY.ORM.AUTH.AuthorizedUser user = new SOWAY.ORM.AUTH.AuthorizedUser();
            user.User = App.Creator;
            new Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.AuthorizedUser>(App.SysCon, this.ConFac).Create(user);
            var itemsStrs = new String[]
            {
                "Model列表", "Module列表", "SqlCon列表", "View列表", "MenuItem列表"
            };


            Dictionary <String, String> subItem = new Dictionary <string, string>();

            subItem.Add("Module列表", "业务包管理");
            subItem.Add("Model列表", "模型管理");
            subItem.Add("SqlCon列表", "连接管理");
            subItem.Add("View列表", "界面管理");
            subItem.Add("MenuItem列表", "菜单项管理");

            Dictionary <String, String> AuthItem = new Dictionary <string, string>();

            AuthItem.Add("AuthorizedUser列表", "授权用户管理");
            AuthItem.Add("Department列表", "部门管理");
            AuthItem.Add("Role列表", "角色管理");

            foreach (var db in App.DataBase)
            {   //4 创建应用数据库
                new Soway.Model.Manage.SqlServerModuleInstaller(this.ConFac).InstallModules
                    (new Soway.Model.AssemblyModuleSource(
                        new Model.AssemblyModelFactory(typeof(SOWAY.ORM.AUTH.User
                                                              ))), App.SysCon, db.Conection);
                //5 创建菜单
                SOWAY.ORM.AUTH.MenuItem item = new SOWAY.ORM.AUTH.MenuItem()
                {
                    Text = "系统管理", SubItems = new List <SOWAY.ORM.AUTH.MenuItem>()
                };
                foreach (var str in subItem.Keys)
                {
                    var view = new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).GetView(str);
                    view.ConnectionType = Model.ConnectionType.AppSys;

                    item.SubItems.Add(new SOWAY.ORM.AUTH.MenuItem()
                    {
                        Text   = subItem[str],
                        ViewID = (int)view.ID
                    });

                    new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).SaveView(view);
                }
                ;
                SOWAY.ORM.AUTH.MenuItem AuthMenu = new SOWAY.ORM.AUTH.MenuItem()
                {
                    Text     = "人员及权限",
                    SubItems = new List <SOWAY.ORM.AUTH.MenuItem>()
                };
                foreach (var str in AuthItem.Keys)
                {
                    var view = new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).GetView(str);
                    view.ConnectionType = Model.ConnectionType.AppSys;

                    AuthMenu.SubItems.Add(new SOWAY.ORM.AUTH.MenuItem()
                    {
                        Text   = AuthItem[str],
                        ViewID = (int)view.ID
                    });

                    new Soway.Model.View.AutoViewFactory(App.SysCon, this.ConFac).SaveView(view);
                }
                ;
                new
                Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.MenuItem>(App.SysCon, this.ConFac).Create(item);
                new
                Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.MenuItem>(App.SysCon, this.ConFac).Create(AuthMenu);
                //6 创建角色
                SOWAY.ORM.AUTH.Role role = new SOWAY.ORM.AUTH.Role()
                {
                    RoleName = "应用管理员"
                };
                role.Items = new List <SOWAY.ORM.AUTH.MenuItem>();
                role.Items.Add(item);
                foreach (var sub in item.SubItems)
                {
                    role.Items.Add(sub);
                }
                role.Items.Add(AuthMenu);
                role.Items.AddRange(AuthMenu.SubItems.ToArray());
                role.AuthUsers = new List <SOWAY.ORM.AUTH.AuthorizedUser>();
                role.AuthUsers.Add(user);

                new
                Soway.Model.SqlServer.ObjectContext <SOWAY.ORM.AUTH.Role>(App.SysCon, this.ConFac).Create(role);

                //7 给用户加入角色
            }
            return(newApp);
        }
Beispiel #5
0
        protected override void ImplementBusinessLogic()
        {
            var view = new Soway.Model.View.AutoViewFactory(this.Info.AppSqlCon, this).GetView(this.Opt.ViewId);

            var sqlCon     = GetViewSql(view);
            var fac        = new Soway.Model.Query.QueryFactory(this.Info.AppSqlCon, this);
            var queryModel = fac.GetQueryModel(view);
            var cxt        = new Soway.Query.QueryContext(fac, sqlCon.ToString());

            cxt.Add(queryModel.Table);
            cxt.Ins.BoolExp = new BoolExpAdapter(queryModel).GetQueryExp(this.Opt.FilterExp,
                                                                         queryModel, this.Info.AppSqlCon, cxt.Ins);
            new Soway.Query.QueryInsFac().RefreshQueryInsReportParam(cxt.Ins);
            foreach (var col in this.Opt.ReportCols)
            {
                var queryCol     = queryModel.Columns.First(p => p.ID == col.ColId);
                var selectedType = QueryCache.GetSelectedType(this.Info.AppSqlCon, queryCol.DataType);
                cxt.Ins.SelectedCols.Add(new Query.SelectedCol()
                {
                    DataCol       = queryModel.Columns.First(p => p.ID == col.ColId),
                    SelectType    = selectedType.First(p => p.ID.ToString() == col.SelectedTypeId),
                    SelectedIndex = col.Index,
                    SelectedName  = col.ColName,
                    OrderType     = col.OrderType,
                    SelectedTable = cxt.Ins.SelectedTables.Tables.First()
                });
            }



            var qresult = cxt.GetResult(sqlCon.ToString(), Opt.PageSize);

            qresult.CurrentPage = this.Opt.CurrentPage;
            var table = qresult.GetData();

            Soway.Report.ReportFactory rfac = new Soway.Report.ReportFactory();

            Soway.Report.TableFormat rfmt  = new Soway.Report.TableFormat();
            List <ReportCell>        cells = new List <ReportCell>();
            int row = 0;

            foreach (DataColumn column in table.Columns)
            {
                rfmt.ValueCell.Add(new Soway.Report.ValueCell
                {
                    SourceColumn = column.ColumnName,
                    Name         = column.ColumnName
                });
                cells.Add(new ReportCell()
                {
                    Col = 0, Row = row, ColSpan = 1, RowSpan = 1, FmtValue = column.ColumnName
                });
            }
            var matrix = new Soway.Report.Views.MatrixTableFactory().CreateMatrixTable(rfmt, table);

            foreach (var cell in matrix.Cells)
            {
                row++;
                foreach (var vcell in cell.Cells)
                {
                    cells.Add(new ReportCell()
                    {
                        Col      = 0,
                        Row      = row,
                        ColSpan  = 1,
                        RowSpan  = 1,
                        FmtValue = vcell.Value.ToString()
                    });
                }
            }


            result.CurrentPage  = Opt.CurrentPage;
            result.PageSize     = Opt.PageSize;
            result.TotalPages   = qresult.TotalPages;
            result.TotalRecords = qresult.TotalRecords;
            result.ViewId       = Opt.ViewId;
            result.Cells        = cells;
        }