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

📄 main.cpp

📁 Direct Oracle Access 非常好的Oracle数据库直接访问组件包 支持个版本的Delphi及C++ Builder 有源码
💻 CPP
字号:
// Direct Oracle Access - DeptEmp
// Allround Automations
// support@allroundautomations.nl
// http://www.allroundautomations.nl
//
// This application demonstrates:
// - The use of Master/Detail datasets
// - Using derived fields in an updateable dataset
// - The use of OnTranslateMessage & EnforceConstraints
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Oracle"
#pragma link "OracleData"
#pragma link "OracleNavigator"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
// Logon during form creation and open both datasets
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  MainLogon->Execute();
  if (MainSession->Connected)
  {
    DeptDataSet->Open();
    EmpDataSet->Open();
  }
}
//---------------------------------------------------------------------------
// Translate all known constraints
void __fastcall TMainForm::DeptDataSetTranslateMessage(
      TOracleDataSet *Sender, int ErrorCode,
      const AnsiString ConstraintName, char Action, AnsiString &Msg)
{
  if (ConstraintName == "EMP_PRIMARY_KEY")
    Msg = "An employee with this number already exists";
  if (ConstraintName == "DEPT_PRIMARY_KEY")
    Msg = "A department with this number already exists";
  if ((ConstraintName == "EMP_FOREIGN_KEY") && (ErrorCode == 2291))
    Msg = "This department does not exist";
  if ((ConstraintName == "EMP_FOREIGN_KEY") && (ErrorCode == 2292))
    Msg = "There are still employees in this department";
  if ((ConstraintName == "EMP_SELF_KEY") && (ErrorCode == 2291))
    Msg = "This employee does not exist";
  if ((ConstraintName == "EMP_SELF_KEY") && (ErrorCode == 2292))
    Msg = "This employee still manages some employees";
}
//---------------------------------------------------------------------------
// Check if Manager exists (and is in fact a manager)
void __fastcall TMainForm::MgrValidate(TField *Sender)
{
  if (Mgr->IsNull)
    MgrName->Clear();
  else
  {
    MgrQuery->SetVariable("EMPNO", Mgr->Value);
    MgrQuery->Execute();
    if (MgrQuery->Eof)
      throw(Exception("Employee does not exist"));
    else
    {
      // Is this employee a manager?
      if (Trim((AnsiString) MgrQuery->Field("JOB")) != "MANAGER")
        throw(Exception("This employee is not a manager"));
      MgrName->Value = MgrQuery->Field("ENAME");
    }
  }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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