<%@ WebHandler Language="C#" Class="Service" %> using System; using System.Web; using System.Data; public class Service : IHttpHandler { public void ProcessRequest (HttpContext c) { c.Response.ContentType = "text/plain"; string sysCode=c.Request.Params["sysCode"].ToString();//系统名称 string interfaceCode = c.Request.Params["interfaceCode"].ToString();//接口名 string interfacePara = c.Request.Params["interfacePara"].ToString();//接口参数|号分割 string strConnect = GetstrConnectBysysCode(sysCode); string SQLStr=GetSQLByinterfaceCode(sysCode,interfaceCode,interfacePara); string ReturnStr = Generating_interface(strConnect, SQLStr); c.Response.Write(ReturnStr); } /// <summary> /// 根据数据库连接和SQL语句返回数据 /// </summary> /// <param name="strConnect"></param> /// <param name="strSQL"></param> public string Generating_interface(string strConnect, string strSQL) { DataTable dt = DataBase.ExecuteTable(strConnect, System.Data.CommandType.Text, strSQL, null); return DataSetJson.DataTableJson(dt); } /// <summary> /// 根据系统名和接口名称,得到查询的SQL语句 /// </summary> /// <param name="sysCode">系统名</param> /// <param name="interfaceCode">接口名称</param> /// <param name="interfaceCode">接口参数</param> public string GetSQLByinterfaceCode(string sysCode, string interfaceCode, string interfacePara) { string str = DataBase.Exec("select Inte_SQL from bill_sysinterface where inte_sysCode = '" + sysCode + "' and Inte_code='" + interfaceCode + "'"); return str; } /// <summary> /// 根据系统名得到数据库连接字符串 /// </summary> /// <param name="sysCode">系统名</param> /// <returns></returns> public string GetstrConnectBysysCode(string sysCode) { string str = DataBase.Exec("select sys_ConnStr from bill_sysconnect where sys_Code = '" + sysCode +"'"); return str; } public bool IsReusable { get { return false; } } }
2 建库脚本
USE [master] GO /****** Object: Database [Test] Script Date: 2017-8-11 16:44:34 ******/ CREATE DATABASE [Test] USE [Test] GO /****** Object: Table [dbo].[bill_sysconnect] Script Date: 2017-8-11 16:44:34 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[bill_sysconnect]( [id] [int] IDENTITY(1,1) NOT NULL, [sys_Name] [nvarchar](200) NULL, [sys_ConnStr] [nvarchar](200) NULL, [sys_Code] [nvarchar](200) NULL, CONSTRAINT [PK_Bill_sysconnect] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[bill_sysinterface] Script Date: 2017-8-11 16:44:34 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[bill_sysinterface]( [id] [int] IDENTITY(1,1) NOT NULL, [Inte_sysName] [nvarchar](200) NULL, [Inte_Name] [nvarchar](200) NULL, [Inte_SQL] [nvarchar](500) NULL, [Inte_sysCode] [nvarchar](200) NULL, [Inte_Code] [nvarchar](200) NULL, CONSTRAINT [PK_bill_sysinterface] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET IDENTITY_INSERT [dbo].[bill_sysconnect] ON INSERT [dbo].[bill_sysconnect] ([id], [sys_Name], [sys_ConnStr], [sys_Code]) VALUES (1, N'南大宿管83', N'server=.;database=hdj_ndgy;uid=sa;pwd=123456', N'hdj_ndgy') SET IDENTITY_INSERT [dbo].[bill_sysconnect] OFF SET IDENTITY_INSERT [dbo].[bill_sysinterface] ON INSERT [dbo].[bill_sysinterface] ([id], [Inte_sysName], [Inte_Name], [Inte_SQL], [Inte_sysCode], [Inte_Code]) VALUES (1, N'南大宿管83', N'查询员工表前10条数据的员工编号和员工姓名', N'select top 10 worker_name,worker_code from base_worker', N'hdj_ndgy', N'base_workerTop10') SET IDENTITY_INSERT [dbo].[bill_sysinterface] OFF USE [master] GO ALTER DATABASE [Test] SET READ_WRITE GO