-- ==============================
-- 长登科技 www.ppfor.com
-- 唐镇波   2010-04-20
-- ------------------------------
-- 产品属性表
-- ==============================

--创建产品属性表
if not exists(select name from sysobjects where name='PPFOR_TZB_ProductAttribute' and type='U')
CREATE TABLE [PPFOR_TZB_ProductAttribute] (
	[ID] int IDENTITY (1, 1) NOT NULL PRIMARY KEY,
	[belongLanguage] int NOT NULL REFERENCES [PPFOR_TZB_Language]([ID]) ON DELETE CASCADE,	--所属语言
	[ifMoreImage] bit NOT NULL ,		--是否开启多图
	[proWidth] tinyint NOT NULL ,		--产品多图宽度
	[proHeight] tinyint NOT NULL ,		--产品多图高度
	[imageWidth] tinyint NOT NULL ,		--产品缩略图宽度
	[imageHeight] tinyint NOT NULL ,	--产品缩略图高度
	[fileDown] [bit] NOT NULL ,			--是否允许下载
	[recommended] [bit] NOT NULL ,		--是否推荐
	[new] [bit] NOT NULL ,				--是否最新
	[hot] [bit] NOT NULL ,				--是否热点
	[slide] [bit] NOT NULL ,			--是否幻灯片
	[shopping] [bit] NOT NULL			--是否启用购物车
)
PPFOR_GO;

--添加产品属性
if exists(select name from sysobjects where name='PPFOR_TZB_ProductAttribute_Add' and type='P')
	drop procedure PPFOR_TZB_ProductAttribute_Add
PPFOR_GO;

CREATE PROCEDURE PPFOR_TZB_ProductAttribute_Add(@ID int output,@belongLanguage int,@ifMoreImage bit,
	@proWidth tinyint,@proHeight tinyint,@imageWidth tinyint,@imageHeight tinyint,@fileDown bit,
	@recommended bit,@new bit,@hot bit,@slide bit,@shopping bit)
 AS 
	begin
		INSERT INTO [PPFOR_TZB_ProductAttribute]([belongLanguage],[ifMoreImage],[proWidth],
		[proHeight],[imageWidth],[imageHeight],[fileDown],[recommended],[new],[hot],[slide],
		[shopping])VALUES(@belongLanguage,@ifMoreImage,@proWidth,@proHeight,@imageWidth,
		@imageHeight,@fileDown,@recommended,@new,@hot,@slide,@shopping)
		SET @ID = @@IDENTITY
	end
PPFOR_GO;

--删除产品属性
if exists(select name from sysobjects where name='PPFOR_TZB_ProductAttribute_Delete' and type='P')
	drop procedure PPFOR_TZB_ProductAttribute_Delete
PPFOR_GO;

CREATE PROCEDURE PPFOR_TZB_ProductAttribute_Delete(@ID int)
 AS 
	DELETE [PPFOR_TZB_ProductAttribute] WHERE [ID]=@ID 
PPFOR_GO;

--获取产品属性
if exists(select name from sysobjects where name='PPFOR_TZB_ProductAttribute_GetModel' and type='P')
	drop procedure PPFOR_TZB_ProductAttribute_GetModel
PPFOR_GO;

CREATE   PROCEDURE PPFOR_TZB_ProductAttribute_GetModel(@belongLanguage int)
 AS 
	SELECT [ID],belongLanguage,ifMoreImage,proWidth,proHeight,imageWidth,imageHeight,fileDown,
		recommended,new,hot,slide,shopping FROM [PPFOR_TZB_ProductAttribute]
		   WHERE belongLanguage=@belongLanguage
PPFOR_GO;

--更新产品属性
if exists(select name from sysobjects where name='PPFOR_TZB_ProductAttribute_Update' and type='P')
	drop procedure PPFOR_TZB_ProductAttribute_Update
PPFOR_GO;

CREATE PROCEDURE PPFOR_TZB_ProductAttribute_Update(@ID int,@belongLanguage int,@ifMoreImage bit,
	@proWidth tinyint,@proHeight tinyint,@imageWidth tinyint,@imageHeight tinyint,@fileDown bit,
	@recommended bit,@new bit,@hot bit,@slide bit,@shopping bit)
 AS 
	UPDATE [PPFOR_TZB_ProductAttribute] SET [belongLanguage] = @belongLanguage,
		[ifMoreImage] = @ifMoreImage,[proWidth] = @proWidth,[proHeight] = @proHeight,
		[imageWidth] = @imageWidth,[imageHeight] = @imageHeight,[fileDown] = @fileDown,
		[recommended] = @recommended,[new] = @new,[hot] = @hot,[slide] = @slide,
		[shopping] = @shopping WHERE [ID]=@ID 
PPFOR_GO;
