home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Bank / Customer.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.9 KB  |  228 lines

  1.  
  2. /*+==========================================================================
  3.   File:      Customer.cpp
  4.  
  5.   Summary:   This file implements getting and setting the Customer
  6.              information
  7.  
  8.   Classes:   None
  9.  
  10.   Functions: Customer, GetId, SetId, GetFirst, 
  11.              SetFirst, GetLast, SetLast, GetAddress, SetAddress
  12.              GetCity, SetCity, GetState, SetState, GetZip, SetZip, 
  13.              GetChkAcct, GetSavAcct, GetLoan, GetMinLoanRate, GetNetWorth,
  14.              Load, Save
  15.  
  16. ----------------------------------------------------------------------------
  17.   This file is part of the Microsoft NGWS Samples.
  18.  
  19.   Copyright (C) 1998-2000 Microsoft Corporation.  All rights reserved.
  20. ==========================================================================+*/
  21. #using <mscorlib.dll>
  22.  
  23. #using "Account.dll"
  24. #using "Loan.dll"
  25. #using "RateSvr.dll"
  26.  
  27. // Needed define so that we do not get a __fltused unresoled external error.  This is due 
  28. // new changes and will be removed at a later date.
  29. extern "C" int _fltused=0;
  30.  
  31. using namespace System;
  32. using namespace System::IO;
  33.  
  34. #define NULL    0
  35.  
  36. __gc public class Customer 
  37. {
  38. private:
  39.     String*     m_Id;
  40.     String*        m_First;    
  41.     String*        m_Last;    
  42.     String*        m_Address;    
  43.     String*        m_City;    
  44.     String*        m_State;    
  45.     String*        m_Zip;    
  46.         
  47.     Account*    m_ChkAcct;
  48.     Account*        m_SavAcct;
  49.     Loan::BankLoan*        m_Loan;
  50.  
  51. public:
  52.     Customer();
  53.     
  54.     String *  GetId() {return m_Id;};
  55.     void SetId(String* Id) {m_Id = Id;};
  56.  
  57.     String * GetFirst() {return m_First;};
  58.     void SetFirst(String* First) {m_First = First;};
  59.  
  60.     String * GetLast() {return m_Last;};
  61.     void SetLast(String* Last) {m_Last = Last;};
  62.  
  63.     String * GetAddress() {return m_Address;};
  64.     void SetAddress(String * Address) {m_Address = Address;};
  65.  
  66.     String * GetCity() {return m_City;};
  67.     void SetCity(String *  City) {m_City = City;};
  68.  
  69.     String * GetState() {return m_State;};
  70.     void SetState(String *  State) {m_State = State;};
  71.  
  72.     String * GetZip() {return m_Zip;};
  73.     void SetZip(String* Zip) {m_Zip = Zip;};
  74.  
  75.     Account* GetChkAcct();
  76.     Account*  GetSavAcct();
  77.     Loan::BankLoan * GetLoan();
  78.  
  79.     double GetMinLoanRate(double Amount, double Term);
  80.     double GetNetWorth();
  81.     
  82.     short Load(String * Id);
  83.     short Save(void);
  84. };
  85.  
  86.  
  87.  
  88. Customer::Customer()
  89. {
  90.     m_Id = new String(L"");
  91.     m_First = new String(L"");    
  92.     m_Last = new String(L"");
  93.     m_Address = new String(L"");
  94.     m_City = new String(L"");
  95.     m_State = new String(L"");
  96.     m_Zip = new String(L"");
  97.  
  98.     m_ChkAcct = NULL;
  99.     m_SavAcct = NULL;
  100.     m_Loan = NULL;
  101. }
  102.  
  103.  
  104.  
  105. Account *  Customer::GetChkAcct()
  106. {
  107.     if (m_ChkAcct == NULL)
  108.         m_ChkAcct = new Account();
  109.  
  110.     return m_ChkAcct;
  111. }
  112.  
  113. Account *  Customer::GetSavAcct()
  114. {
  115.     if (m_SavAcct == NULL)
  116.         m_SavAcct = new Account();
  117.  
  118.     return m_SavAcct;
  119. }
  120.  
  121. Loan::BankLoan* Customer::GetLoan()
  122. {
  123.     if (m_Loan == NULL)
  124.         m_Loan = new Loan::BankLoan();
  125.  
  126.     return m_Loan;
  127. }
  128.  
  129. double Customer::GetMinLoanRate(double Amount, double Term)
  130. {
  131.     double MinRate = 0.0;
  132.  
  133.     RateSvr::RateLookup *rl;
  134.     rl = new RateSvr::RateLookup;
  135.     MinRate = rl->GetLoanRate(Amount, Term);
  136.  
  137.     return MinRate;
  138. }
  139.  
  140. double Customer::GetNetWorth()
  141. {
  142.     double nw = 0.0;
  143.  
  144.     if (m_ChkAcct != NULL)
  145.         nw = nw + m_ChkAcct->GetBalance();
  146.  
  147.     if (m_SavAcct != NULL)
  148.         nw = nw + m_SavAcct->GetBalance();
  149.  
  150.     if (m_Loan != NULL)
  151.         nw = nw - m_Loan->GetBalance();
  152.     
  153.     return nw;
  154. }
  155.  
  156. short Customer::Load(String *  Id)
  157. {
  158.     String *  filename = String::Concat( Id, L".txt");
  159.     
  160.     try {
  161.         StreamReader * tis = new StreamReader (filename);
  162.  
  163.         m_Id = Id;
  164.         m_First = tis->ReadLine();
  165.         m_Last = tis->ReadLine();
  166.         m_Address = tis->ReadLine();
  167.         m_City = tis->ReadLine();
  168.         m_State = tis->ReadLine();
  169.         m_Zip = tis->ReadLine();
  170.  
  171.         String *  buf;
  172.  
  173.         buf = tis->ReadLine();
  174.         m_ChkAcct->SetBalance(Double :: Parse (buf));
  175.  
  176.         buf = tis->ReadLine();
  177.         m_SavAcct->SetBalance(Double :: Parse (buf));
  178.  
  179.         buf = tis->ReadLine();
  180.         m_Loan->SetBalance(Double :: Parse (buf));
  181.  
  182.         buf = tis->ReadLine();
  183.         m_Loan->SetPrincipal(Double :: Parse (buf));
  184.  
  185.         buf = tis->ReadLine();
  186.         m_Loan->SetRate(Double :: Parse (buf) / 100);
  187.  
  188.         buf = tis->ReadLine();
  189.         m_Loan->SetTerm(Double :: Parse (buf));
  190.  
  191.         buf = tis->ReadLine();
  192.         m_Loan->SetPayment(Double :: Parse (buf));
  193.  
  194.         tis->Close();
  195.     }
  196.     catch (Exception * e) {
  197.         return false;
  198.     }
  199.     return true;
  200. }
  201.  
  202. short Customer::Save()
  203. {
  204.     String * filename  = String::Concat(m_Id, L".txt");
  205.  
  206.     StreamWriter *  tos = new StreamWriter(filename, false);
  207.  
  208.     tos->WriteLine(m_First);
  209.     tos->WriteLine(m_Last);
  210.     tos->WriteLine(m_Address);
  211.     tos->WriteLine(m_City);
  212.     tos->WriteLine(m_State);
  213.     tos->WriteLine(m_Zip);
  214.  
  215.     tos->WriteLine(m_ChkAcct->GetBalance());
  216.     tos->WriteLine(m_SavAcct->GetBalance());
  217.  
  218.     tos->WriteLine(m_Loan->GetBalance());
  219.     tos->WriteLine(m_Loan->GetPrincipal());
  220.     tos->WriteLine(m_Loan->GetRate()*100);
  221.     tos->WriteLine(m_Loan->GetTerm());
  222.     tos->WriteLine(m_Loan->GetPayment());
  223.  
  224.     tos->Close();
  225.     
  226.     return true;
  227. }
  228.