Exemplo n.º 1
0
        /// <summary>
        /// 返回访问结果
        /// </summary>
        /// <param name="info"></param>
        /// <param name="connect"></param>
        /// <returns></returns>
        private DataTable GetResult(QueryDepictInfo info, ConnectInfo connect)
        {
            ISourceHandle handle = null;

            switch (connect.connectType)
            {
            case SourceTypeEnum.Excel:
                handle = new ExcelHandle(JObject.Parse(connect.connectStr).ToObject <ExcelLogin>());
                break;

            case SourceTypeEnum.Oracle:
                handle = new OracleHandle(JObject.Parse(connect.connectStr).ToObject <OracleLogin>());
                break;

            case SourceTypeEnum.SAP:
                handle = new SapHandle(JObject.Parse(connect.connectStr).ToObject <SapLogin>());
                break;

            case SourceTypeEnum.SqlServer:
                handle = new SqlServerHandle(JObject.Parse(connect.connectStr).ToObject <SqlServerLogin>());
                break;

            case SourceTypeEnum.WebService:
                handle = new WebServiceHandle(JObject.Parse(connect.connectStr).ToObject <WebServiceLogin>());
                break;

            default:
                break;
            }
            DataTable dt = new DataTable();

            if (handle != null)
            {
                dt = handle.GetResult(info);
            }
            return(dt);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 返回结果集
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public JObject GetResult(HttpContext context)
        {
            JObject obj = new JObject();

            try
            {
                YZRequest request = new YZRequest(context);
                //获取数据连接信息
                int             connectId = request.GetInt32("connectId");
                ConnectInfo     con       = ConnectInfoManager.GetConnectInfo(connectId);
                WebServiceLogin login     = JObject.Parse(con.connectStr).ToObject <WebServiceLogin>();
                ISourceHandle   handle    = new WebServiceHandle(login);
                //获取接口信息
                string          functionName = request.GetString("functionName");
                QueryDepictInfo info         = handle.GetQueryInfo(functionName);

                //获取输入输出参数配置
                StreamReader reader = new StreamReader(context.Request.InputStream);
                using (JsonTextReader streamReader = new JsonTextReader(reader))
                {
                    //获取参数配置
                    JsonSerializer serializer     = new JsonSerializer();
                    JArray         array          = serializer.Deserialize(streamReader) as JArray;
                    JObject        jo             = array[0] as JObject;
                    JArray         parameterArray = jo["parameter"] as JArray;
                    //清空输入参数原始值
                    CommonHandle.ClearParameter(info.parameter);
                    //配置输入参数值
                    foreach (JObject item in parameterArray)
                    {
                        ColumnInfo column = info.parameter.First(n => n.columnName == item["columnName"].ToString());
                        SetParameterValue(column, item);
                    }
                    //判断输出参数是否为无法识别类型
                    if (CommonHandle.IsSchemaNoType(info.schema))
                    {
                        info = handle.GetQueryInfo(info);
                    }
                    JArray schemaArray = jo["schema"] as JArray;
                    //清空输出参数原始值
                    CommonHandle.ClearParameter(info.schema);
                    //配置输出参数值
                    foreach (JObject item in schemaArray)
                    {
                        ColumnInfo columnInfo = info.schema.First(n => n.columnName == item["columnName"].ToString());
                        SetOutputInfo(columnInfo, item);
                    }
                }

                //获取运行结果
                DataTable dt      = handle.GetResult(info);
                JArray    results = new JArray();
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        JObject item = new JObject();
                        foreach (DataColumn column in dt.Columns)
                        {
                            item[column.ColumnName] = row[column.ColumnName].ToString();
                        }
                        results.Add(item);
                    }
                }
                else
                {
                    JObject item = new JObject();
                    foreach (DataColumn column in dt.Columns)
                    {
                        item[column.ColumnName] = "";
                    }
                    results.Add(item);
                }
                obj["children"] = results;
                //执行数据
                obj[YZJsonProperty.success] = true;
                return(obj);
            }
            catch (Exception ex)
            {
                obj[YZJsonProperty.success]      = false;
                obj[YZJsonProperty.errorMessage] = ex.Message;
                return(obj);
            }
        }