表单触发器

这篇博客介绍了如何使用SQL触发器来控制大数据表单的反审核和价格范围审核。通过创建`seoutstock_fcheck`触发器防止2013年以前的数据反审核,以及`seoutstock_checkJ`触发器来确保价格在指定范围内,从而确保数据的正确性和安全性。
摘要由CSDN通过智能技术生成

控制时间的单据不让反审核

create TRIGGER [dbo].[seoutstock_fcheck] ON [dbo].[SEOutStock]
FOR update
AS
 SET NOCOUNT ON

 if exists (select 1 from  deleted  where  fdate<'2013-01-01' and isnull(fcheckerid,0)<>0)
 begin
     if exists (select 1 from  inserted  where  fdate<'2013-01-01' and isnull(fcheckerid,0)=0)
     begin

              DECLARE @FStatus  int
                    DECLARE @Finterid   int
  
               select @FStatus=fcheckerid,@Finterid=finterid from seoutstock
               where finterid in (select finterid from inserted) 
                     if isnull(@FStatus,0)=0
                     begin
               ROLLBACK TRAN 
                    RAISERROR('2013年以前数据,无法反审单据,请冲红!',18,18)
                     end  
        end
END

              

控制价格范围审核    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CREATE trigger icstockbill_check --实现对物料单据管控 on Icstockbill for insert as Declare @Ftrantype int --单据类别定义/生产领料单24/调拔单41/销售出库单21 Select @Ftrantype=Ftrantype from inserted --控制领料单的领料日期不能小于生产任务单的计划开工日期 倒扣物料只能车间仓库发料 if (@Ftrantype=24) begin declare @icmo varchar(20) declare @message varchar(200) declare @message0 varchar(200) declare @message00 varchar(200) declare @message000 varchar(200) declare @finterid240 int set @message='错误!领料日期不能小于生产任务单计划开工日期,请与生管人员联系!错误单号:' set @message0='生产领料单发料仓库不正确,倒扣物料不能从 原料仓/半成品仓/成品仓 发料' set @message00='已完工生产任务单不能跨月领料.请检查领料日期!' set @message000='生产领料单必需关联源生产任务单号,请重新录入单据!' if exists ( select t1.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid where t2.ficmointerid=0 ) begin RAISERROR(@message000,18,18) ROLLBACK end if exists( select t3.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid where t2.fsourceinterid>0 and t1.fdate0 and t1.fdateCast(year(max(t4.fdate)) as int(10))*100+Cast(month(max(t4.fdate)) as int(5)) ) begin RAISERROR(@message00,18,18) ROLLBACK end --更新领料单上的销售订单号 select @finterid240=finterid from inserted update t2 set t2.fentryselfb0445=t4.fbillno from icstockbill as t1 inner join icstockbillentry as t2 on t1.ftrantype=24 and t1.finterid=t2.finterid inner join icmo as t3 on t3.finterid=t2.ficmointerid left join seorder as t4 on t4.finterid=t3.forderinterid where isnull(t4.fbillno,'no')'no' and t2.finterid=@finterid240 return end --控制委外加工生产任务单领料日期不对小于计划开工日期 if (@Ftrantype=28) begin declare @icmo3 varchar(20) declare @message3 varchar(200) set @message3='错误!委外加工发出日期不能小于对应委外加工生产任务单计划开工日期,请与采购人员联系变更!错误单号:' if exists( select t3.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid where t2.fsourceinterid>0 and t1.fdate0 and t1.fdate0 and t1.fdate0 and t1.fdate<t3.FPlanCommitDate set @message4=@message4+@icmo4 RAISERROR(@message4,18,18) ROLLBACK end ; --更新产品入库单上的销售订单号 select @finterid20=finterid from inserted update t2 set t2.fentryselfa0236=t4.fbillno from icstockbill as t1 inner join icstockbillentry as t2 on t1.ftrantype=2 and t1.finterid=t2.finterid inner join icmo as t3 on t3.finterid=t2.ficmointerid left join seorder as t4 on t4.finterid=t3.forderinterid where isnull(t4.fbillno,'no')'no' and t2.finterid=@finterid20 return end ---更新委外加工入单销售订单号 if (@Ftrantype=5) begin update t2 set t2.fentryselfa0548=t4.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join icmo as t3 on t3.finterid=t2.fsourceinterid inner join seorder as t4 on t4.finterid=t3.forderinterid return end ---控制出全部出货的销售订单所对应的采购订单不能退料(红字外购入库单) /*if (@Ftrantype=1) begin declare @message500 varchar(200) set @message500='已全部出货的销售订单所对应的采购订单不能退料!请检查您所退料的采购订单号码是否正确!' if exists (select t1.fbillno from inserted as t1 inner join icstockbillentry as t2 on t2.finterid=t1.finterid inner join seorder as t3 on t3.fbillno=t2.fentryselfa0152 where t2.fqty<0 and t3.fclosed=1 ) begin RAISERROR(@message500,18,18) ROLLBACK end return end */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值