Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf250 Project 1 DATABASE PROGRAMMING USING VC++.NET
}
m_pGet->MoveNext();
}
}
if(ptr->m_Transaction_Type==”DEP”)
{ |
|
|
|
|
|
if(!m_pGet->IsOpen ()) |
|||
|
|
|
|
Y |
|
m_pGet->Open(); |
|||
|
|
|
L |
|
|
if(!m_pGet->IsBOF() && m pGet->IsEOF()) |
|||
|
|
|
F |
|
|
|
|
m pGet->MoveFirst(); |
|
|
long lAccountNum = ptr->m_Account_Number; |
|||
|
|
M |
|
|
|
while(!m pGet->IsEOF()) |
|||
|
{ |
|
|
|
E |
if( m pGet->m_Account_Number == lAccountNum ) |
|||
{ |
|
|||
T |
|
|
|
|
|
|
m_pGet->Edit(); |
||
Am_pGet->m_Balance=m_pGet->m_Balance+ptr- |
>m_Transaction_Amount; if(!m_pGet->Update())
{
AfxMessageBox(“Unable to update Balance”); return;
}
m_pGet->Requery();
AfxMessageBox(“Balance has been Updated”); ptr->m_Transaction_Status=”C”;
break;
}
m_pGet->MoveNext();
}
}
}
if(pCheck->GetCheck()==BST_CHECKED)
{
ptr->m_Transaction_Mode=”CHQ”; ptr-
>m_Transaction_Amount=GetDlgItemInt(IDC_AMTDEPW,NULL,true); ptr-
Team-Fly®
IMPLEMENTING DATA ACCESS TECHNOLOGIES |
Chapter 8 |
251 |
|
|
|
>m_Check_Draft_Number=GetDlgItemInt(IDC_CHECKNO,NULL,true); ptr->m_Transaction_Status=”P”; if(ptr->m_Transaction_Type==”WTH”)
{
if(!m_pGet->IsOpen ()) m_pGet->Open();
if(!m_pGet->IsBOF() && m_pGet->IsEOF()) m_pGet->MoveFirst();
while(!m_pGet->IsEOF())
{
if(m_pGet->m_Account_Number==ptr-
>m_Account_Number)
{
double WAmt=m_pGet->m_Balance-ptr- >m_Transaction_Amount;
if(WAmt<500)
{
AfxMessageBox(“Insufficient Balance Amount -
Should
Deposit Money”); return;
}
else
{
ptr->m_Transaction_Status=”P”; break;
}
}
m_pGet->MoveNext();
}
}
if(ptr->m_Transaction_Type==”DEP”) ptr->m_Transaction_Status=”P”;
}
GetDlgItemText(IDC_TRANDT,ptr->m_Transaction_Date);
if(!ptr->Update())
AfxMessageBox(“Unable to Save....”);
252 Project 1 DATABASE PROGRAMMING USING VC++.NET
if(ptr->Requery()==0)
return;
CDialog::OnOK();
}
When the transaction mode is Cash, the database is immediately updated, whereas if the transaction mode is Check, the transaction is marked “p” to indicate that it is a pending transaction. You will learn how to commit these transactions later.
Coding the Transfer Form
Again, when the user clicks on Transfer, the Click event has to be trapped. The name of the event handler is OnTransfer. Following is the code for the same:
void CBankOperationView::OnTransfer()
{
CTransfer d2; d2.DoModal();
//This function invokes the OnInitDialog method of the CTransfer class
}
The control is then passed on to the OnInitDialog function of the CTransfer class:
BOOL CTransfer::OnInitDialog()
//Performs the same operations as the OnInitDialog of CDeposit class.
{
CComboBox *cmb; cmb=(CComboBox*)GetDlgItem(IDC_FRMACCNO);
CTime t1=CTime::GetCurrentTime(); int dd=t1.GetDay();
int mm=t1.GetMonth(); int yy=t1.GetYear(); char str[30];
sprintf(str,”%2d/%2d/%2d”,dd,mm,yy); SetDlgItemText(IDC_CCDT,str);
IMPLEMENTING DATA ACCESS TECHNOLOGIES |
Chapter 8 |
253 |
|
|
|
if(cmb->GetCount()>0) cmb->Clear();
Ref_AccNo *m_pGet=new Ref_AccNo; if(!m_pGet->IsOpen ())
m_pGet->Open(); if(!m_pGet->IsBOF() && m_pGet->IsEOF())
m_pGet->MoveFirst(); char str1[30]; while(!m_pGet->IsEOF())
{
if(m_pGet->m_Valid_Acc.CompareNoCase(“VA”) == 0)
{
sprintf(str1,”%d”,m_pGet->m_Account_Number); cmb->AddString(str1);
}
m_pGet->MoveNext();
}
GetDlgItem(IDC_FRMACCNO)->SetFocus(); return FALSE;
}
When the Transfer Operations form appears on screen, it has the operational accounts listed in the From Account Number combo box. The user should first select the account number and then specify whether the type of transfer is external or internal. To do so, the user will select the appropriate radio button options. Here’s the code to handle the click of these buttons:
void CTransfer::OnInternal()
{
//The controls are disabled and enabled based on the values that are to be //accepted from the user for an Internal transfer.
((CEdit*)GetDlgItem(IDC_TACCNO))->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CNAME))->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CAMT))->EnableWindow(true);
254 Project 1 DATABASE PROGRAMMING USING VC++.NET
((CEdit*)GetDlgItem(IDC_CBANKNAME))->EnableWindow(false); ((CEdit*)GetDlgItem(IDC_CBANKADDR))->EnableWindow(false);
}
void CTransfer::OnExternal()
{
//The controls are disabled and enabled based on the values that are to be //accepted from the user for an External transfer.
((CEdit*)GetDlgItem(IDC_TACCNO))->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CNAME))->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CAMT))->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CBANKNAME))->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CBANKADDR))->EnableWindow(true);
}
After entering the details, the user will click on the Save button. The event handler corresponding to this is as follows:
void CTransfer::OnCsave()
{
//The Account number specified is validated using the VerifyAccountNumber method. //I have given the code for this after this function.
if (!VerifyAccountNumber()) return;
//Check for the available balance; Again this is a separate function that I have //explained later.
CheckForBalance();
Tran_DW *ptr1; ptr1=new Tran_DW; if(!ptr1->IsOpen ())
ptr1->Open(); if(!ptr1->IsBOF() && ptr1->IsEOF())
ptr1->MoveLast(); ptr1->AddNew();
CButton *pExternal, *pInternal;
IMPLEMENTING DATA ACCESS TECHNOLOGIES |
Chapter 8 |
255 |
|
|
|
pExternal=(CButton*)GetDlgItem(IDC_External); pInternal=(CButton*)GetDlgItem(IDC_INTERNAL);
ptr1->m_Account_Number=GetDlgItemInt(IDC_FRMACCNO, NULL, true); ptr1->m_To_Account=GetDlgItemInt(IDC_TACCNO,NULL,true); GetDlgItemText(IDC_CNAME,ptr1->m_Creditor_Name); ptr1->m_Transaction_Amount=GetDlgItemInt(IDC_CAMT,NULL,true); GetDlgItemText(IDC_CCDT,ptr1->m_Transaction_Date); ptr1->m_Transaction_Status=”P”;
ptr1->m_Transaction_Mode=”TRF”; if(pExternal->GetCheck()==BST_CHECKED)
{
GetDlgItemText(IDC_CBANKNAME,ptr1->m_Creditor_BankName); GetDlgItemText(IDC_CBANKADDR,ptr1->m_Creditor_BankAddr); ptr1->m_Transaction_Type=”ETF”;
}
if(pExternal->GetCheck()==BST_CHECKED) ptr1->m_Transaction_Type=”ETF”; if(pInternal->GetCheck()==BST_CHECKED) ptr1->m_Transaction_Type=”ITF”;
if(!ptr1->Update())
AfxMessageBox(“Unable to Save....”);
AfxMessageBox(“Transaction is successful”); if(ptr1->Requery()==0)
return;
CDialog::OnOK();
}
The VerifyAccountNumber Function
BOOL CTransfer::VerifyAccountNumber()
{
Ref_AccNo *m_ptr1;
m_ptr1=new Ref_AccNo;
256 Project 1 DATABASE PROGRAMMING USING VC++.NET
if(!m_ptr1->IsOpen ()) m_ptr1->Open();
if(m_ptr1->IsBOF() && m_ptr1->IsEOF ()) AfxMessageBox(“No Records in the Database...”);
m_ptr1->MoveFirst();
bool flag=false;
long acc=GetDlgItemInt(IDC_TACCNO,NULL,true);
CButton* pRadioExternal = (CButton*) GetDlgItem(IDC_External); if (pRadioExternal->GetState() & 0x0003)
{
// We won’t check the validity of external checks
return TRUE;
}
while(!m_ptr1->IsEOF())
{
if(acc==m_ptr1->m_Account_Number)
{
if(m_ptr1->m_Valid_Acc==”CA”)
{
AfxMessageBox(“UnOperational Account - Check Account Number”);
flag=false;
((CEdit*)GetDlgItem(IDC_TACCNO))->SetFocus(); return flag;
}
flag=true;
break;
}
m_ptr1->MoveNext();
}
if(m_ptr1->IsEOF() && flag==false)
{
AfxMessageBox(“Invalid Account Number. Please enter again”); ((CEdit*)GetDlgItem(IDC_TACCNO))->SetFocus();
}
return flag;
}
IMPLEMENTING DATA ACCESS TECHNOLOGIES |
Chapter 8 |
257 |
|
|
|
The CheckForBalance Method
Before performing any transaction, you need to find the balance of the account number involved in the transaction. To do so, you will use the CheckForBalance method and the following is the code for the same:
void CTransfer::CheckForBalance()
{
Ref_AccNo *m_ptr1; m_ptr1=new Ref_AccNo; if(!m_ptr1->IsOpen ())
m_ptr1->Open(); if(!m_ptr1->IsBOF() && m_ptr1->IsEOF())
m_ptr1->MoveFirst();
long tamt=GetDlgItemInt(IDC_CAMT,NULL,true); long acc=GetDlgItemInt(IDC_TACCNO,NULL,true); while(!m_ptr1->IsEOF())
{
if(m_ptr1->m_Account_Number==acc) break;
m_ptr1->MoveNext();
}
m_ptr1->MoveFirst(); acc=GetDlgItemInt(IDC_FRMACCNO,NULL,true); while(!m_ptr1->IsEOF())
{
if(m_ptr1->m_Account_Number==acc)
{
double WAmt=m_ptr1->m_Balance-tamt; if(WAmt<500)
{
AfxMessageBox(“You do not have Sufficient Balance in your
Account”);
((CEdit*)GetDlgItem(IDC_CAMT))->SetFocus(); return;
}
else
break;
258 Project 1 DATABASE PROGRAMMING USING VC++.NET
}
m_ptr1->MoveNext();
}
}
The Commit Button
All pending transactions can be updated using the Commit button. The code for implementing this functionality is as follows:
void CBankOperationView::OnBnClickedCommit()
{
//This will commit Pending “Transfer” operations
Tran_DW *ptr_Tran=new Tran_DW; //Contains Transaction Details
Ref_AccNo *m_pGet=new Ref_AccNo; //Contains Customer Details
if(!ptr_Tran->IsOpen()) ptr_Tran->Open();
if(!ptr_Tran->IsBOF() && ptr_Tran->IsEOF ()) ptr_Tran->MoveFirst();
if(!m_pGet->IsOpen()) m_pGet->Open();
if(!m_pGet->IsBOF() && m_pGet->IsEOF ()) m_pGet->MoveFirst();
BOOL bFirstTransactionOver = FALSE;
//Go through all the transactions in transaction recordset while (!ptr_Tran->IsEOF())
{
//Choose pending records from the recordset
if (ptr_Tran->m_Transaction_Status.CompareNoCase(“P”) == 0)
{
//Case of Cheque transactions in Deposit/Withdrawl
if (ptr_Tran->m_Transaction_Mode.CompareNoCase(“CHQ”) == 0)
{
// Deposit Case
if (ptr_Tran->m_Transaction_Type.CompareNoCase(“DEP”) == 0)
{
IMPLEMENTING DATA ACCESS TECHNOLOGIES |
Chapter 8 |
259 |
|
|
|
while (!m_pGet->IsEOF())
{
if (m_pGet->m_Account_Number == ptr_Tran->m_Account_Number)
{
m_pGet->Edit();
m_pGet->m_Balance=m_pGet->m_Balance + ptr_Tran->m_Transaction_Amount; m_pGet->Update();
m_pGet->Requery(); ptr_Tran->Edit();
ptr_Tran->m_Transaction_Status = “C”; ptr_Tran->Update(); ptr_Tran->Requery();
break;
}
m_pGet->MoveNext();
}
m_pGet->MoveFirst();
}
else if (ptr_Tran->m_Transaction_Type.CompareNoCase(“WTH”) == 0)
// Withdrawal Case
{
while (!m_pGet->IsEOF())
{
if (m_pGet->m_Account_Number == ptr_Tran->m_Account_Number)
{
m_pGet->Edit(); m_pGet->m_Balance=m_pGet->m_Balance - ptr_Tran- >m_Transaction_Amount;
m_pGet->Update(); m_pGet->Requery(); ptr_Tran->Edit();
ptr_Tran->m_Transaction_Status = “C”; ptr_Tran->Update(); ptr_Tran->Requery();
break;
}
m_pGet->MoveNext();
}