触发器之修改客单离店时间

动态 置顶 精帖
1748
刘飞
刘飞 Yolo3 2023-12-09 16:40:16

暂时未做修改备注的提醒,因为备注的字段比较特殊,如果必须要做,联系刘飞需改

USE [Yolo880_Hotel]
GO
/****** Object:  Trigger [dbo].[change_EndDateTime]    Script Date: 2023-01-30 13:55:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [dbo].[update_F_DateTimeTxt]
on [dbo].[T_RoomOrder]
after  update
AS
BEGIN 
Declare @dtt varchar(20);  --现累加房费时间
Declare @fid varchar(100);  --房间客单号
Declare @edt varchar(20);  --现离店时间
Declare @user varchar(50);  --操作员
Declare @info varchar(5000);  --原来日志信息
Declare @info1 varchar(5000);  --现在日志信息
--Select @fid=F_ID,@info1=F_InfoTxt from inserted;
Select @fid=F_ID from inserted;

--select @dtt=CONVERT(varchar(100), F_DateTimeTxt, 20),@info=F_InfoTxt ,@edt=CONVERT(varchar(100), F_EndDateTime, 20) from deleted where F_ID = @fid 
select @dtt=CONVERT(varchar(100), F_DateTimeTxt, 20) ,@edt=CONVERT(varchar(100), F_EndDateTime, 20) from deleted where F_ID = @fid 
select @user = u.F_UserName from  t_userpower u inner join(
	        SELECT top 1 F_UserName from T_LoginSysLog where f_hostname =
	        HOST_NAME() and f_leaveinfo is null order by F_ID desc) t on u
	    	.F_UserName = t.F_UserName and u.F_Status = '上班'

 if UPDATE(F_EndDateTime)
 begin
 INSERT INTO dbo.T_Log_RoomSvrc
       ( F_EventType ,F_Content,
         F_Username, F_TableName, F_Table_FID ) 
 SELECT   '记录改变离店日期','房号:'+F_KeyId + ' ,操作员(仅供参考):' + @user + ' ,原离店时间:'+@edt+' 现时间:'+CONVERT(varchar(100), F_EndDateTime, 20) ,@user  ,'T_RoomOrder',f_id   
 FROM inserted
 end
 if  UPDATE(F_DateTimeTxt)
 begin
 INSERT INTO dbo.T_Log_RoomSvrc
       ( F_EventType ,F_Content,
         F_Username, F_TableName, F_Table_FID ) 
 SELECT   '记录改变超时日期','房号:'+F_KeyId + ' ,操作员(仅供参考):' + @user +  ' ,原累加房费时间:'+  @dtt+' 现时间:'+CONVERT(varchar(100), F_DateTimeTxt, 20) ,@user  ,'T_RoomOrder',f_id   
 FROM inserted
 end
 /**
  if  (UPDATE(F_InfoTxt) and (@info1<>@info))
 begin
 INSERT INTO dbo.T_Log_RoomSvrc
       ( F_EventType ,F_Content,
         F_Username, F_TableName, F_Table_FID ) 
 SELECT   '记录改变备注信息','房号:'+F_KeyId + ' ,操作员(仅供参考):' + @user +  ' ,原备注:【'+  @info+'】----- 现备注:【'+ F_InfoTxt+'】' ,@user  ,'T_RoomOrder',f_id   
 FROM inserted
 end
 **/

END