home *** CD-ROM | disk | FTP | other *** search
- // dbengsam.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "dbeng.h"
- #include "dbengsam.h"
- #include "dbeng2.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CDBENGSAMP dialog
-
- CDBENGSAMP::CDBENGSAMP(CWnd* pParent /*=NULL*/)
- : CDialog(CDBENGSAMP::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDBENGSAMP)
- m_dbengine = NULL;
- m_id = "";
- m_lastname = "";
- m_firstname = "";
- m_mi = "";
- //}}AFX_DATA_INIT
- }
-
- void CDBENGSAMP::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDBENGSAMP)
- DDX_VBControl(pDX, IDC_DBENGINE1, m_dbengine);
- DDX_Text(pDX, IDC_EDIT1, m_id);
- DDX_Text(pDX, IDC_EDIT2, m_lastname);
- DDX_Text(pDX, IDC_EDIT3, m_firstname);
- DDX_Text(pDX, IDC_EDIT4, m_mi);
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CDBENGSAMP, CDialog)
- //{{AFX_MSG_MAP(CDBENGSAMP)
- ON_BN_CLICKED(IDC_BUTTON1, OnCreateTable)
- ON_BN_CLICKED(IDC_BUTTON2, OnCreateIndex)
- ON_BN_CLICKED(IDC_BUTTON3, OnOpenTable)
- ON_BN_CLICKED(IDC_BUTTON4, OnCloseTable)
- ON_BN_CLICKED(IDC_BUTTON5, OnTop)
- ON_BN_CLICKED(IDC_BUTTON6, OnBottom)
- ON_BN_CLICKED(IDC_BUTTON7, OnNext)
- ON_BN_CLICKED(IDC_BUTTON8, OnPrevious)
- ON_BN_CLICKED(IDC_BUTTON9, OnInsert)
- ON_BN_CLICKED(IDC_BUTTON10, OnUpdate)
- ON_BN_CLICKED(IDC_BUTTON11, OnDelete)
- ON_BN_CLICKED(IDC_BUTTON12, OnClear)
- ON_BN_CLICKED(IDC_BUTTON13, OnHide)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CDBENGSAMP message handlers
-
- void CDBENGSAMP::OnCreateTable()
- {
- // This function creates the C:\TEST database table with the following
- // Table structure:
- //
- // Field Field Type
- // -----------------------------------
- // ID N
- // Last Name A30
- // First Name A20
- // Middle Initial A1
-
- long result;
-
- m_dbengine->SetStrProperty("TableName","C:\\TEST");
- m_dbengine->SetNumProperty("NFields",4);
- m_dbengine->SetStrProperty("TableFieldNames","ID,Last Name,First Name,Middle Initial");
- m_dbengine->SetStrProperty("TableFieldTypes","N,A30,A20,A1");
- m_dbengine->SetNumProperty("Action",CreateTable);
- result = m_dbengine->GetNumProperty("Reaction");
-
- // If the database table could not be created display meesage box.
- if(result != 0)
- DisplayError();
-
-
- }
-
- void CDBENGSAMP::OnCreateIndex()
- {
- // This function will create a primary index for our C:\TEST
- // database table. The primary index will contain one key field
- // ID. Once the primary index is created our database table will
- // have the following structure:
- //
- // Field Field Type
- // -----------------------------------
- // ID N*
- // Last Name A30
- // First Name A20
- // Middle Initial A1
- //
- // Where key fields are marked with an *.
-
- long result;
-
- m_dbengine->SetNumProperty("IndexNFields",1);
- m_dbengine->SetNumProperty("IndexId",1);
- m_dbengine->SetNumProperty("IndexType", Primary);
-
- m_dbengine->SetNumProperty("Action",CreateIndex);
- result = m_dbengine->GetNumProperty("Reaction");
-
- // If the database table could not be created display meesage box.
- if(result != 0)
- DisplayError();
-
-
- }
-
- void CDBENGSAMP::OnOpenTable()
- {
- // This function opens the C:\TEST database table and fills
- // in the form with the information present in the first record.
-
- long result;
-
-
- // Open the database table
- m_dbengine->SetNumProperty("Action",OpenTable);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else
-
- FillForm();
-
- }
-
- void CDBENGSAMP::OnCloseTable()
- {
- long result;
- // This function closes the database table.
-
- m_dbengine->SetNumProperty("Action",CloseTable);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
-
- }
-
- void CDBENGSAMP::OnTop()
- {
- long result;
-
-
- // Move to the first record in the database table then fill the form
-
- m_dbengine->SetNumProperty("Action",FirstRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else
- FillForm();
-
- }
-
- void CDBENGSAMP::OnBottom()
- {
- long result;
-
-
- // Move to the last record in the database table then fill the form
-
- m_dbengine->SetNumProperty("Action",LastRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else
- FillForm();
-
- }
-
- void CDBENGSAMP::OnNext()
- {
- long result;
-
-
- // Move to the next record in the database table then fill the form
-
- m_dbengine->SetNumProperty("Action",NextRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else
- FillForm();
-
- }
-
- void CDBENGSAMP::OnPrevious()
- {
- long result;
-
-
- // Move to the previous record in the database table then fill the form
-
- m_dbengine->SetNumProperty("Action",PreviousRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else
- FillForm();
-
- }
-
- void CDBENGSAMP::OnInsert()
- {
- long result;
-
- // Insert the form data into the database table
-
- PutForm(); // Place form data into the current record
- m_dbengine->SetNumProperty("Action",InsertRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
-
- }
-
- void CDBENGSAMP::OnUpdate()
- {
- long result;
-
- // Updates the current record with data present on the form
-
- PutForm(); // Place form data into the current record
- m_dbengine->SetNumProperty("Action",UpdateRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
-
- }
-
- void CDBENGSAMP::OnDelete()
- {
- long result;
-
- // Delete the current record
- m_dbengine->SetNumProperty("Action",DeleteRecord);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else
- FillForm();
-
- }
-
- void CDBENGSAMP::OnClear()
- {
-
- // This function just clears the form (Dialog Box) fields.
- // No database operations are performed here.
-
- CWnd *pCtlMyString = GetDlgItem(IDC_EDIT1);
-
-
- m_id = "";
- pCtlMyString->SetWindowText(m_id);
- m_lastname = "";
- pCtlMyString = GetDlgItem(IDC_EDIT2);
- pCtlMyString->SetWindowText(m_lastname);
- m_firstname = "";
- pCtlMyString = GetDlgItem(IDC_EDIT3);
- pCtlMyString->SetWindowText(m_firstname);
- m_mi = "";
- pCtlMyString = GetDlgItem(IDC_EDIT4);
- pCtlMyString->SetWindowText(m_mi);
-
- }
-
- void CDBENGSAMP::OnHide()
- {
- // Hide the DBEngine Custom Control by setting the Visible property False
-
- m_dbengine->SetNumProperty("Visible",0);
- }
-
-
- void CDBENGSAMP::FillForm()
- {
-
- // This function fills the form (Dialog Box) with the information
- // contained in the DBEngine Custom Control's current record.
-
- CWnd *pCtlMyString = GetDlgItem(IDC_EDIT1);
- long result;
-
- // Get the first record in the database table
- // Before we can GetField(s) we must first GetRecord.
- m_dbengine->SetNumProperty("Action",GetRecord);
-
- // Get the ID field value
- m_dbengine->SetStrProperty("FieldName","ID"); // field of interest
- m_dbengine->SetNumProperty("Action",GetField); // Get the field value
- result = m_dbengine->GetNumProperty("Reaction"); // GetField OK?
- if(result != 0)
- DisplayError(); // display error
- else { // if no error
- m_id = m_dbengine->GetStrProperty("FieldValue"); // assign field value to id variable.
- pCtlMyString = GetDlgItem(IDC_EDIT1); // Then place it on the form
- pCtlMyString->SetWindowText(m_id); // (Dialog Box).
- }
-
- // Repeat the process for each and every field on the form (Dialog Box).
-
- // Get Last Name field value
- m_dbengine->SetStrProperty("FieldName","Last Name");
- m_dbengine->SetNumProperty("Action",GetField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else { // if no error
- m_lastname = m_dbengine->GetStrProperty("FieldValue");
- pCtlMyString = GetDlgItem(IDC_EDIT2);
- pCtlMyString->SetWindowText(m_lastname);
- }
-
- // Get First Name field value
- m_dbengine->SetStrProperty("FieldName","First Name");
- m_dbengine->SetNumProperty("Action",GetField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else { // if no error
- m_firstname = m_dbengine->GetStrProperty("FieldValue");
- pCtlMyString = GetDlgItem(IDC_EDIT3);
- pCtlMyString->SetWindowText(m_firstname);
- }
-
- // Get Middle Initial (MI) field value
- m_dbengine->SetStrProperty("FieldName","Middle Initial");
- m_dbengine->SetNumProperty("Action",GetField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- else { // if no error
- m_mi = m_dbengine->GetStrProperty("FieldValue");
- pCtlMyString = GetDlgItem(IDC_EDIT4);
- pCtlMyString->SetWindowText(m_mi);
- }
- }
-
- void CDBENGSAMP::PutForm()
- {
-
- // This function transfers the information contained in the form
- // (Dialog Box) to the DBEngine Custom Control's current record.
- // Information will not be placed in the database table until a
- // InsertRecord or UpdateRecord Action is performed.
-
- long result;
-
- UpdateData(TRUE); // Transfer data from form to string variables
-
- // Place the ID field into the current record
- m_dbengine->SetStrProperty("FieldName","ID");
- m_dbengine->SetStrProperty("FieldValue",m_id);
- m_dbengine->SetNumProperty("Action",PutField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
-
- // Place the Last Name field into the current record
- m_dbengine->SetStrProperty("FieldName","Last Name");
- m_dbengine->SetStrProperty("FieldValue",m_lastname);
- m_dbengine->SetNumProperty("Action",PutField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
-
- // Place the First Name field into the current record
- m_dbengine->SetStrProperty("FieldName","First Name");
- m_dbengine->SetStrProperty("FieldValue",m_firstname);
- m_dbengine->SetNumProperty("Action",PutField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
-
- // Place the MI field into the current record
- m_dbengine->SetStrProperty("FieldName","Middle Initial");
- m_dbengine->SetStrProperty("FieldValue",m_mi);
- m_dbengine->SetNumProperty("Action",PutField);
- result = m_dbengine->GetNumProperty("Reaction");
- if(result != 0)
- DisplayError();
- }
-
- void CDBENGSAMP::DisplayError()
- {
-
- long result;
- int temp;
-
- // This error handling routine is not complete.
- // It provides an example of how such a routine can be
- // constructed.
- //
- // If you continue to get an Unknown error! message when
- // you run this sample program, set a breakpoint at the
- // first line of code below and look at the value in the
- // result variable (the DBEngine Reaction property setting)
- // and cross index the error code with the error code listing
- // in the Appendix of the DBEngine 2.0 Custom Control Reference Guide.
-
- result = m_dbengine->GetNumProperty("Reaction");
- switch(result) {
-
- case 1:
- temp = AfxMessageBox("Drive not ready!", MB_OK,0);
- break;
-
- case 2:
- temp = AfxMessageBox("Directory not found!", MB_OK,0);
- break;
-
- case 3:
- temp = AfxMessageBox("File is busy!", MB_OK,0);
- break;
-
- case 4:
- temp = AfxMessageBox("File is locked!", MB_OK,0);
- break;
-
- case 5:
- temp = AfxMessageBox("File not found!", MB_OK,0);
- break;
-
- case 6:
- temp = AfxMessageBox("Table is corrupt!", MB_OK,0);
- break;
-
- case 7:
- temp = AfxMessageBox("Primary index is corrupt!", MB_OK,0);
- break;
-
- case 8:
- temp = AfxMessageBox("Primary index is out of date!", MB_OK,0);
- break;
-
- case 9:
- temp = AfxMessageBox("Record is locked!", MB_OK,0);
- break;
-
- case 10:
- temp = AfxMessageBox("Sharing violation!", MB_OK,0);
- break;
-
- case 11:
- temp = AfxMessageBox("Sharing violation!", MB_OK,0);
- break;
-
- case 12:
- temp = AfxMessageBox("No access to directory!", MB_OK,0);
- break;
-
- case 13:
- temp = AfxMessageBox("Sort order for index differs from table!", MB_OK,0);
- break;
-
- case 14:
- temp = AfxMessageBox("Single user but directory is shared!", MB_OK,0);
- break;
-
- case 15:
- temp = AfxMessageBox("Multiple PARADOX.NET files!", MB_OK,0);
- break;
-
- case 21:
- temp = AfxMessageBox("Insufficient password rights!", MB_OK,0);
- break;
-
- case 22:
- temp = AfxMessageBox("Table is write protected!", MB_OK,0);
- break;
-
- case 30:
- temp = AfxMessageBox("Data type mismatch!", MB_OK,0);
- break;
-
- case 31:
- temp = AfxMessageBox("Argument is out of range!", MB_OK,0);
- break;
-
- case 33:
- temp = AfxMessageBox("Invalid argument!", MB_OK,0);
- break;
-
- case 40:
- temp = AfxMessageBox("Not enough memory to complete operation!", MB_OK,0);
- break;
-
- case 41:
- temp = AfxMessageBox("Not enough disk space to complete operation!", MB_OK,0);
- break;
-
- case 50:
- temp = AfxMessageBox("Another user deleted record!", MB_OK,0);
- break;
-
- case 70:
- temp = AfxMessageBox("No more file handles!", MB_OK,0);
- break;
-
- case 72:
- temp = AfxMessageBox("No more table handles!", MB_OK,0);
- break;
-
- case 73:
- temp = AfxMessageBox("Invalid date!", MB_OK,0);
- break;
-
- case 74:
- temp = AfxMessageBox("Invalid field name!", MB_OK,0);
- break;
-
- case 78:
- temp = AfxMessageBox("Engine not initialized!", MB_OK,0);
- break;
-
- case 97:
- temp = AfxMessageBox("Key violation!", MB_OK,0);
- break;
-
- case 98:
- temp = AfxMessageBox("Could not login on network!", MB_OK,0);
- break;
-
- case 99:
- temp = AfxMessageBox("Invalid table name!", MB_OK,0);
- break;
-
- case 101:
- temp = AfxMessageBox("End of table!", MB_OK,0);
- break;
-
- case 102:
- temp = AfxMessageBox("Start of table!", MB_OK,0);
- break;
-
- case 103:
- temp = AfxMessageBox("No more record handles available!", MB_OK,0);
- break;
-
- case 105:
- temp = AfxMessageBox("Operation on empty table!", MB_OK,0);
- break;
-
- case 120:
- temp = AfxMessageBox("Table not found!", MB_OK,0);
- break;
-
- case 134:
- temp = AfxMessageBox("Can't lock PARADOX.NET - is SHARE.EXE loaded?", MB_OK,0);
- break;
-
- case 126:
- temp = AfxMessageBox("General hardware error!", MB_OK,0);
- break;
-
- default:
- temp = AfxMessageBox("Unknown error!", MB_OK,0);
- }
-
-
- }