p align="left">}; Рисунок 16. Проект и интерфейс банкомата Рисунок 17. Режим «Администрирование» ATMUnit/h //--------------------------------------------------------------------------- #ifndef atmunitH #define atmunitH //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <ExtCtrls.hpp> #include <ComCtrls.hpp> #include <Buttons.hpp> //--------------------------------------------------------------------------- class ATMObject { private: long _ID; String _serverName; public: ATMObject(){_serverName = "Wells Fargo"; _ID = 100;}; ATMObject(String name){_serverName = name; _ID = 100;}; String serverName(){return _serverName;} void serverName(String name){_serverName = name;} long ID(){return _ID;} void ID(long id){_ID = id;} }; class TFormATM : public TForm { __published: // IDE-managed Components TEdit *NameBox; TEdit *PINBox; TEdit *AmountBox; TLabel *Label1; TLabel *Label2; TLabel *Label3; TRadioGroup *Action; TMemo *Memo1; TRadioGroup *AccountType; TStatusBar *StatusBar1; TBitBtn *BitBtn1; TBitBtn *BitBtn2; TGroupBox *GroupBox1; TGroupBox *GroupBox2; TBitBtn *BitBtn3; TLabel *Label4; TLabel *Label5; TBevel *Bevel1; void __fastcall FormCreate(TObject/* */ *Sender); void __fastcall BitBtn1Click(TObject *Sender); void __fastcall BitBtn2Click(TObject *Sender); void __fastcall BitBtn3Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TFormATM(TComponent* Owner); ATMObject * ATM; long __fastcall TestConnection(); }; //--------------------------------------------------------------------------- extern PACKAGE TFormATM *FormATM; //--------------------------------------------------------------------------- #endif ATMUnit.cpp #include <vcl.h> #pragma hdrstop #include "atmunit.h" #include "servname.h" #include "xaction_c.hh" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" USE_STD_NS TFormATM *FormATM; //--------------------------------------------------------------------------- __fastcall TFormATM::TFormATM(TComponent* Owner) : TForm(Owner) { } char * const * argV; int argC; //--------------------------------------------------------------------------- // ///////////////////////////////////// // Mimic streaming to VCL Memo Window // ///////////////////////////////////// class catchit: public streambuf { TMemo * M; int ct; String S; char * cbuff; public: catchit(TMemo *Memo){M = Memo; ct = 1;}; int sync(); int overflow(int ch); }; int catchit::overflow(int ch) { S += (char)ch; return 0; } int catchit::sync() { // M->Lines->Strings[ct++] = S; M->Lines->Add(S); S = ""; return ct; } // //////////////////////////////////////////// // class _update // Instantiate this object to interface with the view // Usage: new _update(FormATM); // //////////////////////////////////////////// class _update { private: TFormATM * theForm; public: __fastcall _update(TFormATM* ATMForm) { theForm = ATMForm; } long AccountType() { return (long)theForm->AccountType->ItemIndex + 1; } EnumAction ActionType() { return (EnumAction)theForm->Action->ItemIndex; } long UserID() { if (theForm->NameBox->Text == "John") return 0; if (theForm->NameBox->Text == "Bill") return 1; if (theForm->NameBox->Text == "Jim") return 2; if (theForm->NameBox->Text == "Gene") return 3; if (theForm->NameBox->Text == "Wally") return 4; if (theForm->NameBox->Text == "Frank") return 5; return -1; // неизвестный пользователь } long PIN() { try { return (long)theForm->PINBox->Text.ToInt(); } catch (Exception &e) { return (long)0; } } double Amount() { return theForm->AmountBox->Text.ToDouble(); } void UpdateList() { theForm->Memo1->Lines->Clear(); theForm->Memo1->Lines->Add("John, PIN:123, Bank 1"); theForm->Memo1->Lines->Add("Bill, PIN:456, Bank 1"); theForm->Memo1->Lines->Add("Jim, PIN:789, Bank 1"); theForm->Memo1->Lines->Add("Gene, PIN:123, Bank 2"); theForm->Memo1->Lines->Add("Wally, PIN:456, Bank 2"); theForm->Memo1->Lines->Add("Frank, PIN:789, Bank 2"); } void UpdateMemo(String str) { theForm->Memo1->Lines->Add(str); } void UpdateStatus(String str) { theForm->StatusBar1->SimpleText = str; } void Clear() { theForm->Memo1->Clear(); } }; #define mrOK 1 long __fastcall TFormATM::TestConnection() { // проверка соединения try { CORBA::ORB_ptr orb = CORBA::ORB_init(); Server_ptr S = Server::_bind(ServerNameDlg->ServerNameEdit->Text.c_str()); return S->Balance(); } catch(CORBA::Exception &e) { return 0; } } //--------------------------------------------------------------------------- void __fastcall TFormATM::FormCreate(TObject *Sender) { ATM = new ATMObject(); } //--------------------------------------------------------------------------- void __fastcall TFormATM::BitBtn1Click(TObject *Sender) { // Администрирование if (ServerNameDlg->ShowModal() == mrOK) { ATM->serverName(ServerNameDlg->ServerNameEdit->Text); } } //--------------------------------------------------------------------------- void __fastcall TFormATM::BitBtn2Click(TObject *Sender) { // Список клиентов _update * U = new _update(FormATM); U->UpdateList(); delete U; } //--------------------------------------------------------------------------- void __fastcall TFormATM::BitBtn3Click(TObject *Sender) { // Выполнение операции catchit cbuf(Memo1); ostream CCout(&cbuf); // Visibroker имеет предопределенный Cout // Создание интерфейса просмотра ATM-объекта _update* Input = new _update(FormATM); // Создание объекта транзакции xaction_var X = new xaction; // "Заселение" объекта транзакции X->UserID = Input->UserID(); try { X->PIN = Input->PIN(); } catch (Exception &e) { X->PIN = 0; } X->amount = Input->Amount(); X->action = Input->ActionType(); X->account = Input->AccountType(); X->balance = 0.00; X->status = incomplete; try { // Старт ORB CORBA::ORB_ptr orb = CORBA::ORB_init(); Input->UpdateStatus("* ORB Инициализирован."); // Присоединение к ATM-серверу Server_ptr ATMServer = Server::_bind(ATM->serverName().c_str());
Страницы: 1, 2, 3, 4
|