if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_Admin_Login]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_Admin_Login]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_Admin_Menu]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_Admin_Menu]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_Admin_UR]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_Admin_UR]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_GetAffiche]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_GetAffiche]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_GetAffiche_count]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_GetAffiche_count]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_GetMenu]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_GetMenu]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_GetRecordFromPage]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_GetRecordFromPage]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_ad_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_ad_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_ad_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_ad_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_adclass_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_adclass_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_adclass_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_adclass_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_affiche_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_affiche_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_affiche_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_affiche_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_affiche_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_affiche_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_content_view]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_content_view]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_get_menu]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_get_menu]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_get_power]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_get_power]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_member_menu_proc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_member_menu_proc]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_member_urcenter]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_member_urcenter]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_proc_PubSelect]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_proc_PubSelect]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_singlepage_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_singlepage_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Fm_singlepage_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Fm_singlepage_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetArtCount]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetArtCount]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetIndexMap]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetIndexMap]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_column_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_column_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_column_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_column_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_column_Parent]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_column_Parent]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_column_PxUpdate]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_column_PxUpdate]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_column_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_column_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_link_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_link_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_link_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_link_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_link_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_link_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_login_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_login_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_login_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_login_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_member_power_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_member_power_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_member_power_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_member_power_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_model_article_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_model_article_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_model_article_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_model_article_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_model_main_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_model_main_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_model_main_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_model_main_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_model_main_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_model_main_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_power_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_power_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_power_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_power_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_power_Delete_1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_power_Delete_1]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_power_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_power_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_role_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_role_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_role_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_role_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_role_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_role_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_urcenter_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_urcenter_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_urcenter_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_urcenter_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_user_ADD]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_user_ADD]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_user_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_user_Delete]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Query_Fm_user_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Query_Fm_user_Update]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_channels]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_channels]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_getarticle]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_getarticle]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_getclick]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_getclick]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_getcolumn]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_getcolumn]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_getcontent]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_getcontent]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_getlink]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_getlink]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_getnextorfront]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_getnextorfront]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_gettoportread]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_gettoportread]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Tags_sitemap]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[Tags_sitemap]
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc [dbo].[Fm_Admin_Login](@username varchar(50),@userpass varchar(50))
as
select u_id,u_name,u_pass  from Fm_user where u_name=@username and u_pass=@userpass
  

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Fm_Admin_Menu(@where varchar(100))
as
declare @strSql varchar(1000)
set @strSql='select distinct m_name,m_id,m_url,m_parent from (
select role.r_id, role.r_name, men.m_id, men.m_name, men.m_url,men.m_type, 
                      men.m_parent
from Fm_power as pw inner join
                      Fm_menu as men on pw.m_id = men.m_id inner join
                      Fm_role as role on pw.r_id = role.r_id) as Fm_Admin_Menu where'+' '+@where+' and m_type=0' 
exec (@strSql)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc [dbo].[Fm_Admin_UR](@u_id int)
as

select ur.r_id from Fm_urcenter as ur inner join Fm_role as ro on ur.r_id=ro.r_id where u_id=@u_id and g_id=1
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Fm_GetAffiche(@count int)
as
declare @sqlstr varchar(100)
set @sqlstr='select top '+str(@count)+' * from Fm_affiche order by aff_id desc'

exec(@sqlstr)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Fm_GetAffiche_count(@aff_id int)
as

update Fm_affiche set aff_look=aff_look+1 where aff_id=@aff_id

select aff_look from Fm_affiche where aff_id=@aff_id


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Fm_GetMenu(@type varchar(10),@classid int,@count int)
as

declare @parent varchar(50)   --存储parent

declare @SqlStr varchar(300)  --存储SQL语句

declare @where varchar(100)   --存储查询条件


select @parent=cl_parent from Fm_artclass where cl_id=@classid  --获取Parent
/*
查询顶级栏目
*/
if @type='top'
begin
set @SqlStr='select '
set @where='* from Fm_column where len(cl_parent)=2'
    if @count=0
      begin
        set @SqlStr=@SqlStr+@where
      end
    else
      begin
       set @SqlStr=@SqlStr+' top '+str(@count)+' '+@where
      end
