/*
**************************** !!!  !!! *****************************
            
     .
       "Tools\Debugger Options", 
"Language Exceptions".  "Stop On Delphi Exceptions"  .
***************************************************************************
*/
//---------------------------------------------------------------------------
#include <vcl.h>
#include <comobj.hpp>
#pragma hdrstop

#include "fmuMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
Variant ECR;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void Demo()
{
//  
  ECR.OlePropertySet("DeviceEnabled", true);
  if (ECR.OlePropertyGet("ResultCode") != 0) return;

//   
  if (ECR.OleFunction("GetStatus") != 0) return;

//       
  if ((bool)ECR.OlePropertyGet("Fiscal"))
    if (Application->MessageBox(" !    ?", Application->Title.c_str(), MB_ICONEXCLAMATION + MB_YESNO) == IDNO)
      return;

//    ,   
  if (ECR.OlePropertyGet("CheckState") != 0)
    if (ECR.OleFunction("CancelCheck") != 0) return;

//     Z-
  if ((bool)ECR.OlePropertyGet("SessionOpened"))
  {
    //     
    ECR.OlePropertySet("Password", "30");
    //      
    ECR.OlePropertySet("Mode", 3);
    if (ECR.OleFunction("SetMode") != 0) return;
    //  
    ECR.OlePropertySet("ReportType", 1);
    if (ECR.OleFunction("Report") != 0) return;
  };

//    
  //   
  ECR.OlePropertySet("Password", "1");
  //    
  ECR.OlePropertySet("Mode", 1);
  if (ECR.OleFunction("SetMode") != 0) return;

//   
  //  
  ECR.OlePropertySet("Name", "");
  ECR.OlePropertySet("Price", 10.45);
  ECR.OlePropertySet("Quantity", 1);
  ECR.OlePropertySet("Department", 2);
  if (ECR.OleFunction("Registration") != 0) return;
  //     
  ECR.OlePropertySet("Percents", 10);
  ECR.OlePropertySet("Destination", 1);
  if (ECR.OleFunction("PercentsDiscount") != 0) return;
  //  
  ECR.OlePropertySet("Name", "");
  ECR.OlePropertySet("Price", 25);
  ECR.OlePropertySet("Quantity", 5);
  ECR.OlePropertySet("Department", 1);
  if (ECR.OleFunction("Registration") != 0) return;
  //     
  ECR.OlePropertySet("Summ", 10.40);
  ECR.OlePropertySet("Destination", 0);
  if (ECR.OleFunction("SummDiscount") != 0) return;
  //         
  ECR.OlePropertySet("TypeClose", 0);
  if (ECR.OleFunction("CloseCheck") != 0) return;

//   
  //  
  ECR.OlePropertySet("Name", "");
  ECR.OlePropertySet("Price", 10.45);
  ECR.OlePropertySet("Quantity", 1);
  ECR.OlePropertySet("Department", 2);
  if (ECR.OleFunction("Registration") != 0) return;
  //  
  ECR.OlePropertySet("Name", "-");
  ECR.OlePropertySet("Price", 25.00);
  ECR.OlePropertySet("Quantity", 5);
  ECR.OlePropertySet("Department", 1);
  if (ECR.OleFunction("Registration") != 0) return;
  //   
  if (ECR.OleFunction("Storno") != 0) return;
  //  
  ECR.OlePropertySet("Name", "");
  ECR.OlePropertySet("Price", 25);
  ECR.OlePropertySet("Quantity", 5);
  ECR.OlePropertySet("Department", 1);
  if (ECR.OleFunction("Registration") != 0) return;
  //     
  ECR.OlePropertySet("Summ", 50);
  ECR.OlePropertySet("Destination", 0);
  if (ECR.OleFunction("SummDiscount") != 0) return;
  //         
  ECR.OlePropertySet("Summ", 100);
  ECR.OlePropertySet("TypeClose", 0);
  if (ECR.OleFunction("Delivery") != 0) return;

// 
  //  
  ECR.OlePropertySet("Name", "Dirol");
  ECR.OlePropertySet("Price", 7);
  ECR.OlePropertySet("Quantity", 1);
  if (ECR.OleFunction("Annulate") != 0) return;
  //  
  ECR.OlePropertySet("Name", "Orbit");
  ECR.OlePropertySet("Price", 8);
  ECR.OlePropertySet("Quantity", 2);
  if (ECR.OleFunction("Annulate") != 0) return;
  //  
  ECR.OlePropertySet("TypeClose", 0);
  if (ECR.OleFunction("CloseCheck") != 0) return;

// 
  //  
  ECR.OlePropertySet("Name", "");
  ECR.OlePropertySet("Price", 10.45);
  ECR.OlePropertySet("Quantity", 1);
  if (ECR.OleFunction("Return") != 0) return;
  //  
  ECR.OlePropertySet("Name", "");
  ECR.OlePropertySet("Price", 99.99);
  ECR.OlePropertySet("Quantity", 1.235);
  if (ECR.OleFunction("Return") != 0) return;
  //     
  ECR.OlePropertySet("Summ", 50);
  ECR.OlePropertySet("Destination", 0);
  if (ECR.OleFunction("SummDiscount") != 0) return;
  //  
  ECR.OlePropertySet("TypeClose", 0);
  if (ECR.OleFunction("CloseCheck") != 0) return;

//  
  ECR.OlePropertySet("Summ", 400.50);
  if (ECR.OleFunction("CashIncome") != 0) return;

//  
  ECR.OlePropertySet("Summ", 121.34);
  if (ECR.OleFunction("CashOutcome") != 0) return;

// X - 
  //    
  ECR.OlePropertySet("Password", "29");
  //      
  ECR.OlePropertySet("Mode", 2);
  if (ECR.OleFunction("SetMode") != 0) return;
  //  
  ECR.OlePropertySet("ReportType", 2);
  if (ECR.OleFunction("Report") != 0) return;

// Z - 
  //     
  ECR.OlePropertySet("Password", "30");
  //      
  ECR.OlePropertySet("Mode", 3);
  if (ECR.OleFunction("SetMode") != 0) return;
  //  
  ECR.OlePropertySet("ReportType", 1);
  if (ECR.OleFunction("Report") != 0) return;

//    ,  -        
  if (ECR.OleFunction("ResetMode") != 0) return;

//  
  ECR.OlePropertySet("DeviceEnabled", false);
  if (ECR.OlePropertyGet("ResultCode") != 0) return;

  Application->MessageBox("   .", Application->Title.c_str(), MB_ICONINFORMATION + MB_OK);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
//     
//       ,     
  try
  {
    ECR = CreateOleObject("AddIn.FprnM45");
    ECR.OlePropertySet("ApplicationHandle", int(Application->Handle)); //         
  }
  catch (Exception &exception)
  {
    Application->MessageBox("      !", Application->Title.c_str(), MB_ICONERROR + MB_OK);
    Application->Terminate();
  };
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormDestroy(TObject *Sender)
{
//   
  ECR = 0;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnShowPropertiesClick(TObject *Sender)
{
  ECR.OleFunction("ShowProperties");
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnStartClick(TObject *Sender)
{
  btnStart->Enabled = false;
  btnShowProperties->Enabled = false;

  Demo();
  if (ECR.OlePropertyGet("ResultCode") != 0)
    Application->MessageBox((" : " + ECR.OlePropertyGet("ResultDescription") + "!").c_str(), Application->Title.c_str(), MB_ICONERROR + MB_OK);

  btnStart->Enabled = true;
  btnShowProperties->Enabled = true;
}
//---------------------------------------------------------------------------
