Esempio n. 1
0
        /// <summary>
        /// 测试oracle数据库连接
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public JObject JoinOracle(HttpContext context)
        {
            JObject     obj     = new JObject();
            YZRequest   request = new YZRequest(context);
            OracleLogin login   = new OracleLogin();

            login.systemName = request.GetString("systemName");
            login.host       = request.GetString("host");
            login.port       = request.GetString("port");
            login.user       = request.GetString("user");
            login.pwd        = request.GetString("pwd");
            string message = null;
            bool   flag    = CommonHandle.IsOracleJoin(login, out message);

            obj[YZJsonProperty.success]      = true;
            obj[YZJsonProperty.errorMessage] = flag ? "连接成功!" : String.Format("连接失败!原因:<br/>{0}", message);
            return(obj);
        }
Esempio n. 2
0
        /// <summary>
        /// 保存数据源
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public JObject SaveSource(HttpContext context)
        {
            JObject obj = new JObject();

            try
            {
                YZRequest request = new YZRequest(context);
                //操作类型
                string joinType   = request.GetString("joinType");
                string sourceName = request.GetString("sourceName");
                string caption    = request.GetString("caption", "");
                int    connectId  = request.GetInt32("connectId");
                int    sourceId   = request.GetInt32("sourceId", 0);
                string queryStr   = request.GetString("queryStr");
                //判断是否重名
                bool isNameOnly = SourceInfoManager.IsSourceNameRepeat(sourceName, SourceTypeEnum.Oracle, sourceId);
                if (isNameOnly)
                {
                    obj[YZJsonProperty.success]      = false;
                    obj[YZJsonProperty.errorMessage] = "已存在同名的数据源,请重命名数据源名称!";
                    return(obj);
                }
                //执行
                ConnectInfo     con    = ConnectInfoManager.GetConnectInfo(connectId);
                OracleLogin     login  = JObject.Parse(con.connectStr).ToObject <OracleLogin>();
                ISourceHandle   handle = new OracleHandle(login);
                QueryDepictInfo info   = new QueryDepictInfo();
                info.query = queryStr;

                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;
                    if (parameterArray != null && parameterArray.Count > 0)
                    {
                        List <ColumnInfo> paramList = new List <ColumnInfo>();
                        foreach (var item in parameterArray)
                        {
                            ColumnInfo column = new ColumnInfo();
                            column.columnName   = item["columnName"].ToString();
                            column.rename       = item["rename"].ToString();
                            column.isShow       = item["isShow"].ToString().ToUpper().Equals("TRUE") ? 1 : 0;
                            column.defaultValue = item["defaultValue"].ToString();
                            paramList.Add(column);
                        }
                        info.parameter = paramList;
                    }

                    JArray schemaArray = jo["schema"] as JArray;
                    if (schemaArray != null && schemaArray.Count > 0)
                    {
                        List <ColumnInfo> schemaList = new List <ColumnInfo>();
                        foreach (var item in schemaArray)
                        {
                            ColumnInfo column = new ColumnInfo();
                            column.columnName   = item["columnName"].ToString();
                            column.rename       = item["rename"].ToString();
                            column.isShow       = item["isShow"].ToString().ToUpper().Equals("TRUE") ? 1 : 0;
                            column.defaultValue = item["defaultValue"].ToString();
                            schemaList.Add(column);
                        }
                        info.schema = schemaList;
                    }
                }
                if (joinType.ToUpper().Equals("THEEDIT"))
                {
                    SourceInfo sourceInfo = SourceInfoManager.GetSourceInfo(sourceId);
                    sourceInfo.sourceName = sourceName;
                    sourceInfo.caption    = caption;
                    sourceInfo.updateTime = DateTime.Now;
                    sourceInfo.sourceStr  = JObject.FromObject(info).ToString();
                    SourceInfoManager.EditSource(sourceInfo);
                }
                else
                {
                    SourceInfo sourceInfo = new SourceInfo();
                    sourceInfo.sourceName  = sourceName;
                    sourceInfo.sourceType  = SourceTypeEnum.Oracle;
                    sourceInfo.connectInfo = ConnectInfoManager.GetConnectInfo(connectId);
                    sourceInfo.caption     = caption;
                    sourceInfo.isvalid     = true;
                    sourceInfo.createTime  = DateTime.Now;
                    sourceInfo.updateTime  = DateTime.Now;
                    sourceInfo.sourceStr   = JObject.FromObject(info).ToString();
                    SourceInfoManager.AddSource(sourceInfo);
                }
                obj[YZJsonProperty.success]      = true;
                obj[YZJsonProperty.errorMessage] = "保存成功";
                return(obj);
            }
            catch (Exception ex)
            {
                obj[YZJsonProperty.success]      = false;
                obj[YZJsonProperty.errorMessage] = ex.Message.ToString();
                return(obj);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 执行sql语句返回值
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public JObject RunSql(HttpContext context)
        {
            JObject obj = new JObject();

            try
            {
                YZRequest       request  = new YZRequest(context);
                string          queryStr = request.GetString("queryStr");
                QueryDepictInfo info     = new QueryDepictInfo();
                info.query = queryStr;
                StreamReader reader = new StreamReader(context.Request.InputStream);
                using (JsonTextReader streamReader = new JsonTextReader(reader))
                {
                    //获取参数配置
                    JsonSerializer serializer = new JsonSerializer();
                    JArray         array      = serializer.Deserialize(streamReader) as JArray;

                    if (array != null && array.Count > 0)
                    {
                        List <ColumnInfo> paramList = new List <ColumnInfo>();
                        foreach (var item in array)
                        {
                            ColumnInfo column = new ColumnInfo();
                            column.columnName   = item["columnName"].ToString();
                            column.rename       = item["rename"].ToString();
                            column.isShow       = item["isShow"].ToString().ToUpper().Equals("TRUE") ? 1 : 0;
                            column.defaultValue = item["defaultValue"].ToString();
                            paramList.Add(column);
                        }
                        info.parameter = paramList;
                    }
                    //执行
                    int           connectId = request.GetInt32("connectId");
                    ConnectInfo   con       = ConnectInfoManager.GetConnectInfo(connectId);
                    OracleLogin   login     = JObject.Parse(con.connectStr).ToObject <OracleLogin>();
                    ISourceHandle handle    = new OracleHandle(login);
                    DataTable     dt        = handle.GetResult(info);
                    if (dt == null)
                    {
                        obj[YZJsonProperty.success]      = false;
                        obj[YZJsonProperty.errorMessage] = "没有可供查询的结果!";
                        return(obj);
                    }
                    //保存输出参数
                    List <ColumnInfo> schemaList = new List <ColumnInfo>();
                    foreach (DataColumn item in dt.Columns)
                    {
                        schemaList.Add(new ColumnInfo()
                        {
                            columnName = item.ColumnName,
                            rename     = item.ColumnName,
                            columnType = item.DataType.Name,
                            isShow     = 1
                        });
                    }
                    info.schema = schemaList;

                    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);
                        }
                        obj["children"] = results;
                    }
                    else
                    {
                        JObject item = new JObject();
                        foreach (DataColumn column in dt.Columns)
                        {
                            item[column.ColumnName] = "";
                        }
                        results.Add(item);
                        obj["children"] = results;
                    }
                    obj["children"] = results;
                    //执行数据
                    obj[YZJsonProperty.success] = true;
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                obj[YZJsonProperty.success]      = false;
                obj[YZJsonProperty.errorMessage] = ex.Message.ToString();
                return(obj);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 保存oracle数据连接
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public JObject SaveOracleConnect(HttpContext context)
        {
            JObject   obj     = new JObject();
            YZRequest request = new YZRequest(context);

            try
            {
                //获取操作模式
                string joinType = request.GetString("joinType");
                //获取连接数据
                OracleLogin login = new OracleLogin();
                login.systemName = request.GetString("systemName");
                login.host       = request.GetString("host");
                login.port       = request.GetString("port");
                login.user       = request.GetString("user");
                login.pwd        = request.GetString("pwd");
                string message = null;
                if (!CommonHandle.IsOracleJoin(login, out message))
                {
                    obj[YZJsonProperty.success]      = false;
                    obj[YZJsonProperty.errorMessage] = "服务无法连接!";
                    return(obj);
                }
                if (joinType.ToUpper().Equals("THEEDIT"))
                {
                    //编辑模式
                    ConnectInfo info = ConnectInfoManager.GetConnectInfo(request.GetInt32("connectId", -1));
                    info.caption    = request.GetString("caption", "");
                    info.connectStr = JObject.FromObject(login).ToString();
                    info.updateTime = DateTime.Now;
                    info.isvalid    = true;
                    //更新
                    ConnectInfoManager.EditConnect(info);
                    obj["connectId"] = info.connectId;
                }
                else
                {
                    //新增模式
                    if (ConnectInfoManager.IsConnectRepeat(request.GetString("connectName", ""), SourceTypeEnum.Oracle))
                    {
                        obj[YZJsonProperty.success]      = false;
                        obj[YZJsonProperty.errorMessage] = "已存在同名的数据源";
                        return(obj);
                    }
                    ConnectInfo info = new ConnectInfo();
                    info.connectName = request.GetString("connectName", "");
                    info.connectType = SourceTypeEnum.Oracle;
                    info.caption     = request.GetString("caption", "");
                    info.connectStr  = JObject.FromObject(login).ToString();
                    info.createTime  = DateTime.Now;
                    info.updateTime  = DateTime.Now;
                    info.isvalid     = true;
                    //新增
                    ConnectInfoManager.AddConnect(info);
                    obj["connectId"] = ConnectInfoManager.GetConnectInfo(SourceTypeEnum.Oracle, info.connectName).connectId;
                }
                obj[YZJsonProperty.success]      = true;
                obj[YZJsonProperty.errorMessage] = "数据连接保存成功";
                return(obj);
            }
            catch (Exception ex)
            {
                string msg = string.Format("保存失败:{0}", ex.ToString());
                obj[YZJsonProperty.success]      = false;
                obj[YZJsonProperty.errorMessage] = msg;
                return(obj);
            }
        }