end
/*

查询与指定栏目同级别的栏目
*/
if @type='self'
begin
set @SqlStr='select '
set @where='* from Fm_column where'
  if len(@parent)=2
   begin
     set @where=@where+' len(cl_parent)='+str(len(@parent))
   end
  else
   begin
     set @where=@where+' substring(cl_parent,1,'+str(len(@parent)-2)+')='+substring(@parent,1,len(@parent)-2)+' and len(cl_parent)='+str(len(@parent))
   end
   if @count=0
      begin
       set @SqlStr=@SqlStr+@where
      end
   else
      begin
	set @SqlStr=@SqlStr+' top '+str(@count)+' '+@where
      end
end
/*
查询指定栏目的子栏目
*/
if @type='son'
begin
set @SqlStr='select '
set @where='* from Fm_column where substring(cl_parent,1,'+str(len(@parent))+')='+@parent+' and len(cl_parent)='+str(len(@parent)+2)
  if @count=0
    begin
     set @SqlStr=@SqlStr+@where
    end
  else
    begin
      set @SqlStr=@SqlStr+' top '+str(@count)+' '+@where
    end
     
end 

--加上排序条件
set @SqlStr=@SqlStr+' order by cl_px asc'
exec(@SqlStr)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE [dbo].[Fm_GetRecordFromPage]

    @tblName      varchar(255),       -- 表名

    @fldName      varchar(255),       -- 字段名

    @PageSize     int = 10,           -- 页尺寸

    @PageIndex    int = 1,            -- 页码

    @OrderType    bit = 0,            -- 设置排序类型, 非0 值则降序

    @IsCount bit = 0, -- 返回记录总数, 非0 值则返回

    @strWhere     varchar(2000) = ''  -- 查询条件(注意: 不要加where)

    

AS

 

declare @strSQL   varchar(6000)       -- 主语句
 
declare @strTmp   varchar(1000)       -- 临时变量

declare @strOrder varchar(500)        -- 排序类型

 

if @OrderType != 0

begin

    set @strTmp = '<(select min'

    set @strOrder = ' order by [' + @fldName + '] desc'

end

else

begin

    set @strTmp = '>(select max'

    set @strOrder = ' order by [' + @fldName +'] asc'

end

 

