на тему рефераты Информационно-образоательный портал
Рефераты, курсовые, дипломы, научные работы,
на тему рефераты
на тему рефераты
МЕНЮ|
на тему рефераты
поиск
Технология CORBA
p align="left">Input->UpdateStatus("Присоединение к ATM-серверу завершено.");

Input->UpdateStatus("ATM-сервер открыт.");

// Передача транзакции ATM-серверу

ATMServer->HandleTransaction(X);

if (X->status == complete) {

Input->UpdateMemo("Баланс счёта: $" + CurrToStr(X->balance));

Input->UpdateMemo("Транзакция завершена.");

} else if (X->status == incomplete) {

Input->UpdateMemo("Транзакция не обработана.");

Input->UpdateMemo("Баланс счёта: $" + CurrToStr(X->balance));

} else if (X->status == invalid) {

Input->Clear();

Input->UpdateMemo("* ID клиента и PIN не найдены!");

}

}

catch(const CORBA::Exception& e) {

CCout << e._name() << endl;

Input->UpdateStatus("* ATM-сервер отключен!");

}

}

//---------------------------------------------------------------------------

Servername.h

//----------------------------------------------------------------------------

#ifndef servnameH

#define servnameH

//----------------------------------------------------------------------------

#include <vcl\System.hpp>

#include <vcl\Windows.hpp>

#include <vcl\SysUtils.hpp>

#include <vcl\Classes.hpp>

#include <vcl\Graphics.hpp>

#include <vcl\StdCtrls.hpp>

#include <vcl\Forms.hpp>

#include <vcl\Controls.hpp>

#include <vcl\Buttons.hpp>

#include <vcl\ExtCtrls.hpp>

//----------------------------------------------------------------------------

class TServerNameDlg : public TForm

{

__published:

TButton *OKBtn;

TButton *CancelBtn;

TBevel *Bevel1;

TLabel *Label1;

TLabel *ServerNameLabel;

TEdit *ServerNameEdit;

TLabel *Label2;

TButton *ConnectButton;

TLabel *Label3;

TLabel *CountLabel;

TLabel *ResultLabel;

void __fastcall FormShow(TObject/* */ *Sender);

void __fastcall ConnectButtonClick(TObject/* */ *Sender);

void __fastcall OKBtnClick(TObject/* */ *Sender);

private:

public:

virtual __fastcall TServerNameDlg(TComponent* AOwner);

};

//----------------------------------------------------------------------------

extern PACKAGE TServerNameDlg *ServerNameDlg;

//----------------------------------------------------------------------------

#endif

Servername.cpp

#include <vcl.h>

#pragma hdrstop

#include "servname.h"

#include "atmunit.h"

//---------------------------------------------------------------------

#pragma resource "*.dfm"

TServerNameDlg *ServerNameDlg;

//---------------------------------------------------------------------

__fastcall TServerNameDlg::TServerNameDlg(TComponent* AOwner)

: TForm(AOwner)

{

}

//---------------------------------------------------------------------

void __fastcall TServerNameDlg::FormShow(TObject/* */ *Sender)

{

ServerNameLabel->Caption = FormATM->ATM->serverName();

ServerNameEdit->Text = ServerNameLabel->Caption;

ResultLabel->Caption = "";

}

//---------------------------------------------------------------------------

void __fastcall TServerNameDlg::ConnectButtonClick(TObject/* */ *Sender)

{

CountLabel->Caption = String(FormATM->TestConnection());

if (CountLabel->Caption == "0")

ResultLabel->Caption = "* Соединения нет!";

else

ResultLabel->Caption = "Соединение установлено.";

}

//---------------------------------------------------------------------------

void __fastcall TServerNameDlg::OKBtnClick(TObject/* */ *Sender)

{

if (CountLabel->Caption != String("0")) {

FormATM->ATM->serverName(ServerNameEdit->Text);

}

}

//---------------------------------------------------------------------------

Рисунок 5.18. Проект и интерфейс ATM-сервера

#ifndef atmserverunitH

#define atmserverunitH

//---------------------------------------------------------------------------

#include <Classes.hpp>

#include <Controls.hpp>

#include <StdCtrls.hpp>

