?? briefcasemain.cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BriefCaseMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
BaseFileName = "EMPLOYEE.ADTG";
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::LoadData()
{
DataFileName = ExtractFilePath(ParamStr(0))+ BaseFileName;
// If a persisted datafile exists, assume we exited in a disconnected
// (offline) state and load the data from the file.
if (FileExists(DataFileName))
{
adodsEmployees->LoadFromFile(DataFileName);
}
else
{
// Otherwise establish the connection and get data from the database
ckbxConnectionInd->Checked = true;
adodsEmployees->Open();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::UpdateData()
{
// Connect to the database and send the pending updates }
ckbxConnectionInd->Checked = true;
adodsEmployees->UpdateBatch(arAll);
DeleteFile(DataFileName);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::SaveData()
{
adodsEmployees->SaveToFile(DataFileName, pfADTG);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ckbxConnectionIndClick(TObject *Sender)
{
if(ckbxConnectionInd->Checked)
{
// Toggle the connections state
adocnctnConnection->Open("", "");
adodsEmployees->Connection = adocnctnConnection;
adodsEmployees->Open();
}
else
{
// Note here you must clear the connection property of the
// dataset before closing the connection. Otherwise the dataset
// will close with the connection.
adodsEmployees->Connection = NULL;
adocnctnConnection->Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnUpdateButtonClick(TObject *Sender)
{
UpdateData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnRefreshButtonClick(TObject *Sender)
{
// Close and reopen the dataset to refresh the data. Note that in this demo
// there is no checking for pending updates so they are lost if you click
// the refresh data button before clicking the Update database button.
ckbxConnectionInd->Checked = true;
adodsEmployees->Close();
adodsEmployees->CommandType = cmdTable;
adodsEmployees->CommandText = "Employee";
adodsEmployees->Open();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnSaveButtonClick(TObject *Sender)
{
SaveData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if(adodsEmployees->Active)
{
try
{
// When closing, update the database if connected or save it to disk if not
if (adocnctnConnection->Connected)
UpdateData();
else
SaveData();
}
catch(Exception &E)
{
Application->HandleException(Sender);
CanClose = MessageDlg("Data not saved/updated, exit anyway?", mtConfirmation,
TMsgDlgButtons() <<mbYes <<mbNo <<mbCancel, 0)== mbYes;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
adocnctnConnection->ConnectionString = "FILE NAME=" + DataLinkDir() + "\\BCDEMOS.UDL";
LoadData();
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -