home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_MoveMoney_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2002-05-06  |  5.5 KB  |  154 lines

  1. // ==============================================================================
  2. // Filename: MoveMoney.cs
  3. //
  4. // Summary:  C# implememtation of the MoveMoney class for the bank sample
  5. // Classes:  MoveMoney.cs
  6. //
  7. // This file is part of the Microsoft COM+ Samples
  8. //
  9. // Copyright (C) Microsoft Corporation. All rights reserved
  10. //
  11. // This source code is intended only as a supplement to Microsoft
  12. // Development Tools and/or on-line documentation.  See these other
  13. // materials for detailed information reagrding Microsoft code samples.
  14. //
  15. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  16. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  18. // PARTICULAR PURPOSE.
  19. //
  20.  
  21.  
  22. namespace CSharpBank
  23. {
  24.     using System;
  25.     using System.Runtime.InteropServices;
  26.     using AccountComLib;
  27.     using System.EnterpriseServices;
  28.     using ADODB;
  29.  
  30.     [
  31.         TransactionAttribute(TransactionOption.Required)
  32.     ]
  33.     public class MoveMoney : ServicedComponent, IMoveMoney
  34.     {
  35.         // F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++
  36.         //
  37.         // Function: Perform
  38.         //
  39.         // Perform() performs error handling for TruePerform().  If TruePerform() throws an
  40.         // exception, then Perform() will call SetAbort() and pass the exception up
  41.         // to the caller.  Otherwise, Perform() will simply call SetComplete() and return.
  42.         //
  43.         // Args:     lngPrimeAccount -   "From" Account
  44.         //           lngSecondAccount -  "To" Account
  45.         //           lngAmount -         Amount of transaction
  46.         //           lngTranType -       Transaction Type
  47.         //                               (1 = Withdrawal,
  48.         //                                2 = Deposit,
  49.         //                                3 = Transfer)
  50.         //
  51.         // Returns:  String -        Account Balance
  52.         //
  53.         // F-F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---
  54.  
  55.         public String Perform (int lngPrimeAccount, int lngSecondAccount, int lngAmount, int tranType)
  56.         {
  57.  
  58.             String result = "";
  59.             bool bSuccess = false;
  60.  
  61.             try
  62.             {
  63.                 // Check for security
  64.                 if ((lngAmount > 500 || lngAmount < -500) && !ContextUtil.IsCallerInRole ("Managers"))
  65.                     throw new COMException ("Need 'Managers' role for amounts over $500");
  66.  
  67.                 // Call the true function
  68.                 result = truePerform (lngPrimeAccount, lngSecondAccount, lngAmount, tranType);
  69.  
  70.                 bSuccess = true;
  71.                 return result;
  72.             }
  73.             catch(Exception)
  74.             {
  75.                 throw;
  76.             }
  77.  
  78.  
  79.             // Upon exit, always call SetComplete if happy, or SetAbort if unhappy.
  80.             // We do this because we never save state across method calls.
  81.             finally
  82.             {
  83.                     if (bSuccess)
  84.                         ContextUtil.SetComplete();
  85.                     else
  86.                         ContextUtil.SetAbort();
  87.             }
  88.         }
  89.  
  90.         // F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++
  91.         //
  92.         // Function: Perform
  93.         //
  94.         // TruePerform() is the function that performs the actual work for the Account class.
  95.         // If an error occurs during execution, it will throw a COMException for Perform()
  96.         // to handle.
  97.         //
  98.         // Args:     lngPrimeAccount -   "From" Account
  99.         //           lngSecondAccount -  "To" Account
  100.         //           lngAmount -         Amount of transaction
  101.         //           lngTranType -       Transaction Type
  102.         //                               (1 = Withdrawal,
  103.         //                                2 = Deposit,
  104.         //                                3 = Transfer)
  105.         //
  106.         // Returns:  String -        Account Balance
  107.         //
  108.         // F-F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---
  109.  
  110.         private String truePerform (int lngPrimeAccount, int lngSecondAccount, int lngAmount, int tranType)
  111.         {
  112.  
  113.             String result = "";
  114.             IAccount objAccount = null;
  115.             IGetReceipt objReceipt = null;
  116.  
  117.             try
  118.             {
  119.                 // Create the account object
  120.                 objAccount = (IAccount) new Account();
  121.                 switch (tranType)
  122.                 {
  123.                 case 1:     // debit
  124.                     result = objAccount.Post (lngPrimeAccount, (- lngAmount));
  125.                     break;
  126.  
  127.                 case 2:     // credit
  128.                     result = objAccount.Post (lngPrimeAccount, lngAmount);
  129.                     break;
  130.  
  131.                 case 3:     // transfer
  132.                     result = objAccount.Post (lngPrimeAccount, (- lngAmount));
  133.                     result += ".  ";
  134.                     result += objAccount.Post (lngSecondAccount, lngAmount);
  135.                     break;
  136.  
  137.                 default:
  138.                     throw new COMException ("Invalid transaction type");
  139.                 }
  140.  
  141.  
  142.                 // Get the receipt for the transaction
  143.                 objReceipt = (IGetReceipt) new GetReceipt();
  144.                 int iReceiptNo = objReceipt.GetNextReceipt ();
  145.                 result += "; Receipt No:  " + iReceiptNo.ToString();
  146.             }
  147.  
  148.             finally
  149.             {
  150.             }
  151.             return result;
  152.         }
  153.     }
  154. }