/* @(#)update.cc 1.3 */ #include "protos.h" #include "update.h" /*GENB*/ #include "transac.h" #include "customer.h" #include "cardauth.h" //SEQb std::ostream& operator<<(std::ostream& f, UserOrderEnum kind) { switch(kind){ case USERORDER_WITHDRAWAL: comment("0"); break; case USERORDER_DEPOSIT: comment("1"); break; case USERORDER_MENU: comment("2"); break; case USERORDER_QUIT: comment("3"); break; case USERORDER_UNKNOWN: comment("UNKNOWN", "INCONNUE"); break; } return f; } std::istream& operator>>(std::istream& f, UserOrderEnum& kind) { int operation; ClearDisplay(); comment("\nSELECT AN OPERATION ______________________\n", "\nSELECTIONNEZ UNE OPERATION _______________\n"); comment("\t\tWithdrawal\t\t ", "\t\tRetrait\t\t\t "); std::cout<= 0) && (operation < 4)) // Bounds kind = (UserOrderEnum) operation; else kind = USERORDER_UNKNOWN; return f; } void Update::GenInit() //GENB { //GENB Account = 0; //GENB Transaction = 0; //GENB Amount = 0; } //GENB //SEQb Update::Update() //GENB { //GENB GenInit(); //GENB } //GENB //SEQe Update::Update(UserOrderEnum kind) { //GENB GenInit(); Kind = kind; //GENB } //GENB Update::~Update() //GENB { //GENB } //GENB void Update::Execute() { CustomerObj customer; AccountObj account; UserOrderMenuEnum menu; UpdateObj bufupdate; int choice; //Look for the customer customer = (Transaction->CardAuthorization)->Customer; // Look for the first account account = customer->Account; //cout<>Amount; Filter(std::cin, Amount); while (Amount <= 0) { comment("\t Incorrect Amount\n", "\t Montant incorrect\n"); comment("\nAmount ? : ", "\nMontant ? : "); //cin>>Amount; Filter(std::cin, Amount); } // Check if credit and balance are enough if (Amount < (account->Balance + account->CreditLimit)) { comment("Valid Transaction\n","Transaction autorisee\n"); account->Balance -= Amount; } else comment("Refused Transaction : Credit Limit reached\n", "Transaction refusee : Credit maximal atteint\n"); Delay(); break; case USERORDER_DEPOSIT: do { comment("\nAMOUNT ? : ", "\nMONTANT ? : "); Filter(std::cin, Amount); //cin>>Amount; } while(Amount <= 0); account->Balance += Amount; break; case USERORDER_MENU: //cout<<"\n"; //ClearDisplay(); comment("ARE YOU INTERESTED IN", "VOUS ETES INTERESSE PAR"); comment(" ____________\n", " ___________________________\n"); comment("\tBALANCE\t\t\t ", "\tLE SOLDE DE VOTRE COMPTE\t\t: "); std::cout<>choice; Filter(std::cin, choice); // Check if menu is into the bounds if (NEGATIVE(choice) || (choice >1)) menu = USERORDER_MENU_UNKNOWN; else menu = (UserOrderMenuEnum) choice; switch (menu) { case USERORDER_MENU_ACCOUNT_BALANCE: // Look for the first account account = customer->Account; comment("Balance of your account is : ", "Le solde de votre compte est : "); std::cout<Balance<<"\n\n"; break; case USERORDER_MENU_ACCOUNT_LAST: comment("\tList of last operations\t: ", "\tLa liste des dernieres operations\t: "); // Get past update and print //GENB for (bufupdate = Transaction->Update; bufupdate != NULL ; bufupdate = bufupdate->same_Transaction) { std::cout<<*bufupdate; std::cout<<"\n"; } break; case USERORDER_MENU_UNKNOWN : comment("Unknown transaction\n\n", "Transaction inconnue\n\n"); break; } Delay(); break; case USERORDER_QUIT: comment("\nThank you for your visit\n\n", "\nMerci de votre visite\n\n"); break; case USERORDER_UNKNOWN : comment("Unknown transaction\n\n", "Transaction inconnue\n\n"); break; } } std::ostream& operator<<(std::ostream& f, Update& update) { comment("\nOperation :\n"); comment("\tKind\t : ", "\tNature\t : "); std::cout<p_disconnect_Update(*this); //GENB p_disconnect_Transaction(*Transaction); //GENB } //GENB void Update::p_connect_Transaction (class Transaction& a_Transaction) //GENB { //GENB unset_Transaction(); //GENB Transaction = &a_Transaction; //GENB } //GENB void Update::p_disconnect_Transaction(class Transaction& a_Transaction) //GENB { //GENB assert(&a_Transaction == Transaction); //GENB Transaction = 0; //GENB } //GENB void Update::set_Account (class Account& a_Account) //GENB { //GENB p_connect_Account(a_Account); //GENB a_Account.p_connect_Update(*this); //GENB } //GENB void Update::unset_Account () //GENB { //GENB if (Account) Account->p_disconnect_Update(*this); //GENB p_disconnect_Account(*Account); //GENB } //GENB void Update::p_connect_Account (class Account& a_Account) //GENB { //GENB unset_Account(); //GENB Account = &a_Account; //GENB } //GENB void Update::p_disconnect_Account (class Account& a_Account) //GENB { //GENB assert(&a_Account == Account); //GENB Account = 0; //GENB } //GENB //SEQe //SETe //SEQe