Invoice.c
This code is executed when the Client exits Shopping Mall.
Source code of Invoice.c
#include <stdio.h>
#include <cgic.h>
#include <windows.h>
#include <string.h>
#include <sql.h>
#include <sqlext.h>
#include <dos.h>
#include <ctype.h>
// POINTER DECLARATIONS FOR ODBC CONNECTION
void *henv;
void *hdbc;
void *hstmt;
char a[100];char aa[100];char bb[100];int ii;
int result;
char a1[30];char b[30];
char c[30];char d[30];
char e[30];char f[30];char a2[30];
// BUFFER DECLARATIONS FOR FUNC LIST
char IDN1[6]; // for cookies
char *cook; // for cookies
char IDN[5];
char PROD_ID[10];
char PROD_DESC[10];
char QTY[10];
char COST_ITEM[5];
char TOT_COST[8];
char Cost[10];
long n,TEMP=0;
SDWORD cba,cbb,cbc,cbd,cbe,cbf,cba2; // Last parameter of
SqlGetData
int cgiMain()
{
cgiHeaderContentType("text/html");
fprintf(cgiOut,"<HTML><HEAD>\n");
fprintf(cgiOut,"<TITLE>INVOICE</TITLE></HEAD>");
cook=getenv("HTTP_COOKIE");
sprintf(IDN1,"%s",cook);
// odbc code starts
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,"PRODS",-3,0,0,0,0);
SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"SELECT * FROM S WHERE
IDNO='%s'",&IDN1);
SQLExecDirect(hstmt,aa, -3);
result=SQLFetch(hstmt);
while (result != SQL_NO_DATA_FOUND)
{
SQLGetData(hstmt, 1,SQL_C_CHAR,a1,sizeof(a1),&cba);
SQLGetData(hstmt, 2,SQL_C_CHAR,b,sizeof(b),&cbb);
fprintf(cgiOut, "<B>Product ID :</B> %s
<br> ", b);
SQLGetData(hstmt, 3,SQL_C_CHAR,c,sizeof(c),&cbc);
fprintf(cgiOut, "<B>Product Description:</B> %s
<br> ", c);
SQLGetData(hstmt, 4,SQL_C_CHAR,d,sizeof(d),&cbd);
fprintf(cgiOut, "<B>Quantity:</B> %s <br>
", d);
SQLGetData(hstmt, 5,SQL_C_CHAR,e,sizeof(e),&cbe);
fprintf(cgiOut, "<B>Cost per Item :</B> %s
<br>", e);
SQLGetData(hstmt, 6,SQL_C_CHAR,f,sizeof(f),&cbf);
fprintf(cgiOut, "<B>Total Cost:</B> Rs
%s<BR><BR>", f);
n=atol(f);
TEMP=TEMP+n;
ltoa(TEMP,Cost,10);
ii=1;
result=SQLFetch(hstmt);
}
if(ii==1)
{
fprintf(cgiOut, "\n<B>FINAL COST =Rs %s
</B><br><br>\n", Cost);
}
SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 4
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
// odbc code 2 //
SQLAllocEnv(&henv);
SQLAllocConnect(henv,&hdbc);
SQLConnect(hdbc,"RAVI",-3,0,0,0,0);
SQLAllocStmt(hdbc,&hstmt);
sprintf(aa,"SELECT NAME FROM R WHERE
IDNO='%s'",&IDN1);
zzz(aa);
result=SQLExecDirect(hstmt,aa, -3);
sprintf(aa,"Exec Dc=%d",result);
zzz(aa);
result=SQLFetch(hstmt);
sprintf(aa,"Fetch=%d",result);
zzz(aa);
while (result != SQL_NO_DATA_FOUND)
{
SQLGetData(hstmt, 1,SQL_C_CHAR,a1,sizeof(a1),&cba);
SQLGetData(hstmt, 2,SQL_C_CHAR,b,sizeof(a2),&cba2);
SQLGetData(hstmt, 3,SQL_C_CHAR,c,sizeof(c),&cbc);
SQLGetData(hstmt, 4,SQL_C_CHAR,d,sizeof(d),&cbd);
SQLGetData(hstmt, 5,SQL_C_CHAR,e,sizeof(e),&cbe);
SQLGetData(hstmt, 6,SQL_C_CHAR,f,sizeof(f),&cbf);
result=SQLFetch(hstmt);
}
SQLFreeStmt(hstmt,SQL_DROP); // SQLFreeStmt 4
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
fprintf(cgiOut, "<H2><b><font
color='Purple'>Thank
you,<i><u>%s</u></i> for shopping with
us</FONT><b></H2><br>",a1);
fprintf(cgiOut, "<H3>Your current shopping session is
over<H3><br>");
fprintf(cgiOut, "<H3>We hope to serve you better next
time<H3><br><br><br>");
fprintf(cgiOut, "Thank You<br><br>");
fprintf(cgiOut, "<B>Ravi
Jagasia</B><br>");
fprintf(cgiOut, "<B>Prasen
Karlekar</B><br>");
fprintf(cgiOut, "<B>Sachin
Gavankar</B><br>");
fprintf(cgiOut, "</BODY></HTML>\n");
return 0;
}// END OF MAIN
PROGRAM EXPLANATION :Firstly, you have to add cgic.c and cgic.h to your project workspace in Visual C++. These files have been provided in the downloaded files link .
This program execution is similar to that of Recall.c except that here the user is not provided the facility to modify his Shopping Cart.For detailed explanation ,refer recall.c program .
Recall.c :