-- ==============================
-- 长登科技 www.ppfor.com
-- 唐镇波   2010-04-20
-- ------------------------------
-- 邮件设置表
-- ==============================

--创建邮件设置表
if not exists(select name from sysobjects where name='PPFOR_TZB_EmailSetting' and type='U')
create table PPFOR_TZB_EmailSetting
(
	[id] int identity(1,1) not null primary key,	--ID，自动编号，从1开始递增
	emailAddress varchar(255) ,						--邮件地址
	emailUserName varchar(255),						--邮件用户名
	emailPassword varchar(255),						--邮件密码
	emailSMTPServer varchar(255),	            	--邮件服务器SMTP服务
	emailPort int default(25),						--邮件服务器端口
	emailIsSSL bit,									--是否需要SSL安全连接
	emailTestAddress varchar(255)					--测试邮件地址
)
PPFOR_GO;  

--返回邮件设置
if exists(select name from sysobjects where name='PPFOR_TZB_EmailSetting_GetModel' and type='P')
	drop procedure PPFOR_TZB_EmailSetting_GetModel
PPFOR_GO;
create procedure PPFOR_TZB_EmailSetting_GetModel
as
	select top 1 * from PPFOR_TZB_EmailSetting where [id]>0 order by [id] desc
PPFOR_GO;

--邮件设置
if exists(select name from sysobjects where name='PPFOR_TZB_EmailSetting_Update' and type='P')
	drop procedure PPFOR_TZB_EmailSetting_Update
PPFOR_GO;
create procedure PPFOR_TZB_EmailSetting_Update (@emailAddress varchar(255),
	@emailUserName varchar(255),@emailPassword varchar(255),@emailSMTPServer varchar(255),
	@emailPort int,	@emailIsSSL bit,@emailTestAddress varchar(255))	
as
	begin
		if not exists(select [id] from PPFOR_TZB_EmailSetting)
			insert into PPFOR_TZB_EmailSetting(emailAddress,emailUserName,emailPassword,
			emailSMTPServer,emailPort,emailIsSSL,emailTestAddress) values (@emailAddress,
			@emailUserName,@emailPassword,@emailSMTPServer,@emailPort,@emailIsSSL,@emailTestAddress)
		else
			update PPFOR_TZB_EmailSetting set emailAddress=@emailAddress,
			emailUserName=@emailUserName,emailPassword=@emailPassword,
			emailSMTPServer=@emailSMTPServer,emailPort=@emailPort,	
			emailIsSSL=@emailIsSSL,emailTestAddress=@emailTestAddress
	end
PPFOR_GO;

