日期:2014-05-17  浏览次数:20770 次

如何使用C#代码实现数据库触发器的功能
之前使用SQL的触发器来实现触发功能 如 删除入库单时从物料表的库存中减去相应的数量.

但如果我要改成用业务逻辑层代码实现此功能的话要怎么写.谢谢

------解决方案--------------------
事件
------解决方案--------------------
C# code
using System;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Bank b = new Bank();
            b.BeforeClosed +=new Bank.BeforeBankCloseHandler(b_BeforeClosed);
            b.Close();
        }

        static void b_BeforeClosed(object sender, BeforeBankCloseEventArgs e)
        {
            Console.WriteLine("Bank'Name is:"+e.BankName);
            Console.WriteLine("Before bank is closed,I can do something");
        }

    }

    public class Bank
    {
        public delegate void BeforeBankCloseHandler(object sender, BeforeBankCloseEventArgs e);
        public event BeforeBankCloseHandler BeforeClosed;



        public void Close()
        {
            string bName = "China Bank";
            BeforeBankCloseEventArgs arg = new BeforeBankCloseEventArgs(bName);
            BeforeClosed(this, arg);
            Console.WriteLine("Bank Closed");
        }


    }

    public class BeforeBankCloseEventArgs : EventArgs
    {
        public BeforeBankCloseEventArgs(string m)
        {
            _bankName = m;
        }
        private string _bankName;
        public string BankName
        {
            get { return _bankName; }
            set { _bankName = value; }
        }

    }
}

------解决方案--------------------
http://topic.csdn.net/u/20090227/16/9f795a88-45b5-47c7-b68e-a83ae0d74fd8.html