if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[vehicle_insure]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[vehicle_insure]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Function fn_Bill_ConvertApproveSign
/****************************
* 功能:新單據狀態代號轉換為相應的文字
* 作者:Billy
* 日期:2006/12/11
****************************/
(
@ApproveSign char(1)
)
RETURNS NVarChar(3)
As
Begin
Declare @Result nVarchar(3)
Set @Result = Case @ApproveSign When '1' then '未核准' When '2' then '退單' When '3' then '已核准' When '4' then '結案' When '5' Then '略過' Else '' End
return @Result
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Bill_ConvertStatus
/****************************
* 功能:將單據狀態代號轉換為相應的文字
* 作者:Billy
* 日期:2006/12/11
****************************/
(
@Status char(1)
)
RETURNS NVarChar(3)
As
Begin
Declare @Result nVarchar(3)
Set @Result = Case @Status When '1' then '新單' When '2' then '已結案' When '3' then '作廢' When '4' then '簽核中' Else '' End
return @Result
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE function fn_Bill_GetCurrentApproveSeq(@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30))
/****************************************************************
功能:取得單據的當前簽核用戶的ApproveSeq
****************************************************************/
returns int
as
begin
declare @nApproveSeq int
Set @nApproveSeq = -1
if( Not Exists(Select Bill_No From Person_d_Approve Where company_no = @CompanyNo and Kind_No = @KindNo and Bill_No = @BillNo) )
return -1
Select @nApproveSeq = Current_ApproveSeq From Bill_m_Approve Where company_no = @CompanyNo and Kind_No = @KindNo and Bill_No = @BillNo
return @nApproveSeq
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Bill_GetUserNo
/****************************
* 功能:如果實際簽核用戶不為空,則返回實際簽核用戶
* 作者:Billy
* 日期:2006/09/12
****************************/
(
@UserNo varchar(20),
@ActualUserNo varchar(20)
)
RETURNS varchar(20)
As
Begin
Declare @Result varchar(20)
Set @ActualUserNo = IsNull(@ActualUserNo, '')
if @ActualUserNo = ''
set @Result = @UserNo
Else
set @Result = @ActualUserNo
return @Result
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE FUNCTION fn_Bill_GettValidateStatus(@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30), @Seq int)
RETURNS Nvarchar(3)
AS
BEGIN
Declare @Validate char(1)
Select @Validate = Validate From Bill_Approve_Validate Where Company_no = @CompanyNo and Kind_No = @KindNo And Bill_No = @BillNo And Seq = @Seq
Return dbo.fn_ConvertValidateStatus(@Validate)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
--判斷傳入的第一個日期是否包含在第二兩個日期與第三個日期內
create function fn_CheckDateInRange(@CheckDate DateTime, @BeginDate DateTime, @EndDate DateTime )
returns Char(1)
as
begin
Declare @Result char(1)
set @Result = 'N'
if( @CheckDate >=@BeginDate And @CheckDate <= @EndDate )
Set @Result = 'Y'
return(@Result)
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION fn_CheckUserHasMarkName(@UserNo varchar(20) )
RETURNS bit
AS
BEGIN
declare @Retrieve bit
set @Retrieve=0--無
if len((select mark_name from useradmin where user_no=@UserNo))>0
set @Retrieve=1--有
return(@Retrieve)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
create function fn_CheckUserStatus
(
@status char(1),
@SystemDate DateTime, --系統當前日期
@BeginDate DateTime,
@EndDate DateTime
)
/************************************************************************************
*介紹: 檢查用戶是否生效
*作者: Billy
*日期: 2006/11/01
*返回: Y/N
*************************************************************************************/
returns char(1)
as
begin
Declare @Return char(1)
if @Status != 'Y'
set @Return = 'N'
else if( @BeginDate <= @SystemDate And @EndDate >= @SystemDate )
set @Return = 'Y'
Else
set @Return = 'N'
Return @Return
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE FUNCTION fn_ConvertExigencyGrade(@cExigencyGrade char(1) )
RETURNS Nvarchar(2)
AS
BEGIN
declare @ExigencyGrade nvarchar(2)
set @ExigencyGrade= case @cExigencyGrade
when '1' then '普通'
when '2' then '緊急'
when '3' then '特急'
else null end
return(@ExigencyGrade)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION fn_ConvertOperation(@nOperation int )
RETURNS varchar(10)
AS
BEGIN
declare @Retrieve varchar(10)
set @Retrieve= case @nOperation
when 1 then '新增'
when 2 then '修改'
when 3 then '刪除'
when 4 then '審核'
when 5 then '列印'
when 6 then '查看'
when 7 then '作廢單據'
else null
end
return(@Retrieve)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
---------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE function fn_ConvertToTime
/***************************************************
--作者:電腦混混Vincent
--書寫時間:2006/08/23
--說明:將兩日期之差(分鐘)轉換為“xx天xx小時xx分種”
--參數:@MinuteCount:輸入 分鐘總數
@RetrieveTime :輸出 指定格式的日期差
*****************************************************/
(
@MinuteCount int
)
returns varchar(30)
as
begin
declare @RetrieveTime varchar(30)
declare @nDay int
declare @nHour int
declare @nMinute int
/*
----參數傳入錯誤
if @MinuteCount < 1
begin
return 'Error'
end
*/
set @nDay = @MinuteCount / 1440
set @MinuteCount = @MinuteCount % 1440
set @nHour = @MinuteCount / 60
set @MinuteCount = @MinuteCount % 60
set @nMinute = @MinuteCount
set @RetrieveTime = ''
if @nMinute <> 0
begin
set @RetrieveTime = cast(@nMinute as varchar) + '分'
end
if @nHour <> 0
begin
set @RetrieveTime = cast(@nHour as varchar) + '時' + @RetrieveTime
end
if @nDay <> 0
begin
set @RetrieveTime = cast(@nDay as varchar) + '天' + @RetrieveTime
end
return @RetrieveTime
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE FUNCTION fn_ConvertValidateStatus(@Validate char(1) )
RETURNS Nvarchar(3)
AS
BEGIN
declare @ValidateStatus nvarchar(3)
set @ValidateStatus= case @Validate
when '1' then '未進行'
when '2' then '未通過'
when '3' then '已通過'
else '' end
return(@ValidateStatus)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION fn_DepartmentFrame
(
@CompanyNo varchar(10),
@DeptNo varchar(10)
)
RETURNS nvarchar(100)
AS
BEGIN
declare @Retrieve nvarchar(100)
Declare @Exit char(1) , @ChiefFlag char(1)
Select @Exit = 'N', @ChiefFlag = 'N'
set @Retrieve=''
while @Exit != 'Y' and @ChiefFlag != 'Y'
begin
if Exists( Select * From Dept Where company_no = @CompanyNo and Dept_no = @DeptNo)
select @Retrieve=dept_nm+'→'+@Retrieve,
@DeptNo=case isnull(parent_dept_no,'') when '' then '' else parent_dept_no end,
@ChiefFlag = chief_flag
from dept where company_no = @CompanyNo and dept_no=@DeptNo
Else
Set @Exit = 'Y'
end
-- select @Retrieve=C.company_nm+'→'+@Retrieve from dept D inner join company C on D.company_no=C.company_no where D.dept_no=@DeptNo
if len(@Retrieve)>0
if SubString(@Retrieve, Len(@Retrieve), 1) = '→'
set @Retrieve=substring(@Retrieve,1,len(@Retrieve)-1)
return(@Retrieve)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION fn_DepartmentFrameAll
(
@CompanyNo varchar(10),
@DeptNo varchar(10),
@IsStopChief char(1)
)
RETURNS nvarchar(200)
AS
BEGIN
declare @Retrieve nvarchar(100)
Declare @Exit char(1) , @ChiefFlag char(1)
Select @Exit = 'N', @ChiefFlag = 'N'
set @Retrieve=''
while @Exit != 'Y' and @ChiefFlag != 'Y'
begin
if Exists( Select * From Dept Where company_no = @CompanyNo and Dept_no = @DeptNo)
begin
select @Retrieve=dept_nm+'→'+@Retrieve,
@DeptNo=case isnull(parent_dept_no,'') when '' then '' else parent_dept_no end,
@ChiefFlag = chief_flag
from dept where company_no = @CompanyNo and dept_no=@DeptNo
if @IsStopChief != 'Y'
set @ChiefFlag='N'
end
Else
Set @Exit = 'Y'
end
-- select @Retrieve=C.company_nm+'→'+@Retrieve from dept D inner join company C on D.company_no=C.company_no where D.dept_no=@DeptNo
if len(@Retrieve)>0
if SubString(@Retrieve, Len(@Retrieve), 1) = '→'
set @Retrieve=substring(@Retrieve,1,len(@Retrieve)-1)
return(@Retrieve)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Dept_GetAllChildDeptNo( @CompanyNo varchar(10), @DeptNo varchar(10) )
/******************************
功能:返回傳入部門及其所有下屬部門的代號列表,以英文逗號分隔
作者:Billy
日期:2006/11/30
********************************/
returns varchar(2000)
Begin
Declare @DeptResult varchar(2000)
Declare @ID int
Select @DeptResult = @DeptNo , @ID = 1
Declare @TempTable Table( ID int IDentity(1,1), dept_no varchar(10), parent_dept_no varchar(10) )
Insert Into @TempTable Select dept_no, parent_dept_no From Dept Where parent_dept_no = @DeptNo and company_no = @CompanyNo
While Exists(Select * From @TempTable Where ID = @ID)
Begin
Select @DeptNo = Dept_no From @TempTable Where ID = @ID
Set @ID = @ID + 1
Set @DeptResult = @DeptResult + ',' + OA.dbo.fn_Dept_GetAllChildDeptNo(@CompanyNo, @DeptNo)
End
Return @DeptResult
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Dept_GetAllSuperiorDepartMentNo
/****************************
* 功能:取得某部門所有下屬部門(上級部門)列表(包含本部門),返回上級部門時,只搜索到處級
* 作者:Billy
* 日期:2006/11/27
****************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(10),
@Mode char(1) = '1' --1:返回本部門及其下屬部門列表 2:返回本部門及其上級部門列表 3:返回1與2的集合
)
RETURNS varchar(3000)
As
Begin
Declare @IsChief char(1) --是否為處級
Declare @TempDeptNo varchar(10) --存放臨時部門代號
Declare @DepartmentList varchar(3000) --結果列表
Select @IsChief = 'N', @DepartmentList = '', @TempDeptNo = @DeptNo
if @Mode = '1' --取所有下屬部門列表
Begin
Set @DepartmentList = dbo.fn_Dept_GetAllChildDeptNo(@CompanyNo, @DeptNo)
goto ExitFunction
End
--取上級部門列表
While Exists(Select Dept_no From Dept Where Company_no = @CompanyNo and Dept_no = @TempDeptNo)
Begin
Select @IsChief = Chief_Flag, @TempDeptNo = parent_dept_no From Dept
Where Company_no = @CompanyNo and Dept_no = @TempDeptNo
Set @TempDeptNo = Ltrim(@TempDeptNo)
if @TempDeptNo = '' break
Set @DepartMentList = @DepartmentList + ',' + @TempDeptNo
if Upper(@IsChief) = 'Y' break
End
if @Mode = '2'
Begin
if @DepartmentList = ''
Set @DepartmentList = @DeptNo
Else
Set @DepartMentList = @DeptNo + @DepartmentList
goto ExitFunction
End
--返回1、2合集
--先取得用戶所在部門所在的處級部門代號
Set @TempDeptNo = ''
Set @TempDeptNo = dbo.fn_Dept_GetChiefDeptNo(@CompanyNo, @DeptNo)
If @TempDeptNo = '' Set @TempDeptNo = @DeptNo
Set @DepartmentList = dbo.fn_Dept_GetAllChildDeptNo(@CompanyNo, @TempDeptNo)
ExitFunction:
if Substring(@DepartmentList, 1,1) = ','
Set @DepartmentList = Substring(@DepartmentList, 2, Len(@DepartmentList)-1)
If Substring(@DepartmentList, Len(@DepartmentList), 1) = ','
Set @DepartmentList = Substring(@DepartmentList, 1, Len(@DepartmentList)-1)
return @DepartmentList
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Dept_GetChiefDeptNo
/****************************
* 功能:取得某部門所在的處級部門代號, 如果找不到,則返回原部門代號
* 作者:Billy
* 日期:2006/11/27
****************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(10)
)
RETURNS varchar(10)
As
Begin
Declare @ChiefDeptNo varchar(10), @ParentDeptNo varchar(10), @ChiefFlag char(1), @TempDeptNo varchar(10)
Select @ChiefDeptNo = '', @ParentDeptNo = '', @ChiefFlag = 'N', @TempDeptNo = @DeptNo
While( Exists( Select dept_no From Dept Where Dept_No = @TempDeptNo And Company_no = @CompanyNo ) )
Begin
Select @ParentDeptNo = parent_Dept_no, @ChiefFlag = Chief_Flag
From Dept Where Dept_No = @TempDeptNo And Company_No = @CompanyNo
if( @ChiefFlag = 'Y' ) --如果檢索到處級,則返回處級代碼並返回
Begin
Set @ChiefDeptNo = @TempDeptNo
goto ExitFunction
End
Set @TempDeptNo = @ParentDeptNo
End
ExitFunction:
Set @ChiefDeptNo = IsNull(@ChiefDeptNo, '')
If Ltrim(@ChiefDeptNo) = '' Set @ChiefDeptNo = @DeptNo
return @ChiefDeptNo
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE FUNCTION fn_Dept_GetChiefDeptNoFromUserNo
/*
功能:根據用戶帳號查詢用戶所在的處級部門代號
作者:Billy
說明:當處級部門代號為空時,返回用戶所在部門的代號
*/
(
@UserNo Varchar(20)
)
RETURNS Varchar(10)
AS
BEGIN
Declare @ChiefNo varchar(10), @DeptNo varchar(10)
Select @ChiefNo = dbo.fn_Dept_GetChiefDeptNo(Company_no,Dept_no) , @DeptNo = Dept_no From UserAdmin Where User_no = @UserNo
Set @DeptNo = IsNull(@DeptNo,'')
Set @ChiefNo = IsNull(@ChiefNo ,'')
If @ChiefNo = '' Set @ChiefNo = @DeptNo
Return @ChiefNo
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Dept_GetChiefShortCode
/****************************
* 功能:取得某部門所在處級的處級部門簡碼
* 作者:Billy
* 日期:2006/11/27
****************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(10)
)
RETURNS char(1)
As
Begin
Declare @ChiefShortCode char(1), @ParentDeptNo varchar(10), @ChiefFlag char(1)
Select @ChiefShortCode = '', @ParentDeptNo = '', @ChiefFlag = 'N'
While( Exists( Select * From Dept Where Dept_No = @DeptNo And Company_no = @CompanyNo ) )
Begin
Select @ChiefShortCode = Chief_short_code, @ParentDeptNo = parent_Dept_no, @ChiefFlag = Chief_Flag
From Dept Where Dept_No = @DeptNo And Company_No = @CompanyNo
if( @ChiefFlag = 'Y' ) --如果檢索到處級,則返回處級代碼並返回
goto ExitFunction
Else
Set @DeptNo = @ParentDeptNo
End
ExitFunction:
return @ChiefShortCode
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE function fn_GetDeputyFromUser(@UserNo varchar(20), @CurrentTime datetime)
/************************************************************************************
*介紹: 取得用戶的最終代理人帳號
*作者: Billy
*書寫時間: 2006/09/02
*返回: 返回代理人帳號,如果沒有代理人則返回@UserNo
*************************************************************************************/
returns varchar(20)
as
begin
Declare @Deputy varchar(20)
Set @Deputy = @UserNo
if Exists(Select * From DeputyInfo Where ByDeputy = @UserNo And (StartTime <= @CurrentTime And EndTime >= @CurrentTime))
Begin
Select @Deputy = Deputy From DeputyInfo Where ByDeputy = @UserNo And (StartTime <= @CurrentTime And EndTime >= @CurrentTime)
Set @Deputy = dbo.fn_GetDeputyFromUser(@Deputy, @CurrentTime)
End
return @Deputy
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Function fn_GetMinute(@dtStart datetime, @dtEnd datetime, @DefaultTime datetime)
/*
功能:取得兩個時間相隔的分
作者:Billy
日期:2007/02/08
參數說明:
@dtStart:開始時間
@dtEnd:結束時間
@DefaultTime:默認時間
*/
Returns int
As
Begin
Declare @MinuteCount int
Set @MinuteCount = 0
Set @dtStart = IsNull(@dtStart, @DefaultTime)
Set @dtEnd = IsNull(@dtEnd, @DefaultTime)
Set @MinuteCount = Datediff(Minute, @dtStart, @dtEnd)
Return ABS(@MinuteCount)
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Materiel_GetAllChildType( @CompanyNo varchar(10), @TypeNo int)
/******************************
功能:返回傳入物料類型的所有下屬類型的列表
作者:Billy
日期:2007/01/04
********************************/
returns varchar(2000)
Begin
Declare @TypeResult varchar(2000)
Declare @ID int
Select @TypeResult = @TypeNo , @ID = 1
Declare @TempTable Table( ID int IDentity(1,1), type_no varchar(10), superoir_Type_no varchar(10) )
Insert Into @TempTable Select type_no, superior_type_no From Materiel_Type Where superior_type_no = @TypeNo and company_no = @CompanyNo
While Exists(Select * From @TempTable Where ID = @ID)
Begin
Select @TypeNo = type_no From @TempTable Where ID = @ID
Set @ID = @ID + 1
Set @TypeResult = @TypeResult + ',' + dbo.fn_Materiel_GetAllChildType(@CompanyNo, @TypeNo)
End
Return @TypeResult
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_Menu_CheckMenuLevel( @WinNo varchar(20) )
/*****************************************
** 功能:檢查傳入的菜單代號屬於第幾級菜單
第一級:Parent_win_no = ''
第二級:parent_win_no != '' And Exists(Select * From Menu_List Where Parent_Win_no = @WinNo )
第三級:以上兩種情況除外
** 作者:Billy
** 日期:2006/10/28
** 參數:@WinNo
** 返回:1,2, 3
*****************************************/
Returns smallint
As
Begin
Declare @Result smallint, @ParentWinNo varchar(10)
Select @Result = 1, @ParentWinNo = ''
Select @ParentWinNo = Parent_Win_no From Menu_List Where Win_no = @WinNo
if @ParentWinNo = '' --第一級
Set @Result = 1
Else if( Exists(Select * From Menu_List Where Parent_Win_no = @WinNo ) ) --第二級
Set @Result = 2
Else
Begin
Select @ParentWinNo = Parent_Win_no From Menu_List Where Win_no = @WinNo
Select @ParentWinNo = Parent_Win_no From Menu_List Where Win_no = @ParentWinNo
if( @ParentWinNo = '' )
Set @Result = 2
else --第三級
Set @Result = 3
End
return @Result
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Function fn_Menu_HasChildMenu( @WinNo varchar(20) )
/*****************************************
** 功能:檢查傳入的菜單代號是否包含有下級菜單
** 作者:Billy
** 日期:2006/10/28
** 參數:@WinNo
** 返回:Y, N
*****************************************/
Returns char(1)
As
Begin
Declare @Result char(1)
Select @Result = 'N'
if( Exists( Select * From Menu_List Where Parent_win_no = @WinNO ) )
Set @Result = 'Y'
return @Result
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
---------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE function fn_ReplaceString
/* =============================================
--作者:電腦混混Vincent
--書寫時間:2006/08/07
--說明:置換掉輸入的字元串中的特殊字元( ' , -- )
--參數:@SourceString:輸入字元串
@RetrieveString :輸出字元串
-- =============================================*/
(
@SourceString varchar(4000)
)
returns varchar(4000)
as
begin
if CharIndex('''',@SourceString)>0
set @SourceString = replace(@SourceString,'''','''''')
if CharIndex('--',@SourceString)>0
set @SourceString = replace(@SourceString,'--','')
return @SourceString
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE function fn_SelectApproveSeq
/*************************************************
*介紹:得到某單據的前後簽核順序ApproveSeq
*作者:Billy
*書寫時間:2006/08/21
*傳入:單據NO
*說明:
*返回:approveSeq
*************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int , ----當前用戶的實際簽核順序
@cType char (1) ----1:前一位簽核用戶;2:後一位簽核用戶
)
returns int
as
begin
if not Exists(Select bill_no From person_d_Approve Where company_No = @CompanyNo and Kind_No = @KindNo and Bill_No = @BillNo) or @ApproveSeq < 1
return -12
Declare @tbApprove Table( ApproveSeq int)
declare @nApproveSeq int --記錄位置(Sequence)
--將簽核人員列表放入表變量中
Insert into @tbApprove
Select ApproveSeq From
(
Select ApproveSeq From Person_d_Approve P
Inner Join Action_Kind A On P.company_no = A.company_no and P.action_seq = A.action_Seq
Where P.company_No = @CompanyNo and P.Kind_No = @KindNo and P.Bill_No = @BillNo and A.approve = 'Y'
) M
Set @nApproveSeq = -1
if( @cType = '1' ) --前一位用戶
Begin
Select @nApproveSeq = Max(ApproveSeq) From @tbApprove Where ApproveSeq < @ApproveSeq
Goto ExitFunction
End
if( @cType = '2' ) --後一位用戶
Begin
Select @nApproveSeq = min(ApproveSeq) From @tbApprove Where ApproveSeq > @ApproveSeq
Goto ExitFunction
End
ExitFunction:
Set @nApproveSeq = IsNull(@nApproveSeq, -1)
return @nApproveSeq
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE function fn_SelectUserApproveTimeCost
/*************************************************
*介紹:取當前用戶的簽核用時
*作者:Billy
*書寫時間:2006/08/21
*主要用於顯示單據詳細信息(簽核用時)
*************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int,
@DefaultTime dateTime ----系統時間 getdate()
)
returns int
as
begin
declare @sTimeCost varchar(30) --用於返回
declare @nApproveMinuteSpan int --當前用戶簽核用時(分)
declare @dtCurrentUserApproveTime datetime --當前用戶簽核時間
declare @dtPreviousUserApproveTime datetime --前一位用戶簽核時間
Declare @PreviousApproveSeq int --上一位簽核用戶的簽核順序
Declare @TabbleName varchar(60)
Declare @Sql nVarchar(2000)
Declare @tbApprove Table(ID int identity(1,1), ApproveSeq int, Approve_Sign char(1), Approve_Date datetime)
--傳入參數有誤
if @ApproveSeq < 1
return 1
if( Exists( Select Bill_No From Bill_M_Approve Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo) )
Begin
Insert into @tbApprove
Select * From
(
Select ApproveSeq,Approve_Sign,Approve_Date From Person_d_Approve PA
Inner join Action_Kind Ak On PA.company_no=AK.company_no and PA.action_seq=AK.action_seq
Where AK.Approve='Y' and PA.company_no=@CompanyNo and PA.kind_no=@KindNo and PA.bill_no=@BillNo
And PA.ApproveSeq<@ApproveSeq
)M
--取得當前順序的簽核用戶的簽核時間
select @dtCurrentUserApproveTime=isnull(approve_date, @DefaultTime) from Person_d_Approve
where Company_No=@CompanyNo and Kind_no=@KindNo and bill_no=@BillNo and approveSeq=@ApproveSeq
--檢查是否為第一個簽核用戶,如果是,上一簽核時間取建單時間
if Not Exists(Select * From @tbApprove)
Begin
Select @dtPreviousUserApproveTime = Create_Date From Bill_M_Approve
Where company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo
End
Else
Begin
Select @PreviousApproveSeq = Max(ApproveSeq) From @tbApprove
Select @dtPreviousUserApproveTime = Approve_Date From @tbApprove
Set @dtPreviousUserApproveTime = IsNull(@dtPreviousUserApproveTime, @DefaultTime)
End
End
Else --在結案表中
Begin
Insert into @tbApprove
Select * From
(
Select ApproveSeq,Approve_Sign,Approve_Date From Person_d_Approved PA
Inner join Action_Kind Ak On PA.company_no=AK.company_no and PA.action_seq=AK.action_seq
Where AK.Approve='Y' and PA.company_no=@CompanyNo and PA.kind_no=@KindNo and PA.bill_no=@BillNo
And PA.ApproveSeq<@ApproveSeq
)M
--取得當前順序的簽核用戶的簽核時間
select @dtCurrentUserApproveTime=isnull(approve_date, @DefaultTime) from Person_d_Approved
where Company_No=@CompanyNo and Kind_no=@KindNo and bill_no=@BillNo and approveSeq=@ApproveSeq
--檢查是否為第一個簽核用戶,如果是,上一簽核時間取建單時間
if Not Exists(Select * From @tbApprove)
Begin
Select @dtPreviousUserApproveTime = Create_Date From Bill_M_Approved
Where company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo
End
Else
Begin
Select @PreviousApproveSeq = Max(ApproveSeq) From @tbApprove
Select @dtPreviousUserApproveTime = Approve_Date From @tbApprove
Set @dtPreviousUserApproveTime = IsNull(@dtPreviousUserApproveTime, @DefaultTime)
End
End
set @nApproveMinuteSpan = datediff(mi , @dtPreviousUserApproveTime , @dtCurrentUserApproveTime)
return abs(@nApproveMinuteSpan)
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Function fn_Technic_getItemCounts
/****************************
* 功能:取得指定分類的項目總數(包括其下屬的分類項目數)
* 作者:Billy
* 日期:2006/09/12
****************************/
(
@TypeNo int,
@UserNo varchar(20)
)
RETURNS int
As
Begin
Declare @tempTable Table(ID int Identity(1,1), type_no int)
Declare @ID int, @Count int, @ParentNo int
Select @Count = 0, @ID = 1
--取得當前分類下的項目數
Select @Count = Count(*) From TechnicItem Where User_no = @UserNo And type_no = @TypeNo
--將當前分類下的下級分類存入到表變量中
Insert Into @tempTable Select type_no From TechnicType where user_no = @UserNo And parent_Type_No = @TypeNo
While( Exists(Select * From @tempTable Where ID = @ID ) )
Begin
Select @TypeNo = type_no From @tempTable Where ID = @ID
set @Count = @Count + OA.dbo.fn_Technic_getItemCounts(@TypeNo, @UserNo)
Set @ID = @ID + 1
End
return @Count
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Function fn_Technic_getTypePath
/****************************
* 功能:取得當前分類的所有上級分類代號,以 / 分隔
* 作者:Billy
* 日期:2006/09/12
****************************/
(
@TypeNo int,
@UserNo varchar(20)
)
RETURNS varchar(500)
As
Begin
Declare @TypePath varchar(500), @TempTypeNo int
Set @TypePath = ''
if Exists(Select * From TechnicType Where Type_No = @TypeNo And User_No = @UserNo)
Begin
Set @TypePath = Cast(@TypeNo As Varchar)
While Exists(Select * From TechnicType Where Type_No = @TypeNo And User_No = @UserNo)
Begin
Select @TypeNo = Parent_type_no From TechnicType Where Type_No = @TypeNo And User_No = @UserNo
--Set @TypeNo = IsNull(@TypeNo, 0)
Set @TypePath = Cast(@TypeNo As Varchar) + '/' + @TypePath
End
End
return @TypePath
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION fn_UserDepartment(@UserNo varchar(20) )
RETURNS nvarchar(100)
AS
BEGIN
declare @Retrieve nvarchar(100), @CompanyNo varchar(10), @DeptNo varchar(10), @Exit char(1), @ChiefFlag char(1)
set @Retrieve=''
Select @Exit ='N', @ChiefFlag = 'N'
select @CompanyNo = Company_no, @DeptNo=dept_no from useradmin where user_no=@UserNo
if( @CompanyNo Is Null Or @DeptNo Is Null )
Return ''
while @Exit != 'Y' and @ChiefFlag != 'Y'
begin
if Exists( Select * From Dept Where company_no = @CompanyNo and Dept_no = @DeptNo)
select @Retrieve=dept_nm+'→'+@Retrieve,@DeptNo=case isnull(parent_dept_no,'') when '' then '' else parent_dept_no end, @ChiefFlag = chief_Flag
from dept where company_no = @CompanyNo and dept_no=@DeptNo
Else
Set @Exit ='Y'
end
--select @Retrieve=company_nm+'→'+@Retrieve from useradmin M inner join company C on M.company_no=C.company_no where M.user_no=@UserNo
if len(@Retrieve)>0
Begin
if SubString(@Retrieve, Len(@Retrieve), 1) = '→'
set @Retrieve=substring(@Retrieve,1,len(@Retrieve)-1)
End
return(@Retrieve)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE FUNCTION fn_User_CheckRole
/*
功能:檢查傳入的用戶角色是否爲管理員
作者:Billy
日期:2007/05/25
*/
(
@UserNo varchar(20)
)
RETURNS bit
AS
BEGIN
Declare @UserRole char(1)
Declare @Result bit
Set @UserRole = '1'
Set @Result = 0
If Exists(Select User_No From UserAdmin where user_no = @UserNo)
Begin
Select @UserRole = role_level From userAdmin where user_no = @UserNo
End
If @UserRole = '2'
Set @Result = 1
Return @Result
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Function fn_User_GetPositionName(@UserNo varchar(20) )
/*****************************************
** 功能:根據用戶代號取得用戶姓名
** 作者:Billy
** 日期:2006/12/11
** 參數:@CompanyNo, @UserNo
** 返回:用戶姓名
*****************************************/
Returns varchar(30)
As
Begin
Declare @CompanyNo varchar(10), @PositionNo varchar(10), @PositionName varchar(30)
If( Exists(Select user_no From UserAdmin Where User_no = @UserNo) )
Begin
Select @PositionNo = Position_no , @CompanyNo = Company_no From UserAdmin Where User_no = @UserNo
Select @PositionName = position_name From Position Where company_no = @CompanyNo and Position_no = @PositionNo
End
Set @PositionName = IsNull(@PositionName, '')
Return @PositionName
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Function fn_User_GetUserName(@UserNo varchar(20) )
/*****************************************
** 功能:根據用戶代號取得用戶姓名
** 作者:Billy
** 日期:2006/12/11
** 參數:@CompanyNo, @UserNo
** 返回:用戶姓名
*****************************************/
Returns varchar(15)
As
Begin
Declare @UserName varchar(15)
Select @UserName = User_name From UserAdmin Where @UserNo = User_no
Set @UserName = IsNull(@UserName, '')
Return @UserName
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE TABLE [dbo].[Assistant] (
[Seq] [int] NOT NULL ,
[Director_No] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[Assistant_No] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[AssistantName] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Email] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[DeputyInfo] (
[seq] [int] NOT NULL ,
[ByDeputy] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[Deputy] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[StartTime] [smalldatetime] NOT NULL ,
[EndTime] [smalldatetime] NOT NULL ,
[JoinDate] [smalldatetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[MENU_LIST] (
[win_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[win_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[win_note] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[parent_win_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[c_everyone] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_browse] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_new] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_modify] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_del] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_print] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_approve] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_visible] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_dept] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[seq] [int] NOT NULL ,
[large_icon] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[open_type] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[program_path] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Message] (
[ID] [int] NOT NULL ,
[Send_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Incept_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[read_sign] [bit] NULL ,
[subject] [nvarchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [nvarchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[send_date] [datetime] NULL ,
[read_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Results] (
[win_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[large_icon] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[TechnicItem] (
[item_no] [int] NOT NULL ,
[type_no] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[title] [nvarchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[file_path] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Content] [ntext] COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_date] [datetime] NULL ,
[modify_date] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[TechnicType] (
[type_no] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[type_name] [nvarchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[parent_type_no] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[Temp] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[ApproveSeq] [int] NOT NULL ,
[action_seq] [int] NULL ,
[chief_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[actual_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_grade] [int] NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL ,
[mark_name] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_sign] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Add_ApproveUser] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fillin] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[prompt] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[EndCase] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Condition] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[action_kind] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[action_seq] [int] NOT NULL ,
[action_nm] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[approve] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[PRI] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[address_contact] (
[address_id] [int] NOT NULL ,
[tel_id] [int] NOT NULL ,
[type_id] [int] NULL ,
[section] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[contact] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[is_default] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[address_group] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[group_id] [int] NOT NULL ,
[group_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[default_group] [bit] NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[private] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[address_list] (
[address_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[private] [bit] NULL ,
[security] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[owner] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[group_id] [int] NULL ,
[last_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[first_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[person_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[sex] [bit] NULL ,
[birthday] [datetime] NULL ,
[appellative] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[f_country] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[f_province] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[f_city] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[f_postalcode] [varchar] (6) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[f_address] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_company] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[duty] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[department] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_country] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_province] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_city] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_postalcode] [varchar] (6) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[c_address] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[other] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[join_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[address_number_type] (
[type_id] [int] NOT NULL ,
[type_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[default_type] [bit] NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[private] [bit] NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[affiche] (
[affiche_id] [int] NOT NULL ,
[title] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[leaveword] [bit] NULL ,
[everyone] [bit] NULL ,
[importance_level] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[browse_times] [int] NULL ,
[issue_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[issue_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[affiche_file] (
[affiche_id] [int] NOT NULL ,
[file_id] [int] NOT NULL ,
[file_path] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[file_name] [varchar] (128) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[true_name] [varchar] (128) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[affiche_incept] (
[affiche_id] [int] NOT NULL ,
[incept_id] [int] NOT NULL ,
[company_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[include_junior] [bit] NULL ,
[incept_security] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[affiche_leaveword] (
[affiche_id] [int] NOT NULL ,
[leaveword_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (255) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[leaveword_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[assistant_overture] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_approve_log] (
[seq] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_seq] [int] NULL ,
[operate_result] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_approve_validate] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[setting_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[actual_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[validate_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_approve_validate_file] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[seq] [int] NULL ,
[file_id] [smallint] NULL ,
[file_path] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_approve_validate_log] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[log_id] [int] NOT NULL ,
[setting_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[actual_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[validate_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_approved_log] (
[seq] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_seq] [int] NULL ,
[operate_result] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_code_formula] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[formula] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_column] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[column_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[column_title] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[belong_table] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[column_kind] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_length] [int] NULL ,
[row_seq] [int] NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approver_input] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[read_only] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[default_value] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[selection_mode] [char] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[display_format] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_column_display] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[column_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[seq] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_exception_kind] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[exception_no] [char] (2) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[exception_name] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_file] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[file_path] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_file_done] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[file_path] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_flow_d] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[flowitem_id] [int] NOT NULL ,
[seq] [int] NOT NULL ,
[flow_mode] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[action_seq] [int] NOT NULL ,
[local_dept] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[IsUndertaker] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[position_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Add_ApproveUser] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fillin] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[prompt] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[EndCase] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Condition] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_flow_m] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[flow_mode] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[flow_id] [int] NOT NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_item_approve] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[item_001] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[item_002] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[item_003] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[item_004] [int] NULL ,
[item_005] [int] NULL ,
[item_006] [int] NULL ,
[item_007] [decimal](16, 4) NULL ,
[item_008] [decimal](16, 4) NULL ,
[item_009] [decimal](16, 4) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_item_approved] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[item_001] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[item_002] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[item_003] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[item_004] [int] NULL ,
[item_005] [int] NULL ,
[item_006] [int] NULL ,
[item_007] [decimal](16, 4) NULL ,
[item_008] [decimal](16, 4) NULL ,
[item_009] [decimal](16, 4) NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_item_column] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[column_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[column_title] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[belong_table] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[column_kind] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_length] [int] NULL ,
[row_seq] [int] NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approver_input] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[read_only] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[default_value] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[selection_mode] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dispaly_format] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_kind] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_short_code] [varchar] (2) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[formula] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate_choose] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_m_approve] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[native_bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[exigency_grade] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_001] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_002] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_003] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_004] [datetime] NULL ,
[field_005] [datetime] NULL ,
[field_006] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_007] [decimal](16, 4) NULL ,
[field_008] [datetime] NULL ,
[field_009] [decimal](16, 4) NULL ,
[field_010] [decimal](16, 4) NULL ,
[field_011] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_012] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_013] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_014] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_015] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_016] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_017] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_018] [decimal](16, 4) NULL ,
[field_019] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_020] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_021] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_022] [decimal](16, 4) NULL ,
[field_023] [datetime] NULL ,
[field_024] [int] NULL ,
[field_025] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_026] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_027] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_028] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_029] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_030] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_031] [int] NULL ,
[field_032] [int] NULL ,
[field_033] [int] NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[effect_validate_pass] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[complete_date] [datetime] NULL ,
[current_approveseq] [int] NULL ,
[previous_approve_time] [datetime] NULL ,
[Auditing] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[modify_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_m_approved] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[native_bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[exigency_grade] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_001] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_002] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_003] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_004] [datetime] NULL ,
[field_005] [datetime] NULL ,
[field_006] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_007] [decimal](16, 4) NULL ,
[field_008] [datetime] NULL ,
[field_009] [decimal](16, 4) NULL ,
[field_010] [decimal](16, 4) NULL ,
[field_011] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_012] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_013] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_014] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_015] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_016] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_017] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_018] [decimal](16, 4) NULL ,
[field_019] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_020] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_021] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_022] [decimal](16, 4) NULL ,
[field_023] [datetime] NULL ,
[field_024] [int] NULL ,
[field_025] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_026] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_027] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_028] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_029] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_030] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[field_031] [int] NULL ,
[field_032] [int] NULL ,
[field_033] [int] NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[effect_validate_pass] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[complete_date] [datetime] NULL ,
[current_approveseq] [int] NULL ,
[previous_approve_time] [datetime] NULL ,
[Auditing] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[modify_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[bill_security] (
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[c_search] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[c_new] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[r_browse] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[r_print] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_amends] (
[amends_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_name] [varchar] (12) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[company_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[borrow_date] [datetime] NULL ,
[book_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[company] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[department] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[book_concern] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[author] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[publish_date] [datetime] NULL ,
[price] [decimal](16, 4) NULL ,
[buy_date] [datetime] NULL ,
[amends_money] [decimal](16, 2) NULL ,
[operate_date] [datetime] NULL ,
[amends_cause] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[operate_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_borrow_apply] (
[apply_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[lower_id] [int] NOT NULL ,
[book_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[borrow_date] [datetime] NULL ,
[return_date] [datetime] NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[submit_date] [datetime] NULL ,
[approver] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fact_approver] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_info] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_borrow_history] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[lower_id] [int] NOT NULL ,
[book_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[apply_date] [datetime] NOT NULL ,
[approve_date] [datetime] NULL ,
[status] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_borrowed] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[lower_id] [int] NOT NULL ,
[book_id] [int] NOT NULL ,
[borrower] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[borrow_date] [datetime] NULL ,
[giveback_date] [datetime] NULL ,
[actual_giveback_date] [datetime] NULL ,
[giveback] [bit] NULL ,
[note] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[granter] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fact_granter] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[operater] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_deposit] (
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[pay_date] [datetime] NULL ,
[deposit] [decimal](9, 2) NULL ,
[handlers] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_lower_type] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[type_id] [int] NOT NULL ,
[lower_id] [int] NOT NULL ,
[lower_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[book_type] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[type_id] [int] NOT NULL ,
[type_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[books] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[lower_id] [int] NOT NULL ,
[book_id] [int] NOT NULL ,
[chief_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[book_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[state] [bit] NULL ,
[book_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[book_image] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[miniature_image] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[book_concern] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[author] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[publish_date] [datetime] NULL ,
[price] [decimal](16, 2) NULL ,
[edition] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[spec] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[buy_date] [datetime] NULL ,
[page_size] [int] NULL ,
[bar_code] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[stocks] [int] NULL ,
[loans] [int] NULL ,
[recomment] [bit] NULL ,
[lease] [bit] NULL ,
[create_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[company] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[short_code] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[company_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[boss] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fax] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[address] [varchar] (80) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[contribute] (
[contribute_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_date] [datetime] NULL ,
[title] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[new_path] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_info] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[customer] (
[customer_id] [int] NOT NULL ,
[customer_no] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[company] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[corporation] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[register_date] [datetime] NULL ,
[calling] [int] NULL ,
[area] [int] NULL ,
[state] [int] NULL ,
[customer_grade] [int] NULL ,
[quarry] [int] NULL ,
[customer_type] [int] NULL ,
[character] [int] NULL ,
[reality] [bit] NULL ,
[province] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[city] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[post_code] [varchar] (6) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[address_zh] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[address_en] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fax] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[homepage] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[bank] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[bank_account] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[customer_linkman] (
[customer_id] [int] NOT NULL ,
[linkman_id] [int] NOT NULL ,
[linkman_name] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[department] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[position] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[sex] [bit] NULL ,
[birthday] [datetime] NULL ,
[native_place] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[appellation] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[responsibility] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[contact_grade] [int] NULL ,
[credit_grade] [int] NULL ,
[role_grade] [int] NULL ,
[master] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[customer_linkman_d] (
[customer_id] [int] NOT NULL ,
[linkman_id] [int] NOT NULL ,
[contact_id] [int] NOT NULL ,
[contact_type] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[contact_value] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[customer_property] (
[property_id] [int] NOT NULL ,
[property_type] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[property_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[dept] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[dept_level_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[chief_short_code] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[chief_flag] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[chief_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[boss] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[parent_dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[dept_depth] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[dept_level_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[dept_level_name] [nvarchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_depth] [int] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[dept_tmp_for_employee] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_nm] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[parent_dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[chief_flag] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[level] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[directory] (
[diectory_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[directory_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[parent_directory_id] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[directory_setting] (
[user_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[max_size] [smallint] NULL ,
[directory_amount] [smallint] NULL ,
[file_amount] [smallint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[dispatch_column] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[destination] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[person] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[retinue] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[begin_time] [datetime] NULL ,
[end_time] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[dispatch_kind] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[divan] (
[divan_id] [int] NOT NULL ,
[divan_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[divan_name] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[owner_dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[divan_size] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[lodge_amount] [int] NULL ,
[has_video] [bit] NULL ,
[has_audio] [bit] NULL ,
[state] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel_1] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel_2] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel_3] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[address] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[divan_description] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[divan_apply_list] (
[divan_id] [int] NOT NULL ,
[apply_id] [int] IDENTITY (1, 1) NOT NULL ,
[apply_user] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[register_date] [datetime] NULL ,
[user_name] [varchar] (12) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_dept] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[begin_date] [datetime] NULL ,
[end_date] [datetime] NULL ,
[subject] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[attend_dept] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[apply_date] [datetime] NULL ,
[exigency_grade] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[flag] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Approve_user] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL ,
[register] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[driver] (
[driver_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[driver_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[sex] [bit] NULL ,
[allow_kind] [varchar] (2) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[birthday] [smalldatetime] NULL ,
[identity_card] [varchar] (18) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[licence] [varchar] (18) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[address] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[get_date] [smalldatetime] NULL ,
[native_place] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[photo] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[job_date] [smalldatetime] NULL ,
[dimission_date] [smalldatetime] NULL ,
[dimission_cause] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[employee] (
[employee_id] [int] NOT NULL ,
[employee_no] [varchar] (8) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[employee_name] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[sex] [bit] NULL ,
[register_date] [datetime] NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[id_card] [varchar] (18) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[marriage] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[nationality] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[native_place] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[nation] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[birthday] [datetime] NULL ,
[position_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[family_address] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[post_code] [varchar] (6) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[educate_grade] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[school] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dimission_date] [datetime] NULL ,
[dimission_mode] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dimission_cause] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[home_tel] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[handset_tel] [varchar] (12) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[exigency_address] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[photo] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[error_code] (
[product_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[error_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[error_nm] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[note] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[expense_kind] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_id] [int] NOT NULL ,
[kind_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[expense_list] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[expense_id] [int] NULL ,
[kind_id] [int] NULL ,
[t_money] [float] NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[file_list] (
[directory_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[file_id] [int] NOT NULL ,
[upload_name] [varchar] (128) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[save_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[file_type] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[file_size] [int] NULL ,
[up_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[group_setting] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[group_no] [varchar] (6) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[group_nm] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[library_card] (
[card_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[register_date] [datetime] NULL ,
[foregift] [decimal](16, 2) NULL ,
[certificate_kind] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[certificate_code] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[borrow_books] [smallint] NULL ,
[enable] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[maintain_kind] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_id] [int] NOT NULL ,
[kind_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[materiel_list] (
[company_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[type_no] [int] NOT NULL ,
[materiel_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[ID] [float] NOT NULL ,
[spec] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[unit] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[money_type] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[last_price] [decimal](16, 8) NULL ,
[base_price] [decimal](16, 8) NULL ,
[remark] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_date] [datetime] NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[modify_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[materiel_type] (
[company_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[type_no] [int] NOT NULL ,
[superior_type_no] [int] NULL ,
[materiel_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[remark] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[message_content] (
[message_id] [int] IDENTITY (1, 1) NOT NULL ,
[send_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[subject] [nvarchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[content] [nvarchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[send_date] [datetime] NOT NULL ,
[emphasis] [bit] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[message_person] (
[seq] [int] IDENTITY (1, 1) NOT NULL ,
[message_id] [int] NOT NULL ,
[Incept_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[read_sign] [bit] NULL ,
[read_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[news_list] (
[news_id] [int] NOT NULL ,
[type_id] [int] NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[security] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[title] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[new_file] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[source] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[editor] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[issue_date] [datetime] NULL ,
[browse_times] [int] NULL ,
[hotspot] [bit] NULL ,
[recommend] [bit] NULL ,
[big_news] [bit] NULL ,
[contribute] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[news_review] (
[news_id] [int] NOT NULL ,
[review_id] [int] NOT NULL ,
[review_date] [datetime] NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[ip] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[news_type] (
[type_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[type_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[online_user] (
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[computer_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[ip] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[login_time] [datetime] NULL ,
[refresh_time] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[person_approve_file] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[seq_file] [int] NOT NULL ,
[file_path] [nvarchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[person_approved_file] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[seq_file] [int] NOT NULL ,
[file_path] [nvarchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[person_d_approve] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[ApproveSeq] [int] NOT NULL ,
[action_seq] [int] NULL ,
[chief_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[actual_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_grade] [int] NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL ,
[mark_name] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_sign] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Add_ApproveUser] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fillin] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[prompt] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[EndCase] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Condition] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Create_Person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[person_d_approved] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[seq] [int] NOT NULL ,
[ApproveSeq] [int] NOT NULL ,
[action_seq] [int] NULL ,
[chief_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[actual_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_grade] [int] NULL ,
[note] [varchar] (6000) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_date] [datetime] NULL ,
[mark_name] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_sign] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Add_ApproveUser] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[fillin] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[effect_validate] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[prompt] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[EndCase] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Condition] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll] (
[poll_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[poll_security] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[poll_kind] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[subject] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[poll_alow] [bit] NULL ,
[content] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[end_date] [datetime] NULL ,
[create_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_option] (
[poll_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[option_id] [int] NOT NULL ,
[seq] [int] NULL ,
[option] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[counts] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_review] (
[poll_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[review_id] [int] NOT NULL ,
[review_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[publish_date] [datetime] NULL ,
[content] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[ip] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[poll_user] (
[poll_id] [int] NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[option_id] [int] NOT NULL ,
[poll_user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[poll_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[position] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[position_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[depth_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[position_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[dept_director] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[position_depth] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[depth_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[depth_name] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[depth] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[product_kind] (
[product_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_nm] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[note] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[product_style] (
[product_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[style_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[style_nm] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[note] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[create_date] [datetime] NOT NULL ,
[modify_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[modify_date] [datetime] NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[record] (
[seq] [int] NOT NULL ,
[record_date] [datetime] NOT NULL ,
[win_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[action_type] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[note] [varchar] (300) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[security] (
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[win_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_browse] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_new] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_modify] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_del] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_print] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_approve] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[p_visible] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[send_mail_log] (
[Seq] [int] NOT NULL ,
[mail_from] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_to] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_cc] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_subject] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_body] [ntext] COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_pass] [bit] NULL ,
[send_time] [datetime] NULL ,
[note] [varchar] (200) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[thread_sendmail] (
[Seq] [int] NOT NULL ,
[mail_from] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_to] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_cc] [varchar] (500) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_subject] [nvarchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mail_body] [ntext] COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[join_date] [datetime] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
CREATE TABLE [dbo].[use_phrase] (
[seq] [int] NOT NULL ,
[system_phrase] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[phrase_content] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_date] [datetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[user_company] (
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[useradmin] (
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[user_password] [varchar] (32) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_name] [varchar] (12) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[position_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[email] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[tel] [varchar] (15) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[dept_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[approve_grade] [int] NULL ,
[role_level] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[group_no] [varchar] (6) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mark_name] [varchar] (60) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[active_date] [datetime] NOT NULL ,
[disable_date] [datetime] NOT NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[online_mark] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[email_inform] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[window] [bit] NULL ,
[incumbency] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vegicle_image] (
[image_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[description] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[image_path] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehcile_maintain] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[maintain_id] [int] NOT NULL ,
[maintain_date] [smalldatetime] NULL ,
[duty_visit] [bit] NULL ,
[Kilometer] [int] NULL ,
[causation] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[repair_shop] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[complete_date] [smalldatetime] NULL ,
[result] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[upkeep] [decimal](10, 2) NULL ,
[complete] [bit] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehcile_maintain_list] (
[list_id] [int] NOT NULL ,
[maintain_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_id] [int] NULL ,
[price] [decimal](7, 2) NULL ,
[amount] [smallint] NULL ,
[t_money] [decimal](7, 2) NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehiche_use_register] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[driver_id] [int] NULL ,
[department] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[user_no] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[destination] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[use_mode] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[retinue] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[leave_time] [datetime] NULL ,
[Kilometer] [int] NULL ,
[return_time] [datetime] NULL ,
[return_Kilometer] [int] NULL ,
[run_Kilometer] [int] NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehicle] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[brand] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[content] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[car_kind] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[driver] [int] NULL ,
[buy_date] [smalldatetime] NULL ,
[price] [decimal](16, 4) NULL ,
[init_Kilometer] [int] NULL ,
[Displacement] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[status] [char] (1) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Oil_consumption] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[engine_number] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[carriage] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[load] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[seating] [tinyint] NULL ,
[color] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[create_date] [datetime] NULL ,
[create_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehicle_accident] (
[accident_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[driver_id] [int] NULL ,
[happen_date] [datetime] NULL ,
[place] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[confirm_person] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[summary] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[causation] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[mangle_grade] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[compromise] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[duty_cognizance] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[party_name] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[party_tel] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[party_department] [varchar] (50) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[party_card_kind] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[party_number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[party_mangle_grade] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[assume_money] [decimal](10, 2) NULL ,
[party_assume_money] [decimal](10, 2) NULL ,
[damage] [decimal](10, 2) NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehicle_examine] (
[examine_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ,
[check_date] [smalldatetime] NULL ,
[check_kind] [varchar] (20) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[next_date] [smalldatetime] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehicle_gas] (
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[kind_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[bill_no] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[gas_id] [int] NOT NULL ,
[fill_date] [datetime] NULL ,
[previous_Kilometer] [int] NULL ,
[gas_station] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[previous_fill_date] [datetime] NULL ,
[gas_kind] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[Kilometer] [int] NULL ,
[fill_count] [decimal](7, 2) NULL ,
[price] [decimal](10, 2) NULL ,
[t_money] [decimal](10, 2) NULL ,
[note] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[vehicle_insure] (
[insure_id] [int] NOT NULL ,
[company_no] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[number_plate] [varchar] (10) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[insure_date] [smalldatetime] NULL ,
[end_date] [smalldatetime] NULL ,
[insurer] [varchar] (30) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL ,
[note] [varchar] (100) COLLATE Chinese_Taiwan_Stroke_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.VIEW1
AS
SELECT dbo.useradmin.user_name, dbo.useradmin.dept_no, dbo.dept.dept_nm,
dbo.dept.dept_no AS Expr1
FROM dbo.useradmin LEFT OUTER JOIN
dbo.dept ON dbo.useradmin.dept_no = dbo.dept.dept_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.[user]
AS
SELECT dbo.useradmin.user_no, dbo.useradmin.user_name, dbo.useradmin.email,
dbo.useradmin.tel, dbo.[position].position_name, dbo.dept.dept_nm,
dbo.group_setting.group_nm
FROM dbo.useradmin LEFT OUTER JOIN
dbo.group_setting ON
dbo.useradmin.group_no = dbo.group_setting.group_no LEFT OUTER JOIN
dbo.dept ON dbo.useradmin.dept_no = dbo.dept.dept_no LEFT OUTER JOIN
dbo.[position] ON dbo.useradmin.position_no = dbo.[position].position_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************************
*介紹:辦公自動化OA系統 (刪除會議列表)
*作者:YM
*書寫時間:2007/05/09
*傳入:會議列表@DivanID
*說明:涉及表名[divan,divan_apply_list,divan_use_history]
*********************************************/
CREATE proc Divan_SelectDivanByDivanID
(
@DivanID int
)
AS
select * from divan where divan_id = @DivanID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc Pr_Bill_GetAllApproveUser
/*****************************
功能:取得單據中所有的簽核用戶的姓名、部門、職務、Email地址信息(包含代理簽核與預設用戶)
以在單據結案後發送郵件通知
作者:Billy
日期:2007/02/11
返回:所有參與簽核的用戶列表(包括預設、代理的用戶)
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
Declare @Sql nVarchar(400), @TableName varchar(60)
Declare @ID int, @RowCount int
Declare @UserNo varchar(20)
Create Table #tbUserList( ID int IDentity(1,1), User_No varchar(20), default_user char(1)) --default_user:1預設用戶 2代理用戶 3工作助手
Create Table #tbTemp (ID int IDentity(1,1), User_no varchar(20))
if Exists(Select Bill_no From Bill_M_Approve Where company_no = @CompanyNo and Kind_no = @kindNo and Bill_no = @BillNo)
Set @TableName = 'Person_d_Approve'
Else
Set @TableName = 'Person_d_Approved'
Set @Sql = N'Select Distinct User_no, ''1'' default_user From ' + @TableName + ' Where company_no = @CompanyNo and Kind_no = @kindNo and Bill_no = @BillNo'
Insert Into #tbUserList Execute Sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)',
@CompanyNo, @KindNo, @BillNo
Set @Sql = N'Select actual_user_no From ' + @TableName + ' Where company_no = @CompanyNo and Kind_no = @kindNo and Bill_no = @BillNo and user_no != actual_user_no'
Insert into #tbTemp Execute Sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)',
@CompanyNo, @KindNo, @BillNo
Set @ID = 1
Set @UserNo = ''
Select @RowCount = Count(*) From #tbTemp
While @ID <= @RowCOunt
Begin
Select @UserNo = user_no From #tbTemp Where ID = @ID
if @UserNo is Not Null And @UserNo != ''
Begin
if Not Exists( Select * From #tbUserList Where User_no = @UserNo)
Insert into #tbUserList (User_no, default_user)Values(@UserNo, '2')
End
Set @ID = @ID + 1
End
--添加工作助手的郵件
Insert into #tbUserList Select Assistant_No, '3' Default_User From Assistant Where (Director_no In(Select User_no From #tbUserList Where Default_User = '1') and Assistant_no Not In(Select User_No From #tbUserList))
Select M.default_user,U.User_no,U.User_name, P.Position_name, U.email, dbo.fn_DepartmentFrame(U.company_no, U.dept_no) Department
From #tbUserList M
Inner Join UserAdmin U On M.user_no = U.user_no
Left Join Position P On U.company_no = P.company_no And U.position_no = P.position_no
Where U.email_inform = 'Y' and U.email != '' And U.email Is Not Null
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc Pr_Bill_GetNeedEffectValidateUserList
/*****************************
功能:取得需要進行效果確認的用戶的姓名列表
作者:Billy
日期:2007/02/11
返回:所有需要進行效果確認的用戶姓名列表
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
declare @TableName Nvarchar(60)
Declare @MainName Nvarchar(60)
Declare @Sql Nvarchar(3000)
If Exists(Select Bill_No From Person_D_Approve Where Company_no=@CompanyNo and Kind_no =@KindNo and Bill_No = @BillNo)
Set @TableName = N'Person_d_Approve'
ELse
Set @TableName = N'Person_d_Approved'
Set @Sql = 'Select U.user_Name, U.Email From ' + @TableName + ' B Inner Join UserAdmin U On B.user_no = U.user_no '
+ 'Where U.email_inform = ''Y'' and B.company_no = @CompanyNo and B.kind_no = @KindNo and B.bill_no = @BillNo '
+ 'And B.Effect_Validate=''Y'' and U.email != '''' And U.email is not null '
Exec sp_ExecuteSql @Sql, N'@CompanyNo varchar(10),@KindNo varchar(10),@BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室登記確認)
*作者:Ym
*書寫時間:2007/05/15
*傳入:
*頁面:DivanApprove
*說明:涉及表名[divan_apply_list]
*********************************/
CREATE proc Pr_Divan_ApplyUseDivan
(
@ID int,
@apply_user varchar(20)
)
AS
update divan_apply_list set register =1 ,register_date=getdate() where apply_id =@ID and apply_user =@apply_user
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室檢查申請日期是否存在)
*作者:Ym
*書寫時間:2007/05/20
*傳入:
*說明:涉及表名[ divan_apply_list]
*********************************/
Create proc Pr_Divan_CheckdateByRegister
(
@ID int=0,
@begin_date datetime,
@end_date datetime
)
As
select * from divan_apply_list where begin_date=@begin_date and end_date =@end_date and divan_id = @ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************************
*介紹:辦公自動化OA系統 (刪除會議列表)
*作者:YM
*書寫時間:2007/05/09
*傳入:會議列表@DivanID
*說明:涉及表名[divan,divan_apply_list,divan_use_history]
*********************************************/
CREATE proc Pr_Divan_DeleteDivan
(
@DivanID int
)
AS
begin transaction
delete divan_apply_list where divan_id = @DivanID
delete divan where divan_id = @DivanID
if(@@error!=0)
rollback transaction
else
commit transaction
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室歷史登記查詢)
*作者:Ym
*書寫時間:2007/05/15
*傳入:
*頁面:DivanHistory
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE proc Pr_Divan_DivanHistory
(
@DeptName varchar(50)='',
@nPageSize int=10,
@nPageIndex int=1,
@nPageCount int=0 Output
)
As
declare @sWhere Nvarchar(1000)
declare @sSql Nvarchar(4000)
declare @sOrderBy NvarChar(1000)
set @sOrderBy = ' divan_id desc '
set @sWhere =' where 1 = 1 '
begin
if(@DeptName<>'')
set @sWhere = @sWhere +' AND A.divan_no like ''%'+@DeptName+'%'''
print @sWhere
--set @sSql ='select B.subject ,B.apply_user,B.divan_id,B.user_Name,B.user_dept,B.apply_date,case B.flag when 1 then ''未通過'' when 2 then ''不通過'' when 3 then '' 通過'' end as flag, '+'Convert(varchar(10),begin_date,120)+ ''-'' +Convert(varchar(10),end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id=B.divan_id ' +@sWhere
set @sSql ='select Case B.register when 1 then ''已使用'' when 0 then ''未使用'' end as register,B.register_date, B.attend_dept, B.subject ,B.apply_user,B.divan_id,B.user_Name,B.user_dept,B.apply_date,case B.flag when 1 then ''未通過'' when 2 then ''不通過'' when 3 then '' 通過'' end as flag, '+'Convert(varchar(10),begin_date,120)+ ''-'' +Convert(varchar(10),end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id=B.divan_id ' +@sWhere
end
Exec pr_SelectDataPager @sSql, @nPageSize, @nPageIndex, @nPageCount Output, '*', @sOrderBy
print @nPageCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統
*作者:Ym
*書寫時間:2007/05/11
*傳入:
*說明:涉及表名[Divan]
*********************************/
CREATE proc Pr_Divan_DivanSearchList
(
@Divan_No varchar(10),
@Divan_Name varchar(50),
@Divan_Count int=0,
@Divan_Begin_Date datetime,
@Divan_End_Date datetime,
@Has_Video int,
@Has_audio int
)
AS
declare @sWhere nvarchar(1000)
declare @sSql nvarchar(1000)
set @sWhere=N' where 1=1 '
if(@Divan_No<>'')
set @sWhere=@sWhere +N' AND A.divan_no like ''%'+@Divan_No+'%'''
if(@Divan_Name<>'')
set @sWhere = @sWhere +N' AND A.divan_name like ''%'+@Divan_Name+'%'''
if(@Divan_Count<>0)
set @sWhere = @sWhere +N' AND A.lodge_amount = ' +Convert(nvarchar(10),@Divan_Count)
if(Rtrim(@Divan_Begin_Date)<>'')
set @sWhere = Rtrim(@sWhere)+' AND B.begin_date>=''' + convert(varchar(30),@Divan_Begin_Date,20) +''''
else
set @sWhere = Rtrim(@sWhere)+' AND B.begin_date>='''
if(Rtrim(@Divan_End_Date)<>'')
set @sWhere = Rtrim(@sWhere)+' And B.end_date<= ''' + convert(varchar(30),@Divan_End_Date,20) + ''''
else
set @sWhere = Rtrim(@sWhere)+' And B.end_date<=getdate()'
if(@Divan_Begin_Date!='' and @Divan_End_Date!='')
set @sWhere = Rtrim(@sWhere)+' AND B.begin_date>=''' + convert(varchar(30),@Divan_Begin_Date,20) +''' AND B.end_date<= ''' + convert(varchar(30),@Divan_End_Date,20) + ''''
else
--set @sWhere = Rtrim(@sWhere)+' And B.end_date<=getdate()'
print @Has_audio
if(@Has_Video!=3)
set @sWhere = @sWhere +N' AND A.has_video='+Convert(nvarchar(1),@Has_Video)
if(@Has_audio!=3)
set @sWhere =@sWhere +N' AND A.has_audio =' +Convert(nvarchar(1),@Has_audio)
select @sSql =N'select A.* from divan A inner join divan_apply_list B on A.divan_id = B.divan_id ' +@sWhere
print @sSql
exec sp_executesql @sSql
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室歷史登記查詢)
*作者:Ym
*書寫時間:2007/05/15
*傳入:
*頁面:DivanHistory
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE proc Pr_Divan_DivanUseHistory
(
@DeptName varchar(50)='',
@nPageSize int=10,
@nPageIndex int=1,
@nPageCount int=0 Output
)
As
declare @sWhere Nvarchar(1000)
declare @sSql Nvarchar(4000)
declare @sOrderBy NvarChar(1000)
set @sOrderBy = ' divan_id desc '
set @sWhere =' where 1 = 1 and B.register =1 '
begin
if(@DeptName<>'')
set @sWhere = @sWhere +' AND A.divan_no like ''%'+@DeptName+'%'''
print @sWhere
--set @sSql ='select B.subject ,B.apply_user,B.divan_id,B.user_Name,B.user_dept,B.apply_date,case B.flag when 1 then ''未通過'' when 2 then ''不通過'' when 3 then '' 通過'' end as flag, '+'Convert(varchar(10),begin_date,120)+ ''-'' +Convert(varchar(10),end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id=B.divan_id ' +@sWhere
set @sSql ='select Case B.register when 1 then ''已使用'' when 0 then ''未使用'' end as register ,B.register_date, B.attend_dept, B.subject ,B.apply_user,B.divan_id,B.user_Name,B.user_dept,B.apply_date,case B.flag when 1 then ''未通過'' when 2 then ''不通過'' when 3 then '' 通過'' end as flag, '+'Convert(varchar(10),begin_date,120)+ ''-'' +Convert(varchar(10),end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id=B.divan_id ' +@sWhere
end
Exec pr_SelectDataPager @sSql, @nPageSize, @nPageIndex, @nPageCount Output, '*', @sOrderBy
print @nPageCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc Pr_Divan_GetDeptByDivanNo
AS
select Distinct divan_no,divan_name from divan
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc Pr_Divan_GetUserDeptAndUserName
(
@UserID varchar(50)
)
AS
select A.*,B.dept_nm from useradmin A inner join dept B on A.dept_no = B.dept_no where user_no = @UserID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室申請)
*作者:Ym
*書寫時間:2007/05/14
*傳入:
*說明:涉及表名Divan,divan_apply_list]
*********************************/
CREATE proc Pr_Divan_InsertDivanApply
(
@ID int,
@Subject varchar(60),
@Attend_dept varchar(300),
@Begin_date datetime,
@End_date datetime,
@Exigency_grade char(1),
@apply_user varchar(20),
@user_name varchar(12),
@user_dept varchar(100)
)
as
declare @flag char(1)
declare @state char(1)
declare @register bit
declare @Count int
set @state=1
set @flag =1
BEGIN
insert into divan_apply_list(divan_id,subject,attend_dept,begin_date,end_date,exigency_grade,apply_user,user_name,user_dept,flag,status,apply_date)
values(@ID,@Subject,@Attend_dept,@Begin_date,@End_date,@Exigency_grade,@apply_user,@user_name,@user_dept,@flag,@state,getdate())
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (DivanRequest)
*作者:Ym
*書寫時間:2007/05/11
*傳入:
*說明:涉及表名Divan,divan_apply_list]
*********************************/
CREATE PROC Pr_Divan_InsertRequest
(
@Divan_No varchar(10),-------插入主表字段
@Divan_Name varchar(50),
@Ower_Dept_No varchar(10),
@User_No varchar(10),
@Divan_Size varchar(20),
@Lodge_Amount SmallInt,
@Has_Videobit bit,
@Has_audio bit,
@State char(1),
@TEl varchar(20),
@Address varchar(100),
@Divan_Description varchar(200),
@Subject varchar(60), ------------------插入從表數據
@Attend_dept varchar(300),
@Begin_date datetime,
@End_date datetime,
@Exigency_grade char(1)
)
as
begin transaction
declare @ID int
select @ID = Max(divan_id) from divan
set @ID =Isnull(@ID,0)+1
insert into divan(divan_id,divan_no,divan_name,owner_dept_no,divan_size,lodge_amount,has_video,has_audio,state, tel_1,address,user_no,divan_description)
values(@ID,@Divan_No,@Divan_Name,@Ower_Dept_No,@Divan_Size,@Lodge_Amount,@Has_Videobit,@Has_audio,@State,@Tel,@Address,@User_No,@Divan_Description)
insert into divan_apply_list(divan_id,subject,attend_dept,begin_date,end_date,exigency_grade)values(@ID,@Subject,@Attend_dept,@Begin_date,@End_date,@Exigency_grade)
if(@@Error!=0)
rollback Transaction
else
commit Transaction
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************************
*介紹:辦公自動化OA系統 ()
*作者:YM
*書寫時間:2007/05/09
*傳入:會議列表@DivanID
*說明:涉及表名[divan,divan_apply_list,divan_use_history]
*********************************************/
CREATE proc Pr_Divan_ManageQuery
(
@Divan_name varchar(50) = '',
@nPageIndex int =1,
@nPageSize int=3,
@nPageCount int=0 Output
)
as
declare @Sql Nvarchar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
begin
set @sWhere = 'Where 1 = 1 '
set @sOrderBy = 'divan_name desc'
If (Rtrim(@Divan_name) <> '')
begin
set @sWhere = Rtrim(@sWhere) + ' AND divan_name Like ''%' + @Divan_name + '%'''
print @sWhere
end
set @Sql ='select * from divan '+ Rtrim(@sWhere)
Exec pr_SelectDataPager @Sql, @nPageSize, @nPageIndex, @nPageCount Output, '*', @sOrderBy
print @nPageCount
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統
*作者:Ym
*書寫時間:2007/05/11
*傳入:@ID
*說明:涉及表名Divan,divan_apply_list]
*********************************/
CREATE proc Pr_Divan_SelectDivanApplyList
(
@ID int
)
as
select * from divan_apply_list where divan_id =@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (查詢會議室詳細信息)
*作者:Ym
*書寫時間:2007/05/15
*傳入:
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE proc Pr_Divan_SelectShowDetailes
(
@ID int
)
As
if(exists(select A. *,B.apply_user,B.subject ,B.user_name,B.apply_date, Convert(varchar(10),B.begin_date,120)+'-'+Convert(varchar(10),B.end_date,120) AS UseDate from divan A inner join dbo.divan_apply_list B on A.divan_id =B.divan_id where A.divan_id =@ID))
select A. *,B.apply_user,B.subject ,B.user_name,B.apply_date, Convert(varchar(10),B.begin_date,120)+'-'+Convert(varchar(10),B.end_date,120) AS UseDate from divan A inner join dbo.divan_apply_list B on A.divan_id =B.divan_id where A.divan_id =@ID
else
select A. * from divan A where divan_id =@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************************
*介紹:辦公自動化OA系統 ()
*作者:YM
*書寫時間:2007/05/23
*傳入:會議列表@DivanID
*說明:涉及表名[useradmin,divan_apply_list]
*********************************************/
CREATE proc Pr_Divan_SendMail
(
@ID int
)
AS
select B.divan_id,B.user_name,D.position_name,A.divan_name,C.email,B.apply_date,case B.flag when 1 then '未審核' when 2 then '不通過' when 3 then '通過' end as flag ,Convert(varchar(10),B.begin_date,120)+ '-' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id left join useradmin C on C.user_name = B.user_name left join position D on C.position_no = D.position_no WHERE A.divan_id=@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室所有登記查詢)
*作者:Ym
*書寫時間:2007/05/15
*傳入:
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE proc Pr_Divan_ShowAllApply
(
@ID int=0,
@apply_user varchar(20)='',
@nPageSize int=10,
@nPageIndex int=1,
@nPageCount int=0 Output
)
As
declare @sSql Nvarchar(4000)
declare @sOrderBy NvarChar(1000)
declare @sWhere Nvarchar(1000)
set @sOrderBy = 'apply_date desc '
set @sWhere =' where 1 = 1 '
if(@ID=0)
begin
set @sWhere =Rtrim(@sWhere)+ 'AND B.apply_user ='''+@apply_user+''''
set @sSql =N'select A.divan_no,B.subject,B.attend_dept, B.user_dept,B.apply_id,B.divan_id,B.user_name,A.divan_name,B.apply_date,case B.flag when 1 then ''未審核'' when 2 then ''不通過'' when 3 then ''通過'' end as flag ,'+'Convert(varchar(10),B.begin_date,120)+ ''-'' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id' +Rtrim(@sWhere)
end
if(@ID =1)
begin
set @sWhere =Rtrim(@sWhere) +' ANd B.flag = 1 and B.apply_user ='''+@apply_user+''''
set @sSql =N'select A.divan_no, B.subject,B.attend_dept, B.user_dept,B.apply_id,B.divan_id,B.user_name,A.divan_name,B.apply_date,case B.flag when 1 then ''未審核'' when 2 then ''不通過'' when 3 then ''通過'' end as flag ,'+'Convert(varchar(10),B.begin_date,120)+ ''-'' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id' +Rtrim(@sWhere)
end
if(@ID =2)
begin
set @sWhere =Rtrim(@sWhere) +' And B.flag = 2 and B.apply_user ='''+@apply_user+''''
set @sSql =N'select A.divan_no, B.subject,B.attend_dept, B.user_dept, B.apply_id,B.divan_id,B.user_name,A.divan_name,B.apply_date,case B.flag when 1 then ''未審核'' when 2 then ''不通過'' when 3 then ''通過'' end as flag ,'+'Convert(varchar(10),B.begin_date,120)+ ''-'' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id' +Rtrim(@sWhere)
end
if(@ID =3)
begin
set @sWhere =Rtrim(@sWhere) +' And B.flag = 3 and B.apply_user ='''+@apply_user+''''
set @sSql =N'select A.divan_no,B.subject,B.attend_dept, B.user_dept,B.apply_id,B.divan_id,B.user_name,A.divan_name,B.apply_date,case B.flag when 1 then ''未審核'' when 2 then ''不通過'' when 3 then ''通過'' end as flag ,'+'Convert(varchar(10),B.begin_date,120)+ ''-'' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id' +Rtrim(@sWhere)
end
if(@ID =4)
begin
set @sWhere =Rtrim(@sWhere) +' AND B.register =0 and B.apply_user ='''+@apply_user+''''
set @sSql =N'select A.divan_no,B.subject,B.attend_dept, B.user_dept, B.apply_id, B.divan_id,B.user_name,A.divan_name,B.apply_date,case B.flag when 1 then ''未審核'' when 2 then ''不通過'' when 3 then ''通過'' end as flag ,'+'Convert(varchar(10),B.begin_date,120)+ ''-'' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id' +Rtrim(@sWhere)
end
if(@ID =5)
begin
set @sWhere =Rtrim(@sWhere) +' AND B.register = 1 and B.apply_user ='''+@apply_user+''''
set @sSql =N'select A.divan_no,B.subject,B.attend_dept, B.user_dept, B.divan_id,B.user_name,A.divan_name,B.apply_date,case B.flag when 1 then ''未審核'' when 2 then ''不通過'' when 3 then ''通過'' end as flag ,'+'Convert(varchar(10),B.begin_date,120)+ ''-'' +Convert(varchar(10),B.end_date,120) as useDate from divan A inner join divan_apply_list B on A.divan_id =B.divan_id' +Rtrim(@sWhere)
print @sWhere
end
Exec pr_SelectDataPager @sSql, @nPageSize, @nPageIndex, @nPageCount Output, '*',@sOrderBy
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc Pr_Divan_ShowApplyMessage
(
@ID int
)
AS
--select A.divan_id, A.apply_date,A.user_name,A.user_dept, A.subject, A.attend_dept,Convert(varchar(10),A.begin_date,120)+'-'+Convert(varchar(10),A.end_date,120) as UseDate from divan_apply_list A left join divan B on A.divan_id =B.divan_id where A.divan_id =@ID
select A.divan_id,A.apply_id, A.apply_date,A.user_name,A.user_dept, A.subject, A.attend_dept,A.begin_date,A.end_date,A.flag from divan_apply_list A left join divan B on A.divan_id =B.divan_id where A.divan_id =@ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE Pr_Divan_UpdateDivan
(
@Divan_ID int,
@Divan_No varchar(10),
@Divan_Name varchar(50),
@Company_No varchar(10),
@Ower_Dept_No varchar(10),
@Divan_Size varchar(20),
@Lodge_Amount smallint,
@Has_Videobit bit,
@has_audio bit,
@State char(1),
@Tel_1 varchar(20),
@Tel_2 varchar(20),
@Tel_3 varchar(20),
@Address varchar(100),
@User_No varchar(20),
@Divan_description varchar(200)
)
as
begin
update divan
set divan_no=@Divan_No,
divan_name=@Divan_Name,
company_no=@Company_No,
owner_dept_no=@Ower_Dept_No,
divan_size=@Divan_Size,
lodge_amount=@Lodge_Amount,
has_video=@Has_Videobit,
has_audio =@has_audio,
state=@State,
tel_1=@Tel_1,
tel_2=@Tel_2,
tel_3=@Tel_3,
address=@Address,
user_no=@User_No,
divan_description=@Divan_description
where divan_id = @Divan_ID
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (會議室登記作廢)
*作者:Ym
*書寫時間:2007/05/15
*傳入:
*頁面:DivanHistory
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE proc Pr_Divan_UpdateDivanApply
(
@ID int,
@apply_user varchar(20)
)
AS
update divan_apply_list set register =0 where apply_id =@ID and apply_user =@apply_user
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (不通過審核)
*作者:Ym
*書寫時間:2007/05/16
*傳入:
*頁面:DivanRemark
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE proc Pr_Divan_UpdateFlag
(
@ID int,
@Apply_user varchar(20)
)
AS
update divan_apply_list set flag = 2, Approve_user = @Apply_user, approve_date = getdate() where apply_id = @ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (通過審核)
*作者:Ym
*書寫時間:2007/05/16
*傳入:
*頁面:DivanRemark
*說明:涉及表名[divan, divan_apply_list]
*********************************/
CREATE Proc Pr_Divan_UpdateFlagStatus
(
@ID int,
@Apply_user varchar(20)
)
AS
update divan_apply_list set flag = 3, Approve_user = @Apply_user, approve_date = getdate() where apply_id = @ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc Pr_Divan_selectShowDetailesByUser
(
@ID int,
@userName varchar(20)
)
AS
--select * from Divan_apply_list where divan_id = @ID and apply_user = @userName
select A.*,B.apply_user,B.subject ,B.user_name,B.apply_date, Convert(varchar(10),B.begin_date,120)+'-'+Convert(varchar(10),B.end_date,120) AS UseDate from divan A inner join dbo.divan_apply_list B on A.divan_id =B.divan_id where A.divan_id =@ID and apply_user=@userName
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Setting_GetPositionGroup
/****************************
* 功能:取得職務組列表
* 作者:Billy
* 日期:2006/09/11
****************************/
(
@CompanyNo varchar(10)
)
As
Select * From Position_Depth Where Company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Technic_SelectAllItem
/****************************
* 功能:根據頁碼選擇項目信息
* 作者:Billy
* 日期:2006/09/11
****************************/
(
@UserNo varchar(20) = '',
@TypeNo int = 0,
@Title nvarchar(50) = ''
)
As
Declare @Sql varchar(3000)
Select @Sql = 'Select T.Type_Name As TypeName, I.Item_no, I.Type_no, I.User_No, I.Title, I.Create_Date, I.Modify_Date
From TechnicItem I Inner Join TechnicType T On I.type_no = T.Type_no Where 1 = 1 '
if @TypeNo != 0
Set @Sql = @Sql + ' And I.Type_no = ' + cast(@TypeNo as varchar)
set @Sql = @Sql + ' And (I.Title Like ''%' + Replace(@Title, ' ', '%'' or I.Title Like ''%') + '%'')'
Exec(@Sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Technic_SelectItemFromPage
/****************************
* 功能:根據頁碼選擇項目信息
* 作者:Billy
* 日期:2006/09/11
****************************/
(
@UserNo varchar(20),
@TypeNo int,
@Title nvarchar(50),
@PageIndex int = 1, --當前頁碼
@PageSize int = 25, --分頁大小
@PageCount int = 0 output --頁總數
)
As
Declare @Sql varchar(3000)
Select @Sql = 'Select T.Type_Name As TypeName, I.Item_no, I.Type_no, I.User_No, I.Title, I.Create_Date, I.Modify_Date
From TechnicItem I Inner Join TechnicType T On I.type_no = T.Type_no Where 1 = 1 '
if @TypeNo != 0
Set @Sql = @Sql + ' And I.Type_no = ' + cast(@TypeNo as varchar)
set @Sql = @Sql + ' And (I.Title Like ''%' + Replace(@Title, ' ', '%'' or I.Title Like ''%') + '%'')'
Print @Sql
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Technic_SelectSingleItem
/****************************
* 功能:根據 ItemNo 和 UserNo 選擇單條信息
* 作者:Billy
* 日期:2006/09/11
****************************/
(
@ItemNo int,
@UserNo varchar(20)
)
As
Select T.Type_Name As TypeName, I.* From TechnicItem I
Inner Join TechnicType T On I.type_no = T.Type_no
Where I.item_no = @ItemNo And I.user_no = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Technic_SelectSingleType
/****************************
* 功能:取得單條分類信息
* 作者:Billy
* 日期:2006/09/13
****************************/
(
@TypeNo int,
@UserNo varchar(20)
)
As
Select * From TechnicType Where Type_no = @TypeNo and user_no = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Technic_SelectTypePathWithTypeNo
/****************************
* 功能:取得指定類型及其所有上級類型的代號組成的路徑
* 作者:Billy
* 日期:2006/09/12
****************************/
(
@UserNo varchar(20),
@TypeNo int
)
As
Select OA.dbo.fn_Technic_getTypePath( @TypeNo, @UserNo ) As TypePath
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc Pr_Technic_SelectTypeWithCounts
/****************************
* 功能:取得指定用戶的分類信息,同時取該分類的項目數
* 作者:Billy
* 日期:2006/09/12
****************************/
(
@UserNo varchar(20)
)
As
Select type_no, Type_Name As TypeName , parent_type_no, OA.dbo.fn_Technic_getItemCounts(type_no, user_no) as Counts
From TechnicType
Where user_no = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--Exec Pr_User_GetAllAproveGradeListFromDeptNo 'ETC', 'CL2000'
CREATE Proc Pr_User_GetAllAproveGradeListFromDeptNo
/**********************************************
功能:功能部門代號取得該部門對應的所有上級(至處級)以及下屬部門中人員的簽核等級
作者:Billy
日期:2006-12-25
參數:@CompnayNo, @DeptNo
**********************************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(10)
)
As
Declare @tbUser Table(ID int IDentity(1,1), company_no varchar(10), User_No varchar(20),
User_name varchar(12), Approve_Grade int, Status char(1), Position_No varchar(10), Dept_no varchar(10))
Declare @DepartMentList varchar(2000), @TempDeptNo varchar(10), @ChiefFlag char(1)
Declare @StartIndex int, @Length int
If( Not Exists(Select Dept_No From Dept Where Company_No = @CompanyNo And Dept_no = @DeptNo) )
Begin
Goto ExitProc
End
Select @StartIndex = 1, @Length = 1, @TempDeptNo = '', @ChiefFlag = 'N'
--本部門及其所有下屬部門審核等級大於0的用戶信息
Set @DepartMentList = dbo.fn_Dept_GetAllChildDeptNo(@CompanyNo, @DeptNo) + ','
Set @StartIndex = 1
Set @Length = CharIndex(',', @DepartMentList, @StartIndex) - 1
While( @Length > 0 )
Begin
Set @TempDeptNo = Substring(@DepartMentList, @StartIndex, @Length)
Insert Into @tbUser
Select company_no, User_No, User_Name, Approve_Grade,
dbo.fn_CheckUserStatus(status, getdate(), active_date, Disable_date), position_no, Dept_no
From UserAdmin
Where company_no = @CompanyNo and dept_no = @TempDeptNo and Approve_Grade > 0
Set @StartIndex = @StartIndex + @Length + 1
Set @Length = CharIndex(',', @DepartMentList, @StartIndex ) - @StartIndex
End
--取其所有上級部門(到處級)審核等級大於0的用戶信息
if( Not Exists(Select * From Dept Where company_No = @CompanyNo and Dept_no = @DeptNo) )
Begin
Goto ExitProc
End
Select @TempDeptNo = Parent_dept_no, @ChiefFlag = Chief_flag From Dept Where company_No = @CompanyNo and Dept_no = @DeptNo
while( Exists(Select Dept_Nm From Dept Where company_No = @CompanyNo and Dept_no = @TempDeptNo) )
Begin
Insert Into @tbUser
Select company_no, User_No, User_Name, Approve_Grade,
dbo.fn_CheckUserStatus(status, getdate(), active_date, Disable_date), position_no, Dept_no
From UserAdmin
Where company_no = @CompanyNo and dept_no = @TempDeptNo and Approve_Grade > 0
if @ChiefFlag = 'Y'
break;
Select @TempDeptNo = Parent_dept_no, @ChiefFlag = chief_flag From Dept Where company_No = @CompanyNo and Dept_no = @TempDeptNo
End
ExitProc:
Select U.*, P.Position_name, D.dept_nm From @tbUser U
Left Join Position P on U.company_no = P.company_no and U.position_no = P.position_no
Left Join Dept D On U.company_no = D.company_no and U.dept_no = D.dept_no
Order By U.Approve_Grade Asc, U.Dept_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteAddressContact
/********************************
*介紹:辦公自動化OA系統 (刪除號碼類型表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[address_contact]
*********************************/
(
@tel_id int
)
as
delete from address_contact where tel_id=@tel_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteAddressGroup
/********************************
*介紹:辦公自動化OA系統 (刪除通訊組)
*作者:游勇
*書寫時間:2007/04/27
*傳入:通訊組id
*說明:涉及表名[address_group]
*********************************/
(
@group_id int
)
as
declare @num int
set @num=0
select @num=count(*) from address_list where group_id=@group_id
if @num = 0
delete from address_group where group_id=@group_id
else
return -1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteAddressList
/********************************
*介紹:辦公自動化OA系統 (刪除通訊錄)
*作者:游勇
*書寫時間:2007/04/27
*傳入:通訊錄id
*說明:涉及表名[address_address]
*********************************/
(
@address_id int
)
as
begin transaction
delete address_contact where address_id=@address_id
delete address_list where address_id=@address_id
if @@error !=0 rollback transaction
else commit transaction
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteCustomer
/********************************
*介紹:辦公自動化OA系統 (刪除客戶)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[customer]
*********************************/
(
@user_no varchar(10),
@customer_id int
)
as
declare @ERR int
declare @count int
--是否是自己的各戶
select @count = count(*) from customer where user_no = @user_no and customer_id=@customer_id
if @count=0 set @ERR=-1
else
begin
begin transaction
delete from customer_linkman_d where customer_id=@customer_id
delete from customer_linkman where customer_id=@customer_id
delete from customer where customer_id=@customer_id
set @ERR = @@ERROR
if @ERR = 0 commit
else rollback
end
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteEmployee
/********************************
*介紹:辦公自動化OA系統 (刪除員工)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[employee]
*********************************/
(
@employee_id int
)
as
declare @ERR int
delete from employee where employee_id=@employee_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteLinkMan
/********************************
*介紹:辦公自動化OA系統 (刪除客戶聯繫人)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[customer_linkman]
*********************************/
(
@user_no varchar(10),
@customer_id int,
@linkman_id int
)
as
declare @ERR int
declare @count int
select @count=count(*) from customer where customer_id=@customer_id and user_no=@user_no
if @count = 0 set @ERR = -1
else
begin
begin transaction
delete from customer_linkman_d where customer_id=@customer_id and linkman_id = @linkman_id
delete from customer_linkman where customer_id=@customer_id and linkman_id=@linkman_id
set @ERR = @@ERROR
if @ERR = 0 commit
else rollback
end
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeleteNumberType
/********************************
*介紹:辦公自動化OA系統 (刪除號碼類型表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:通訊組id
*說明:涉及表名[address_number_type]
*********************************/
(
@type_id int
)
as
declare @num int
set @num=0
select @num=count(*) from address_contact where type_id=@type_id
if @num=0
delete from address_number_type where type_id=@type_id
else
return -1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeletePrivateAddressGroup
/********************************
*介紹:辦公自動化OA系統 (刪除通訊組)
*作者:游勇
*書寫時間:2007/04/27
*傳入:通訊組id
*傳出
*返回:@ERR = -1 通訊列表中已存在此通訊組所屬資料
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名[address_group]
*********************************/
(
@group_id int
)
as
declare @ERR int
declare @num int
select @num=count(*) from address_list where group_id=@group_id
if @num <> 0
begin
set @ERR = -1
select @ERR
return
end
else
delete from address_group where group_id=@group_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeletePrivateAddressList
/********************************
*介紹:辦公自動化OA系統 (刪除個人通訊錄)
*作者:游勇
*書寫時間:2007/04/27
*傳入:類型id
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名[address_list, address_contact]
*********************************/
(
@address_id int
)
as
declare @ERR int
declare @num int
begin transaction
delete from address_contact where address_id=@address_id
delete from address_list where address_id=@address_id
set @ERR = @@error
if @ERR != 0 rollback
else commit
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeletePrivateNumberType
/********************************
*介紹:辦公自動化OA系統 (刪除個人號碼類型)
*作者:游勇
*書寫時間:2007/04/27
*傳入:類型id
*傳出
*返回:@ERR = -1 已存在其所屬資料
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名[number_type]
*********************************/
(
@type_id int
)
as
declare @ERR int
declare @num int
select @num=count(*) from address_contact where type_id=@type_id
if @num <> 0
begin
set @ERR = -1
select @ERR
return
end
else
delete from address_number_type where type_id=@type_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_DeletePublicAddressList
/********************************
*介紹:辦公自動化OA系統 (刪除公共通訊錄)
*作者:游勇
*書寫時間:2007/04/27
*傳入:類型id
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名[address_list, address_contact]
*********************************/
(
@dept_no varchar(10),
@address_id int
)
as
declare @ERR int
declare @count int
select @count = count(*) from address_list where dept_no=@dept_no and address_id=@address_id
if @count = 0 set @ERR = -1
else
begin
begin transaction
delete from address_contact where address_id=@address_id
delete from address_list where address_id=@address_id
set @ERR = @@error
if @ERR != 0 rollback
else commit
end
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_AddressList_GetPublicAddressListRecordCount
/********************************
*介紹:辦公自動化OA系統 (查詢公共通訊錄)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[AddressList]
*********************************/
(
@dept_no varchar(10),
@company_no varchar(10),
@group_id int
)
as
declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10), cheif_flag char(1),[level] int)
-- if @group_id='0' --所有組
select * into address_list from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and dept_no=@dept_no union
select * from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.company_no=@company_no union
select * from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3
-- else --指定組
-- select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and a.group_id=@group_id and dept_no=@dept_no union
-- select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.group_id=@group_id and a.company_no=@company_no union
-- select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3 and a.group_id=@group_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_AddressList_GetPublicAddressRecordCount
/********************************
*介紹:辦公自動化OA系統 (查詢公共通訊錄)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[AddressList]
*********************************/
(
@dept_no varchar(10),
@company_no varchar(10),
@group_id int
)
as
declare @tmp table (address_id varchar(10))
if @group_id='0' --所有組
begin
insert @tmp select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and dept_no=@dept_no
insert @tmp select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.company_no=@company_no
insert @tmp select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3
end
else --指定組
begin
insert into @tmp select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and a.group_id=@group_id and dept_no=@dept_no
insert into @tmp select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.group_id=@group_id and a.company_no=@company_no
insert into @tmp select address_id from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3 and a.group_id=@group_id
end
select count(distinct(address_id)) from @tmp
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertAddressContact
/********************************
*介紹:辦公自動化OA系統 (新增聯絡號碼表)
*作者:游勇
*書寫時間:2007/04/28
*傳入:組id, 組名
*說明:涉及表名[address_contact]
*********************************/
(
@address_id int,
@tel_id int,
@type_id int,
@section char(1),
@contact varchar(100),
@is_default bit
)
as
insert into address_contact values(@address_id, @tel_id, @type_id, @section, @contact, @is_default)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertAddressGroup
/********************************
*介紹:辦公自動化OA系統 (新增通訊組列表)
*作者:游勇
*書寫時間:2007/04/
*傳入:公司代號,空則取全部
*說明:涉及表名[address_group]
*********************************/
(
@group_id int,
@group_name varchar(20),
@default_group bit,
@user_no varchar(20),
@private bit,
@company_no varchar(10)
)
as
insert into address_group(group_id, group_name, default_group, user_no, private, company_no) values(@group_id, @group_name, @default_group, @user_no, @private, @company_no)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertAddressList
/********************************
*介紹:辦公自動化OA系統 (新增通訊錄)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[address_number_type]
*********************************/
(
@address_id int,
@company_no varchar(10),
@dept_no varchar(20),
@private bit,
@security char(1),
@owner varchar(20),
@group_id int,
@last_name varchar(20),
@first_name varchar(20),
@person_name varchar(30),
@sex bit,
@birthday datetime,
@appellative varchar(20),
@f_country varchar(20),
@f_province varchar(20),
@f_city varchar(20),
@f_postalcode varchar(6),
@f_address varchar(50),
@c_company varchar(50),
@duty varchar(20),
@department varchar(20),
@c_country varchar(20),
@c_province varchar(20),
@c_city varchar(20),
@c_postalcode varchar(6),
@c_address varchar(50),
@other varchar(300),
@join_date datetime
)
as
insert into address_list(address_id, company_no, dept_no, private, security, owner, group_id, last_name, first_name, person_name, sex, birthday, appellative, f_country, f_province, f_city, f_postalcode, f_address, c_company, duty, department, c_country, c_province, c_city, c_postalcode, c_address, other, join_date)
values(@address_id, @company_no, @dept_no, @private, @security, @owner, @group_id, @last_name, @first_name, @person_name, @sex, @birthday, @appellative, @f_country, @f_province, @f_city, @f_postalcode, @f_address, @c_company, @duty, @department, @c_country, @c_province, @c_city, @c_postalcode, @c_address, @other, @join_date)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertCustomer
/********************************
*介紹:辦公自動化OA系統 (Customer)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Customer]
*********************************/
(
@customer_no varchar(20),
@company varchar(20),
@corporation varchar(20),
@register_date varchar(20),
@calling int,
@area int,
@state int,
@customer_grade int,
@quarry int,
@customer_type int,
@character int,
@reality bit,
@province varchar(20),
@city varchar(20),
@post_code varchar(6),
@address_zh varchar(60),
@address_en varchar(60),
@tel varchar(20),
@fax varchar(20),
@mail varchar(30),
@homepage varchar(30),
@bank varchar(30),
@bank_account varchar(20),
@user_no varchar(20),
@content varchar(200)
)
as
declare @ERR int
declare @customer_id int
--生成@customer_id
select @customer_id = max(customer_id) from customer
if @customer_id is null set @customer_id = 0
set @customer_id = @customer_id + 1
insert into customer
(
customer_id,
customer_no,
company,
corporation,
register_date,
calling,
area,
state,
customer_grade,
quarry,
customer_type,
[character],
reality,
province,
city,
post_code,
address_zh,
address_en,
tel,
fax,
mail,
homepage,
bank,
bank_account,
user_no,
content
)
values(
@customer_id,
@customer_no,
@company,
@corporation,
@register_date,
@calling,
@area,
@state,
@customer_grade,
@quarry,
@customer_type,
@character,
@reality,
@province,
@city,
@post_code,
@address_zh,
@address_en,
@tel,
@fax,
@mail,
@homepage,
@bank,
@bank_account,
@user_no,
@content
)
set @ERR = @@ERROR
select @customer_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertEmployee
/********************************
*介紹:辦公自動化OA系統 (Employee)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Employee]
*********************************/
(
@employee_no varchar(8),
@employee_name varchar(15),
@sex bit,
@register_date datetime=null,
@company_no varchar(10),
@dept_no varchar(10),
@id_card varchar(18),
@status varchar(1),
@marriage varchar(1),
@nationality varchar(20),
@native_place varchar(30),
@nation varchar(10),
@birthday datetime,
@position_no varchar(10),
@family_address varchar(50),
@post_code varchar(6),
@educate_grade varchar(1),
@school varchar(20),
@dimission_date datetime,
@dimission_mode varchar(10),
@dimission_cause varchar(20),
@tel varchar(15),
@home_tel varchar(15),
@handset_tel varchar(12),
@exigency_address varchar(50),
@photo varchar(60)
)
as
declare @ERR int
declare @employee_id int
--生成employee_id
select @employee_id = max(employee_id) from employee
if @employee_id is null set @employee_id = 0
set @employee_id = @employee_id + 1
-- insert員工
insert into employee
(
employee_id,
employee_no,
employee_name,
sex,
register_date,
company_no,
dept_no,
id_card,
status,
marriage,
nationality,
native_place,
nation,
birthday,
position_no,
family_address,
post_code,
educate_grade,
school,
dimission_date,
dimission_mode,
dimission_cause,
tel,
home_tel,
handset_tel,
exigency_address,
photo
)
values(
@employee_id ,
@employee_no,
@employee_name,
@sex,
@register_date,
@company_no,
@dept_no,
@id_card,
@status,
@marriage,
@nationality,
@native_place,
@nation,
@birthday,
@position_no,
@family_address,
@post_code,
@educate_grade,
@school,
@dimission_date,
@dimission_mode,
@dimission_cause,
@tel,
@home_tel,
@handset_tel,
@exigency_address,
@photo
)
--取系統錯誤號
set @ERR = @@ERROR
--輸出組id和錯誤號
select @employee_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertNumberType
/********************************
*介紹:辦公自動化OA系統 (新增號碼類型表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[address_number_type]
*********************************/
(
@type_id int,
@type_name varchar(20),
@default_type bit,
@user_no varchar(20),
@private bit,
@company_no varchar(10)
)
as
insert into address_number_type(type_id, [type_name], default_type, user_no, private,company_no)
values(@type_id, @type_name, @default_type, @user_no, @private,@company_no)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertPrivateAddressGroup
/********************************
*介紹:辦公自動化OA系統 (新增通訊組列表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:組名, 用戶代號
*傳出:
*返回:相同組名: @group_id > 0 and @ERR = -1
成功: @group_id > 0 and @ERR = 0
失敗: @group_id > 0 and @ERR > 0
*說明:涉及表名[address_group]
*********************************/
(
@group_name varchar(20),
@user_no varchar(20)
)
as
declare @ERR int
declare @group_id int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在 相同組名
--當前自己組中 是否存在 相同組名
select @group_id = group_id from address_group where ((company_no=@company_no and default_group=1 and private=1) or user_no=@user_no) and group_name=@group_name
--存在相同組名
if @group_id is not null
begin
set @ERR = -1
select @group_id, @ERR
return
end
--生成group_id
select @group_id = max(group_id) from address_group
if @group_id is null set @group_id = 0
set @group_id = @group_id + 1
-- insert 組
insert into address_group(group_id, group_name, user_no, private)
values(@group_id, @group_name, @user_no, 1)
--取系統錯誤號
select @ERR = @@ERROR
--輸出組id和錯誤號
select @group_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_InsertPrivateNumberType
/********************************
*介紹:辦公自動化OA系統 (新增號碼類型)
*作者:游勇
*書寫時間:2007/04/27
*傳入:類型名, 用戶代號
*傳出:
*返回:相同組名: @ERR = -1
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[address_number_type]
*********************************/
(
@type_name varchar(20),
@user_no varchar(20)
)
as
declare @ERR int
declare @type_id int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在
--當前自己組中 是否存在
select @type_id = type_id from address_number_type where ((company_no=@company_no and default_type=1 and private=1) or user_no=@user_no) and [type_name]=@type_name
--存在相同
if @type_id is not null
begin
set @ERR = -1
select @type_id, @ERR
return
end
--生成type_id
select @type_id = max(type_id) from address_number_type
if @type_id is null set @type_id = 0
set @type_id = @type_id + 1
-- insert 類型
insert into address_number_type(type_id, [type_name], user_no, private)
values(@type_id, @type_name, @user_no, 1)
--取系統錯誤號
select @ERR = @@ERROR
--輸出id和錯誤號
select @type_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectAddressContact
/********************************
*介紹:辦公自動化OA系統 (查詢聯系號碼表)
*作者:游勇
*書寫時間:2007/04/28
*傳入:
*說明:涉及表名[address_contact]
*********************************/
(
@address_id int,
@section int
)
as
select a.*, b.[type_name] from address_contact a inner join address_number_type b on a.type_id=b.type_id where address_id=@address_id and [section]=@section
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectAddressGroup
/********************************
*介紹:辦公自動化OA系統 (查詢通訊組列表)
*作者:游勇
*書寫時間:2007/04/
*傳入:公司代號,空則取全部
*說明:涉及表名[address_group]
*********************************/
(
@user_no varchar(20)--,
--@company_no varchar(10)
)
as
select * from address_group where default_group=1
union
select * from address_group where user_no=@user_no --and company_no=@company_no
union
select * from address_group where private=0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectAddressList
/********************************
*介紹:辦公自動化OA系統 (取得個人通訊錄)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回: 通訊錄
*說明:涉及表名[address_list]
*********************************/
(
@user_no varchar(20)
)
as
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司默認私有通訊組和自己的通訊組
select group_id, group_name from address_group where (company_no=@company_no and default_group=1 and private=1) or user_no=@user_no order by default_group desc
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectAddressNumberType
/********************************
*介紹:辦公自動化OA系統 (取得個人號碼類型表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回: 通訊錄
*說明:涉及表名[address_number_type]
*********************************/
(
@user_no varchar(20)
)
as
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司默認私有通訊組和自己的通訊組
select type_id, [type_name] from address_number_type where (company_no=@company_no and default_type=1 and private=1) or user_no=@user_no order by default_type desc
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectCustomerProperty
/********************************
*介紹:辦公自動化OA系統 (取得客戶屬性表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回:
*說明:涉及表名[customer_property]
*********************************/
(
@user_no varchar(20)
)
as
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司默認私有通訊組和自己的屬性分類
select * from customer_property where company_no=@company_no or user_no=@user_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectEmployeeByDeptNo
/********************************
*介紹:辦公自動化OA系統 (查詢員工信息)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[employee, dept]
*********************************/
(
@dept_no varchar(10),
@employee_name varchar(15),
@PageSize int=30, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output, --總頁數據 傳入0時可返回頁總數
@ShowFields varchar (4000)='', --要顯示的字段列表,如果查詢結果有標識字段,需要指定此值,且不包含標識字段
@OrderFields varchar (1000)='' ,--排序字段列表
@RecordCount int=0 output -- 總記錄數
)
as
--declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10), chief_flag char(1),[level] int)
declare @i int
declare @dno varchar(10)
--declare @company_no varchar(10)
declare @QueryText varchar(1000)
set @QueryText = ''
set @i=1
set @dno = '' --部門的處級代號
--set @company_no='' --公司代號
--insert @tmp select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
delete from dept_tmp_for_employee
insert dept_tmp_for_employee select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
while @@rowcount<>0
begin
set @i=@i+1
-- insert @tmp select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag,@i from dept a, @tmp b where a.parent_dept_no=b.dept_no and b.level=@i-1
insert dept_tmp_for_employee select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag,@i from dept a, dept_tmp_for_employee b where a.parent_dept_no=b.dept_no and b.level=@i-1
end
--select a.*, b.dept_nm from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from @tmp) order by a.dept_no, a.employee_id
set @QueryText = 'select a.*, b.dept_nm from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from dept_tmp_for_employee) and a.employee_name like ''%' + @employee_name + '%'''
--print @QueryText
--set @QueryText = 'select a.*, b.dept_nm from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from @tmp)'
Execute pr_SelectDataPager @QueryText, @PageSize , @PageCurrent, @PageCount Output, @ShowFields, @OrderFields
if @employee_name = ''
select @RecordCount=count(*) from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from dept_tmp_for_employee)
else
select @RecordCount=count(*) from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from dept_tmp_for_employee) and a.employee_name like @employee_name
--print @PageCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectLowerCustomer
/********************************
*介紹:辦公自動化OA系統 (查詢客戶)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[customer]
*********************************/
(
@user_no varchar(10),
@queryWhere varchar(1000),
@PageSize int=30, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output, --總頁數據 傳入0時可返回頁總數
@ShowFields varchar (4000)='', --要顯示的字段列表,如果查詢結果有標識字段,需要指定此值,且不包含標識字段
@OrderFields varchar (1000)='' , --排序字段列表
@RecordCount int=0 --記錄數
)
as
--declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10),[level] int)
declare @i int
declare @dept_director char(1)
declare @dept_no varchar(10)
declare @position_no varchar(10)
declare @QueryText varchar(1000)
declare @QueryCount nvarchar(1000)
set @QueryText = ''
select @dept_no=dept_no, @position_no=position_no from useradmin where user_no=@user_no
select @dept_director = dept_director from position where position_no=@position_no
if @dept_director = 'Y'
begin
set @i=1
--insert @tmp select company_no, dept_no, dept_nm, parent_dept_no, @i from dept where dept_no=@dept_no
delete from dept_tmp_for_employee
insert dept_tmp_for_employee select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
while @@rowcount<>0
begin
set @i=@i+1
--insert @tmp select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, @i from dept a, @tmp b where a.parent_dept_no=b.dept_no and b.level=@i-1
insert dept_tmp_for_employee select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag, @i from dept a, dept_tmp_for_employee b where a.parent_dept_no=b.dept_no and b.level=@i-1
end
--set @QueryText = 'select * from customer where user_no in ( select user_no from useradmin where dept_no in (select dept_no from @tmp) ) and ' + @queryWhere
set @QueryText = 'select * from customer where user_no in ( select user_no from useradmin where dept_no in (select dept_no from dept_tmp_for_employee) ) and ' + @queryWhere
set @QueryCount = N'select count(*) as recordcount from customer where user_no in ( select user_no from useradmin where dept_no in (select dept_no from dept_tmp_for_employee) ) and ' + @queryWhere
end
else
begin
set @QueryText = 'select * from customer where user_no=''' + @user_no + ''' and ' + @queryWhere
set @QueryCount = N'select count(*) as recordcount from customer where user_no=''' + @user_no + ''' and ' + @queryWhere
end
print @QueryText
Execute pr_SelectDataPager @QueryText, @PageSize , @PageCurrent, @PageCount Output, @ShowFields, @OrderFields
execute sp_executesql @QueryCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectLowerUser
/********************************
*介紹:辦公自動化OA系統 (查詢公共通訊錄)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[useradmin]
*********************************/
(
@user_no varchar(10)
)
as
declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10),[level] int)
declare @i int
declare @dept_director char(1)
declare @dept_no varchar(10)
declare @position_no varchar(10)
declare @QueryText varchar(1000)
set @QueryText = ''
select @dept_no=dept_no, @position_no=position_no from useradmin where user_no=@user_no
select @dept_director = dept_director from position where position_no=@position_no
if @dept_director = 'Y'
begin
set @i=1
insert @tmp select company_no, dept_no, dept_nm, parent_dept_no, @i from dept where dept_no=@dept_no
while @@rowcount<>0
begin
set @i=@i+1
insert @tmp select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, @i from dept a, @tmp b where a.parent_dept_no=b.dept_no and b.level=@i-1
end
end
select * from customer where user_no in ( select user_no from useradmin where dept_no in (select dept_no from @tmp) )
--set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and dept_no=''' + @dno + ''' union
-- select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.company_no=''' + @company_no +''' union
--print @QueryText
--Execute pr_SelectDataPager @QueryText, @PageSize , @PageCurrent, @PageCount Output, @ShowFields, @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectPublicAddressList
/********************************
*介紹:辦公自動化OA系統 (查詢公共通訊錄)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[AddressList]
*********************************/
(
@dept_no varchar(10),
@company_no varchar(10),
@group_id int,
@person_name varchar(30),
@PageSize int=30, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output, --總頁數據 傳入0時可返回頁總數
@ShowFields varchar (4000)='', --要顯示的字段列表,如果查詢結果有標識字段,需要指定此值,且不包含標識字段
@OrderFields varchar (1000)='' --排序字段列表
)
as
declare @QueryText varchar(1000)
set @QueryText = ''
if @group_id='0' --所有組
set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and dept_no=''' + @dept_no + ''' and person_name like ''%' + @person_name + '%'' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.company_no=''' + @company_no + ''' and person_name like ''%' + @person_name + '%'' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3' + ' and person_name like ''%' + @person_name + '%'''
else --指定組
set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and a.group_id=' + cast(@group_id as varchar) + ' and dept_no=''' + @dept_no + ''' and person_name like ''%' + @person_name + '%'' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.group_id=' + cast(@group_id as varchar) + ' and a.company_no=''' + @company_no + ''' and person_name like ''%' + @person_name + '%'' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3 and a.group_id=' + cast(@group_id as varchar) + ' and person_name like ''%' + @person_name + '%'''
Execute pr_SelectDataPager @QueryText, @PageSize , @PageCurrent, @PageCount Output, @ShowFields, @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectPublicAddressList_old
/********************************
*介紹:辦公自動化OA系統 (查詢公共通訊錄)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[AddressList]
*********************************/
(
@dept_no varchar(10),
@group_id int,
@PageSize int=30, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output, --總頁數據 傳入0時可返回頁總數
@ShowFields varchar (4000)='', --要顯示的字段列表,如果查詢結果有標識字段,需要指定此值,且不包含標識字段
@OrderFields varchar (1000)='' --排序字段列表
)
as
declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10), cheif_flag char(1),[level] int)
declare @i int
declare @dno varchar(10)
declare @company_no varchar(10)
declare @QueryText varchar(1000)
set @QueryText = ''
set @i=1
set @dno = '' --部門的處級代號
set @company_no='' --公司代號
--取得處級代號
insert @tmp select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
while @@rowcount<>0
begin
set @i=@i+1
insert @tmp select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag,@i from dept a, @tmp b where a.dept_no=b.parent_dept_no and b.level=@i-1
end
--是否存在處級代號
select @dno=dept_no, @company_no=company_no from @tmp c where c.cheif_flag='Y'
--print 'dno=' + @dno
--print 'company_no=' + @company_no
if len(@dno)=0 --處級以上
begin
if @group_id='0'
--select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0
set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0'
else
--select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and a.group_id=@group_id
set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and a.group_id=' + cast(@group_id as varchar)
-- print '1'
end
else --處級及其以下
begin
if @group_id='0' --所有組
begin
--select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and dept_no=@dno union --處內人員
--select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.company_no=@company_no union --本公司人員
--select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3 --全員
set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and dept_no=''' + @dno + ''' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.company_no=''' + @company_no +''' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3'
--print '3'
end
else --指定組
begin
set @QueryText = 'select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=1 and a.group_id=' + cast(@group_id as varchar) + ' and dept_no=''' + @dno + ''' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=2 and a.group_id=' + cast(@group_id as varchar) + ' and a.company_no=''' + @company_no +''' union
select a.*, b.group_name from address_list a inner join address_group b on a.group_id=b.group_id where a.private=0 and security=3 and a.group_id=' + cast(@group_id as varchar)
--print @company_no
--print @dno
--print '4'
end
--print '2'
end
print @QueryText
Execute pr_SelectDataPager @QueryText, @PageSize , @PageCurrent, @PageCount Output, @ShowFields, @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_SelectUserAdmin
/********************************
*介紹:辦公自動化OA系統 (取得用戶)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[useradmin]
*********************************/
(
@user_no varchar(20)
)
as
select a.*, b.short_code, b.company_nm, c.dept_nm,c.dept_level_no, c.chief_flag,c.chief_no, c.parent_dept_no, d.dept_director from useradmin a inner join company b on a.company_no=b.company_no
inner join dept c on a.dept_no=c.dept_no
inner join position d on a.position_no=d.position_no
where user_no=@user_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
create Proc pr_AddressList_SelectUserHighDept
/********************************
*介紹:辦公自動化OA系統 (取得用戶的處級部門編號)
*作者:游勇
*書寫時間:2007/05/04
*傳入:
*說明:涉及表名[useradmin]
*********************************/
(
@dept_no varchar(10)
)
as
declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10), cheif_flag char(1),[level] int)
declare @i int
set @i=1
--取得處級代號
insert @tmp select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
while @@rowcount<>0
begin
set @i=@i+1
insert @tmp select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag,@i from dept a, @tmp b where a.dept_no=b.parent_dept_no and b.level=@i-1
end
--是否存在處級代號
select dept_no, company_no from @tmp c where c.cheif_flag='Y'
--print 'dno=' + @dno
--print 'company_no=' + @company_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdateAddressGroup
/********************************
*介紹:辦公自動化OA系統 (更新通訊組列表)
*作者:游勇
*書寫時間:2007/04/
*傳入:組id, 組名
*說明:涉及表名[address_group]
*********************************/
(
@group_id int,
@group_name varchar(20)
)
as
update address_group set group_name=@group_name where group_id=@group_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdateAddressList
/********************************
*介紹:辦公自動化OA系統 (修改通訊錄)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[address_list]
*********************************/
(
@address_id int,
@company_no varchar(10),
@dept_no varchar(20),
@private bit,
@security char(1),
@owner varchar(20),
@group_id int,
@last_name varchar(20),
@first_name varchar(20),
@person_name varchar(30),
@sex bit,
@birthday datetime,
@appellative varchar(20),
@f_country varchar(20),
@f_province varchar(20),
@f_city varchar(20),
@f_postalcode varchar(6),
@f_address varchar(50),
@c_company varchar(50),
@duty varchar(20),
@department varchar(20),
@c_country varchar(20),
@c_province varchar(20),
@c_city varchar(20),
@c_postalcode varchar(6),
@c_address varchar(50),
@other varchar(300),
@join_date datetime
)
as
update address_list
set company_no=@company_no, dept_no=@dept_no, private=@private, security=@security, owner=@owner, group_id=@group_id, last_name=@last_name, first_name=@first_name, person_name=@person_name, sex=@sex, birthday=@birthday, appellative=@appellative, f_country=@f_country, f_province=@f_province, f_city=@f_city, f_postalcode=@f_postalcode, f_address=@f_address, c_company=@c_company, duty=@duty, department=@department, c_country=@c_country, c_province=@c_province, c_city=@c_city, c_postalcode=@c_postalcode, c_address=@c_address, other=@other, join_date=@join_date where address_id=@address_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdateCustomer
/********************************
*介紹:辦公自動化OA系統 (Customer)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Customer]
*********************************/
(
@customer_id int,
@customer_no varchar(20),
@company varchar(20),
@corporation varchar(20),
@register_date varchar(20),
@calling int,
@area int,
@state int,
@customer_grade int,
@quarry int,
@customer_type int,
@character int,
@reality bit,
@province varchar(20),
@city varchar(20),
@post_code varchar(6),
@address_zh varchar(60),
@address_en varchar(60),
@tel varchar(20),
@fax varchar(20),
@mail varchar(30),
@homepage varchar(30),
@bank varchar(30),
@bank_account varchar(20),
@user_no varchar(20),
@content varchar(200)
)
as
declare @ERR int
declare @count int
select @count = count(*) from customer where customer_id = @customer_id and user_no = @user_no
if @count = 0 set @ERR = -1
else
begin
update customer
set
customer_no = @customer_no,
company = @company,
corporation = @corporation,
register_date = @register_date,
calling = @calling,
area = @area,
state = @state,
customer_grade = @customer_grade,
quarry = @quarry,
customer_type = @customer_type,
[character] = @character ,
reality = @reality,
province = province,
city = @city,
post_code = @post_code,
address_zh = @address_zh,
address_en = @address_en,
tel = @tel,
fax = @fax ,
mail = @mail,
homepage = @homepage,
bank = @bank,
bank_account = @bank_account,
user_no = @user_no,
content = @content
where customer_id = @customer_id
set @ERR = @@ERROR
end
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdateEmployee
/********************************
*介紹:辦公自動化OA系統 (Employee)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Employee]
*********************************/
(
@employee_id int,
@employee_no varchar(8),
@employee_name varchar(15),
@sex bit,
@register_date datetime,
@company_no varchar(10),
@dept_no varchar(10),
@id_card varchar(18),
@status varchar(1),
@marriage varchar(1),
@nationality varchar(20),
@native_place varchar(30),
@nation varchar(10),
@birthday datetime,
@position_no varchar(10),
@family_address varchar(50),
@post_code varchar(6),
@educate_grade varchar(1),
@school varchar(20),
@dimission_date datetime,
@dimission_mode varchar(10),
@dimission_cause varchar(20),
@tel varchar(15),
@home_tel varchar(15),
@handset_tel varchar(12),
@exigency_address varchar(50),
@photo varchar(60)
)
as
declare @ERR int
update employee
set employee_no = @employee_no,
employee_name = @employee_name ,
sex = @sex,
register_date = @register_date,
company_no = @company_no,
dept_no = @dept_no,
id_card = @id_card,
status = @status,
marriage = @marriage,
nationality = @nationality,
native_place = @native_place,
nation = @nation,
birthday = @birthday,
position_no = @position_no,
family_address = @family_address,
post_code = @post_code,
educate_grade = @educate_grade,
school = @school,
dimission_date = @dimission_date,
dimission_mode = @dimission_mode,
dimission_cause = @dimission_cause,
tel = @tel,
home_tel = @home_tel,
handset_tel = @handset_tel,
exigency_address = @exigency_address,
photo = @photo
where employee_id=@employee_id
set @ERR = @@ERROR
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdateNumberType
/********************************
*介紹:辦公自動化OA系統 (更新號碼類型表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:組id, 組名
*說明:涉及表名[address_number_type]
*********************************/
(
@type_id int,
@type_name varchar(20)
)
as
update address_number_type set [type_name]=@type_name where type_id=@type_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdatePrivateAddressGroup
/********************************
*介紹:辦公自動化OA系統 (新增通訊組列表)
*作者:游勇
*書寫時間:2007/04/27
*傳入:組名, 用戶代號
*傳出:
*返回:相同組名: @ERR = -1
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[address_group]
*********************************/
(
@group_id int,
@group_name varchar(20),
@user_no varchar(20)
)
as
declare @ERR int
declare @group_id_exist int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在 相同組名
--當前自己組中 是否存在 相同組名
select @group_id_exist = group_id from address_group where ((company_no=@company_no and default_group=1 and private=1) or user_no=@user_no) and group_name=@group_name and group_id<>@group_id
if @group_id_exist is not null
begin
set @ERR = -1
select @ERR
return
end
-- update 組
update address_group set group_name=@group_name where group_id=@group_id
--取系統錯誤號
set @ERR = @@ERROR
--輸出組id和錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_AddressList_UpdatePrivateNumberType
/********************************
*介紹:辦公自動化OA系統 (更新號碼類型 )
*作者:游勇
*書寫時間:2007/04/27
*傳入:名, 用戶代號
*傳出:
*返回:相同組名: @ERR = -1
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[address_number_type]
*********************************/
(
@type_id int,
@type_name varchar(20),
@user_no varchar(20)
)
as
declare @ERR int
declare @type_id_exist int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認 是否存在
--當前用戶中 是否存在
select @type_id_exist = type_id from address_number_type where ((company_no=@company_no and default_type=1 and private=1) or user_no=@user_no) and [type_name]=@type_name and type_id<>@type_id
if @type_id_exist is not null
begin
set @ERR = -1
select @ERR
return
end
-- update 組
update address_number_type set [type_name]=@type_name where type_id=@type_id
--取系統錯誤號
set @ERR = @@ERROR
--輸出id和錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Admin_SelectInValidationDeptList
/***********************************************
** 功能:取得無效上級部門代號的部門列表
** 作者: Billy
** 日期: 2006/11/06
*************************************************/
As
Select Company_no, Dept_no, dbo.fn_DepartmentFrame(company_no,dept_no) dept_name,
OA.dbo.fn_departmentframe(company_no,parent_dept_no) parent_dept_name
From dept
Where parent_dept_no not in( Select Distinct Dept_No From dept)and parent_dept_no != ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Admin_SelectUserListWhereInValidationDeptNo
/***********************************************
** 功能:取得?效部?代?的用?列表
** 作者: Billy
** 日期: 2006/11/06
*************************************************/
As
Select user_no, user_name,user_password, OA.dbo.fn_departmentframe(company_no,Dept_no) DepartMent,
OA.dbo.fn_CheckUserStatus(status, getDate(), active_date, disable_date) As Status
From useradmin where dept_no not in (Select Distinct Dept_no From Dept)
or dept_no in (Select dept_no From dept Where parent_dept_no not in( Select Distinct Dept_No From dept) and parent_dept_no != '')
Order By Status, DepartMent
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_AfficheTakeList
/********************************
*介紹:辦公自動化OA系統 (取得對應用戶可查看的公告列表)
*作者:william
*書寫時間:2007/05/
*說明:
*********************************/
(
@sTitle varchar(100),
@sUserNo varchar(20),
@PerviewOrMessage varchar(20),
@nPageIndex int=1,
@nPageSize int=10,
@OrderFields varchar(400),
@nPageCount int=0 output,
@nRecordCount int=0 output
)
AS
declare @sql varchar(2000),@dept_nos varchar(1000)
declare @company_no varchar(20),@dept_no varchar(10)
if(@sUserNo!='')
begin
if(@PerviewOrMessage='preview')
begin
select @company_no=company_no,@dept_nos=dbo.fn_Dept_GetAllSuperiorDepartMentNo(company_no,dept_no,'2'),@dept_no=dept_no
from useradmin where user_no=@sUserNo
set @sql='select a.*,u.user_name from affiche a left join useradmin u on a.issue_person = u.user_no where ((a.everyone=1)
or a.affiche_id in (select affiche_id from affiche_incept where company_no='''+@company_no+''' and incept_security=''1'')
or a.affiche_id in (select affiche_id from affiche_incept where dept_no='''+@dept_no+''' and incept_security=''2'')
or a.affiche_id in (select affiche_id from affiche_incept where charindex(dept_no,'''+@dept_nos+''')>0 and incept_security=''2'' and include_junior=1))'
end
else
if(dbo.fn_User_CheckRole(@sUserNo)=1)
set @sql='select a.*,u.user_name from affiche a left join useradmin u on a.issue_person = u.user_no'
else
set @sql='select a.*,u.user_name from affiche a left join useradmin u on a.issue_person = u.user_no where 1=1 and a.issue_person='''+@sUserNo+''''
end
else
begin
set @sql='select a.*,u.user_name from affiche a left join useradmin u on a.issue_person = u.user_no where 1=1'
end
if(@sTitle<>'')
set @sql = @sql + ' and title like ''%'+@sTitle+'%'''
print @sql
if(@nRecordCount=0)
begin
declare @RecordCountSql nvarchar(2000)
set @RecordCountSql = N'select @nRecordCount=count(*) from ('+@sql+') M'
--print @RecordCountSql
exec sp_executesql @RecordCountSql,N'@nRecordCount int out',@nRecordCount out
end
exec dbo.pr_SelectDataPager @sql,@nPageSize,@nPageIndex,@nPageCount output,'*',@OrderFields
--print @nPageCount
--print @nRecordCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_AnyPoepleInPosition
/********************************
*介紹:辦公自動化OA系統 (查詢在某公司某部門某職務下是否有人任職)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[useradmin]
*********************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(10),
@PositionNo varchar(10),
@Counts int output
)
as
select @Counts=count(*) from useradmin
where company_no=@CompanyNo and dept_no=@DeptNo and position_no=@PositionNo and approve_grade>0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_ApprovePerson_Add
/********************************
*介紹:辦公自動化OA系統 (添加一個簽核人員檔)
*作者:Billy
*書寫時間:2006/07/06
*說明:涉及表名[person_d_approvel]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ActionSeq int,
@UserNo varchar(20),
@ApproveGrade int,
@AddApproveUser char(1) = '0',
@FillIn char(1) = 'N',
@EffectValidate char(1) = 'N',
@Prompt Nvarchar(100) = '',
@EndCase char(1) = 'N',
@Condition varchar(50) = '',
@CreatePerson varchar(20)
)
as
declare @Seq int,@ApproveSeq int
Declare @ChiefNo varchar(10)
exec @Seq=pr_GetSeqNumber 'person_d_approve'
Set @ChiefNo = dbo.fn_Dept_GetChiefDeptNoFromUserNo(@UserNo)
Set @ApproveSeq = 0
Select @ApproveSeq = Max(ApproveSeq) From Person_d_Approve Where Bill_no = @BillNo
Set @ApproveSeq = IsNull(@ApproveSeq, 0) + 1
Insert into person_d_approve (company_no,kind_no,bill_no,seq,ApproveSeq,action_seq,chief_no,user_no,approve_grade, Add_ApproveUser,fillin, Effect_Validate, prompt, EndCase, Condition,Create_Person)
values(@CompanyNo,@KindNo,@BillNo,@Seq,@ApproveSeq, @ActionSeq,@ChiefNo, @UserNo,@ApproveGrade, @AddApproveUser, @FillIn, @EffectValidate, @prompt, @EndCase, @Condition,@CreatePerson)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_ApprovePerson_AdjustSeq
/*
功能:調一個簽核人員的順序
作者:Billy
日期:2007/03/06
說明:每次只能調整一個簽核人員的位置
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@Seq int, --Seq欄位值
@NewApproveSeq int --新的ApproveSeq序號
)
As
Declare @ApproveSeq int --原ApproveSeq序號
Declare @MaxApproveSeq int --最大的ApproveSeq序號
If @NewApproveSeq < 1
Return 0 --超出范圍
If Not Exists(Select Bill_No From Person_D_Approve Where Company_No = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo And Seq = @Seq)
Begin
Return 0 --數據不存在
End
Select @ApproveSeq = ApproveSeq From Person_D_Approve Where Company_No = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo And Seq = @Seq
If @ApproveSeq = @NewApproveSeq
Return 1 --不需進行調整
Select @MaxApproveSeq = Max(ApproveSeq) From Person_D_Approve Where Company_No = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo
if @NewApproveSeq > @MaxApproveSeq
Return 0 --超出范圍
--執行調整動作,注意:應保存ApproveSeq的序號是連續的
Begin Transaction
If @ApproveSeq < @NewApproveSeq --由小調到大
Begin
Update Person_d_Approve Set ApproveSeq = ApproveSeq - 1
Where Company_No = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo
And (ApproveSeq >= @ApproveSeq And ApproveSeq <= @NewApproveSeq)
If @@Error != 0 GoTo Err
End
Else --由大調到小
Begin
Update Person_d_Approve Set ApproveSeq = ApproveSeq + 1
Where Company_No = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo
And (ApproveSeq >= @NewApproveSeq And ApproveSeq < @ApproveSeq)
If @@Error != 0 GoTo Err
End
Update Person_d_Approve Set ApproveSeq = @NewApproveSeq
Where Company_No = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo And Seq = @Seq
If @@Error != 0 GoTo Err
Commit Transaction
Return 1
Err:
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_ApprovePerson_Delete
/*
功能:刪除流程中的簽核用戶
作者:Billy
說明:刪除後同時更新後面的簽核順序
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@SeqList Varchar(200)
)
As
If @SeqList = '' Or @SeqList Is Null
return 1
Declare @Seq int
Declare @ID int
Declare @ApproveSeq int
DeClare @Sql Varchar(2000)
Declare @Rows int
Begin Transaction
Set @Sql = 'Delete Person_d_Approve Where Company_No=''' + @CompanyNo + ''' And Kind_No=''' + @KindNo + ''' And Bill_No=''' + @BillNo + ''' And Seq In (' + @SeqList + ') '
Exec( @Sql)
If @@Error != 0 Goto Error
--更新序號
Select [ID]=Identity(int,1,1), Seq, ApproveSeq Into #tbPerson From Person_d_Approve
Where Company_No=@CompanyNo And Kind_No=@KindNo And Bill_No=@BillNo Order By ApproveSeq
Set @ID = 1
Select @Rows = Count(*) From #tbPerson
While @ID <= @Rows
Begin
Select @ApproveSeq = ApproveSeq, @Seq = Seq From #tbPerson Where ID = @ID
Update Person_d_Approve Set ApproveSeq = @ID Where Company_No=@CompanyNo And Kind_No=@KindNo And Bill_No=@BillNo And Seq = @Seq
if @@Error != 0 goto Error
Set @ID = @ID + 1
End
Commit Transaction
Print '成功'
Return 1
Error:
RollBack Transaction
print '失敗'
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_ApprovePerson_Insert
/*************************************************
*介紹:插入新的簽核用戶
*作者:Billy
*書寫時間:2006/08/21
*************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30) , --需要添加簽核用戶的單據代號
@UserNo varchar(20) , --待添加的簽核用戶的代號
@Action int , --添加用戶所需要執行的簽核動作(action_kind.action_seq)
@Sequence int , --添加用戶的序號
@ApproveGrade int , --添加用戶的審覈等級
@AddApproveUser char(1) = '0', --添加的用戶是否允許添加新的審核用戶, 0:不添加, 1:添加任意用戶, 2:只能從本單位中選擇用戶, 3:添加窗口人員
@FillIn char(1) = 'N', --填寫表單
@EffectValidate char(1) = 'N', --單據效果確認
@Prompt nVarchar(100) = N'' , --簽核提示
@EndCase char(1) = 'N' , --添加的用戶是否能夠結案單據
@Condition varchar(50) = '', --單據結案條件(如果允許結案)
@CreatePerson varchar(20) --操作的用戶
)
as
declare @nSeq int --記錄序號(作為主鍵插入)
Declare @ChiefNo varchar(10) --當前用戶所在的處級代碼
Set @ChiefNo = ''
if Not Exists(Select User_No From UserAdmin Where User_no = @UserNo) --當前添加的用戶不存在
Return 0
--取得簽核人員檔的序號
exec @nSeq = pr_GetSeqNumber 'person_d_approve'
--取得用戶所在的處級單位代碼
Set @ChiefNo = dbo.fn_Dept_GetChiefDeptNoFromUserNo(@UserNo)
--開始事務處理
begin transaction
--(第一步)更新插入用戶之後的簽核用戶的審覈順序
update person_d_approve set ApproveSeq = ApproveSeq + 1
where company_No = @CompanyNo and Kind_No = @KindNo and bill_no = @BillNo and approveSeq >= @Sequence
if @@error <> 0 goto Err
--(第二步)添加用戶
insert person_d_approve ( company_no, kind_no, bill_no, seq, approveSeq,action_seq, chief_no,user_no, approve_grade, approve_sign, add_approveUser, fillin, effect_validate, prompt, endCase, Condition, create_Person )
values ( @CompanyNo, @KindNo, @BillNo, @nSeq, @Sequence, @Action, @ChiefNo, @UserNo, @ApproveGrade, '1', @AddApproveUser, @FillIn, @EffectValidate, @Prompt, @EndCase, @Condition, @CreatePerson)
if @@error <> 0 goto Err
commit transaction
return 1
Err:
rollback transaction
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_CAR_SelectList
/***********************************************************
*介紹:查詢客訴單
*作者:Billy
*時間:2006/12/27
*傳入:用戶代號,單據編號,單據狀態,緊急程度,單據建立人,建立日期(起止)
*返回:查得單據列表
*說明:涉及表名[bill_m_approve,bill_m_approved]
************************************************************/
(
@UserNo varchar(20),
@BillNo varchar(30)='',
@BillStatus char(1)='0',
@BillExigencyGrade char(1)='0',
@CreatePerson varchar(20)='',
@ClientName varchar(100) ='',
@ProductName varchar(100) = '',
@CreateDateStart varchar(20)='',
@CreateDateEnd varchar(20)='',
@OrderFields varchar(200) = '',
@PageSize int=25,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @CompanyNo varchar(10), @KindNo varchar(10)
Declare @sSqlMain varchar(6000), @sWhere varchar(1000), @sRelation varchar(1000)
Declare @DeputyUserList NVarchar(4000), @ID int, @Searchable char(1)
Create Table #tbSecurity(ID int IDentity(1,1), c_Search char(1))
Select @DeputyUserList = '', @ID = 1, @Searchable = 'N'
Exec pr_SelectDeputyPersonList @UserNo, @DeputyUserList out
if( @DeputyUserList != '' )
Set @DeputyUserList = '''' + @UserNo + ''',''' + Replace(@DeputyUserList,',', ''',''') + ''''
Else
Set @DeputyUserList = '''' + @UserNo + ''''
Set @DeputyUserList = 'Select c_Search from Bill_Security Where user_no In(' + @DeputyUserList + ') and Company_no = ''ETC'' and kind_no = ''CAR'''
--將本人及其代理人的單據查詢權限存到臨時表中
Insert Into #tbSecurity Exec sp_ExecuteSql @DeputyUserList
While Exists(Select * From #tbSecurity Where ID = @ID)
Begin
Select @Searchable = c_Search From #tbSecurity Where ID = @ID
If(@Searchable = 'Y') Break;
Set @ID = @ID + 1
End
--初始化
set @sSqlMain='Select M.bill_no, field_001 Client_Name, field_003 Product_Name, dbo.fn_Bill_ConvertStatus(M.status) status, '+
'dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade, U.user_name, '
+ 'convert(varchar(10),M.create_date,120) as create_date from '
if( @Searchable != 'Y' )
Begin
Exec(@sSqlMain + ' Bill_M_Approve M Inner Join UserAdmin U On M.Create_Person=U.user_No Where 1>2')
Return 0
End
set @sRelation=' M left outer join useradmin U on M.create_person=U.user_no '
set @sWhere='where M.company_no=''ETC'' and M.kind_no=''CAR'' '
--是否傳入單據代號
if @BillNo != ''
set @sWhere=@sWhere+'and M.bill_no like ''%'+@BillNo+'%'' '
--是否傳入單據緊急程度
if @BillExigencyGrade != '0'
set @sWhere=@sWhere+'and M.exigency_grade='''+@BillExigencyGrade+''' '
--是否傳入單據建立人
if @CreatePerson != ''
set @sWhere=@sWhere+'and ( M.create_person like''%'+@CreatePerson+'%'' or U.user_name Like ''%' + @CreatePerson + '%'') '
if @ClientName != ''
set @sWhere=@sWhere+'and field_001 like ''%' + Replace(@ClientName, '''', '''''') + '%'' '
if @ProductName != ''
set @sWhere=@sWhere+'and field_003 Like ''%' + Replace(@ProductName, '''', '''''') + '%'' '
--是否傳入建立開始日期
if @CreateDateStart != ''
set @sWhere=@sWhere+'and M.create_date>='''+Convert(varchar(10),@CreateDateStart,120)+''' '
--是否傳入建立終止日期
if @CreateDateEnd != ' '
set @sWhere=@sWhere+'and M.create_date<='''+Convert(varchar(10),@CreateDateEnd,120)+''' '
--是否傳入單據狀態
if @BillStatus != '0'
begin
set @sWhere=@sWhere+'and M.status='''+@BillStatus+''' '
if @BillStatus='1' or @BillStatus='4'
--在表 bill_m_approve 中查找
set @sSqlMain=@sSqlMain+'bill_m_approve '+@sRelation+@sWhere
else if @BillStatus='2' or @BillStatus='3'
--在表 bill_m_approved 中查找
set @sSqlMain=@sSqlMain+'bill_m_approved '+@sRelation+@sWhere
end
Else
set @sSqlMain=@sSqlMain+'bill_m_approve '+@sRelation+@sWhere+' union ('+@sSqlMain+'bill_m_approved '+@sRelation+@sWhere+') '
if( @OrderFields = '' )
Set @OrderFields = 'Create_date desc'
--調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSqlMain,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields = @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_Car_Report_ClientForMonth
/********************************
*介紹:生成某月某客戶客訴的單據信息,提供報表分析
*作者:Billy
*書寫時間:2006/11/10
*傳入:@Date, @ClientName
*返回:用戶列表
*說明:涉及表名[useradmin,Dept, Position]
*********************************/
(
@Date DateTime,
@ClientName varchar(60)
)
As
Select C.Company_nm, Bk.kind_nm, Main.* From
(
Select company_no, kind_no, bill_no, status, Field_001 ClientName, field_002 OrderNo, Field_003 Product,
field_007 ExceptionCounts, field_006 DutyDepartMent, Field_005 ReceiptDate, Complete_Date, Create_Date
From Bill_M_Approve
Where Field_001 = @ClientName And Convert(varchar(7), Create_Date, 120) = Convert(varchar(7), @Date, 120) And Kind_No = 'CAR'
Union
Select company_no, kind_no, bill_no, status, Field_001 ClientName, field_002 OrderNo, Field_003 Product,
field_007 ExceptionCounts, field_006 DutyDepartMent, Field_005 ReceiptDate, Complete_Date, Create_Date
From Bill_M_Approved
Where Field_001 = @ClientName And Convert(varchar(7), Create_Date, 120) = Convert(varchar(7), @Date, 120) And Kind_No = 'CAR'
) Main
Left outer Join Bill_Kind Bk On Main.Company_No = Bk.Company_No And Main.Kind_No = BK.Kind_no
Left Outer Join Company C On Main.Company_No = C.Company_No
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_Car_Report_List
/********************************
*介紹:生成某月某客戶客訴的單據信息,提供報表分析
*作者:Billy
*書寫時間:2006/11/10
*傳入:
*返回:用戶列表
*說明:涉及表名[useradmin,Dept, Position]
*********************************/
(
@CompanyNo varchar(10)
)
As
Select C.Company_nm, Bk.kind_nm, Main.* From
(
Select company_no, kind_no, bill_no, status, Field_001 ClientName, field_002 OrderNo, Field_003 Product,
field_007 ExceptionCounts, field_006 DutyDepartMent, Field_005 ReceiptDate,
Convert(datetime, Complete_Date, 120) Complete_Date, Convert(datetime, Create_Date, 120) Create_Date
From Bill_M_Approve
Union
Select company_no, kind_no, bill_no, status, Field_001 ClientName, field_002 OrderNo, Field_003 Product,
field_007 ExceptionCounts, field_006 DutyDepartMent, Field_005 ReceiptDate,
Convert(datetime, Complete_Date, 120) Complete_Date, Convert(datetime, Create_Date, 120) Create_Date
From Bill_M_Approved
) Main
Left outer Join Bill_Kind Bk On Main.Company_No = Bk.Company_No And Main.Kind_No = BK.Kind_no
Left Outer Join Company C On Main.Company_No = C.Company_No
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_CompareUser
/*************************
功能:比較當前傳入的用戶是否為單據的當前簽核用戶
如果單據的當前簽核用戶被當前用戶代理,則被為相同
作者:Billy
日期:2007/02/08
返回:@IsCompare :是否相同
@AddApproveUser: 0:不允許添加用戶 1:允許添加任意的用戶 2:只允許添加本部門的用戶
******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@UserNo varchar(20),
@IsCompare bit = 0 out,
@ApproveSeq int out,
@AddApproveUser char(1) = '0' out
)
As
Declare @UserList varchar(1000)
Declare @ApproveUserNo varchar(20)
Set @IsCompare = 0
Set @AddApproveUser = '0'
Set @UserList = ''
Set @ApproveUserNo = ''
Set @ApproveSeq = 0
--得到代理的用戶列表
Exec pr_SelectDeputyPersonList @UserNo, @UserList out
if Not Exists(Select Bill_no From Bill_M_Approve Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo)
Begin
return 0
End
--得到單據的當前簽核順序ApproveSeq
Select @ApproveSeq = Current_ApproveSeq From Bill_M_Approve Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo
Select @ApproveUserNo = User_no, @AddApproveUser = Add_ApproveUser From Person_d_Approve Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo and ApproveSeq = @ApproveSeq
if Upper(@ApproveUserNo) = Upper(@UserNo)
Begin
Set @IsCompare = 1
Return 0
End
--當前用戶與單據的當前簽核用戶不相同時,檢查是否代理的用戶
if @UserList = ''
Begin
Set @AddApproveUser = '0'
Return 0
End
--返回的借用戶列表格式:a,b,c
Set @UserList = ',' + @UserList + ','
if CharIndex(','+@UserNo+',', @UserList) > 0
Set @IsCompare = 1
Else
Begin
Set @AddApproveUser = '0'
Set @IsCompare = 0
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_DeleteBillColumnShow
/********************************
*介紹:刪除某單據的顯示欄位信息
*作者:Billy
*書寫時間:2006/1/27
*說明:涉及表名[bill_column_display]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10)
)
as
Delete bill_column_display Where Company_no = @CompanyNo and Kind_no = @KindNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_DeleteBillFromBillNo
/*******************************
程序功能:刪除指定單據代號的單據信息
編寫人員:Billy
編寫日期:2006/09/16
*******************************/
(
@BillNo varchar(30)
)
As
if Exists( Select * From bill_m_approve Where Bill_No = @BillNo)
Begin
delete From bill_file where bill_no = @BillNo
delete From person_approve_file where bill_no = @BillNo
delete From Person_d_approve Where bill_no = @BillNo
delete From bill_m_approve where bill_no =@BillNo
delete From bill_item_approve where bill_no =@BillNo
delete From bill_approve_log where bill_no =@BillNo
End
if Exists( Select * From bill_m_approved Where Bill_No = @BillNo)
Begin
delete From bill_file_done where bill_no = @BillNo
delete From person_approved_file where bill_no = @BillNo
delete From bill_approve_validate where bill_no =@BillNo
delete From person_d_approved where bill_no = @BillNo
delete From bill_m_approved where bill_no = @BillNo
delete From bill_item_approved where bill_no =@BillNo
delete From bill_approve_validate_log where bill_no =@BillNo
delete From bill_approved_log where bill_no =@BillNo
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_DeleteColumn
/*******************************
程序功能:刪除某單據類型的單據欄位定義信息
編寫人員:Billy
編寫日期:2006/12/04
*******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BelongTable char(1) --指示是刪除主表的欄位信息還是明細表欄位信息。1:主表; 2:明細表
)
As
Delete From Bill_Column Where Company_No = @CompanyNo and Kind_No = @KindNo and belong_table = @BelongTable
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_BillKindList
/*
功能:
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@BillNo: 單據代號
說明:
*/
(
@UserNo varchar(20),
@CompanyNo varchar(10),
@Complete char(1) = 'N'
)
As
Declare @UserList varchar(1000), @Sql NVarchar(4000)
Create Table #tb1 (company_no varchar(10), kind_no varchar(10))
Create Table #tb2 (company_no varchar(10), kind_no varchar(10))
Exec pr_SelectDeputyPersonList @UserNo, @UserList out
If @UserList = '' Or @UserList Is Null
Set @UserList = @UserNo
Else
Set @UserList = @UserList + ',' + @UserNo
Set @UserList = '''' + Replace(@UserList, ',', ''',''') + ''''
--未完成確認的部分
Set @Sql = N'Select Distinct company_no,Kind_no From Bill_Approve_Validate Where Company_No = @CompanyNo and setting_user_no in(' + @UserList + ') and validate != ''3'''
Insert into #tb1 Execute sp_ExecuteSql @Sql, N'@CompanyNo varchar(10)', @CompanyNo
--已完成確認的部分
Set @Sql = N'Select Distinct company_no, Kind_no From Bill_Approve_Validate Where Company_No=@CompanyNo and setting_user_no in(' + @UserList + ') and validate = ''3'''
Insert into #tb2 Execute sp_ExecuteSql @Sql, N'@CompanyNo varchar(10)', @CompanyNo
If @Complete = 'Y' --取已完成確認的單據類型
Select M.Kind_no, B.Kind_Nm From #tb2 M Inner join Bill_Kind B On M.company_no = B.Company_No And M.kind_no = B.Kind_no Where M.Kind_no Not In(Select Kind_no From #tb1)
Else --取未完成確認的單據類型
Select M.Kind_no, B.Kind_nm From #tb1 M Inner join Bill_Kind B On M.company_no = B.Company_No And M.kind_no = B.Kind_no Where M.Kind_no Not In(Select Kind_no From #tb2)
Drop Table #tb1
Drop Table #tb2
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_Content
/*
功能:取得某單據的效果確認內容
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
Select B.Seq, B.Setting_User_no, B.actual_User_no, U.User_name Setting_User_Name,
B.Validate, B.Note, Convert(varchar(19),B.Validate_Date,120) Validate_Date Into #tbPerson From Bill_Approve_Validate B
left Outer Join UserAdmin U On B.Setting_User_No = U.user_no
Where B.Company_no = @CompanyNo and B.Kind_No = @KindNo and B.Bill_No = @BillNo
Order By B.Validate Desc, B.Validate_Date Asc
Update #tbPerson Set Actual_user_no = setting_user_no Where Actual_User_no is null
Select M.*, U.User_Name Actual_User_Name, P.Position_Name Actual_Position_Name,
dbo.fn_DepartmentFrame(U.company_no,U.dept_No) Actual_Department
From #tbPerson M
left Outer Join UserAdmin U On M.actual_user_no = u.user_no
Left Outer Join Position P On U.position_no = P.Position_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Bill_EffectValidate_File_Delete
/*
功能:刪除一個效果確認附檔
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@Seq: 用戶對應字段Seq的值
@FileID: 文檔ID
@FilePath: 文檔路徑,傳出參數
說明:當成功刪除時,請同時在程序中物理刪除此文檔
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@Seq int,
@FileID int,
@FilePath varchar(100) out
)
As
Set @FilePath = ''
Select @FilePath = File_Path From Bill_Approve_Validate_File
Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo And Seq = @Seq And [File_ID] = @FileID
Delete Bill_Approve_Validate_File Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo And Seq = @Seq And [File_ID] = @FileID
If @@Error = 0
Return 1
Else
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Bill_EffectValidate_File_Info
/*
功能:取得某單據所有用戶的效果確認信息及附檔
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@Complete: 是否已全部通過確認, Y:全部通過 N:未完成
說明:
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@Complete char(1) out
)
As
Set @Complete = 'N'
--取得該單據所有進行效果確認的用戶信息
Select M.Company_no, M.Kind_no, M.Bill_No, M.Seq, dbo.fn_ConvertValidateStatus(M.Validate),
U1.User_Name Default_User_Name, U2.User_Name actual_User_name, P.Position_Name actual_Position_Name,
dbo.Fn_DepartmentFrame(U2.company_no,U2.dept_no) actual_Dept_nm,M.Note, Validate_Date
From Bill_Approve_Validate M
Left outer Join UserAdmin U1 On M.setting_user_no = U1.user_no
Left Outer Join UserAdmin U2 On M.actual_user_no = U2.User_no
left Outer Join Position P On P.company_no = U2.company_no and P.Position_no = U2.Position_no
Where M.Company_No = @CompanyNo And M.Kind_No = @KindNo and M.Bill_No = @BillNo
Order By M.Seq
--取得附件列表
Select Seq, [File_ID], File_Path From Bill_Approve_Validate_File
Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo
--檢查是否完成效果驗證
If Not Exists(Select Bill_No From Bill_Approve_Validate Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo and Validate != '3' )
Set @Complete = 'Y'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Bill_EffectValidate_File_List
/*
功能:保存效果確認附檔
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
說明:
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
Select Seq, [File_ID], File_Path From bill_Approve_Validate_File Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_File_Save
/*
功能:保存效果確認附檔
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@Seq: 用戶對應字段Seq的值
@FilePath1: 文檔路徑,傳出參數
@FilePath2: 文檔路徑,傳出參數
@FilePath3: 文檔路徑,傳出參數
說明:
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@Seq int,
@FilePath1 varchar(100),
@FilePath2 varchar(100),
@FilePath3 varchar(100)
)
As
Declare @FileID SmallInt
Set @FilePath1 = IsNull(@FilePath1,'')
Set @FilePath2 = IsNull(@FilePath2,'')
Set @FilePath3 = IsNull(@FilePath3,'')
If Not Exists(Select Bill_no From Bill_Approve_Validate Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo And Seq = @Seq)
Return 0
Select @FileID=Max(file_id) From Bill_Approve_Validate_File Where Company_No = @CompanyNo And Kind_No = @KindNo and Bill_No = @BillNo
Set @FileID = IsNull(@FileID, 0)
Begin Transaction
If( @FilePath1 != '' )
Begin
set @FileID = @FileID + 1
Insert into Bill_Approve_Validate_File (company_no,Kind_no,bill_no, seq, [File_ID], file_path)
Values(@CompanyNo, @KindNo, @BillNo, @Seq, @FileID, @FilePath1)
If @@Error != 0 Goto Err
End
If( @FilePath2 != '' )
Begin
set @FileID = @FileID + 1
Insert into Bill_Approve_Validate_File (company_no,Kind_no,bill_no, seq, [File_ID], file_path)
Values(@CompanyNo, @KindNo, @BillNo, @Seq, @FileID, @FilePath2)
If @@Error != 0 Goto Err
End
If( @FilePath3 != '' )
Begin
set @FileID = @FileID + 1
Insert into Bill_Approve_Validate_File (company_no,Kind_no,bill_no, seq, [File_ID], file_path)
Values(@CompanyNo, @KindNo, @BillNo, @Seq, @FileID, @FilePath3)
If @@Error != 0 Goto Err
End
Commit Transaction
Return 1
Err:
RollBack Transaction
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_List
/*
功能:取得某用戶需要進行效果確認的列表
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@UserNo: 當前用戶代號
@Mode: 查詢驗證狀態,1:未進行, 2:未通過, 3:已通過, 4:1&2的並集, 5:全部
@OrderField: 排序的字段
@OrderType: 排序方式, 1:降序, 2:升序
@PageIndex: 當前頁索引
@PageSize: 頁大小
@PageCount: 頁總數,傳出
*/
(
@UserNo varchar(20),
@CompanyNo varchar(10) = '',
@KindNo varchar(10) = '',
@BillNo varchar(30) = '',
@Mode char(1) = '4',
@OrderField varchar(100) = 'Complete_Date',
@OrderType char(1) = '1',
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
As
Declare @UserList varchar(1000), @Sql Varchar(6000)
Exec pr_SelectDeputyPersonList @UserNo, @UserList out
If @UserList = '' Or @UserList Is Null
Set @UserList = @UserNo
Else
Set @UserList = @UserList + ',' + @UserNo
Set @UserList = '''' + Replace(@UserList, ',', ''',''') + ''''
Set @CompanyNo = Ltrim(@CompanyNo)
Set @KindNo = Ltrim(@KindNo)
Set @BillNo = Ltrim(Rtrim(@BillNo))
--處理排序
If @OrderField = ''
Set @OrderField = 'Complete_Date'
If @OrderType = '2'
Set @OrderField = @OrderField + ' Desc'
/*
--當查詢完成跟蹤的單據時,不會重復
Set @Sql = 'Select Distinct B.Company_No,B.Kind_no,B.Bill_No,Case ' + @Mode + ' when ''3'' then 0 else M.seq End Seq,dbo.fn_ConvertExigencyGrade(B.Exigency_Grade) Exigency,'
+ 'dbo.fn_ConvertValidateStatus(M.Validate) Validate,convert(varchar(16),B.Complete_Date,120) Complete_date,Convert(varchar(16),B.Create_Date,120) Create_Date'
+ ',U.User_Name create_person From (select Distinct Company_no,kind_no,Bill_no,Seq,Validate From Bill_Approve_Validate '
+ 'Where setting_User_no In(' + @UserList + ') '
*/
Set @Sql = 'Select B.Company_No,B.Kind_no,B.Bill_No, M.seq,dbo.fn_ConvertExigencyGrade(B.Exigency_Grade) Exigency,'
+ 'dbo.fn_ConvertValidateStatus(M.Validate) Validate,convert(varchar(16),B.Complete_Date,120) Complete_date,Convert(varchar(16),B.Create_Date,120) Create_Date'
+ ',U.User_Name create_person From (select Distinct Company_no,kind_no,Bill_no,Seq,Validate From Bill_Approve_Validate '
+ 'Where setting_User_no In(' + @UserList + ') '
if( @Mode = '1' or @Mode = '2' Or @Mode = '3' )
Set @Sql = @Sql + 'And Validate = ''' + @Mode + ''' '
if( @Mode = '4' )
Set @Sql = @Sql + 'And Validate != ''3'' '
if ( @CompanyNo != '' )
Set @Sql = @Sql + 'And Company_no=''' + @CompanyNo + ''' '
If( @KindNo != '' )
Set @Sql = @Sql + 'And Kind_no=''' + @KindNo + ''' '
if( @BillNo != '' )
SEt @Sql = @Sql + ' And Bill_no Like ''%' + @BillNo + '%'' '
Set @Sql = @Sql + ') M Inner Join Bill_M_Approved B On M.company_no=B.company_no and M.Kind_no=B.Kind_no And M.Bill_No=B.Bill_No '
+ 'Left outer Join UserAdmin U On B.Create_Person=U.User_No'
Print @Sql
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', @OrderField
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_Log
/*
功能:取得某單據的效果確認日志信息
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
說明:
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
--取得該單據所有進行效果確認的用戶信息
Select M.Seq, M.Validate,M.actual_user_no,M.setting_user_no,
U1.User_Name Setting_User_Name, U2.User_Name actual_User_name, P.Position_Name actual_Position_Name,
dbo.Fn_DepartmentFrame(U2.company_no,U2.dept_no) actual_Department,M.Note, Convert(varchar(19),Validate_Date,120) Validate_Date
From Bill_Approve_Validate_Log M
Left outer Join UserAdmin U1 On M.setting_user_no = U1.user_no
Left Outer Join UserAdmin U2 On M.actual_user_no = U2.User_no
left Outer Join Position P On P.company_no = U2.company_no and P.Position_no = U2.Position_no
Where M.Company_No = @CompanyNo And M.Kind_No = @KindNo and M.Bill_No = @BillNo
Order By M.Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_Save
/*
功能:保存用戶的單據效果確認信息
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@UserNo: 進行效果確認的用戶代號
@Seq: 用戶對應字段Seq的值
@Pass: 是否通過, Y通過,N未通過
@Note: 確認信息
@Complete: 是否全部完成確認,1:完成 0:未完成
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@UserNo varchar(20),
@Seq int,
@Pass char(1) = 'N',
@Note varchar(6000),
@Complete bit = 0 out
)
As
Declare @DefaultUserNo varchar(20)
Declare @LogID int
Set @Complete = 0
--檢查記錄是否存在
If Not Exists(Select Bill_No From Bill_Approve_Validate Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_No = @BillNo And Seq = @Seq)
Return 0
Select @DefaultUserNo = Setting_User_no From Bill_Approve_Validate Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_No = @BillNo And Seq = @Seq
If @Pass = 'Y'
Set @Pass = '3'
Else
Set @Pass = '2'
Begin Transaction
Update Bill_Approve_Validate
Set actual_User_no = @UserNo, Validate = @Pass, Note = @Note, Validate_Date = GetDate()
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_No = @BillNo And Seq = @Seq
If @@Error != 0 GoTo Err
Select @LogID = Max(Log_ID) From Bill_Approve_Validate_Log Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_No = @BillNo
Set @LogID = IsNull(@LogID, 0) + 1
--添加日志
Insert Into Bill_Approve_Validate_Log
Select Company_no, Kind_no, Bill_No,Seq, @LogID, Setting_User_No, Actual_User_no, Validate, Note, Validate_Date
From Bill_Approve_Validate
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_No = @BillNo And Seq = @Seq
If @@Error != 0 GoTo Err
--通過確認,檢查是否全部完成確認動作
If @Pass = '3' And Not Exists(Select Bill_No From Bill_Approve_Validate Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_No = @BillNo And Validate != '3')
Set @Complete = 1
Commit Transaction
Return 1
Err:
RollBack Transaction
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_EffectValidate_Value
/*
功能:取得某用戶對某單據的效果確認信息及上傳的附檔列表
作者:Billy
日期:2007/03/07
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@UserNo: 當前用戶代號
@PageIndex: 當前頁索引
@PageSize: 頁大小
@PageCount: 頁總數,傳出
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@Seq int,
@Note varchar(6000) out
)
As
Set @Note = ''
Select @Note = note From Bill_Approve_Validate
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_no = @BillNo And Seq = @Seq
Select [File_ID], File_Path From Bill_Approve_Validate_File
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_no = @BillNo And Seq = @Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Bill_Exception_Kind_Delete
/**************************************
* 功能:刪除單條品質異常種類
* 作者:Billy
* 日期:2006/11/18
**************************************/
(
@CompanyNo varchar(10),
@ExceptionNo Varchar(2),
@ErrorNo varchar(50) out
)
As
Declare @RowCount int
if Not Exists( Select * From Bill_Exceptino_Kind Where Exception_No = @ExceptionNo And Company_No = @CompanyNo)
Begin
Set @ErrorNo = 'NoData'
return 0
End
Delete From Bill_Exceptino_Kind Where Exception_No = @ExceptionNo And Company_No = @CompanyNo
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @ErrorNo = 'UnDelete'
Return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Bill_Exception_Kind_Insert
/**************************************
* 功能:添加新的品質異常種類
* 作者:Billy
* 日期:2006/11/18
**************************************/
(
@CompanyNo varchar(10),
@ExceptionNo varchar(2),
@ExceptionName varchar(60),
@Note varchar(100),
@ErrorNo varchar(50) out
)
As
Declare @RowCount int
--檢查類型代號是否被占用
if( Exists(Select * From Bill_Exception_Kind Where Exception_no = @ExceptionNo And Company_No = @CompanyNo) )
Begin
Set @ErrorNo = 'InUse'
return 0
End
--檢查名稱是否重復
If(Exists(Select * From Bill_Exception_Kind Where Exception_Name = @ExceptionName And Company_No = @CompanyNo) )
Begin
Set @ErrorNo = 'HasSameName'
return 0
End
Insert Into Bill_Exception_Kind (company_no, exception_No, exception_name, note )
Values( @CompanyNo, @ExceptionNo, @ExceptionName, @Note)
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @ErrorNo = 'Failing'
Return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Procedure pr_Bill_Exception_Kind_Select_Batch
/**************************************
* 功能:批量查詢異常種類信息
* 作者:Billy
* 日期:2006/11/18
* 說明:@SearchMode : 1:按公司查詢, 2:按傳遞的值查詢
**************************************/
(
@SearchMode char(1) = '1',
@CompanyNo varchar(60) = '',
@ExceptionNo Varchar(2) = '',
@ExceptionName varchar(60) = '',
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
As
Declare @Sql nVarchar(4000)
Set @Sql = 'Select C.company_nm, BK.* From Bill_Exception_Kind BK
Left Join Company C On BK.company_No = C.Company_No Where 1 = 1 '
if( Ltrim(@CompanyNo) != '' )
begin
if( @SearchMode = '1' )
Set @Sql = @Sql + ' and BK.company_no = ''' + @CompanyNo + ''' '
Else
Set @Sql = @Sql + ' and BK.company_no Like ''%' + @CompanyNo + '%'' Or C.Company_nm Like ''%' + @CompanyNo + '%'' '
End
if( @SearchMode = '2' )
begin
if( Ltrim(@ExceptionNo) != '' )
Set @Sql = @Sql + ' And BK.exception_no = ''' + @ExceptionNo + ''' '
if( Ltrim(@ExceptionName) != '' )
Set @Sql = @Sql + ' And Bk.Exception_Name Like ''%' + @ExceptionName + '%'''
end
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', N'company_nm, Exception_no'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Procedure pr_Bill_Exception_Kind_Select_Single
/**************************************
* 功能:查詢單條異常種類信息
* 作者:Billy
* 日期:2006/11/18
**************************************/
(
@CompanyNo varchar(10),
@ExceptionNo varchar(2)
)
As
Select C.company_nm, BK.* From Bill_Exception_Kind BK
Left Join Company C On BK.company_No = C.Company_No
Where BK.company_no = @CompanyNo And BK.exception_no = @ExceptionNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Bill_Exception_Kind_Update
/**************************************
* 功能:更新的品質異常種類
* 作者:Billy
* 日期:2006/11/18
**************************************/
(
@OldCompanyNo varchar(10),
@OldExceptionNo varchar(2),
@CompanyNo varchar(10),
@ExceptionNo varchar(2),
@ExceptionName varchar(60),
@Note varchar(100),
@ErrorNo varchar(50) out
)
As
Declare @RowCount int
if( Exists(Select * From Bill_Exception_Kind Where Company_no = @CompanyNo And Exception_No = @ExceptionNo))
Begin
Set @ErrorNo = 'NoData'
return 0
End
--檢查名稱是否重復
if( @OldCompanyNo = @CompanyNo )
Begin
if( @OldExceptionNo != @ExceptionNo )
Begin
If Exists(Select * From Bill_Exception_Kind Where company_no = @CompanyNo And exception_no = @ExceptionNo)
Begin
Set @ErrorNo = 'InUse'
return 0
End
End
If(Exists(Select * From Bill_Exception_Kind Where Exception_Name = @ExceptionName And Company_No = @CompanyNo And Exception_No != @ExceptionNo) )
Begin
Set @ErrorNo = 'HasSameName'
return 0
End
End
Else
Begin
--檢查數據是否已存在
if( Exists(Select *From Bill_Exception_Kind Where Company_no = @CompanyNo And Exception_No = @OldExceptionNo))
Begin
Set @ErrorNo = 'InUse'
Return 0
End
If( Exists(Select * From Bill_Exception_Kind Where Company_No = @CompanyNo And Exception_Name = @ExceptionName) )
Begin
Set @ErrorNo = 'HasSameName'
return 0
End
End
Update Bill_Exception_Kind Set Company_No = @CompanyNo, Exception_No =@ExceptionNo, Exception_Name = @ExceptionName, Note = @Note
Where Exception_No = @OldExceptionNo And Company_No = @OldCompanyNo
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @ErrorNo = 'Failing'
Return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Bill_GetApproveFromFlowSetting
/*************************************
** 將流程設定(bill_flow_d)轉換為最終的簽核人員列表
** 作者:Billy
** 時間:2006/10/22
** 參數:@CompanyNo, @KindNo, @UserNo
** 涉及表:bill_flow_d, useradmin , bill_kind, dept, position
** 注意:找不到的流程項忽略不管
*************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@UserNo varchar(20)
)
As
--存在結果集的表格,字段Result:1正常,2找不到,3多人任職
Declare @ApproveList Table(ID int Identity(1,1), flow_mode char(1), Result char(1), seq int, user_no varchar(20), approve_grade int, approve_company_no varchar(10), dept_no varchar(10),
position_no varchar(10), action_seq int, add_approveuser char(1), fillin char(1), effect_validate char(1), prompt varchar(100), endCase char(1),Condition varchar(50))
--存在臨時的用戶列表
Declare @TempApprover Table( ID int Identity(1,1), company_no varchar(10), dept_no varchar(10), position_no varchar(10), user_no varchar(20), approve_grade int)
if Not Exists(select * From bill_flow_d where company_no = @CompanyNo and kind_no = @KindNo)
GoTo ExitProc
Declare @MaxSeq int, @CycNumber int, @RowCount int, @Result char(1), @ChiefFlag char(1) --流程項序號、循環變量、記錄數、查找結果標記、處級標記
--存放用戶的公司、部門、職務信息、審核用戶代號
Declare @ApproveUser varchar(20), @UserCompanyNo varchar(10), @UserDeptNo varchar(10), @ApproveGrade int
Declare @UserPositionNo varchar(10), @ApproveUserNo varchar(20), @Seq int
--定義存放流程設定變量
Declare @FlowMode char(1), @ActionSeq int, @FillIn char(1), @EffectValidate char(1)
Declare @AddApproveUser char(1), @Prompt varchar(100), @EndCase char(1), @Condition varchar(50)
Select @MaxSeq = Max(Seq) From Bill_Flow_d WHere company_no = @CompanyNo and kind_no = @KindNo
Select @CycNumber = 1, @ApproveUser = @UserNo, @ApproveGrade = 0, @Prompt = ''
--得到用戶的公司、部門、職務信息
Select @UserCompanyNo = Company_no, @UserDeptNo = Dept_no, @UserPositionNo = Position_no, @ApproveGrade = approve_grade
From UserAdmin Where user_no = @UserNo
--通過循環,將流程設定轉換為最終的簽核人員列表
While @CycNumber <=@MaxSeq
Begin
Select @FlowMode = Flow_Mode From Bill_flow_d
WHere company_no = @CompanyNo and kind_no = @KindNo And Seq = @CycNumber
Select @Seq = Seq, @UserCompanyNo = approve_company_no, @UserDeptNo = dept_no, @UserPositionNo = position_no, @ActionSeq = action_seq,
@AddApproveUser = add_approveuser, @FillIn = fillin, @EffectValidate = effect_validate, @Prompt = prompt, @EndCase = endcase, @Condition = condition
From bill_flow_d WHere company_no = @CompanyNo and kind_no = @KindNo And Seq = @CycNumber
if @FlowMode = '1' --根據公司、部門、職務代號找用戶
Begin
--得到公司、部門、職務代號
Select @UserCompanyNo = Approve_company_no, @UserDeptNo = dept_no, @UserPositionNo = Position_no From Bill_flow_d
WHere company_no = @CompanyNo and kind_no = @KindNo And Seq = @CycNumber
--根據取得的公司、部門、職務代號找用戶,並將結果保存到@TempApprover
Delete From @TempApprover
Insert Into @TempApprover
Select company_no, dept_no, position_no, user_no, approve_grade From UserAdmin
Where Company_no = @UserCompanyNo And Dept_no = @UserDeptNo And Position_No = @UserPositionNo
And Approve_Grade > 0 And OA.dbo.fn_CheckUserStatus(Status, getDate(), active_Date, Disable_date) = 'Y'
if Not Exists( Select * From @TempApprover ) --無匹配的數據
Goto NextCyc
Select @RowCount = Count(*) From @TempApprover --或Set @RowCount = @@RowCount
Select @Result = Case @RowCount When 0 then '2' When 1 then '1' else '3' end
Insert Into @ApproveList
Select @FlowMode flow_mode, @Result, @Seq As Seq, user_no, approve_grade, company_no,
dept_no, position_no, @ActionSeq, @AddApproveUser, @FillIn, @EffectValidate, @Prompt, @EndCase, @Condition
From @TempApprover
Goto NextCyc
End
If @FlowMode = '2' Or @FlowMode = '3' --2本部門, 3根據部門
Begin
if @FlowMode = '2' --本部門
Select @UserCompanyNo = company_no, @UserDeptNo = dept_no From UserAdmin Where user_no = @UserNo
Else --根據部門
Select @UserCompanyNo = Approve_company_no, @UserDeptNo = Dept_no From Bill_Flow_d Where company_no = @CompanyNo and kind_no = @KindNo And Seq = @CycNumber
--找出本部門的主管
Delete From @TempApprover
Insert into @TempApprover
select U.Company_no, U.Dept_no, U.Position_no, U.user_no, approve_Grade
From UserAdmin U
Inner Join Position P On U.position_no = P.position_no
Where U.dept_no = @UserDeptNo And (P.Dept_Director = 'Y' OR P.Approve = 'Y')
And OA.dbo.fn_CheckUserStatus(U.Status, getDate(), U.active_Date, U.Disable_date) = 'Y'
if Not Exists( Select * From @TempApprover ) --無匹配的數據
Goto NextCyc
Select @RowCount = Count(*) From @TempApprover
Select @Result = Case @RowCount When 0 then '2' else '1' end
Insert Into @ApproveList
Select @FlowMode flow_mode, @Result, @Seq As Seq, user_no, approve_grade, company_no,
dept_no, position_no, @ActionSeq, @AddApproveUser, @FillIn, @EffectValidate, @Prompt, @EndCase, @Condition
From @TempApprover
GoTo NextCyc
End
if @FlowMode = '4' --建單人
Begin
if Not Exists(Select * From UserAdmin Where User_No = @UserNo)
Begin
GoTo NextCyc
End
--得到用戶的公司、部門、職務代號
Select @UserCompanyNo = Company_no , @UserDeptNo = Dept_no, @UserPositionNo = position_no, @ApproveGrade = approve_grade From UserAdmin WHere User_no = @UserNo
Set @ApproveUser = @UserNo
Insert into @ApproveList (flow_mode, result, Seq, user_no, approve_grade, approve_company_no, dept_no, position_no, action_seq, add_approveuser, fillin, effect_validate, prompt, endcase, condition)
values( @FlowMode,'1', @seq, @ApproveUser, @ApproveGrade, @UserCompanyNo, @UserDeptNo, @UserPositionNo, @ActionSeq, @AddApproveUser, @FillIn, @EffectValidate, @Prompt, @EndCase, @Condition)
Goto NextCyc
End
if @FlowMode = '5' Or @FlowMode = '6' --5從建單人部門到處級, 6從選擇部門到處級
Begin
if @FlowMode = '5' --5從建單人部門到處級
Select @UserCompanyNo =Company_no, @UserDeptNo = Dept_no From UserAdmin Where User_No = @UserNo
Else --6從選擇部門到處級
Select @UserCompanyNo = Approve_Company_No, @UserDeptNo = Dept_no From Bill_Flow_d Where company_no = @CompanyNo and kind_no = @KindNo And Seq = @CycNumber
Delete From @TempApprover
Set @ChiefFlag = 'N'
--得到部門到處級的主管
While( Exists(Select * From Dept WHere Company_no = @UserCompanyNo And Dept_no = @UserDeptNo) And @ChiefFlag != 'Y' )
Begin
Insert Into @TempApprover
select U.Company_no, U.Dept_no, U.Position_no, U.user_no, approve_grade
From UserAdmin U
Inner Join Position P On U.position_no = P.position_no
Where U.Company_no = @UserCompanyNo And U.dept_no = @UserDeptNo And (P.Dept_Director = 'Y' OR P.Approve = 'Y')
And OA.dbo.fn_CheckUserStatus(U.Status, getDate(), U.active_Date, U.Disable_date) = 'Y'
Order By Approve_Grade ASC
--得到上級部門代號
Select @UserDeptNo = Parent_Dept_no, @ChiefFlag = Chief_Flag From Dept Where Company_no = @UserCompanyNo And Dept_no = @UserDeptNo
End
if Not Exists( Select * From @TempApprover ) --無匹配的數據
Goto NextCyc
Select @RowCount = Count(*) From @TempApprover
Select @Result = Case @RowCount When 0 then '2' else '1' end
Insert Into @ApproveList
Select @FlowMode flow_mode, @Result, @Seq As Seq, user_no, approve_grade, company_no,
dept_no, position_no, @ActionSeq, @AddApproveUser, @FillIn, @EffectValidate, @Prompt, @EndCase, @Condition
From @TempApprover
Goto NextCyc
End
NextCyc:
Set @CycNumber = @CycNumber + 1
End
ExitProc:
Select AL.*, AK.action_nm, Ak.approve, U.User_name, U.Approve_Grade, dbo.fn_DepartMentFrame(AL.approve_company_no, AL.dept_no) DepartMent, P.Position_Name
From @ApproveList AL
Inner Join UserAdmin U On AL.User_no = U.User_no
Inner Join Position P On AL.position_No = P.position_No
Inner Join Action_Kind Ak On AK.company_no = @CompanyNo and AL.action_seq = AK.action_seq
Order by ID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetApproveInfoForMail
/********************************
*介紹:取得某單據信息及其簽核人員的信息,以提供發送郵件時使用
*作者:Billy
*書寫時間:2006/12/13
*修改時間:
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
Declare @BillTableName varchar(50), @CreaterSql varchar(1000)
Declare @ID int, @RowCount int, @DeputyUserNo varchar(20)
--定義表變量,存在簽核人員信息
Declare @ApprovePerson Table(ID int IDentity(1,1),company_no varchar(10), kind_no varchar(10), Bill_No varchar(30), Seq int, ApproveSeq int, Action_Seq int,
User_No varchar(20), ApproveUser varchar(20), DeputyUser varchar(20), Approve_Date DateTime, Approve_Sign char(1), Note varchar(6000))
if Exists( Select * From Bill_m_Approve Where company_no = @CompanyNo and Kind_no = @KindNo and bill_no = @BillNo ) --在第一套表中操作
Begin
Insert into @ApprovePerson
Select company_no, kind_no, Bill_no, Seq, ApproveSeq, Action_Seq, User_no, Actual_User_no ApproveUser,'' DeputyUser, Approve_Date, Approve_sign, Note
From Person_d_Approve Where company_no = @CompanyNo and Kind_no = @KindNo and Bill_no = @BillNo
Set @BillTableName = 'Bill_M_Approve'
End
else
Begin
Insert into @ApprovePerson
Select company_no, kind_no, Bill_no, Seq, ApproveSeq, Action_Seq, User_no, Actual_User_no ApproveUser, '' DeputyUser, Approve_Date, Approve_sign, Note
From Person_d_Approved Where company_no = @CompanyNo and Kind_no = @KindNo and Bill_no = @BillNo
Set @BillTableName = 'Bill_M_Approved'
End
--ApproveUser為實際簽核用戶
Update @ApprovePerson Set DeputyUser = case ApproveUser When Null then ApproveUser Else User_no End
Update @ApprovePerson Set DeputyUser = dbo.fn_GetDeputyFromUser(DeputyUser, getdate())
Select M.ID, M.ApproveSeq, M.Approve_Sign, M.Action_Seq, A.Action_nm, A.Approve, M.note,
M.User_no DefaultUser, U1.User_Name DefaultUserName, P1.Position_name DefaultUserPosition, U1.email_inform DefaultUserInform, dbo.fn_DepartmentFrame(U1.company_no, U1.dept_no) DefaultUserDepartMent, U1.email DefaultUserEmail,
ApproveUser, U2.User_name ApproveUserName, P2. Position_Name ApproveUserPosition, U2.email_inform ApproveUserInform, dbo.fn_DepartmentFrame(U2.company_no, U2.dept_no) ApproveUserDepartMent, U2.email ApproveUserEmail,
DeputyUser, U3.User_Name DeputyUserName, P3.Position_name DeputyUserPosition, U3.email_inform DeputyUserInform, dbo.fn_DepartmentFrame(U3.company_no, U3.dept_no) DeputyUserDepartMent, U3.Email DeputyUserEmail
From @ApprovePerson M
Left Join Action_Kind A On M.action_seq = A.action_Seq And M.company_no = A.company_No
Left Join UserAdmin U1 On M.user_no = U1.user_no
Left Join UserAdmin U2 on M.ApproveUser = U2.user_no
Left Join UserAdmin U3 On M.DeputyUser = U3.User_no
Left Join Position P1 On U1.Position_no = P1.Position_No And U1.company_no = P1.company_no
Left Join Position P2 On U2.Position_no = P2.Position_No And U2.company_no = P2.company_no
Left Join Position P3 On U3.Position_no = P3.Position_No And U3.company_no = P3.company_no
Order by ApproveSeq, ID
--單據創建者
Set @CreaterSql = 'select M.*,P.position_name From
(
Select B.company_no,B.Kind_no,BK.company_nm, Bk.Kind_nm, B.bill_no,B.Exigency_grade,B.create_person,B.create_date,
U.User_no, U.user_name,U.email,U.email_inform,U.position_no, U.Tel, dbo.fn_DepartMentFrame(U.company_no,U.Dept_no) DepartMent
From ' + @BillTableName + ' B
Left Join (
Select C.Company_Nm, K.Kind_nm, K.Kind_No From Bill_Kind K
Inner Join Company C On K.company_no = C.Company_no
) BK ON B.Kind_no = BK.Kind_no
left Join UserAdmin U ON B.create_person=U.user_no WHere B.company_no = ''' +@CompanyNo + ''' and B.Kind_no = ''' + @KindNo + ''' and B.Bill_no = ''' +@BillNo + '''
)M left Join position P on P.position_no=M.position_no'
Exec( @CreaterSql )
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetApproveNote
/*******************************
程序功能:取得某單據某序號對應的簽核信息
編寫人員:Billy
編寫日期:2007/01/12
*******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int,
@Note varchar(6000) out
)
As
Set @Note = ''
Select @Note = Note From Person_d_Approve
Where Company_No = @CompanyNo and Kind_No = @KindNo and Bill_no = @BillNo and ApproveSeq = @ApproveSeq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetApprovePerson
/********************************
*介紹:取得簽核用戶列表
*作者:Billy
*書寫時間:2007/01/08
*傳入:
*返回:
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@StartApproveSeq int = 0,
@EndApproveSeq int = 0,
@CurrentApproveSeq int out --單據的當前待簽用戶對應的ApproveSeq
)
as
Declare @TableName Nvarchar(50), @FileTableName varchar(50), @Sql nVarchar(2000)
Declare @MainTable nVarchar(50)
Declare @ApproveSeq int --存放臨時的ApproveSeq
Declare @ID int, @Rows int --用於循環計數
Declare @PreviousTime datetime --前一用戶簽核日期
Declare @CurrnetTime datetime --用戶簽核日期
Declare @ApproveSign char(1)
Declare @NeedApprove char(1) --是否需要簽核
--創建臨時表,存在簽核用戶信息
Create Table #tbPerson(ID int Identity(1,1), Seq int, ApproveSeq int, Action_Seq int, Approve char(1), Action_Nm varchar(20),
Chief_No Varchar(10),User_No varchar(20),Actual_User_no varchar(20), Approve_Grade int, Note varchar(6000),
Approve_Date DateTime, Mark_Name varchar(60), Approve_Sign char(1), TimeCost varchar(20))
--初始化變量
Set @CurrentApproveSeq = 0
Set @ApproveSeq = 0
Set @ID = 0
Set @Rows = 0
Set @PreviousTime = getDate()
Set @ApproveSign = '1'
Set @NeedApprove = 'N'
if Exists(select Bill_No from bill_m_approve where Company_no = @CompanyNo and Kind_no = @KindNo and bill_no=@BillNo)
Select @MainTable = 'Bill_M_Approve', @TableName = 'Person_d_Approve', @FileTableName = 'Person_Approve_File'
else
Select @MainTable = 'Bill_M_Approve', @TableName = 'Person_d_Approved', @FileTableName = 'Person_Approved_File'
Set @Sql = N'Select M.Seq,M.ApproveSeq, M.Action_Seq,A.Approve,A.Action_Nm,M.Chief_no, M.User_no,M.actual_User_no,'
+ N' M.Approve_Grade,M.Note,M.Approve_Date,M.Mark_Name,M.Approve_Sign, '''' '
+ N' From ' + @TableName + ' M Left Join Action_Kind A On A.Company_no=@CompanyNo And M.action_Seq=A.action_seq'
+ N' Where M.Company_no=@CompanyNo and M.Kind_no=@KindNo and M.Bill_No=@BillNo Order By M.ApproveSeq'
--將實際的簽核用戶信息插入臨時表中
insert into #tbPerson Exec Sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
Select @Rows = Count(*) From #tbPerson
If @Rows < 1 GoTo ExitProc
/*開始計算並更新各簽核用戶的簽核時間*/
--取得當前簽核順序及建單日期
Select @Sql = N'Select @CurrentApproveSeq=Current_ApproveSeq,@PreviousTime = Create_Date From ' + @MainTable + ' Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo'
Exec sp_Executesql @Sql, N'@CurrentApproveSeq int out, @PreviousTime DateTime out, @CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CurrentApproveSeq out, @PreviousTime out, @CompanyNo, @KindNo, @BillNo
Set @ID = 1
While @ID <= @Rows
Begin
Select @ApproveSign = Approve_Sign, @ApproveSeq = ApproveSeq, @CurrnetTime = Approve_Date, @NeedApprove = Approve From #tbPerson Where [ID] = @ID
If @NeedApprove != 'Y' Or @ApproveSign = '5'
Begin
Set @ID = @ID + 1
Continue
End
If @CurrnetTime Is Null Set @CurrnetTime = GetDate()
Update #tbPerson
Set TimeCost = dbo.fn_ConvertToTime(AbS( datediff(mi , @PreviousTime , @CurrnetTime))) Where ID = @ID
If @ApproveSeq = @CurrentApproveSeq Or @ApproveSign = '2' Or @ApproveSign = '4'
Break --已到達當前待簽用戶或為退單、結案的用戶,後面的不需再進行計算
Set @PreviousTime = @CurrnetTime
Set @ID = @ID + 1
End
If @StartApproveSeq > 0
Delete #tbPerson Where ApproveSeq Not between @StartApproveSeq And @EndApproveSeq
Set @Sql = 'select Seq,Seq_File,File_path From ' + @FileTableName + ' Where company_No=@CompanyNo and kind_No=@KindNo and Bill_No=@BillNo'
ExitProc:
select M.seq,M.approveSeq,C.company_nm,M.user_no, U1.user_name,D1.dept_nm userdept,P1.position_name,
M.actual_user_no,U2.user_name actualName,D2.dept_nm actualDept,P2.position_name Actual_position_name,
M.action_nm,M.Approve,M.approve_date,M.TimeCost,
M.action_seq,M.approve_sign,dbo.fn_Bill_ConvertApproveSign(M.approve_sign) ApproveSign,M.note,M.mark_name
from #tbPerson M
inner join company C on C.company_no = @CompanyNo
Inner join useradmin U1 on M.user_no=U1.user_no
left join useradmin U2 on M.actual_user_no=U2.user_no
left Join Position P1 On U1.position_no = P1.position_no and U1.company_no=P1.company_no
left Join Position P2 On U2.position_no = P2.position_no and U2.company_no=P2.company_no
left join dept D1 On U1.company_no = D1.company_no and D1.dept_no = U1.dept_no
left join dept D2 On U2.company_no = D2.company_no and D2.dept_no = U2.dept_no
Order By M.ApproveSeq
Execute sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Procedure pr_Bill_GetApprovePersonFiles
/**************************************
* 功能:取得某簽核人在某簽核順序上傳的附檔
* 作者:Billy
* 日期:2007/01/08
**************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int
)
As
Declare @Seq int
Set @Seq = 0
--根據@ApproveSeq取得Seq序號
Select @Seq = Seq From Person_D_Approve
Where Company_no = @CompanyNo and Kind_No = @KindNo and Bill_No = @BillNo and ApproveSeq = @ApproveSeq
Select Seq, Seq_File, File_Path From Person_Approve_File
Where Company_no = @CompanyNo and Kind_No = @KindNo and Bill_No = @BillNo and Seq = @Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetApprovePersonGroup
/********************************
*介紹:取得簽核用戶列表
*作者:Billy
*書寫時間:2007/01/08
*傳入:
*返回:
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
Declare @MainTable nVarchar(50), @TableName Nvarchar(50), @FileTableName varchar(50), @Sql nVarchar(2000)
Declare @CurrentApproveSeq int --單據的當前待簽用戶對應的ApproveSeq
Declare @UserCompanyNo varchar(10)
Declare @UserNo varchar(20)
Declare @ID int, @Rows int --用於循環計數
Declare @TempID int
Declare @ChiefNo varchar(10) --當前單位的處級代號
Declare @TempChiefNo varchar(15)
Declare @PersonCount smallint --各單位的簽核用戶數(包括被略過的簽核用戶,但不包括通知的用戶)
Declare @PreviousTime datetime --前一用戶簽核日期
Declare @StartApproveDate dateTime --當前單位開始簽核的時間
Declare @EndApproveDate datetime --當前單位最後的簽核時間
Declare @ApproveSign char(1) --簽核標記
Declare @SysTime DateTime --當前系統時間
Declare @StartApproveSeq int
Declare @EndApproveSeq int
Declare @Note Varchar(6000)
Declare @TimeCost varchar(30)
Set @SysTime = GetDate()
Create Table #tbPerson(ID int IDentity(1,1), ApproveSeq int, User_NO varchar(20),Chief_Group varchar(15), Chief_No varchar(10),Note varchar(6000), Approve_Date DateTime, Approve_Sign char(1))
/*定義用於保存結果的臨時表*/
Create Table #tbGroup(ID int identity(1,1), person_company_no varchar(10), person_dept_no varchar(10), Approve_Person_Count int, ApproveSeq_From int,
ApproveSeq_End int, Previous_Approve_Date datetime,Start_Approve_Date datetime, End_Approve_Date dateTime, TimeCost varchar(30),status nvarchar(5),Note varchar(6000))
--初始化變量
Set @CurrentApproveSeq = 1
Set @StartApproveSeq = 0
Set @ID = 0
Set @Rows = 0
Set @PreviousTime = getDate()
Set @ApproveSign = '1'
if Exists(select Bill_No from bill_m_approve where Company_no = @CompanyNo and Kind_no = @KindNo and bill_no=@BillNo)
Select @MainTable = 'Bill_M_Approve', @TableName = 'Person_d_Approve', @FileTableName = 'Person_Approve_File'
else
Select @MainTable = 'Bill_M_Approve', @TableName = 'Person_d_Approved', @FileTableName = 'Person_Approved_File'
Set @Sql = N'Select ApproveSeq, user_no, '''',Chief_no, Note,Approve_Date,Approve_Sign '
+ N'From ' + @TableName + ' Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo Order By ApproveSeq'
--將實際的簽核用戶信息插入臨時表中
insert into #tbPerson Exec Sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
Select @Rows = Count(*) From #tbPerson
If @Rows < 1 GoTo ExitProc
--通過設置Chief_Group,對各單位進行分組
Set @ID = 1
Set @TempID = 1
Set @TempChiefNo = ''
Set @ChiefNo = ''
Select @ChiefNo = Chief_no From #tbPerson Where ID = 1
While @ID <= @Rows
Begin
Select @TempChiefNo = Chief_No From #tbPerson Where ID = @ID
If @ChiefNo != @TempChiefNo
Begin
Set @TempID = @TempID + 1
Set @ChiefNo = @TempChiefNo
End
Update #tbPerson Set Chief_Group = Chief_No + '_' + Cast(@TempID As Varchar(4)) Where ID = @ID
Set @ID = @ID + 1
End
/*開始計算並更新各簽核用戶的簽核時間*/
--取得當前簽核順序及建單日期
Select @Sql = N'Select @CurrentApproveSeq=Current_ApproveSeq,@PreviousTime = Create_Date From ' + @MainTable + ' Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo'
Exec sp_Executesql @Sql, N'@CurrentApproveSeq int out, @PreviousTime DateTime out, @CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CurrentApproveSeq out, @PreviousTime out, @CompanyNo, @KindNo, @BillNo
Set @ID = 1
While @ID <= @Rows
Begin
Select @ApproveSign = Approve_Sign, @StartApproveSeq = ApproveSeq, @UserNo = User_No,
@ChiefNo = chief_no, @TempChiefNo = chief_Group, @StartApproveDate = Approve_Date
From #tbPerson Where [ID] = @ID
--取得用戶所在的公司代號
Select @UserCompanyNo = Company_No From UserAdmin Where User_No = @UserNo
--取得當前單位的最後一位簽核的用戶對應的ID(注意:此ID不一定為此單位最後一位簽核的用戶)
Select @TempID = Max(ID) From #tbPerson Where chief_group = @TempChiefNo
Select @EndApproveSeq = ApproveSeq From #tbPerson Where ID = @TempID
Set @PersonCount = @TempID - @ID + 1
Set @ID = @TempID + 1 --下一單位開始的ID的號
Print '@ID:' + Cast(@ID As varchar(10))
--取得最後一位簽核用戶的簽核時間
--如果有結案的用戶,則取結案用戶的簽核時間
If Exists(Select ID From #tbPerson Where chief_group = @TempChiefNo And Approve_Sign = '4')
Select @EndApproveDate = Approve_Date, @Note = Note From #tbPerson Where chief_group = @TempChiefNo And Approve_Sign = '4'
Else
Begin
Select @TempID = Max(ID) From #tbPerson Where chief_group = @TempChiefNo And Approve_Sign != '5'
Select @EndApproveDate = Approve_Date, @Note = Note From #tbPerson Where ID = @TempID
End
If @PreviousTime is Not null And @EndApproveDate is Not Null
Set @TimeCost = dbo.fn_ConvertToTime(Abs(Datediff(Minute, @PreviousTime, @EndApproveDate)))
Else If @PreviousTime Is Not Null
Set @TimeCost = dbo.fn_ConvertToTime(Abs(Datediff(Minute, @PreviousTime, @SysTime)))
Else
Set @TimeCost = ''
--插入到#tbGroup中
Insert Into #tbGroup
Values(@UserCompanyNo, @ChiefNo, @PersonCount, @StartApproveSeq, @EndApproveSeq, @PreviousTime, @StartApproveDate, @EndApproveDate, '', '', @Note)
Set @PreviousTime = @EndApproveDate
End
--更新簽核標記
If Exists(Select ID From #tbGroup Where @CurrentApproveSeq In(ApproveSeq_From,ApproveSeq_End))
Begin
Select @StartApproveSeq = ApproveSeq_From, @EndApproveSeq = ApproveSeq_End From #tbGroup Where @CurrentApproveSeq In(ApproveSeq_From,ApproveSeq_End)
Update #tbGroup Set Status = '已核准' Where ApproveSeq_From < @StartApproveSeq
Update #tbGroup Set Status = '未核准' Where ApproveSeq_End > @EndApproveSeq
Update #tbGroup Set Status = '簽核中' Where @CurrentApproveSeq In(ApproveSeq_From, ApproveSeq_End)
End
ExitProc:
Select M.ID, M.Person_Company_no, D.Dept_Nm, M.Person_Dept_no, M.Approve_Person_Count, ApproveSeq_From,
M.ApproveSeq_End, Convert(varchar(16),M.Start_Approve_Date, 120) Start_Approve_Date,
Convert(varchar(16), M.End_Approve_Date, 120) End_Approve_Date,
dbo.fn_ConvertToTime(dbo.fn_GetMinute(M.Previous_Approve_Date,M.End_Approve_Date,getdate())) TimeCost,
M.Status, M.Note From #tbGroup M
Inner Join Dept D On M.Person_company_no = D.company_no and M.Person_Dept_no = D.Dept_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetApproveUserFromDept
/********************************
*介紹:根據部門得出該部門(含該部門)所有上級的主管帳號或需要簽核文件的帳號
*作者:Billy
*書寫時間:2006/10/20
*傳入:@DeptNo
*返回:用戶列表
*說明:涉及表名[useradmin,Dept, Position]
*********************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(10),
@ToChiefDept char(1) = 'Y' --是否到處級部門
)
as
Declare @ParentDeptNo varchar(10), @ChiefFlag char(1)
Declare @User Table(ID int Identity(1,1), Company_no varchar(10), Dept_no varchar(10), User_no varchar(20), Approve_Grade int,
User_name varchar(12), position_no varchar(10), position_name varchar(30), Dept_Director char(1), approve char(1))
Select @ChiefFlag = 'N'
While( Exists(Select * From Dept WHere Dept_no = @DeptNo And Company_no = @CompanyNo) )
Begin
Insert Into @User
select U.Company_no, U.Dept_no, U.user_no, U.Approve_Grade, U.User_name, U.Position_no, P.Position_name, P.dept_Director, P.approve
From UserAdmin U
Inner Join Position P On U.position_no = P.position_no
inner join Dept D On U.dept_no = D.Dept_no And U.Company_no = D.Company_no
Where U.dept_no = @DeptNo And (P.Dept_Director = 'Y' OR P.Approve = 'Y')
if @ToChiefDept != 'Y'
Break;
--得到上級部門代號
Select @DeptNo = Parent_Dept_no, @ChiefFlag = Chief_Flag From Dept Where Dept_no = @DeptNo And Company_no = @CompanyNo
if( @ChiefFlag = 'Y' And @ToChiefDept = 'Y' )
Break;
End
Select *, OA.dbo.fn_DepartMentFrame(company_no, Dept_no) As DepartMent From @User order by Approve_grade
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetBillForApproverFillIn
/*****************************************************************
* 功能介紹:取得主表、子表的信息,以供審覈用戶在審覈過程中填寫相應的欄位信息
* 說明:
@CompanyNo :公司代號
@KindNo :單據類型代號
@BillNo :單據編號
* 返回回值:指定單據包含的字段名稱,字段類型,字段長度,是否允許空
* 注意事項:
* 建立日期:2006/06/28
* 建立人:Billy
* 修改日期:2006/07/01
* 修改人:Billy
* 修改內容:修改字段描述欄返回的值、返回單據欄位的所有值及單據對應的值
*****************************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
Exec pr_Bill_GetTableFrame @CompanyNo, @KindNo, @BillNo, '1'
Exec pr_Bill_GetTableFrame @CompanyNo, @KindNo, @BillNo, '2'
exec pr_Bill_GetItemList @CompanyNo, @KindNo, @BillNo, 'N'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetColumnValue
/********************************
*介紹:辦公自動化OA系統 (查詢指定欄位的值)
*作者:Bill6
*書寫時間:2006/12/06
*傳入:欄位名稱,單據NO
*返回:欄位值
*說明:涉及表名[bill_column]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(20),
@BelongTable char(1), --1為主表, 2為子表
@Column varchar(20),
@Value varchar(6000) out
)
AS
declare @sql nvarchar(500),@tableName sysname
if( @BelongTable = '1' )
Begin
if (Exists(select * from bill_m_approve where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo))
set @tableName='bill_m_approve'
else if (Exists(select * from bill_m_approved where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo))
set @tableName='bill_m_approved'
else
return 1
End
else --子表中查
Begin
if (Exists(select * from bill_Item_approve where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo))
set @tableName='bill_Item_approve'
else if (Exists(select * from bill_Item_approved where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo))
set @tableName='bill_Item_approved'
else
return 1
End
set @sql=N'select @Retrieve='+@Column+' from '+@tableName+ ' where company_no = ''' + @CompanyNo
+ ''' and Kind_no = ''' + @KindNo + ''' and bill_no='''+@BillNo+''''
exec sp_executesql @sql,N'@Retrieve nvarchar(4000) out',@Retrieve=@Value output
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE pr_Bill_GetFirstApproveSeq
/********************************
功能:取得單據的第一個簽核用戶的ApproveSeq
作者:Billy
日期:2007/02/11
返回:第一個簽核用戶對應的ApproveSeq,如果不存在則返回-1
說明:在未結案表中(Person_d_Approve)查找
***********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@FirstApproveSeq int out
)
As
Select @FirstApproveSeq = Min(M.ApproveSeq) From Person_d_Approve M
Inner Join Action_Kind A On M.company_no = A.company_no and M.action_Seq = A.action_Seq
Where M.company_no = @CompanyNo and M.kind_no = @KindNo and M.bill_no = @BillNo And A.approve = 'Y'
Set @FirstApproveSeq = IsNull(@FirstApproveSeq, -1)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetItemList
/*******************************
功能:取得Bill_item_approve中單據的值,且將字段以ColumnTitle取別名
作者:Billy
日期:2006/12/07
*******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ReplaceColumnName char(1) = 'N'
)
As
Declare @Sql varchar(5000), @ID int, @ColumnList varchar(4500), @RowCount int
Declare @ColumnName varchar(60), @ColumnTitle varchar(60), @TableName varchar(100)
Select @Sql = '', @ID = 0, @ColumnList = 'company_no, kind_no, bill_no, seq'
Select @ColumnName = '', @ColumnTitle = '', @TableName = 'Bill_Item_Approve'
if( Not Exists(Select * From Bill_Column Where Company_no = @CompanyNo and Kind_no = @KindNo And Belong_Table = '2') )
Begin
--不存在,返回一個空集
Select * From Bill_Item_Approve Where 1 > 2
return
End
--取得字段列表
Select ID=Identity(int,1,1), Seq, column_nm,column_title,column_kind,user_length into #tbColumn From Bill_Column Where Company_no = @CompanyNo and Kind_no = @KindNo and Belong_table = '2' order by Row_Seq
Set @ID = 1
Select @RowCount = Count(*) From #tbColumn
While @ID <= @RowCount
Begin
Select @ColumnName = Column_nm, @ColumnTitle = Column_title From #tbColumn Where ID = @ID
if @ReplaceColumnName = 'Y'
Set @ColumnList = @ColumnList + ',' + @ColumnName + ' [' + @ColumnTitle + ']'
else
Set @ColumnList = @ColumnList + ',' + @ColumnName
Set @ID = @ID + 1
End
if( Exists(Select * From bill_item_Approve Where Company_no = @CompanyNo and Kind_no = @KindNo and bill_no = @BillNo) )
set @TableName = 'Bill_Item_Approve'
else
set @TableName = 'Bill_Item_Approved'
Set @Sql = 'Select ' + @ColumnList + ' From ' + @TableName + ' Where company_no = ''' + @CompanyNo + ''' and Kind_No = ''' + @KindNo
+ ''' And Bill_no = ''' + @BillNo + ''' Order By Seq'
Print @Sql
Exec(@Sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Bill_GetItemSeqFromBillNo
/*******************************
功能:取得某單據在Bill_item_approve中的新Seq
作者:Billy
日期:2006/12/07
*******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(10),
@Seq int Out
)
As
Set @Seq = 0
Select @Seq = Max(Seq) From Bill_Item_Approve Where Company_no = @CompanyNo and Kind_No = @KindNo And Bill_no = @BillNo
Set @Seq = IsNull(@Seq, 0) + 1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE proc pr_Bill_GetLastApproveInfo
/*************************************
** 取得某單據結案用戶的簽核信息
** 作者:Billy
** 時間:2007/04/03
** 參數:輸入:@CompanyNo, @KindNo, @UserNo
** 注意:
*************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
Declare @Status char(1)
If Not Exists(Select Bill_No From Bill_M_Approved Where Company_no = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo)
Goto NoFound
Select @Status = status From Bill_M_Approved Where Company_no = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo
If @Status != '2' --非正常結案單據
GoTo NoFound
If Not Exists(Select Bill_No From Person_d_Approved Where Company_no = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo and Approve_Sign = '4')
Goto NoFound --找不到此單據結案的人員
--一張單據只能由一個人進行結案,所以只要找標記為4的數據
Select * From Person_d_Approved Where Company_no = @CompanyNo And Kind_No = @KindNo And Bill_No = @BillNo And Approve_Sign = '4'
Return 1
NoFound:
Select * From Person_D_Approve Where 1 > 2
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetNeedApproveBillCounts
/*******************************
程序功能:取得當前用戶待簽的單據數量
編寫人員:Billy
編寫日期:2006/12/09
*******************************/
(
@UserNo varchar(20)
)
As
Declare @DeputyUser varchar(1000), @Counts int
Declare @Sql nvarchar(4000)
exec pr_SelectDeputyPersonList @UserNo,@DeputyUser out
if @DeputyUser != ''
set @DeputyUser=@UserNo+','+@DeputyUser
else
set @DeputyUser=@UserNo
--取得當前用戶代理的其他用戶帳號
set @DeputyUser=''''+Replace(@DeputyUser,',',''',''')+''''
Set @Counts = 0
Set @Sql = N'Select @Counts=Count(*) From Bill_M_Approve BA '
+N'Inner Join Person_d_Approve PA On BA.company_no=PA.company_no and BA.kind_no=PA.kind_no and BA.bill_no=PA.bill_No and BA.current_ApproveSeq=PA.ApproveSeq '
+N'Inner Join Action_Kind AK On PA.company_no=AK.company_no and PA.action_Seq=AK.action_Seq '
+N'Where AK.Approve = ''Y'' and PA.User_no In(' + @DeputyUser + ')'
Exec sp_ExecuteSql @Sql, N'@Counts int out', @Counts output
Set @Counts = IsNull(@Counts, 0)
Return @Counts
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetPrototypeFrame
/*****************************************************************
* 功能介紹:取得單據原始表結構
* 說明:
* 返回回值:指定單據包含的字段名稱,字段類型,字段長度,是否允許空,字符描述
* 注意事項:
* 建立日期:2006/07/01
* 建立人:Billy
* 修改日期:2006/11/29
* 修改人:Billy
* 修改內容:篩選掉一些固定欄位
*****************************************************************/
(
@BelongTable char(1) = '1' --1:主表 2:子表
)
as
declare @sid varchar(20)
If @BelongTable = '1' --返回主表結構
Begin
select @sid=id from sysobjects where name='bill_m_approve'
select C.[name] as FieldName,C.colorder , T.[name] as TypeName , C.length , C.IsNullable, IsNull(P.value, C.[Name]) as Description
From syscolumns C inner join systypes T on T.xtype=C.xtype left join sysproperties P on C.colorder=P.smallid and C.id=P.id
where C.id =@sid And C.[name] Not In ('company_no', 'kind_no', 'bill_no', 'status', 'exigency_grade', 'effect_validate', 'effect_validate_pass', 'complete_date',
'current_approveSeq','previous_approve_time', 'Auditing', 'create_person', 'create_date', 'modify_person', 'modify_date')
order by C.colorder
Return 0
End
--返回子表結構
select @sid=id from sysobjects where name='bill_item_approve'
select C.[name] as FieldName,C.colorder , T.[name] as TypeName , C.length , C.IsNullable,IsNull(P.value, C.[Name]) as Description
From syscolumns C inner join systypes T on T.xtype=C.xtype left join sysproperties P on C.colorder=P.smallid and C.id=P.id
where C.id =@sid And C.[Name] Not In ('company_no', 'kind_no', 'bill_no', 'seq')
order by C.colorder
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetSerialNumber
/********************************
*介紹:取得流水碼
*作者:Billy
*書寫時間:2006/11/27
*說明:涉及表名[bill_m_approve,bill_m_approved]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30) output,
@OrderSerial varchar(3) output
)
as
Declare @NewBillNo varchar(30) --由存儲過程產生單號
Declare @OrderNo int
Declare @TempBillNo varchar(30)
Declare @BillTable Table (company_no varchar(10),kind_no varchar(10),bill_no varchar(20))
insert into @BillTable Select company_no,kind_no,bill_no
from bill_m_approve
where company_no = @CompanyNo And Kind_No = @KindNo And convert(char(7),create_Date,120) = Convert(char(7), getDate(), 120)
insert into @BillTable Select company_no,kind_no,bill_no
from bill_m_approved
where company_no = @CompanyNo And Kind_No = @KindNo and convert(char(7),create_Date,120) = Convert(char(7), getDate(), 120)
--開始計算得出三位流水號
select @OrderNo=1, @OrderSerial = '001'
set @TempBillNo= Replace(@BillNo,'{SerialNumber}', @OrderSerial)
while exists(select bill_no From @BillTable Where bill_no=@TempBillNo)
begin
set @OrderNo=@OrderNo+1
Set @OrderSerial = replicate('0',3-len(convert(varchar(3),@OrderNo)))+convert(varchar(3),@OrderNo)
set @TempBillNo= Replace(@BillNo,'{SerialNumber}', @OrderSerial)
end
set @BillNo=@TempBillNo
print @BillNo
Print @TempBillNo
Print @OrderSerial
Print @OrderNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Bill_GetShowBillColumn
/********************************
* 功能:取得某單據類型的單據欄位信息(包括公共欄位)
* 作者:Billy
* 時間:2006/12/26
*******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10)
)
As
Create Table #tbColumn(Seq int, Column_nm varchar(60), Column_Title varchar(60))
--開始添加公共欄位
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(1, 'company_no','公司')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(2, 'kind_no','單據')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(3, 'bill_no','單據編號')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(4, 'status','狀態')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(5, 'exigency_grade','緊急程度')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(6, 'complete_date','簽核完成日期')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(7, 'current_action_seq','簽核動作')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(8, 'current_Approve_person','簽核人')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(9, 'create_person','建單人')
Insert Into #tbColumn(Seq, Column_nm, Column_Title)Values(10, 'create_date','建單日期')
Insert Into #tbColumn Select Seq, Column_nm, Column_Title From Bill_Column Where Company_no = @CompanyNo and Kind_No = @KindNo And Column_nm != 'note'
--返回未選欄位
Select * From #tbColumn Where column_nm Not in(select Column_nm From bill_column_display Where Company_no = @CompanyNo and Kind_No = @KindNo) order by seq
--返回已選欄位
Select BD.*, BC.Column_Title From bill_column_display BD
Inner Join #tbColumn BC On BD.Column_nm = BC.Column_Nm
Where Company_no = @CompanyNo and Kind_No = @KindNo order by BD.seq
Drop Table #tbColumn
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_GetTableFrame
/*****************************************************************
* 名 稱:pr_Bill_GetTableFrame
* 功能介紹:取得指定公司、單據類型的表結構
* 說明:
@CompanyNo :公司代號
@KindNo :單據類型代號
@BillNo :單據編號
* 返回回值:指定單據包含的字段名稱,字段類型,字段長度,是否允許空
* 注意事項:
* 建立日期:2006/06/28
* 建立人:Billy
* 修改日期:2006/07/01
* 修改人:Billy
* 修改內容:修改字段描述欄返回的值、返回單據欄位的所有值及單據對應的值
*****************************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30) = '',
@BelongTable char(1) = '1' --1為主表, 2為子表
)
as
declare @sid varchar(20), @ID int , @ColumnName varchar(60), @Value varchar(6000)
Declare @RowCount int, @Sql nVarchar(2000)
Create Table #tbBillColumn
(
ID int IDentity(1,1),
Company_no varchar(10),
Kind_No varchar(10),
seq int,
column_nm varchar(60),
column_title varchar(60),
column_kind char(1),
note varchar(100),
user_Length int,
row_seq int,
status char(1),
approver_input char(1),
[read_only] char(1),
default_value varchar(100),
Selection_mode char(1),
Display_Format varchar(20),
TypeName varchar(20),
length int,
IsNullable bit,
[Description] varchar(128),
Value varchar(6000)
)
Select @BillNo = IsNull(@BillNo, ''), @ID = 1, @RowCount = 0
if @BelongTable = '1'
select @sid=id from sysobjects where name='Bill_M_Approve'
Else
select @sid=id from sysobjects where name='Bill_Item_Approve'
Print @Sid
Set @Sql = N'Select B.Company_no,B.Kind_No,B.Seq,B.Column_nm,B.Column_Title,B.Column_Kind,B.Note,B.User_Length,B.Row_Seq,'
+ N'B.Status,B.Approver_Input,B.[Read_Only],B.Default_Value,B.Selection_Mode,B.Display_Format,'
+ N'S.TypeName,S.length,S.IsNullable,Convert(varchar(128),S.[Description]) , '''' as value From Bill_Column B '
+ N'left join(select C.[name] as FieldName,C.colorder , T.[name] as TypeName , C.length , C.IsNullable,IsNull(P.value, C.[Name]) as [Description] '
+ N'From syscolumns C inner join systypes T on T.xtype=C.xtype left join sysproperties P on C.colorder=P.smallid and C.id=P.id '
+ N'where C.id =@sid ) S on B.column_nm=S.FieldName '
+ N'Where B.company_no=@CompanyNo and B.kind_no=@KindNo and B.Belong_table = @BelongTable Order by Row_Seq'
Insert Into #tbBillColumn Exec sp_ExecuteSql @Sql, N'@SID varchar(20),@CompanyNo varchar(10),@KindNo varchar(10),@BelongTable char(1)',
@Sid, @CompanyNo, @KindNo, @BelongTable
if( @BillNo != '' and @BelongTable = '1' ) --查詢主表時才需要取值
Begin
Select @RowCount = Count(*) From #tbBillColumn
--根據單據編號,取得對應的值更新到@BillColumn中
While @ID < = @RowCount
Begin
Select @ColumnName = column_nm From #tbBillColumn Where ID = @ID
exec pr_Bill_GetColumnValue @CompanyNo, @KindNo, @BillNo, @BelongTable, @ColumnName, @Value out
Update #tbBillColumn Set Value = @Value Where ID = @ID
Set @ID = @ID + 1
End
End
Select * From #tbBillColumn Order by Row_Seq
if( @BillNo != '' and @BelongTable = '2' )
Begin
exec pr_Bill_GetItemList @CompanyNo, @KindNo, @BillNo, 'Y' --返回子表數據
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_IQC_SelectList
/***********************************************************
*介紹:查詢進料異常單據
*作者:Billy
*時間:2006/12/27
*傳入:用戶代號,單據編號,單據狀態,緊急程度,單據建立人,建立日期(起止)
*返回:查得單據列表
*說明:涉及表名[bill_m_approve,bill_m_approved]
************************************************************/
(
@UserNo varchar(20),
@BillNo varchar(30)='',
@BillStatus char(1)='0',
@BillExigencyGrade char(1)='0',
@CreatePerson varchar(20)='',
@Field001 varchar(100) ='', --廠商名稱
@Field002 varchar(100) = '', --訂單號碼
@Field003 varchar(100) = '', --物料來源
@Field006 varchar(100) = '', --進料異常編號
@Field011 varchar(100) = '', --物料類別
@Field012 varchar(100) = '', --產品類別
@Field013 varchar(100) = '', --料號
@Field014 varchar(100) = '', --物料名稱
@CreateDateStart varchar(20)='',
@CreateDateEnd varchar(20)='',
@OrderFields varchar(200) = '',
@PageSize int=25,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @CompanyNo varchar(10), @KindNo varchar(10)
Declare @sSqlMain varchar(4000), @sWhere varchar(3000), @sRelation varchar(1000)
Declare @DeputyUserList NVarchar(4000), @ID int, @Searchable char(1)
Create Table #tbSecurity(ID int IDentity(1,1), c_Search char(1)) --保存用戶單據查詢的權限(含被代理人)
Select @DeputyUserList = '', @ID = 1, @Searchable = 'N'
Exec pr_SelectDeputyPersonList @UserNo, @DeputyUserList out
if( @DeputyUserList != '' )
Set @DeputyUserList = '''' + @UserNo + ''',''' + Replace(@DeputyUserList,',', ''',''') + ''''
Else
Set @DeputyUserList = '''' + @UserNo + ''''
Set @DeputyUserList = N'Select c_Search from Bill_Security Where user_no In(' + @DeputyUserList + N') and Company_no = ''ETC'' and kind_no = ''IQC'''
--將本人及其代理人的單據查詢權限存到臨時表中
Insert Into #tbSecurity Exec sp_ExecuteSql @DeputyUserList
While Exists(Select * From #tbSecurity Where ID = @ID)
Begin
Select @Searchable = c_Search From #tbSecurity Where ID = @ID
If(@Searchable = 'Y') Break;
Set @ID = @ID + 1
End
--初始化
set @sSqlMain='Select M.bill_no,field_001,field_002,field_003,field_006,field_012,field_013,field_014,dbo.fn_Bill_ConvertStatus(M.status) status,'+
'dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,U.user_name,'
+ 'convert(varchar(10),M.create_date,120) as create_date from '
if( @Searchable != 'Y' ) --沒有查詢進料異常單的權限,只返回一個空表
Begin
Exec(@sSqlMain + ' Bill_M_Approve M Inner Join UserAdmin U On M.Create_Person=U.user_No Where 1>2')
Return 0
End
set @sRelation=' M left outer join useradmin U on M.create_person=U.user_no '
set @sWhere='where M.company_no=''ETC'' and M.kind_no=''IQC'' '
--是否傳入單據代號
if @BillNo != ''
set @sWhere=@sWhere+'and M.bill_no like ''%'+@BillNo+'%'' '
--是否傳入單據緊急程度
if @BillExigencyGrade != '0'
set @sWhere=@sWhere+'and M.exigency_grade='''+@BillExigencyGrade+''' '
--是否傳入單據建立人
if @CreatePerson != ''
set @sWhere=@sWhere+'and ( M.create_person like''%'+@CreatePerson+'%'' or U.user_name Like ''%' + @CreatePerson + '%'') '
if @Field001 != ''
set @sWhere=@sWhere+'and field_001 like ''%' + Replace(@Field001, '''', '''''') + '%'' '
if @Field002 != ''
set @sWhere=@sWhere+'and field_002 like ''%' + Replace(@Field002, '''', '''''') + '%'' '
if @Field003 != ''
set @sWhere=@sWhere+'and field_003 like ''%' + Replace(@Field003, '''', '''''') + '%'' '
if @Field006 != ''
set @sWhere=@sWhere+'and field_006 like ''%' + Replace(@Field006, '''', '''''') + '%'' '
if @Field011 != ''
set @sWhere=@sWhere+'and field_011 like ''%' + Replace(@Field011, '''', '''''') + '%'' '
if @Field012 != ''
set @sWhere=@sWhere+'and field_012 like ''%' + Replace(@Field012, '''', '''''') + '%'' '
if @Field013 != ''
set @sWhere=@sWhere+'and field_013 like ''%' + Replace(@Field013, '''', '''''') + '%'' '
if @Field014 != ''
set @sWhere=@sWhere+'and field_014 like ''%' + Replace(@Field014, '''', '''''') + '%'' '
--是否傳入建立開始日期
if @CreateDateStart != ''
set @sWhere=@sWhere+'and M.create_date>='''+Convert(varchar(10),@CreateDateStart,120)+''' '
--是否傳入建立終止日期
if @CreateDateEnd != ' '
set @sWhere=@sWhere+'and M.create_date<='''+Convert(varchar(10),@CreateDateEnd,120)+''' '
--是否傳入單據狀態
if @BillStatus != '0'
begin
set @sWhere=@sWhere+'and M.status='''+@BillStatus+''' '
if @BillStatus='1' or @BillStatus='4'
--在表 bill_m_approve 中查找
set @sSqlMain=@sSqlMain+'bill_m_approve '+@sRelation+@sWhere
else if @BillStatus='2' or @BillStatus='3'
--在表 bill_m_approved 中查找
set @sSqlMain=@sSqlMain+'bill_m_approved '+@sRelation+@sWhere
end
Else
set @sSqlMain=@sSqlMain+'bill_m_approve '+@sRelation+@sWhere+' union ('+@sSqlMain+'bill_m_approved '+@sRelation+@sWhere+') '
Print '========================================='
print @sSqlMain
Print '========================================='
if( @OrderFields = '' )
Set @OrderFields = 'Create_date desc'
--調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSqlMain,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields = @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Bill_InsertApproveFile
/********************************
*介紹:添加簽核用戶在簽核時上傳的附檔信息
*作者:Billy
*書寫時間:2006/12/26
*說明:涉及表名[person_approve_file]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int,
@FilePath nvarchar(300)
)
as
declare @Seq int, @SeqFile int
If( not Exists(Select * From Person_d_Approve Where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo And ApproveSeq = @ApproveSeq) )
return 0
Select @Seq = Seq From Person_d_Approve Where company_no =@CompanyNo and kind_no = @KindNo and bill_no = @BillNo And ApproveSeq = @ApproveSeq
Select @SeqFile = Max(seq_file) From Person_Approve_File
Set @SeqFile = IsNull(@SeqFile, 0) + 1
Insert into Person_Approve_File (company_no, kind_no, bill_no, seq, Seq_File, File_path)values(@CompanyNo, @KindNo, @BillNo, @Seq, @SeqFile, @FilePath)
if( @@Error = 0 )
return 1
else
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_InsertBillColumnShow
/********************************
*介紹:新增某單據的顯示欄位信息
*作者:Billy
*書寫時間:2006/1/27
*說明:涉及表名[bill_column_display]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@ColumnName varchar(60),
@Seq int
)
as
Insert Into Bill_Column_Display (Company_no, Kind_No, Column_nm, Seq)
Values(@CompanyNo, @KindNo, @ColumnName, @Seq)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_MoveBillToApprove
/*
功能:將單據從結案表格中移到待簽表格,將當前簽核用戶重置為結案用戶
作者:Billy
日期:2007-05-05
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
Declare @ApproveSeq int
If Not Exists(Select Bill_No From Bill_M_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo)
Begin
Print '單據不存在!'
Return 0
End
Begin Transaction --啟用事務處理
Insert Into Bill_M_Approve Select * From Bill_M_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Insert Into Person_d_Approve Select * From Person_d_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Insert into Bill_File Select * From Bill_File_Done Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Insert into Person_Approve_File Select * From Person_Approved_File Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Insert into Bill_Item_Approve Select * From Bill_Item_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
--移動日志
Insert into Bill_Approve_Log Select * From Bill_Approved_Log Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
--從效果跟蹤列表中清除原來的資料
Delete Bill_Approve_Validate_Log Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Bill_Approve_Validate_File Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Bill_Approve_Validate Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
--刪除結案表中的資料
Delete Person_Approved_File Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Bill_file_done Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Bill_Item_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Person_d_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Bill_M_Approved Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
Delete Bill_Approved_Log Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
if @@Error != 0 Goto ERR
--將當前用戶的簽狀態改為未簽
If Exists(Select Bill_NO From Person_D_Approve Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo and Approve_Sign = '4')
Begin
Select @ApproveSeq = ApproveSeq From Person_D_Approve Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo and Approve_Sign = '4'
Set @ApproveSeq = IsNull(@ApproveSeq, 0)
if @ApproveSeq != 0
Begin
Update Person_D_Approve Set Approve_Sign = 1 Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo and Approve_Sign = '4'
If @@Error != 0 Goto Err
Update Bill_M_Approve Set Current_ApproveSeq = @ApproveSeq Where Company_No = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
If @@Error != 0 Goto Err
End
End
Commit Transaction
Print '移轉成功!'
Return 1
ERR:
RollBack Transaction
print '移轉失敗!'
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_PQC_SelectList
/***********************************************************
*介紹:查詢制程異常單據
*作者:Billy
*時間:2006/12/27
*返回:查得單據列表
*說明:涉及表名[bill_m_approve,bill_m_approved]
************************************************************/
(
@UserNo varchar(20),
@BillNo varchar(30)='',
@BillStatus char(1)='0',
@BillExigencyGrade char(1)='0',
@CreatePerson varchar(20)='',
@Field001 varchar(100) ='', --客戶名稱
@Field002 varchar(100) = '', --訂單號碼
@Field003 varchar(100) = '', --機種名稱
@Field012 varchar(100) = '', --事業處
@Field013 varchar(100) = '', --料號
@Field014 varchar(100) = '', --物料名稱
@CreateDateStart varchar(20)='',
@CreateDateEnd varchar(20)='',
@OrderFields varchar(200) = '',
@PageSize int=25,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @CompanyNo varchar(10), @KindNo varchar(10)
Declare @sSqlMain varchar(4000), @sWhere varchar(3000), @sRelation varchar(1000)
Declare @DeputyUserList NVarchar(4000), @ID int, @Searchable char(1)
Create Table #tbSecurity(ID int IDentity(1,1), c_Search char(1)) --保存用戶單據查詢的權限(含被代理人)
Select @DeputyUserList = '', @ID = 1, @Searchable = 'N'
Exec pr_SelectDeputyPersonList @UserNo, @DeputyUserList out
if( @DeputyUserList != '' )
Set @DeputyUserList = '''' + @UserNo + ''',''' + Replace(@DeputyUserList,',', ''',''') + ''''
Else
Set @DeputyUserList = '''' + @UserNo + ''''
Set @DeputyUserList = N'Select c_Search from Bill_Security Where user_no In(' + @DeputyUserList + N') and Company_no = ''ETC'' and kind_no = ''PQC'''
--將本人及其代理人的單據查詢權限存到臨時表中
Insert Into #tbSecurity Exec sp_ExecuteSql @DeputyUserList
While Exists(Select * From #tbSecurity Where ID = @ID)
Begin
Select @Searchable = c_Search From #tbSecurity Where ID = @ID
If(@Searchable = 'Y') Break;
Set @ID = @ID + 1
End
--初始化
set @sSqlMain='Select M.bill_no,field_001,field_002,field_003,field_013,field_014,dbo.fn_Bill_ConvertStatus(M.status) status,'+
'dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,U.user_name,'
+ 'convert(varchar(10),M.create_date,120) as create_date from '
if( @Searchable != 'Y' ) --沒有查詢進料異常單的權限,只返回一個空表
Begin
Exec(@sSqlMain + ' Bill_M_Approve M Inner Join UserAdmin U On M.Create_Person=U.user_No Where 1>2')
Return 0
End
set @sRelation=' M left outer join useradmin U on M.create_person=U.user_no '
set @sWhere='where M.company_no=''ETC'' and M.kind_no=''PQC'' '
--是否傳入單據代號
if @BillNo != ''
set @sWhere=@sWhere+'and M.bill_no like ''%'+@BillNo+'%'' '
--是否傳入單據緊急程度
if @BillExigencyGrade != '0'
set @sWhere=@sWhere+'and M.exigency_grade='''+@BillExigencyGrade+''' '
--是否傳入單據建立人
if @CreatePerson != ''
set @sWhere=@sWhere+'and ( M.create_person like''%'+@CreatePerson+'%'' or U.user_name Like ''%' + @CreatePerson + '%'') '
if @Field001 != ''
set @sWhere=@sWhere+'and field_001 like ''%' + Replace(@Field001, '''', '''''') + '%'' '
if @Field002 != ''
set @sWhere=@sWhere+'and field_002 like ''%' + Replace(@Field002, '''', '''''') + '%'' '
if @Field003 != ''
set @sWhere=@sWhere+'and field_003 like ''%' + Replace(@Field003, '''', '''''') + '%'' '
if @Field012 != ''
set @sWhere=@sWhere+'and field_012 like ''%' + Replace(@Field012, '''', '''''') + '%'' '
if @Field013 != ''
set @sWhere=@sWhere+'and field_013 like ''%' + Replace(@Field013, '''', '''''') + '%'' '
if @Field014 != ''
set @sWhere=@sWhere+'and field_014 like ''%' + Replace(@Field014, '''', '''''') + '%'' '
--是否傳入建立開始日期
if @CreateDateStart != ''
set @sWhere=@sWhere+'and M.create_date>='''+Convert(varchar(10),@CreateDateStart,120)+''' '
--是否傳入建立終止日期
if @CreateDateEnd != ' '
set @sWhere=@sWhere+'and M.create_date<='''+Convert(varchar(10),@CreateDateEnd,120)+''' '
--是否傳入單據狀態
if @BillStatus != '0'
begin
set @sWhere=@sWhere+'and M.status='''+@BillStatus+''' '
if @BillStatus='1' or @BillStatus='4'
--在表 bill_m_approve 中查找
set @sSqlMain=@sSqlMain+'bill_m_approve '+@sRelation+@sWhere
else if @BillStatus='2' or @BillStatus='3'
--在表 bill_m_approved 中查找
set @sSqlMain=@sSqlMain+'bill_m_approved '+@sRelation+@sWhere
end
Else
set @sSqlMain=@sSqlMain+'bill_m_approve '+@sRelation+@sWhere+' union ('+@sSqlMain+'bill_m_approved '+@sRelation+@sWhere+') '
Print '========================================='
print @sSqlMain
Print '========================================='
if( @OrderFields = '' )
Set @OrderFields = 'Create_date desc'
--調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSqlMain,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields = @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_PrejudicationCount
/***********************************************************
*介紹:辦公自動化OA系統 (查詢當前用戶的預審單據總數)
*作者:Billy
*書寫時間:2006/12/19
*傳入:用戶代號
*返回:查得當前用戶的待簽單據列表
*Execute eg: execute pr_SelectNeedApproveBillCount 'Billy'
************************************************************/
(
@AssistantNo varchar(20)
)
as
--declare @sSql nvarchar(4000)
declare @sManager varchar(20) -----助理的主管代號
Declare @BillCount int
Select @BillCount = 0
if( Not Exists(Select * From Assistant Where Assistant_NO = @AssistantNo) )
Return @BillCount
Select @sManager = director_no From assistant Where assistant_no = @AssistantNo
Exec @BillCount = pr_Bill_GetNeedApproveBillCounts @sManager
Return @BillCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_SaveSingleColumn
/*******************************
程序功能:保存一條欄位信息
編寫人員:Billy
編寫日期:2006/12/04
*******************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@ColumnTitle varchar(60),
@ColumnName varchar(60),
@ColumnKind char(1),
@Note varchar(100),
@UserLength int,
@RowSeq int,
@Status char(1) = 'N',
@ApproverInput char(1) = 'N',
@ReadOnly char(1) = 'N',
@DefaultValue varchar(100),
@SelectionMode char(1) = '1', --1:文本框, 2:復選框, 3:單選列表, 4:下拉列表
@DisplayFormat varchar(20) = '',
@BelongTable char(1) -- 1:保存單據主表; 2:保存到明細表
)
As
--暫不進行數據檢查,等時間充足時再加入
Declare @Seq int, @RowCount int
Select @Seq = 0, @RowCount = 0
If @BelongTable != '1' And @BelongTable != '2'
Return 0
if Exists(Select column_nm From Bill_Column Where company_no = @CompanyNo and Kind_No = @KindNo and Column_nm = @ColumnName and Belong_Table = @BelongTable) --不允許相同的名稱
return 0
Select @Seq = max(seq) From Bill_Column
Set @Seq = IsNull(@Seq, 0) + 1
Insert into Bill_Column
( company_no, kind_no, seq, column_title, column_nm, column_kind, belong_table,note, user_length, row_seq, status, approver_input, [read_only], default_value, Selection_Mode, Display_Format)
values
(@CompanyNo, @KindNo, @Seq, @ColumnTitle, @ColumnName, @ColumnKind, @BelongTable, @Note, @UserLength, @RowSeq, @Status, @ApproverInput, @ReadOnly, @DefaultValue, @SelectionMode, @DisplayFormat)
return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_SelectBillInfoForPrint
/********************************
*介紹:辦公自動化OA系統 (取得單據的相關信息,以供打印)
*作者:Billy
*書寫時間:2006/10/18
*參數:@BillNo
*說明:使用表:Bill_kind, Bill_m_Approve, Bill_m_approved, person_d_approve, person_d_approved, UserAdmin
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@CompanyName varchar(60) out,
@KindName varchar(60) out
)
as
Declare @TableName Nvarchar(50), @Sql nVarchar(2000)
Declare @MainTable nVarchar(50)
Declare @CurrentApproveSeq int
Declare @ApproveSeq int --存放臨時的ApproveSeq
Declare @ID int, @Rows int --用於循環計數
Declare @PreviousTime datetime --前一用戶簽核日期
Declare @CurrnetTime datetime --用戶簽核日期
Declare @ApproveSign char(1)
Declare @NeedApprove char(1) --是否需要簽核
--創建臨時表,存在簽核用戶信息
Create Table #tbPerson(ID int Identity(1,1),ApproveSeq int, Action_Nm varchar(20),
Chief_No Varchar(10),User_No varchar(20),Actual_User_no varchar(20), Note varchar(6000),
Approve_Date DateTime, Mark_Name varchar(60), Approve_Sign char(1), TimeCost varchar(20))
--初始化變量
Set @CurrentApproveSeq = 1
Set @ApproveSeq = 0
Set @ID = 0
Set @Rows = 0
Set @PreviousTime = getDate()
Set @ApproveSign = '1'
Set @NeedApprove = 'N'
--取得單據名稱
Select @KindName = Kind_Nm From Bill_Kind
Where company_no = @CompanyNo And Kind_no = @KindNo
--取得單據對應的公司名稱
Select @CompanyName = Company_nm From Company Where Company_no = @CompanyNo
--取得單據欄位及值
Exec pr_SelectBillColumns @CompanyNo, @KindNo, @BillNo --得到單據的欄位及對應值
if Exists(select Bill_No from bill_m_approve where Company_no = @CompanyNo and Kind_no = @KindNo and bill_no=@BillNo)
Select @MainTable = 'Bill_M_Approve', @TableName = 'Person_d_Approve'
else
Select @MainTable = 'Bill_M_Approved', @TableName = 'Person_d_Approved'
Set @Sql = N'Select M.ApproveSeq,Action_Nm,M.Chief_no, M.User_no,M.actual_User_no,'
+ N' M.Note,M.Approve_Date,M.Mark_Name,M.Approve_Sign, '''' '
+ N' From ' + @TableName + ' M Left Join Action_Kind A On A.Company_no=M.Company_No And M.action_Seq=A.action_seq'
+ N' Where M.Company_no=@CompanyNo and M.Kind_no=@KindNo and M.Bill_No=@BillNo And A.Approve=''Y'' Order By M.ApproveSeq'
--將實際的簽核用戶信息插入臨時表中
insert into #tbPerson Exec Sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
Update #tbPerson Set Actual_User_No = User_no Where actual_user_no = '' or Actual_User_no is null
Select @Rows = Count(*) From #tbPerson
If @Rows < 1 GoTo ExitProc
/*開始計算並更新各簽核用戶的簽核時間*/
--取得當前簽核順序及建單日期
Select @Sql = N'Select @CurrentApproveSeq=Current_ApproveSeq,@PreviousTime = Create_Date From ' + @MainTable + ' Where Company_no=@CompanyNo and Kind_no=@KindNo and Bill_No=@BillNo'
Exec sp_Executesql @Sql, N'@CurrentApproveSeq int out, @PreviousTime DateTime out, @CompanyNo varchar(10), @KindNo varchar(10), @BillNo varchar(30)', @CurrentApproveSeq out, @PreviousTime out, @CompanyNo, @KindNo, @BillNo
Set @ID = 1
While @ID <= @Rows
Begin
Select @ApproveSign = Approve_Sign, @ApproveSeq = ApproveSeq, @CurrnetTime = Approve_Date From #tbPerson Where [ID] = @ID
If @ApproveSign = '5'
Begin
Set @ID = @ID + 1
Continue
End
If @CurrnetTime Is Null Set @CurrnetTime = GetDate()
Update #tbPerson
Set TimeCost = dbo.fn_ConvertToTime(AbS( datediff(mi , @PreviousTime , @CurrnetTime))) Where ID = @ID
If @ApproveSeq = @CurrentApproveSeq Or @ApproveSign = '2' Or @ApproveSign = '4'
Begin
Break --已到達當前待簽用戶或為退單、結案的用戶,後面的不需再進行計算
End
Set @PreviousTime = @CurrnetTime
Set @ID = @ID + 1
End
ExitProc:
select M.approveSeq,C.company_nm,U1.user_name, U2.user_name actualName,
dbo.fn_UserDepartment(M.actual_user_no) actualDept,
P2.position_name Actual_position_name,
M.action_nm,Convert(Varchar(19),M.approve_date,120) Approve_Date,M.TimeCost,
M.approve_sign,dbo.fn_Bill_ConvertApproveSign(M.approve_sign) ApproveSign,M.note,M.mark_name
from #tbPerson M
inner join company C on C.Company_No = @CompanyNo
Left join useradmin U1 on M.user_no=U1.user_no --預計的用戶
left join useradmin U2 on M.actual_user_no=U2.user_no --代理用戶
left Join Position P2 On U2.company_no=P2.company_no and U2.position_no = P2.position_no
Order By M.ApproveSeq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Bill_SelectUsersTimeSpan
/**************************************
* 功能:後台線程發通知郵件專用(查詢出所有超出指定時數未進行簽核的用戶列表)
* 作者:Billy
* 日期:2006/12/11
**************************************/
(
@Hours int
)
As
Declare @UserList Table(ID int identity(1,1), kind_nm varchar(60), bill_no varchar(30), Hours int, Current_Approve_person varchar(20),
Current_Approve_Person_Name varchar(15), Current_Approve_Person_PositionName varchar(60),Current_Approve_Person_Email varchar(60),
Create_Person varchar(20), Create_Person_Name varchar(15), Create_Person_DepartMent nVarchar(100))
Declare @ID int, @Rows int, @UserNo varchar(20), @TempUser varchar(20), @DeputyUserList varchar(2000)
Declare @StartIndex int , @EndIndex int, @Length int -- 用戶於字符截取使用
--將超過@Hours時數時進行簽核的用戶信息插入臨時表
Insert into @UserList
Select * From
(
Select BK.Kind_nm, BA.Bill_no, DateDiff(hour, Previous_Approve_Time, getdate()) Hours,
PA.user_no, '' Current_Approve_Person_Name ,'' Current_Approve_Person_PositionName ,
'' Current_Approve_Person_Email, BA.Create_Person, '' Create_Person_Name,'' Create_Person_DepartMent
From Bill_M_Approve BA
Inner join Person_d_Approve PA On BA.company_no = PA.company_no and BA.kind_no = PA.Kind_no and BA.Bill_no = PA.Bill_No and BA.Current_ApproveSeq = PA.approveseq
left Outer Join Bill_Kind BK On BA.company_no = BK.company_no and BA.kind_no = BK.kind_no
Where BA. Auditing = 'Y'
) Main
Where Hours>= @Hours
if( Not Exists(Select * From @UserList) )
GoTo ExitProc
--替換被代理用戶為代理用戶
Select @Rows = Count(*) From @UserList
Select @ID = 1 , @UserNo = '', @DeputyUserList = '', @TempUser = ''
While( Exists(Select * From @UserList Where ID = @ID) )
Begin
Set @DeputyUserList = ''
select @UserNo = Current_Approve_Person From @UserList Where ID = @ID
--取得用戶代理的用戶
exec pr_SelectDeputyPersonList @UserNo, @DeputyUserList out
Set @DeputyUserList = Ltrim(Rtrim(@DeputyUserList))
if @DeputyUserList != ''
begin
Select @StartIndex = 1, @EndIndex = CharIndex(@DeputyUserList, ',')
While( @EndIndex > 0 )
Begin
--通過逗號分隔截取,逐個到更新
Set @Length = @EndIndex - @StartIndex
Set @TempUser = SubString(@DeputyUserList, @StartIndex, @Length)
Print '代理用戶:' + @UserNo
--更新到表變量中
Update @UserList Set Current_Approve_Person = @UserNo Where Current_Approve_Person = @TempUser
Set @EndIndex = CharIndex(@DeputyUserList, ',', @EndIndex + 1)
Set @StartIndex = @EndIndex + 1
End
end
Set @ID = @ID + 1
End
--更新審核用戶的姓名及職務信息
Update @UserList
Set Current_Approve_Person_Name = dbo.fn_User_GetUserName(Current_Approve_Person),
Current_Approve_Person_PositionName = dbo.fn_User_GetPositionName(Current_Approve_Person),
Create_Person_Name = dbo.fn_User_GetUserName(Create_Person),
Create_Person_DepartMent = dbo.fn_UserDepartment(Create_Person),
Current_Approve_Person_Email = (Select email From useradmin where user_no = Current_Approve_Person)
ExitProc:
Select * From @UserList
Select Distinct Current_Approve_Person From @UserList
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_SelectValues
/********************************
*介紹:取得單據的信息(
*作者:Billy
*書寫時間:2007/01/8
*傳入:
*返回:主單據值,主單據欄位信息,子表數據
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
Declare @Sql nVarchar(4000), @TableName nVarchar(20)
if (Exists(select Bill_no from bill_m_approve where Company_no = @CompanyNo and Kind_no = @KindNo and bill_no=@BillNo) )
Set @TableName = 'Bill_m_Approve'
else
Set @TableName = 'Bill_m_Approved'
Set @Sql = N'select C.company_nm,M.bill_no,dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,'
+ N'U.user_name create_person,M.create_date,dbo.fn_UserDepartment(M.create_person) userdept '
+ N'from ' + @TableName + ' M '
+ N'inner join company C on M.company_no=C.company_no '
+ N'inner join useradmin U on M.create_person=U.user_no '
+ N'where M.company_no=@CompanyNo and Kind_no=@KindNo and M.bill_no=@BillNo'
Exec sp_ExecuteSql @Sql, N'@CompanyNo varchar(10),@KindNo varchar(10),@BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
Exec pr_SelectBillColumns @CompanyNo, @kindNo, @BillNo
--單據明細信息
Exec pr_Bill_GetItemList @CompanyNo, @kindNo, @BillNo, 'Y'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_Select_value
/********************************
*介紹:取得主單據的信息
*作者:Billy
*書寫時間:2007/01/8
*傳入:
*返回:異常單據詳細信息
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
Declare @Sql Varchar(8000), @TableName nVarchar(20)
DeClare @ID int, @RowCount int, @ColumnName varchar(60)
Create Table #tbColumn(ID int Identity(1,1), Column_Nm varchar(60))
insert into #tbColumn Select column_nm From bill_Column where company_no = @CompanyNo and Kind_no = @KindNo and Belong_Table = '1'
Set @ID = 1
Select @RowCount = Count(*) From #tbColumn
Set @Sql = 'Select M.bill_no,M.status,M.exigency_grade'
While @ID <= @RowCount
Begin
Select @ColumnName = Column_nm From #tbColumn Where ID = @ID
Set @Sql = @Sql + ',M.' + @ColumnName
Set @ID = @ID + 1
End
if (Exists(select Bill_no from bill_m_approve where Company_no = @CompanyNo and Kind_no = @KindNo and bill_no=@BillNo) )
Set @TableName = 'Bill_m_Approve'
else
Set @TableName = 'Bill_m_Approved'
Set @Sql = @Sql + ',M.effect_validate, M.Effect_validate_pass,'
+ 'M.complete_date,M.Current_ApproveSeq,M.Previous_approve_time,'
+ 'M.Auditing,M.Create_Person,C.company_nm, M.company_no, B.kind_nm From ' + @TableName + ' M '
+ 'Left outer join company C on M.company_no = C.company_no left outer join '
+ 'bill_kind B on M.kind_no = B.kind_no '
+ ' Where M.company_no = ''' + @CompanyNo + ''' and M.kind_no = ''' + @KindNo + ''' and M.bill_no = ''' + @BillNo + ''''
Exec(@Sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Bill_UpdateLastApproveInfo
/*
功能:更新簽核信息
作者:Billy
日期:2007/04/03
參數:
@CompanyNo: 單據類型對應的公司代號
@KindNo: 單據類型代號
@BillNo: 單據代號
@ApproveSeq: 簽核順序
@Note: 簽核批示
*/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int,
@Note varchar(6000)
)
As
If Not Exists(Select Bill_No From Person_D_Approved Where Company_no = @CompanyNo and kind_no = @KindNo and Bill_No = @BillNo And ApproveSeq = @ApproveSeq)
Return 0
Update Person_D_Approved Set Note = @Note Where Company_no = @CompanyNo and kind_no = @KindNo and Bill_No = @BillNo And ApproveSeq = @ApproveSeq
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Bill_Update_FirstApproveSeq
/**************************************
* 功能:更新下一審核用戶到主表中[Bill_M_Approve]
* 作者:Billy
* 日期:2006/12/11
**************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
As
Declare @FirstApproveSeq int, @Rows int, @CreateTime datetime
Select ApproveSeq into #tbApprove From person_d_Approve P
Inner Join Action_Kind A On P.company_no = A.company_no and P.action_seq = A.action_Seq
Where P.company_no = @CompanyNo and P.kind_no = @KindNo and P.Bill_No = @BillNo and A.Approve = 'Y'
Order By ApproveSeq
if Not Exists(Select ApproveSeq From #tbApprove)
return 0
Select @FirstApproveSeq = Min(ApproveSeq) From #tbApprove
Select @CreateTime = create_date From bill_m_Approve Where company_no = @CompanyNo and kind_no = @KindNo and Bill_No = @BillNo
Update Bill_M_Approve Set Current_approveSeq = @FirstApproveSeq, previous_Approve_time = @CreateTime
Where company_no = @CompanyNo and kind_no = @KindNo and Bill_No = @BillNo
Set @Rows = @@RowCount
if( @@Error <> 0 )
Set @Rows = 0
Return @Rows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Bill_ValidateApproveSeq
/************************************
功能:驗證當前傳入的簽核順序ApproveSeq, 如果該ApproveSeq對應的簽核動作為通知,
則查到與其最近的需要執行簽核動作的簽核順序ApproveSeq
作者:Billy
日期:2007/02/09
返回:ApproveSeq
**************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@ApproveSeq int output
)
As
Declare @NextApproveSeq int
DeClare @EndApproveSeq int
DeClare @TableName varchar(60), @Sql nVarchar(300)
Create Table #tbApproveList(ID int Identity(1,1), ApproveSeq int)
Set @NextApproveSeq = @ApproveSeq
Set @EndApproveSeq = 0
--將單據需要執行簽核動作的用戶存入臨時表中
if Exists(Select Bill_No From Bill_M_Approve Where Company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo)
Set @TableName = 'Person_d_Approve'
Else
Set @TableName = 'Person_d_Approved'
Set @Sql = N'Select M.ApproveSeq From ' + @TableName + ' M '
+ N'Inner Join Action_Kind A On M.action_seq = A.action_Seq and M.company_no=A.company_no '
+ N'Where M.Company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo and A.Approve = ''Y'' Order by M.ApproveSeq'
Insert into #tbApproveList Execute sp_ExecuteSql @Sql, N'@CompanyNo varchar(10),@KindNo varchar(10), @BillNo varchar(30)', @CompanyNo, @KindNo, @BillNo
Select @EndApproveSeq = Max(ApproveSeq) From #tbApproveList
Print @EndApproveSeq
if @ApproveSeq >= @EndApproveSeq
Begin
Set @ApproveSeq = @EndApproveSeq
Return 0
End
--檢查當傳入的ApproveSeq對應的用戶是否需要執行簽核動作,如果不需要則更最近的下一簽核順序ApproveSeq
If Not Exists( Select * From #tbApproveList Where ApproveSeq = @ApproveSeq )
Begin
Select @NextApproveSeq = Min(ApproveSeq) From #tbApproveList Where ApproveSeq > @ApproveSeq
End
Set @ApproveSeq = @NextApproveSeq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_ApproveApply
/********************************
*介紹:審覈借閱申請信息
*作者:Tim
*書寫時間:2007/05/11
*參數: @申請ID
*說明:表:book_borrow_apply
*********************************/
(
@apply_id int,
@status int,
@return_date datetime,
@approver varchar(15),
@fact_approver varchar(15),
@approve_info varchar(30)
)
as
update book_borrow_apply set status=@status,return_date=@return_date,approver=@approver,fact_approver=@fact_approver,approve_info=@approve_info, approve_date=getdate() where apply_id=@apply_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_CreateCardNO
/********************************
*介紹:生成借書卡卡號
*作者:Tim
*書寫時間:2007/05/11
*說明:表:library_card
*********************************/
(
@UserNo varchar(20)
)
as
Declare @ID varchar(20)
Declare @MaxID varchar(20)
declare @company_no varchar(20)
begin
select @company_no=company_no from useradmin where user_no=@UserNo
select @MaxID=right( convert(varchar(20),max(card_no)),3) from library_card
set @MaxID=IsNull(@MaxID,'001')
select @ID = @company_no+convert(varchar(10),DATEPART(year, GETDATE()))+right('00'+convert(varchar(10),DATEPART(month, GETDATE())),2)+right('00'+convert(varchar(10),convert(int,@MaxID)+1),3)
--創建臨時表,以為表形式返回借書卡號
create table #tbcardno
(
card_no varchar(20)
)
insert into #tbcardno values(@ID)
select * from #tbcardno
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_DeleteBookBorrowApply
/*******************************
程序功能:刪除圖書借閱申請信息
編寫人員:Tim
編寫日期:2007-5-14
*******************************/
(
@apply_id int
)
as
begin
if(not exists(select * from book_borrow_apply where apply_id=@apply_id)) return 1
insert into book_borrow_history select company_no,lower_id,book_id,user_no,submit_date,approve_date,0 from book_borrow_apply where apply_id=@apply_id
delete book_borrow_apply where apply_id=@apply_id return 0
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_DeleteLibrarycard
/*******************************
程序功能:刪除圖書借閱申請信息
編寫人員:Tim
編寫日期:2007-5-14
*******************************/
(
@card_no varchar(20)
)
as
begin
if(not exists(select * from Library_card where card_no=@card_no)) return 1
delete Library_card where card_no=@card_no return 0
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_DeleteType
/********************************
*介紹:辦公自動化OA系統 (更新圖書類別信息)
*作者:tim
*書寫時間:2007/05/12
*參數: @TypeNo 分類代號
*說明:表:book_type, book_lower_type
*********************************/
(
@lastNo int,
@TypeNo int
)
as
BEGIN
IF(RTRIM(@lastNo)=0)--頂級分類
BEGIN
DELETE book_type WHERE type_id=@TypeNo
END
ELSE --小分類
BEGIN
DELETE book_lower_type WHERE lower_id=@TypeNo
END
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_GrantBook
/********************************
*介紹:發放圖書
*作者:Tim
*書寫時間:2007/05/11
*參數: @申請ID
*說明:表:book_borrow_apply
*********************************/
(
@apply_id int,
@granter varchar(20),
@fact_granter varchar(20)
)
as
begin tran
insert into book_borrowed select company_no,lower_id,book_id, user_no,getdate(),return_date,null,0 ,null ,@granter,@fact_granter ,null from book_borrow_apply where apply_id = @apply_id
if @@error<>0 rollback tran
insert into book_borrow_history select company_no,lower_id,book_id, user_no ,submit_date,approve_date,1 from book_borrow_apply where apply_id = @apply_id
if @@error<>0 rollback tran
delete book_borrow_apply where apply_id = @apply_id
if @@error<>0 rollback tran
update books set loans = loans+1 where book_id in ( select book_id from book_borrow_apply where apply_id = @apply_id )
if @@error<>0 rollback tran
commit tran
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_InsertBookBorrowApply
/*******************************
程序功能:插入圖書借閱申請信息
編寫人員:Tim
編寫日期:2007-5-14
*******************************/
(
@company_no varchar(10),
@lower_id int,
@book_id int,
@user_no varchar (20) ,
@borrow_date datetime ,
@return_date datetime
)
as
DECLARE @Seq INT
begin
if(exists(select * from book_borrow_apply where company_no=@company_no and lower_id=@lower_id and book_id=@book_id and user_no=@user_no)) return 1
if(exists(select * from book_borrowed where company_no=@company_no and lower_id=@lower_id and book_id=@book_id and borrower=@user_no and giveback=1)) return 2
Select @Seq = Max(apply_id) From book_borrow_apply
Set @Seq = IsNull(@Seq, 0) + 1
insert into book_borrow_apply values(@Seq ,@company_no,@lower_id,@book_id,@user_no ,@borrow_date,@return_date ,'0' ,getdate() ,null,null ,null,null ) return 0
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Book_ReduceLoans
/********************************
*介紹:還書操作,減少圖書借出量
*作者:Tim
*書寫時間:2007/05/11
*參數: @book_id 圖書代號
*說明:表:books
*********************************/
(
@company_no varchar(20),
@lower_id int,
@book_id int
)
as
update books set loans=loans-1 where company_no=@company_no and lower_id=@lower_id and book_id=@book_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelecBookAmends
/********************************
*介紹:辦公自動化OA系統 (查詢用戶賠償紀錄)
*作者:Tim
*書寫時間:2007-5-14
*傳入:查詢條件
*說明:涉及表名[book_amends]
*********************************/
(
@seq varchar(20),
@book varchar(30),
@user Varchar(20),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Begin
--判斷條件
if (@seq = null ) select @seq =''
If (@book = Null) Select @book=''
if (@user = null ) select @user =''
--產生條件
Select @sWhere = 'Where 1=1 '
If(Rtrim(@seq) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (amends_id = ' + @seq + ' ) '
If(Rtrim(@book) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_name like ''%' + @book + '%'' ) '
If(Rtrim(@user) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (user_no like ''%' +@user+ '%'' or user_name like ''%'+@user+'%'') '
--生成語句
Select @sSql = 'SELECT * '
+ ' FROM book_amends '
+ Rtrim(@sWhere)
select @sOrderBy=' operate_date desc '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelecHotBooks
/********************************
*介紹:辦公自動化OA系統 (查詢熱門圖書)
*作者:Tim
*書寫時間:2007-5-14
*傳入:查詢條件
*說明:涉及表名[book_borrowed]
*********************************/
(
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out,
@strWhere varchar(6000)
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
SET @sSql='select * from( select book_borrowed.company_no,book_borrowed.book_id,books.book_name,count(*) borrowed_times '
+' from book_borrowed '
+' join books on book_borrowed.book_id=books.book_id '
+ ' group by book_borrowed.company_no,book_borrowed.book_id,books.book_name ) S '
+ ' where 1=1 '+@strWhere
SET @sOrderBy='borrowed_times DESC'
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBookApplyHistory
/********************************
*介紹:辦公自動化OA系統 (查詢圖書信息)
*作者:Tim
*書寫時間:2007-5-14
*傳入:查詢條件
*說明:涉及表名[books,book_borrow_history,useradmin]
*********************************/
(
@companyno varchar(10),
@lower_id int,
@book_id int,
@user_no Varchar(20),
@status char(1),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Begin
--判斷條件
If (@companyno = Null) Select @companyno=''
If (@lower_id = Null) Select @lower_id=0
If (@book_id = Null) Select @book_id=0
If (@user_no = Null) Select @user_no=''
if (@status = null ) select @status =''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@companyno) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_history.company_no = ''' + @companyno + ''' ) '
If (Rtrim(@lower_id) <> 0) Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_history.lower_id = ' + cast(@lower_id as varchar(100)) + ' ) '
If (Rtrim(@book_id) <> 0) Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_history.book_id = ' + cast(@book_id as varchar(100)) + ' ) '
If(Rtrim(@user_no) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_history.user_no = ''' + @user_no + ''' ) '
If(Rtrim(@status) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_history.status =' +@status+ ') '
--生成語句
Select @sSql = 'SELECT book_borrow_history.*,books.book_name,(CASE book_borrow_history.status WHEN 0 THEN ''失敗'' ELSE ''成功'' END) AS Status_nm , useradmin.user_name '
+ ' FROM book_borrow_history '
+' left join useradmin on book_borrow_history.user_no = useradmin.user_no '
+' left join books on book_borrow_history.company_no=books.company_no and book_borrow_history.lower_id =books.lower_id and book_borrow_history.book_id=books.book_id '
+ Rtrim(@sWhere)
select @sOrderBy=' apply_date desc '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBookBorrowed
/********************************
*介紹:辦公自動化OA系統 (查詢圖書信息)
*作者:Tim
*書寫時間:2007-5-14
*傳入:查詢條件
*說明:涉及表名[books,book_borrowed,useradmin]
*********************************/
(
@companyno varchar(10),
@lower_id varchar(20),
@book_id int,
@borrower Varchar(20),
@giveback char(1),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Begin
--判斷條件
If (@companyno = Null) Select @companyno=''
If (@lower_id = Null) Select @lower_id=0
If (@book_id = Null) Select @book_id=0
If (@borrower = Null) Select @borrower=''
if (@giveback = null ) select @giveback =''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@companyno) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrowed.company_no = ''' + @companyno + ''' ) '
If (Rtrim(@lower_id) <> 0) Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrowed.lower_id = ' + cast(@lower_id as varchar(100)) + ' ) '
If (Rtrim(@book_id) <> 0) Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrowed.book_id = ' + cast(@book_id as varchar(100)) + ' ) '
If(Rtrim(@borrower) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrowed.borrower = ''' + @borrower + ''' ) '
If(Rtrim(@giveback) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrowed.giveback =' +@giveback+ ') '
--生成語句
Select @sSql = 'SELECT book_borrowed.*,books.book_no,books.book_name,(CASE book_borrowed.giveback WHEN 0 THEN ''未歸還'' ELSE ''已歸還'' END) AS Status_nm , useradmin.user_name '
+ ' FROM book_borrowed '
+' left join useradmin on book_borrowed.borrower = useradmin.user_no '
+' left join books on book_borrowed.company_no=books.company_no and book_borrowed.lower_id =books.lower_id and book_borrowed.book_id=books.book_id '
+ Rtrim(@sWhere)
select @sOrderBy=' borrow_date '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBookGrantInfo
/********************************
*介紹:根據審覈用戶查詢圖書借閱申請信息
*作者:Tim
*書寫時間:2007/05/11
*參數:@申請ID
*說明:表:book_borrow_apply
*********************************/
(
@apply_id int
)
as
Begin
--查詢圖書信息
select book_borrow_apply.*,isnull(book_deposit.deposit,0) ,books.miniature_image,books.price,books.book_name,books.book_no,books.chief_no ,U.dept_nm, U.user_name,library_card.card_no,library_card.foregift,library_card.borrow_books from book_borrow_apply
left join ( select useradmin.user_no,useradmin.user_name, OA.dbo.fn_DepartmentFrame(useradmin.company_no,useradmin.dept_no) dept_nm from useradmin LEFT join dept on useradmin.dept_no=dept.dept_no)U on book_borrow_apply.user_no = U.user_no
join books on book_borrow_apply.company_no=books.company_no and book_borrow_apply.lower_id =books.lower_id and book_borrow_apply.book_id=books.book_id
left join library_card on book_borrow_apply.user_no = library_card.user_no
left join book_deposit on book_borrow_apply.user_no = book_deposit.user_no
where book_borrow_apply.apply_id=@apply_id and library_card.enable=1
--查詢對應用戶已經借閱圖書信息
select book_borrowed.*, useradmin.user_name from book_borrowed
join book_borrow_apply on book_borrowed.company_no=book_borrow_apply.company_no and book_borrowed.lower_id =book_borrow_apply.lower_id and book_borrowed.book_id=book_borrow_apply.book_id
left join useradmin on book_borrowed.borrower = useradmin.user_no
join books on book_borrowed.company_no=books.company_no and book_borrowed.lower_id =books.lower_id and book_borrowed.book_id=books.book_id
where book_borrow_apply.apply_id = @apply_id
--查詢用戶對應押金檔
select * from book_deposit where user_no in (select user_no from book_borrow_apply where apply_id=@apply_id)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBookInfo
/********************************
*介紹:辦公自動化OA系統 (查詢圖書信息)
*作者:Tim
*書寫時間:2007-5-14
*傳入:查詢條件
*說明:涉及表名[books,book_lower_type,book_type]
*********************************/
(
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out,
@strWhere varchar(6000)
)
as
declare @sSql Nvarchar(4000)
set @sSql='select * from (select books.*,T.lower_name,T.type_id,T.type_name,company.company_nm,d1.dept_nm ,d2.dept_nm chief_nm from books '
+' join ( select book_lower_type.lower_id, book_lower_type.lower_name,book_type.type_name ,book_type.type_id from book_lower_type '
+' join book_type on book_lower_type.type_id=book_type.type_id) T on books.lower_id=T.lower_id '
+' join company on books.company_no=company.company_no '
+' join dept d1 on books.company_no=d1.company_no and books.dept_no=d1.dept_no '
+' join dept d2 on books.company_no=d2.company_no and books.chief_no=d2.dept_no ) B '
+ ' where 1=1 '+@strWhere
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='create_date desc'
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBorrowApply
/********************************
*介紹:根據條件查詢圖書借閱申請信息
*作者:Tim
*書寫時間:2007/05/11
*參數:@companyno 公司代號 @lower_id 分類代號 @book_id 圖書ID @user_no 申請人
*說明:表:book_borrow_apply
*********************************/
(
@companyno varchar(10),
@lower_id int,
@book_id int,
@user_no Varchar(20),
@status char(1),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Begin
--判斷條件
If (@companyno = Null) Select @companyno=''
If (@lower_id = Null) Select @lower_id=0
If (@book_id = Null) Select @book_id=0
If (@user_no = Null) Select @user_no=''
if (@status = null ) select @status =''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@companyno) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_apply.company_no = ''' + @companyno + ''' ) '
If (Rtrim(@lower_id) <> 0) Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_apply.lower_id = ' + cast(@lower_id as varchar(100)) + ' ) '
If (Rtrim(@book_id) <> 0) Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_apply.book_id = ' + cast(@book_id as varchar(100)) + ' ) '
If(Rtrim(@user_no) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_apply.user_no = ''' + @user_no + ''' ) '
If(Rtrim(@status) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (book_borrow_apply.status =''' + @status + ''' ) '
--生成語句
Select @sSql = 'SELECT book_borrow_apply.*,books.book_name,(CASE book_borrow_apply.status WHEN ''0'' THEN ''待審'' WHEN ''1'' THEN ''通過'' ELSE ''拒借'' END) AS Status_nm , U.user_name,U.email ,U.position_name '
+ ' FROM book_borrow_apply '
+' join ( select useradmin.user_no,useradmin.user_name,useradmin.email,position.position_name from useradmin LEFT join position on useradmin.position_no=position.position_no)U on book_borrow_apply.user_no = U.user_no '
+' left join books on book_borrow_apply.company_no=books.company_no and book_borrow_apply.lower_id =books.lower_id and book_borrow_apply.book_id=books.book_id '
+ Rtrim(@sWhere)
select @sOrderBy=' submit_date '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBorrowApplyByApprover
/********************************
*介紹:根據審覈用戶查詢圖書借閱申請信息
*作者:Tim
*書寫時間:2007/05/11
*參數: @申請審覈人
*說明:表:book_borrow_apply
*********************************/
(
@UserNo Varchar(20),
@status char(1),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Declare @DeputyUserList NVarchar(4000)
Declare @ID int
Begin
-------------------------獲取被該用戶代理用戶列表
Select @DeputyUserList = '',@ID = 1
Exec pr_SelectDeputyPersonList @UserNo, @DeputyUserList out
if( @DeputyUserList != '' )
Set @DeputyUserList = '''' + @UserNo + ''',''' + Replace(@DeputyUserList,',', ''',''') + ''''
Else
Set @DeputyUserList = '''' + @UserNo + ''''
Set @DeputyUserList = 'Select user_no from Security Where user_no In(' + @DeputyUserList+ ') and win_no = ''A060403'' and p_approve = ''Y'''
-------------------------將本人及其代理人的審覈權限存到臨時表中
Create Table #tbSecurity(ID int IDentity(1,1), user_no varchar(20)) --保存用戶借閱申請審覈的權限(含被代理人)
Insert Into #tbSecurity Exec sp_ExecuteSql @DeputyUserList
-------------------------查詢用戶(含被代理人)借閱申請審覈信息)
DECLARE @SelectUser VARCHAR(200)
DECLARE @UserChief varchar(10)
DECLARE @Company_no varchar(20)
DECLARE @Dept_no varchar(20)
Select @sWhere = '',@UserChief=''
Create Table #tbChief( user_no varchar(20),UserChief varchar(10)) --保存用戶處級代號列表(含被代理人)
declare apply cursor for SELECT user_no FROM #tbSecurity
open apply
fetch next from apply into @SelectUser
while @@fetch_status = 0
begin
If (@SelectUser = Null) Select @SelectUser=''
if @SelectUser <> '' --如果有用戶
Begin
select @Company_no=company_no,@Dept_no=dept_no from useradmin where user_no =@SelectUser
select @UserChief= OA.dbo.fn_Dept_GetChiefDeptNo(@Company_no,@Dept_no)
insert into #tbChief values(@SelectUser,@UserChief )
End
fetch next from apply into @SelectUser
end
close apply
deallocate apply
delete #tbSecurity
-------------------------生成查詢語句
Select @sWhere = ' where 1=1 '
If(Rtrim(@status) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (T.status = ' + @status + ' ) '
Select @sSql = ' select T.*,#tbChief.user_no deputy_no from (select book_borrow_apply.* ,books.book_no,books.book_name,books.chief_no,(CASE book_borrow_apply.status WHEN ''0'' THEN ''待審'' WHEN ''1'' THEN ''通過'' ELSE ''拒借'' END) AS Status_nm , U.user_name,U.email ,U.position_name from book_borrow_apply '
+' join ( select useradmin.user_no,useradmin.user_name,useradmin.email,position.position_name from useradmin LEFT join position on useradmin.position_no=position.position_no)U on book_borrow_apply.user_no = U.user_no '
+' join books on book_borrow_apply.company_no=books.company_no and book_borrow_apply.lower_id =books.lower_id and book_borrow_apply.book_id=books.book_id) T '
+' join #tbChief on T.user_no= #tbChief.user_no and T.chief_no= #tbChief.UserChief '
+ Rtrim(@sWhere)
select @sOrderBy=' submit_date '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectBorrowedByAdmin
/********************************
*介紹:查詢已借出圖書信息
*作者:Tim
*書寫時間:2007/05/11
*參數: @UserNo 管理用戶
*說明:表:book_borrowed
*********************************/
(
@UserNo Varchar(20),
@Borrower varchar(20),
@Book varchar(30),
@BarCode varchar(20),
@giveback char(1),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Declare @DeputyUserList NVarchar(4000)
Declare @ID int
Begin
-------------------------獲取被該用戶代理用戶列表
Select @DeputyUserList = '',@ID = 1
Exec pr_SelectDeputyPersonList @UserNo, @DeputyUserList out
if( @DeputyUserList != '' )
Set @DeputyUserList = '''' + @UserNo + ''',''' + Replace(@DeputyUserList,',', ''',''') + ''''
Else
Set @DeputyUserList = '''' + @UserNo + ''''
Set @DeputyUserList = 'Select user_no from Security Where user_no In(' + @DeputyUserList+ ') and win_no = ''A060404'' and p_approve = ''Y'''
-------------------------將本人及其有還書管理權限的代理人存到臨時表中
Create Table #tbSecurity(ID int IDentity(1,1), user_no varchar(20))
Insert Into #tbSecurity Exec sp_ExecuteSql @DeputyUserList
-------------------------查詢用戶(含被代理人)已借出圖書信息)
DECLARE @SelectUser VARCHAR(200)
DECLARE @UserChief varchar(10)
DECLARE @Company_no varchar(20)
DECLARE @Dept_no varchar(20)
Select @sWhere = '',@UserChief=''
Create Table #tbChief( user_no varchar(20),UserChief varchar(10)) --保存用戶處級代號列表(含被代理人)
declare apply cursor for SELECT user_no FROM #tbSecurity
open apply
fetch next from apply into @SelectUser
while @@fetch_status = 0
begin
If (@SelectUser = Null) Select @SelectUser=''
if @SelectUser <> '' --如果有用戶
Begin
select @Company_no=company_no,@Dept_no=dept_no from useradmin where user_no =@SelectUser
select @UserChief= OA.dbo.fn_Dept_GetChiefDeptNo(@Company_no,@Dept_no)
insert into #tbChief values(@SelectUser,@UserChief )
End
fetch next from apply into @SelectUser
end
close apply
deallocate apply
delete #tbSecurity
-------------------------生成查詢語句
Select @sWhere = ' where 1=1 '
If(Rtrim(@Borrower) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (T.borrower like ''% ' + @Borrower + '%'' or T.user_name like ''% ' + @Borrower + '%'' ) '
If(Rtrim(@Book) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (T.book_no like ''% ' + @Book + '%'' or T.book_name like ''% ' + @Book + '%'' ) '
If(Rtrim(@BarCode) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (T.bar_code = ''' + @BarCode + ''' ) '
If(Rtrim(@giveback) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (T.giveback = ' + @giveback + ' ) '
Select @sSql = ' select T.*,#tbChief.user_no deputy_no from
(select book_borrowed.* ,books.book_no,books.bar_code,books.book_name,books.chief_no ,isnull(books.price,0) price, U.user_name,isnull(U.deposit,0) deposit from book_borrowed '
+' join ( select useradmin.user_no,useradmin.user_name,book_deposit.deposit from useradmin LEFT join book_deposit on useradmin.user_no=book_deposit.user_no)U on book_borrowed.borrower = U.user_no '
+' join books on book_borrowed.company_no=books.company_no and book_borrowed.lower_id =books.lower_id and book_borrowed.book_id=books.book_id) T '
+' join #tbChief on T.chief_no= #tbChief.UserChief '
+ Rtrim(@sWhere)
select @sOrderBy=' borrow_date '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
create Proc pr_Book_SelectLibrary_card
/********************************
*介紹:根據條件查詢用戶借書卡信息
*作者:Tim
*書寫時間:2007/05/11
*參數:@CardNo 借書卡代號 @UserNo 用戶代號
*說明:表:library_card
*********************************/
(
@CardNo varchar(20),
@UserNo varchar(20)
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
begin
--判斷條件
If (@CardNo = Null) Select @CardNo=''
If (@UserNo = Null) Select @UserNo=''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@CardNo) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (card_no = ''' + @CardNo + ''' ) '
If (Rtrim(@UserNo) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (user_no = ''' + @UserNo + ''' ) '
--創建臨時用戶信息表
Select U.*, C.Company_nm, D.Dept_nm, P.Position_name, OA.dbo.fn_DepartmentFrame(U.company_no,U.dept_no) Department
into #tbUsers From UserAdmin U
Left Join Company C on U.Company_no = C.Company_no
Left Join Dept D on U.Company_no = D.Company_no And U.dept_no = D.dept_no
Left Join Position P on U.position_no = P.position_no
--生成語句
Select @sSql ='select library_card.*,#tbUsers.Department,#tbUsers.user_name from library_card left join #tbUsers ON library_card.user_no=#tbUsers.user_no '
+ Rtrim(@sWhere)
Execute sp_executesql @sSql
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectLibrarycardList
/********************************
*介紹:查詢本單位所有用戶借書卡信息
*作者:Tim
*書寫時間:2007/05/11
*參數: @查詢條件
*說明:表:library_card
*********************************/
(
@sWhere varChar(4000),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sOrderBy NvarChar(1000)
begin
select @sSql='select library_card.*,T.Department,T.user_name,T.Company_no from library_card left join '
+' (Select U.*, C.Company_nm, D.Dept_nm, P.Position_name, OA.dbo.fn_DepartmentFrame(U.company_no,U.dept_no) Department ,'
+ ' OA.dbo.fn_Dept_GetChiefDeptNo(U.company_no, U.dept_no) ChiefDeptNo '
+' From UserAdmin U '
+ 'Left Join Company C on U.Company_no = C.Company_no '
+ 'Left Join Dept D on U.Company_no = D.Company_no And U.dept_no = D.dept_no '
+ ' Left Join Position P on U.position_no = P.position_no) T '
+ ' ON library_card.user_no=T.user_no '
+ ' where 1=1 '+ RTRIM(@sWhere)
select @sOrderBy=' card_no '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_SelectType
/********************************
*介紹:根據條件查詢圖書分類信息
*作者:Tim
*書寫時間:2007/05/11
*參數:@CompanyNo 公司代號 @lastNo 上級分類編號 @TypeNo 分類代號 @TypeNM 分類名稱
*說明:表:book_type, book_lower_type
*********************************/
(
@CompanyNo varchar(10),
@lastNo varchar(20),
@TypeNo Varchar(20),
@TypeNM Varchar(20)
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Begin
--判斷條件
If (@CompanyNo = Null) Select @CompanyNo=0
If (@lastNo = Null) Select @lastNo=''
If (@TypeNo = Null) Select @TypeNo=''
If (@TypeNM = Null) Select @TypeNM=''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@CompanyNo) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (company_no = ''' + @CompanyNo + ''' ) '
If (Rtrim(@TypeNo) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (type_id = ' + @TypeNo + ' ) '
If (Rtrim(@TypeNM) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (type_name LIKE ''%' + @TypeNM + '%'' ) '
If(Rtrim(@lastNo) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (last_type = ' + @lastNo + ' ) ' --""代表搜索所有類別信息;"0" 代表搜索大類信息
else Select @sWhere = Rtrim(@sWhere) +' AND last_type<>0 '
--生成語句
Select @sSql = 'SELECT * '
+ 'FROM (SELECT *,0 last_type from book_type union select company_no,lower_id as type_id,lower_name as type_name,type_id as last_type from book_lower_type) T '
+ Rtrim(@sWhere)
+ ' ORDER BY company_no, type_id '
Execute sp_executesql @sSql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_UpdateBooks
/*******************************
程序功能:更新圖書信息
編寫人員:Tim
編寫日期:2007-5-14
*******************************/
(
@company_no varchar (10) ,
@lower_id int ,
@book_id int,
@chief_no varchar (10) ,
@dept_no varchar (10),
@book_no varchar (20) ,
@state bit,
@book_name varchar (30) ,
@book_image varchar (100) ,
@miniature_image varchar (100) ,
@book_concern varchar (20) ,
@author varchar (30) ,
@publish_date datetime ,
@price decimal (16, 4) ,
@edition varchar (30) ,
@spec varchar (30) ,
@buy_date datetime ,
@page_size int ,
@bar_code varchar (15) ,
@content varchar (200) ,
@stocks int ,
@loans int,
@recomment bit ,
@lease bit ,
@create_date datetime
)
as
DECLARE @Seq INT
if(@book_id=0)--新增數據
begin
Select @Seq = Max(book_id) From books
Set @Seq = IsNull(@Seq, 0) + 1
insert into books values(@company_no ,
@lower_id ,
@Seq,
@chief_no ,
@dept_no ,
@book_no ,
@state,
@book_name ,
@book_image ,
@miniature_image ,
@book_concern ,
@author ,
@publish_date ,
@price ,
@edition ,
@spec ,
@buy_date ,
@page_size ,
@bar_code ,
@content ,
@stocks ,
@loans ,
@recomment ,
@lease,
@create_date )
end
else--更新數據
update books set company_no=@company_no ,
lower_id=@lower_id ,
chief_no=@chief_no ,
dept_no=@dept_no ,
book_no=@book_no ,
state=@state,
book_name =@book_name ,
book_image=@book_image ,
miniature_image=@miniature_image ,
book_concern=@book_concern ,
author=@author ,
publish_date=@publish_date ,
price = @price ,
edition= @edition ,
spec = @spec ,
buy_date=@buy_date ,
page_size=@page_size ,
bar_code=@bar_code ,
content=@content ,
stocks=@stocks ,
recomment=@recomment ,
lease=@lease,
create_date=@create_date
where book_id = @book_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_UpdateLibrarycard
/*******************************
程序功能:更新圖書卡信息
編寫人員:Tim
編寫日期:2007-5-14
*******************************/
(
@IsNew int,
@card_no varchar (20) ,
@user_no varchar (20) ,
@register_date datetime ,
@foregift decimal(16,2) ,
@certificate_kind varchar (10) ,
@certificate_code varchar (20) ,
@borrow_books smallint ,
@enable bit
)
as
if(@IsNew=0)--新增數據
begin
if(exists(select * from Library_card where card_no=@card_no )) return 1
insert into Library_card values(
@card_no ,
@user_no ,
@register_date ,
@foregift ,
@certificate_kind ,
@certificate_code ,
@borrow_books ,
@enable )
end
else--更新數據
begin
update Library_card set
user_no=@user_no ,
register_date=@register_date ,
foregift=@foregift ,
certificate_kind=@certificate_kind ,
certificate_code=@certificate_code ,
borrow_books=@borrow_books ,
enable=@enable
where card_no = @card_no
end
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_UpdateType
/********************************
*介紹:辦公自動化OA系統 (更新圖書類別信息)
*作者:tim
*書寫時間:2007/05/12
*參數:@CompanyNo 公司代號 @lastNo 上級分類編號 @TypeNo 分類代號 @TypeNM 分類名稱
*說明:表:book_type, book_lower_type
*********************************/
(
@CompanyNo varchar(10),
@TypeNo int,
@TypeNM Varchar(20),
@lastNo int
)
as
BEGIN
DECLARE @Seq INT
IF(RTRIM(@TypeNo)=0) --編號為空則為插入操作
BEGIN
IF(RTRIM(@lastNo)=0)--頂級分類
BEGIN
Select @Seq = Max(type_id) From book_type
Set @Seq = IsNull(@Seq, 0) + 1
INSERT INTO book_type VALUES(@CompanyNo,@Seq,@TypeNM)
END
ELSE --小分類
BEGIN
Select @Seq = Max(lower_id) From book_lower_type
Set @Seq = IsNull(@Seq, 0) + 1
INSERT INTO book_lower_type VALUES(@CompanyNo,@lastNo,@Seq,@TypeNM)
END
END
ELSE
BEGIN
IF(RTRIM(@lastNo)=0)--頂級分類
BEGIN
IF(EXISTS(SELECT * FROM book_type WHERE type_id=@TypeNo ))
UPDATE book_type SET company_no=@CompanyNo,[type_name]=@TypeNM WHERE type_id=@TypeNo
ELSE
BEGIN
Select @Seq = Max(type_id) From book_type
Set @Seq = IsNull(@Seq, 0) + 1
INSERT INTO book_type VALUES(@CompanyNo,@Seq,@TypeNM)
DELETE book_lower_type WHERE type_id=@TypeNo
END
END
ELSE --小分類
BEGIN
IF(EXISTS(SELECT * FROM book_lower_type WHERE type_id=@TypeNo ))
UPDATE book_lower_type SET company_no=@CompanyNo,type_id=@lastNo,lower_name=@TypeNM WHERE lower_id=@TypeNo
ELSE
BEGIN
Select @Seq = Max(lower_id) From book_lower_type
Set @Seq = IsNull(@Seq, 0) + 1
INSERT INTO book_lower_type VALUES(@CompanyNo,@lastNo,@Seq,@TypeNM)
DELETE book_type WHERE type_id=@TypeNo
END
END
END
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Book_update_book_amends
/********************************
*介紹:插入用戶賠償紀錄
*作者:Tim
*書寫時間:2007/05/11
*參數: @UserNo 用戶代號,@book_id 圖書代號,@borrow_date 借閱時間
@amends_money 賠償金額 @amends_cause 賠償原因 @note 備注
@operate_user_no 操作員
*說明:表:books,useradmin
exec pr_Book_update_book_amends 'lxg',1,'2007-5-23',1,'0','部分頁面已損壞','lxg'
*********************************/
(
@user_no varchar(20),
@book_id int,
@borrow_date datetime,
@amends_money decimal(16,2),
@amends_cause char(1),
@note varchar(60),
@operate_user_no varchar(20)
)
as
begin
--取得用戶詳細信息
Select U.*, C.Company_nm, D.Dept_nm, P.Position_name,
OA.dbo.fn_Dept_GetChiefDeptNo(U.company_no, U.dept_no) ChiefDeptNo into #tbuser
From UserAdmin U
Left Join Company C on U.Company_no = C.Company_no
Left Join Dept D on U.Company_no = D.Company_no And U.dept_no = D.dept_no
Left Join Position P on U.position_no = P.position_no
Where U.user_no=@user_no
--取得圖書詳細信息
select books.*,T.lower_name,T.type_id,T.type_name,company.company_nm company,d1.dept_nm Department ,d2.dept_nm chief_nm into #tbbook from books
join ( select book_lower_type.lower_id, book_lower_type.lower_name,book_type.type_name ,book_type.type_id from book_lower_type
join book_type on book_lower_type.type_id=book_type.type_id) T on books.lower_id=T.lower_id
join company on books.company_no=company.company_no
join dept d1 on books.company_no=d1.company_no and books.dept_no=d1.dept_no
join dept d2 on books.company_no=d2.company_no and books.chief_no=d2.dept_no
where book_id = @book_id
DECLARE @Seq INT
Select @Seq = Max(amends_id) From book_amends
Set @Seq = IsNull(@Seq, 0) + 1
insert into book_amends select @Seq,#tbuser.user_no,#tbuser.user_name,#tbuser.Company_nm,#tbuser.dept_nm,@borrow_date,#tbbook.book_name,#tbbook.company,#tbbook.Department,#tbbook.book_concern,#tbbook.author,#tbbook.publish_date,#tbbook.price,#tbbook.buy_date,@amends_money,getdate(),@amends_cause,@note,@operate_user_no from #tbuser,#tbbook
--如果圖書遺失,則漸少圖書庫存數輿借出數
if(@amends_cause='1') update books set stocks=stocks-1 where book_id=@book_id
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
create Proc pr_Book_update_deposit
(
@user_no varchar(20),
@pay_date datetime,
@deposit decimal(9,2),
@handlers varchar(10)
)
as
If(exists(select * from book_deposit where user_no=@user_no))
update book_deposit set pay_date=@pay_date,deposit=@deposit,handlers=@handlers where user_no=@user_no
else
insert into book_deposit values (@user_no,@pay_date,@deposit,@handlers)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_CheckUserExist
/********************************
*介紹:辦公自動化OA系統 (檢查用戶是否存在)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶NO
*返回:用戶是否存在 0:否;1是
*說明:涉及表名[useradmin,record]
*********************************/
(@UserNo varchar(20))
as
if exists(select * from useradmin where user_no=@UserNo)
return 1
else
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_CompleteBillProcess
/********************************
*介紹:辦公自動化OA系統 (單據審核完成後將其相關信息轉移到已結案檔中)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:單據NO
*說明:涉及表名[bill_m_approve,person_d_approve,person_approve_file]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(20)
)
as
declare @IsEffectValidate char(1)
select @IsEffectValidate = effect_validate
from bill_m_approved
where bill_no = @BillNo
----進行移轉
begin transaction
insert into bill_m_approved select * from bill_m_approve where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo
if @@Error<>0
goto Err
insert into bill_item_approved select * from bill_item_approve where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo
if @@Error<>0
goto Err
insert into person_d_approved select * from person_d_approve where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo
if @@Error<>0
goto Err
insert into bill_file_done select * from bill_file where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo
if @@Error<>0
goto Err
insert into person_approved_file select * from person_approve_file where company_no = @CompanyNo and Kind_No = @KindNo and bill_no=@BillNo
if @@Error<>0
goto Err
--更新單據簽核完成日期
update bill_m_approved Set complete_date = getdate() Where company_no = @CompanyNo and Kind_No = @KindNo and bill_no = @BillNo
if @@Error <> 0
goto Err
----單據需要效果確認
if @IsEffectValidate = 'Y'
begin
insert into bill_approved_validate(company_no, kind_no, bill_no, seq, setting_user_no)
select company_no, kind_no, bill_no, seq, User_no from person_d_approved
where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo and effect_validate = 'Y'
if @@Error<>0 goto Err
end
delete bill_file where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@Error<>0
goto Err
delete person_approve_file where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@Error<>0
goto Err
delete person_d_approve where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@Error<>0
goto Err
delete bill_item_approve where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@Error<>0
goto Err
delete bill_m_approve where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@Error<>0
goto Err
commit transaction
return 0
Err:
rollback transaction
return 1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Customer_DeleteCustomer
/********************************
*介紹:辦公自動化OA系統 (刪除客戶)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[customer]
*********************************/
(
@customer_id int
)
as
delete from customer where customer_id=@customer_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Customer_InsertCustomer
/********************************
*介紹:辦公自動化OA系統 (Customer)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Customer]
*********************************/
(
@customer_id int,
@customer_no varchar(20),
@company varchar(20),
@corporation varchar(20),
@register_date varchar(20),
@calling int,
@area int,
@state int,
@customer_grade int,
@quarry int,
@customer_type int,
@character int,
@reality bit,
@province varchar(20),
@city varchar(20),
@post_code varchar(6),
@address_zh varchar(60),
@address_en varchar(60),
@tel varchar(20),
@fax varchar(20),
@mail varchar(30),
@homepage varchar(30),
@bank varchar(30),
@bank_account varchar(20),
@user_no varchar(20),
@content varchar(200)
)
as
insert into customer
(
customer_id,
customer_no,
company,
corporation,
register_date,
calling,
area,
state,
customer_grade,
quarry,
customer_type,
[character],
reality,
province,
city,
post_code,
address_zh,
address_en,
tel,
fax,
mail,
homepage,
bank,
bank_account,
user_no,
content
)
values(
@customer_id,
@customer_no,
@company,
@corporation,
@register_date,
@calling,
@area,
@state,
@customer_grade,
@quarry,
@customer_type,
@character,
@reality,
@province,
@city,
@post_code,
@address_zh,
@address_en,
@tel,
@fax,
@mail,
@homepage,
@bank,
@bank_account,
@user_no,
@content
)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_DeleteAffiche
/********************************
*介紹:辦公自動化OA系統 (刪除公告及相關資訊)
*作者:william
*書寫時間:2007/05/
*說明:
*********************************/
(
@AfficheID int,
@IsDeleteAllInfo int,
@sMessage varchar(300) out
)
AS
if(exists(select * from affiche where affiche_id=@AfficheID))
begin
if(@IsDeleteAllInfo=1)
begin
begin transaction
delete from affiche_incept where affiche_id=@AfficheID
delete from affiche_file where affiche_id=@AfficheID
delete from affiche_leaveword where affiche_id=@AfficheID
delete from affiche where affiche_id=@AfficheID
if(@@error=0)
commit transaction
else
begin
rollback transaction
set @sMessage='刪除失敗'
end
end
else
begin
if(exists(select * from affiche_incept where affiche_id=@AfficheID)
or exists(select * from affiche_file where affiche_id=@AfficheID)
or exists(select * from affiche_leaveword where affiche_id=@AfficheID))
set @sMessage='無法刪除該公告,該公告含有相關留言、附檔等相關信息,請選擇刪除該公告的全部信息'
else
delete from affiche where affiche_id=@AfficheID
end
end
else
set @sMessage='未找到相關公告'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_DeleteAssistantInfo
/********************************
*介紹:辦公自動化OA系統 (刪除助理信息)
*作者:Billy
*書寫時間:2006/08/19
*參數:
*說明:
*********************************/
@Seq int
as
Delete From Assistant Where Seq = @Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_DeleteBillFlowM
/********************************
*介紹:辦公自動化OA系統 (刪除一單據流程)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[bill_flow_m]
*********************************/
(
@FlowID int
)
as
delete from bill_flow_m where flow_id=@FlowID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteBillKind
/********************************
*介紹:辦公自動化OA系統 (刪除單據類型)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[bill_kind,record]
*********************************/
(
@KindNo varchar(10)
)
as
delete bill_kind where kind_no=@KindNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_DeleteBillSecurityFromUserNo
/********************************
*介紹:辦公自動化OA系統 (刪除指定用戶的單據建立權限)
*作者:Billy
*書寫時間:2006/07/07
*傳入:用戶帳號
*返回:
*說明:涉及表名[bill_security]
*********************************/
(
@UserNo varchar(20)
)
as
Delete From Bill_Security Where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteCompany --judgement foreign key
/********************************
*介紹:辦公自動化OA系統 (查詢公司信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:公司代號,操作者,操作窗口
*返回:刪除是否成功
*說明:涉及表名[company,record]
*********************************/
(
@CompanyNo varchar(10)
)
as
delete company where company_no=@CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteDepartment
/********************************
*介紹:辦公自動化OA系統 (刪除指定的部門)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:公司代號,部門代號,操作者,操作窗口
*返回:刪除是否成功
*說明:涉及表名[dept,record]
*********************************/
(
@CompanyNo varchar(10),
@DepartmentNo varchar(20)
)
as
delete dept where company_no=@CompanyNo and dept_no=@DepartmentNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_DeleteDeputyInfoFromSeq
/********************************
*介紹:辦公自動化OA系統 (查詢用戶的工作代理設置)
*作者:Billy
*書寫時間:2006/07/26
*傳入:序號
*返回:代理列表
*說明:涉及表名[DeputyInfo]
*********************************/
(
@Seq int
)
as
Delete From DeputyInfo Where seq=@Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteErrorCode
/********************************
*介紹:辦公自動化OA系統 (根據類型和異常代號刪除品質異常對照檔)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[error_code,record]
*********************************/
(
@ProductNo varchar(10),
@ErrorNo varchar(10)
)
as
delete error_code where product_no=@ProductNo and error_no=@ErrorNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteMenuItem
/********************************
*介紹:辦公自動化OA系統 (刪除指定的菜單項)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:窗口代號,操作者,操作窗口
*說明:涉及表名[menu_list,record]
*返回:刪除是否成功
*********************************/
(
@WindowNo varchar(20),
@Operator varchar(20),
@OperateWin varchar(20)
)
as
declare @error int
set @error=0
begin transaction
delete menu_list where win_no=@WindowNo
if (@@error<>0) set @error=1
exec pr_InsertNewLog @Operator,@OperateWin,'3'
if (@@error<>0) set @error=1
if @error=0
begin
commit transaction
return 1
end
else
begin
rollback transaction
return 0
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeletePosition
/********************************
*介紹:辦公自動化OA系統 (根據給定的職務NO刪除對應的職務)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:職位代號,操作者,操作窗口
*返回:刪除是否成功
*說明:涉及表名[position,record]
*********************************/
(
@CompanyNo varchar(10),
@PositionNo varchar(10)
)
as
delete position where position_no=@PositionNo and Company_No = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteProductKind
/********************************
*介紹:辦公自動化OA系統 (根據產品NO移除對應的產品信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_kind,record]
*********************************/
(
@ProductNo varchar(10),
@Operator varchar(20),
@WindowNo varchar(20)
)
as
delete product_kind where product_no=@ProductNo
exec pr_InsertNewLog @Operator,@WindowNo,'3'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteProductStyle
/********************************
*介紹:辦公自動化OA系統 (刪除指定的機型檔案)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_style,record]
*********************************/
(
@ProductNo varchar(10),
@StyleNo varchar(10)
)
as
delete product_style where product_no=@ProductNo and style_no=@StyleNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_DeleteUser
/********************************
*介紹:辦公自動化OA系統 (刪除指定的用戶)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶NO,操作者,操作窗口
*返回:刪除是否成功0:否;1:是
*說明:涉及表名[useradmin,record]
*********************************/
(
@UserNo varchar(20)
)
as
delete useradmin where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_DeleteUserDiskSetting
/********************************
*介紹:辦公自動化OA系統 (刪除用戶網盤設定)
*作者:william
*書寫時間:2007/05/
*說明:涉及表名[directory_setting]
*********************************/
(
@UserNo varchar(20)
)
AS
if(exists(select * from directory_setting where user_no=@UserNo))
delete from directory_setting where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_DeleteUserPurview
/********************************
*介紹:辦公自動化OA系統 (刪除某用戶的所有權限)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[Security]
*********************************/
(
@UserNo varchar(20)
)
as
Delete From security Where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_DepartmentRight_SelectMenuList
/********************************
*介紹:辦公自動化OA系統 (根據用戶代號取得窗口列表)
*作者:Billy
*書寫時間:2006/08/25
*參數:@UserNo 用戶代號
*說明:表:Menu_List, Security
*********************************/
(
@user_no Varchar(20)
)
as
SELECT a.win_no, a.win_nm,a.parent_win_no, a.c_EveryOne,
OA.dbo.fn_Menu_HasChildMenu(a.Win_no) As HasChildMenu, OA.dbo.fn_Menu_CheckMenuLevel(a.Win_no) As Menu_Level,
b.p_seted,b.user_no,b.p_browse, b.p_new, b.p_modify, b.p_del,
b.p_print, b.p_approve, b.p_visible
FROM menu_list a
left join
(
SELECT 'Y' p_seted,* FROM security WHERE user_no = @user_no
) b
ON a.win_no = b.win_no
where a.c_dept = 'Y'
Order By a.win_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_DepartmentRight_SelectUserFromCondition
/********************************
*介紹:辦公自動化OA系統 (取指定條件的用戶信息)
*作者:Billy
*書寫時間:2006/08/25
*參數:@UserNo 用戶代號
*說明:表:UserAdmin, Position, Dept, Company
*********************************/
( @user_no varchar(10),
@User Varchar(20) = '',
@PageIndex int = 1,
@PageSize int = 10 ,
@PageCount int = 1 output
)
as
Declare @Sql varchar(4000)
declare @dept_no varchar(10)
--/取得用戶所在部門
select @dept_no = dept_no from useradmin a inner join position b on a.position_no=b.position_no and b.dept_director='Y' where a.user_no=@user_no
Set @Sql = 'SELECT U.user_no, U.user_name, U.tel, U.email, U.approve_grade, U.role_level, U.mark_name, U.active_date, U.disable_date, U.window,'
+ ' C.company_nm, P.position_name, D.dept_no,D.dept_nm,U.Company_no , dbo.fn_Departmentframe(u.company_no, u.dept_no) DepartMent, '
+ ' dbo.fn_CheckUserStatus(U.status, getdate(), U.active_date, U.disable_date) status '
+ ' FROM UserAdmin U '
+ ' inner JOIN dept D On U.Dept_no = D.Dept_no '
+ ' inner JOIN Company C ON U.Company_no = C.Company_no '
+ ' inner JOIN [position] P ON U.position_no = P.position_no '
+ ' Where U.dept_no = ''' + @dept_no + '''' +
+ ' and (U.user_name like ''%' + @User + '%'' or U.user_no like ''%' + @User + '%'') '
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', 'DepartMent, Approve_grade, position_name'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Dept_GetShortCodeList
/**********************************
* 功能:取得所有公司的處級簡碼列表
* 作者:Billy
* 日期:2006/11/17
**********************************/
(
@CompanyNo varchar(10)
)
As
Select company_no, dept_nm, dept_no, chief_short_code From dept
Where chief_flag = 'Y' and company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************************
*介紹:辦公自動化OA系統 ()
*作者:YM
*書寫時間:2007/05/09
*傳入:會議列表@DivanID
*說明:涉及表名[divan,divan_apply_list,divan_use_history]
*********************************************/
CREATE PROCEDURE pr_Divan_InsertDivan
(
@Divan_No varchar(10),
@Divan_Name varchar(50),
@Company_No varchar(10),
@Ower_Dept_No varchar(10),
@Divan_Size varchar(20),
@Lodge_Amount smallint,
@Has_Videobit bit,
@has_audio bit,
@State char(1),
@Tel_1 varchar(20),
@Tel_2 varchar(20),
@Tel_3 varchar(20),
@Address varchar(100),
@User_No varchar(20),
@Divan_description varchar(200)
)
as
Declare @ID int
Declare @Err int
Declare @D_No int
Declare @D_Name int
select @D_No=Count(*) from divan where divan_no =@Divan_No
if(@D_No<>0)
begin
set @Err =-1
select @Err
return
end
select @D_Name =Count(*) from divan where divan_name =@Divan_Name
if(@D_Name<>0)
begin
set @Err=-2
select @Err
return
end
--Select @ID = Max(divan_id) From Divan_no
Select @ID = Max(divan_id) From divan
Set @ID = IsNull(@ID, 0) + 1
--insert into divan_apply_list(divan_id) values(@ID)
insert into divan(divan_id,divan_no,divan_name,company_no,owner_dept_no,divan_size,lodge_amount,has_video,has_audio,state, tel_1,tel_2,tel_3,address,user_no,divan_description)
values(@ID,@Divan_No,@Divan_Name,@Company_No,@Ower_Dept_No,@Divan_Size,@Lodge_Amount,@Has_Videobit,@has_audio,@State,@Tel_1,@Tel_2,@Tel_3,@Address,@User_No,@Divan_description)
--取系統錯誤號
select @Err = @@Error
--輸出組id和錯誤號
select @Err
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************************
*介紹:辦公自動化OA系統 ()
*作者:YM
*書寫時間:2007/05/09
*傳入:會議列表@DivanID
*說明:涉及表名[divan,divan_apply_list,divan_use_history]
*********************************************/
CREATE proc pr_Divan_SelectDivan
(
@Divan_name varchar(50) = '',
@nPageIndex int =1,
@nPageSize int=3,
@nPageCount int=0 Output
)
as
declare @Sql Nvarchar(4000)
Declare @sOrderBy NvarChar(1000)
set @sOrderBy = 'divan_name desc'
--If (Rtrim(@Divan_name) <> '')
set @Sql = N'select a.*,(select count(*) from divan_apply_list b where b.divan_id=a.divan_id ) divancount from divan a where a.divan_name Like ''%' + @Divan_name + '%'''
print @Sql
Exec pr_SelectDataPager @Sql, @nPageSize, @nPageIndex, @nPageCount Output, '*',@sOrderBy
print @nPageCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Employee_DeleteEmployee
/********************************
*介紹:辦公自動化OA系統 (刪除員工)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[employee]
*********************************/
(
@employee_id int
)
as
delete from employee where employee_id=@employee_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Employee_InsertEmployee
/********************************
*介紹:辦公自動化OA系統 (Employee)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Employee]
*********************************/
(
@employee_id int,
@employee_no varchar(8),
@employee_name varchar(15),
@sex bit,
@register_date datetime=null,
@company_no varchar(10),
@dept_no varchar(10),
@id_card varchar(18),
@status varchar(1),
@marriage varchar(1),
@nationality varchar(20),
@native_place varchar(30),
@nation varchar(10),
@birthday datetime,
@position_no varchar(10),
@family_address varchar(50),
@post_code varchar(6),
@educate_grade varchar(1),
@school varchar(20),
@dimission_date datetime,
@dimission_mode varchar(10),
@dimission_cause varchar(20),
@tel varchar(15),
@home_tel varchar(15),
@handset_tel varchar(12),
@exigency_address varchar(50),
@photo varchar(60)
)
as
insert into employee
(
employee_id,
employee_no,
employee_name,
sex,
register_date,
company_no,
dept_no,
id_card,
status,
marriage,
nationality,
native_place,
nation,
birthday,
position_no,
family_address,
post_code,
educate_grade,
school,
dimission_date,
dimission_mode,
dimission_cause,
tel,
home_tel,
handset_tel,
exigency_address,
photo
)
values(
@employee_id ,
@employee_no,
@employee_name,
@sex,
@register_date,
@company_no,
@dept_no,
@id_card,
@status,
@marriage,
@nationality,
@native_place,
@nation,
@birthday,
@position_no,
@family_address,
@post_code,
@educate_grade,
@school,
@dimission_date,
@dimission_mode,
@dimission_cause,
@tel,
@home_tel,
@handset_tel,
@exigency_address,
@photo
)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Employee_SelectEmployeeByDeptNo
/********************************
*介紹:辦公自動化OA系統 (查詢員工信息)
*作者:游勇
*書寫時間:2007/04/
*傳入:
*說明:涉及表名[employee, dept]
*********************************/
(
@dept_no varchar(10),
@employee_name varchar(15),
@PageSize int=30, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output, --總頁數據 傳入0時可返回頁總數
@ShowFields varchar (4000)='', --要顯示的字段列表,如果查詢結果有標識字段,需要指定此值,且不包含標識字段
@OrderFields varchar (1000)='' ,--排序字段列表
@RecordCount int=0 output -- 總記錄數
)
as
--declare @tmp table (company_no varchar(10), dept_no varchar(10), dept_nm varchar(60), parent_dept_no varchar(10), chief_flag char(1),[level] int)
declare @i int
declare @dno varchar(10)
--declare @company_no varchar(10)
declare @QueryText varchar(1000)
set @QueryText = ''
set @i=1
set @dno = '' --部門的處級代號
--set @company_no='' --公司代號
--insert @tmp select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
delete from dept_tmp_for_employee
insert dept_tmp_for_employee select company_no, dept_no, dept_nm, parent_dept_no, chief_flag, @i from dept where dept_no=@dept_no
while @@rowcount<>0
begin
set @i=@i+1
-- insert @tmp select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag,@i from dept a, @tmp b where a.parent_dept_no=b.dept_no and b.level=@i-1
insert dept_tmp_for_employee select a.company_no, a.dept_no, a.dept_nm, a.parent_dept_no, a.chief_flag,@i from dept a, dept_tmp_for_employee b where a.parent_dept_no=b.dept_no and b.level=@i-1
end
--select a.*, b.dept_nm from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from @tmp) order by a.dept_no, a.employee_id
set @QueryText = 'select a.*, b.dept_nm from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from dept_tmp_for_employee) and a.employee_name like ''%' + @employee_name + '%'''
--print @QueryText
--set @QueryText = 'select a.*, b.dept_nm from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from @tmp)'
Execute pr_SelectDataPager @QueryText, @PageSize , @PageCurrent, @PageCount Output, @ShowFields, @OrderFields
if @employee_name = ''
select @RecordCount=count(*) from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from dept_tmp_for_employee)
else
select @RecordCount=count(*) from employee a inner join dept b on a.dept_no=b.dept_no where a.dept_no in (select dept_no from dept_tmp_for_employee) and a.employee_name like @employee_name
--print @PageCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Employee_UpdateEmployee
/********************************
*介紹:辦公自動化OA系統 (Employee)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*說明:涉及表名[Employee]
*********************************/
(
@employee_id int,
@employee_no varchar(8),
@employee_name varchar(15),
@sex bit,
@register_date datetime,
@company_no varchar(10),
@dept_no varchar(10),
@id_card varchar(18),
@status varchar(1),
@marriage varchar(1),
@nationality varchar(20),
@native_place varchar(30),
@nation varchar(10),
@birthday datetime,
@position_no varchar(10),
@family_address varchar(50),
@post_code varchar(6),
@educate_grade varchar(1),
@school varchar(20),
@dimission_date datetime,
@dimission_mode varchar(10),
@dimission_cause varchar(20),
@tel varchar(15),
@home_tel varchar(15),
@handset_tel varchar(12),
@exigency_address varchar(50),
@photo varchar(60)
)
as
update employee
set employee_no = @employee_no,
employee_name = @employee_name ,
sex = @sex,
register_date = @register_date,
company_no = @company_no,
dept_no = @dept_no,
id_card = @id_card,
status = @status,
marriage = @marriage,
nationality = @nationality,
native_place = @native_place,
nation = @nation,
birthday = @birthday,
position_no = @position_no,
family_address = @family_address,
post_code = @post_code,
educate_grade = @educate_grade,
school = @school,
dimission_date = @dimission_date,
dimission_mode = @dimission_mode,
dimission_cause = @dimission_cause,
tel = @tel,
home_tel = @home_tel,
handset_tel = @handset_tel,
exigency_address = @exigency_address,
photo = @photo
where employee_id=@employee_id
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Exists_action_seq
@action_seq int
as
declare @count int
declare @sum int
set @sum = 0
set @count = 0
select @count = count(*) from bill_flow_d where action_seq=@action_seq
set @sum = @sum+@count
select @count = count(*) from person_d_approved where action_seq=@action_seq
set @sum = @sum + @count
select @count = count(*) from person_d_approve where action_seq=@action_seq
set @sum = @sum + @count
if(@sum = 0)
return 0
else
return 1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_GetAfficheLogUserInfo
/********************************
*介紹:辦公自動化OA系統 (取得用戶資訊,如:ETC 軟體課 張三)
*作者:william
*書寫時間:2007/05/
*說明:
*********************************/
(
@Userno varchar(20)
)
AS
select c.company_nm,d.dept_nm,u.user_name from useradmin u
left join company c on c.company_no = u.company_no
left join dept d on d.company_no = c.company_no and d.dept_no = u.dept_no
where u.user_no = @Userno
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_GetBottomMenuItemFromUserNo
/*************
取得最底層的功能表
****************/
(
@UserNo varchar(20),
@WinNo varchar(20)
)
as
Declare @Sql Nvarchar(4000), @UserList varchar(2021)
Select @Sql = '', @UserList = ''
Exec pr_SelectDeputyPersonList @UserNo, @UserList out
if( @UserList = '' )
Set @UserList = @UserNo
Else
set @UserList = @UserNo + ',' + @UserList
Print @UserList
Set @Sql='select M.win_no, M.win_nm caption,M.win_note title,M.seq,M.Large_icon,'
+ ' case M.open_type when ''1'' then ''_self'' else ''_blank'' end target ,M.Program_path From Menu_List M'
+ ' Where M.Win_no In (Select Distinct Win_no From Security where user_no in ('''+Replace(@UserList,',',''',''')+''')) '
+ ' and M.c_Visible = ''Y'' and parent_Win_no = ''' + @WinNo + ''' or (parent_Win_no = ''' + @WinNo + ''' and M.c_EveryOne = ''Y'')'
exec(@Sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_GetDeptFrameFromDeptNo
/********************************
*介紹:辦公自動化OA系統 (取得某用戶的部門結構,以字符串形式返回)
*作者:Billy
*書寫時間:2006/08/28
*參數:。。。。。
*說明:涉及表名[UserAdmin]
*********************************/
(
@CompanyNo varchar(10),
@DeptNo varchar(20),
@UserInfo varchar(500) = '' out
)
as
Set @UserInfo = ''
Select @UserInfo = OA.dbo.fn_DepartMentFrame(@CompanyNo, @DeptNo)
Set @UserInfo = IsNull(@UserInfo, 'N/A')
print @UserInfo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_GetMenuItemFromUserNo
(
@UserNo varchar(20)
)
as
Declare @Sql Nvarchar(4000), @UserList varchar(2021)
Select @Sql = '', @UserList = ''
Exec pr_SelectDeputyPersonList @UserNo, @UserList out
if( @UserList = '' )
Set @UserList = @UserNo
Else
set @UserList = @UserNo + ',' + @UserList
Print @UserList
Set @Sql='select Distinct M.win_no,M.parent_win_no,S.HasSecurity,M.c_EveryOne, M.win_nm,M.win_note,M.seq,M.Large_icon,'
+ ' M.open_type,M.Program_path,M.c_visible,S.p_browse,S.p_new,S.p_modify,S.p_del,S.p_print,'
+ ' S.p_approve,S.p_visible From Menu_List M'
+ ' Left join (Select ''Y'' HasSecurity,* From Security where user_no in ('''+Replace(@UserList,',',''',''')+''')) S '
+ ' on S.win_no=M.win_no '
print @Sql
exec(@Sql)
select win_no,parent_win_no, c_EveryOne from Menu_List order by win_no,seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_GetSeqNumber
/********************************
*介紹:辦公自動化OA系統 (取指定數據表的序號)
*作者:Billy
*書寫時間:2006/06/20
*參數:@TableName --數據表名稱
*說明:Declare @i int
exec @i=pr_GetSeqNumber 'bill_flow_m'
當返回0時表示傳入的表格名稱不在生成的范圍內
*********************************/
(
@TableName varchar(50)
)
as
Declare @Seq int
Declare @Done bit --傳進的是否在規定的范圍內
Declare @tempSeq int
set @Seq=0
set @Done=0
set @TableName=Lower(@TableName)
--單據流程表
if @TableName='bill_flow_m'
select @Seq=max(flow_id) from bill_flow_m
--單據欄位明細表
if @TableName='bill_column'
select @Seq=max(seq) from bill_column
--日志表
if @TableName='record'
select @Seq=max(seq) from record
--動作類型表
if @TableName='action_kind'
select @Seq=max(action_seq) from action_kind
--單據流程項表
if @TableName='bill_flow_d'
select @Seq=max(seq) from bill_flow_d
--簽核人員明細表
if @TableName='person_d_approve'
begin
select @Seq=max(seq) from person_d_approve
select @tempSeq=max(seq) from person_d_approved
set @Seq=IsNull(@Seq,0)
set @tempSeq=IsNull(@TempSeq,0)
if @tempSeq>@Seq
set @Seq=@tempSeq
end
--代理人員表
if @TableName='DeputyInfo'
select @Seq=max(seq) from DeputyInfo
--簽核人員附檔表
if @TableName='person_approve_file'
begin
select @Seq=max(seq_file) from person_approve_file
select @tempSeq=max(seq_file) from person_approved_file
set @Seq=IsNull(@Seq,0)
set @tempSeq=IsNull(@TempSeq,0)
if @tempSeq>@Seq
set @Seq=@tempSeq
end
--單據附檔表
if @TableName='bill_file'
begin
select @Seq=max(seq) from bill_file
select @tempSeq=max(seq) from bill_file_done
set @Seq=IsNull(@Seq,0)
set @tempSeq=IsNull(@TempSeq,0)
if @tempSeq>@Seq
set @Seq=@tempSeq
end
set @Seq=IsNull(@Seq,0)
set @Seq=@Seq+1
return @Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_GetUserBillSecurity
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@UserNo varchar(20),
@Create bit = 0 out,
@Search bit = 0 out,
@Browse bit = 0 out,
@Print bit = 0 out,
@Accounts varchar(2000) out
)
as
declare @ID int, @RowCount int
declare @tempNew char(1),@tempSearch char(1), @TempReportView char(1), @TempReportPrint char(1)
declare @DeputyList varchar(2000) --代理的用戶列表
Declare @Sql nvarchar(4000)
Create Table #BillSecurity(ID int Identity(1,1), C_New char(1), C_Search char(1), r_Browse char(1),r_Print char(1))
Set @ID = 1
Set @RowCount = 0
Select @Create = 0, @Search = 0, @Browse = 0, @Print = 0
select @tempNew='N', @tempSearch='N', @TempReportView = 'N', @TempReportPrint = 'N'
exec pr_SelectDeputyPersonList @UserNo,@DeputyList output
if @DeputyList=''
set @DeputyList=@UserNo
else
set @DeputyList=@DeputyList+','+@UserNo
Set @DeputyList = '''' + Replace(@DeputyList, ',', ''',''') + ''''
Set @Accounts = @DeputyList
Set @Sql = N'Select c_new,c_search,r_browse,r_print From bill_security where user_no in (' + @DeputyList + ') and company_no=@CompanyNo and kind_no=@KindNo'
Insert into #BillSecurity Execute sp_ExecuteSql @Sql, N'@CompanyNo varchar(10), @KindNo varchar(10)', @companyNo, @kindNo
Select @RowCount = count(*) From #BillSecurity
--取得每位用戶相應的單據權限
while @ID <= @RowCount
begin
select @tempNew=c_new,@tempSearch=c_search, @TempReportView = r_browse, @TempReportPrint = r_Print
from #BillSecurity where ID = @ID
if @tempNew='Y' set @Create = 1
if @tempSearch='Y' set @Search = 1
if @TempReportView = 'Y' set @Browse = 1
if @TempReportPrint = 'Y' Set @Print = 1
Set @ID = @ID + 1
end
Select @Create 建單, @Search 查詢, @Browse 瀏覽, @Print 列印
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_GetUserInfoToString
/********************************
*介紹:辦公自動化OA系統 (取得用戶基本信息,並以字符串傳出)
*作者:Billy
*書寫時間:2006/08/28
*參數:。。。。。
*說明:涉及表名[UserAdmin, Position]
*********************************/
(
@UserNo varchar(20),
@UserInfo varchar(500) = '' out
)
as
Set @UserInfo = ''
Select @UserInfo = OA.dbo.fn_DepartMentFrame(U.company_no, U.Dept_no) + ' ' + U.User_Name +'〔' + P.Position_Name + '〕' From UserAdmin U
Left Join Position P On U.position_no = P.Position_no
Where U.User_no = @UserNo
Set @UserInfo = IsNull(@UserInfo, 'N/A')
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_GetUserSecurity
/********************************
*介紹:辦公自動化OA系統 (取得指定用戶在指定窗口的許可權列表)
*作者:Billy
*書寫時間:2006/06/06
*參數:以逗號分隔的用戶帳號列表 , 窗口代號
*說明:涉及表名[Security]
*********************************/
(
@UserNo varchar(1000),
@WindowNo varchar(20)
)
as
declare @sql varchar(1000)
set @UserNo=''''+Replace(@UserNo,',',''',''')+''''
set @sql='Select p_browse,p_new,p_modify,p_del,p_print,p_approve,p_visible from Security Where win_no='''+@WindowNo+''' and User_no in ('+@UserNo+')'
exec(@Sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_InsertActionKind
---------------------往action_kind表中插入新記錄
@company_no varchar(10),
@action_nm varchar(20),
@PRI int,
@approve char(1),
@ErrorNo varchar(50) output
as
declare @sum int --------保存調用pr_ExistsPRI存儲過程的返回值
declare @action_seq int
declare @error int
set @error=0
set @sum=0
begin transaction
exec @action_seq=pr_GetSeqNumber 'action_kind'
if Exists(select Company_no from action_kind where (company_no=@company_no and action_nm=@action_nm) or (company_no=@company_no and PRI=@PRI))
begin
set @ErrorNo='Existed'
return 0
end
insert into action_kind values (@company_no,@action_seq,@action_nm,@approve,@PRI)
if(@@error<>0) set @error=1
if(@error=0)
commit transaction
else
rollback transaction
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertBillFlowItem
/********************************
*介紹:辦公自動化OA系統 (添加一流程項)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[bill_flow_d]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@FlowMode char(1) = '1',
@ActionSeq int,
@ApproveCompanyNo varchar(10),
@DeptNo varchar(10),
@PositionNo varchar(10),
@AddApproveUser char(1),
@FillIn char(1),
@EffectValidate char(1),
@Prompt nvarchar(100) = N'',
@EndCase char(1),
@Condition varchar(50)
)
as
declare @FlowItemID int
Declare @Seq int
select @FlowItemID=max(flowitem_id) from bill_flow_d
select @Seq=max(seq) from Bill_Flow_d where company_no=@CompanyNo and kind_no=@KindNo
set @Seq=IsNull(@Seq,0);
set @FlowItemID=IsNull(@FlowItemID,0)
set @FlowItemID=@FlowItemID+1
set @Seq=@Seq+1
insert into bill_flow_d
(
company_no, kind_no, flowitem_id, seq, flow_mode, action_seq, approve_company_no, dept_no,
position_no, Add_ApproveUser, fillIn, Effect_Validate, EndCase, Condition
) values
(
@CompanyNo, @KindNo, @FlowItemID, @Seq, @FlowMode, @ActionSeq, @ApproveCompanyNo ,@DeptNo,
@PositionNo, @AddApproveUser, @FillIn, @EffectValidate, @EndCase, @Condition
)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertBillFlowM
/********************************
*介紹:辦公自動化OA系統 (新增一單據流程)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[bill_flow_m]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@FlowMode char(1)='1',
@Note varchar(100)
)
as
declare @FlowID int
exec @FlowID=pr_GetSeqNumber 'bill_flow_m'
insert into bill_flow_m values(@CompanyNo,@KindNo,@FlowMode,@FlowID,@Note)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE ProcEDURE pr_InsertCommonPhrase
@UserRole INT,
@UserNo VARCHAR(30),
@PhraseContent VARCHAR(200),
@CreateDate DATETIME
AS
DECLARE @iSeq int
DECLARE @error int
SET @error=0
SELECT @iSeq=MAX(seq) FROM use_phrase
IF(NOT LEN(@iSeq)>0)
SET @iSeq = 0
ELSE
SET @iSeq = @iSeq + 1
BEGIN TRANSACTION
IF(@UserRole=2)
INSERT INTO use_phrase (seq, system_phrase, user_no, phrase_content, create_date) VALUES (@iSeq, 'Y', @UserNo,@PhraseContent, @CreateDate)
ELSE
INSERT INTO use_phrase (seq, system_phrase, user_no, phrase_content, create_date) VALUES (@iSeq, 'N', @UserNo,@PhraseContent, @CreateDate)
IF(@@ERROR<>0)
SET @error=1
IF(@error=0)
COMMIT TRANSACTION
ELSE
ROLLBACK TRANSACTION
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/********************************
*介紹:辦公自動化OA系統 (添加一會議管理)
*作者:YM
*書寫時間:2007/05/08
*傳入:會議主鍵
*返回:
*說明:涉及表名[divan]
*********************************/
CREATE PROCEDURE pr_InsertDivan
(
@Divan_ID int,
@Divan_No varchar(10),
@Divan_Name varchar(50),
@Company_No varchar(10),
@Ower_Dept_No varchar(10),
@Divan_Size varchar(20),
@Lodge_Amount smallint,
@Has_Videobit bit,
@State char(1),
@Tel_1 varchar(10),
@Tel_2 varchar(10),
@Tel_3 varchar(10),
@Address varchar(100),
@User_No varchar(20),
@Divan_description varchar(200),
@ErrorNo varchar(50) output
)
as
declare @Error int
set @Error = 0
begin transaction
if(exists(select * from divaen where Divan_ID = @Divan_ID))
begin
set @ErrorNo='會議編號已經存在'
return 0
end
insert into divan values(@Divan_ID,@Divan_No,@Divan_Name,@Company_No,@Ower_Dept_No,@Divan_Size,@Lodge_Amount,@Has_Videobit,@State,@Tel_1,@Tel_2,@Tel_3,@Address,@User_No,@Divan_description)
if(@@error<>0)
set @Error =0
if(@Error=0)
commit transaction
else
rollback transaction
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_InsertLeaveword
/********************************
*介紹:辦公自動化OA系統 (新增公告留言)
*作者:william
*書寫時間:2007/05/
*說明:
*********************************/
(
@affiche_id int,
@user_no varchar(20),
@content varchar(255)
)
AS
declare @seq int
exec dbo.pr_getTableSeq 'affiche_leaveword','leaveword_id',@seq out
print @seq
insert into affiche_leaveword values(@affiche_id,@seq,@user_no,@content,getdate())
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewAssistantInfo
/********************************
*介紹:辦公自動化OA系統 (插入工作助手信息)
*作者:Billy
*書寫時間:2006/08/29
*參數:@DirectorID, @AssistantID
*說明:使用表:Assistant
*********************************/
(
@DirectorNo varchar(20),
@AssistantNo varchar(20)
)
as
Declare @Seq int
if exists( Select * From Assistant Where Director_No = @DirectorNo And Assistant_No = @AssistantNO)
return 0
Set @Seq = 0
Select @Seq = Max(Seq) From Assistant
Set @Seq = IsNull(@Seq, 0) + 1
Insert Into Assistant (Seq, Director_No, Assistant_No) values (@seq, @DirectorNo, @AssistantNo)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_InsertNewBillApproveLog
/*************************************************
*介紹:辦公自動化OA系統 ___審核單據操作:拒絕簽核指定的單據
*作者:電腦混混Vincent
*書寫時間:2006/08/21
*傳入:單據NO,用戶NO,拒簽到用戶,操作時間
*說明: 被訪表名[bill_Approve_Log]
更新表名[]
*
*************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30), ----單據編號
@UserNo varchar(20), ----用戶代號
@OperateResult char(1), ----簽核結果 1:通過;2:拒簽
@ApproveSeq int, ----審覈順序(用於退簽)
@Note varchar(6000) ----簽核批示
)
as
Declare @nSeq int ----主鍵(序號)
declare @sRejectToUserName varchar(20)----退單到用戶名稱
Declare @OperateTime datetime
Select @nSeq = Max(Seq) From Bill_Approve_Log
Set @nSeq = IsNull(@nSeq, 0) + 1
set @OperateTime = getdate();
----拒簽退單
if @OperateResult = '2'
begin
----為批示添加附屬信息
select @sRejectToUserName = user_name
from person_d_approve P
inner join useradmin U on P.actual_user_no = U.user_no
where P.bill_no = @BillNo
and P.approveSeq = @ApproveSeq
set @Note = @Note + '此單據被拒簽退單到第' + cast(@ApproveSeq as varchar)
+'位簽核用戶(' + @sRejectToUserName+ ')'
end
Insert Into Bill_Approve_Log
Values
(@nSeq, @CompanyNo, @KindNo, @BillNo, @UserNo, @ApproveSeq, @OperateResult, @Note, @OperateTime)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_InsertNewBillFile
/********************************
*介紹:新增一單據文檔信息
*作者:Billy
*書寫時間:2006/12/08
*說明:涉及表名[bill_file]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30),
@FilePath nvarchar(300)
)
as
declare @Seq int
Select @Seq = Max(Seq) From Bill_File
Set @Seq = IsNull(@Seq, 0) + 1
Insert into bill_file (company_no, kind_no, bill_no, seq, File_path)values(@CompanyNo,@KindNo,@BillNo,@Seq,@FilePath)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewBillKind
/********************************
*介紹:辦公自動化OA系統 (添加新的單據類型)
*作者:Billy
*書寫時間:2006/05/29
*
*說明:涉及表名[bill_kind,record]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@KindShortCode varchar(2),
@KindName varchar(60),
@EffectValidate char(1) = 'N',
@EffectValidateChoose char(1) = 'N',
@Formula varchar(200),
@Note varchar(60),
@CreatePerson varchar(20),
@ErrorNo varchar(50) out
)
as
Declare @RowCount int
--檢查單據類型代號是否已被占用
if( Exists( Select * From Bill_Kind WHere Company_no = @CompanyNo And Kind_no = @KindNo ) )
Begin
Set @ErrorNo = 'Exists'
return 0
End
if( LTrim(@KindShortCode) = '' )
Begin
Set @ErrorNo = 'UnInputNo'
return 0
end
if( Exists(Select * From bill_kind Where company_no = @CompanyNo And kind_short_code = @KindShortCode ) )
Begin
Set @ErrorNo = 'ExistsCode'
return 0
End
insert bill_kind(company_no,kind_no,kind_short_code, kind_nm, effect_validate , effect_validate_choose,formula, note,create_person,modify_person)
values(@CompanyNo,@KindNo, @KindShortCode, @KindName, @EffectValidate, @EffectValidateChoose, @Formula, @Note,@CreatePerson,@CreatePerson)
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @ErrorNo = 'Failing'
return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewBillSecurity
/********************************
*介紹:辦公自動化OA系統 (添加一用戶建單權限)
*作者:Billy
*書寫時間:2006/07/07
*傳入:用戶帳號
*返回:
*說明:涉及表名[bill_security]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@UserNo varchar(20),
@New char(1)='N',
@Search char(1)='N',
@BrowseReport char(1) = 'N',
@PrintReport char(1) = 'N'
)
as
--Declare @ComapnyNo varchar(10)
--select @ComapnyNo=company_no from Bill_kind where kind_no=@KindNo
Insert into bill_security (user_no,company_no,kind_no,c_new,c_search, r_browse, r_print)values(@UserNo,@CompanyNo,@KindNo,@New,@Search, @BrowseReport, @PrintReport)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewCompany
/********************************
*介紹:辦公自動化OA系統 (添加新的公司信息)
*作者:Billy
*書寫時間:2006/05/29
*傳入:新的公司代號,公司名稱,負責人,電話,傳真,地址,備注,建立人
*返回:添加是否成功
*說明:涉及表名[company,record]
*********************************/
(
@CompanyNo varchar(10),
@ShortCode char(1),
@CompanyName varchar(60),
@Boss varchar(20)=null,
@Tel varchar(20)=null,
@Fax varchar(20)=null,
@Address varchar(80)=null,
@Note varchar(100)=null,
@CreatePerson varchar(20),
@ErrorNo nVarchar(50) out
)
as
Declare @RowCount int
--判斷公司代號是否已存在
if( Exists( Select * From Company Where Company_No = @CompanyNo ))
Begin
Set @ErrorNo = 'ExistsNo'
return 0
End
--判斷公司簡碼是否已存在
if( Exists( Select * From Company Where Company_No = @CompanyNo and short_code = @ShortCode ) )
Begin
Set @ErrorNo = 'ExistsCode'
return 0
End
insert company(company_no, short_code, company_nm, boss,tel,fax,address,note,create_person,modify_person) values
(@CompanyNo, @ShortCode, @CompanyName,@Boss,@Tel,@Fax,@Address,@Note,@CreatePerson,@CreatePerson)
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @ErrorNo = 'Failing'
return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewDepartment
/********************************
*介紹:辦公自動化OA系統 (添加新的部門信息)
*作者:bILLY
*書寫時間:2006/05/29
*傳入:新的公司代號,部門代號,部門名稱,負責人,電話,
上級部門編號,備注,建立人,操作窗口
*返回:添加是否成功
*說明:涉及表名[dept,record]
*********************************/
(
@CompanyNo varchar(10),
@DepartmentNo varchar(10),
@ChiefShortCode char(1),
@DepartmentName varchar(60),
@DepthNo varchar(10),
@IsChief char(1),
@Boss varchar(20),
@Tel varchar(20),
@ParentDepartmentNo varchar(10),
@Note varchar(100),
@CreatePerson varchar(20),
@ErrorNo varchar(50) out
)
as
Declare @RowCount int
--檢查部門代號是否被占用
if( Exists(Select * From Dept WHere Company_No = @CompanyNo And Dept_no = @DepartMentNo) )
begin
Set @ErrorNo = ''
Return 0
End
if( @IsChief != 'Y' )
Set @ChiefShortCode = ''
Else
Begin
--檢查處級代碼是否被占用
if( Ltrim(@ChiefShortCode) = '' )
Begin
Set @ErrorNo = 'NoInput'
return 0
End
If (Exists(Select * From Dept Where Company_No = @CompanyNo And Chief_Short_Code = @ChiefShortCode) )
Begin
Set @ErrorNo = 'ExistsCode'
return 0
End
End
insert dept( company_no,
dept_no,
chief_short_code,
dept_nm,
dept_level_no,
chief_flag,
boss,
tel,
parent_dept_no,
note,
create_person,
modify_person)
values(
@CompanyNo,
@DepartmentNo,
@ChiefShortCode,
@DepartmentName,
@DepthNo,
@IsChief,
@Boss,
@Tel,
@ParentDepartmentNo,
@Note,
@CreatePerson,
@CreatePerson)
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @ErrorNo = 'Failing'
Return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewDeputyInfo
/********************************
*介紹:辦公自動化OA系統 (添加新的代理資訊)
*作者:電腦混混Vincent
*書寫時間:2006/07/20
*傳入:單據NO
*返回:異常單據詳細信息
*說明:涉及表名[deputyinfo]
*********************************/
(
@UserNo varchar(20),
@DeputyUserNo varchar(20),
@StartTime smalldatetime,
@EndTime smalldatetime,
@ErrorNo varchar(50) out
)
as
declare @nSeq int
exec @nSeq=pr_GetSeqNumber 'DeputyInfo'
if exists (select Deputy from deputyInfo where ByDeputy=@DeputyUserNo and (@StartTime>=startTime and @StartTime<=endTime or @EndTime>=startTime and @EndTime<=endTime))
begin
set @ErrorNo='CanNotSet'
return 1
end
if exists (select Deputy from deputyInfo where ByDeputy=@UserNo and (@StartTime>=startTime and @StartTime<=endTime or @EndTime>=startTime and @EndTime<=endTime))
begin
set @ErrorNo='Seted'
return 1
end
insert deputyInfo values(@nSeq,@UserNo,@DeputyUserNo,@StartTime,@EndTime,getdate())
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_InsertNewErrorCode
/********************************
*介紹:辦公自動化OA系統 (添加品質異常對照檔)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[error_code,record]
*********************************/
(
@ProductNo varchar(10),
@ErrorNo varchar(10),
@ErrorName varchar(100),
@Note varchar(60),
@CreatePerson varchar(20)
)
as
insert error_code(product_no,error_no,error_nm,note,create_person,modify_person)
values(@ProductNo,@ErrorNo,@ErrorName,@Note,@CreatePerson,@CreatePerson)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewLog
/********************************
*介紹:辦公自動化OA系統 (添加新的日志項)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:操作者,操作窗口,操作類型,操作備注。
*返回:添加是否成功 0:否;1:是
*說明:涉及表名 [record]
*********************************/
(
@Operator varchar(20),
@WindowNo varchar(20),
@ActionType char(1)='6', ----1:new 2: modify 3: del 4: approve 5: print 6: browse
@Note varchar(300)=''
)
as
declare @Seq int
exec @Seq=pr_GetSeqNumber 'record'
insert record(seq,win_no,user_no,action_type,note) values
(@seq,@WindowNo,@Operator,@ActionType,@Note)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewMenuItem
/********************************
*介紹:辦公自動化OA系統 (添加新的窗口信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:窗口代號,窗口名稱,備注信息,上層窗口代號,是否可見,序號建立人,操作窗口
*返回:添加是否成功 0:否;1:是
*說明:涉及表名[menu_list,record]
*********************************/
(
@WindowNo varchar(20),
@WindowName varchar(60),
@WindowNote varchar(200)='',
@ParentWindowNo varchar(20),
@EveryOne char(1) = 'Y',
@Visible char(1)='1',
@Seq int=1 ,
@KindNo varchar(10)='',
@LargeIcon varchar(60)='Images/MenuIcon/Image01.png',
@OpenType char(1)='1',
@ProgramPath varchar(60)='',
@CreatePerson varchar(20)=''
)
as
insert menu_list(win_no,win_nm,win_note,parent_win_no,c_everyone,c_visible,seq,kind_no,large_icon,open_type,program_path,create_person,modify_person)
values(@WindowNo,@WindowName,@WindowNote,@ParentWindowNo,@EveryOne,@Visible,@Seq,@KindNo,@LargeIcon,@OpenType,@ProgramPath,@CreatePerson,@CreatePerson)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewPosition
/********************************
*介紹:辦公自動化OA系統 (添加新的職務)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[position]
*********************************/
(
@CompanyNo varchar(10),
@PositionNo varchar(10),
@PositionName varchar(30),
@Manager char(1),
@Approve char(1),
@DepthNo varchar(10),
@Note varchar(100),
@CreatePerson varchar(20)
)
as
insert position (company_no, position_no, position_name, dept_director, approve, depth_no, note, create_person, modify_person)
values (@CompanyNo,@PositionNo, @PositionName, @Manager, @Approve, @DepthNo, @Note, @CreatePerson, @CreatePerson)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_InsertNewProductKind
/********************************
*介紹:辦公自動化OA系統 (添加產品類型)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_kind,record]
*********************************/
(
@ProductNo varchar(10),
@KindName varchar(30),
@Note varchar(60),
@CreatePerson varchar(20)
)
as
insert product_kind(product_no,kind_nm,note,create_person,modify_person)
values(@ProductNo,@KindName,@Note,@CreatePerson,@CreatePerson)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_InsertNewProductStyle
/********************************
*介紹:辦公自動化OA系統 (添加新的機型檔案)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_style,record]
*********************************/
(
@ProductNo varchar(10),
@StyleNo varchar(10),
@StyleName varchar(30),
@Note varchar(60),
@CreatePerson varchar(20)
)
as
insert product_style(product_no,style_no,style_nm,note,create_person,modify_person)
values(@ProductNo,@StyleNo,@StyleName,@Note,@CreatePerson,@CreatePerson)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertNewUser
/********************************
*介紹:辦公自動化OA系統 (添加新的用戶)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶NO,密碼,用戶名稱,職位,Email,電話,公司代號,部門代號,審核等級,角色,
電子簽章,生效日期,失效日期,狀態,操作者,操作窗口
*返回:添加是否成功0:否;1:是
*說明:涉及表名[useradmin,record]
*********************************/
(
@UserNo varchar(20),
@Password varchar(32),
@UserName varchar(12),
@PositionNo varchar(10),
@Email varchar(50),
@Tel varchar(15),
@CompanyNo varchar(10),
@DepartmentNo varchar(10),
@ApproveGrade int,
@RoleLevel char(1),
@GroupNo varchar(6),
@MarkName varchar(60),
@ActiveDate datetime,
@DisableDate datetime,
@Window bit = 0,
@Status char(1) = N,
@EmailInform char(1)
)
as
declare @error int
set @error=0
if @Status != 'Y' set @Status='N'
if @RoleLevel is null set @RoleLevel=1
if( Exists(Select * From UserAdmin Where User_no = @UserNo) )
return 0
insert useradmin(
user_no,user_password,user_name,position_no,email,tel,company_no,dept_no,
approve_grade,role_level,group_no,mark_name,active_date,disable_date,window,status,
email_inform) values(
@UserNo,@Password,@UserName,@PositionNo,@Email,@Tel,@CompanyNo,
@DepartmentNo,@ApproveGrade,@RoleLevel,@GroupNo,@MarkName,
@ActiveDate,@DisableDate,@Window,@Status,@EmailInform)
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_InsertUserDiskSetting
/********************************
*介紹:辦公自動化OA系統 (新增用戶網盤設定)
*作者:william
*書寫時間:2007/05/
*說明:涉及表名[directory_setting]
*********************************/
(
@UserNo varchar(20),
@MaxSize int,
@DirectoryAmount int,
@FileAmount int
)
AS
if(not exists(select * from directory_setting where user_no=@UserNo))
insert into directory_setting (user_no,max_size,directory_amount,file_amount)values(@UserNo,@MaxSize,@DirectoryAmount,@FileAmount)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InsertUserPurview
/********************************
*介紹:辦公自動化OA系統 (添加一條權限信息)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。
*說明:涉及表名[Security]
*********************************/
(
@UserNo varchar(20),
@WinNo varchar(20),
@Browse char(1)='N',
@New char(1)='N',
@Modify char(1)='N',
@Del char(1)='N',
@Print char(1)='N',
@Approve char(1)='N',
@Visible char(1)='N'
)
as
insert into security values(@UserNo,@WinNo,@Browse,@New,@Modify,@Del,@Print,@Approve,@Visible)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_InvalidBill
/********************************
*介紹:(作廢指定的單據
*作者:電腦混混Vincent
*書寫時間:2006/06/29
*傳入:單據NO
*返回:是否成功
*說明:涉及表名[bill_m_approve]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(20)
)
as
begin transaction
update bill_m_approve set status='3' where company_no = @CompanyNo and kind_no = @kindNo and bill_no=@BillNo
if @@error<>0 goto Err
exec pr_CompleteBillProcess @CompanyNo, @KindNo, @BillNo
if @@Error <> 0 goto Err
commit transaction
return 1
Err:
rollback transaction
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Mail_Log_Insert
/****************************
* 功能:插入一條郵件發送日志
* 作者:Billy
* 日期:2006/12/13
****************************/
(
@MailFrom varchar(500),
@MailTo varchar(500),
@MailCC nvarchar(500),
@MailSubject Nvarchar(100),
@MailBody Ntext,
@SendTime datetime,
@MailPass bit,
@Note varchar(200)
)
As
Declare @InsertRow int, @Text varbinary(16), @ID int, @Seq int
Select @Seq = Max(Seq) From Send_Mail_Log
Set @Seq = IsNull(@Seq, 0) + 1
Begin Transaction
Insert Into Send_Mail_Log(Seq, Mail_From,Mail_To, Mail_CC, Mail_Subject, Mail_Pass, Mail_body, Send_Time, Note )
Values(@Seq, @MailFrom, @MailTo, @MailCC, @MailSubject, @MailPass, '',@SendTime, @Note)
--取得新記錄指針
Select @Text = TextPtr(Mail_Body) From send_mail_log Where seq = @Seq
--寫入文本
WriteText Send_Mail_Log.Mail_Body @Text @MailBody
if @@Error = 0
Begin
Commit Transaction
set @InsertRow = 1
End
else
Begin
RollBack Transaction
Set @InsertRow = 0
End
return @InsertRow
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Mail_Log_Select
/****************************
* 功能:分頁查詢郵件發送日志
* 作者:Billy
* 日期:2006/12/13
****************************/
(
@StartTime dateTime = null,
@EndTime DateTime = null,
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
As
Declare @Sql varchar(200)
Declare @Where varchar(60)
Set @Where = ' Where 1=1 '
if Ltrim(@StartTime) = ''
Set @StartTime = null
If Ltrim(@EndTime) = ''
Set @EndTime = null
Set @Sql = 'Select Seq, mail_from, mail_to, mail_cc, mail_subject, mail_pass, send_time, note From Send_Mail_Log'
If @StartTime Is Not Null
Set @Where = @Where + ' and Send_Time >= ''' + @StartTime + ''' '
If @EndTime Is Not Null
Set @Where = @Where + ' and Send_Time <= ''' + @EndTime + ''' '
Set @Sql = @Sql + @Where
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount Out, '', 'Send_Time Desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Mail_Log_Select_Single
/****************************
* 功能:查看單條郵件內容
* 作者:Billy
* 日期:2006/12/13
****************************/
(
@Seq int
)
As
Select * From Send_Mail_Log Where Seq = @Seq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Mail_SelectAssistantEmail
/*************************************************
*介紹:辦公自動化OA系統 ___取當前簽核用戶的助理Email
*作者:Billy
*書寫時間:2006/08/31
*傳入:單據NO
*說明:被訪表名[person_d_approve,assistant]
*
*************************************************/
(
@UserNo varchar(20) , ----傳入的當前簽核用戶
@AssistantMailList varchar(500) out, ----當前用戶助理郵件列表
@AssistantNames nVarchar(500) out --當前用戶助手姓名
)
as
----定義表變量,用於取郵件列表
declare @tbEmailTemp table (id int identity,UserName varchar(20), email varchar(50), PositionName varchar(30))
declare @nIndex int ----循環控制變量
declare @nCount int ----記錄總數
Select @AssistantMailList = '', @AssistantNames = ''
insert into @tbEmailTemp
select U.User_Name, U.email, P.Position_Name from useradmin U
Inner Join Position P On U.company_no = P.company_No and U.Position_No = P.Position_No
where U.email_inform = 'Y' and U.user_no in
(
select Assistant_no from assistant where Director_no = @UserNo
)
select @nCount = count(*) from @tbEmailTemp
set @nIndex = 1
set @AssistantMailList = ''
while @nIndex <= @nCount
begin
Select @AssistantMailList = @AssistantMailList + ',' + email, @AssistantNames = @AssistantNames + ', '+ UserName + PositionName
From @TbEmailTemp Where ID = @nIndex
set @nIndex = @nIndex + 1
end
----去除郵件列表中最後一個分隔符“,”
set @AssistantMailList = substring(@AssistantMailList,2,len(@AssistantMailList))
Set @AssistantNames = SubString(@AssistantNames, 2, Len(@AssistantNames))
Select @AssistantMailList, @AssistantNames
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Mail_Thread_Delete
/****************************
* 功能:刪除指定序號的郵件信息
* 作者:Billy
* 日期:2006/12/13
****************************/
(
@SeqList varchar(200) --序號列表,如1,2,3,4
)
As
Declare @Sql varchar(1000)
if @SeqList Is Null
Return
Set @SeqList = Ltrim(Rtrim(@SeqList))
if @SeqList = ''
Return
if( Substring(@SeqList, 1,1) = ',' )
Set @SeqList = SubString(@SeqList, 2, Len(@SeqList))
if( Substring(@SeqList, Len(@SeqList), 1) = ',' )
Set @SeqList = SubString(@SeqList, 1, Len(@SeqList) - 1)
Set @Sql = 'Delete Thread_SendMail Where Seq In(' + @SeqList + ')'
Exec( @Sql )
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Mail_Thread_Insert
/****************************
* 功能:插入一條郵件發送失敗的郵件
* 作者:Billy
* 日期:2006/12/13
****************************/
(
@MailFrom varchar(500),
@MailTo varchar(500),
@MailCC nvarchar(500),
@MailSubject Nvarchar(100),
@MailBody Ntext
)
As
Declare @InsertRow int, @Text varbinary(16), @Seq int
Select @Seq = Max(Seq) From Thread_SendMail
Set @Seq = IsNull(@Seq, 0) + 1
Begin Transaction
Insert Into Thread_SendMail(Seq, Mail_From,Mail_To, Mail_CC, Mail_Subject, Mail_body )
Values(@Seq, @MailFrom, @MailTo, @MailCC, @MailSubject, '')
--取得新記錄指針
Select @Text = TextPtr(Mail_Body) From Thread_SendMail Where Seq = @Seq
--寫入文本
WriteText Thread_SendMail.Mail_Body @Text @MailBody
if @@Error = 0
Begin
Commit Transaction
set @InsertRow = 1
End
else
Begin
RollBack Transaction
Set @InsertRow = 0
End
return @InsertRow
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Mail_Thread_Select
/****************************
* 功能:分頁查詢郵件發送日志
* 作者:Billy
* 日期:2006/12/13
****************************/
As
Select Top 30 * From Thread_SendMail order by join_date
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Delete
/********************************
*介紹:刪除指定的物料分類信息
*作者:Billy
*時間:2007/01/02
*傳入:
*返回:受影響行數
*說明:
*********************************/
(
@ID Nvarchar(2000)
)
AS
Declare @Rows int, @Sql nVarchar(4000)
Set @Rows = 0
Set @Sql = N'Delete Materiel_List Where ID in(' + @ID + ') Select @Rows=@@RowCount'
Exec sp_ExecuteSql @Sql, N'@Rows int out', @Rows out
Return @Rows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Save
/***********************************************************
*介紹:保存物料信息
*作者:Billy
*時間:2007/01/04
*傳入:
*返回:
************************************************************/
(
@CompanyNo varchar(10),
@TypeNo int,
@ID float, --操作的ID, 非0時為修改模式,0為新增模式
@MaterielNo varchar(20),
@Spec varchar(300),
@Unit varchar(20),
@MoneyType varchar(10),
@LastPrice decimal(16,8),
@BasePrice decimal(16,8),
@Remark varchar(50),
@OperatePerson varchar(20)
)
as
Declare @nRows smallint
Set @nRows = 0
--注意:同一公司下,不允許存在相同的料號
if( @ID <= 0 )
Begin
if( Exists(Select materiel_no From Materiel_List Where Company_No = @CompanyNo and materiel_no = @MaterielNo) )
Begin
return 0
End
--求最大的ID
Select @ID = Max([ID]) From Materiel_List
Set @ID = IsNull(@ID, 0) + 1
Insert Into materiel_List (company_No, type_no, [ID], materiel_no, spec, unit, money_type, last_price, base_price, remark, create_person)
values(@CompanyNo, @TypeNo, @ID, @MaterielNo, @Spec, @Unit, @MoneyType, @LastPrice, @BasePrice, @Remark, @OperatePerson)
set @nRows = @@RowCOunt
if @nRows > 0 Set @nRows = @ID
Return @nRows
End
--更新操作
--1. 檢查更新的信息是否存在
if(Not Exists( Select Materiel_NO From Materiel_List Where Company_No = @CompanyNo and Materiel_no = @MaterielNo and [ID] = @ID) )
return 0
--2. 檢查是否有料號沖突
if( Exists(Select materiel_no From Materiel_List Where Company_no = @CompanyNo and Materiel_No = @MaterielNo and [ID] != @ID) )
Return 0
Update Materiel_List Set Type_no = @TypeNo, spec = @Spec, unit = @Unit, money_type = @MoneyType, last_price = @LastPrice, Base_price = @BasePrice,
remark = @Remark, Modify_Person=@OperatePerson, Modify_Date = getDate()
Where Company_no = @CompanyNo and [ID] = @ID and Materiel_No = @MaterielNo
set @nRows = @@RowCOunt
if @nRows > 0 Set @nRows = @ID
Return @nRows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Select
/***********************************************************
*介紹:查詢物料信息
*作者:Billy
*時間:2007/01/04
*傳入:
*返回:
************************************************************/
(
@UserNo varchar(20),
@CompanyNo varchar(10)='',
@TypeNo int = 0, --為0時代表所有分類
@Include bit = 0, --是否包含下級分類
@MaterielNo varchar(20)='',
@MaterielSpec varchar(300) ='',
@OrderFields varchar(200) = '',
@PageIndex int=1,
@PageSize int=25,
@PageCount int=1 out
)
as
Declare @sSqlMain varchar(6000), @sWhere varchar(2000)
Declare @TypeNoList Varchar(1000)
Set @TypeNoList = @TypeNo
--初始化
set @sSqlMain='Select L.ID as Seq,T.Company_no,C.Company_Nm,T.Type_No,T.Materiel_Name,L.Materiel_No,L.Spec,L.Unit,L.Money_Type,L.Last_Price,L.Base_Price,L.Create_Date From Materiel_List L '
+ 'Inner Join Materiel_Type T On L.company_no=T.company_No and L.Type_No=T.Type_No '
+ 'Inner Join Company C On L.company_No=C.company_no '
set @sWhere='where 1=1 '
if @CompanyNo != ''
set @sWhere=@sWhere+'and L.company_no='''+@CompanyNo+''' '
if @TypeNo != 0
Begin
if( @Include = 1 ) --取得所有下屬分類代號
Begin
set @TypeNoList = dbo.fn_Materiel_GetAllChildType(@CompanyNo, @TypeNo)
End
set @sWhere=@sWhere+'and L.Type_no in(' + @TypeNoList + ') '
End
if @MaterielNo != ''
set @sWhere=@sWhere+'and L.Materiel_No like''%'+@MaterielNo+ ''' '
if @MaterielSpec != ''
set @sWhere=@sWhere+'and L.Spec like ''%' + Replace(@MaterielSpec, '''', '''''') + '%'' '
set @sSqlMain=@sSqlMain+@sWhere
Print '========================================='
print @sSqlMain
Print '========================================='
if( @OrderFields = '' )
Set @OrderFields = 'Create_date desc'
--調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSqlMain,@PageSize,@PageIndex,@PageCount=@PageCount out,@OrderFields = @OrderFields
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Type_Delete
/********************************
*介紹:刪除一條物料分類信息
*作者:Billy
*時間:2007/01/02
*傳入:
*返回:受影響行數
*說明:
*********************************/
(
@CompanyNo varchar(10),
@TypeNo int
)
AS
--檢查當前分類是否包含有下級分類或數據,如果有,則不允許刪除
if( Exists(Select * From Materiel_Type Where Company_no = @CompanyNo and Superior_Type_No = @TypeNo) or Exists(Select * From Materiel_List Where Company_No = @CompanyNo and type_no = @TypeNo) )
Begin
return 0
End
Delete Materiel_Type Where Company_no = @CompanyNo and Type_no = @TypeNo
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Type_InsertNew
/********************************
*介紹:插入一條物料分類信息
*作者:Billy
*時間:2007/01/02
*傳入:
*返回:受影響行數
*說明:
*********************************/
(
@CompanyNo varchar(10),
@SuperiorTypeNo int,
@MaterielName varchar(30),
@ReMark varchar(50)
)
AS
Declare @TypeNo int
--產生新的類型代號
Select @TypeNo = Max(type_no) From Materiel_type Where Company_No = @CompanyNo
Set @TypeNo = IsNull(@TypeNo, 0) + 1
Insert Into Materiel_Type (company_no, type_no, superior_type_no, materiel_name, remark)
values(@CompanyNo, @TypeNo, @SUperiorTypeNo, @MaterielName, @Remark)
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Type_Select
/********************************
*介紹:取得物料分類列表
*作者:Billy
*時間:2007/01/02
*傳入:公司名稱
*返回:物料分類列表
*說明:當傳入公司代號為空時,返回所有分類列表
*********************************/
(
@CompanyNo varchar(10) = ''
)
AS
if( @CompanyNo = '' )
Select * From Materiel_type
else
Select * From Materiel_Type Where Company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Type_SelectSingle
/********************************
*介紹:取得物料分類信息
*作者:Billy
*時間:2007/01/02
*傳入:公司代號,類型代號
*返回:物料分類信息
*說明:
*********************************/
(
@CompanyNo varchar(10),
@TypeNo int
)
AS
Select * From Materiel_Type Where Company_no = @CompanyNo and Type_no = @TypeNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Materiel_Type_Update
/********************************
*介紹:更新物料分類信息
*作者:Billy
*時間:2007/01/02
*傳入:公司代號,類型代號
*返回:物料分類信息
*說明:
*********************************/
(
@CompanyNo varchar(10),
@TypeNo int,
@SuperiorTypeNo int,
@MaterielName varchar(30),
@ReMark varchar(50)
)
AS
Update Materiel_Type Set superior_type_no = @SuperiorTypeNo, materiel_name = @MaterielName, remark = @Remark
Where company_No = @CompanyNo and Type_no = @TypeNo
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- =============================================
-- 名稱:pr_Message_DeleteBatchMessage
-- 功能:刪除用戶選定的多個信息
-- 編寫:Billy
-- 時間:2006/12/22
-- =============================================
CREATE PROCEDURE pr_Message_DeleteBatch
(
@InceptUserNo varchar(20),
@MessageID varchar(500),
@MessageSeq varchar(500),
@ErrorNo nVarchar(50) out
)
AS
Declare @RowCount int, @ID int
Declare @Sql nvarchar(1000)
Declare @StartIndex int, @Length int
Set @Sql = N'Select @RowCount = Count(*) From Message_Person Where Message_ID in(' + @MessageID + ') and Seq In(' + @MessageSeq + ')'
Exec sp_ExecuteSql @Sql, N'@RowCount int out', @RowCount out
if( @RowCount = 0 )
Begin
Set @ErrorNo = 'UnFound'
Return 0
End
Begin Transaction
Set @Sql = N'Delete Message_Person Where Message_ID in(' + @MessageID + ') and Seq In(' + @MessageSeq + ')'
Exec( @Sql )
If( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing!'
GoTo Roll
End
Set @Sql = N'Select @RowCount = Count(*) From Message_Person Where Message_ID in(' + @MessageID + ')'
Exec sp_ExecuteSql @Sql, N'@RowCount int out', @RowCount out
if( @RowCount = 0 ) --在Message_Person中已不存在@MessageID列表中的記錄
Begin
Set @Sql = N'Delete Message_Person Where Message_ID in(' + @MessageID + ')'
Exec( @Sql )
If( @@Error <> 0 )
begin
Set @ErrorNo = 'Failing'
goto Roll
End
End
Else --Message_Person中仍存在部分@MessageID列表中的記錄,所以只能通過循環來刪除
Begin
Set @MessageID = @MessageID + ','
Set @StartIndex = 1
Set @Length = CharIndex(',', @MessageID, @StartIndex ) - @StartIndex
While( @Length > 0 )
Begin
Set @ID = Cast(Substring(@MessageID, @StartIndex, @Length) as int)
if(Not Exists(Select * From Message_Person Where Message_ID = @ID) )
Begin
Delete Message_Content Where message_id =@MessageID
if( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing'
Goto Roll
End
End
Set @StartIndex = @StartIndex + @Length
Set @Length = CharIndex(',', @MessageID, @StartIndex) - @StartIndex
End
End
Commit Transaction
return 1
Roll:
Rollback Transaction
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- =============================================
-- 名稱:pr_Message_GetMessageInfo
-- 功能:取得某條信息的內容
-- 編寫:Billy
-- 時間:2006/12/22
-- =============================================
CREATE PROCEDURE pr_Message_GetMessageInfo
(
@UserNo varchar(20),
@MessageID int,
@MessageSeq int,
@ErrorNo nVarchar(50) out
)
AS
Declare @ReadRegin bit
If( Not Exists( Select * From Message_Person Where Incept_User_No = @UserNo And Message_ID = @MessageID And Seq = @MessageSeq)
Or Not Exists(Select * From Message_Content Where Message_ID = @MessageID) )
Begin
Set @ErrorNo = 'UnFound'
Return 0
End
Select @ReadRegin = Read_Sign From Message_Person Where Incept_User_no = @UserNo and Message_ID = @MessageID and Seq = @MessageSeq
if( @ReadRegin = 0 )
Begin
Update Message_Person Set Read_Sign = 1 Where Incept_User_no = @UserNo and Message_ID = @MessageID and Seq = @MessageSeq
End
Select M.Emphasis, M.Send_User_No, M.Subject, M.content, M.Send_Date,
Case M.Send_User_No When '10000' Then 'Admin' Else U.User_Name End + '[' + M.Send_User_no + ']' SendPerson,
P.Seq, P.Message_ID, P.Read_Sign, P.Read_Date From Message_Person P
Inner Join Message_Content M On P.Message_ID = M.Message_ID
Left Join UserAdmin U On M.Send_User_no = U.User_no
Where P.Incept_User_no = @UserNo and P.Message_ID = @MessageID and Seq = @MessageSeq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- =============================================
-- 名稱:pr_Message_SelectFromPage
-- 功能:取某用戶的信息列表(分頁)
-- 編寫:Billy
-- 時間:2006/12/22
-- =============================================
CREATE PROCEDURE pr_Message_SelectFromPage
(
@UserNo varchar(20),
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
AS
Declare @Sql Nvarchar(4000)
Set @Sql = N'Select M.Emphasis, M.Send_User_No, M.Subject, M.Send_Date, '
+ ' Case M.Send_User_No When ''10000'' Then ''Admin'' Else U.User_Name End + ''['' + M.Send_User_no + '']'' UserName,'
+ ' P.Seq, P.Message_ID, P.Read_Sign, P.Read_Date From Message_Person P'
+ ' Inner Join Message_Content M On P.Message_ID = M.Message_ID'
+ ' Left Join UserAdmin U On M.Send_User_no = U.User_no'
+ ' Where P.Incept_User_no = ''' + @UserNo + ''''
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', 'Read_Sign, Send_Date Desc '
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-- =============================================
-- 名稱:pr_Message_DeleteBatchMessage
-- 功能:刪除用戶選定的多個信息
-- 編寫:Billy
-- 時間:2006/12/22
-- =============================================
CREATE PROCEDURE pr_Message_Send
(
@SendUserNo varchar(20),
@InceptUserNo varchar(20),
@Subject nvarchar(50),
@Content nvarchar(500),
@Emphasis bit = 0,
@UserType bit, --0:依帳號, 1:依姓名 (注意:依姓名時,可以存在多個姓名相同的接收者)
@ErrorNo nVarchar(50) out
)
AS
Declare @MessageID int
Begin Transaction
--發送
Insert into Message_Content(Send_User_no, Subject, content, send_date, emphasis)
values(@SendUserNo, @Subject, @Content, GetDate(), @Emphasis)
If( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing'
Goto Roll
End
Set @MessageID = @@IDentity
if( @UserType = 0 )
Begin
If( Not Exists(Select * From Useradmin Where User_no = @InceptUserNo ) )
Begin
Set @ErrorNo = 'UnFound'
Goto Roll
End
Insert into Message_Person(Message_ID, Incept_User_no, Read_Sign, Read_date)
Values(@MessageID, @InceptUserNo, 0, getDate())
If( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing'
Goto Roll
End
End
Else
Begin
If( Not Exists(Select * From Useradmin Where User_name = @InceptUserNo ) )
Begin
Set @ErrorNo = 'UnFound'
Goto Roll
End
Insert into Message_Person Select @MessageID, User_No, 0, getDate() From UserAdmin Where User_name = @InceptUserNo
If( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing'
Goto Roll
End
End
Commit Transaction
return 1
Roll:
Rollback Transaction
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*****************************************************************/
-- * 名 稱:pr_News_CheckDate
-- * 功能簡介:檢測日期字符串
-- * 說明:
--@sFactDate char(10) = ‘’ Output 要檢測的日期字符串,可返回
-- * 返回值:合法的日期型字符串
-- * 注意事項:
-- * 創日期:2005-09-23
-- * 創建人::Sunny_Li
-- * 修改日期:
-- * 修改人:
/*****************************************************************/
CREATE PROCEDURE pr_News_CheckDate @sFactDate VarChar(10) ='' Output
AS
Begin
Select @sFactDate = Rtrim(@sFactDate)
If (Rtrim(@sFactDate)='') Return --如果值為空,直接返回
If (ISDATE(@sFactDate)=1) Return--如果日期是有效的,產生日期條件
If (ISDATE(Rtrim(@sFactDate) + '-01')=1) Return--數據為格式yyyy-mm
Select @sFactDate=''
Return
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*****************************************************************/
-- * 名 稱:pr_News_CreateDataWhere
-- * 功能簡介:產生日期型查詢條件
-- * 說明明:
--@sReturnWhere Char(200) = ‘’ Output 可返回的日期查詢條件語句
--@sBeginDate char(10) = ‘’ 開始日期
--@sEndDate char(10) = ‘’ 截止日期
-- * 返回值:產生日期型查詢條件
-- * 注意事項:
-- * 創建日期:2005-12-23
-- * 創建人::Sunny_Li
-- * 修改日期:
-- * 修改人:
/*****************************************************************/
CREATE PROCEDURE pr_News_CreateDataWhere @sReturnWhere VarChar(200)='' Output, @sBeginDate VarChar(10)='', @sEndDate VarChar(10)=''
AS
Declare @sSql varChar(4000)
Begin
Select @sReturnWhere = ''
Exec pr_News_CheckDate @sBeginDate Output
Exec pr_News_CheckDate @sEndDate Output
If (Rtrim(@sBeginDate) = '' AND Rtrim(@sEndDate) = '') Return
If (Rtrim(@sBeginDate) = '' and Rtrim(@sEndDate) <> '')--無開始日期
begin
Select @sReturnWhere = '<'+'CONVERT(DATETIME, ''' + Rtrim(@sEndDate) + ' 23:23:59.999'', 120) ' Return
end
If (Rtrim(@sBeginDate) <> '' and Rtrim(@sEndDate) = '') --無結束日期
begin
Select @sReturnWhere = ' >'+ 'CONVERT(DATETIME, ''' + Rtrim(@sBeginDate) + ' 00:00:00'', 120) ' Return
end
If (Rtrim(@sBeginDate) <> '' and Rtrim(@sEndDate) <> '')
Select @sReturnWhere = ' BETWEEN CONVERT(DATETIME, ''' + Rtrim(@sBeginDate) + ' 00:00:00'', 120) AND CONVERT(DATETIME, ''' + Rtrim(@sEndDate) + ' 23:23:59.999'', 120)'
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_DeleteType
/********************************
*介紹: 刪除新聞類別信息
*作者:Tim
*書寫時間:2007/05/25
*參數: @分類主鍵
*說明:表:news_type
*********************************/
(
@type_id int
)
as
begin
delete news_type where type_id=@type_id
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_SearchNews
/********************************
*介紹:查詢新聞類別信息
*作者:Tim
*書寫時間:2007/05/25
*參數: @分類主鍵
*說明:表:news_list
*********************************/
(
@company_no varchar(10),
@type_id varChar(10),
@title varchar(30),
@DateBegin varchar(10),
@DateEnd varchar(10),
@hotspot varChar(1),
@recommend varChar(1),
@big_news varChar(1),
@contribute varChar(1),
@user varchar(30),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Declare @sDateWhere varChar(200)
begin
--判斷條件
If (@company_no = Null) Select @company_no=''
If (@type_id = Null) Select @type_id=''
If (@title = Null) Select @title=''
If (@DateBegin = Null) Select @DateBegin=''
If (@DateEnd = Null) Select @DateEnd=''
If (@user = Null) Select @user=''
If (@hotspot = Null) Select @hotspot=''
If (@recommend = Null) Select @recommend=''
If (@big_news = Null) Select @big_news=''
If (@contribute = Null) Select @contribute=''
--產生條件
Select @sWhere = 'Where 1=1 '
--產生日期條件
if(@DateBegin<>'' and @DateEnd<>'')
begin
Exec pr_News_CreateDataWhere @sDateWhere Output, @DateBegin, @DateEnd--調用存儲過程產生日期條件
If (Rtrim(@sDateWhere)<>'') Select @sWhere = @sWhere + ' AND (N.issue_date '+ Rtrim(@sDateWhere) +')'
end
If (Rtrim(@company_no) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.company_no =''' + @company_no + ''' ) '
If (Rtrim(@type_id) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.type_id = ' + @type_id + ' ) '
If (Rtrim(@title) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.title like ''%' + @title + '%'' ) '
If (Rtrim(@hotspot) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.hotspot = ' + @hotspot + ' ) '
If (Rtrim(@recommend) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.recommend = ' + @recommend + ' ) '
If (Rtrim(@contribute) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.contribute = ' + @contribute + ' ) '
If (Rtrim(@big_news) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.big_news = ' + @big_news + ' ) '
If (Rtrim(@user) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.user_no like ''%' + @user + '%'' or U.user_name like ''%'+@user+'%'' ) '
select @sSql='select N.*,U.user_name '
+' From news_list N '
+' Left Join useradmin U on N.user_no = U.user_no '
+ RTRIM(@sWhere)
select @sOrderBy=' issue_date desc '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_SelectContribute
/********************************
*介紹:查詢新聞類別信息
*作者:Tim
*書寫時間:2007/05/25
*參數: @分類主鍵
*說明:表:Contribute
*********************************/
(
@contribute_id varChar(10),
@company_no varchar(10),
@title varchar(30),
@user_no varchar(20),
@user varchar(30),
@status varchar(1),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
Declare @sDateWhere varChar(200)
begin
--判斷條件
If (@company_no = Null) Select @company_no=''
If (@contribute_id = Null) Select @contribute_id=''
If (@title = Null) Select @title=''
If (@user_no = Null) Select @user_no=''
If (@user = Null) Select @user=''
If (@status = Null) Select @status=''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@company_no) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (U.company_no =''' + @company_no + ''' ) '
If (Rtrim(@contribute_id) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.contribute_id = ' + @contribute_id + ' ) '
If (Rtrim(@title) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.title like ''%' + @title + '%'' ) '
If (Rtrim(@status) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.status = ' + @status + ' ) '
If (Rtrim(@user_no) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.user_no = ' + @user_no + ' ) '
If (Rtrim(@user) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.user_no like ''%' + @user + '%'' or U.user_name like ''%'+@user+'%'' ) '
select @sSql='select N.*,U.user_name '
+' From contribute N '
+' Left Join useradmin U on N.user_no = U.user_no '
+ RTRIM(@sWhere)
select @sOrderBy=' create_date '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_SelectMaxID
/********************************
*介紹: 查找最大ID
*作者:Tim
*書寫時間:2007/05/25
*參數:
*說明:表:@table查找表, @seq查找字段
*********************************/
(
@table varchar(20),
@seq varchar(20)
)
as
declare @sSql Nvarchar(1000)
begin
set @sSql='Select IsNull(Max('+@seq+'), 0) + 1 From '+@table
Execute sp_executesql @sSql
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_SelectNewsInfo
/********************************
*介紹: 查找指定新聞信息
*作者:Tim
*書寫時間:2007/05/25
*參數: @新聞主鍵
*說明:表:news_list
*********************************/
(
@news_id int
)
as
begin
select news_list.*,useradmin.user_name from news_list join useradmin on news_list.user_no=useradmin.user_no where news_list.news_id=@news_id
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_SelectType
/********************************
*介紹:查詢新聞類別信息
*作者:Tim
*書寫時間:2007/05/25
*參數: @分類主鍵
*說明:表:news_type
*********************************/
(
@company_no varchar(10),
@type_id varChar(10),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
Declare @sSql NvarChar(4000)
Declare @sWhere NvarChar(1000)
Declare @sOrderBy NvarChar(1000)
begin
--判斷條件
If (@company_no = Null) Select @company_no=''
If (@type_id = Null) Select @type_id=''
--產生條件
Select @sWhere = 'Where 1=1 '
If (Rtrim(@company_no) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.company_no =''' + @company_no + ''' ) '
If (Rtrim(@type_id) <> '') Select @sWhere = Rtrim(@sWhere) + ' AND (N.type_id = ' + @type_id + ' ) '
select @sSql='select N.*,C.company_nm '
+' From news_type N '
+' Left Join Company C on N.Company_no = C.Company_no '
+ RTRIM(@sWhere)
select @sOrderBy=' type_id '
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields=@sOrderBy
set @sSql = 'select count(*) RecordCount from ('+rtrim(@sSql)+') B'
Execute sp_executesql @sSql
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_News_UpdateType
/********************************
*介紹: 更新新聞類別信息
*作者:Tim
*書寫時間:2007/05/25
*參數: @分類主鍵
*說明:表:news_type
*********************************/
(
@company_no varchar(10),
@type_id int,
@type_name varchar(20)
)
as
begin
DECLARE @Seq INT
if(@type_id=0)
begin
Select @Seq = Max(type_id) From news_type
Set @Seq = IsNull(@Seq, 0) + 1
insert into news_type values(@Seq,@company_no,@type_name)
end
else
begin
update news_type set company_no=@company_no,type_name=@type_name where type_id=@type_id
end
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_PassedApproveOperate
/*************************************************
*介紹: 審核單據操作:通過簽核指定的單據
*作者: Billy
*時間: 2006/08/21
*傳入: 單據NO,用戶NO,拒簽到用戶,操作時間
*說明: 被訪表名[bill_m_approve,person_d_approve,person_approve_file]
*
*************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30), --單據編號
@ApproveSeq int,
@ActualUserNo varchar(20), --實際操作用戶的代號
@Note varchar(6000) = '', --簽核指示
@HasComplete char(1) = 'N', --是否結案單據
@MarkName varchar(60)=null, --電子簽章
@ToNextDepartMent bit = 0, --是否完成本單位簽核直接送至下一單位處理
@NextApproveSeq int out --傳出下一位簽用戶對應的ApproveSeq
)
as
if @BillNo is null or @ActualUserNo is null
return 0
declare @cBillStatus char(1) --記錄當前操作的單據的狀態(1:新單 4:處理中)
declare @nUserCount int --用戶總數(包括不具有簽核動作的用戶)
Declare @LastApproveSeq int --最後的簽核順序
declare @CurrentChiefNo varchar(20), @NextChiefNo varchar(20)
declare @ID int, @TempNextApproveSeq int
Declare @OperateTime datetime
Declare @ApproveSign char(1)
--初始化變量
set @OperateTime = getdate()
set @CurrentChiefNo = ''
Set @NextChiefNo = ''
set @NextApproveSeq = @ApproveSeq
Set @TempNextApproveSeq = -1
set @ID = 1
set @LastApproveSeq = @ApproveSeq
Set @ApproveSign = '3' --默認情況下為已核准
--開啟數據庫事務
Begin Transaction
If @HasComplete = 'Y'
GoTo EndCase --轉到結案處理部分
--將當前單據的所有簽核用戶信息放入臨時表(不包過通知的用戶)
Select id =identity(int, 1,1), chief_no, M.User_no, M.ApproveSeq
into #tbApproveList From Person_D_Approve M
Inner Join Action_Kind A On M.action_seq = A.action_Seq
Where M.Company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo and A.Approve = 'Y'
Order by M.ApproveSeq
Select @nUserCount = Count(*) From #tbApproveList
--取得最後一位簽核用戶的序號
Select @LastApproveSeq = Max(ApproveSeq) From #tbApproveList
If @ApproveSeq = @LastApproveSeq --是否已為最後簽核的用戶
Begin
Set @HasComplete = 'Y'
Goto EndCase
End
If @ToNextDepartMent = 0 --按順序簽,直接取當前用戶的下一簽核用戶的序號ApproveSeq
Select @NextApproveSeq = Min(ApproveSeq) From #tbApproveList Where ApproveSeq >@ApproveSeq
Else --送簽至下一單位
Begin
--取得當前用戶所在的處級部門代號
Select @CurrentChiefNo = Chief_No From #tbApproveList Where ApproveSeq = @ApproveSeq
--檢查當前用戶是否處於最後一個單位,如果是則直接通知進行結案
if Not Exists(Select * From #tbApproveList Where Chief_no != @CurrentChiefNo And ApproveSeq >@ApproveSeq)
Begin
Set @HasComplete = 'Y'
Goto EndCase
End
--取得下一簽核用戶(下一單位的第一位簽核用戶)的簽核序號(ApproveSeq)
Select @NextApproveSeq = Min(ApproveSeq) From #tbApproveList Where Chief_no != @CurrentChiefNo And ApproveSeq >@ApproveSeq
If @NextApproveSeq > @ApproveSeq + 1
Begin
--更新中間被略過的簽核用戶的簽核標記為5
Update Person_d_Approve Set Approve_Sign = '5'
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_no = @BillNo
And ApproveSeq In(Select ApproveSeq From #tbApproveList Where ApproveSeq > @ApproveSeq And ApproveSeq < @NextApproveSeq)
if @@error <> 0 goto Err
End
End
--更新本人標記為已簽核
Set @ApproveSign = '3'
Update Person_d_Approve
set approve_Sign = @ApproveSign, note = @Note, mark_name = @MarkName, approve_date = @OperateTime, actual_user_no = @ActualUserNo
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_no = @BillNo And ApproveSeq = @ApproveSeq
if @@error <> 0 goto Err
--更新單據狀態為簽核中
Update bill_m_approve Set Status = '4', Current_ApproveSeq = @NextApproveSeq, previous_approve_time = @OperateTime
where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@error <> 0 goto Err
--記錄日志
Exec pr_InsertNewBillApproveLog @CompanyNo, @KindNo, @BillNo, @ActualUserNo, '1', @ApproveSeq, @Note
if @@error <> 0 goto Err
GoTo Submit
--結案操作
EndCase:
Set @ApproveSign = '4' --已結案
Update Person_d_Approve
set approve_Sign = @ApproveSign, note = @Note, mark_name = @MarkName, approve_date = @OperateTime, actual_user_no = @ActualUserNo
Where Company_no = @CompanyNo And Kind_no = @KindNo And Bill_no = @BillNo And ApproveSeq = @ApproveSeq
if @@error <> 0 goto Err
--更新單據狀態為結案
Update bill_m_approve Set Status = '2', previous_approve_time = @OperateTime, Complete_Date = @OperateTime
where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@error <> 0 goto Err
--移動單據日志至結案表中
Insert into bill_approved_log Select * From bill_approve_log Where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@Error <> 0 goto Err
Delete From bill_approve_log Where company_no = @CompanyNo and kind_no = @KindNo and Bill_no = @BillNo
if @@Error <> 0 goto Err
--將單據相關記錄 [ 剪切 ] 到 已結案檔 包括(主檔,審核人員檔,審核附件檔,單據附件檔)
exec pr_CompleteBillProcess @CompanyNo, @KindNo, @BillNo
if @@error <> 0 goto Err
GoTo Submit
Submit:
commit transaction
return 1
Err:
rollback transaction
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_RejectApproveOperate
/*************************************************
*介紹:辦公自動化OA系統 ___審核單據操作:拒絕簽核指定的單據
*作者:電腦混混Vincent
*書寫時間:2006/08/21
*傳入:單據NO,用戶NO,拒簽到用戶,操作時間
*說明: 被訪表名[bill_m_approve,person_d_approve,person_approve_file]
更新表名[]
*
*************************************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30), --單據編號
@ActualUserNo varchar(20), --實際操作用戶的代號
@Note varchar(6000), --簽核指示
@RejectSequence int --(總小於實際簽核位置,實際簽核位置為1時,拒簽到位置為0,作廢單據)
)
as
declare @CurrentSequence int --記錄單據當前簽核用戶的簽核順序(ApproveSeq)
declare @OperateTime datetime
if @BillNo is null or @ActualUserNo is null
return 0
--取當前簽核用戶對應的ApproveSeq
Select @CurrentSequence = Current_ApproveSeq From Bill_M_Approve Where company_no = @CompanyNo and Kind_No = @KindNo and Bill_no = @BillNo
set @OperateTime = getdate()
--開始事務
begin transaction
--更新本人的簽核信息
update person_d_approve
set approve_sign = '2', note = @Note, actual_user_no = @ActualUserNo, approve_date = @OperateTime
where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo and approveSeq = @CurrentSequence
if @@error <> 0 goto exception
--第一位簽核用戶退單
if @RejectSequence = 0
begin
update bill_m_approve set status = '3' where company_no = @CompanyNo and kind_no = @KindNo and bill_no = @BillNo
if @@error <> 0 goto exception
--將單據相關記錄 [ 剪切 ] 到 已結案檔 包括(主檔,審核人員檔,審核附件檔,單據附件檔)
exec pr_CompleteBillProcess @CompanyNo, @KindNo, @BillNo
if @@error <> 0 goto exception
goto endOperation
end
--更新Bill_M_Approve中用戶標記(Previous_Approve_Time
if( Exists(Select * From Person_d_Approve Where company_no = @CompanyNo and kind_no = @KindNo and Bill_No = @BillNo and ApproveSeq = @RejectSequence ) )
Begin
Update BilL_M_Approve Set Current_ApproveSeq = @RejectSequence, Previous_Approve_Time = @OperateTime
Where company_no = @CompanyNo and kind_no = @KindNo and Bill_No = @BillNo
if( @@Error <> 0) goto Exception
End
endOperation:
commit transaction
return 0
exception:
rollback transaction
return 1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SaveBillValidateOperation
/********************************
*介紹:辦公自動化OA系統____對單據進行效果確認
*作者:電腦混混Vincent
*書寫時間:2006/10/11
*傳入:用戶NO
*說明:涉及表名[bill_approved_agree,person_d_approve,person_approve_file]
*********************************/
(
@UserNo varchar(10),
@BillNo varchar(30),
@OperateTime datetime ,
@Content varchar(500),
@Result char(1) ---- 'Y':通過 'N':不通過
)
as
------考慮代理
set @Result = case @Result when 'Y' then '3' else '2' end
update bill_approve_validate
set actual_user_no = @UserNo,validate_date = @OperateTime, note = @Content, validate = @Result
where bill_no = @BillNo
----檢查當前單據是否完成效果確認
if Exists(select 1 from bill_approve_validate where bill_no = @BillNo and validate != '3') ----未完成
return
----單據效果確認完成
----寫入單據確認完成標記
update bill_m_approved set effect_validate_pass = 'Y' where bill_no = @BillNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_SaveGroupItem
/***********************************************************
*介紹:辦公自動化OA系統 ˍˍˍ保存組項信息
*作者:電腦混混Vincent
*書寫時間:2006/09/09
*傳入:組項NO (程序中自動生成),組項類別,組項名稱,組項深度
*返回:
*說明:涉及表名[ dept_depth,dept / position_depth,position ]
*@GroupType: 1 DepartmentGroup
2 PositionGroup
*@Operate : 1 Insert
2 Update
3 Delete
*更新:組項名稱
*插入:組項名稱,深度
************************************************************/
(
@ItemNo varchar(10),
@CompanyNo varchar(10),
@GroupType char(1) ,
@ItemName varchar(30),
@Depth int,----深度值
@Operate char(1)----執行操作
)
as
----判斷傳入參數正確性
if len(@ItemNo) < 1
return 1
if len(@ItemName) < 1
return 1
if @Depth < -1
return 1
----開始事務處理
begin transaction
if @GroupType = '1'
begin
if @Operate = '1'
----添加部門組
begin
----插入新組項 select * From dept_depth
insert dept_depth(dept_level_no, company_no, dept_level_name, dept_depth)
values (@ItemNo,@CompanyNo,@ItemName,@Depth)
if @@error <> 0
begin
print '加入新組項ERROR'
goto exception
end
end
else if @Operate = '2'
----更新部門組
begin
----更新深度
update dept_depth set dept_depth = @Depth ,
dept_level_name = @ItemName
where dept_level_no = @ItemNo
if @@error <> 0
begin
print '部門組深度源後組項更新ERROR'
goto exception
end
end
else
----刪除部門組
begin
delete dept_depth where dept_level_no = @ItemNo
if @@error <> 0
begin
print '刪除部門組項ERROR'
goto exception
end
end
end
else if @GroupType = '2'
begin
if @Operate = '1'
----添加職位組
begin
----插入新組項select * From position_depth
insert position_depth (depth_no, company_no, depth_name, depth)
values (@ItemNo,@CompanyNo,@ItemName,@Depth)
if @@error <> 0
begin
print '加入新組項ERROR'
goto exception
end
end
else if @Operate = '2'
----更新職位組
begin
----更新深度
update position_depth set depth = @Depth ,
depth_name = @ItemName
where depth_no = @ItemNo
if @@error <> 0
begin
print '職位組深度源後組項更新ERROR'
goto exception
end
end
else
----刪除職位組
begin
delete position_depth where depth_no = @ItemNo
if @@error <> 0
begin
print '刪除職位組項ERROR'
goto exception
end
end
end
commit transaction
return 0
exception:
rollback transaction
return 1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SearchBillListForLogs
/********************************
*介紹:辦公自動化OA系統 (為單據簽核日志查詢單據列表)
*作者:Billy
*書寫時間:2006/08/31
*參數:@Company, @BillKind, @BillNo
*說明:使用表:Assistant
*修改公司編號錯誤
*********************************/
(
@Company varchar(60) = '',
@BillKind varchar(60) = '',
@BillNo varchar(30) ='',
@UserNo varchar(20) = '',
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
as
Declare @Sql varchar(8000)
Set @Sql = 'Select B.kind_no, K.kind_nm, B.Bill_no, dbo.fn_Bill_ConvertStatus(B.status) Status , dbo.fn_ConvertExigencyGrade(B.exigency_grade) Exigency_Grade, '
+' U.User_Name, B.Create_Person, B.Create_Date'
+' From ( Select * From Bill_m_Approve union Select * From Bill_M_Approved) B'
+' Inner Join UserAdmin U On B.Create_Person = U.User_no'
+' inner Join Bill_Kind K On B.company_no=K.company_No and B.Kind_No = K.Kind_no'
+' Where 1 = 1'
if @Company !=''
Set @Sql = @Sql + ' And (B.Company_no Like ''%' + @Company + '%'' Or K.Company_nm Like ''%' + @Company + '%'')'
if @BillKind !=''
Set @Sql = @Sql + ' And ( B.Kind_no Like ''%' + @BillKind + '%'' Or B.Kind_no Like ''%' + @BillKind + '%'')'
if @BillNo != ''
set @Sql = @Sql + ' And B.Bill_no Like ''%' + @BillNo + '%'''
if @UserNo != ''
Set @Sql = @Sql + ' And (U.User_no Like ''%' + @UserNO + '%'' Or U.User_name Like ''%' + @UserNo + '%'')'
Print @Sql
Exec Pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount Out
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectActionKindFromUserNo
/********************************
*介紹:辦公自動化OA系統 (取簽核動作列表)
*作者:Billy
*書寫時間:2006/08/21
*參數:@UserNo --用戶代號
*說明:
*********************************/
(
@UserNo varchar(20)
)
as
Declare @CompanyNo varchar(10)
set @CompanyNo = ''
Select @CompanyNo = company_no From UserAdmin Where user_no = @UserNo
select a.*,C.company_nm From action_kind A inner join company C on C.company_no=A.company_no where A.company_no=@CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectApproveLogFromBillNo
/********************************
*介紹:辦公自動化OA系統 (根據單據編號查義單據簽核日志)
*作者:Billy
*書寫時間:2006/08/31
*參數:@BillNo
*說明:使用表:bill_Approve_Log, person_d_Approve, userAdmin, positon
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
if Exists( Select * From Bill_Approve_Log Where company_no = @CompanyNo and kind_no = @KindNo And Bill_no = @BillNo )
Begin
Select Main.*, A.action_nm , P.Position_name From
(
Select M.user_no, M.bill_no, M.approve_seq, case M.operate_result when '1' then 'Pass' when '2' then 'Reject' else '' End As Operater_Result,
M.Note, M.Approve_Date, U.User_Name, U.Position_No, dbo.fn_DepartmentFrame(U.company_no,U.dept_no) DepartMent, D.action_Seq
From bill_approve_log M
Inner Join UserAdmin U On M.user_no = U.User_no
Left outer Join Person_D_Approve D On M.bill_no = D.Bill_no And M.Approve_Seq = D.ApproveSeq
Where M.company_no = @CompanyNo and M.kind_no = @KindNo And M.bill_no = @BillNo
) Main
Inner Join Position P On Main.position_no = P.Position_no
Inner Join Action_Kind A On Main.Action_Seq = A.Action_Seq
Order by Main.Approve_Date ASC
End
Else
Begin
Select Main.*, A.action_nm , P.Position_name From
(
Select M.user_no, M.bill_no, M.approve_seq, case M.operate_result when '1' then 'Pass' when '2' then 'Reject' else '' End As Operater_Result,
M.Note, M.Approve_Date, U.User_Name, U.Position_No, OA.dbo.fn_DepartmentFrame(U.company_no,U.dept_no) DepartMent, D.action_Seq
From bill_approved_log M
Inner Join UserAdmin U On M.user_no = U.User_no
Left outer Join Person_D_Approved D On M.bill_no = D.Bill_no And M.Approve_Seq = D.ApproveSeq
Where M.company_no = @CompanyNo and M.kind_no = @KindNo And M.bill_no = @BillNo
) Main
Inner Join Position P On Main.position_no = P.Position_no
Inner Join Action_Kind A On Main.Action_Seq = A.Action_Seq
Order by Main.Approve_Date ASC
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectApprovePerson
/********************************
*介紹:根據序號及單據編號查詢審核人員信息
*作者:Billy
*書寫時間:2006/08/24
*參數:@ApproveSeq 審核順序 @BillNo:單據編號
*說明:表:Person_d_Approve, UserAdmin, Dept, Action_Kind, Position
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo Varchar(30),
@ApproveSeq int = -1 --當前簽核用戶所在的位置,-1時返回所有簽核用戶,非-1時返回其相連的同單位的簽核人員
)
as
Select [ID] = identity(int,1,1),P.* , U.User_name, OA.dbo.fn_DepartmentFrame(U.company_no, U.Dept_no) DepartMent, U.Position_no, A.action_Nm,PT.position_name Into #tbApprovePerson
From Person_d_Approve P
Inner Join UserAdmin U On P.user_no = U.user_no
Inner Join Action_Kind A On P.action_seq = A.action_seq
left outer join position PT on U.company_no = PT.company_no and U.position_no = PT.Position_no
Where P.Company_no = @CompanyNo and P.Kind_no = @KindNo and P.Bill_no = @BillNo
Order By P.ApproveSeq
if @ApproveSeq = -1
Begin
Select * From #tbApprovePerson
Return 1
End
If Not Exists(Select User_no From #tbApprovePerson Where ApproveSeq = @ApproveSeq)
Begin
Select * From #tbApprovePerson Where 1 > 2
End
Declare @ChiefNo varchar(10)
Declare @TempChiefNo varchar(10)
Declare @TempApproveSeq int
Select @ChiefNo = Chief_no From #tbApprovePerson Where ApproveSeq = @ApproveSeq
Delete #tbApprovePerson Where ApproveSeq <= @ApproveSeq
Select @TempApproveSeq = Min(ApproveSeq) From #tbApprovePerson Where Chief_no != @ChiefNo
If @TempApproveSeq is Not Null
Begin
Delete #tbApprovePerson Where ApproveSeq >= @TempApproveSeq
End
Select * from #tbApprovePerson
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectApprovedBillList
/***********************************************************
*介紹:查詢已簽單據列表
*作者:Billy
*書寫時間:2006/08/07
*傳入:用戶代號,單據代號,類型代號(類型),審核動作,緊急程度,查詢類型
*查詢類型 : 1 : 實際簽核列表 ; 實簽人員 = 預設人員 and 實際人員 = 登陸用戶
2 : 代理簽核列表 ; 實際人員 != 預設人員 and 實際人員 = 登陸用戶
3 : 代理人簽核列表 ; 實際人員 != 預設人員 and 預設人員 = 登陸用戶
4 : 拒簽列表 ; 簽核標記 = 2 (簽) and (預設人員 = 登陸用戶 or 實際人員 = 登陸用戶)
*返回:查得已簽單據列表
*Execute eg : execute pr_SelectApprovedBillList 'Vincent','1','ETC--','','',3
*說明:涉及表名[bill_m_approve,bill_m_approved,person_d_approve,person_d_approved]
************************************************************/
(
@UserNo varchar(20),
@SearchType char(1) = '1',
@CompanyNo varchar(10) = '',
@KindNo varchar(10) = '',
@BillNo varchar(30) = '',
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sSql varchar(8000)
declare @sWhere varchar(800)
declare @SearchWhere varchar(300)
if @UserNo is null return 0
if( @SearchType != '1' And @SearchType != '2' And @SearchType != '3' And @SearchType != '4' )
Set @SearchType = '1'
/*
set @sSql='select distinct M.bill_no,M.action_seq,'+
'M.company_no,'+
'C.company_nm,'+
'M.kind_no,'+
'K.kind_nm,'+
'A.action_nm,'+
'M.status,'+
'M.exigency,'+
'M.user_no,'+
'U.user_name,'+
'M.actual_user_no,'+
'U.user_name as actual_user_name,'+
'M.approve_Sign,'+
'M.create_date '+
'from ('+
'select Pa.company_no,'+
'Pa.kind_no,'+
'Pa.bill_no,'+
'Pa.action_seq,'+
'Pa.user_no,'+
'Pa.actual_user_no,'+
'Pa.approve_sign,'+
'dbo.fn_Bill_ConvertStatus(status) status ,'+
'exigency_grade as exigency,'+
'create_date '+
'from person_d_approve Pa '+
' inner join bill_m_approve Ba on Pa.company_no=Ba.company_no and Pa.kind_No=Ba.kind_no and Pa.bill_no = Ba.bill_no '+
'where approve_sign!=1 '+
'union '+
'select Pa.company_no,'+
'Pa.kind_no,'+
'Pa.bill_no,'+
'Pa.action_seq,'+
'Pa.user_no,'+
'Pa.actual_user_no,'+
'Pa.approve_sign,'+
'dbo.fn_Bill_ConvertStatus(status) status ,'+
'exigency_grade as exigency,'+
'create_date '+
'from person_d_approved Pa '+
' inner join bill_m_approved Ba on Pa.company_no=Ba.company_no and Pa.kind_No=Ba.kind_no and Pa.bill_no = Ba.bill_no '+
'where approve_Sign!=1'+
' ) M '+
' inner join company C on M.company_no = C.company_no '+
' left join bill_kind K on M.Company_No=K.Company_No and M.kind_no = K.kind_no '+
' left join action_kind A on M.company_No=A.company_no and M.action_seq = A.action_seq '+
' left join useradmin U on M.actual_user_no = U.user_no '+
' where A.approve = ''Y'' '
*/
set @sSql='select distinct M.company_no,M.kind_no,M.bill_no,C.company_nm,'+
'K.kind_nm,A.action_nm,M.status,M.exigency,M.user_No,M.actual_user_no,'+
'M.approve_Sign,M.create_date from ('+
'select P.company_no,P.kind_no,P.bill_no,P.action_seq,P.user_no,P.actual_user_no,'+
'P.approve_sign,dbo.fn_Bill_ConvertStatus(status) status,exigency_grade as exigency,create_date '+
'from person_d_approve P '+
' inner join bill_m_approve B on P.company_no=B.company_no and P.kind_No=B.kind_no and P.bill_no = B.bill_no '+
'where approve_sign!=1 '+
'union select P.company_no,P.kind_no,P.bill_no,P.action_seq,P.user_no,P.actual_user_no,'+
'P.approve_sign,dbo.fn_Bill_ConvertStatus(status) status,exigency_grade as exigency,create_date '+
'from person_d_approved P '+
' inner join bill_m_approved B on P.company_no=B.company_no and P.kind_No=B.kind_no and P.bill_no = B.bill_no '+
'where approve_Sign!=1'+
' ) M '+
' inner join company C on M.company_no = C.company_no '+
' left join bill_kind K on M.Company_No=K.Company_No and M.kind_no = K.kind_no '+
' left join action_kind A on M.company_No=A.company_no and M.action_seq = A.action_seq '+
' where A.approve = ''Y'' '
set @sWhere = ''
Set @SearchWhere = ''
----合併查詢條件
if @CompanyNo != ''
set @sWhere = @sWhere + 'and M.Company_no = ''' + Replace(@CompanyNo,'''','''''') +''' '
if @KindNo != ''
set @sWhere = @sWhere + 'and M.kind_no = ''' + Replace(@KindNo,'''','''''') + ''' '
if @BillNo != ''
set @sWhere = @sWhere + 'and M.bill_no like ''%' + Replace(@BillNo,'''','''''')+'%'' '
Print @sWhere
set @SearchWhere = case @SearchType
when '1' then 'and M.user_no = M.actual_user_no and M.user_no = '''+@UserNo+''' and M.approve_Sign!= ''2'' '
when '2' then 'and M.user_no != M.actual_user_no and M.actual_user_no = '''+@UserNo+''' '
when '3' then 'and M.user_no != M.actual_user_no and M.user_no = '''+@UserNo+''' '
when '4' then 'and M.approve_sign = ''2'' and (M.actual_user_no='''+@UserNo+''' or M.user_no='''+@UserNo+''') '
end
set @sSql = @sSql + @sWhere + @SearchWhere
--調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectApprovedBillsMyCreate
/********************************
*介紹:辦公自動化OA系統 (查詢已結案的異常單據列表<我的異常單>)
*作者:電腦混混Vincent
*書寫時間:2006/07/03
*傳入:用戶NO
*返回:已結案的異常單據列表
*說明:涉及表名[bill_m_approve]
*********************************/
(
@UserNo varchar(20),
@PageSize int=10, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output --總頁數據 傳入0時可返回頁總數
)
as
declare @sSql varchar(500)
set @sSql='select C.company_nm,M.company_no,B.kind_nm,M.kind_no,M.bill_no, dbo.fn_Bill_ConvertStatus(M.status) status,'
+' dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,'
+' M.create_date from bill_m_approved M inner join company C on M.company_no=C.company_no inner join bill_kind B on M.kind_no=B.kind_no'
if @UserNo is null
return 1
else
set @sSql=@sSql+' where M.create_person='''+@UserNo+''''
--------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount output,@ShowFields='',@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectApprovedUserList
/********************************
*介紹:取得對指定單據已簽用戶列表
*作者:Billy
*書寫時間:2006/08/25
*傳入:單據代號
*返回:已簽用戶列表
*說明:涉及表名[person_d_approve]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
Declare @ApproveSeq int
Set @ApproveSeq = dbo.fn_Bill_GetCurrentApproveSeq(@CompanyNo, @KindNo, @BillNo)
Select P.seq, P.ApproveSeq, A.action_nm, P.Approve_date, U.User_name, dbo.fn_DepartMentFrame(U.company_no, U.dept_no) as Dept_nm
From Person_D_Approve P
Inner Join Action_Kind A on P.action_Seq = A.action_seq
Left Join UserAdmin U On P.user_no = U.user_no
Where P.company_no = @CompanyNo and P.kind_no = @KindNo and P.bill_no = @BillNo and P.approveSeq < @ApproveSeq and A.approve='Y'
order by P.ApproveSeq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectAssistantList
/********************************
*介紹:辦公自動化OA系統 (查詢職務列表)
*作者:Billy
*書寫時間:2006/08/19
*傳入:公司代號,類型代號
*返回:類型名稱
*說明:涉及表名[Assistant]
*********************************/
@UserNo varchar(20)
as
select * from Assistant Where Director_No = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectAssistantListFromUserNo
/********************************
*介紹:辦公自動化OA系統 (取得指定人員的工作助手列表)
*作者:Billy
*書寫時間:2006/08/29
*參數:@UserNo
*說明:使用表:UserAdmin, Dept, Position
*********************************/
(
@UserNo varchar(20)
)
as
Select M.*, D.Dept_nm, P.position_name From
(
Select Assistant.Seq, U.User_Name, U.Dept_no, U.Position_no, U.User_no, U.Tel, U.email From Assistant
Inner Join UserAdmin U On Assistant.Assistant_no = U.User_no
Where Director_no = @UserNo
) M
Inner Join Dept D on M.Dept_no = D.Dept_no
Left Join Position P on M.position_no = P.Position_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectAssistantNeedReadBillList
/***********************************************************
*介紹:辦公自動化OA系統 (查詢當前用戶(助理身份)的待查閱單據列表)
*作者:電腦混混Vincent
*書寫時間:2006/09/01
*傳入:用戶代號,分頁數據
*返回:查得當前用戶的待簽單據列表
*Execute eg : execute pr_SelectNeedApproveBillList 'Vincent'
*說明:涉及表名[bill_m_approve,person_d_approve]
************************************************************/
(
@AssistantNo varchar(20),
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sManager varchar(20) -----助理的主管代號
select @sManager = director_no from assistant
where assistant_no = @AssistantNo
set @sManager = IsNull(@sManager, '')
exec pr_SelectNeedApproveBillList
@UserNo = @sManager,
@PageSize = @PageSize,
@PageCount = @PageCount out
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillBaseInfo
/********************************
*介紹:辦公自動化OA系統____取指定單據的基本列表
*作者:Billy
*書寫時間:2006/10/11
*傳入:單據編號
*說明:涉及表名[bill_m_approved]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
if @CompanyNo = '' or @KindNo = ''
Begin
if Exists( Select Bill_no From Bill_M_Approve Where Bill_No = @BillNo )
Select @CompanyNo = Company_no, @KindNo = kind_no From Bill_M_Approve Where Bill_no = @BillNo
Else
Select @CompanyNo = Company_no, @KindNo = kind_no From Bill_M_Approved Where Bill_no = @BillNo
End
if Exists( Select Bill_no From Bill_M_Approve Where Company_no = @CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo )
Begin
select C.Company_nm, K.kind_nm, dbo.fn_Bill_ConvertStatus(M.status) status, dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,
M.note, U.user_name as create_person, M.create_date, M.Effect_Validate
from bill_m_approve M
left join company c on m.company_no = m.company_no
left join bill_kind K on M.company_no=K.Company_no and M.kind_no = K.kind_no
left join useradmin U on M.create_person = U.user_no
Where M.company_no = @CompanyNo and M.Kind_No = @KindNo and M.bill_no = @BillNo
End
Else
Begin
select C.company_nm,K.kind_nm, dbo.fn_Bill_ConvertStatus(M.status) status, dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,
M.note, U.user_name as create_person, M.create_date, M.Effect_Validate
from bill_m_approved M
left join company c on m.company_no = m.company_no
left join bill_kind K on M.company_no=K.Company_no and M.kind_no = K.kind_no
left join useradmin U on M.create_person = U.user_no
Where M.company_no = @CompanyNo and M.Kind_No = @KindNo and M.bill_no = @BillNo
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillColumns
/********************************
*介紹:(查詢指定單據的欄位列表
*作者:Billy
*書寫時間:2006/07/03
*傳入:公司代號,類型代號
*返回:欄位列表
*說明:涉及表名[bill_column]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(20)
)
as
declare @tempTable table (id int Identity(1,1),row_seq int, columnTitle varchar(50),columnName varchar(50),columnValue varchar(6000), ColumnKind char(1))
declare @nPosition int,@nCounter int,@sTemp varchar(6000),@sTempCol varchar(30), @BelongTable char(1)
set @BelongTable = '1'
--插入單據欄位資料到臨時表中
insert into @tempTable(row_seq,columnTitle,columnName, ColumnKind)
select row_seq,column_title,column_nm, Column_Kind from bill_column
where company_no=@CompanyNo and kind_no=@KindNo and belong_table = @BelongTable order by row_seq
select @nCounter=count(*) from @tempTable
set @nPosition=1
while @nPosition<=@nCounter
begin
select @sTempCol=columnName from @tempTable where id=@nPosition
Exec pr_Bill_GetColumnValue @CompanyNo, @KindNo, @BillNo, @BelongTable, @sTempCol, @sTemp out
if @sTempCol='product_no'
select @sTemp=kind_nm from product_kind where product_no=@sTemp
if @sTempCol='style_no'
select @sTemp=style_nm from product_style where style_no=@sTemp
if @sTempCol='error_no'
select @sTemp=error_nm from error_code where error_no=@sTemp
---將欄位值更新到臨時表中
update @tempTable set columnValue=@sTemp where id=@nPosition
set @nPosition=@nPosition+1
end
select ID, columnTitle, ColumnName, ColumnValue,
case ColumnKind
When '1' then 'string'
When '2' then 'float'
When '3' then 'int'
When '4' then 'datetime'
when '5' then 'bool'
else 'unKown'
End as ColumnKind
from @tempTable
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillFileList
/********************************
*介紹:辦公自動化OA系統 (查詢指定單據的附件檔列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:單據NO
*返回:異常單據列表
*說明:涉及表名[]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30)
)
as
if Exists(select bill_no from bill_m_approve where company_no = @CompanyNo and kind_no = @KindNo and bill_no=@BillNo)
select seq , file_path from bill_file where company_no = @CompanyNo and kind_no = @KindNo and bill_no=@BillNo
else
select seq , file_path from bill_file_done where company_no = @CompanyNo and kind_no = @KindNo and bill_no=@BillNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillFlowItem
/********************************
*介紹:辦公自動化OA系統 (取得某一單據的流程列表)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[bill_flow_m]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10)
)
as
if @CompanyNo=''
select * From bill_flow_d where kind_no=@KindNo order by seq ASC
else
select * From bill_flow_d where company_no=@CompanyNo and kind_no=@KindNo order by seq ASC
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillFlowItemInfo
/********************************
*介紹:辦公自動化OA系統 (取得某公司對應單據類型的流程項信息)
*作者:Billy
*書寫時間:2006/06/06
*參數:。。。。。
*說明:涉及表名[bill_flow_d,useradmin,position,dept]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@ActionSeq int=0
)
as
declare @sql varchar(4000)
set @sql='Select flowitem_ID,company_no,kind_no,seq,action_seq,local_dept,approve_company_no,dept_no,position_no,
company_nm,dept_nm,position_name,User_Name,User_no From
(
Select M.*,U.User_Name,U.User_no From
(SELECT D.company_no, D.kind_no,
D.flowitem_id, D.seq, D.action_seq,
D.local_dept, D.approve_company_no,
D.dept_no, D.position_no,
company.company_nm, dept.dept_nm,
[position].position_name
FROM bill_flow_d D LEFT OUTER JOIN
dept ON D.dept_no = dept.dept_no LEFT OUTER JOIN
company ON D.approve_company_no = company.company_no LEFT OUTER
JOIN [position] ON D.position_no = [position].position_no) M
left join UserAdmin U on M.approve_company_no=U.company_no and M.dept_no=U.dept_no and M.position_no=U.position_no
) C
Where company_no='''+@CompanyNO+''' and kind_no='''+@KindNo+''''
if(@ActionSeq<>0)
set @sql=@sql+' and action_seq='''+@ActionSeq+''''
set @sql=@sql+' order by action_seq,seq'
exec(@sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillFlowItemList
/********************************
*介紹:辦公自動化OA系統 (取得某一單據的流程列表)
*作者:Billy
*書寫時間:2006/07/24
*參數:。。。。。
*說明:涉及表名[bill_flow_m,Company,Dept,Position,action_kind]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10)
)
as
select D.flowitem_id, D.seq, D.action_seq, D.Flow_mode, D.approve_company_no, D.dept_no, D.position_no,
D.Add_ApproveUser, D.FillIn, D.Effect_Validate, D.prompt, D.EndCase, D.Condition, A.action_nm,
C.company_nm,P.Position_name,dept.dept_nm, OA.dbo.fn_DepartMentFrame(D.approve_company_no,D.dept_no) DepartMent
From bill_Flow_d D
left join action_kind A on D.action_seq=A.action_seq
left join company C on D.approve_company_no=C.company_no
left join dept on D.dept_no=dept.dept_no
left join position P on D.position_no=P.position_no
where D.company_no=@CompanyNo and D.Kind_no=@KindNo
order by seq asc
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillFlowMode
/********************************
*介紹:辦公自動化OA系統 (根據主鍵得到單據審核流程)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*說明:涉及表名[bill_flow_m,record]
*返回:單據審核流程(1:自動;2:手動;)
*調用:ExecuteScaler()
*********************************/
(
@FlowID int
)
as
select M.*,B.Kind_nm,C.company_nm from bill_flow_m M
inner join bill_kind B on M.company_no=B.company_no and M.kind_no=B.kind_no
inner join Company C on M.company_no=C.company_no
where M.flow_id=@FlowID
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillKindFromCompanyNoAndKindNo
/********************************
*介紹:辦公自動化OA系統 (根據公司代號和單據類型代號取得單據類型信息)
*作者:Billy
*書寫時間:2006/07/04
*參數:
*說明:
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10)
)
as
select B.* ,C.company_nm From Bill_kind B inner join Company C on B.company_no=C.company_no
Where B.company_no=@CompanyNo and kind_no=@KindNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillKindFromUserNo
/********************************
*介紹:辦公自動化OA系統 (取單據類型列表)
*作者:Billy
*書寫時間:2006/08/21
*參數:@UserNo --用戶代號
*說明:
*********************************/
(
@UserNo varchar(20)
)
as
Declare @CompanyNo varchar(10)
set @CompanyNo = ''
Select @CompanyNo = company_no From UserAdmin Where user_no = @UserNo
select B.*,C.company_nm From bill_kind B inner join company C on C.company_no=B.company_no where B.company_no=@CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillKindList
/********************************
*介紹:辦公自動化OA系統 (查詢單據類型列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:公司代號,空則取全部
*說明:涉及表名[bill_kind,record]
*********************************/
(
@CompanyNo varchar(10)
)
as
if @CompanyNo is null or @CompanyNo=''
select kind_no,kind_nm from bill_kind
else
select kind_no,kind_nm from bill_kind where company_no=@CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillKindWithSecurity
/********************************
*介紹:辦公自動化OA系統 (取得某用戶某有權限的單據列表)
*作者:Billy
*書寫時間:2006/07/07
*傳入:用戶帳號
*返回:
*說明:涉及表名[bill_security, bill_kind, company]
*********************************/
(
@UserNo varchar(20)
)
as
declare @Sql varchar(1000)
declare @DeputyUser varchar(1000)
exec pr_SelectDeputyPersonList @UserNo,@DeputyUser output
if @DeputyUser=''
set @DeputyUser=@UserNo
else
set @DeputyUser=@DeputyUser+','+@UserNo
set @DeputyUser=''''+Replace(@DeputyUser,',',''',''')+''''
set @Sql='select distinct C.company_nm,K.Kind_nm,K.company_no,K.kind_no,K.note from bill_security S
inner join bill_kind K on S.company_no=K.company_no and S.kind_no=K.kind_no
inner join company C on C.company_no=S.company_no
where S.user_no in ('+@DeputyUser+') and S.c_new=''Y'' order by K.company_no,K.kind_no'
exec(@Sql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectBillOperationPurivew
/********************************
*介紹:辦公自動化OA系統____取得當前用戶對當前單據的操作權限
* (1:郵件通知,2:電子簽章,3:添加簽核用戶,4:結案單據)
*
*作者:電腦混混Vincent
*書寫時間:2006/08/22
*傳入:用戶代號,單據代號
*返回:0:有1:無
*說明:涉及表名[person_d_approve]
*********************************/
(
@UserNo varchar(20), --用戶代號
@CompanyNo Varchar(10),
@KindNo Varchar(10),
@BillNo varchar(30), --單據代號
@MailInform char(1) output, --是否允許郵件通知(簽單操作以後)
@AddApproveUser char(1) output, --是否能夠添加新的簽核用戶
@FillIn char(1) output, --是否填寫表單
@HasFillInBillColumn char(1) output, --單據主表是否在填寫的欄位
@HasFillInItemColumn char(1) output, --單據從表是否在填寫的欄位
@Prompt nVarchar(100) output, --簽核提示信息
@EndCase char(1) output, --是否能夠結案當前單據
@Condition varchar(50)output, --單據結案條件
@ApproveSeq int output, --實際簽核位置(序號ApproveSeq)
@MarkName varchar(60) output --電子簽章(無則為NULL)
)
as
select @ApproveSeq = Current_ApproveSeq From Bill_M_Approve Where company_no=@CompanyNo and Kind_no = @KindNo and Bill_No = @BillNo
Select @HasFillInBillColumn = 'N', @HasFillInItemColumn = 'N'
----取當前用戶是否允許郵件通知
select @MailInform = email_inform, @MarkName = mark_name from useradmin where user_no = @UserNo
----取當前用戶是否能添加簽核用戶和結案單據
select @AddApproveuser = add_approveUser, @FillIn = FillIn, @Prompt = prompt, @EndCase = endCase, @Condition = condition
from person_d_approve
where company_no = @CompanyNo and Kind_no = @KindNo and bill_no = @BillNo and approveSeq = @ApproveSeq
if( @FillIn = 'Y' ) --當需要填寫表單時,檢查是否有可填寫的欄位
Begin
if Exists(Select bill_no From Bill_M_Approve where company_no = @CompanyNo and Kind_no = @KindNo and bill_no = @BillNo)
Begin
--檢查欄位設置表
if Exists(Select Approver_input From Bill_Column where company_no = @CompanyNo and Kind_no = @KindNo and Approver_Input = 'Y' and belong_table = '1')
Set @HasFillInBillColumn = 'Y'
End
if Exists(Select bill_no From Bill_Item_Approve where company_no = @CompanyNo and Kind_no = @KindNo and bill_no = @BillNo)
Begin
--檢查欄位設置表
if Exists(Select Approver_input From Bill_Column where company_no = @CompanyNo and Kind_no = @KindNo and Approver_input = 'Y' and Belong_table = '2')
Set @HasFillInItemColumn = 'Y'
End
End
Set @Prompt = IsNull(@Prompt, '')
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillSecurityFromUserNo
/********************************
*介紹:辦公自動化OA系統 (取得某用戶的單據權限列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶NO,操作者,操作窗口
*返回:刪除是否成功0:否;1:是
*說明:涉及表名[useradmin,record]
*********************************/
(
@UserNo varchar(20)
)
as
declare @BillSecurity Table (company_no varchar(10),kind_no varchar(10),company_nm varchar(60), kind_nm varchar(60),user_no varchar(20),c_new char(1),c_search char(1), r_browse char(1), r_print char(1))
insert into @BillSecurity (company_no,kind_no,company_nm,kind_nm,user_no,c_new,c_search, r_browse, r_print)
(
select K.company_no,K.kind_no,C.company_nm,K.kind_nm,S.user_no,S.c_new,S.c_search, S.r_browse, S.r_Print From bill_kind K
left join (select * from bill_security where user_no=@UserNo) S on K.company_no=S.company_no and K.kind_no=S.kind_no
Inner Join company C on K.company_no=C.company_no
)
update @BillSecurity set c_new='N' where c_new<>'Y'
update @BillSecurity set c_search='N' where c_search<>'Y'
update @BillSecurity set r_Browse='N' where r_Browse<>'Y'
update @BillSecurity set r_print='N' where r_print<>'Y'
select * From @BillSecurity order by company_no,kind_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillSuggestList
/*************************************************
*介紹:辦公自動化OA系統 ___取當前簽核用戶的助理對當前單據的建議
*作者:電腦混混Vincent
*書寫時間:2006/08/21
*傳入:用戶NO,單據代號
*說明: 被訪表名[assistant_overture]
更新表名[]
*
*************************************************/
(
@UserNo varchar(20),
@BillNo varchar(20)
)
as
select M.content,U.user_name as assistantName,Convert(datetime,M.create_date,120) as create_date
from assistant_overture M
inner join useradmin U on M.user_no = U.user_no
where M.bill_no = @BillNo and M.user_no in ( select assistant_no from assistant where director_no = @UserNo )
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillTraceKindList
/********************************
*介紹:取當前用戶需要單據(已結案)效果確認單據類型列表
*作者:電腦混混Vincent
*書寫時間:2006/10/11
*傳入:用戶NO
查詢類別@SelectType:‘1’需要效果追蹤
‘2’已效果確認
*說明:涉及表名[bill_approved_agree,bill_m_approved]
********************************/
(
@UserNo varchar(20),
@SelectType char(1)
)
as
declare @sDeputyPersonList varchar(1000),@UserList varchar(1000)
declare @sSql varchar(4000),@sWhere varchar(500)
------------------------------------------------------------------------------------------------------------
-- 首先傳入用戶NO進行判斷(檢查用戶是否為其它用戶的代理人,如果是,
--同時列出被其代理用戶的待簽單据.
--工作代理人 :代理我的用戶(因為有預設、實際簽核用戶之分可不作考慮)
--被代理人 :我代理的用戶(重點進行考慮)
------------------------------------------------------------------------------------------------------------
exec pr_SelectDeputyPersonList @UserNo,@sDeputyPersonList out
------------------------------------------傳出的被代理人列表進行判斷,檢查是否有被代理人存在
--print @sDeputyPersonList
if @sDeputyPersonList is not null
begin
set @sDeputyPersonList=replace(@sDeputyPersonList,',',''',''')
set @UserList='M.setting_user_no in ('''+@UserNo+''','''+@sDeputyPersonList+''') '
end
else
set @UserList='M.setting_user_no='''+@UserNo+''' '
print @UserList
set @sWhere = case @SelectType when '1' then 'M.validate !=''3'' and '+@UserList
when '2' then 'M.validate =''3'' and '+ @UserList end
set @sSql = 'select distinct M.company_no,M.kind_no,C.kind_nm from bill_approve_validate M '+
'inner join bill_kind C on M.company_No=C.Company_No and M.kind_no = C.kind_no where ' + @sWhere
exec(@sSql)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillValidateInfo
/********************************
*介紹:辦公自動化OA系統____取當前單據效果確認的詳細信息
*作者:電腦混混Vincent
*書寫時間:2006/10/11
*傳入:用戶NO,查詢類型
*查詢類型 1: 未進行效果確認
2: 通過效果確認
3: 未通過效果確認
*說明:涉及表名[bill_approved_agree,bill_m_approved]
*********************************/
(
@BillNo varchar(20) ----
)
as
select U.user_name as setting_user,
A.user_name as actual_user,
case M.validate when 'Y' then 'Pass' else 'Reject' end as result,
M.note,
M.validate_date
from bill_approve_validate M
inner join useradmin U on M.setting_user_no = U.user_no
inner join useradmin A on A.user_no = M.actual_user_no
where M.bill_no = @BillNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectBillValidateLogs
/********************************
*介紹:辦公自動化OA系統____取當前單據效果確認的日志內容
*作者:電腦混混Vincent
*書寫時間:2006/10/11
*傳入:用戶NO,查詢類型
*查詢類型 1: 未進行效果確認
2: 通過效果確認
3: 未通過效果確認
*說明:涉及表名[bill_approved_agree,bill_m_approved]
*********************************/
(
@BillNo varchar(20), ----
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sSql nvarchar(4000)
set @sSql = 'select C.company_nm ,'+
'K.kind_nm,'+
'M.bill_no,'+
'U.user_name as setting_user,'+
'A.user_name as actual_user,'+
'case M.validate when ''Y'' then ''Pass'' else ''Reject'' end as result, '+
'M.note,'+
'M.validate_date '+
'from bill_approve_validate_log M '+
'inner join Company C on M.company_no = C.company_no '+
'inner join bill_kind K on M.compay_no=K.company_No and M.kind_no = K.kind_no '+
'inner join useradmin U on M.setting_user_no = U.user_no '+
'inner join useradmin A on A.user_no = M.actual_user_no '+
'where M.bill_no = ''' + @BillNo + ''''
print @sSql
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='validate_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectChildWindowFromWindowNo
/********************************
*介紹:辦公自動化OA系統 (根據提供的WindowNO得出其他所有的子窗體代號)
*作者:Billy
*書寫時間:2006/0824
*參數:@WindowNo:窗體代號
*說明:代用表:Menu_List
*********************************/
(
@WindowNo varchar(20) = '',
@ChildList Varchar(4000) output
)
as
Set @ChildList = IsNull(@ChildList, '')
Declare @tmpWindowNo varchar(20), @ID int , @RowsCount int
Declare @TempTable Table (ID int Identity(1,1), Win_no varchar(20))
Set @ID = 1
Insert into @TempTable Select Win_no From Menu_List Where Parent_Win_no = @WindowNo order by Win_no
Select @RowsCount = Count(*) From @TempTable
While @ID <= @RowsCount
Begin
Select @TmpWindowNo = Win_no From @TempTable Where ID = @ID
Set @ChildList = @ChildList + ',' + @TmpWindowNo
Set @ID = @ID + 1
Exec pr_SelectChildWindowFromWindowNo @TmpWindowNo, @ChildList output
End
if Len(@ChildList) > 0
if SubString(@ChildList, 1,1) = ','
Set @ChildList = SubString(@ChildList, 2,Len(@ChildList))
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectCompanyFromCompanyNo
/*******************************
功能:根據公司代號取公司信息
作者:Billy
日期:2006/12/07
*******************************/
(
@CompanyNo varchar(10)
)
As
Select * From Company Where Company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectCompanyList
/********************************
*介紹:辦公自動化OA系統 (查詢公司信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:操作者,操作窗口
*返回:公司列表
*說明:涉及表名[company,record]
*********************************/
as
select company_no,company_nm from company
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectCurrentSuggest
/*************************************************
*介紹:辦公自動化OA系統 ___取當前用戶(助理身份)對當前單據簽寫的建議
*作者:電腦混混Vincent
*書寫時間:2006/09/05
*傳入:單據NO
*說明: 被訪表名[assistant_overture]
*
*************************************************/
(
@UserNo varchar(20), ----傳入用戶代號
@CompanyNo varchar(10),
@KindNo varchar(10),
@BillNo varchar(30), ----傳入單據編號
@Suggest varchar(1000) output ----輸出建議
)
as
select @Suggest = content from assistant_overture
where user_no = @UserNo and company_no = @CompanyNo and Kind_no = @KindNo and bill_no = @BillNo
set @Suggest = IsNull(@Suggest, '')
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectDailyPhraseList
/*************************************************
*介紹:辦公自動化OA系統 ___提取用戶的日常簽核批示用語(包括系統用語)
*作者:電腦混混Vincent
*書寫時間:2006/08/21
*傳入:單據NO
*說明: 被訪表名[use_phrase]
更新表名[]
*
*************************************************/
(
@UserNo varchar(20)
)
as
select phrase_content from use_phrase where user_no = @UserNo and system_phrase = 'N'
union
select phrase_content from use_phrase where system_phrase = 'Y'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE pr_SelectDataPager
(
@QueryText varchar(6000), --表名、視圖名、查詢語句
@PageSize int=30, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output, --總頁數據 傳入0時可返回頁總數
@ShowFields varchar (4000)='', --要顯示的字段列表,如果查詢結果有標識字段,需要指定此值,且不包含標識字段
@OrderFields varchar (1000)='' --排序字段列表
)
AS
DECLARE @sSql varchar(8000)
DECLARE @nTotal Int
Declare @nSql nVarchar(4000)
DECLARE @FdName varchar(250) --表中的主鍵或表、臨時表中的標識列名
,@Id1 varchar(20),@Id2 varchar(20) --開始和結束的記錄號
,@Obj_ID int --對像ID
--表中有復合主鍵的處理
DECLARE @strfd varchar(2000) --復合主鍵列表
,@strjoin varchar(4000) --連接字段
,@strwhere varchar(2000) --查詢條件
Set @OrderFields = IsNull(@OrderFields, '')
Set @Obj_ID = object_id(@QueryText)
Set @ShowFields = case isnull(@ShowFields,'') when '' then ' *' else ' '+@ShowFields end
Set @OrderFields=case @OrderFields when '' then '' else ' order by '+@OrderFields end
Set @QueryText=case when @Obj_ID is not null then ' '+@QueryText else ' ('+@QueryText+') M' end
--查詢第一頁返回紀錄總數
--如果傳入的@PageCount為0則查詢記錄總數閾返回頁總數據
if (@PageCount = 0)
begin
Set @nSql = N'select @nTotal = count(*) from '+Convert(nVarchar(4000),@QueryText)
Execute sp_executesql @nSql, N'@nTotal Int Output', @nTotal Output
Select @PageCount=@nTotal / @PageSize
if ((@PageCount * @PageSize) < @nTotal) Select @PageCount = @PageCount + 1
end
--如果顯示第一頁,可以直接用top來完成
if @PageCurrent=1
begin
select @Id1=cast(@PageSize as varchar(20))
Print ('select top '+@Id1 +@ShowFields + ' from '+@QueryText+@OrderFields)
exec('select top '+@Id1 +@ShowFields + ' from '+@QueryText+@OrderFields)
return
end
--如果是表,則檢查表中是否有標識更或主鍵
if @Obj_ID is not null and objectproperty(@Obj_ID,'IsTable')=1
begin
select @Id1=cast(@PageSize as varchar(20)), @Id2=cast((@PageCurrent-1)*@PageSize as varchar(20))
select @FdName=name from syscolumns where id=@Obj_ID and status=0x80
if @@rowcount=0 --如果表中無標識列,則檢查表中是否有主鍵
begin
--如果表中無主鍵,則用臨時表處理
if not exists(select 1 from sysobjects where parent_obj=@Obj_ID and xtype='PK') goto lbusetemp
select @FdName=name from syscolumns where id=@Obj_ID and colid in(
select colid from sysindexkeys where @Obj_ID=id and indid in(
select indid from sysindexes where @Obj_ID=id and name in(
select name from sysobjects where xtype='PK' and parent_obj=@Obj_ID)))
if @@rowcount>1 --檢查表中的主鍵是否為復合主鍵
begin
select @strfd='',@strjoin='',@strwhere=''
select @strfd=@strfd+',['+name+']', @strjoin=@strjoin+' and a.['+name+']=b.['+name+']', @strwhere=@strwhere+' and b.['+name+'] is null' from syscolumns where id=@Obj_ID and colid in(
select colid from sysindexkeys where @Obj_ID=id and indid in(
select indid from sysindexes where @Obj_ID=id and name in(
select name from sysobjects where xtype='PK' and parent_obj=@Obj_ID)))
select @strfd=substring(@strfd,2,2000), @strjoin=substring(@strjoin,5,4000), @strwhere=substring(@strwhere,5,4000)
goto LbUsePK
end
end
end
else
goto LbUseTemp
/*--使用標識列或主鍵為單一字段的處理方法--*/
LbUseIdentity:
exec('select top '+@Id1+@ShowFields+' from '+@QueryText +' where '+ @FdName+' not in(select top ' + @Id2+' '+@FdName+' from '+@QueryText+@OrderFields + ')'+@OrderFields)
return
/*--表中有復合主鍵的處理方法--*/
LbUsePK:
exec('select '+@ShowFields+' from(select top '+@Id1+' a.* from (select top 100 percent * from '+
@QueryText+@OrderFields+') a left join (select top '+@Id2+' '+@strfd+' from '+@QueryText+@OrderFields+') b on '+ @strjoin+' where '+@strwhere+') a')
return
/*--用臨時表處理的方法--*/
LbUseTemp:
select @FdName='[ID]',--_'+cast(newid() as varchar(40))+']',
@Id1=cast(@PageSize*(@PageCurrent-1)+1 as varchar(20)),
@Id2=cast(@PageSize+@Id1-1 as varchar(20))
exec('select '+@ShowFields+'
into #tb from'+@QueryText+@OrderFields+' select '+@FdName+'=identity(int,1,1),* into #temp from #tb select * From #temp where '+@FdName+' between ' +@Id1+' and '+@Id2)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectDepartmentList
/********************************
*介紹:辦公自動化OA系統 (查詢部門列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:公司代號,操作者,操作窗口
*返回:部門列表
*說明:涉及表名[dept,record]
*********************************/
(
@CompanyNo varchar(10)
)
as
if @CompanyNo=''
select dept_no,dept_nm,parent_dept_no,company_no from dept
else
select dept_no,dept_nm,parent_dept_no,company_no from dept where company_no=@CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
/*****************************************************************
** 過程名稱:pr_SelectDeputyListFromUserNo
** 創建日期:2006-08-21 09:39:13
** 修改日期:2006-08-21 09:39:13
*****************************************************************/
CREATE Proc pr_SelectDeputyListFromUserNo
/********************************
*介紹:辦公自動化OA系統 (查詢用戶的工作代理設置)
*作者:Billy
*書寫時間:2006/07/26
*傳入:用戶代號
*返回:代理列表
*說明:涉及表名[DeputyInfo,UserAdmin]
*********************************/
(
@UserNo varchar(20)
)
as
Select M.seq,M.Deputy,M.User_name,P.Position_Name,dbo.fn_UserDepartment(M.Deputy) as DepartMent ,M.StartTime,M.EndTime,M.JoinDate From
(
select D.*,U.user_name,U.position_no From DeputyInfo D
Left Join UserAdmin U ON D.Deputy=U.user_no Where D.ByDeputy=@UserNo
) M
Left Join Position P on M.position_no=P.Position_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectDeputyPersonList
/********************************************************************
*介紹:辦公自動化OA系統 (查得?入用?的所有被代理人列表)
?用pr_SelectDeputyPersonTemp存??程??取出所有代理人列表
(用","分隔)
*作者:電腦混混Vincent
*書寫時間:2006/07/18
*傳入:用戶NO
*返回:所有被代理人列表
*說明:涉及表名[deputyInfo]
********************************************************************/
(
@DeputyUser varchar(20),
@ByDeputyUserList varchar(1000) out
)
as
declare @tempDeputy table(id int identity(1,1), ByDeputy varchar(20), Deputy varchar(20) )
declare @rowIndex int,@rowCount int,@ByDeputy varchar(20),@Result varchar(2000),@Temp varchar(1000)
insert into @tempDeputy(ByDeputy,Deputy)
select ByDeputy,Deputy from deputyinfo
where Deputy=@DeputyUser and StartTime
set @rowIndex=1
set @Temp=null
set @Result=''
select @rowCount=count(*) from @tempDeputy
while @rowIndex<=@rowCount
begin
select @ByDeputy=ByDeputy from @tempDeputy where id=@rowIndex
set @Temp=@ByDeputy+','
exec pr_SelectDeputyPersonTemp @ByDeputy,@ByDeputyPerson=@Temp out
set @Result=@Result+@Temp
set @rowIndex=@rowIndex+1
end
if len(@Result)>0
begin
set @Result=substring(@Result,1,(len(@Result)-1))
end
set @ByDeputyUserList=@Result
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectDeputyPersonTemp
(
@DeputyUser varchar(20),
@ByDeputyPerson varchar(20)out
)
as
declare @tempTable table (id int identity(1,1),
ByDeputy varchar(20),
Deputy varchar(20)
)
declare @rowIndex int,@rowCount int,@DeputyPerson varchar(20),@Temp varchar(20)
insert into @tempTable(ByDeputy,Deputy)
select ByDeputy,Deputy from deputyinfo
where Deputy=@DeputyUser and StartTime
set @rowIndex=1
set @Temp=null
select @rowCount=count(*) from @tempTable
while @rowIndex<=@rowCount
begin
select @DeputyPerson=ByDeputy from @tempTable where id=@rowIndex
set @Temp=@DeputyPerson+','
exec pr_SelectDeputyPersonTemp @DeputyPerson,@ByDeputyPerson=@Temp out
set @ByDeputyPerson=@ByDeputyPerson+@Temp
set @rowIndex=@rowIndex+1
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectErrorCodeFromProduct
/********************************
*介紹:辦公自動化OA系統 (查詢類型名稱)
*作者:電腦混混Vincent
*書寫時間:2006/07/03
*傳入:公司代號,類型代號
*返回:類型名稱
*說明:涉及表名[bill_kind]
*********************************/
(
@ProductNo varchar(10)
)
as
if @ProductNo=''
Select product_no,error_no,error_nm from error_code
else
Select product_no,error_no,error_nm from error_code where product_no=@ProductNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectInformBillList
/***********************************************************
*介紹:查詢通知某用戶的單據(只查詢未結案單據,忽略結案的結案)
*作者:Billy
*時間:2007/02/06
*傳入:用戶代號,分頁數據
*返回:查得當前用戶的待簽單據列表
*Execute eg : execute pr_SelectInformBillList 'Vincent'
*說明:涉及表名[bill_m_approve,person_d_approve]
************************************************************/
(
@UserNo varchar(20),
@CompanyNo varchar(10) = '',
@KindNo varchar(10) = '',
@BillNo varchar(30) = '',
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sSql nvarchar(4000)
declare @sDeputyPersonList varchar(1000),@UserList varchar(1000)
-- 首先檢查用戶是否為其它用戶的代理人,如果是,同時列出被其代理用戶的待簽單据.
exec pr_SelectDeputyPersonList @UserNo,@sDeputyPersonList out
if @sDeputyPersonList is not null and ltrim(@sDeputyPersonList) != ''
begin
set @sDeputyPersonList=replace(@sDeputyPersonList,',',''',''')
set @UserList=''''+@UserNo+''','''+@sDeputyPersonList+''') '
end
else
set @UserList=''''+@UserNo+''''
Set @sSql = 'Select M.company_no,M.kind_no,M.bill_no,B.kind_nm,C.company_nm,M.Create_Date,PA.action_nm,'
+ 'dbo.fn_Bill_ConvertStatus(status) status,dbo.fn_ConvertExigencyGrade(M.exigency_Grade) exigency_grade '
+ 'From Bill_M_Approve M Inner Join ( '
+ 'select Distinct P.Company_no,P.Kind_no,P.Bill_No, A.action_nm From Person_d_Approve P '
+ 'Inner Join action_Kind A On P.company_No=A.company_no and P.action_Seq=A.action_seq '
+ ' Where P.User_No in(' + @UserList + ') and A.approve!=''Y'' '
+ ') PA On M.company_no=PA.company_no and M.kind_no=PA.Kind_no and M.bill_no=PA.bill_No '
+ 'Left Join Bill_Kind B On M.company_no=B.company_no and M.kind_no=B.kind_no '
+ 'left join company C On M.company_no=C.company_no '
if @CompanyNo != ''
set @sSql = @sSql +'And M.Company_no = ''' + @CompanyNo + ''' '
if @KindNo != ''
set @sSql = @sSql +'And M.Kind_no = ''' + @KindNo + ''' '
if @BillNo != ''
set @sSql = @sSql +'And M.Bill_no Like ''%' + @BillNo + '%'' '
print @sSql
--調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectKindName
/********************************
*介紹:辦公自動化OA系統 (查詢類型名稱)
*作者:電腦混混Vincent
*書寫時間:2006/07/03
*傳入:公司代號,類型代號
*返回:類型名稱
*說明:涉及表名[bill_kind]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10)
)
as
select kind_nm from bill_kind where company_no=@CompanyNo and kind_no=@KindNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectLogs
/********************************
*介紹:辦公自動化OA系統 (查詢日志項)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:
*返回:日志列表
*說明:
*********************************/
(
@Operator varchar(20)='',
@WindowNo varchar(20)='',
@StartDate varchar(30)='',
@EndDate varchar(30)='',
@PageCurrent int=1, ---默認查詢頁碼
@PageSize int=30, ---默認頁大小
@PageCount int=0 out --頁總數 (傳入0時可查入頁總數)
)
as
---1: browse 2: new 3: modify 4: del 5: print 6: approve
declare @tempSql varchar(4000),
@sWhere varchar(200)
Declare @SearchWindowList varchar(4000)
------生成WHERE條件字符串
set @sWhere = ''
if @Operator!='' set @sWhere=' And R.user_no Like ''%' + @Operator + '%'' Or U.User_name Like ''%' + @Operator +'%'''
if @WindowNo!=''
Begin
exec pr_SelectChildWindowFromWindowNo @WindowNo, @SearchWindowList out
if @SearchWindowList != ''
Set @SearchWindowList = '''' + Replace( @SearchWindowList, ',', ''',''') +''''
if @SearchWindowList != ''
set @sWhere= @sWhere + ' And R.win_no IN ('+@SearchWindowList+')'
Else
set @sWhere= @sWhere + ' And R.win_no =''' + @WindowNo + ''''
End
if @StartDate!='' And @StartDate Is Not Null
set @sWhere= @sWhere + ' And R.record_date>'''+@StartDate+''''
if @EndDate!='' And @EndDate Is Not Null
set @sWhere= @sWhere + ' And R.record_date<'''+@EndDate+''''
---------------------------------------------------------------------------------------------------------------------------
set @tempSql='select R.record_date,R.user_no,U.user_name, R.win_no,M.Win_nm, OA.dbo.fn_ConvertOperation(R.action_type) as operation,note from record R
Left Join UserAdmin U On U.user_no = R.user_no
Left Join Menu_List M On R.win_no = M.win_no Where 1=1 '+@sWhere
exec pr_SelectDataPager @tempSql,@PageSize,@PageCurrent,@PageCount out, '', 'Record_Date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectMenuListFromUserNo
/********************************
*介紹:辦公自動化OA系統 (根據用戶代號取得全部窗口列表)
*作者:Billy
*書寫時間:2006/08/25
*參數:@UserNo 用戶代號
*說明:表:Menu_List, Security
*********************************/
(
@UserNo Varchar(20)
)
as
SELECT MENU_LIST.win_no, MENU_LIST.win_nm,MENU_LIST.parent_win_no, MENU_LIST.c_EveryOne,
OA.dbo.fn_Menu_HasChildMenu(MENU_LIST.Win_no) As HasChildMenu, OA.dbo.fn_Menu_CheckMenuLevel(MENU_LIST.Win_no) As Menu_Level,
security.p_seted,security.user_no,security.p_browse, security.p_new, security.p_modify, security.p_del,
security.p_print, security.p_approve, security.p_visible
FROM MENU_LIST
LEFT OUTER JOIN
(
SELECT 'Y' p_seted,* FROM security WHERE user_no = @UserNo
) security
ON MENU_LIST.win_no = security.win_no
Order By Menu_List.win_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectNeedApproveBillList
/***********************************************************
*介紹:查詢當前用戶的待簽單據列表
*作者:Billy
*時間:2007/02/06
*傳入:用戶代號,分頁數據
*返回:查得當前用戶的待簽單據列表
************************************************************/
(
@UserNo varchar(20),
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sSql Nvarchar(4000)
declare @UserList varchar(1000)
-- 首先檢查用戶是否代理其他用戶的代理人,如果是,同時列出被其代理用戶的待簽單据.
exec pr_SelectDeputyPersonList @UserNo,@UserList out
Set @UserList = IsNull(@UserList, '')
if @UserList != ''
begin
set @UserList=replace(@UserList,',',''',''')
set @UserList=' ''' + @UserNo+''','''+@UserList+''' '
end
else
set @UserList ='''' + @UserNo + ''''
print @UserList
Set @sSql = 'select C.company_nm,BK.kind_nm,PA.action_Seq,AK.action_nm,BA.company_no,BA.kind_no,BA.bill_no,dbo.fn_Bill_ConvertStatus(BA.status) as status,'
+'dbo.fn_ConvertExigencyGrade(Exigency_Grade) Exigency_Grade,Convert(varchar(19),BA.create_date,120) create_date '
+'From Bill_M_Approve BA '
+'Inner Join Person_d_Approve PA On BA.company_no=PA.company_no and BA.kind_no=PA.kind_no and BA.bill_no=PA.bill_No and BA.current_ApproveSeq=PA.ApproveSeq '
+'Inner Join Action_Kind AK On PA.company_no=AK.company_no and PA.action_Seq=AK.action_Seq '
+'Left Outer Join Company C On BA.Company_No=C.Company_No '
+'left Outer Join Bill_Kind BK on BA.Company_No=BK.Company_no and BA.Kind_no = BK.kind_no '
+'Where AK.Approve = ''Y'' and PA.User_no In(' + @UserList + ')'
---調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectNeedBillTraceList
/********************************
*介紹:取當前用戶需要單據效果確認單據列表
*作者:電腦混混Vincent
*書寫時間:2006/10/19
*傳入:用戶NO,單據類型
*說明:涉及表名[bill_approve_validate,bill_m_approved]
*********************************/
(
@UserNo varchar(20), ----
@CompanyNo varchar(10),
@KindNo varchar(10), ----
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sSql nvarchar(4000)
declare @sDeputyPersonList varchar(1000),@UserList varchar(1000)
------------------------------------------------------------------------------------------------------------
-- 首先傳入用戶NO進行判斷(檢查用戶是否為其它用戶的代理人,如果是,
--同時列出被其代理用戶的待簽單据.
--工作代理人 :代理我的用戶(因為有預設、實際簽核用戶之分可不作考慮)
--被代理人 :我代理的用戶(重點進行考慮)
------------------------------------------------------------------------------------------------------------
exec pr_SelectDeputyPersonList @UserNo,@sDeputyPersonList out
------------------------------------------傳出的被代理人列表進行判斷,檢查是否有被代理人存在
--print @sDeputyPersonList
if @sDeputyPersonList is not null
begin
set @sDeputyPersonList=replace(@sDeputyPersonList,',',''',''')
set @UserList='M.setting_user_no in ('''+@UserNo+''','''+@sDeputyPersonList+''') '
end
else
set @UserList='M.setting_user_no='''+@UserNo+''' '
print @UserList
set @UserList = 'M.validate !=''3'' and M.company_no = ''' + @CompanyNo + ''' and M.kind_no = '''+@KindNo+''' and '+@UserList
set @sSql = 'select M.company_no,M.bill_no,U.user_name as create_person,'+
'C.create_date,case M.validate when ''1'' then ''UnConfirm'' when ''2'' then ''UnPass'' end as result '+
'from bill_approve_validate M '+
'inner join bill_m_approved C on M.bill_no = C.bill_no '+
'inner join useradmin U on C.create_person = U.user_no '+
'where ' + @UserList
print @sSql
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectPassedBillTraceList
/********************************
*介紹:辦公自動化OA系統____取當前用戶已經單據效果確認單據列表
*作者:電腦混混Vincent
*書寫時間:2006/10/19
*傳入:用戶NO,單據類型
*說明:涉及表名[bill_approve_validate,bill_m_approved]
*********************************/
(
@UserNo varchar(20), ----
@CompanyNo varchar(10),
@KindNo varchar(10), ----
----------用於分頁
@PageSize int=10,
@PageCurrent int=1,
@PageCount int=1 out
)
as
declare @sSql nvarchar(4000)
declare @sDeputyPersonList varchar(1000),@UserList varchar(1000)
------------------------------------------------------------------------------------------------------------
-- 首先傳入用戶NO進行判斷(檢查用戶是否為其它用戶的代理人,如果是,
--同時列出被其代理用戶的待簽單据.
--工作代理人 :代理我的用戶(因為有預設、實際簽核用戶之分可不作考慮)
--被代理人 :我代理的用戶(重點進行考慮)
------------------------------------------------------------------------------------------------------------
exec pr_SelectDeputyPersonList @UserNo,@sDeputyPersonList out
------------------------------------------傳出的被代理人列表進行判斷,檢查是否有被代理人存在
--print @sDeputyPersonList
if @sDeputyPersonList is not null
begin
set @sDeputyPersonList=replace(@sDeputyPersonList,',',''',''')
set @UserList='C.setting_user_no in ('''+@UserNo+''','''+@sDeputyPersonList+''') '
end
else
set @UserList='C.setting_user_no='''+@UserNo+''' '
print @UserList
set @UserList = ' M.company_no = ''' + @CompanyNo + ''' and M.kind_no = '''+@KindNo+''' and '+@UserList
set @sSql = 'select M.company_no,'+
'M.bill_no,'+
'U.user_name as create_person,'+
'M.create_date,'+
'case M.effect_validate_pass when ''N'' then ''UnCompleted'' when ''Y'' then ''Complete'' '+
' end as result '+
'from bill_m_approved M '+
'inner join bill_approve_validate C on M.bill_no = C.bill_no ' +
'inner join useradmin U on M.create_person = U.user_no '+
'where ' + @UserList
print @sSql
-------------------------調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount out,@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectPositionList
/********************************
*介紹:辦公自動化OA系統 (查詢職務列表)
*作者:電腦混混Vincent
*書寫時間:2006/07/03
*傳入:公司代號,類型代號
*返回:類型名稱
*說明:涉及表名[bill_kind]
*********************************/
as
select position_no,position_name from position
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_SelectPositionListFromCompanyNo
/********************************
*介紹:取某公司的職務列表
*作者:Billy
*時間:2006/12/22
*傳入:公司代號
*返回:類型名稱
*說明:涉及表名[position]
*********************************/
(
@CompanyNo varchar(10)
)
as
select position_no,position_name from position
Where Company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectPositionNameFromUserNo
/********************************
*介紹:辦公自動化OA系統 (根據用戶代號取得職務名稱)
*作者:Billy
*書寫時間:2006/07/10
*傳入:用戶代號
*返回:刪除是否成功
*說明:涉及表名[useradmin,position]
*********************************/
(
@UserNo varchar(10)
)
as
Select P.Position_name from UserAdmin U Inner Join Position P on U.Position_no=P.Position_no Where User_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectPostionFromCompanyNOAndDeptNo
/********************************
*介紹:辦公自動化OA系統 (選擇職位列表)
*作者:Billy
*書寫時間:2006/07/24
*傳入:公司代號,部門代號
*返回:部門列表
*說明:涉及表名[dept,record]
*********************************/
(
@CompanyNo varchar(10),
@DepartMentNo varchar(10)
)
as
Select position_no,position_name From position Where Position_no In (select Position_no from UserAdmin Where company_no=@CompanyNo and dept_no=@DepartMentNo)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectProcessBillsMyCreate
/********************************
*介紹:查詢正在處理中的異常單據列表<我的異常單>
*作者:Billy
*書寫時間:2006/07/03
*傳入:用戶NO
*返回:正在處理的異常單據列表
*說明:涉及表名[bill_m_approve]
*********************************/
(
@UserNo varchar(20),
@PageSize int=10, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output --總頁數據 傳入0時可返回頁總數
)
as
declare @sSql varchar(500)
set @sSql='select C.company_nm,M.company_no,B.kind_nm,M.kind_no,M.bill_no,dbo.fn_bill_ConvertStatus(M.status) status,'
+ 'dbo.fn_ConvertExigencyGrade(M.exigency_grade) exigency_grade,'
+ 'Convert(varchar(19),M.create_date,120) Create_Date from bill_m_approve M inner join company C on M.company_no=C.company_no inner join bill_kind B on M.company_No=B.company_No and M.kind_no=B.kind_no'
if @UserNo is null
return 1
else
set @sSql=@sSql+' where M.create_person='''+@UserNo+''''
---調用分頁存儲過程進行分頁處理
exec pr_SelectDataPager @sSql,@PageSize,@PageCurrent,@PageCount=@PageCount output,@ShowFields='',@OrderFields='create_date desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectProductKindList
/********************************
*介紹:辦公自動化OA系統 (查詢產品類型列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_kind,record]
*********************************/
as
select product_no,kind_nm from product_kind
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectProductStyleFromProduct
/********************************
*介紹:辦公自動化OA系統 (查詢機型檔案列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_style,record]
*********************************/
(
@ProductNo varchar(10)
)
as
if @ProductNo=''
select style_no,style_nm from product_style
else
select style_no,style_nm from product_style where product_no=@ProductNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectProductStyleList
/********************************
*介紹:辦公自動化OA系統 (查詢機型檔案列表)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_style,record]
*********************************/
as
select style_no,style_nm from product_style
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectSearchData
/***********************************************************
*介紹:得到單據查詢的查詢條件
*作者:電腦混混Vincent
*書寫時間:2006/07/06
*傳入:
*返回:列表1:公司列表;
列表2:單據類型列表;
列表3:審核動作列表
************************************************************/
as
-------公司信息
select company_no,company_nm from company
-------單據類型
select kind_no,kind_nm from bill_kind
-------審核動作
select action_seq,action_nm from action_kind
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_SelectUserFromCompanyAndDept
/********************************
*介紹:辦公自動化OA系統 (根據公司和部門查詢用戶資料)
*作者:Billy
*書寫時間:2006/08/15
*傳入:用戶列表
*返回:
*說明:涉及表名[useradmin, dept, position]
*********************************/
(
@CompanyNo varchar(10) = '', --查詢的公司代號
@DeptNo varchar(10) = '', --查詢的部門代號
@SearchUser varchar(20) = '', --查詢的用戶姓名或代號
@FiltrateDisableUser char(1) = 'N', --是否過濾失效的用戶
@FiltrateNoApproveUser char(1) = 'N', --是否過濾無審核權限的用戶
@FiltrateWindow char(1) = 'N', --是否只查找窗口人
@PageSize int=25, --每頁的大小(行數)
@PageCurrent int=1, --要顯示的頁
@PageCount int=1 Output --總頁數據, 傳入0時可返回頁總數
)
as
declare @Sql varchar(500)
Set @Sql = 'Select U.Company_no, U.user_no, U.user_name, U.Approve_grade,'
+ 'dbo.fn_DepartmentFrame(U.company_no,U.dept_no) Department, P.Position_name,U.tel,U.email,U.window,'
+ 'dbo.fn_CheckUserStatus(U.status,getdate(),U.active_date,U.disable_date) Status From UserAdmin U '
+ 'Inner Join Position P on U.position_no = P.position_no where 1=1 '
Select @CompanyNo = Replace(@CompanyNo, '''', ''''''), @DeptNo = Replace(@DeptNo, '''', ''''''), @SearchUser = Replace(@SearchUser, '''', '''''')
If( @FiltrateWindow = 'Y' )
Set @Sql = @Sql + ' And U.window=1'
if( @SearchUser != '' )
Set @Sql = @Sql + ' And ( U.User_no Like ''%' + @SearchUser + '%'' Or U.User_name Like ''%' + @SearchUser + '%'' )'
if( @CompanyNo != '' )
Set @Sql = @Sql + ' And U.Company_no = ''' + @CompanyNo + ''''
if( @DeptNo != '' )
Set @Sql = @Sql + ' And U.Dept_no = ''' + @DeptNo + ''''
if( @FiltrateDisableUser = 'Y' ) --過濾失效的用戶
Set @Sql = @Sql + ' And OA.dbo.fn_CheckUserStatus(U.status, getDate(),U.active_date,U.disable_date) = ''Y'''
if( @FiltrateNoApproveUser = 'Y' ) --過濾無審核權限的用戶
Set @Sql = @Sql + ' And U.Approve_Grade > 0 '
exec pr_SelectDataPager @Sql, @PageSize, @PageCurrent, @PageCount out, '','Department'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectUserFromCondition
/********************************
*介紹:辦公自動化OA系統 (取指定條件的用戶信息)
*作者:Billy
*書寫時間:2006/08/25
*參數:@UserNo 用戶代號
*說明:表:UserAdmin, Position, Dept, Company
*********************************/
(
@Company Varchar(60) = '',
@Dept varchar(60) = '',
@User Varchar(20) = '',
@PageIndex int = 1,
@PageSize int = 10 ,
@PageCount int = 1 output
)
as
Declare @Sql varchar(4000)
Set @Sql = 'SELECT U.user_no, U.user_name, U.tel, U.email, U.approve_grade, U.role_level, U.mark_name, U.active_date, U.disable_date, U.window,'
+ ' C.company_nm, P.position_name, D.dept_no,D.dept_nm,U.Company_no , dbo.fn_Departmentframe(u.company_no, u.dept_no) DepartMent, '
+ ' dbo.fn_CheckUserStatus(U.status, getdate(), U.active_date, U.disable_date) status '
+ ' FROM UserAdmin U '
+ ' Left OUTER JOIN dept D On U.Dept_no = D.Dept_no '
+ ' Left OUTER JOIN Company C ON U.Company_no = C.Company_no '
+ ' LEFT OUTER JOIN [position] P ON U.position_no = P.position_no '
+ ' Where (C.company_nm like ''%' + @Company + '%'' Or U.company_no like ''%' + @Company + '%'') '
+ ' and (D.dept_nm like ''%' + @Dept + '%'' or U.dept_no like ''%' + @Dept + '%'') '
+ ' and (U.user_name like ''%' + @User + '%'' or U.user_no like ''%' + @User + '%'') '
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', 'DepartMent, Approve_grade, position_name'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectUserFromUserNo
/*
根據用戶代號取得用戶信息
*/
(
@UserNo varchar(20)
)
as
Select U.*, C.Company_nm, D.Dept_nm, P.Position_name, OA.dbo.fn_DepartmentFrame(U.company_no,U.dept_no) Department ,
OA.dbo.fn_Dept_GetChiefDeptNo(U.company_no, U.dept_no) ChiefDeptNo
From UserAdmin U
Left Join Company C on U.Company_no = C.Company_no
Left Join Dept D on U.Company_no = D.Company_no And U.dept_no = D.dept_no
Left Join Position P on U.position_no = P.position_no
Where U.user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectUserInfoFromUserNo
/********************************
*介紹:辦公自動化OA系統 (取得某位用戶的相關信息)
*作者:Billy
*書寫時間:2006/08/19
*參數:
*說明:
*********************************/
@UserNo varchar(20)
as
Select U.*, C.Company_nm, C.Short_Code, OA.dbo.fn_Dept_GetChiefShortCode(d.company_no, d.dept_no) Chief_Short_Code,
D.Dept_nm, P.Position_name, OA.dbo.fn_DepartmentFrame(U.company_no,U.dept_no) Department, G.group_nm
From UserAdmin U
Left outer Join Company C on U.Company_no = C.Company_no
Left outer Join Dept D on U.Company_no = D.Company_no And U.dept_no = D.dept_no
Left outer Join Position P on U.position_no = P.position_no and U.company_no = P.company_no
Left outer Join Group_Setting G On U.group_no = G.Group_no and U.company_no = G.company_no
Where U.user_no = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectUserList
/********************************
*介紹:辦公自動化OA系統 (用戶列表)
*作者:Billy
*書寫時間:2006/07/04
*參數:
*說明:
*********************************/
as
Select U.user_no, u.user_name, u.tel, U.email, dbo.fn_checkuserstatus(U.status, getdate(), active_date, disable_date) status, C.Company_nm, D.Dept_nm, P.Position_name, OA.dbo.fn_DepartmentFrame(U.company_no, U.dept_no) Department
From UserAdmin U
Inner Join Company C on U.Company_no = C.Company_no
Inner Join Dept D on U.Company_no = D.Company_no And U.dept_no = D.dept_no
Inner Join Position P on U.position_no = P.position_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectUserListForFilter
/********************************
*介紹:辦公自動化OA系統 (取得指定部門及其所有下屬部門的人員信息)
*作者:Billy
*書寫時間:2006/08/29
*參數:@UserNo
*說明:使用表:UserAdmin, Dept, Position
*********************************/
(
@UserNo varchar(20),
@SearchUser varchar(20) = '',
@FilterDepartMent bit = 1, ---是否只顯示本部門及其下屬部門人員
@PageSize int = 25,
@PageIndex int = 1,
@PageCount int = 1 out
)
as
Declare @Sql varchar(8000)
Declare @List varchar(2000)
Set @SearchUser = Replace(IsNull(@SearchUser, ''), '''', '''''')
Set @Sql ='Select U.company_no,U.user_no, U.User_name,U.Approve_Grade,dbo.fn_DepartMentFrame(u.company_No, u.dept_no) Department, '
+ ' P.Position_name,U.Tel, U.email, dbo.fn_CheckUserStatus(U.status,getdate(),U.active_date, U.disable_Date) status From UserAdmin U '
+ ' Left Join Position P on U.position_no = P.position_no and u.company_no = P.company_no'
+ ' Where U.User_no <> ''' + @UserNo + ''''
if( @SearchUser != '' )
Set @Sql = @Sql + ' and (U.User_no Like ''%' + @SearchUser + '%'' Or U.User_name Like ''%' + @SearchUser + '%'') '
if( @FilterDepartMent = 1 ) --只顯示本單位及下屬單位人員
Begin
Set @List = ''
--取得本單位及下屬單位的部門代號列表
Select @List = dbo.fn_Dept_GetAllChildDeptNo(company_no,dept_no) From UserAdmin Where User_no = @UserNo
Set @List = '''' + Replace(@List, ',',''',''') + ''''
Set @Sql = @Sql + ' and U.dept_no in (' + @List + ') '
End
--調用分頁存儲過程
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', 'Department'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectUserListForSelectAssistant
/********************************
*介紹:得到用戶列表以供用戶選擇工作助手
*作者:Billy
*書寫時間:2006/08/29
*參數:@UserNo
*說明:使用表:UserAdmin, Dept, Position
*********************************/
(
@UserNo varchar(20),
@PageIndex int = 1,
@PageSize int = 25,
@pageCount int = 0 out
)
as
Declare @Sql varchar(8000)
Declare @List varchar(2000)
Set @List = ''
Select @List = dbo.fn_Dept_GetAllChildDeptNo(company_no,dept_no) From UserAdmin Where User_no = @UserNo
Set @List = '''' + Replace(@List, ',',''',''') + ''''
Set @Sql ='Select U.user_no, U.User_name, D.Dept_nm, P.Position_name, U.Tel, U.email From UserAdmin U
Left Join Position P on U.position_no = P.position_no
Inner join Dept D on U.Dept_no = D.dept_no
Where U.dept_no in (' + @List + ') And user_no != ''' +@UserNo + ''' and U.User_no Not in (select Assistant_No From Assistant Where Director_no = ''' + @UserNo + ''')'
--調用分頁存儲過程
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_SelectUserMarkName
/********************************
*介紹:辦公自動化OA系統 (查詢用戶名稱)
*作者:電腦混混Vincent
*書寫時間:2006/06/26
*傳入:單據NO
*返回:異常單據詳細信息
*說明:涉及表名[useradmin]
*********************************/
(
@UserNo varchar(20),
@MarkName varchar(60) out
)
as
select @MarkName=mark_name from useradmin where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectUserName
/********************************
*介紹:辦公自動化OA系統 (根據用戶代號取得用戶姓名)
*作者:Billy
*書寫時間:2006/06/20
*參數:@UserNo --數據表名稱
*說明:
*********************************/
(
@UserNo varchar(20)
)
as
select user_name from useradmin where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_SelectWindowList
/********************************
*介紹:辦公自動化OA系統 (用戶列表)
*作者:Billy
*書寫時間:2006/07/04
*參數:
*說明:
*********************************/
as
Select win_no, win_nm, win_note, parent_win_no, c_visible, seq From Menu_List
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_Setting_Group_Delete
------------------刪除指定@group_no的記錄
@CompanyNo varchar(10),
@GroupNo varchar(6),
@ErrorNo varchar(100) output
as
Declare @Rows int
if( Exists(select * from useradmin where group_no=@GroupNo and company_no = @CompanyNo) )
begin
set @ErrorNo='CanNotDelete'
return 0
end
if( Not Exists(select * from group_setting where group_no=@GroupNo and Company_no = @CompanyNo) )
begin
set @ErrorNo='UnFound'
return 0
end
delete from group_setting where group_no=@GroupNo and Company_no = @CompanyNo
Set @Rows = @@RowCount
if( @Rows < 1 )
Set @ErrorNo = 'UnDelete'
return @Rows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Setting_InsertUserGroup
/********************************
*介紹:新增用戶組信息
*作者:Billy
*書寫時間:2006/12/19
*********************************/
(
@CompanyNo varchar(10),
@GroupNO varchar(6),
@GroupName varchar(30),
@ErrorNo Varchar(50) out
)
as
Declare @Rows int
--檢查是否已存在
if( Exists(Select * From Group_Setting Where Company_No = @CompanyNo and Group_No = @GroupNo) )
Begin
Set @ErrorNo = 'ExistsNo'
return 0
End
if( Exists(Select * From Group_Setting Where Company_No = @CompanyNo and Group_NM = @GroupName) )
Begin
Set @ErrorNo = 'ExistsName'
return 0
End
--開始插入
Insert Into Group_Setting (company_no , group_no, group_nm) values (@CompanyNo, @GroupNo, @GroupName)
Set @Rows = @@RowCount
if( @Rows < 1 )
Set @ErrorNo = 'Failing'
Return @Rows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Setting_SelectUserGroupFromPage
/********************************
*介紹:新增用戶組信息
*作者:Billy
*書寫時間:2006/12/19
*********************************/
(
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
as
Declare @Sql NVarchar(100)
Set @Sql = 'Select G.*, C.Company_Nm From Group_Setting G Inner Join Company C On G.Company_no = C.Company_No'
Exec Pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', 'Company_no, group_no'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Setting_UpdateUserGroup
/********************************
*介紹:新增用戶組信息
*作者:Billy
*書寫時間:2006/12/19
*********************************/
(
@CompanyNo varchar(10),
@GroupNo varchar(6),
@GroupName varchar(30),
@ErrorNo Varchar(50) out
)
as
Declare @Rows int
--檢查是否已存在
if Exists(Select * From Group_Setting Where Group_Nm = @GroupName and Company_No = @CompanyNo and Group_No != @GroupNo )
Begin
Set @ErrorNo = 'ExistsName'
return 0
End
--開始更新
Update Group_Setting Set group_nm = @GroupName Where Company_no = @CompanyNo And Group_no = @GroupNo
Set @Rows = @@RowCount
if( @Rows < 1 )
Set @ErrorNo = 'Failing'
Return @Rows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_System_Affiche_Delete
/*********************
* 功能:刪除指定的系統公告(新增/更新)
* 作者:Billy
* 日期:2007/01/25
**********************/
(
@SeqList varchar(500), --要刪除公告的Seq列表,如1,2,3
@DeleteCount int out --返回被刪除的記錄數
)
As
Declare @Sql nVarchar(1000)
Set @DeleteCount = 0
Set @Sql = N'Delete System_Affiche Where Seq In(' + @SeqList + ') Set @DeleteCount = @@RowCount'
Execute sp_ExecuteSql @Sql, N'@DeleteCount int out', @DeleteCount out
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_System_Affiche_Save
/*********************
* 功能:保存系統公告(新增/更新)
* 作者:Billy
* 日期:2007/01/25
**********************/
(
@Operate bit, --操作模式:1新增, 0更新
@Seq int = 0, --更新公告的Seq,新增時不需提供
@Subject varchar(50), --標題
@Content varchar(6000), --內容
@Display bit = 1, --是否顯示
@BeginDate DateTime, --開始顯示的時間
@ShowDays int, --顯示的天數
@Result char(1) out --返回結果代號 0: 保存失敗, 1:保存成功, 2:記錄不存在, 3:資訊不完整, 4:參數不正確
)
As
Declare @RowCount int
Set @Result = '0'
Set @RowCount = 0
if LTrim(@Subject) = '' Or Ltrim(@Content) = '' or @ShowDays is null
Begin
Set @Result = '3'
return 0
End
if( @Operate = 0 ) --更新
Begin
if Not Exists(Select Subject From System_Affiche Where Seq = @Seq)
Begin
--記錄不存在
Set @Result = '2'
return 0
End
Update System_Affiche
Set Subject = @Subject, Content = @Content, Display = @Display, Begin_date =@BeginDate, show_days = @ShowDays
Where Seq = @Seq
Set @RowCount = @@RowCount
if( @RowCount < 1 )
Set @Result = '0'
Else
Set @Result = '1'
return @RowCount
End
/*********新增*****************/
--取得最大的Seq值
if( @Operate = 1 ) --增加
begin
Select @Seq = Max(Seq) From System_Affiche
Set @Seq = IsNull(@Seq, 0) + 1
Insert Into System_Affiche (Seq,Subject, Content, Display, Begin_Date, Show_Days, Issue_Date)
Values(@Seq,@Subject, @Content, @Display, @BeginDate, @ShowDays, getDate())
Set @RowCount = @@RowCount
if( @RowCount > 0 )
Set @Result = '1'
Else
Set @Result = '0'
Return @Seq
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create proc pr_System_Affiche_Select
/*********************
* 功能:取得本日需要顯示的系統公告列表
* 作者:Billy
* 日期:2007/01/25
**********************/
As
Declare @Date dateTime
Set @Date = GetDate()
Select * From System_Affiche Where Begin_date >= @Date and DateAdd(day, Show_Days, Begin_Date) <= @Date
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_System_Affiche_Select_Page
/*********************
* 功能:取得指定頁的公告記錄
* 作者:Billy
* 日期:2007/01/25
**********************/
(
@PageIndex int =1, --頁索引
@PageSize int = 25, --每頁顯示的記錄數
@PageCount int = 1 out --頁總數
)
As
Exec pr_SelectDataPager 'System_Affiche', @PageSize, @PageIndex, @PageCount out, '', 'Seq Desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_System_SendMessage
/********************************
* 功能:系統管理員信息/郵件群發,如果為發信息,則在本程序內部完成,如為Email則返回符合條件的Email列表
* 作者: Billy
* 日期:2006/12/22
**********************************/
(
@SendUserNo VarChar(20),
@Accounts VarChar(5000),
@CompanyNo VarChar(10),
@Target VarChar(20),
@SendMode Char(1), --1:所有人, 2:按公司, 3:按部門, 4:按用戶組, 5:按帳號, 6在線用戶
@Include Bit, --是否包含下屬部門
@SendType Bit, -- 1:發郵件 , 0: 發系統內部信息
@Subject NVarChar(50),
@Content NVarChar(500),
@Emphasis bit = 0,
@ErrorNo VarChar(50) out
)
AS
Declare @tbUser Table(ID int IDentity(1,1), User_No varchar(20), Email varchar(50))
Declare @TempValue varchar(5000)
Declare @Sql nVarchar(4000), @ID int
Create Table #tbUser(ID int IDentity(1,1), User_No varchar(20), Email varchar(50))
if( @SendMode = '1' ) --All User
Begin
Insert Into #tbUser Select User_No, Email From UserAdmin Where Email <> '' And Email Is Not Null
GoTo SendMessage
End
if( @SendMode = '2' ) -- From Company
Begin
Insert Into #tbUser Select User_No, Email From UserAdmin
Where Company_No = @CompanyNo And Email <> '' And Email Is Not Null
GoTo SendMessage
End
If( @SendMode = '3' ) --From DepartMent
Begin
if( @Include = 1 ) --包含下屬部門
Begin
Set @TempValue = dbo.fn_Dept_GetAllChildDeptNo(@CompanyNo, @Target)
Set @TempValue = '''' + Replace(@TempValue, ',', ''',''') + ''''
Set @Sql = N'Select User_no, Email From UserAdmin Where company_no = ''' + @CompanyNo + ''' and Dept_no in(' + @TempValue + ') And Email <> '''' And Email Is Not Null'
Insert Into #tbUser Exec sp_ExecuteSql @Sql
GoTo SendMessage
End
--不包含下屬部門
Insert Into #tbUser Select User_No, Email From UserAdmin
Where Company_No = @CompanyNo And Dept_no = @TarGet And Email <> '' And Email Is Not Null
GoTo SendMessage
End
if( @SendMode = '4' ) -- From UserGroup
Begin
Insert Into #tbUser Select User_No, Email From UserAdmin
Where Company_No = @CompanyNo And Group_No = @TarGet And Email <> '' And Email Is Not Null
Goto SendMessage
End
if( @SendMode = '5' ) -- From Accounts
Begin
Set @Accounts = Replace(@Accounts, ' ', '')
Set @Accounts = Replace(@Accounts, ';', ',')
Set @Accounts = '''' + Replace(@Accounts, ',', ''',''') + ''''
Set @Sql = N'Select User_no, Email From UserAdmin Where User_No In(' + @Accounts + ') And Email <> '''' And Email Is Not Null'
Insert Into #tbUser Exec sp_ExecuteSql @Sql
Goto SendMessage
End
if( @SendMode = '6' ) --Online User
Begin
Insert Into #tbUser Select O.user_no, U.email From Online_User O inner join UserAdmin U On O.user_no = U.user_no
GoTo SendMessage
End
SendMessage:
If( @SendType = 1 ) -- 發送郵件,此處返回不重復的郵件列表
Begin
Select Distinct Email From #tbUser
Drop Table #tbUser
return 0
End
if( Not Exists( Select * From #tbUser ) )
Begin
Set @ErrorNo = 'UnFound'
return 0
End
--Send Message
Begin Transaction
Insert Into Message_Content (send_user_no, subject, content, send_date, emphasis)Values
(@SendUserNo, @Subject, @Content, getDate(), @Emphasis)
Set @ID = @@IDentity
If( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing'
goTo Roll
End
Insert Into Message_Person Select Distinct @ID, User_no, 0, getdate() From #tbUser
If( @@Error <> 0 )
Begin
Set @ErrorNo = 'Failing'
Goto Roll
End
Commit Transaction
Drop Table #tbUser
return 1
Roll:
Rollback Transaction
Drop Table #tbUser
return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create proc pr_Technic_DeleteItem
/****************************
* 功能:刪除內容
* 作者:Billy
* 日期:2006/09/11
****************************/
(
@ItemNo int,
@UserNo varchar(20)
)
AS
Delete From TechnicItem Where item_no = @ItemNo And user_no = @UserNo
Return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_Technic_DeleteType
/****************************
* 功能:刪除分類
* 作者:Billy
* 日期:2006/09/09
****************************/
(
@UserNo varchar(20),
@TypeNo int,
@ErrorMessage nvarchar(50) out
)
As
Declare @RowCount int
select @ErrorMessage = '', @RowCount = 0
--檢查是否存在下屬分類,如果存在則不進行刪除
If Exists(Select * From TechnicType Where Parent_Type_no = @TypeNo And User_no = @UserNo)
Begin
Set @ErrorMessage = 'CanNotDelete'
Set @RowCount = 0
GoTo ExitProc
End
--檢查是否存在項目內容
if Exists( Select * From TechnicItem Where Type_no = @TypeNo And User_no = @UserNo)
Begin
Set @ErrorMessage = 'CanNotDelete'
Set @RowCount = 0
GoTo ExitProc
End
Delete TechnicType Where User_no = @UserNo And Type_no = @TypeNo
Set @RowCount = @@RowCount
ExitProc:
return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create proc pr_Technic_InsertNewItem
/****************************
* 功能:插入新的內容
* 作者:Billy
* 日期:2006/09/09
****************************/
(
@TypeNo int,
@ItemNo int Out,
@UserNo varchar(20),
@Title nvarchar(50),
@Content nText
)
As
Declare @Seq int, @InsertRow int, @Text varbinary(16)
Set @Seq = 0
Begin Transaction
Select @Seq = Max(item_no) From TechnicItem
Set @Seq = IsNull(@Seq, 0) + 1
Set @ItemNo = @Seq
Insert Into TechnicItem (item_no, type_no, user_no, title, content, create_date, modify_date)
Values(@Seq, @TypeNo, @UserNo, @Title, '', GetDate(), GetDate())
--取得新記錄指針
Select @Text = TextPtr(Content) From TechnicItem Where item_no = @Seq
--寫入文本
WriteText TechnicItem.Content @Text @Content
if @@Error = 0
Begin
Commit Transaction
set @InsertRow = 1
End
else
Begin
RollBack Transaction
Set @InsertRow = 0
End
return @InsertRow
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Technic_InsertNewType
/****************************
* 功能:插入新的分類
* 作者:Billy
* 日期:2006/09/09
****************************/
(
@UserNo varchar(20),
@TypeName nvarchar(30),
@ParentTypeNo int
)
As
Declare @Seq int
Set @Seq = 0
Select @Seq = Max(Type_No) From TechnicType Where User_No = @UserNo
Set @Seq = IsNull(@Seq, 0) + 1
Insert Into TechnicType (type_no, user_no, type_name, parent_type_no)
Values( @Seq, @UserNo, @TypeName, @ParentTypeNo)
return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Technic_SelectType
/****************************
* 功能:選擇分類
* 作者:Billy
* 日期:2006/09/09
****************************/
(
@UserNo varchar(20)
)
as
Select Type_no, Type_Name As TypeName, User_No, Parent_Type_no From TechnicType T Where User_no = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Technic_UpDateType
/****************************
* 功能:更新分類信息
* 作者:Billy
* 日期:2006/09/09
****************************/
(
@UserNo varchar(20),
@TypeNo int,
@TypeName nvarchar(30),
@ParentTypeNo int
)
As
Update TechnicType Set Type_Name = @TypeName, Parent_Type_no = @ParentTypeNo Where Type_no = @TypeNo And user_no = @UserNo
return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_Technic_UpDateTypeName
/****************************
* 功能:更新分類名稱
* 作者:Billy
* 日期:2006/09/09
****************************/
(
@UserNo varchar(20),
@TypeNo int,
@TypeName nvarchar(30)
)
As
Update TechnicType Set Type_Name = @TypeName Where Type_no = @TypeNo And user_no = @UserNo
return @@RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_Technic_UpdateItem
/****************************
* 功能:更新內容
* 作者:Billy
* 日期:2006/09/11
****************************/
(
@ItemNo int,
@TypeNo int,
@UserNo varchar(20),
@Title nvarchar(50),
@Content ntext,
@ErrorNo varchar(50) out
)
As
Declare @Text varbinary(16), @ResultRow int
if Not Exists(Select type_no From TechnicItem Where Item_no = @ItemNo And User_no = @UserNo)
Begin
set @ResultRow = 0
set @ErrorNo = 'UnFound'
Goto ExitProc
End
Begin Transaction
--取得記錄的Content字段指針
Select @Text = TextPtr(Content) From TechnicItem Where Item_no = @ItemNo And User_no = @UserNo
UpDate TechnicItem Set Type_no = @TypeNo, title = @Title, Modify_Date = getDate()
Where Item_no = @ItemNo And User_no = @UserNo
WriteText TechnicItem.Content @Text @Content
if @@Error = 0
Begin
Set @ResultRow = 1
Set @ErrorNo = 'Saved'
Commit Transaction
Goto ExitProc
End
Else
Begin
Set @ResultRow = 0
RollBack Transaction
Set @ErrorNo = 'Failing'
Goto ExitProc
End
ExitProc:
Return @ResultRow
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_UpdateActionKind
@CompanyNo varchar(10),
@ActionSeq int,
@ActionNm varchar(20),
@PRI int,
@Approve char(1),
@ErrorNo varchar(100) output
as
if Exists(select count(*) from action_kind where (company_no=@CompanyNo and action_nm=@ActionNm and action_seq<>@actionseq) or (company_no=@CompanyNo and PRI=@PRI and action_seq<>@actionseq))
begin
set @ErrorNo = 'Existed'
return 0
End
update action_kind set company_no=@CompanyNo, action_nm=@ActionNm, approve=@Approve, PRI=@PRI where action_seq=@ActionSeq
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_UpdateAffiche
/********************************
*介紹:辦公自動化OA系統 (更新公告主檔資訊)
*作者:william
*書寫時間:2007/05/
*說明:涉及表名[Affiche]
*********************************/
(
@Affiche_ID int Output,
@Title varchar(100),
@Content varchar(6000),
@LeaveWord bit,
@Everyone bit,
@Importance_Level char(1),
@Issue_Person varchar(20),
@ErrorNo varchar(50) out
)
AS
if(@Affiche_ID=0)
begin
declare @Seq int
exec pr_getTableSeq 'Affiche','Affiche_ID',@Seq out
insert into Affiche (Affiche_ID,Title,Content,LeaveWord,Everyone,Importance_Level,Issue_Person,Issue_date)
values (@Seq,@Title,@Content,@LeaveWord,@Everyone,@Importance_Level,@Issue_Person,getdate())
set @Affiche_ID = @Seq
end
else
if(exists(select * from Affiche where Affiche_ID=@Affiche_ID))
begin
update Affiche
set Title = @Title,
Content = @Content,
LeaveWord = @LeaveWord,
Everyone = @Everyone,
Importance_Level = @Importance_Level
where Affiche_ID = @Affiche_ID
return 1
end
else
begin
set @ErrorNo='未找到相關數據'
return 0;
end
if(@@error<>0)
begin
set @ErrorNo='數據更新失敗'
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_UpdateBillFlowMode
/********************************
*介紹:辦公自動化OA系統 (更新單據流程)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[bill_flow_m,record]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@FlowMode char(1),
@Note varchar(100)
)
as
update bill_flow_m set flow_mode=@FlowMode , note=@Note
where company_no=@CompanyNo and kind_no=@KindNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_UpdateBillKindInfo
/********************************
*介紹:辦公自動化OA系統 (更新單據類型相關信息)
*作者:Billy
*書寫時間:2006/05/29
*說明:涉及表名[bill_kind,record]
*********************************/
(
@CompanyNo varchar(10),
@KindNo varchar(10),
@KindShortCode varchar(2),
@KindName varchar(60),
@EffectValidate char(1),
@EffectValidateChoose char(1),
@Formula varchar(200),
@Note varchar(60),
@ModifyPerson varchar(20),
@ErrorNo varchar(50) out
)
as
Declare @RowCount int
--數據完整性檢查
if( Ltrim(@KindNo) = '' )
Begin
Set @ErrorNo = 'UnInputNo'
Return 0
End
if( LTrim(@KindShortCode) = '')
Begin
Set @ErrorNo = 'UnInputNo'
return 0
End
--簡碼是否被占用
if( Exists( Select * From Bill_Kind Where Company_no = @CompanyNo And kind_Short_Code = @KindShortCode And Kind_No != @KindNo) )
Begin
Set @ErrorNo = 'ExistsCode'
return 0
End
update bill_kind set kind_nm=@KindName, kind_short_code = @KindShortCode, effect_validate=@EffectValidate, effect_validate_choose = @EffectValidateChoose,
formula = @Formula, note=@Note,modify_person=@ModifyPerson,modify_date=getdate()
where kind_no=@KindNo and company_no=@CompanyNo
Set @RowCount = @@RowCount
if(@RowCount < 1 )
Set @ErrorNo = 'Failing'
return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE ProcEDURE pr_UpdateCommonPhrase
@Seq INT,
@PhraseContent VARCHAR(200)
AS
DECLARE @error INT
SET @error = 0
BEGIN TRANSACTION
UPDATE use_phrase SET phrase_content=@PhraseContent WHERE seq=@Seq
IF(@@ERROR<>0)
SET @error = 1
IF(@error=0)
COMMIT TRANSACTION
ELSE
ROLLBACK TRANSACTION
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_UpdateCompanyInfo
/********************************
*介紹:辦公自動化OA系統 (更新指定的公司信息)
*作者:Billy
*書寫時間:2006/05/29
*傳入:公司代號,公司名稱,負責人,電話,傳真,地址,備注,操作者
*返回:是否更新成功 0:否;1:是
*說明:涉及表名[company,record]
*********************************/
(
@CompanyNo varchar(10),
@ShortCode char(1),
@CompanyName varchar(60),
@Boss varchar(20),
@Tel varchar(20),
@Fax varchar(20),
@Address varchar(80),
@Note varchar(100),
@ModifyPerson varchar(20),
@ErrorNo varchar(50) out
)
as
Declare @Rows int
--先檢查公司簡碼是否已被占用
if( Exists(Select * From Company Where Company_No != @CompanyNo and Short_code = @ShortCode) )
Begin
Set @ErrorNo = 'ExistsCode'
return 0
End
if Exists( Select company_no From Company Where Company_no != @CompanyNo and Company_nm = @CompanyName)
Begin
Set @ErrorNo = 'ExistsName'
return 0
End
update company
set short_code = @ShortCode, company_nm = @CompanyName, boss = @Boss, tel = @Tel,
fax = @Fax, address = @Address, note = @Note, modify_person = @ModifyPerson
where company_no = @CompanyNo
set @Rows = @@RowCount
if( @Rows < 1 )
Set @ErrorNo = 'Failing'
return @Rows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_UpdateDepartmentInfo
/********************************
*介紹:辦公自動化OA系統 (更新指定的部門信息)
*作者:Billy
*書寫時間:2006/05/29
*傳入:公司代號,部門代號,部門名稱,負責人,電話,上級部門代號,
備注,修改人,操作窗口
*返回:更新是否成功
*說明:涉及表名[dept,record]
*********************************/
(
@CompanyNo varchar(10),
@DepartmentNo varchar(10),
@ChiefShortCode Char(1),
@DepartmentName varchar(60),
@DepthNo varchar(10),
@IsChief char(1),
@Boss varchar(20),
@Tel varchar(20),
@ParentDepartmentNo varchar(10),
@Note varchar(100),
@ModifyPerson varchar(20),
@ErrorNo varchar(50) out
)
as
Declare @RowCount int
--當部門為非處級單位時,忽略掉簡碼
if( @IsChief != 'Y' )
Set @ChiefShortCode = ''
else
Begin
--檢查選擇了處級單位時是否輸入處級簡碼
if( Ltrim(@ChiefShortCode) = '' )
Begin
Set @ErrorNo = 'UnInput'
return 0
End
--查詢處級簡碼是否被占用
if Exists( Select * From Dept Where Company_No = @CompanyNo And Dept_No != @DepartMentNo And chief_short_code = @ChiefShortCode)
Begin
Set @ErrorNo = 'ExistsCode'
return 0
End
end
update dept set dept_nm = @DepartmentName,
dept_level_no = @DepthNo,
chief_short_code = @ChiefShortCode,
chief_flag = @IsChief,
boss = @Boss,
tel = @Tel,
parent_dept_no = @ParentDepartmentNo,
note = @Note,
modify_person = @ModifyPerson,
company_no = @CompanyNo
where dept_no = @DepartmentNo And Company_no = @CompanyNo
Set @RowCount = @@RowCount
if @RowCount < 1
Set @ErrorNo = 'Failing'
return @RowCount
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_UpdateErrorCodeInfo
/********************************
*介紹:辦公自動化OA系統 (更新品質異常對照檔)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[error_code,record]
*********************************/
(
@ProductNo varchar(10),
@ErrorNo varchar(10),
@ErrorName varchar(100),
@Note varchar(60),
@Operator varchar(20)
)
as
update error_code set product_no=@ProductNo,error_nm=@ErrorName,note=@Note,modify_person=@Operator
where error_no=@ErrorNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_UpdateMenuItemInfo
/********************************
*介紹:辦公自動化OA系統 (更新指定的菜單項)
*作者:Billy
*書寫時間:2006/06/10
*傳入:
*說明:涉及表名[menu_list,record]
*********************************/
(
@WindowNo varchar(20),
@WindowName varchar(60),
@WindowNote varchar(200),
@ParentWindowNo varchar(20),
@EveryOne char(1),
@Visible char(1),
@Seq int=1 ,
@KindNo varchar(10) ,
@LargeIcon varchar(60),
@OpenType char(1)='1',
@ProgramPath varchar(60)='',
@ModifyPerson varchar(20)
)
as
update menu_list set win_nm=@WindowName,win_note=@WindowNote,parent_win_no=@ParentWindowNo,
c_everyone = @EveryOne, c_visible=@Visible,seq=@Seq,kind_no=@KindNo,
large_icon=@LargeIcon,open_type=@OpenType,program_path=@ProgramPath,
modify_person=@ModifyPerson where win_no=@WindowNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
---------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_UpdatePositionInfo
/********************************
*介紹:辦公自動化OA系統 (根據職務代碼更新職務信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:職位代號,職位名稱,備注,修改人,操作者,操作窗口
*返回:更新是否成功
*說明:涉及表名[position,record]
*********************************/
(
@CompanyNo varchar(10),
@PositionNo varchar(10),
@PositionName varchar(30),
@DepthNo varchar(10),
@IsDirector char(1),
@ApproveFile char(1),
@Note varchar(100),
@ModifyPerson varchar(20)
)
as
update position set position_name = @PositionName,
depth_no = @DepthNo,
dept_director = @IsDirector,
approve = @ApproveFile,
note = @Note,
modify_person = @ModifyPerson,
modify_date = getdate()
where position_no = @PositionNo and company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_UpdateProductKindInfo
/********************************
*介紹:辦公自動化OA系統 (更新產品類型信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_kind,record]
*********************************/
(
@ProductNo varchar(10),
@KindName varchar(30),
@Note varchar(60),
@Operator varchar(20)
)
as
update product_kind set product_no=@ProductNo,kind_nm=@KindName,note=@Note,modify_person=@Operator
where product_no=@ProductNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_UpdateProductStyleInfo
/********************************
*介紹:辦公自動化OA系統 (更新指定的機型檔案信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*
*說明:涉及表名[product_style,record]
*********************************/
(
@ProductNo varchar(10),
@StyleNo varchar(10),
@StyleName varchar(30),
@Note varchar(60),
@ModifyPerson varchar(20)
)
as
update product_style set product_no=@ProductNo,style_nm=@StyleName,note=@Note,modify_person=@ModifyPerson
where style_no=@StyleNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_UpdateUserInfo
/********************************
*介紹:辦公自動化OA系統 (更新用戶信息)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶NO,密碼,用戶名,職位,公司代號,
*說明:涉及表名[useradmin,record]
*********************************/
(
@UserNo varchar(20),
@Password varchar(32),
@UserName varchar(12),
@PositionNo varchar(10),
@Email varchar(50),
@Tel varchar(15),
@CompanyNo varchar(10),
@DepartmentNo varchar(10),
@ApproveGrade int,
@RoleLevel char(1)='1',
@GroupNo varchar(6),
@MarkName varchar(60),
@ActiveDate datetime,
@DisableDate datetime,
@Window bit = 0,
@Status char(1)='Y',
@EmailInform char(1)
)
as
update useradmin set user_name=@UserName, position_no=@PositionNo, email=@Email,tel=@Tel, company_no=@CompanyNo,
dept_no=@DepartmentNo,approve_grade=@ApproveGrade,role_level=@RoleLevel,group_no=@GroupNo, mark_name=@MarkName,
active_date=@ActiveDate,disable_date=@DisableDate, window=@Window, status=@Status, email_inform=@EmailInform
where user_no=@UserNo
if @Password !=''
update useradmin set user_password=@Password where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_UpdateUserOnlineMark
/********************************
*介紹:辦公自動化OA系統 (更新用戶在線狀態)
*作者:Billy
*書寫時間:2006/07/06
*參數:。。。。。
*說明:涉及表名[useradmin]
*********************************/
(
@UserNo varchar(20),
@OnLineMark char(1)
)
as
set @OnLineMark=Upper(@OnLineMark)
if @OnLineMark<>'Y'
set @OnLineMark='N'
Update useradmin Set online_mark=@OnLineMark Where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_UserLogin
/********************************
*介紹:辦公自動化OA系統 (用戶登陸)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶NO,密碼
*傳出:錯誤信息
*返回:登陸是否成功
*說明:涉及表名[useradmin,record]
*********************************/
(
@UserNo varchar(20),
@Password varchar(32),
@ComputerName varchar(30),
@LoginIP varchar(15),
@IsLogin bit out, --登陸驗證是否成功
@ErrorNo varchar(50) out
)
as
Declare @Status char(1)
Set @IsLogin = 0
if( Not Exists(Select * From UserAdmin Where User_no = @UserNo) )
begin
set @ErrorNo='UnFound'
return 0
end
--先清理在線用戶列表
Exec pr_User_Refresh_OnLineUser
if Exists( Select * From online_user where user_no = @UserNo )
begin
set @ErrorNo='OnLine'
return 0
end
if( Not Exists(Select * from UserAdmin where user_no=@UserNo and user_password=@Password) )
begin
set @ErrorNo='Error'
return 0
end
--查檢用戶是否失效
Select @Status = dbo.fn_CheckUserStatus(status, getDate(), active_date, disable_date) From UserAdmin Where User_No = @UserNo
if(@Status != 'Y')
begin
set @ErrorNo='Disabled'
return 0
end
Set @IsLogin = 1
--在online_user表中記錄當前用戶
Insert Into OnLine_User (user_no, Computer_name, IP, Login_time, refresh_time) Values ( @UserNo, @ComputerName, @LoginIP, getDate(), getDate())
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_User_CheckUser
/*******************************
功能:檢查用戶是否存在,如果存在,則取得用戶相關信息
作者:Billy
日期:2006/12/19
********************************/
(
@UserNo varchar(20),
@Found char(1) out, --是否存在
@Status char(1) out --當前是否生效
)
As
If(Not Exists(Select User_Name From UserAdmin Where User_No = @UserNo))
Begin
Select @Found = 'N', @Status = 'N'
Return 0
End
Select @Found = 'Y', @Status = dbo.fn_CheckUserStatus(status, getdate(), active_date, disable_date)
From UserAdmin Where User_No = @UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create Proc pr_User_Delete
/*********************
* 功能:刪除用戶
* 作者:Billy
* 日期:2007/03/03
* 注意:刪除前,請確認此用戶是否在簽核單據,如果在簽核單據,則不允許刪除
*********************/
(
@UserNo varchar(20)
)
As
--檢查用戶是否存在
If Not Exists(Select User_no From UserAdmin Where User_No = @UserNo)
Return 1
If Exists(Select Bill_No From Bill_M_Approve Where Create_Person = @UserNo)
Return 0
If Exists(Select Bill_No From Bill_M_Approved Where Create_Person = @UserNo)
Return 0
If Exists(Select Bill_No From Person_d_Approve Where User_No = @UserNo)
Return 0
If Exists(Select Bill_No From Person_d_Approved Where User_No = @UserNo)
Return 0
Begin Transaction
Delete Security Where User_no = @UserNo
If @@Error != 0 GoTo RollBackTransaction
Delete Bill_Security Where User_no = @UserNo
If @@Error != 0 GoTo RollBackTransaction
Delete UserAdmin Where User_No = @UserNo
If @@Error != 0 GoTo RollBackTransaction
CommitTransaction:
Commit Transaction
Return 1
RollBackTransaction:
RollBack Transaction
Return 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_Delete_OnLine
/***********************************
功能:刪除指定的在線用戶信息
作者:Billy
日期:2006/09/16
************************************/
(
@UserList varchar(3000)
)
As
if( @UserList Is Null or @UserList = '' )
return 0
Declare @nRows int, @sql nvarchar(4000)
Set @nRows = 0
Set @UserList = '''' + Replace(@UserList, ',', ''',''') + ''''
Set @sql ='Delete OnLine_User Where User_no in(' + Convert(nvarchar(3000),@UserList) + ') set @nRows=@@RowCount'
Execute sp_ExecuteSql @sql, N'@nRows int out', @nRows Out
return @nRows
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_User_GetDeaprtMent
/**************************************
* 功能:取得用戶所在的部門名稱
* 作者:Billy
* 日期:2007/01/15
**************************************/
(
@UserNo varchar(20),
@CompanyName varchar(60) out,
@DepartMent varchar(60) out,
@FullDepartMent Varchar(300) out
)
As
select @DepartMent = '', @FullDepartMent= ''
If Not Exists(Select User_No From UserAdmin Where User_No = @UserNo)
return 0
Declare @CompanyNo varchar(10), @DeptNo varchar(10)
Select @CompanyNo = company_no, @DeptNo = dept_no From useradmin where user_no = @UserNo
set @FullDepartMent = dbo.fn_DepartMentFrame(@CompanyNo, @DeptNo)
Select @DepartMent = dept_nm From dept where company_no = @CompanyNo and Dept_no = @DeptNo
select @CompanyName = company_nm from company where company_no = @companyNo
return 1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_GetGroupWithCompanyNo
/********************************
*介紹:取某公司的用戶組信息
*作者:Billy
*書寫時間:2006/12/20
*********************************/
(
@CompanyNo varchar(10) --查詢的公司代號
)
as
Select company_no, Group_no, Group_nm From Group_Setting Where Company_no = @CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_GetUserInfoForWelcomePage
/**********************************************
功能:為WelCome.aspx頁面取得用戶的相關信息
作者:Billy
日期:2006-12-19
**********************************************/
(
@UserNo varchar(20),
@UserName varchar(15) out,
@PositionName varchar(60) out,
@DepartMent varchar(500) out,
@UserGroup varchar(60) out,
@ApproveBillCount int out,
@PrejudicationCount int out,
@MessageCount int out,
@DeputyUserInfo nVarchar(100) out,
@WorkAssistant nVarchar(500) out
)
As
Set @UserName = ''
Set @PositionName = ''
Set @Department = ''
Set @UserGroup = ''
Set @ApproveBillCount = 0
Set @PrejudicationCount = 0
Set @DeputyUserInfo = N''
Set @WorkAssistant = N''
Declare @TempUser Table (ID int Identity(1,1), UserName varchar(15), PositionName varchar(30))
Declare @TempUserNo varchar(20)
Declare @Id int , @RowCount int
--取得用戶的相關信息
Select @UserName = U.User_Name, @PositionName = P.Position_Name, @Department = dbo.fn_DepartMentFrame(U.Company_no, U.Dept_no), @UserGroup = G.Group_nm From UserAdmin U
Inner Join Position P On U.company_no = P.company_no and U.Position_no = P.Position_no
Inner Join Group_Setting G On U.group_no = G.Group_no and U.company_no = G.company_no
Where U.User_No = @UserNo
--取得待簽單據的數量
Exec @ApproveBilLCount = pr_Bill_GetNeedApproveBillCounts @UserNo
--取得預審單據數量
Exec @PrejudicationCount = pr_Bill_PrejudicationCount @UserNo
--取得未讀信息的數量
Select @MessageCount = Count(*) From Message_Person Where Incept_User_no = @UserNo and Read_Sign = 0
--取代理用戶列表
Set @TempUserNo = dbo.fn_GetDeputyFromUser(@UserNo, getDate())
If( @TempUserNo = @UserNo )
Set @DeputyUserInfo = N''
Else
Begin
Select @DeputyUserInfo = U.User_Name + P.Position_Name From UserAdmin U
Inner Join Position P On U.company_no = P.company_no and U.position_no = P.Position_No
Where U.User_no = @TempUserNo
End
--取得工作助手列表
Insert Into @TempUser
Select U.User_Name, P.Position_name
From Assistant A
Inner Join UserAdmin U ON A.Assistant_no = U.User_No
Inner Join Position P On U.company_no = P.company_no and U.position_no = P.position_no
Where Director_No = @UserNo
Select @ID = 1, @RowCount = Count(*) From @TempUser
if( @RowCount > 0 )
Begin
While @ID <= @RowCount
Begin
Select @WorkAssistant = @WorkAssistant + ',' + UserName + PositionName
From @TempUser Where ID = @ID
Set @ID = @ID + 1
End
Set @WorkAssistant = Substring(@WorkAssistant, 2, Len(@WorkAssistant) )
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_LoginCheck
/**********************************
功能:檢查用戶登陸的狀態,當超過20分鐘時
**********************************/
(
@UserNo varchar(20),
@ComputerName varchar(30),
@IP varchar(15)
)
As
if( Not Exists( Select * From OnLine_User Where User_no = @UserNo ) )
Begin
Insert Into OnLine_User(user_no, computer_name, ip, Login_time, refresh_time)
Values(@UserNo, @ComputerName, @IP, getDate(), GetDate())
return 1
End
Declare @TempName varchar(30), @tempIP varchar(15)
Select @TempName = Computer_Name, @tempIP = IP From OnLine_User Where User_No = @UserNo
if @TempName != @ComputerName Or @IP != @TempIP
Begin
Update online_user Set Login_Time = GetDate(), Refresh_Time = getdate(),
Computer_name = @ComputerName, IP = @IP where user_no = @UserNo
Return 1
End
UpDate OnLine_User Set Refresh_Time = getDate() Where User_no = @UserNo
--將刷新時間超過10分的用戶刪除
Exec pr_User_Refresh_OnLineUser
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_Logout
/********************************
*介紹:辦公自動化OA系統 (退出系統)
*作者:Billy
*書寫時間:2006/09/21
*參數:@UserNo 用戶代號
*說明:表:UserAdmin, online_user
*********************************/
(
@UserNo Varchar(20)
)
as
--從在線用戶表中刪除用戶信息
Delete online_user Where User_no = @UserNo
Update UserAdmin Set online_mark = 'N' Where User_no = @UserNo
--因為是每5分鐘會自動刷新一次,所有當刷新時間Refresh_Time超出5分鐘便視為離線
Exec pr_User_Refresh_OnLineUser
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_Refresh_OnLineUser
/*******************************
功能:刷新當前在線的用戶(即刪除最後一次刷新時間大於5分鐘的用戶)
作者:Billy
日期:2006/09/21
********************************/
As
Delete OnLine_User Where DateDiff( Minute, Refresh_Time, GetDate() ) > 5
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_Rename
/**********************************************
功能:修改用戶的帳號user_no
作者:Billy
日期:2006-09-27
參數:@OldUserNo 原帳號, @NewUserNo
**********************************************/
(
@OldUserNo varchar(20),
@NewUserNo varchar(20),
@ErrorNo Varchar(50) out
)
As
Declare @Result int
Set @Result = 0
Set @ErrorNo = 'Saved'
begin transaction
--第一步,檢查原帳號是否已存在
if Not Exists(Select * From UserAdmin Where User_no = @OldUserNo)
Begin
Set @ErrorNo = 'UnFound'
Set @Result = 1
Goto ExitProc
End
--第二步,檢查新帳號是否已存在
if Exists(Select * From UserAdmin where user_no = @NewUserNo)
Begin
Set @ErrorNo = 'Exists'
Set @Result = 1
Goto ExitProc
End
--第三步,根據原帳號添加新帳號
select * into #tbUser From UserAdmin Where User_no = @OldUserNo
Update #tbUser Set User_no = @NewUserNo
Insert into UserAdmin
Select * From #tbUser
if @@Error != 0
Begin
Set @ErrorNo = 'Failing'
Set @Result = 1
GoTo ExitProc
End
--第四步, 更新相關的表
Update Bill_Security Set user_no = @NewUserNo Where user_no = @OldUserNo
Update Position Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Position Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update User_Company Set user_no = @NewUserNo Where user_no = @OldUserNo
Update Security Set User_no = @NewUserNo Where user_no = @OldUserNo
Update Menu_List Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Menu_List Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Record Set user_no = @NewUserNo Where user_no = @OldUserNo
Update Online_User Set User_no = @NewUserNo Where user_no = @OldUserNo
Update Company Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Company Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Dept Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Dept Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Error_Code Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Error_Code Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Product_Kind Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Product_Kind Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Product_Style Set Create_Person = @NewUserNo Where Create_Person = @OldUserNo
Update Product_Style Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
--更新單據表
Update Person_d_Approve Set User_no = @NewUserNo Where user_no = @OldUserNo
Update Person_d_Approve Set actual_user_no = @NewUserNo Where actual_user_no = @OldUserNo
Update Bill_m_Approve Set Create_Person = @NewUserNo Where Create_person = @OldUserNo
Update Bill_m_Approve Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Bill_Approve_Log Set User_no = @NewUserNo WHere user_no = @OldUserNo
Update Person_d_Approved Set User_no = @NewUserNo Where user_no = @OldUserNo
Update Person_d_Approved Set actual_user_no = @NewUserNo Where actual_user_no = @OldUserNo
Update Bill_m_Approved Set Create_Person = @NewUserNo Where Create_person = @OldUserNo
Update Bill_m_Approved Set Modify_Person = @NewUserNo Where Modify_Person = @OldUserNo
Update Bill_Approved_Log Set User_no = @NewUserNo WHere user_no = @OldUserNo
Update Assistant_overture Set user_no = @NewUserNo Where User_no = @OldUserNo
Update use_phrase Set user_no = @NewUserNo Where User_no = @OldUserNo
Update Assistant Set Director_no = @NewUserNo Where Director_no = @OldUserNo
Update Assistant Set assistant_no = @NewUserNo Where assistant_no = @OldUserNo
Update DeputyInfo Set bydeputy = @NewUserNo Where bydeputy = @OldUserNo
Update DeputyInfo Set deputy = @NewUserNo Where deputy = @OldUserNo
Update TechnicItem Set user_no= @NewUserNo Where user_no = @OldUserNo
Update TechnicType Set user_no= @NewUserNo Where user_no = @OldUserNo
if @@Error != 0
Begin
Set @ErrorNo = 'Failing'
Set @Result = 1
GoTo ExitProc
End
--第五步,刪除UserAdmin表中的原帳號記錄
Delete From UserAdmin Where User_no = @OldUserNo
if @@Error != 0
Begin
Set @ErrorNo = 'Failing'
Set @Result = 1
GoTo ExitProc
End
ExitProc:
if @Result = 0
Commit Transaction
else
RollBack Transaction
return @Result
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_SelectAllOnLineUserList
/***********************************
功能:取得在線用戶的列表
作者:Billy
日期:2006/09/16
************************************/
As
Select U.User_no, U.User_Name, U.Tel, U.Email, O.IP As Login_IP, O.computer_name, C.Company_Nm,
dbo.fn_DepartMentFrame(U.company_no, U.Dept_No) Dept_Nm, P.Position_Name, O.Login_Time, O.Refresh_Time,
dbo.fn_ConvertToTime(abs(datediff(minute, O.Login_Time, getdate()))) OnlineTime
From OnLine_User O
Left outer Join UserAdmin U On O.User_No = U.User_no
Left outer Join Dept D On U.Dept_no = D.Dept_no
Left outer Join Position P On U.Position_no = P.Position_no
Left outer Join Company C On U.Company_no = C.Company_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Proc pr_User_SelectOnLineUserList
/***********************************
功能:取得在線用戶的列表
作者:Billy
日期:2006/09/16
************************************/
(
@pageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
As
Declare @Sql varchar(1300)
Set @Sql ='Select O.computer_name, U.User_Name, U.Tel, U.Email, O.IP As Login_IP, C.Company_Nm, D.Dept_Nm, P.Position_Name, O.Login_Time, O.Refresh_Time,'
+ 'dbo.fn_ConvertToTime(abs(datediff(minute, O.Login_Time, getdate()))) OnlineTime From OnLine_User O '
+ 'Inner Join UserAdmin U On O.User_No = U.User_no '
+ 'Inner Join Dept D On U.Dept_no = D.Dept_no '
+ 'Inner Join Position P On U.Position_no = P.Position_no '
+ 'Inner Join Company C On U.Company_no = C.Company_no '
print @Sql
Exec pr_SelectDataPager @Sql ,@PageSize, @PageIndex, @PageCount Out
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE proc pr_User_SelectRelationList
/******************************************
* 功能:取得與當前用戶相關的用戶列表
* 作者:Billy
* 日期:2007/02/23
* 參數說明:
@UserNo:用戶代號
@SearchUser:查詢的用戶代號或姓名
@Mode:
1: 取當前用戶所在部門及其下屬部門的用戶列表
2: 取當前用戶所在部門及其上級部門的用戶列表(只到處級)
3: 取當前用戶所在部門、上級部門、下屬部門的用戶列表(上級部門只到處級)
* 返回:用戶列表
******************************************/
(
@UserNo varchar(20),
@SearchUser varchar(20) = '',
@Mode char(1) = '1',
@PageIndex int = 1,
@PageSize int = 25,
@PageCount int = 1 out
)
As
Declare @Sql varchar(8000)
Declare @CompanyNo varchar(10)
Declare @DepartmentList varchar(3000)
Select @CompanyNo = company_no,@DepartmentList = dbo.fn_Dept_GetAllSuperiorDepartMentNo(company_no,dept_no, @Mode) From UserAdmin Where User_no = @UserNo
Set @DepartmentList = '''' + Replace(@DepartmentList , ',', ''',''') + ''''
Set @Sql = 'Select U.Company_no,User_no,User_Name,Approve_Grade,dbo.fn_DepartmentFrame(u.company_no,dept_no) Department,'
+ 'P.position_name,tel,email,dbo.fn_CheckUserStatus(status,getdate(),active_date,disable_date) status From Useradmin U '
+ 'Left outer Join Position P On U.company_no=P.company_no and U.position_no=P.position_no '
+ 'Where U.company_no='''+@CompanyNo + ''' and dept_no in(' + @DepartmentList + ') '
Set @SearchUser = ltrim(@SearchUser)
If @SearchUser != ''
Set @Sql = @Sql + 'and (User_no Like ''%' + @SearchUser + '%'' Or User_name Like ''%' + @SearchUser + '%'''
Print @Sql
Exec pr_SelectDataPager @Sql, @PageSize, @PageIndex, @PageCount out, '', 'Department,Approve_Grade Desc'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_User_UpdatePassword
/********************************
*介紹:辦公自動化OA系統 (用戶更改密碼)
*作者:電腦混混Vincent
*書寫時間:2006/05/29
*傳入:用戶ID,原密碼,新密碼,操作窗口
*傳出:錯誤信息
*返回:是否成功0:否;1:是
*說明:涉及表名[security,record]
*********************************/
(
@UserNo varchar(20),
@OldPassword varchar(32),
@NewPassword varchar(32)
)
as
if exists(select * from useradmin where user_no=@UserNo and user_password=@OldPassword)
update useradmin set user_password=@NewPassword where user_no=@UserNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehcile_SelectExpenseKind
/********************************
*介紹:辦公自動化OA系統 (取得費用項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回:
*說明:涉及表名[expense_kind]
*********************************/
(
@user_no varchar(20),
@pageSize int = 25,
@pageCurrent int=1,
@pageCount int = 0 output
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
set @queryText = 'select * from expense_kind where company_no = ''' + @company_no + ''''
Execute pr_SelectDataPager @queryText, @pageSize , @pageCurrent, @pageCount Output, '', ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehcile_SelectMaintainKind
/********************************
*介紹:辦公自動化OA系統 (取得維修項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回: 通訊錄
*說明:涉及表名[maintain_kind]
*********************************/
(
@user_no varchar(20),
@pageSize int = 25,
@pageCurrent int=1,
@pageCount int = 0 output
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
set @queryText = 'select * from maintain_kind where company_no = ''' + @company_no + ''''
Execute pr_SelectDataPager @queryText, @pageSize , @pageCurrent, @pageCount Output, '', ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehcile_SelectVehcile
/********************************
*介紹:辦公自動化OA系統 (取得車輛信息)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回:
*說明:涉及表名[vehicle]
*********************************/
(
@user_no varchar(20),
@number_plate varchar(10),
@content varchar(50),
@pageSize int = 25,
@pageCurrent int=1,
@pageCount int = 0 output
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
set @queryText = 'select * from vehicle where company_no = ''' + @company_no + ''' and number_plate like ''%' + @number_plate + '%'' and content like ''%' + @content + '%'''
Execute pr_SelectDataPager @queryText, @pageSize , @pageCurrent, @pageCount Output, '', ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_DeleteDriver
/********************************
*介紹:辦公自動化OA系統 (刪除)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名
*********************************/
(
@driver_id varchar(10)
)
as
declare @ERR int
delete from driver where driver_id=@driver_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_DeleteExpenseKind
/********************************
*介紹:辦公自動化OA系統 (刪除費用項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名[expense_kind]
*********************************/
(
@kind_id int
)
as
declare @ERR int
declare @num int
delete from expense_kind where kind_id=@kind_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_DeleteMaintainKind
/********************************
*介紹:辦公自動化OA系統 (刪除維修項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名[maintain_kind]
*********************************/
(
@kind_id int
)
as
declare @ERR int
declare @num int
delete from maintain_kind where kind_id=@kind_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_DeleteVehicle
/********************************
*介紹:辦公自動化OA系統 (刪除)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名
*********************************/
(
@number_plate varchar(10)
)
as
declare @ERR int
declare @num int
delete from vehicle where number_plate=@number_plate
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_DeleteVehicleExamine
/********************************
*介紹:辦公自動化OA系統 (刪除)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名
*********************************/
(
@examine_id varchar(10)
)
as
declare @ERR int
declare @num int
delete from vehicle_examine where examine_id=@examine_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_DeleteVehicleInsure
/********************************
*介紹:辦公自動化OA系統 (刪除)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出
*返回:
@ERR = 0 刪除成功
@ERR > 0 刪除失敗
*說明:涉及表名
*********************************/
(
@insure_id varchar(10)
)
as
declare @ERR int
declare @num int
delete from vehicle_insure where insure_id=@insure_id
set @ERR = @@error
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_InsertExpenseKind
/********************************
*介紹:辦公自動化OA系統 (新增費用項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:組名, 用戶代號
*傳出:
*返回:成功: @kind_id > 0 and @ERR = 0
失敗: @kind_id > 0 and @ERR > 0
*說明:涉及表名[expense_kind]
*********************************/
(
@user_no varchar(20),
@kind_name varchar(20)
)
as
declare @ERR int
declare @kind_id int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在 相同組名
--生成kind_id
select @kind_id = max(kind_id) from expense_kind
if @kind_id is null set @kind_id = 0
set @kind_id = @kind_id + 1
-- insert 組
insert into expense_kind(company_no, kind_id, kind_name)
values(@company_no, @kind_id, @kind_name)
--取系統錯誤號
select @ERR = @@ERROR
--輸出組id和錯誤號
select @kind_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_InsertMaintainKind
/********************************
*介紹:辦公自動化OA系統 (新增維修項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:組名, 用戶代號
*傳出:
*返回:成功: @kind_id > 0 and @ERR = 0
失敗: @kind_id > 0 and @ERR > 0
*說明:涉及表名[maintain_kind]
*********************************/
(
@user_no varchar(20),
@kind_name varchar(20)
)
as
declare @ERR int
declare @kind_id int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在 相同組名
--生成kind_id
select @kind_id = max(kind_id) from maintain_kind
if @kind_id is null set @kind_id = 0
set @kind_id = @kind_id + 1
-- insert 組
insert into maintain_kind(company_no, kind_id, kind_name)
values(@company_no, @kind_id, @kind_name)
--取系統錯誤號
select @ERR = @@ERROR
--輸出組id和錯誤號
select @kind_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_InsertVehicle
/********************************
*介紹:辦公自動化OA系統 (新增車輛)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:成功: @kind_id > 0 and @ERR = 0
失敗: @kind_id > 0 and @ERR > 0
*說明:涉及表名[]
*********************************/
(
@number_plate varchar(10),
@brand varchar(20),
@content varchar(50),
@car_kind varchar(10),
@driver int,
@buy_date smalldatetime,
@price decimal,
@init_Kilometer int,
@Displacement varchar(10),
@status varchar(1),
@Oil_consumption varchar(10),
@engine_number varchar(20),
@carriage varchar(10),
@load varchar(10),
@seating tinyint,
@color varchar(10),
@note varchar(100),
@create_date datetime,
@create_person varchar(20)
)
as
declare @ERR int
declare @count int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@create_person
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在 相同組名
--生成kind_id
select @count = count(*) from vehicle where company_no=@company_no and number_plate=@number_plate
if @count > 0
begin
set @ERR=-1
select @ERR
return
end
-- insert 組
insert into vehicle
(
company_no,
number_plate,
brand,
content,
car_kind,
driver,
buy_date,
price,
init_Kilometer,
displacement,
status,
oil_consumption,
engine_number,
carriage,
[load],
seating,
color,
note,
create_date,
create_person
)
values
(
@company_no,
@number_plate,
@brand,
@content,
@car_kind,
@driver,
@buy_date,
@price,
@init_Kilometer,
@displacement,
@status,
@oil_consumption,
@engine_number,
@carriage,
@load,
@seating,
@color,
@note,
@create_date,
@create_person
)
--取系統錯誤號
select @ERR = @@ERROR
--輸出組id和錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_InsertVehicleExamine
/********************************
*介紹:辦公自動化OA系統
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[]
*********************************/
(
@user_no varchar(20),
@number_plate varchar(10),
@check_date datetime,
@check_kind varchar(20),
@note varchar(100),
@next_date datetime
)
as
declare @ERR int
declare @company_no varchar(10)
declare @examine_id int
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
select @examine_id = examine_id from vehicle_examine
if @examine_id is null
set @examine_id = 0
set @examine_id = @examine_id +1
-- insert 組
insert into vehicle_examine
(
examine_id,
company_no,
number_plate,
check_date,
check_kind,
note,
next_date
)
values
(
@examine_id,
@company_no,
@number_plate,
@check_date,
@check_kind,
@note,
@next_date)
--取系統錯誤號
select @ERR = @@ERROR
--輸出id和錯誤號
select @examine_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_InsertVehicleInsure
/********************************
*介紹:辦公自動化OA系統
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[]
*********************************/
(
@user_no varchar(20),
@number_plate varchar(10),
@insure_date datetime,
@insurer varchar(20),
@note varchar(100),
@end_date datetime
)
as
declare @ERR int
declare @company_no varchar(10)
declare @insure_id int
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
select @insure_id = insure_id from vehicle_insure
if @insure_id is null
set @insure_id = 0
set @insure_id = @insure_id +1
-- insert 組
insert into vehicle_insure
(
insure_id,
company_no,
number_plate,
insure_date,
insurer,
note,
end_date
)
values
(
@insure_id,
@company_no,
@number_plate,
@insure_date,
@insurer,
@note,
@end_date)
--取系統錯誤號
select @ERR = @@ERROR
--輸出id和錯誤號
select @insure_id, @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_SelectDriver
/********************************
*介紹:辦公自動化OA系統 (取得駕駛員信息)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回:
*說明:涉及表名[driver]
*********************************/
(
@user_no varchar(20),
@driver_name varchar(20),
@pageSize int = 25,
@pageCurrent int=1,
@pageCount int = 0 output
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
set @queryText = 'select a.*, b.dept_nm from driver a left join dept b on a.dept_no=b.dept_no where a.company_no = ''' + @company_no + ''' and a.driver_name like ''%' + @driver_name + '%'''
Execute pr_SelectDataPager @queryText, @pageSize , @pageCurrent, @pageCount Output, '', ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_SelectDriverByUserNo
/********************************
*介紹:辦公自動化OA系統 (取得駕駛員信息)
*作者:游勇
*書寫時間:2007/04/27
*傳入:用戶代號
*傳出:
*返回:
*說明:涉及表名[driver]
*********************************/
(
@user_no varchar(20)
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
select a.*, b.dept_nm from driver a left join dept b on a.dept_no=b.dept_no where a.company_no=@company_no
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_SelectVehicleExamine
/********************************
*介紹:辦公自動化OA系統
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:
*說明:涉及表名
*********************************/
(
@user_no varchar(20),
@number_plate varchar(10),
@pageSize int = 25,
@pageCurrent int=1,
@pageCount int = 0 output
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
set @queryText = 'select * from vehicle_examine where company_no=''' + @company_no + ''' and number_plate=''' + @number_plate + ''''
Execute pr_SelectDataPager @queryText, @pageSize , @pageCurrent, @pageCount Output, '', ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_SelectVehicleInsure
/********************************
*介紹:辦公自動化OA系統
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:
*說明:涉及表名
*********************************/
(
@user_no varchar(20),
@number_plate varchar(10),
@pageSize int = 25,
@pageCurrent int=1,
@pageCount int = 0 output
)
as
declare @company_no varchar(10)
declare @queryText varchar(200)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
--取得當前用戶下所在公司
set @queryText = 'select * from vehicle_insure where company_no=''' + @company_no + ''' and number_plate=''' + @number_plate + ''''
Execute pr_SelectDataPager @queryText, @pageSize , @pageCurrent, @pageCount Output, '', ''
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_UpdateExpenseKind
/********************************
*介紹:辦公自動化OA系統 (新增費用項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[expense_kind]
*********************************/
(
@user_no varchar(20),
@kind_id int,
@kind_name varchar(20)
)
as
declare @ERR int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
-- update 組
update expense_kind set kind_name=@kind_name where kind_id=@kind_id
--取系統錯誤號
set @ERR = @@ERROR
--輸出錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_UpdateMaintainKind
/********************************
*介紹:辦公自動化OA系統 (新增維修項目)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名[address_group]
*********************************/
(
@user_no varchar(20),
@kind_id int,
@kind_name varchar(20)
)
as
declare @ERR int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@user_no
if @company_no is null set @company_no = 'ETC'
-- update 組
update maintain_kind set kind_name=@kind_name where kind_id=@kind_id
--取系統錯誤號
set @ERR = @@ERROR
--輸出錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_UpdateVehicle
/********************************
*介紹:辦公自動化OA系統 (更新車輛)
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:成功: @kind_id > 0 and @ERR = 0
失敗: @kind_id > 0 and @ERR > 0
*說明:涉及表名[]
*********************************/
(
@number_plate varchar(10),
@brand varchar(20),
@content varchar(50),
@car_kind varchar(10),
@driver int,
@buy_date smalldatetime,
@price decimal,
@init_Kilometer int,
@Displacement varchar(10),
@status varchar(1),
@Oil_consumption varchar(10),
@engine_number varchar(20),
@carriage varchar(10),
@load varchar(10),
@seating tinyint,
@color varchar(10),
@note varchar(100),
@create_date datetime,
@create_person varchar(20)
)
as
declare @ERR int
--declare @count int
declare @company_no varchar(10)
--取得當前用戶所在公司
select @company_no = company_no from useradmin where user_no=@create_person
if @company_no is null set @company_no = 'ETC'
--當前公司私有默認組 是否存在 相同組名
--生成kind_id
--select @count = count(*) from vehicle where company_no=@company_no and number_plate=@number_plate
--if @count > 0
--begin
-- set @ERR=-1
-- select @ERR
-- return
--end
-- iupdate
update vehicle set
company_no = @company_no ,
--number_plate = @number_plate ,
brand = @brand ,
content = @content ,
car_kind = @car_kind ,
driver = @driver ,
buy_date = @buy_date ,
price = @price ,
init_Kilometer = @init_Kilometer ,
displacement = @displacement ,
status = @status ,
oil_consumption = @oil_consumption ,
engine_number = @engine_number ,
carriage = @carriage ,
[load] = @load ,
seating = @seating ,
color = @color ,
note = @note ,
create_date = @create_date ,
create_person = @create_person
--取系統錯誤號
select @ERR = @@ERROR
--輸出錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_UpdateVehicleExamine
/********************************
*介紹:辦公自動化OA系統
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名
*********************************/
(
@examine_id int,
@check_date datetime,
@check_kind varchar(20),
@note varchar(100),
@next_date datetime
)
as
declare @ERR int
--declare @company_no varchar(10)
--取得當前用戶所在公司
--select @company_no = company_no from useradmin where user_no=@user_no
--if @company_no is null set @company_no = 'ETC'
-- update
update vehicle_examine set
check_date=@check_date,
check_kind=@check_kind,
note=@note,
next_date=@next_date
where examine_id=@examine_id
--取系統錯誤號
set @ERR = @@ERROR
--輸出錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Proc pr_Vehicle_UpdateVehicleInsure
/********************************
*介紹:辦公自動化OA系統
*作者:游勇
*書寫時間:2007/04/27
*傳入:
*傳出:
*返回:
成功: @ERR = 0
失敗: @ERR > 0
*說明:涉及表名
*********************************/
(
@insure_id int,
@insure_date datetime,
@insurer varchar(20),
@note varchar(100),
@end_date datetime
)
as
declare @ERR int
--declare @company_no varchar(10)
--取得當前用戶所在公司
--select @company_no = company_no from useradmin where user_no=@user_no
--if @company_no is null set @company_no = 'ETC'
-- update
update vehicle_insure set
insure_date=@insure_date,
insurer=@insurer,
note=@note,
end_date=@end_date
where insure_id=@insure_id
--取系統錯誤號
set @ERR = @@ERROR
--輸出錯誤號
select @ERR
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_WriteBillSuggest
/*************************************************
*介紹:辦公自動化OA系統 ___主管助理為主管審單簽寫的建議(新增或更新)
*作者:電腦混混Vincent
*書寫時間:2006/09/02
*傳入:單據NO,用戶NO
*說明: 被訪表名[assistant_overture,bill_m_approve]
更新表名[]
*
*************************************************/
(
@BillNo varchar(30), ----單據編號
@UserNo varchar(20), ----用戶代號
@SuggestContent varchar(1000), ----建議內容
@CreateDate datetime ----簽寫時間(為保證WEB和SQL服務器時間的同步)
)
as
declare @sCompanyNo varchar(10) ----公司代號
declare @sKindNo varchar(10) ----單據類型代號
declare @nSeq int ----建議序號(作為主鍵,可能一個主管有多位助理)
declare @cSuggestExist char(1) ----建議是否已存在
----判定建議是否已存在
select @cSuggestExist = case count(*)
when 1 then 'Y'
else 'N'
end
from assistant_overture
where bill_no = @BillNo
and user_no = @UserNo
if @cSuggestExist = 'N'
begin
----取得建議序號
select @nSeq = max(seq) from assistant_overture where bill_no = @BillNo
set @nSeq = isnull(@nSeq,1) + 1
----根據單據代號取公司代號和單據類型代號
select @sCompanyNo = company_no ,
@sKindNo = kind_no
from bill_m_approve
where bill_no = @BillNo
----寫入建議
insert assistant_overture
values(
@sCompanyNo,@sKindNo,@BillNo,@nSeq,@UserNo,@SuggestContent,@CreateDate
)
end
else
begin
----建議已存在
update assistant_overture
set content = @SuggestContent,
create_date = @CreateDate
where bill_no = @BillNo
and user_no = @UserNo
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
-------------------------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_WriteBillValidateOperationLog
/********************************
*介紹:辦公自動化OA系統____寫入單據進行效果確認日志
*作者:電腦混混Vincent
*書寫時間:2006/10/11
*傳入:用戶NO
*說明:涉及表名[bill_approved_agree,person_d_approve,person_approve_file]
*********************************/
(
@UserNo varchar(10),
@BillNo varchar(30),
@OperateTime datetime ,
@Content varchar(500),
@Result char(1) ---- 'Y':通過 'N':不通過
)
as
declare @SettingUserNo varchar(20),@CompanyNo varchar(10),@KindNo varchar(10),@Seq int
select @CompanyNo = company_no ,
@KindNo = kind_no,
@Seq = seq,
@SettingUserNo = setting_user_no
from bill_approve_validate
where bill_no = @BillNo
------考慮代理
insert bill_approve_validate_log ( company_no,
kind_no,
bill_no,
seq,
setting_user_no,
actual_user_no,
validate_date,
note,
validate
) values
(
@CompanyNo,
@KindNo,
@BillNo,
@Seq,
@SettingUserNo,
@UserNo,
@OperateTime,
@Content,
@Result
)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure pr_delaction_kind
-----------通過傳進的@company_no和@action_seq刪除指定的記錄
@company_no varchar(10),
@action_seq int
as
declare @error int
declare @sum int
set @error=0
set @sum = 0
begin transaction
exec @sum = pr_Exists_action_seq @action_seq
if(@sum = 0)
delete from action_kind where company_no=@company_no and action_seq=@action_seq
if(@@error<>0) set @error=1
if(@error=0)
begin
commit transaction
return 1
end
else
begin
rollback transaction
return 0
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_getAffiche
/********************************
*介紹:辦公自動化OA系統 (取得對應公告,公告附檔,公告留言)
*作者:william
*書寫時間:2007/05/
*說明:
*********************************/
(
@affiche_id int,
@SelectType int
)
AS
if(exists(select * from affiche where affiche_id=@affiche_id))
begin
if(@SelectType=1)
begin
update affiche set browse_times = isnull(browse_times,0)+1 where affiche_id=@affiche_id
select a.title,a.content,a.affiche_id,leaveword from affiche a where a.affiche_id=@affiche_id
end
else if(@SelectType=2)
begin
select title,content,affiche_id,leaveword,everyone,importance_level from affiche where affiche_id=@affiche_id
select i.*,c.company_nm,dbo.fn_DepartmentframeAll(c.company_no, d.dept_no,'N') dept_nm from affiche_incept i
left join company c on c.company_no = i.company_no
left join dept d on i.dept_no = d.dept_no
where affiche_id=@affiche_id
end
else
begin
select a.title,a.content,a.affiche_id,leaveword from affiche a where a.affiche_id=@affiche_id
end
select * from affiche_file where affiche_id=@affiche_id
select l.content,l.leaveword_date,u.user_name from affiche_leaveword l
left join useradmin u on l.user_no=u.user_no where l.affiche_id=@affiche_id order by leaveword_date desc
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE procedure pr_getTableSeq
/********************************
*介紹:辦公自動化OA系統 (取得表的自增序?)
*作者:william
*書寫時間:2007/05/
*說明:
*********************************/
(
@sTableName varchar(50),
@sColumnName varchar(50),
@nSeq int out
)
AS
begin
declare @Sql nvarchar(500)
set @Sql = N'select @nSeq = isNull(max('+@sColumnName+'),0)+1 from '+@sTableName
print @Sql
print @sTableName
exec sp_executesql @Sql,N'@nSeq int out',@nSeq out
return @nSeq
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
--------------------------------------------------------------------------------------------------------------------
CREATE Proc pr_selectActionKind
/********************************
*介紹:辦公自動化OA系統 (取得第三層的菜單列表)
*作者:Billy
*書寫時間:2006/06/29
*參數:@WinNo --窗口代號
*說明:
*********************************/
(
@CompanyNo varchar(20)=''
)
as
if(@CompanyNo='')
select a.*,C.company_nm From action_kind A inner join company C on C.company_no=A.company_no
else
select a.*,C.company_nm From action_kind A inner join company C on C.company_no=A.company_no where A.company_no=@CompanyNo
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc testes
(
@Divan_No varchar(10)
)
As
declare @sWhere varchar(1000)
set @sWhere=' '
if(Rtrim(@Divan_No)!='')
set @sWhere=Rtrim(@sWhere) +' AND divan_no like "%'+@Divan_No+'%"'
select * from divan where 1=1 +Rtrim(@sWhere)
print @sWhere
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO