Beispiel #1
0
 // 具体请求处理方法
 public override void ProcessRequest(PurchaseRequest request)
 {
     if (request.Amount < 80000)
     {
         // 处理请求
         Console.WriteLine("经理 {0} 审批采购单:{1},金额:{2} 元,采购目的:{3}。",
                           this.name, request.Number, request.Amount, request.Purpose);
     }
     else
     {
         this.successor.ProcessRequest(request);
     }
 }
 // 递交采购单给审批者
 public void SendRequestToApprover(PurchaseRequest request)
 {
     if (request.Amount < 5000) // 主任可审批该采购单
     {
         HandleByDirector(request);
     }
     else if (request.Amount < 100000) // 副董事长可审批该采购单
     {
         HandleByVicePresident(request);
     }
     else if (request.Amount < 500000) // 董事长可审批该采购单
     {
         HandleByPresident(request);
     }
     else
     {
         HandleByCongress(request); // 董事会可审批该采购单
     }
 }
Beispiel #3
0
        public static void Main(string[] args)
        {
            // 创建职责链
            Approver andy    = new Director("Andy");
            Approver jacky   = new Manager("Jacky");
            Approver ashin   = new VicePresident("Ashin");
            Approver anya    = new President("Anya");
            Approver meeting = new Congress("Congress");

            andy.SetSuccessor(jacky);
            jacky.SetSuccessor(ashin);
            ashin.SetSuccessor(anya);
            anya.SetSuccessor(meeting);
            // 构造采购请求单并发送审批请求
            PurchaseRequest request1 = new PurchaseRequest(45000.00,
                                                           "MANULIFE201706001",
                                                           "购买PC和显示器");

            andy.ProcessRequest(request1);

            PurchaseRequest request2 = new PurchaseRequest(60000.00,
                                                           "MANULIFE201706002",
                                                           "2017开发团队活动");

            andy.ProcessRequest(request2);

            PurchaseRequest request3 = new PurchaseRequest(160000.00,
                                                           "MANULIFE201706003",
                                                           "2017公司年度旅游");

            andy.ProcessRequest(request3);

            PurchaseRequest request4 = new PurchaseRequest(800000.00,
                                                           "MANULIFE201706004",
                                                           "租用新临时办公楼");

            andy.ProcessRequest(request4);

            Console.ReadKey();
        }
Beispiel #4
0
        public static void InitializeDemo(PurchaseRequest request)
        {
            PurchaseRequestHandler requestHandler = new PurchaseRequestHandler();

            requestHandler.SendRequestToApprover(request);
        }
Beispiel #5
0
 // 抽象请求处理方法
 public abstract void ProcessRequest(PurchaseRequest request);
Beispiel #6
0
 // 具体请求处理方法
 public override void ProcessRequest(PurchaseRequest request)
 {
     // 处理请求
     Console.WriteLine("董事会 {0} 审批采购单:{1},金额:{2} 元,采购目的:{3}。",
                       this.name, request.Number, request.Amount, request.Purpose);
 }
 // 董事会审批采购单
 private void HandleByCongress(PurchaseRequest request)
 {
     // 代码省略
 }
 // 董事长审批采购单
 private void HandleByPresident(PurchaseRequest request)
 {
     // 代码省略
 }
 // 主管审批采购单
 private void HandleByDirector(PurchaseRequest request)
 {
     // 代码省略
 }