Beispiel #1
0
        public ActionResult EditDbServer(long dbServerId)
        {
            var server = _dbServerService.GetDbServer(dbServerId);

            ViewBag.DbType = _dbTypeAppService.GetDropDownList();
            var model = server == null ? new DbServerInput() :
                        AutoMapper.Mapper.Map <DbServerInput>(
                AutoMapper.Mapper.Map <Domain.DbServer>(server));

            return(View("Easyman.FwWeb.Views.DbServer.EditDbServer", model));
        }
Beispiel #2
0
        public ActionResult EditImpTb(long?id)
        {
            ViewBag.ImpType  = _impTypeAppService.GetDropDownList();
            ViewBag.DbServer = _dbServerAppService.GetDropDownList();
            ViewBag.DbType   = _dbTypeAppService.GetDropDownList();
            ViewBag.Rule     = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "以日期后缀创建表", Value = "1"
                },
                new SelectListItem()
                {
                    Text = "以指定表名创建表", Value = "2"
                },
                new SelectListItem()
                {
                    Text = "以用户后缀创建表", Value = "3"
                },
                new SelectListItem()
                {
                    Text = "自定义后缀创建表", Value = "4"
                }
            };
            var sql  = "";
            var data = new ImpTbInput();

            if (id != null)
            {
                data = _impTbAppService.Get(id.Value);
                data.DefaultFields = _impTbAppService.GetIds(id.Value);
                try
                {
                    var dbServer = _dbServerAppService.GetDbServer(data.DbServerId);
                    var dbType   = _dbTypeAppService.Get(a => a.Name == dbServer.DbTypeName);
                    data.DbTypeId = dbType.Id;
                }
                catch { }
                sql = data.Sql;
            }
            ViewBag.Sql = sql;
            return(View("Easyman.FwWeb.Views.Import.EditImpTb", data));
        }
Beispiel #3
0
        public string GetDBType(long id)
        {
            var server = _dbServerService.GetDbServer(id);

            return(Newtonsoft.Json.JsonConvert.SerializeObject(server.DbTypeId));
        }
Beispiel #4
0
        /// <summary>
        /// 根据code代码及传入条件拼凑和执行sql
        /// </summary>
        /// <param name="code"></param>
        /// <param name="rows"></param>
        /// <param name="page"></param>
        /// <param name="queryParams"></param>
        /// <param name="sidx"></param>
        /// <param name="sord"></param>
        /// <param name="err"></param>
        /// <returns></returns>
        public string ExcuteReportSql(string code, int rows, int page, string queryParams, string sidx, string sord, ref ErrorInfo err)
        {
            if (!string.IsNullOrEmpty(code))
            {
                var ent = _reportRepository.FirstOrDefault(p => p.Code == code);
                if (ent != null)
                {
                    string    dbType   = "";              //数据库种类
                    int       records  = 0;               //总数量
                    DataTable endTable = new DataTable(); //查询结果

                    #region 获取数据库
                    DbServerOutput dbServer = new DbServerOutput();
                    //中心库
                    if (ent.DbServerId == null)
                    {
                        var connection = ConnectionMsg.GetCurConnection();//获取当前承载库连接信息
                        dbType   = connection.DbType.ToString();
                        dbServer = null;
                    }
                    else
                    {
                        dbServer = _dbServerApp.GetDbServer(ent.DbServerId.Value);
                        dbType   = dbServer.DbTypeName;
                        if (dbServer == null)
                        {
                            err.IsError = true;
                            err.Message = "未找到当前code对应的数据库编号[" + ent.DbServerId.Value + "]!";
                            return("");
                        }
                    }
                    #endregion

                    //替换全局变量
                    string sql = ReplaceGlobalVar(ent.Sql);
                    //替换变量(内置或自定义、外置)
                    sql = ReplaceDefaultValue(sql, queryParams);
                    //当IsPlaceholder==true时,拼凑查询筛选条件
                    if (ent.IsPlaceholder == null || !ent.IsPlaceholder.Value)
                    {
                        sql = AnalysisParam(dbType, sql, queryParams);
                    }
                    sql = SqlForOrder(sql, sidx, sord);                            //生成排序sql
                    string sqlPage = SqlForPage(dbType, sql, page, rows, ref err); //拼凑分页sql

                    //获取总数
                    string sqlC = string.Format(@"select count(1) from ({0})", sql);
                    if (dbServer != null)
                    {
                        //记录总数
                        object num = _dbServerApp.ExecuteScalar(ent.DbServerId.Value, sqlC, ref err);
                        records  = Convert.ToInt32(num);
                        endTable = _dbServerApp.ExecuteGetTable(ent.DbServerId.Value, sqlPage);
                    }
                    else//根据承载库查询
                    {
                        try
                        {
                            object num = DbHelper.ExecuteScalar(sqlC);
                            records  = Convert.ToInt32(num);
                            endTable = DbHelper.ExecuteGetTable(sqlPage);
                        }
                        catch (Exception ex)
                        {
                            err.IsError = true;
                            err.Message = "查询数据错误:" + ex.Message;
                            return("");
                        }
                    }
                    //拼凑json串
                    string result = "{\"records\":" + records + ",\"page\":" + page + ",\"total\":" + Math.Ceiling(decimal.Divide(records, rows)) + ",\"rows\":" + JSON.DecodeToStr(endTable) + "}";
                    return(result);
                }
                else
                {
                    err.IsError = true;
                    err.Message = "未找到编号为[" + code + "]的报表!";
                }
            }
            else
            {
                err.IsError = true;
                err.Message = "传入的代码不能为空!";
            }
            return("");
        }