Beispiel #1
0
 /// <summary>
 /// 在指定库中根据filterId获取下拉键值集合(code所在数据库)
 /// </summary>
 /// <param name="dictTypeName">字典类型名称</param>
 /// <returns></returns>
 public string GetFilterDropDown(long?filterId, string code)
 {
     if (filterId != null)
     {
         var report = _reportAppService.GetReportBase(code);
         var ft     = _tbReportAppService.GetFilter(filterId.Value);
         if (ft != null)
         {
             DataTable table = new DataTable();
             //默认的承载库
             if (report.DbServerId == null || report.DbServerId == 0)
             {
                 table = DbHelper.ExecuteGetTable(ft.FilterSql);
             }
             else//指定库
             {
                 table = _dbServerAppService.ExecuteGetTable(report.DbServerId.Value, ft.FilterSql);
             }
             if (table != null && table.Rows.Count > 0)
             {
                 return(Fun.DataTable2Json(table));
             }
         }
     }
     return("[]");
 }
Beispiel #2
0
        public string OnlineExportData(ExportDataModel exp)
        {
            EasyMan.Dtos.ErrorInfo err = new EasyMan.Dtos.ErrorInfo();
            err.IsError = false;
            try
            {
                //非压缩导出
                string strFileName = exp.FileName;
                //lngDbServerId = (long)exp.DbServerId;
                strMapPathAll = "";
                strPathAll    = "";
                string strPath = exp.FilePath;
                Easyman.Common.Fun.GetPath(ref strFileName, exp.FileFormat, ref strMapPathAll, ref strPath);//重新整理保存路径

                #region 表结果dt
                DataTable dt = new DataTable();
                if (exp.DbServerId == null)
                {
                    dt = DbHelper.ExecuteGetTable(exp.Sql);
                }
                else
                {
                    dt = _dbServerAppService.ExecuteGetTable((int)exp.DbServerId, exp.Sql); //要导出的数据集
                }
                #endregion

                string ColumnHeader = "";
                switch (exp.FileFormat.ToLower())
                {
                case ".xlsx":
                    ColumnHeader = GetHeadStr(exp.TopFields);    //将表头对像转成字符串
                    OutExcelHelper.ExportExcel(dt, strFileName, strMapPathAll, ColumnHeader, true);
                    break;

                case ".csv":
                    OutExcelHelper.ExportCsv(dt, strFileName, strMapPathAll, ColumnHeader, true);
                    break;

                case ".txt":
                    OutExcelHelper.ExportTxt(dt, strFileName, strMapPathAll, ColumnHeader, true);
                    break;

                default:
                    ColumnHeader = GetHeadStr(exp.TopFields);    //将表头对像转成字符串
                    OutExcelHelper.ExportExcel(dt, strFileName, strMapPathAll, ColumnHeader, true);
                    break;
                }
                exp.FileName += exp.FileFormat;
                SavaDBSql(strPath, strMapPathAll, exp);
                return(strPath);
            }
            catch (Exception ex)
            {
                err.IsError = true;
                err.Message = ex.Message;
                throw;
            }
        }
Beispiel #3
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("");
        }