Ejemplo n.º 1
0
        public async Task <PagedResultDto <ReportDataSourceOutputDto> > GetReportDataSources()
        {
            var entities = await _ReportDataSourceManager.GetAllReportDataSourcesAsync();

            var listDto = entities.MapTo <List <ReportDataSourceOutputDto> >();

            return(new PagedResultDto <ReportDataSourceOutputDto>(
                       listDto.Count,
                       listDto
                       ));
        }
Ejemplo n.º 2
0
        public async Task <List <DataSet> > GetDataSource(long template_Id, Dictionary <string, string> dicparamters)
        {
            var entityparamters = await _ReportParameterManager.GetAllReportParametersAsync();

            var paramters = entityparamters.Where(d => d.Template_Id == template_Id).OrderBy(d => d.Id);

            var entityDataSources = await _ReportDataSourceManager.GetAllReportDataSourcesAsync();

            var dataSources = entityDataSources.Where(d => d.Template_Id == template_Id).OrderBy(d => d.Id);

            List <DataSet> listDs = new List <DataSet>();

            foreach (var dataSource in dataSources)
            {
                string sql  = dataSource.CommandText;
                string conn = ConfigurationManager.ConnectionStrings[dataSource.ConnkeyName].ConnectionString;

                //List<string> resultP = GetParamsBySql(sql);
                List <string> resultP = GetParamsByStr(dataSource.DataParams);

                OracleParameter[] paras = new OracleParameter[resultP.Count];
                for (int i = 0; i < resultP.Count; i++)
                {
                    var dataParam = paramters.Where(p => p.ParameterName.ToUpper() == resultP[i].ToUpper());
                    if (dataParam.Count() == 0)
                    {
                        continue;
                    }

                    string val = string.Empty;

                    if (dicparamters.Keys.Contains(resultP[i]))
                    {
                        val = dicparamters[resultP[i]];
                    }


                    #region 判断类型
                    switch (dataParam.First().ParamterType)
                    {
                    case (int)ReportDefine.ParamterTypes.字符型:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = val
                        };
                        break;

                    case (int)ReportDefine.ParamterTypes.整型:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = Convert.ToInt32(val)
                        };
                        break;

                    case (int)ReportDefine.ParamterTypes.浮点型:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = Convert.ToDecimal(val)
                        };
                        break;

                    case (int)ReportDefine.ParamterTypes.日期型:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = val == "#sysDate#" ? DateTime.Now : Convert.ToDateTime(val)
                        };
                        break;

                    case (int)ReportDefine.ParamterTypes.布尔型:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = Convert.ToBoolean(val)
                        };
                        break;

                    case (int)ReportDefine.ParamterTypes.Guid型:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = new Guid(val)
                        };
                        break;

                    default:
                        paras[i] = new OracleParameter
                        {
                            ParameterName = resultP[i],
                            Value         = val
                        };
                        break;
                    }
                    #endregion
                }
                var dataSet = OracleDbHelper.ExecuteDataset(conn,
                                                            sql,
                                                            dataSource.CommandType == 1 ? System.Data.CommandType.Text : System.Data.CommandType.StoredProcedure,
                                                            paras);
                dataSet.Tables[0].TableName = "dt_" + dataSource.TableName;
                dataSet.DataSetName         = "ds_" + dataSource.TableName;
                listDs.Add(dataSet);
            }
            return(await Task.FromResult(listDs));
        }