⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 AbsDataBase5.16 最新版
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "ABSMain"
#pragma resource "*.dfm"
TForm1 *Form1;

const AnsiString DataBaseFileName = "..\\..\\Data\\Demos.abs";

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  dbDemos->DatabaseFileName = ExtractFilePath(Application->ExeName) + DataBaseFileName;
  // enable multi-user mode
  dbDemos->MultiUser = True;
  dbDemos->Open();
  // open table
  ABSTable1->Active = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ABSTable1DeleteError(TDataSet *DataSet,
      EDatabaseError *E, TDataAction &Action)
{
   Action = daAbort;
   if (String(E->ClassName()) == "EABSEngineError") {
        switch (((EABSEngineError*)E)->ErrorCode) {
          case ABS_ERR_RECORD_LOCKED:
           {
             if (MessageDlg("The record is locked. Do you want to try to delete this record again?",
                             mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0)==mrYes)  Action = daRetry;
             break;
           }
          case ABS_ERR_TABLE_LOCKED:
           {
             if (MessageDlg("The table is locked. Do you want to try to delete this record again?",
                             mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0)==mrYes) Action = daRetry;
             break;
           }
          case ABS_ERR_DELETE_RECORD_MODIFIED:
           {
             MessageDlg("The record you are trying to delete has been modified by another user. The table will now be refreshed. If you want to delete this record, try again.",
                        mtWarning,TMsgDlgButtons()<<mbOK,0);
             DataSet->Refresh();
             break;
           }
          case ABS_ERR_DELETE_RECORD_DELETED:
           {
             MessageDlg("The record you are trying to delete has been deleted by another user The table will now be refreshed",
                        mtWarning,TMsgDlgButtons()<<mbOK,0);
             DataSet->Refresh();
             break;
           }
          default:
            MessageDlg(E->Message,mtError,TMsgDlgButtons()<<mbOK,0);
            break;
        }
   } else {
      MessageDlg(E->Message,mtError,TMsgDlgButtons()<<mbOK,0);
   }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ABSTable1EditError(TDataSet *DataSet,
      EDatabaseError *E, TDataAction &Action)
{
   Action = daAbort;
   if (String(E->ClassName()) == "EABSEngineError") {
        switch (((EABSEngineError*)E)->ErrorCode) {
          ABS_ERR_RECORD_LOCKED:
            {
             if (MessageDlg("The record you are trying to edit is locked. Do you want to try again?",
                           mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0)==mrYes) Action = daRetry;
             break;
            }
          ABS_ERR_TABLE_LOCKED:
            {
             if (MessageDlg("The table you are trying to edit is locked. Do you want to try again?",
                           mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0)==mrYes) Action = daRetry;
              break;
           }
          ABS_ERR_UPDATE_RECORD_MODIFIED:
           {
             MessageDlg("The record you are trying to edit has been modified by another user. The table will now be refreshed",
                        mtWarning,TMsgDlgButtons()<<mbOK,0);
             DataSet->Refresh();
             Action = daRetry;
             break;
           }
          ABS_ERR_UPDATE_RECORD_DELETED:
           {
             MessageDlg("The record you are trying to edit has been deleted by another user The table will now be refreshed",
                        mtWarning,TMsgDlgButtons()<<mbOK,0);
             DataSet->Refresh();
             Action = daRetry;
             break;
           }
          default:
           {
             MessageDlg(E->Message,mtError,TMsgDlgButtons()<<mbOK,0);
             break;
           }
        }
   } else {
      MessageDlg(E->Message,mtError,TMsgDlgButtons()<<mbOK,0);
   }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ABSTable1PostError(TDataSet *DataSet,
      EDatabaseError *E, TDataAction &Action)
{
   Action = daAbort;
   if (String(E->ClassName()) == "EABSEngineError") {
      if (((EABSEngineError*)E)->ErrorCode == ABS_ERR_CONSTRAINT_VIOLATED) {
         MessageDlg(((EABSEngineError*)E)->ErrorMessage+
                    ". Please change the record to make the constraint satisfied and re-post the record.",
                    mtError,TMsgDlgButtons()<<mbOK,0);
      } else if (((EABSEngineError*)E)->ErrorCode == ABS_ERR_TABLE_LOCKED) {
         if (MessageDlg("The table is locked. Do you want to try to post this record again?",
                        mtWarning,TMsgDlgButtons()<<mbYes<<mbNo,0)==mrYes) Action = daRetry;
      } else {
         MessageDlg(((EABSEngineError*)E)->ErrorMessage,mtError,TMsgDlgButtons()<<mbOK,0);
      }
   } else {
      MessageDlg(E->Message,mtError,TMsgDlgButtons()<<mbOK,0);
   }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -