【机房重构】——存储过程

【机房重构】——存储过程_第1张图片

【机房重构】——存储过程_第2张图片 

D层

public DataTable GroupQuery(Entity.GroupQuery group)
        {
            SqlHelper sqlHelper = new SqlHelper();
            //存储过程
            string sql = @"PROC_GroupQuery";
            SqlParameter[] sqlParams={
                                         new SqlParameter("@comboBox1",group.comboBox1),
                                         new SqlParameter("@comboBox2",group.comboBox2),
                                         new SqlParameter("@comboBox3",group.comboBox3),
                                         new SqlParameter("@comboBox4",group.comboBox4),
                                         new SqlParameter("@comboBox5",group.comboBox5),
                                         new SqlParameter("@comboBox6",group.comboBox6),
                                         new SqlParameter("@comboBox7",group.comboBox7),
                                         new SqlParameter("@comboBox8",group.comboBox8),
                                         new SqlParameter("@textBox1",group.textBox1),
                                         new SqlParameter("@textBox2",group.textBox2),
                                         new SqlParameter("@textBox3",group.textBox3),
                                         new SqlParameter("@GetDBName",group.GetDBName)
                                     };
            //存储过程
            DataTable table = sqlHelper.ExecuteQuery(sql, sqlParams, CommandType.StoredProcedure);
            return table;
        }

SQL

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<张文慧>
-- Create date: <2018-10-14>
-- Description:	<注册时和数据库的交互>
-- =============================================
ALTER PROCEDURE [dbo].[Proc_Register]

	-- Add the parameters for the stored procedure here 所需要的参数
	@cardNo varchar(20),
	@studentName varchar(20),
	@sex char(10),
	@department varchar(20),
	@grade varchar(50),
	@specialty varchar(50),
	@balance numeric(10,2),
	@UserID varchar(20),
	@PWD varchar(20),
	@RechargeCash numeric(10,2)
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- 添加记录给Student表
    insert into Student(cardNo,studentName,sex,department,grade,specialty,balance,UserID,state,Ischeck)values(@cardNo,@studentName,@sex,@department,@grade,@specialty,@balance,@UserID,'True','False')
    
    --添加记录给User_Info表
    insert into User_Info(UserID,PWD,Level,UserName,state)values(@cardNo,@PWD,'学生',@studentName,'True')
    
    --添加记录给ReCharge表
    insert into ReCharge(cardNo,RechargeCash,Balance,UseID,Ischeck)values(@cardNo,@RechargeCash,@RechargeCash,@UserID,'False')
    
END
USE [charge_sys]
GO
/****** Object:  StoredProcedure [dbo].[PROC_GroupQuery]    Script Date: 2018/11/12 9:01:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		张文慧
-- Create date: 2018—11—8
-- Description:	组合查询时候进行数据交互
-- =============================================
ALTER PROCEDURE [dbo].[PROC_GroupQuery]  
/****需要传递的参数****/
@cboFiled1 varchar(20),
@cboFiled2 varchar(20),
@cboFiled3 varchar(20),
@cboMark1 varchar(10),
@cboMark2 varchar(10),
@cboMark3 varchar(10),
@Content1 varchar(20),
@Content2 varchar(20),
@Content3 varchar(20),
@Relationship1 varchar(10),
@Relationship2 varchar(10),
@DbtableName varchar(20)
AS
	declare @TempSql varchar(500)
BEGIN
	SET @TempSql='SELECT * FROM '+@DbtableName+' WHERE '+@cboFiled1+@cboMark1+char(39)+@Content1+char(39)
	if(@Relationship1!='')
	BEGIN
		SET @TempSql=@TempSql+@Relationship1+CHAR(32)+@cboFiled2+@cboMark2+char(39)+@Content2+char(39)
		if(@Relationship2!='')
		BEGIN
		SET @TempSql=@TempSql+@Relationship2+CHAR(32)+@cboFiled3+@cboMark3+char(39)+@Content3+char(39)
		END
    END
ExECUTE(@TempSql)
END

 

你可能感兴趣的:(C/S)