set @strSQL = 'select top ' + str(@PageSize) + ' * from ['

    + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['

    + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['

    + @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'

    + @strOrder


if @strWhere != ''

    set @strSQL = 'select top ' + str(@PageSize) + ' * from ['

        + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['

        + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['

        + @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '

        + @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder

 

if @PageIndex = 1

begin

    set @strTmp = ''

    if @strWhere != ''

        set @strTmp = ' where (' + @strWhere + ')'

 

    set @strSQL = 'select top ' + str(@PageSize) + ' * from ['

        + @tblName + ']' + @strTmp + ' ' + @strOrder

end

if @IsCount != 0 
begin
if @strWhere !=''
set @strSQL = 'select count(' + @fldName + ') as Total from ['+ @tblName + '] where '+ @strWhere+ ' '
else
set @strSQL = 'select count(' + @fldName + ') as Total from [' + @tblName + ']'
end
exec (@strSQL)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：ACP
--说明：
--时间：2010-2-4 0:36:59
------------------------------------
CREATE PROCEDURE Fm_ad_ADD
@adid int output,
@adletter varchar(100),
@adpic varchar(100),
@adjs varchar(500),
@adurl varchar(200),
@acid int
 AS 
	INSERT INTO [Fm_ad](
	[adletter],[adpic],[adjs],[adurl],[acid]
	)VALUES(
	@adletter,@adpic,@adjs,@adurl,@acid
	)
	SET @adid = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：ACP
--说明：
--时间：2010-2-4 0:36:59
------------------------------------
CREATE PROCEDURE Fm_ad_Update
@adid int,
@adletter varchar(100),
@adpic varchar(100),
@adjs varchar(500),
@adurl varchar(200),
@acid int
 AS 
	UPDATE [Fm_ad] SET 
	[adletter] = @adletter,[adpic] = @adpic,[adjs] = @adjs,[adurl] = @adurl,[acid]=@acid
	WHERE adid=@adid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：ACP
--说明：
--时间：2010-2-4 0:39:00
------------------------------------
CREATE PROCEDURE Fm_adclass_ADD
@acid int output,
@acname varchar(100),
@acintro varchar(1000)

 AS 
	INSERT INTO [Fm_adclass](
	[acname],[acintro]
	)VALUES(
	@acname,@acintro
	)
	SET @acid = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：ACP
--说明：
--时间：2010-2-4 0:39:00
------------------------------------
CREATE PROCEDURE Fm_adclass_Update
@acid int,
@acname varchar(100),
@acintro varchar(1000)
 AS 
	UPDATE [Fm_adclass] SET 
	[acname] = @acname,[acintro] = @acintro
	WHERE acid=@acid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-7 15:23:22
------------------------------------
CREATE PROCEDURE Fm_affiche_ADD
@aff_id int output,
@aff_title varchar(200),
@aff_content varchar(6000),
@aff_user varchar(50),
@aff_btime datetime,
@aff_look int

 AS 
	INSERT INTO [Fm_affiche](
	[aff_title],[aff_content],[aff_user],[aff_btime],[aff_look]
	)VALUES(
	@aff_title,@aff_content,@aff_user,@aff_btime,@aff_look
	)
	SET @aff_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-7 15:23:22
------------------------------------
CREATE PROCEDURE Fm_affiche_Delete
@aff_id int
 AS 
	DELETE [Fm_affiche]
	 WHERE aff_id=@aff_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-7 15:23:22
------------------------------------
CREATE PROCEDURE Fm_affiche_Update
@aff_id int,
@aff_title varchar(200),
@aff_content varchar(6000),
@aff_user varchar(50),
@aff_btime datetime,
@aff_look int
 AS 
	UPDATE [Fm_affiche] SET 
	[aff_title] = @aff_title,[aff_content] = @aff_content,[aff_user] = @aff_user,[aff_btime] = @aff_btime
	WHERE aff_id=@aff_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Fm_content_view(@where varchar(100))
as
declare @sqlstr varchar(200)
set @sqlstr='select  *   from Fm_model_article_view where '+@where+' order by docid desc'

exec(@sqlstr)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Fm_get_menu(@m_id int)
as
select * from Fm_menu where m_type=0 and m_parent=@m_id

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Fm_get_power(@r_id int)
as
select * from Fm_power where r_id=@r_id

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Fm_member_menu_proc(@where varchar(150))
as
declare @sqlstr varchar(1000)

set @sqlstr='select distinct menu.mid,menu.mname,menu.url,menu.parent,power.mid,power.rid from Fm_member_menu as menu inner join 
                 Fm_member_power as power on power.mid=menu.mid where '+@where

exec(@sqlstr)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Fm_member_urcenter(@uid int)
as
declare @sqlstr varchar(1000)

set @sqlstr='select role.r_id,role.g_id,role.r_name,u.u_id from Fm_urcenter as ur
                inner join Fm_role as role on ur.r_id=role.r_id
                  inner join Fm_user as u on ur.u_id=u.u_id where u.u_id='+str(@uid)

exec(@sqlstr)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Fm_proc_PubSelect(@tablename varchar(50),@field varchar(100),@where varchar(100))
as

declare @sqlstr varchar(300)
   
set @sqlstr='select '+@field+' from '+@tablename

if @where<>''
   set @sqlstr=@sqlstr+' where '+@where

exec(@sqlstr)



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：ACP
--说明：
--时间：2010-2-4 0:44:57
------------------------------------
CREATE PROCEDURE Fm_singlepage_ADD
@sid int output,
@stitle varchar(100),
@skeywords varchar(100),
@sintro varchar(300),
@scontent text,
@stemplates varchar(50),
@spath varchar(80)

 AS 
	INSERT INTO [Fm_singlepage](
	[stitle],[skeywords],[sintro],[scontent],[stemplates],[spath]
	)VALUES(
	@stitle,@skeywords,@sintro,@scontent,@stemplates,@spath
	)
	SET @sid = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：ACP
--说明：
--时间：2010-2-4 0:44:57
------------------------------------
CREATE PROCEDURE Fm_singlepage_Update
@sid int,
@stitle varchar(100),
@skeywords varchar(100),
@sintro varchar(300),
@scontent text,
@stemplates varchar(50),
@spath varchar(80)
 AS 
	UPDATE [Fm_singlepage] SET 
	[stitle] = @stitle,[skeywords] = @skeywords,[sintro] = @sintro,[scontent] = @scontent,[stemplates] = @stemplates,[spath] = @spath
	WHERE sid=@sid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc GetArtCount(@aid int)
as

update Fm_art set art_count=art_count+1 where art_id=@aid

select art_count from Fm_art where art_id=@aid


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc GetIndexMap
as
 select top 6 * from Fm_art_view where art_flash=1 order by art_time desc


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-24 19:52:25
------------------------------------
CREATE PROCEDURE Query_Fm_column_ADD
@cl_id int,
@cl_name varchar(100),
@cl_tg bit,
@cl_xs bit,
@cl_path varchar(60),
@cl_location bit,
@cl_options int,
@cl_attribute int,
@cl_temp_index varchar(100),
@cl_temp_list varchar(100),
@cl_temp_cont varchar(100),
@cl_default varchar(100),
@cl_content varchar(100),
@cl_list varchar(100),
@cl_url varchar(100),
@cl_keyword varchar(300),
@cl_intro varchar(500),
@cl_parent varchar(50),
@cl_px int

 AS 
	INSERT INTO [Fm_column](
	[cl_id],[cl_name],[cl_tg],[cl_xs],[cl_path],[cl_location],[cl_options],[cl_attribute],[cl_temp_index],[cl_temp_list],[cl_temp_cont],[cl_default],[cl_content],[cl_list],[cl_url],[cl_keyword],[cl_intro],[cl_parent],[cl_px]
	)VALUES(
	@cl_id,@cl_name,@cl_tg,@cl_xs,@cl_path,@cl_location,@cl_options,@cl_attribute,@cl_temp_index,@cl_temp_list,@cl_temp_cont,@cl_default,@cl_content,@cl_list,@cl_url,@cl_keyword,@cl_intro,@cl_parent,@cl_px
	)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-24 19:52:25
------------------------------------
CREATE PROCEDURE Query_Fm_column_Delete
@cl_id int
 AS 
	DELETE [Fm_column]
	 WHERE cl_id=@cl_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [Query_Fm_column_Parent]
@cl_id int,
@cl_parent varchar(50)
 AS

  update Fm_column set cl_parent=@cl_parent where cl_id=@cl_id

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE Query_Fm_column_PxUpdate
@cl_id int,
@cl_px varchar(50)
AS

    update Fm_column set cl_px=@cl_px where cl_id=@cl_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-24 19:52:25
------------------------------------
CREATE PROCEDURE Query_Fm_column_Update
@cl_id int,
@cl_name varchar(100),
@cl_tg bit,
@cl_xs bit,
@cl_path varchar(60),
@cl_location bit,
@cl_options int,
@cl_attribute int,
@cl_temp_index varchar(100),
@cl_temp_list varchar(100),
@cl_temp_cont varchar(100),
@cl_default varchar(100),
@cl_content varchar(100),
@cl_list varchar(100),
@cl_url varchar(100),
@cl_keyword varchar(300),
@cl_intro varchar(500),
@cl_parent varchar(50),
@cl_px int
 AS 
	UPDATE [Fm_column] SET 
	[cl_name] = @cl_name,[cl_tg] = @cl_tg,[cl_xs] = @cl_xs,[cl_path] = @cl_path,[cl_location] = @cl_location,[cl_options] = @cl_options,[cl_attribute] = @cl_attribute,[cl_temp_index] = @cl_temp_index,[cl_temp_list] = @cl_temp_list,[cl_temp_cont] = @cl_temp_cont,[cl_default] = @cl_default,[cl_content] = @cl_content,[cl_list] = @cl_list,[cl_url] = @cl_url,[cl_keyword] = @cl_keyword,[cl_intro] = @cl_intro,[cl_parent] = @cl_parent,[cl_px] = @cl_px
	WHERE cl_id=@cl_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 17:29:15
------------------------------------
CREATE PROCEDURE Query_Fm_link_ADD
@link_id int output,
@link_name varchar(50),
@link_url varchar(50),
@link_px int,
@link_type bit,
@link_logo varchar(100),
@link_intro varchar(300)

 AS 
	INSERT INTO [Fm_link](
	[link_name],[link_url],[link_px],[link_type],[link_logo],[link_intro]
	)VALUES(
	@link_name,@link_url,@link_px,@link_type,@link_logo,@link_intro
	)
	SET @link_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 17:29:15
------------------------------------
CREATE PROCEDURE Query_Fm_link_Delete
@link_id int
 AS 
	DELETE [Fm_link]
	 WHERE link_id=@link_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 17:29:15
------------------------------------
CREATE PROCEDURE Query_Fm_link_Update
@link_id int,
@link_name varchar(50),
@link_url varchar(50),
@link_px int,
@link_type bit,
@link_logo varchar(100),
@link_intro varchar(300)
 AS 
	UPDATE [Fm_link] SET 
	[link_name] = @link_name,[link_url] = @link_url,[link_px] = @link_px,[link_type] = @link_type,[link_logo] = @link_logo,[link_intro] = @link_intro
	WHERE link_id=@link_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-7 23:46:51
------------------------------------
CREATE PROCEDURE Query_Fm_login_ADD
@lo_id int output,
@lo_user varchar(50),
@lo_ip varchar(50),
@lo_time datetime

 AS 
	INSERT INTO [Fm_login](
	[lo_user],[lo_ip],[lo_time]
	)VALUES(
	@lo_user,@lo_ip,@lo_time
	)
	SET @lo_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-7 23:46:51
------------------------------------
CREATE PROCEDURE Query_Fm_login_Delete
@lo_id int
 AS 
	DELETE [Fm_login]
	 WHERE lo_id=@lo_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-28 0:55:10
------------------------------------
CREATE PROCEDURE Query_Fm_member_power_ADD
@pid int output,
@mid int,
@rid int

 AS 
	INSERT INTO [Fm_member_power](
	[mid],[rid]
	)VALUES(
	@mid,@rid
	)
	SET @pid = @@IDENTITY


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-28 0:55:10
------------------------------------
CREATE PROCEDURE Query_Fm_member_power_Delete
@rid int
 AS 
	DELETE [Fm_member_power]
	 WHERE rid=@rid 


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：Fmcms
--说明：
--时间：2010-1-17 23:22:13
------------------------------------
CREATE PROCEDURE Query_Fm_model_article_ADD
@docid int,
@content text,
@author varchar(100),
@source varchar(100)

 AS 
	INSERT INTO [Fm_model_article](
	[docid],[content],[author],[source]
	)VALUES(
	@docid,@content,@author,@source
	)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：Fmcms
--说明：
--时间：2010-1-18 0:12:46
------------------------------------
CREATE PROCEDURE Query_Fm_model_article_Update
@docid int,
@content text,
@author varchar(100),
@source varchar(100)
 AS 
	UPDATE [Fm_model_article] SET 
	[content] = @content,[author] = @author,[source] = @source
	WHERE docid=@docid 

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-12 13:43:03
------------------------------------
CREATE PROCEDURE Query_Fm_model_main_ADD
@docid int output,
@colid int,
@title varchar(300),
@head bit,
@map bit,
@flash bit,
@commend bit,
@bold bit,
@writertime smalldatetime,
@username varchar(50),
@click int,
@audit bit,
@comment bit,
@color varchar(30),
@keyword varchar(300),
@intro varchar(1000),
@html bit,
@topclick int,
@tread int,
@thumbnail varchar(150)

 AS 
	INSERT INTO [Fm_model_main](
	[colid],[title],[head],[map],[flash],[commend],[bold],[writertime],[username],[click],[audit],[comment],[color],[keyword],[intro],[html],[topclick],[tread],[thumbnail]
	)VALUES(
	@colid,@title,@head,@map,@flash,@commend,@bold,@writertime,@username,@click,@audit,@comment,@color,@keyword,@intro,@html,@topclick,@tread,@thumbnail
	)
	SET @docid = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-12 13:43:03
------------------------------------
CREATE PROCEDURE Query_Fm_model_main_Delete
@docid int
 AS 
	DELETE [Fm_model_main]
	 WHERE docid=@docid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：Fmcms
--说明：
--时间：2009-10-12 13:43:03
------------------------------------
CREATE PROCEDURE Query_Fm_model_main_Update
@docid int,
@colid int,
@title varchar(300),
@head bit,
@map bit,
@flash bit,
@commend bit,
@bold bit,
@writertime smalldatetime,
@username varchar(50),
@click int,
@audit bit,
@comment bit,
@color varchar(30),
@keyword varchar(300),
@intro varchar(1000),
@html bit,
@topclick int,
@tread int,
@thumbnail varchar(150)
 AS 
	UPDATE [Fm_model_main] SET 
	[colid] = @colid,[title] = @title,[head] = @head,[map] = @map,[flash] = @flash,[commend] = @commend,[bold] = @bold,[writertime] = @writertime,[username] = @username,[click] = @click,[audit] = @audit,[comment] = @comment,[color] = @color,[keyword] = @keyword,[intro] = @intro,[html] = @html,[topclick] = @topclick,[tread] = @tread,[thumbnail] = @thumbnail
	WHERE docid=@docid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 23:32:52
------------------------------------
CREATE PROCEDURE Query_Fm_power_ADD
@p_id int output,
@m_id int,
@r_id int

 AS 
	INSERT INTO [Fm_power](
	[m_id],[r_id]
	)VALUES(
	@m_id,@r_id
	)
	SET @p_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 23:32:52
------------------------------------
CREATE PROCEDURE Query_Fm_power_Delete
@p_id int
 AS 
	DELETE [Fm_power]
	 WHERE p_id=@p_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [Query_Fm_power_Delete_1] 
@r_id int
AS

delete Fm_power where r_id=@r_id



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 23:32:52
------------------------------------
CREATE PROCEDURE Query_Fm_power_Update
@p_id int,
@m_id int,
@r_id int
 AS 
	UPDATE [Fm_power] SET 
	[m_id] = @m_id,[r_id] = @r_id
	WHERE p_id=@p_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 23:32:06
------------------------------------
CREATE PROCEDURE Query_Fm_role_ADD
@r_id int output,
@r_name varchar(50),
@g_id int

 AS 
	INSERT INTO [Fm_role](
	[r_name],[g_id]
	)VALUES(
	@r_name,@g_id
	)
	SET @r_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 23:32:06
------------------------------------
CREATE PROCEDURE Query_Fm_role_Delete
@r_id int
 AS 
	DELETE [Fm_role]
	 WHERE r_id=@r_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 23:32:06
------------------------------------
CREATE PROCEDURE Query_Fm_role_Update
@r_id int,
@r_name varchar(50),
@g_id int
 AS 
	UPDATE [Fm_role] SET 
	[r_name] = @r_name,[g_id] = @g_id
	WHERE r_id=@r_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 22:20:51
------------------------------------
CREATE PROCEDURE Query_Fm_urcenter_ADD
@c_id int output,
@u_id int,
@r_id int

 AS 
	INSERT INTO [Fm_urcenter](
	[u_id],[r_id]
	)VALUES(
	@u_id,@r_id
	)
	SET @c_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 22:20:51
------------------------------------
CREATE PROCEDURE Query_Fm_urcenter_Update
@c_id int,
@u_id int,
@r_id int
 AS 
	UPDATE [Fm_urcenter] SET 
	[u_id] = @u_id,[r_id] = @r_id
	WHERE c_id=@c_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：增加一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 22:04:38
------------------------------------
CREATE PROCEDURE Query_Fm_user_ADD
@u_id int output,
@u_name varchar(20),
@u_pass varchar(50),
@u_nc varchar(30),
@u_mail varchar(50)

 AS 
	INSERT INTO [Fm_user](
	[u_name],[u_pass],[u_nc],[u_mail]
	)VALUES(
	@u_name,@u_pass,@u_nc,@u_mail
	)
	SET @u_id = @@IDENTITY
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：删除一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 22:04:38
------------------------------------
CREATE PROCEDURE Query_Fm_user_Delete
@u_id int
 AS 
	DELETE [Fm_user]
	 WHERE u_id=@u_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

------------------------------------
--用途：修改一条记录 
--项目名称：CodematicDemo
--说明：
--时间：2009-9-8 22:04:38
------------------------------------
CREATE PROCEDURE Query_Fm_user_Update
@u_id int,
@u_name varchar(20),
@u_pass varchar(50),
@u_nc varchar(30),
@u_mail varchar(50)
 AS 
	UPDATE [Fm_user] SET 
	[u_name] = @u_name,[u_pass] = @u_pass,[u_nc] = @u_nc,[u_mail] = @u_mail
	WHERE u_id=@u_id
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/************
频道标签数据调用
**************/
CREATE proc Tags_channels(@cid int)
as
declare @sqlstr varchar(200)
declare @parent varchar(30)
set @sqlstr='select * from Fm_column where cl_xs=1 and cl_attribute<>1 '
if @cid=0
begin
  set @sqlstr=@sqlstr+' and len(cl_parent)=2'
end
else
begin
  select @parent=cl_parent from Fm_column where cl_id=@cid
  set @sqlstr=@sqlstr+' and substring(cl_parent,1,'+str(len(@parent))+')='+@parent+' and len(cl_parent)='+str(len(@parent)+2)
end

exec(@sqlstr)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

/**********************************************
{fm:article}标签数据调用存储过程!
***********************************************/
CREATE proc Tags_getarticle(@type varchar(20),@cid int,@count int)
as
declare @sqlstr varchar(600)--SQL语句
declare @where varchar(200)--查询条件
declare @parent varchar(50)--如果是封面栏目就用来存储栏目上级编号
declare @attribute int --存储栏目属性

set @sqlstr='select top '+str(@count)+' colid as cid,docid,title,content,writertime,username,click,color,keyword,intro,topclick,tread,thumbnail,author,source,cl_name as cname,path,html from Fm_model_article_view'

if @cid!=0
begin
  select @parent=cl_parent,@attribute=cl_attribute from Fm_column where cl_id=@cid
  if @attribute=1
  begin
    set @where=' where substring(cl_parent,1,2)='+@parent
  end 
  else
  begin
   set @where=' where colid='+str(@cid)
  end 
  set @where=@where+' and audit=1'
end
else
begin
  set @where=' where audit=1'
end
  
/*调用最新*/
if @type='new'
begin

  set @where=@where+' order by docid desc'
end
/*调用头条*/
if @type='head'
begin
   set @where=@where+' and head=1 order by docid desc'
end
/*调用图文*/
if @type='map'
begin
    set @where=@where+' and map=1 order by docid desc'
end
/*调用幻灯*/
if @type='flash'
begin
  set @where=@where+' and flash=1 order by docid desc'
end
/*调用热门*/
if @type='hot'
begin
  if @cid=0
  begin
    set @where=''
  end
  set @where=@where+'  order by click desc'
end
/*调用推荐*/
if @type='commend'
begin
 
  set @where=@where+' and commend=1 order by docid desc'
end
/*调用DIGG*/
if @type='top'
begin
  if @cid=0
  begin
    set @where=''
  end
  set @where=@where+' order by topclick desc'
end
if @type='tread'
begin
  if @cid=0
  begin
    set @where=''
  end
  set @where=@where+' order by tread desc'
end

set @sqlstr=@sqlstr+@where

exec(@sqlstr)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Tags_getclick(@docid int,@page int)
as
if @page=1
begin
 update Fm_model_main set click=click+1 where docid=@docid
end

select click from Fm_model_main where docid=@docid



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Tags_getcolumn(@type varchar(10),@cid int,@count int)
as

declare @parent varchar(50)   --存储parent

declare @SqlStr varchar(300)  --存储SQL语句

declare @where varchar(100)   --存储查询条件


select @parent=cl_parent from Fm_column where cl_id=@cid  --获取Parent
/*
查询顶级栏目
*/
if @type='top'
begin
set @SqlStr='select '
set @where='* from Fm_column where len(cl_parent)=2'
    if @count=0
      begin
        set @SqlStr=@SqlStr+@where
      end
    else
      begin
       set @SqlStr=@SqlStr+' top '+str(@count)+' '+@where
      end
end
/*

查询与指定栏目同级别的栏目
*/
if @type='self'
begin
set @SqlStr='select '
set @where='* from Fm_column where'
  if len(@parent)=2
   begin
     set @where=@where+' len(cl_parent)='+str(len(@parent))
   end
  else
   begin
     set @where=@where+' substring(cl_parent,1,'+str(len(@parent)-2)+')='+substring(@parent,1,len(@parent)-2)+' and len(cl_parent)='+str(len(@parent))
   end
   if @count=0
      begin
       set @SqlStr=@SqlStr+@where
      end
   else
      begin
	set @SqlStr=@SqlStr+' top '+str(@count)+' '+@where
      end
end
/*
查询指定栏目的子栏目
*/
if @type='son'
begin
set @SqlStr='select '
set @where='* from Fm_column where substring(cl_parent,1,'+str(len(@parent))+')='+@parent+' and len(cl_parent)='+str(len(@parent)+2)
  if @count=0
    begin
     set @SqlStr=@SqlStr+@where
    end
  else
    begin
      set @SqlStr=@SqlStr+' top '+str(@count)+' '+@where
    end
     
end 

--加上排序条件
set @SqlStr=@SqlStr+' and cl_xs=1 order by cl_px asc'
exec(@SqlStr)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Tags_getcontent(@docid int)
as
select  *   from Fm_model_article_view where docid=@docid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Tags_getlink(@type varchar(10),@count int)
as
declare @sqlstr varchar(300)

set @sqlstr='select top '+str(@count)+' * from Fm_link'
if @type='logo'
    set @sqlstr=@sqlstr+' where link_type=1'
if @type='letter'
    set @sqlstr=@sqlstr+' where link_type=0'

set @sqlstr=@sqlstr+' order by link_px desc'

exec(@sqlstr)


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Tags_getnextorfront(@docid int,@type varchar(10))
as

declare @sqlstr varchar(200)
declare @where varchar(50)
 
set @sqlstr='select top 1 docid,title,color,path,html from Fm_model_article_view where'

if @type='front'
    set @where=' docid<'+str(@docid)
if @type='next'
    set @where=' docid>'+str(@docid)

set @sqlstr=@sqlstr+@where+' order by docid desc'

exec(@sqlstr)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

create proc Tags_gettoportread(@docid int,@type int)
as

if @type=0
  begin
   update Fm_model_main set topclick=topclick+1 where docid=@docid
   select topclick from Fm_model_main where docid=@docid
  end
if @type=1
  begin
   update Fm_model_main set tread=tread+1 where docid=@docid
   select tread from Fm_model_main where docid=@docid
  end



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE proc Tags_sitemap(@cid int)
as
declare @parent varchar(50)

select @parent=cl_parent from Fm_column where cl_id=@cid

select * from Fm_column where cl_parent like ''+substring(@parent,1,2)+'%'
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

