#include#include #include #include #include void sql_execute (char query[100] , char userid[10], char password[15] ); void show_table(char userid[10],char password[15]); void insert_table(char userid[10],char password[15]); void report(char userid[10],char password[15]); int main() { char menu ; char userid[10], password[15]; system("clear"); cout< "; cin>> userid ; cout<<" password==> " ; cin>>password; while(1 ) { system("clear"); cout<<" |*********************************** | "< "; gets(&menu ); if(menu=='0') break; else if(menu=='1') { show_table(userid,password); } else if(menu=='2') { insert_table(userid,password); } else if(menu=='3') { report(userid,password); } else { system("clear"); cout<<"Sorry,invalid choice !" < "; gets(&table_index); if(table_index=='R') break; else if(table_index =='A') { sprintf(command, "MB.show_employees"); sql_execute(command ,userid,password); } else if(table_index =='B') { sprintf(command, "MB.show_suppliers"); sql_execute(command ,userid,password); } else if(table_index =='C') { sprintf(command, "MB.show_products"); sql_execute(command ,userid,password); } else if(table_index =='D') { sprintf(command, "MB.show_customers"); sql_execute(command ,userid,password); } else if(table_index =='E') { sprintf(command, "MB.show_transactions"); sql_execute(command ,userid,password); } else if(table_index =='F') { sprintf(command, "MB.show_log1"); sql_execute(command ,userid,password); } else { system("clear"); cout<<"sorry,invalid choice !" < "; gets(&table_index); if(table_index=='R') break; } } void insert_table(char userid[10],char password[15]) { char table_index; char command[100]; char tele[20]; char ename[10],salary[20]; char address[20], date[10]; char sname[10], city[15]; char pname[10],qty[20],pprice[15],sprice[15],desp[20]; char cname[10]; char cid[20],pid[20],eid[20],tprice[10]; while(1) { system("clear"); cout<<" |*******************************************| "< "; gets(&table_index) ; if(table_index=='R') break; else if(table_index =='A') { system("clear"); cout<<" Please input employee's information " < " ; gets(ename); cout<<"address( varchar2(15) )-->"; gets(address); cout<<"telephone number( char(10) )-->" ; gets(tele); cout<<"salary ( number(8,2) )-->" ; gets(salary) ; if(strlen(salary)==0) strcpy(salary,"NULL"); cout<<"start_date( DD-MM-YY)-->" ; gets(date); sprintf(command, "MB.add_employees('%s','%s','%s',%s,'%s')",ename,address,tele,salary,date); sql_execute(command ,userid,password); } else if(table_index =='B') { system("clear"); cout<<" Please input supplier's information " < " ; gets(sname); cout<<"city( varchar2(15) )-->"; gets(city); cout<<"telephone number( char(12) )-->" ; gets(tele); sprintf(command, "MB.add_suppliers('%s','%s','%s')",sname,city,tele); sql_execute(command ,userid,password); } else if(table_index =='C') { system("clear"); cout<<" Please input product's information " < " ; gets(pname); cout<<"quantity on hand-->"; gets(qty); cout<<"purchase price( number(6,2) )-->" ; gets(pprice); cout<<"sale price ( number(6,2) )-->" ; gets(sprice) ; cout<<"supplier name(varchar2(15))-->" ; gets(sname); cout<<" Description -->" ; gets(desp); sprintf(command, "MB.add_products('%s',%s,%s,%s,'%s','%s')",pname,qty,pprice,sprice,sname,desp); sql_execute(command ,userid,password); } else if(table_index =='D') { system("clear"); cout<<" Please input customer's information " < " ; gets(cname); cout<<"address (varchar2(15))->"; gets(address); cout<<"telephone number(char(12))-->" ; gets(tele); sprintf(command, "MB.add_customers('%s','%s','%s')",cname,address,tele); sql_execute(command ,userid,password); } else if(table_index =='E') { system("clear"); cout<<" Please input transaction information " < " ; gets(cid); cout<<"product id-->"; gets(pid); cout<<"employee id-->" ; gets(eid); cout<<"quantity purchased-->" ; gets(qty) ; cout<<"purchase date-->"; gets(date); sprintf(command,"MB.add_transactions(%s,%s,%s,%s,'%s')",cid,pid,eid,qty,date); sql_execute(command ,userid,password); } else { system("clear"); cout<<"Sorry,invalid choice !" < "; gets(&table_index); if(table_index=='R') break; } } void report(char userid[10],char password[15]) { char table_index; char command[100]; char customerid[20]; char productid[20]; while(1) { system("clear"); cout<<" |*******************************************| "< "; gets(&table_index); if(table_index=='R') break; else if(table_index =='A') { cout<<"Please input customer's id ==> "; gets(customerid); sprintf(command, "MB.report_purchase(%s)", customerid); sql_execute(command ,userid,password); } else if(table_index =='B') { sprintf(command, "MB.report_stats"); sql_execute(command,userid,password ); } else if(table_index =='C') { cout<< "Please input product's id ==> "; gets(productid); sprintf(command, "MB.report_stats(%s)",productid); sql_execute(command ,userid,password); } else if(table_index =='D') { sprintf(command, "MB.report_profit"); sql_execute(command,userid,password ); } else { system("clear"); cout<<"Sorry,invalid choice !" < " ; gets(&table_index); if(table_index=='R') break; } } void sql_execute (char query[100] , char userid[10], char password[15] ) { FILE *Qfile; char command1[100]; char idpassword[30] ; Qfile=fopen("query.sql","w"); fprintf(Qfile,"%s\n","set serveroutput on; "); sprintf(command1,"execute %s;",query); fprintf(Qfile,"%s\n", command1); fclose(Qfile); sprintf(idpassword, "sqlplus -s %s/%s < query.sql " , userid,password); system("clear"); system(idpassword ); }
Text file Source (historic): geocities.com/wenxiazheng
(to report bad content: archivehelp @ gmail)
|
|
|
|
|