-- ==============================
-- 长登科技 www.ppfor.com
-- 唐镇波   2010-04-19
-- ------------------------------
-- 支付方式表
-- ==============================

--创建支付方式表
if not exists (select * from sysobjects where name='PPFOR_TZB_Payment')
CREATE TABLE [PPFOR_TZB_Payment] (
	[ID] int IDENTITY (1, 1) NOT NULL PRIMARY KEY,
	[Name] nvarchar (50) COLLATE Chinese_PRC_CS_AS NOT NULL unique,
	[Type] int  not null REFERENCES [PPFOR_TZB_PaymentType]([ID]) ON DELETE CASCADE,
	[IsFix] bit not null,
	[Rate] decimal (10,4) NOT NULL,	
	[FixMoney] money not null,
	[Status] bit not null, 
	[Order] int not null,
	[Description] text null,
	[Args1] int not null default(-1),
	[Args2] int not null default(-1),	
	[Args3] int not null default(-1),
	[Args4] int not null default(-1),
	[Args5] varchar(50) null,
	[Args6] varchar(50) null,
	[Args7] varchar(50) null,
	[Args8] varchar(50) null,
	[Args9] varchar(150) null,
	[Args10] varchar(150) null,
	[Args11] varchar(150) null,
	[Args12] varchar(150) null,
	[Args13] text null
)
PPFOR_GO;	

--是否存在支付方式
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_IsExists' and type='P')
	drop procedure [PPFOR_TZB_Payment_IsExists]
PPFOR_GO;
create procedure PPFOR_TZB_Payment_IsExists(@Name nvarchar(50),@retValue bit out)
as
	if exists (select [ID] from [PPFOR_TZB_Payment] where [Name]=@Name)
		set @retValue=1
	else
		set @retValue=0
PPFOR_GO;

--添加支付方式
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_Add' and type='P')
	drop procedure [PPFOR_TZB_Payment_Add]
PPFOR_GO;
create procedure PPFOR_TZB_Payment_Add(@ID int out,@Name nvarchar(50),@Type int,@IsFix bit,
	@Rate decimal (10,4),@FixMoney money,@Status bit,@Order int,@Description text,@Args1 int,@Args2 int,
	@Args3 int,@Args4 int,@Args5 varchar(50),@Args6 varchar(50),@Args7 varchar(50),@Args8 varchar(50),
	@Args9 varchar(150),@Args10 varchar(150),@Args11 varchar(150),@Args12 varchar(150),@Args13 text)
as
	begin
		insert into [PPFOR_TZB_Payment] ([Name],[Type],[IsFix],[Rate],[FixMoney],[Status],[Order],
			[Description],[Args1],[Args2],[Args3],[Args4],[Args5],[Args6],[Args7],[Args8],[Args9],
			[Args10],[Args11],[Args12],[Args13]) values (@Name,@Type,@IsFix,@Rate,@FixMoney,@Status,
			@Order,@Description,@Args1,@Args2,@Args3,@Args4,@Args5,@Args6,@Args7,@Args8,@Args9,
			@Args10,@Args11,@Args12,@Args13)
		if @@ROWCOUNT>0
			set @ID=@@IDENTITY
		else 
			set @ID=0
	end
PPFOR_GO;

--更新支付方式
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_Update' and type='P')
	drop procedure [PPFOR_TZB_Payment_Update]
PPFOR_GO;
create procedure PPFOR_TZB_Payment_Update(@ID int,@Name nvarchar(50),@Type int,@IsFix bit,
	@Rate decimal (10,4),@FixMoney money,@Status bit,@Order int,@Description text,@Args1 int,@Args2 int,
	@Args3 int,@Args4 int,@Args5 varchar(50),@Args6 varchar(50),@Args7 varchar(50),@Args8 varchar(50),
	@Args9 varchar(150),@Args10 varchar(150),@Args11 varchar(150),@Args12 varchar(150),@Args13 text)
as
	begin
		update [PPFOR_TZB_Payment] set [Name]=@Name,[IsFix]=@IsFix,[Rate]=@Rate,[FixMoney]=@FixMoney,
			[Status]=@Status,[Order]=@Order,[Description]=@Description,[Args1]=@Args1,[Args2]=@Args2,
			[Args3]=@Args3,[Args4]=@Args4,[Args5]=@Args5,[Args6]=@Args6,[Args7]=@Args7,[Args8]=@Args8,
			[Args9]=@Args9,[Args10]=@Args10,[Args11]=@Args11,[Args12]=@Args12,[Args13]=@Args13 
		where [ID]=@ID 
	end
PPFOR_GO;

--列表更新支付方式
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_UpdateList' and type='P')
	drop procedure [PPFOR_TZB_Payment_UpdateList]
PPFOR_GO;
create procedure PPFOR_TZB_Payment_UpdateList(@ID int,@Status bit,@Order int)
as
	begin
		update [PPFOR_TZB_Payment] set [Status]=@Status,[Order]=@Order
			where [ID]=@ID
	end
PPFOR_GO;

--删除支付方式
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_Delete' and type='P')
	drop procedure [PPFOR_TZB_Payment_Delete]
PPFOR_GO;
create procedure PPFOR_TZB_Payment_Delete(@ID int)
as
	begin
		delete [PPFOR_TZB_Payment] where [ID]=@ID
	end
PPFOR_GO;

---获取支付方式
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_GetModel' and type='P')
	drop procedure PPFOR_TZB_Payment_GetModel
PPFOR_GO;

CREATE  PROCEDURE PPFOR_TZB_Payment_GetModel(@ID int)
 AS 
	select * from [PPFOR_TZB_Payment] where [ID]=@ID
PPFOR_GO;

---查询所有支付方式类型
if exists(select name from sysobjects where name='PPFOR_TZB_Payment_GetShortList' and type='P')
	drop procedure PPFOR_TZB_Payment_GetShortList
PPFOR_GO;

CREATE  PROCEDURE PPFOR_TZB_Payment_GetShortList
 AS 
	select [ID],[Name],[Type],[IsFix],[Rate],[FixMoney],[Status],[Order] from [PPFOR_TZB_Payment] 
		order by [Order] asc,[ID] asc
PPFOR_GO;

if exists(select name from sysobjects where name='PPFOR_TZB_Payment_GetModelList' and type='P')
	drop procedure PPFOR_TZB_Payment_GetModelList
PPFOR_GO;

CREATE  PROCEDURE PPFOR_TZB_Payment_GetModelList
 AS 
	select * from [PPFOR_TZB_Payment] order by [Order] asc,[ID] asc
PPFOR_GO;