Online Gas booking System in C++ | How to create project in Visual C++ OOAD

The aim of our project is to develop software for implementing “Online gas booking” using VISUAL C++. This project deals with the booking details, billing and maintenance in its process. The customers are instructed in an easy way to feel comfortable with the processing. In this C++ Source code we are inserting data into the database using sql language. Customer data has been remove from the database using delete query.
Source Code in C++ Programming Online Gas Booking System
#include<windows.h>
#include<sqlext.h>
#include<stdio.h>
#include<string.h>
#define TEST_LEN 50
int main()
{
int c;
char ch='y';
SQLINTEGER CustomerID,Phoneno;
SQLCHAR Customername[TEST_LEN+1],Agencyname[TEST_LEN+1],Address[TEST_LEN+1],Billingadd[TEST_LEN+1],Bookingdate[TEST_LEN+1];
HENV hEnv=NULL;
HDBC hDBC=NULL;
HSTMT hStmt=NULL;
UCHAR szSqlStr[]="insert into gas(CustomerID,Customername,Agencyname,Address,Phoneno,Billingadd,Bookingdate) values(?,?,?,?,?,?,?)";
UCHAR szSqlStr1[]="delete * from gas where CustomerID = ?";
UCHAR szSqlStr2[]="select * from gas";
UCHAR szDSN[SQL_MAX_DSN_LENGTH]="gasbook";
UCHAR *szUID=NULL;
UCHAR *szPasswd=NULL;
UCHAR szModel1[128];
UCHAR szModel2[128];
UCHAR szModel3[128];
UCHAR szModel4[128];
UCHAR szModel5[128];
UCHAR szModel6[128];
UCHAR szModel7[128];
SDWORD cbModel1;
SDWORD cbModel2;
SDWORD cbModel3;
SDWORD cbModel4;
SDWORD cbModel5;
SDWORD cbModel6;
SDWORD cbModel7;
SDWORD cbtest=SQL_NTS;
RETCODE retcode;
do
{
printf("=======================================\n ONLINE GAS BOOKING SYSTEM\n=======================================\n");
printf("1.Enter the customer detail \n2.Delete the customer detail\n3.Display the customer detail\n\n");
printf("Enter ur option......\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\n-----------------------------------------");
printf("\nEnter the details");
printf("\n-----------------------------------------");
printf("\nEnter the Customer ID:\t");
scanf("%d",&CustomerID);
printf("\nEnter the Customername:\t");
scanf("%s",&Customername);
printf("\nEnter the Agency name:\t");
scanf("%s",&Agencyname);
printf("\nEnter the Address:\t");
scanf("%s",&Address);
printf("\nEnter the Phoneno:\t");
scanf("%d",&Phoneno);
printf("\nEnter Billingadd:\t");
scanf("%s",&Billingadd);
printf("\nEnter Billing date:\t");
scanf("%s",&Bookingdate);
printf("\n-----------------------------------------");
SQLAllocEnv(&hEnv);
SQLAllocConnect(hEnv,&hDBC);
retcode=SQLConnect(hDBC,szDSN,SQL_NTS,szUID,SQL_NTS,szPasswd,SQL_NTS);
if(retcode==SQL_SUCCESS||retcode==SQL_SUCCESS_WITH_INFO)
{
retcode=SQLAllocStmt(hDBC,&hStmt);
retcode=SQLPrepare(hStmt,szSqlStr,sizeof(szSqlStr));
SQLBindParameter(hStmt,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,1,0,&CustomerID,0,&CustomerID);
SQLBindParameter(hStmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,TEST_LEN,0,Customername,0,&cbtest);
SQLBindParameter(hStmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,TEST_LEN,0,Agencyname,0,&cbtest);
SQLBindParameter(hStmt,4,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,TEST_LEN,0,Address,0,&cbtest);
SQLBindParameter(hStmt,5,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,1,0,&Phoneno,0,&Phoneno);
SQLBindParameter(hStmt,6,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,TEST_LEN,0,Billingadd,0,&cbtest);
SQLBindParameter(hStmt,7,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,TEST_LEN,0,Bookingdate,0,&cbtest);
retcode=SQLExecute(hStmt);
printf("\n\n Detail is inserted.......... \n\n");
}
break;
case 2:
printf("\nDelete the detail\n");
SQLAllocEnv(&hEnv);
SQLAllocConnect(hEnv,&hDBC);
retcode=SQLConnect(hDBC,szDSN,SQL_NTS,szUID,
SQL_NTS,szPasswd,SQL_NTS);
if(retcode==SQL_SUCCESS||retcode==SQL_SUCCESS_WITH_INFO)
{
retcode=SQLAllocStmt(hDBC,&hStmt);
retcode=SQLPrepare(hStmt,szSqlStr1,sizeof(szSqlStr1));
SQLBindParameter(hStmt,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,1,0,&CustomerID,0,&CustomerID);
printf("\nEnter the Customer ID\n");
scanf("%d",&CustomerID);
retcode=SQLExecute(hStmt);
printf("detail has been deleted\n\n");
}
break;
case 3:
printf("\nDisplay the detail\n");
SQLAllocEnv(&hEnv);
SQLAllocConnect(hEnv,&hDBC);
retcode=SQLConnect(hDBC,szDSN,SQL_NTS,szUID,SQL_NTS,szPasswd,SQL_NTS);
if(retcode==SQL_SUCCESS||retcode==SQL_SUCCESS_WITH_INFO)
{
retcode=SQLAllocStmt(hDBC,&hStmt);
retcode=SQLPrepare(hStmt,szSqlStr2,sizeof(szSqlStr2));
retcode=SQLExecute(hStmt);
SQLBindCol(hStmt,1,SQL_C_CHAR,szModel1,sizeof(szModel1),&cbModel1);
SQLBindCol(hStmt,2,SQL_C_CHAR,szModel2,sizeof(szModel2),&cbModel2);
SQLBindCol(hStmt,3,SQL_C_CHAR,szModel3,sizeof(szModel3),&cbModel3);
SQLBindCol(hStmt,4,SQL_C_CHAR,szModel4,sizeof(szModel4),&cbModel4);
SQLBindCol(hStmt,5,SQL_C_CHAR,szModel5,sizeof(szModel5),&cbModel5);
SQLBindCol(hStmt,6,SQL_C_CHAR,szModel6,sizeof(szModel6),&cbModel6);
SQLBindCol(hStmt,7,SQL_C_CHAR,szModel7,sizeof(szModel7),&cbModel7);
retcode=SQLFetch(hStmt);
printf("\nCustomeID\tCustomername\tAgencyname\tAddress\tPhoneno\tBillingadd\tBookingdate\n\n");
while(retcode==SQL_SUCCESS||retcode==SQL_SUCCESS_WITH_INFO)

{
printf("%s\t\t%s\t\t%s\t\t%s\t%s %s\t%s\n",szModel1,szModel2,szModel3,szModel4,szModel5,szModel6,szModel7);
retcode=SQLFetch(hStmt);
}
}

break;

}
flushall();
printf("\nDo u wan to cont (y/n)");
scanf("%s",&ch);
}
while(ch=='y');
return 0;
}
Output of Online Gas booking system in Object Oriented Analysis Design
Enter the customer details in Online Gas booking system
How to display the customer details from the database

How to delete record from the database in C++

Related post