#include <Forms.hpp>

#include "xaction_s.hh"

#include "banking_s.hh"

#include <Buttons.hpp>

//---------------------------------------------------------------------------

class TForm2 : public TForm

{

__published: // IDE-managed Components

TLabel *Transactions;

TEdit *Count;

TEdit *ServerNameEdit;

TLabel *Label1;

TBitBtn *BitBtn1;

TGroupBox *GroupBox2;

TGroupBox *GroupBox1;

TBitBtn *BitBtn2;

TMemo *Memo1;

TComboBox *BankBox;

void __fastcall FormClose(TObject *Sender, TCloseAction &Action);

void __fastcall BitBtn1Click(TObject *Sender);

void __fastcall BitBtn2Click(TObject *Sender);

private: // User declarations

public: // User declarations

__fastcall TForm2(TComponent* Owner);

void StartServer();

void DownServer();

CORBA::ORB_var orb;

CORBA::BOA_var boa;

CORBA::Object_ptr obj;

String CurrentServerName;

};

//---------------------------------------------------------------------------

extern PACKAGE TForm2 *Form2;

//---------------------------------------------------------------------------

#endif

ATMServerUnit.cpp

#include <vcl.h>

#pragma hdrstop

#include "atmserverunit.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm2 *Form2;

//---------------------------------------------------------------------------

__fastcall TForm2::TForm2(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

char * const * argV;

int argC;

//---------------------------------------------------------------------------

// /////////////////////////////////////

// Implement CORBA object from skeleton class

// /////////////////////////////////////

class ATMServerImpl : public _sk_Server

{

public:

ATMServerImpl(const char *object_name);

void UpCount(int i = 0){

if (i == 1) {

Form2->Memo1->Lines->Add("ATM-сервер включен.");

return;

}

Form2->Count->Text = String(count++);

}

virtual xaction HandleTransaction(xaction& Transaction)

{

UpCount();

Form2->Memo1->Lines->Add("Банк найден.");

Transaction.status = invalid;

for (int i = 0; i < UserCount; i++) {

if(Transaction.UserID == CardHolders[i]->UserID) {

if (Transaction.PIN == CardHolders[i]->PIN) {

Transaction.status = OK;

try {

BankServer_var BankServer = BankServer::_bind((*Banks[CardHolders[i]->Bank]).c_str());

BankServer->HandleTransaction(Transaction);

Form2->Memo1->Lines->Add("Транзакция с " + *Banks[CardHolders[i]->Bank]);

} catch(CORBA::Exception &e){

Form2->Memo1->Lines->Add("* Сервер банка недоступен!");

return Transaction;

}

}

}

}

// Transaction.status = complete;

return Transaction;

}

virtual CORBA::Long Balance(){UpCount(); return CORBA::Long(count);}

class NoServer: public CORBA::UserException

{

public:

NoServer(){}

static ATMServerImpl::NoServer* _narrow() throw (CORBA::SystemException);

};

private:

int count;

struct _user{

long UserID;

long Bank;

long PIN;

};

_user * CardHolders[10];

long BankOne;

long BankTwo;

int UserCount;

String * Banks[10];

};

ATMServerImpl::ATMServerImpl(const char *object_name=NULL) :

_sk_Server(object_name)

{

count = 0;

UserCount = 0;

UpCount(1);

Banks[0] = new String("BankOne");

Banks[1] = new String("BankTwo");

TStrings *SL = new TStringList();

SL->Add(*Banks[0]);

SL->Add(*Banks[1]);

Form2->BankBox->Items->Assign(SL);

Form2->BankBox->ItemIndex = 0;

BankOne = 0;

Страницы: 1, 2, 3, 4



© 2003-2013
Рефераты бесплатно, курсовые, рефераты биология, большая бибилиотека рефератов, дипломы, научные работы, рефераты право, рефераты, рефераты скачать, рефераты литература, курсовые работы, реферат, доклады, рефераты медицина, рефераты на тему, сочинения, реферат бесплатно, рефераты авиация, рефераты психология, рефераты математика, рефераты кулинария, рефераты логистика, рефераты анатомия, рефераты маркетинг, рефераты релиния, рефераты социология, рефераты менеджемент.