Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Date: 12/21/15
- Hi Kristen Stewart,
- This was a project I did in 1998 when I was studying in NIIT Computer Training.
- So the rights of this source code is mine.
- May be you want to teach your kids something similar yourself.
- We cannot allow other nationals to take our US's well-paying, decent full time jobs depriving
- means of livelihood for American workers first.
- Employers should be hiring AMerican workers first and priority is American workers.
- Don't let your kids lose out in this mad race.
- If any doubt revert to me with questions I think your kids if you have any are already smart enough to figure out computer code with the help of the Internet by themselves.
- Personally, Take it as a token of affection for ya, regardless of who you are what do you do.
- ok
- The following code is for a fictional video lending store. The platform is UNIX and the programming language is C++ and the database used is Sybase. Even if it were any other database or any other programming language the code is going to be something similar. Any questions revert to me I am glad to teach if I have free time at the moment, no obligations on your part ok? I am doing this because I don't want other nationals stealing our IT jobs meant for employing American workers first. What will your kids work on when they grow up in this competitive world? Scares me as it should scare you too. Again, revert to me for any clarifications
- Sybase Table Creation Script
- /* tables.vi */
- /* Sybase SQL Server System 10 */ use f4 go
- set nocount on go
- /* drop dependent tables first */
- if exists(select name from sysobjects where name='invoices') drop table invoices go
- if exists(select name from sysobjects where name='customers') drop table customers go
- if exists(select name from sysobjects where name='movies') drop table movies go
- create table customers
- (
- cust_id int constraint pk primary key, first_name char(30), last_name char(30) null, phone char(20) null,
- address char(50) null, deposit smallmoney default 300,
- doj smalldatetime default getdate()) go
- create table movies
- (
- movie_id int constraint pk primary key, movie_title char(40), movie_cast char(45), copies smallint default 3,
- theme char(15) constraint t check (theme in ("Action","Comedy","Drama","Fiction","Documentary",
- "Horror","Musical","ScienceFiction","Sports","Suspense","Porn","Romance")), movie_rating char(2) default "G" constraint m check
- (movie_rating in ("PG","12","18","G"))
- )
- go
- create table invoices
- (
- inv_id constraint pk primary key, inv_date smalldatetime default getdate(), cust_id int, movie_id int,
- date_due smalldatetime default dateadd(dd,3,getdate()), date_returned smalldatetime null, amount smallmoney default 50,
- fine smallmoney default 0
- )
- go
- if exists(select name from sysobjects where type='P' and name='inscust') drop proc inscust
- go
- create proc inscust(@custid int, @fname char(30), @lname char(30), @ph char(20), @addr char(30)) as
- /* check whether the customer exists */
- if (select count(*) from customers where cust_id=@custid) > 0 begin return 1000 end
- insert customers values(@custid,@fname,@lname,@ph,@addr,300,getdate()) return go
- if exists(select name from sysobjects where type='P' and name='insmovie') drop proc insmovie go
- create proc insmovie(@mid int, @mtitle char(40), @mcast char(40), @copies int,
- @theme char(20), @mrating char(2)) as
- /* check whether the movie already exists */ if (select count(*) from movies where movie_id=@mid) > 0 begin return 1001 end
- insert movies values(@mid,@mtitle,@mcast,@copies,@theme,@mrating) return go
- if exists(select name from sysobjects where type='P' and name='addtrans')
- drop proc addtrans
- go
- create proc addtrans(@invid int, @custid int, @mid int) as
- /* check whether the customer exists */ if (select count(*) from customers where cust_id=@custid)=0 begin return 1002
- end
- /* check whether the movie exists */ if (select count(*) from movies where movie_id=@mid)=0) begin return 1003
- end
- /* check that the invoice id does not already exist */ if (select count(*) from invoices where inv_id=@invid) > 0 begin return 1004
- end
- /* check whether the movie is available */
- if (select copies from movies where movie_id=@mid)=0 begin return 1005
- end
- insert invoices(inv_id,cust_id,movie_id,amount) values(@invid,@custid,@mid,50) return go
- if exists(select name from sysobjects where name='cust_del') drop trigger cust_del go
- create trigger cust_del on customers
- for delete as
- if (select count(*) from invoices,deleted where invoices.cust_id=deleted.cust_id)>0
- begin
- delete invoices from invoices,deleted
- where invoices.cust_id=deleted.cust_id end
- return go
- if exists(select name from sysobjects where name='movie_del') drop trigger movie_del go
- create trigger movie_del
- on movies for delete as
- if (select count(*) from invoices,deleted where invoices.movie_id=deleted.movie_id) > 0
- begin
- delete invoices from invoices,deleted where invoices.movie_id=deleted.movie_id end
- return go
- if exists(select name from sysobjects where name='inv_ins') drop trigger inv_ins go
- create trigger inv_ins on invoices
- for insert
- as update movies set copies=copies-1 from inserted
- where movies.movie_id=inserted.movie_id return go
- if exists(select name from sysobjects where name ='inv_upd')
- drop trigger inv_upd
- go
- create trigger inv_upd on invoices
- for update as
- if update(date_returned) begin update movies
- set copies=copies+1
- from inserted
- where movies.movie_id=inserted.movie_id end
- return go
- /****** INSERT TEST RECORDS *********/ truncate table customers
- go
- exec inscust 1, 'Mike', 'Kasem', '19340343','3b marine drive' go
- ...
- truncate table movies
- go
- exec insmovie 1, 'City Hall',
- 'Al Pacino, Jack Cusack, Bridget Fonda',3,'Action','PG' go
- ...
- truncate table invoices go
- exec addtrans 1,1,1 go
- ...
- /* Have disk(s) returned */
- update invoices set date_returned = getdate() where inv_id=1 go
- /* Overdue movies */
- update invoices set inv_date=dateadd(dd,-2,getdate()), date_due=dateadd(dd,-2,getdate()) where inv_id=8 go
- ...
- C Program Video Library Maintenance
- /***
- video.cc
- Compile with g++ 2.5.7
- g++ -l. -l$SYBASE/include $1.cc -L$SYBASE/lib -lsybdb -lcurses -lnsl -lm -o $1
- **/
- #define NIIT_CIT
- #include <fstream.h>
- #include <curses.h>
- #include <stdio.h>
- #include <string.h>
- #ifdef NIIT_CIT
- #include <sybcc.h>
- #endif
- #ifdef DROME
- #include <sybase.h>
- #endif
- #include <stdlib.h>
- #include <time.h>
- #include <sys/types.h>
- #include <signal.h> #include <unistd.h>
- char cMenu1[7][50] = { " Customer Details ",
- " Movie Details ",
- " Transactions ",
- " Reports ",
- " Lock Terminal ",
- " About ... / Credits ",
- " Exit (ESCAPE) "
- };
- char help1[7][50] =
- { " Add/Modify/Delete/View Customer(s) ",
- " Add/Modify/Delete/View Movie(s) ",
- " Rent/Return a LD/VCD ",
- " Various Reports ",
- " Lock the terminal with a password ",
- " View Credits of Video Library v. 2.0 ",
- " Exit from this program "
- };
- char cMenu2[5][50] = { " Add Customer(s) ",
- " Modify Customer(s) ",
- " Delete Customer(s) ",
- "View Customer(s) ",
- " Return to Main Menu (ESCAPE) "
- };
- char help2[5][50] = { " Add Customer(s) record(s) ",
- " Modify Customer(s) record(s) ",
- " Delete Customer(s) record(s) ",
- " Search for Customer(s) ",
- " Return to the Main Menu "
- };
- char cMenu3[7][50] = { " Add Movie(s) ",
- " Modify Movie(s) ",
- " Delete Movie(s) ",
- " Find Movie(s) by Name/Theme ",
- " List Movies in Circulation ",
- " Check Movie Availability ",
- " Return to Main Menu ",
- };
- char help3[7][50] = { " Add Movie(s) record(s) ",
- " Modify Movie(s) record(s) ", " Delete Movie(s) record(s) ",
- " Search for Movie(s) by Name/Theme ",
- " List all Movie(s) in Circulation ",
- " Check Movie Availability ",
- " Return to Main Menu "
- };
- char cMenu4[4][50] = { " Rent a LD/VCD ",
- " Return a LD/VCD ",
- " View Today's Transactions ",
- " Return to Main Menu (ESCAPE) "
- };
- char help4[4][50] = { "Rent a disk to a customer ",
- "Customer returns a disk ",
- " View today's transactions ",
- " Return to Main Menu "
- };
- char cMenu5[6][50] = { " Monthly Rental Transactions Report ",
- " Current Stock Report ",
- " Movies in Circulation ",
- " Daily Cash Summary ",
- " Movies that are overdue ",
- " Return to Main Menu (ESCAPE) "
- };
- char help5[6][50] = { "Shows monthly transaction summary ",
- " Shows current stock ",
- " List movie(s) in circulation ",
- " Daily Cash Summary ",
- " Shows movies that are overdue ",
- " Return to Main Menu "
- };
- int cho; inline void rtr() { refresh(); } char str[255];
- void spc(int no)
- {
- char tempstr[255]; strcpy(tempstr, " "); for(int i=2; i<= no; i++) strcat(tempstr," ");
- addstr(tempstr);
- }
- #ifdef NIIT_CIT
- inline void cr0() { attrset(A_BOLD); } inline void cr1() { attrset(0); }
- inline void cr2()
- { attrset(A_COLOR|A_DIM|A_UNDERLINE); }
- inline void cr3()
- { attrset(A_REVERSE); }
- inline void cr4()
- { attrset(A_COLOR&A_BOLD&A_BLINK); }
- #endif
- #ifdef DROME
- inline void cr0()
- { attrset(A_REVERSE); } inline void cr1() { attrset(0); } inline void cr2() { cr0(); } inline void cr3() { cr0(); } inline void cr4()
- { cr0(); } #endif
- inline void mvw(int a, int b, char *s) { mvprintw(a,b,s); }
- inline void mvwr(int a, int b, char *s)
- {
- mvw(a,b,s);
- rfr(); }
- inline void c()
- {
- wclear(stdscr);
- } void remov(int i, int k)
- {
- int x=10, y=0; char s[255], t[255];
- switch(i)
- {
- case 1: y=6; break; case 2: y=8; break; case 3: y=10; break; case 4: y=12; break; case 5: y=14; break; case 6: y=16; break; case 7: y=18; break;
- }
- cho=i; switch(k)
- {
- case 1: strcpy(s,cMenu1[i-1]);
- strcpy(t,help1[i-1]); break; case 2: strcpy(s,cMenu2[i-1]); strcpy(t,help2[i-1]); break; case 3: strcpy(s,cMenu3[i-1]); strcpy(t,help3[i-1]); break; case 4: strcpy(s,cMenu4[i-1]); strcpy(t,help4[i-1]); break; case 5: strcpy(s,cMenu5[i-1]); strcpy(t,help5[i-1]); break;
- }
- mvwr(y,x,s); cr3();
- mvwr(19,19,t); cr2();
- }
- inline void highlt(int i, int k)
- { cr0(); remov(i,k); cr2(); }
- void sel(int i, int j, int k)
- { int l;
- remov(i,k); switch(k)
- {
- case 1: l=7; break; case 2: l=5; break; case 3: l=7; break; case 4: l=4; break; case 5: l=6; break;
- }
- switch(j)
- {
- case 1: /* SEL_NEXT */ if (cho==l) cho=1; else cho++; break; case 2: /* SEL_PREV */
- if (cho==1) cho=l; else cho--; break;
- } highlt(cho,k);
- }
- inline void wt()
- {
- addstr(" PRESS ANY KEY TO CONTINUE... ");
- rfr();
- noecho(); getch(); echo();
- }
- inline void b()
- {
- wattrset(stdscr,A_ALTCHARSET);
- box(stdscr, ACS_VLINE, ACS_HLINE);
- }
- inline void m(int r, int c) { move(r,c); }
- inline void scr() { cr1(); c(); b(); cr0();
- }
- inline void scr2() { cr1(); c(); b(); cr1(); }
- inline void jbanner()
- { cr1(); mvw(2,70," #"); mvw(3,70," #"); mvw(4,70," #"); mvw(5,70," #"); mvw(6,70,"# #"); mvw(7,70,"# #"); mvw(8,70,"######"); cr4(); mvw(9,70,"Jurassic");
- }
- void itd() { scr(); jbanner(); cr0(); mvw(7,10," Video Library v 2.0 "); cr1(); jbanner(); cr0();
- mvw(19,15,"From Pretty Advanced Software Inc. "); mvw(20,15,"1500 Glenridge Dr, Beverly Hills, CA 90210"); mvw(21,5,"www.advanced.com"); m(21,25); wt();
- }
- char buff[50]; int x,y; void uaf()
- {
- beep();
- mvw(20,3," User Authorisation Failure."); wt(); m(20,1);
- clrtoeol();
- }
- int ok=0; int match=1; char passw1[10],passw2[10];
- void unlocktrml()
- {
- do { scr2();
- mvw(12,30,"PASSWORD:");
- cr0(); m(12,40); spc(10);
- mvw(7,25," Enter password to unlock the terminal."); m(12,40); noecho(); getstr(passw1); echo();
- if (strcmp(passw1,passw2) != 0)
- { uaf(); continue;
- }
- else {ok=1;}
- } while (!ok);
- }
- void locktrml()
- {
- do {scr2();
- mvw(12,30,"PASSWORD:");
- mvw(14,30,"CONFIRM :");
- cr0(); m(12,40); spc(10); m(14,40); spc(10);
- mvw(7,20," Enter a password to lock the terminal. (MAX 10 chars.)"); mvw(8,20," Use mixed case letters and no.s for more security. "); m(12,40); noecho(); getstr(passw1); m(14,40); getstr(passw2); echo(); match=1;
- if (strcmp(passw1,passw2) != 0)
- {
- match = 0; beep();
- mvw(20,3," Passwords dont match."); wt(); m(20,1);
- clrtoeol();
- }
- } while (!match);
- unlocktrml();
- }
- void readid()
- {
- int ok=0; do { scr2(); mvw(10,30,"USER ID:");
- mvw(12,30,"PASSWORD:");
- cr0(); m(10,40); spc(10); m(12,40); spc(10);
- mvw(6,25, " Enter your User ID and Password "); m(10,40); char uname[8]; rfr();
- getstr(uname); m(12,40); char passw[8]; noecho(); getstr(passw); echo(); #ifdef NIIT_CIT if (strcmp(uname,"syb6") != 0)
- #endif #ifdef DROME
- if (strcmp(uname,"syb3") != 0)
- #endif
- { uaf(); continue;
- }
- else { #ifdef NIIT_CIT
- if (strcmp(passw,"sybase") != 0)
- #endif
- #ifdef DROME
- if (strcmp(passw,"sybase3") != 0)
- #endif
- { uaf(); continue;
- }
- else {ok=1;}
- }
- } while (!ok);
- }
- chtype ch;
- DBPROCESS *dbproc; LOGINREC *login; int mflag=0; void exitall() { dbexit(); cr1();c(); cr4(); alarm(0);
- mvw(16,5," Video Library v.2.0 *** Program exited normally"); rfr(); cr1(); alarm(0); endwin(); #ifdef NIIT_CIT system("nwlogout>tmp");
- #endif system("rm rcpt 2>tmp"); system("rm tmp 2>tmp");
- exit(STDEXIT);
- }
- void mhead(int k)
- { int items; mflags=0;
- scr();cr1(); jbanner(); cr0();
- switch(k)
- {
- case 1: mvwr(3,19," Jurassic Video Rental--Main Menu "); items=7; break;
- case 2: mvwr(3,19," Customer Details Submenu "); items=5; break;
- case 3: mvwr(3,19," Movie Details Submenu "); items=7; break;
- case 4: mvwr(3,19," Transactions Submenu "); items=4; break;
- case 5: mvwr(3,19," Reports Submenu "); items=6; break;
- }
- cr1(); for(int z=1; z<=78; z++) mvw(20,z,"-"); cr3();
- mvw(21,15, " Use up arrow/down arrow to move the highlight bar."); mvw(22,15, " Then press Spacebar or ENTER to select that option."); cr2(); for (z=1; z<=items; z++) remov(z,k);
- highlt(1,k); keypad(stdscr,TRUE); slk_init(1); int l=0; curs_set(0); do { noecho(); ch=getch(); echo(); switch(ch)
- {
- case KEY_RIGHT:
- case KEY_DOWN: sel(cho,1,k); break; case KEY_LEFT:
- case KEY_UP: sel(cho,2,k); break; case 32:
- case 10:l=1; break;
- case 27: if (k==1) exitall(); else { mflag=1; return; } default: beep(); continue;
- }
- } while (l==0); curs_set(1); keypad(stdscr,FALSE);
- }
- void ma(); //forward
- void mu()
- {
- do
- {
- mhead(1); ma(); } while (1);
- } void custdet(); //forward void movdet(); //forward void tran(); //forward void rep(); //forward
- void ma()
- {
- alarm(0); //show timer only when main menu shows switch(cho)
- {
- case 1: custdet(0); break; case 2: movdet(); break; case 3: tran(); break; case 4: rep(); break; case 5: locktrml(); break; case 6: itd(); break; case 7: exitall();
- }
- alarm(1); return; } int sflag=1; void cma(); //forward
- void custdet()
- {
- sflag=1; while(sflag)
- {
- mhead(2);
- if (!mflag) cma(); else return;
- }
- }
- void cadd(); //forward void cmodf(); //forward void cdel(); //forward void cview(); //forward void cma()
- {
- sflag=1; switch(cho)
- {
- case 1:cadd(); break; case 2:cmodf(); break; case 3:cdel(); break; case 4:cview(); break; case 5:sflag=0 ; return;
- }
- }
- void mma(); //forward void movdet()
- {
- sflag=1; while (sflag)
- {
- mhead(3);
- if (!mflag) mma(); else return;
- }
- }
- void madd(); //forward void mmodf(); //forward void mdel(); //forward void mclist(); //forward void mavbl(); //forward void mfind(); //forward void mma()
- {
- sflag=1; switch(cho)
- {
- case 1: madd(); break; case 2:mmodf(); break; case 3: mdel(); break; case 4:mfind(); break; case 5: mclist(); break; case 6: mavbl(); break; case 7: sflag=0; return;
- }
- }
- void tma(); //forward void tran()
- {
- sflag=1; while (sflag)
- {
- mhead(4);
- if (!mflag) tma(); else return;
- }
- } void rent(); //forward void retvcd(); //forward void today(); //forward
- void tma()
- {
- sflag=1; switch(cho)
- { case 1: rent(); break; case 2:retvcd(); break; case 3:today(); break;
- case 4:sflag=0; return;
- }
- }
- void rma(); //forward
- void rep()
- {
- sflag=1; while (sflag)
- {
- mhead(5);
- if (!mflag) rma(); else return;
- }
- }
- void monthly(); //forward void curstk(); //forward void dcs(); //forward void overdue(); //forward
- void rma()
- {
- switch(cho)
- {
- case 1: monthly(); break; case 2: curstk(); break; case 3: mclist(); break; case 4: dcs(); break; case 5: overdue(); break;
- case 6: sflag=0; return;
- }
- }
- inline void m15(int ln, char *s)
- {
- mvw(ln,15,s);
- }
- inline void m28(int ln)
- {
- m(ln-1,28); spc(5); m(ln,28); spc(30); m(ln+1,28); spc(30); m(ln+2,28); spc(20); m(ln+3,28); spc(45);
- }
- void custhd()
- {
- cr1();
- m15(6,"CUSTOMER ID:"); mvw(6,35, "DATE OF JOIN:"); m15(7," FIRST NAME:");
- m15(8,"LAST NAME:"); m15(9,"PHONE NO:") m15(10,"ADDRESS:"); m15(11,"DEPOSIT:"); mvw(11,28,"RS. 300/-");
- cr0(); m(6,48); spc(10);
- m28(7);
- rfr(); } int cid; int ret_flag=0;
- void disperr(int z)
- {
- switch(z)
- {
- case 0: mvwr(18,2," SQL statement failure.... "); break;
- case 1: mvwr(20,2," That customer ID does not exist.... ");
- break;
- case 2: mvwr(20,2," That movie ID does not exist... ");
- break;
- case 3: mvwr(20,2," That invoice ID does not exist... "); break;
- case 10: mvwr(19,2," No data exists that match these criteria... "); break;
- }
- ret_flag=2; wt(); }
- void doit(int z)
- {
- ret_flag=1;
- if (dbsqlexec(dbproc)==FAIL) { disperr(z); return; } if (dbsqlexec(dbproc)==FAIL) { disperr(z); return; } if (DBCMDROW(dbproc) != SUCCEED) return; //chk whether the stt can send rows
- if (DBROWS(dbproc) != SUCCEED) { disperr(z); return; }
- //chk whether there are rows
- }
- inline void dbn() { dbnextrow(dbproc); }
- int amt=0; char fn[30],ln[30],ph[20],ad[45]; char cidstr[10], curdate[9]; ofstream rcpt; inline void line()
- {
- rcpt<<"------------------------------------------------------------------"<<"\n";
- }
- long t; struct tm *tp; char *ts; inline void phdr()
- {
- mvwr(16,20," Printing receipt... "); line();
- rcpt<<" ** JURASSIC VIDEO RENTAL STORE **"<<"\n"; rcpt<<"\n";
- rcpt<<" ** RECEIPT **"<<"\n"; time(&t); tp=localtime(&t); ts=asctime(tp); rcpt<<ts<<"\n";
- }
- inline void ropen()
- { rcpt.open("rcpt");
- }
- inline void rclose() { rcpt.close();
- }
- inline void do_lp()
- {
- system("lp rcpt>tmp");
- mvwr(16,40," Receipt printed... ");
- }
- void prntrcpt()
- {
- ropen(); phdr(); rcpt<<"Customer ID:"<<cidstr<<"\n"; rcpt<<"Name:"<<fn<<" "<<ln<<"\n"; rcpt<<"Address:"<<ad<<"\n"; rcpt<<"Phone:"<<ph<<"\n";
- rcpt<<"Deposit:": Rs.300/-"<<"\n";
- line(); rclose(); do_lp();
- }
- char invidstr[10]; char dtdue[20]; char midstr[10]; char mtit[41]; char joindt[10]; void printinv(int q)
- {
- ropen(); phdr(); rcpt<<"Invoice ID:"<<invidstr<<"\n"; rcpt<<"Due On:"<<dtdue<<"\n"; rcpt<<"Customer ID:"<<cidstr<<"\n"; rcpt<<"Name:"<<str<<"\n"; rcpt<<"Movie ID:"<<midstr<<"\n"; rcpt<<"Title:"<<mtit<<"\n"; if (q != 3)
- {
- rcpt << "Amount: Rs. 50/-";
- switch(q)
- {
- case 1: rcpt<<" Received W/Thanks"; break;
- case 2: rcpt<<" TO-PAY"; break;
- } rcpt<<"\n";
- }
- if (q==3)
- {
- rcpt<<"Fine: Rs. "<<buff<<" Collected W/Thanks"<<"\n";
- } line(); rclose(); do_lp();
- }
- char mcst[46]; char cps[3];
- void inputstr(int row, int col, int id)
- { char s[255]; int no;
- switch(id)
- {
- case 1: case 2: no=30; break; case 3: no=20; break; case 4: case 6: no=45; break; case 5: no=40; break; case 7: no=3; break; case 8: case 9: no=5; break;
- }
- m(row,col); cr3();
- spc(no); rfr(); m(row,col); getstr(s); switch(id)
- {
- case 1: strcpy(fn,s); break; case 2: strcpy(ln,s); break; case 3: strcpy(ph,s); break; case 4: strcpy(ad,s); break; case 5: strcpy(mtit,s); break; case 6: strcpy(mcst,s); break; case 7: strcpy(cps,s); break; case 8: strcpy(cidstr,s); break;
- case 9: strcpy(midstr,s); break;
- }
- m(row,col); cr0(); spc(no);
- mvwr(row,col,s);
- }
- int q; void getcust(int no)
- {
- if (no==1) q=7; else q=13; for (int v=1;v<=4; v++)
- inputstr(q++,28,v);
- }
- void getmov(int no)
- {
- if (no==1) q=7; else q=13; for (int v=5; v<=7; v++)
- inputstr(q++,28,v);
- }
- void cadd()
- {
- do
- {
- scr();
- mvw(3,30," ADD CUSTOMER(s) ");
- custhd();
- dbcmd(dbproc,"select max(cust_id) from customers"); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &cid); dbn(); cid++;
- sprintf(cidstr,"%d",cid); m(6,28); addstr(cidstr); mvw(6,48,curdate); rfr(); getcust(1);
- mvwr(12,20," Insert this record? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- dbfcmd(dbproc,"insert customers values(%d,'%s','%s','%s','%s',300,getdate())",cid,fn,ln,ph,ad); doit(0);
- if (ret_flag==2) return; amt+=300;
- prntrcpt();mvw(20,2," Record added. ");
- }
- else { mvw(20,2," Record not added. ");
- }
- addstr(" Add more customer records? [Y/N]: "); rfr();
- ch=getch();
- } while(ch=='Y'||ch=='y');
- }
- void showc()
- {
- dbbind(dbproc,1,STRINGBIND,0,fn); dbbind(dbproc,2,STRINGBIND,0,ln); dbbind(dbproc,3,STRINGBIND,0,ph); dbbind(dbproc,4,STRINGBIND,0,ad); dbbind(dbproc,5,STRINGBIND,0,joindt); dbn(); mvw(7,28,fn); mvw(8,28,ln); mvw(9,28,ph); mvw(10,28,ad);
- mvwr(6,48,joindt);
- }
- void getcid(int p)
- {
- scr(); switch(p)
- {
- case 1: mvw(3,35," MODIFY CUSTOMER(S) "); break;
- case 2: mvw(3,35," DELETE CUSTOMER(S) "); break;
- }
- cr1();
- mvw(6,15,"CUSTOMER ID:"); cr3(); m(6,28); spc(5); m(6,28);
- rfr(); getstr(cidstr); dbfcmd(dbproc,"select first_name,last_name,phone,address,convert(varchar(8),doj,3) from customers where cust_id=%s", cidstr); doit(1); if (ret_flag==2) return;
- }
- void cmodf()
- {
- do
- { getcid(1); if (ret_flag==2) return; scr();
- mvw(3,35," MODIFY CUSTOMER(S) "); custhd();
- mvw(5,10," OLD DETAILS "); mvwr(6,28,cidstr);
- showc();
- mvw(12,10," ENTER NEW DETAILS "); cr1(); m15(13," FIRST NAME:"): m15(14," LAST NAME :"); m15(15," PHONE NO :");
- m15(16," ADDRESS :");
- cr0();
- m28(13);
- rfr();
- getcust(2);
- mvwr(18,20," Modify this record? [Y/N]: "); ch=getch();
- if (ch=='y' || ch=='Y')
- {
- dbfcmd(dbproc,"update customers set first_name='%s', last_name='%s', phone='%s', address='%s' where cust_id=%s",fn,ln,ph,ad,cidstr); doit(0);
- if (ret_flag==2) return;
- mvw(20,2," Record modified. ");
- }
- else { mvw(20,2," Record not modified. "); }
- addstr(" Modify more customer records? [Y/N]: "); rfr();
- ch=getch();
- } while (ch=='Y'||ch=='y');
- }
- void cdel()
- {
- do
- { getcid(2);
- if (ret_flag==2) return; scr();
- mvw(3,35," DELETE CUSTOMER(S) "); custhd(); mvwr(6,28,cidstr);
- showc();
- mvwr(12,20," Delete this customer? [Y/N]: " ); ch=getch();
- if (ch=='y' || ch=='Y')
- {
- dbfcmd(dbproc,"delete customers where cust_id=%s",cidstr); doit(0); if (ret_flag==2) return;
- mvw(20,2," Record deleted. ");
- } else {
- mvw(20,2," Record not deleted. ");
- }
- addstr(" Delete more customer records? [Y/N]: "); rfr();
- ch=getch();
- } while (ch=='Y'||ch=='y');
- }
- void cview()
- { scr();
- mvw(3,35," VIEW CUSTOMER(S) ");
- mvw(4,5," To view all customers, put a %% in the column "); cr1();
- mvw(6,15,"Look for customer named:"); cr0(); m(6,40); spc(20); m(6,40); rfr(); getstr(str);
- dbfcmd(dbproc,"select cust_id,first_name,last_name, phone, convert(varchar(8),doj,3) from customers where first_name like '%s'", str); doit(10);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &cid); dbbind(dbproc,2,STRINGBIND,0,fn); dbbind(dbproc,3,STRINGBIND,0,ln); dbbind(dbproc,4,STRINGBIND,0,ph);
- dbbind(dbproc,5,STRINGBIND,0,joindt); scr();
- mvw(2,30," Query Results: "); mvw(4,2,"Cust ID:"); mvw(4,7,"First Name:"); mvw(4,22,"Last Name:"); mvw(4,35,"Phone:");
- mvw(4,55,"JOIN DATE:");
- cr1(); int p=5;
- while (dbnextrow(dbproc)!= NO_MORE_ROWS)
- {
- sprintf(cidstr,"%d",cid); mvw(p,2,cidstr); mvw(p,7,fn); mvw(p,22,ln); mvw(p,36,ph); mvw(p,55,joindt); p++;
- }
- m(20,2); wt();
- }
- void me28(int ln); //forward void mhd()
- { cr1();
- m15(6,"MOVIE ID :");
- m15(7,"MOVIE TITLE :"); m15(8,"MOVIE CAST :"); m15(9,"COPIES :"); m15(10,"THEME :"); m15(11,"MOVIE RATING :");
- cr0();
- me28(7);
- rfr();
- }
- void me28(int ln)
- {
- m(ln-1,28); spc(5); m(ln,28); spc(40); m(ln+1,28); spc(45); m(ln+2,28); spc(3); m(ln+3,28); spc(15); m(ln+4,28); spc(11);
- }
- int mov_id; char mtheme[20], mrtng[3]; int cps_int; int x2; int x1; char crtng[4][3] = {"G","12","18","PG"};
- char cthm[12][15]=
- { "Action ",
- "Comedy ",
- "Drama ", "Fiction ",
- "Documentary ",
- "Horror ",
- "Musical ",
- "ScienceFiction ",
- "Sports ",
- "Suspense ",
- "Porn ",
- "Romance "
- };
- void rmv2(int i) { int y=0; y=i+4; x2=i; mvwr(y,1,cthm[x2-1]);
- }
- void hgh2(int i) { cr0(); rmv2(i); cr2(); }
- void s12(int i, int j)
- {
- rmv2(i); switch(j)
- {
- case 1: /* SEL NEXT */ if (x2==12) x2=1; else x2++; break; case 2: /* SEL PREV */ if (x2==1) x2=12; else x2--; break;
- }
- hgh2(x2);
- }
- void rmv1(int i,int row) { int y=0; switch(i)
- {
- case 1: y = 28; break; case 2: y = 31; break; case 3: y = 34; break; case 4: y = 37; break;
- }
- x1=i; mvwr(row,y,crtng[x1-1]);
- }
- void hghl(int i, int row) { cr0(); rmv1(i, row); cr2(); }
- void sl1(int i, int j, int row)
- {
- rmv1(i, row); switch (j)
- {
- case 1: /* SEL_NEXT */ if (x1==4) x1=1; else x1++; break; case 2: /* SEL_PREV */
- if (x1==1) x1=4; else x1--; break;
- }
- hghl(x1,row);
- }
- void getmovrtng(int row)
- { cr2(); for (int z=1; z<=4; z++) rmv1(z,row); hghl(l,row); keypad(stdscr,TRUE); curs_set(0); int l=0; ret_flag=1; do { noecho(); ch=getch(); echo(); switch(ch)
- {
- case KEY_RIGHT: case KEY_DOWN:
- sl1(x1,1,row); break; case KEY_LEFT: case KEY_UP:
- sl1(x1,2,row); break; case 32: case 10: l=1; break; case 27: ret_flag=2; return; default: beep(); continue;
- }
- } while (l==0); curs_set(1); keypad(stdscr,FALSE); if (x1==1) strcpy(mrtng,"G"); else strcpy(mrtng,crtng[x1-1]); cr0();
- }
- void getmovthm(int row)
- {
- m(row,28); cr3(); spc(15); cr2(); for (int z=1; z<=12; z++) rmv2(z); hgh2(1); keypad(stdscr,TRUE); curs_set(0); int l=0; ret_flag=1; do
- {
- noecho(); ch=getch(); echo(); switch(ch)
- {
- case KEY_RIGHT:
- case KEY_DOWN: sl2(x2,1); break; case KEY_LEFT:
- case KEY_UP: sl2(x2,2); break; case 32:
- case 10: l=1; break; case 27: ret_flag=2; return;
- default: beep(); continue;
- }
- } while(l==0); curs_set(1); keypad(stdscr,FALSE); int xyz=0; while (*cthm[xyz++] != ' ') continue; *cthm[xyz]='\0'; strcpy(mtheme,cthm[x2-1]);
- cr0(); m(row,28); spc(15); mvwr(row,28,mtheme);
- }
- void madd()
- {
- do
- {
- scr(); mvw(3,35," ADD MOVIE(S) "); mhd();
- dbcmd(dbproc,"Select max(movie_id) from movies"); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &mov_id); dbn(); mov_id++;
- sprintf(buff,"%d",mov_id);
- m(6,28); addstr(buff); rfr(); getmov(1);
- if (strcmp(cps,"")==0)
- {
- strcpy(cps,"3"); mvwr(9,28,cps);
- mvwr(9,35," Using Default-3 Copies ");
- }
- getmovthm(10);
- if (ret_flag==2) return; getmovrtng(11); if (ret_flag==2) return;
- mvwr(13,20," Insert this record? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- dbfcmd(dbproc,"insert movies values(%d,'%s','%s','%s','%s','%s')",mov_id,mtit,mcst,cps,mtheme,mrtng); doit(0);
- if (ret_flag==2) return;
- mvw(20,2," Record added. ");
- }
- else { mvw(20,2," Record not added. "); }
- addstr(" Add more movie records? [Y/N]: "); rfr();
- ch=getch();
- } while(ch=='Y'||ch=='y');
- }
- void showm()
- {
- dbbind(dbproc,1,STRINGBIND,0,mtit); dbbind(dbproc,2,STRINGBIND,0,mcst); dbbind(dbproc,3,INTBIND,0,(CS_BYTE *) &cps_int); dbbind(dbproc,4,STRINGBIND,0,mtheme); dbbind(dbproc,5,STRINGBIND,0,mrtng); dbn(); mvw(7,28,mtit); mvw(8,28,mcst); sprintf(buff,"%d",cps_int); mvw(9,28,buff); mvw(10,28,mtheme);
- mvw(11,28,mrtng);
- }
- void getmovid(int p)
- {
- scr(); switch(p)
- {
- case 1:mvw(3,35," MODIFY MOVIE(S) "); break;
- case 2:mvw(3,35," DELETE MOVIE(S) "); break;
- case 3:mvw(3,25," MOVIE AVAILABILITY/VIEW MOVIE DETAILS "); break;
- } cr1();
- mvw(6,15,"MOVIE ID :");
- cr3(); m(6,28);
- spc(5); m(6,28); rfr(); getstr(midstr);
- dbfcmd(dbproc,"select movie_title,movie_cast,copies,theme,movie_rating from movies where movie_id=%s",midstr); doit(2); if (ret_flag==2) return;
- }
- void mmodf()
- {
- do { getmovid(1); if (ret_flag==2) return; scr();
- mvw(3,35," MODIFY MOVIE(S) "); mhd();
- mvw(5,40," OLD DETAILS "); mvwr(6,28,midstr); showm();
- mvw(12,40," ENTER NEW DETAILS "); cr1();
- m15(13,"MOVIE TITLE :"); m15(14,"MOVIE CAST :"); m15(15,"COPIES :"); m15(16,"THEME :"); m15(17,"MOVIE RATING :"); cr0(); me28(13); rfr(); getmov(13);
- if (strcmp(cps,"")==0)
- {
- strcpy(cps,"3"); mvwr(15,28,cps);
- mvwr(15,35," Using Default=3 Copies ");
- }
- getmovthm(16);
- if (ret_flag==2) return; getmovrtng(17); if (ret_flag==2) return;
- mvwr(19,20," Modify this record? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- dbfcmd(dbproc,"update movies set movie_title='%s',movie_cast='%s',copies=%s,theme='%s',movie_rating='%s' where movie_id=%s",mtit,mcst,cps,mtheme,mrtng,midstr); doit(0);
- if (ret_flag==2) return;
- mvw(20,2," Record modified. ");
- }
- else
- { mvw(20,2," Record not modified. "); } addstr(" Modify more movie records? [Y/N]: "); rfr();
- ch=getch();
- } while (ch=='Y'||ch=='y');
- }
- void mdel()
- {
- do { getmovid(2); if (ret_flag==2) return; scr();
- mvw(3,35," DELETE MOVIE(S) "); mhd(); mvwr(6,28,midstr); showm();
- mvwr(14,20," Delete this movie? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- dbfcmd(dbproc,"delete movies where movie_id=%s",midstr); doit(0);
- if (ret_flag==2) return;
- mvw(20,2," Record deleted.");
- } else {
- mvw(20,2," Record not deleted. ");
- }
- addstr(" Delete more movie records? [Y/N]: "); rfr();
- ch=getch();
- } while(ch=='y'||ch=='Y');
- }
- void mfind()
- { scr(); strcpy(mtit,""); strcpy(mtheme,""); mvw(3,35," FIND MOVIE(S) ");
- mvw(19,2," Enter one or more values to search on. Part of the values are acceptable "); mvw(20,2," To search for all themes, press Esc when the theme menu appears. "); mvw(21,2," To search for all movies, leave that column blank "); cr1();
- mvw(6,10," Look for movie:"); mvw(8,10," Look for theme:"); cr0(); m(6,28); spc(40); m(8,28); spc(15); m(6,28); rfr(); inputstr(6,28,5); getmovthm(8); if (strcmp(mtit,"")==0) strcpy(mtit,"%"); if (strcmp(mtheme,"")==0) strcpy(mtheme,"%");
- dbfcmd(dbproc,"Select movie_id,movie_title,theme,movie_rating,copies from movies where movie_title like '%s' and theme like '%s'",mtit,mtheme); doit(10); if (ret_flag==2)
- return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &mov_id); dbbind(dbproc,2,STRINGBIND,0,mtit); dbbind(dbproc,3,STRINGBIND,0,mtheme); dbbind(dbproc,4,STRINGBIND,0,mrtng); dbbind(dbproc,5,INTBIND,0,(CS_BYTE *) &cps_int); ten:scr();
- mvw(2,30," Query Results: "); mvw(3,2,"MOV_ID"); mvw(3,9,"TITLE"); mvw(3,40,"COPIES"); mvw(3,55,"THEME"); mvw(3,72,"RATING");
- cr1();
- int p=4;
- while (dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- sprintf(midstr,"%d",mov_id); mvw(p,2,midstr); mvw(p,6,mtit); mvw(p,55,mtheme); mvw(p,72,mrtng); sprintf(cps,"%d",cps_int); mvw(p,40,cps);
- p++; if (p>=17) { cr0(); m(22,2); wt(); goto ten; }
- } cr0();
- mvw(19,2," To view movie cast, etc., note down movie_id "); mvw(20,2," and choose MOVIE AVAILABILITY/VIEW MOVIE DETAILS "); mvw(21,2," in the Movie Details Submenu... "); m(22,2); wt();
- } void mclist()
- { scr();
- mvw(3,35," MOVIES IN CIRCULATION AS ON "); addstr(curdate);
- dbcmd(dbproc,"select movie_title,convert(varchar(8),date_due,3) from movies,invoices where movies.movie_id=invoices.movie_id and date_returned is null"); doit(0); if (ret_flag==2) return; dbbind(dbproc,1,STRINGBIND,0,mtit); dbbind(dbproc,2,STRINGBIND,0,dtdue);
- twenty:scr(); mvw(2,30," Query Results: "); int p=5; mvw(4,2,"Movie Title:");
- mvw(4,50,"Date Due:"); cr1();
- while (dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- mvw(p,2,mtit); mvw(p,50,dtdue);
- p++; if (p>=22) goto twenty;
- }
- m(20,2); cr0(); wt();
- }
- void mavbl()
- {
- getmovid(3); if (ret_flag==2) return; scr();
- mvw(3,35," MOVIE AVAILABILITY/VIEW MOVIE DETAILS "); mhd(); mvwr(6,28,midstr); showm();
- if (cps_int==0)
- {
- mvwr(14,2," Movie not available for renting right now. Check again if you want to."); m(16,20); wt();
- }
- else
- {
- mvw(14,10," Movie available for renting. "); cr1();
- mvwr(16,2," Go to the add transaction screen to rent this movie? [Y/N]: ");
- ch=getch();
- if (ch=='y' || ch=='Y') rent();
- }
- } void i28(int ln)
- {
- m(ln-2,28); spc(5); m(ln,28); spc(5);
- m(ln+1,28); spc(5);
- } void ihd(int h)
- {
- cr1(); m15(6, " INVOICE ID:"); m15(7," INVOICE DATE:"); m15(8," CUSTOMER ID:"); m15(9," MOVIE ID:"); m15(10," DATE DUE:"); m15(11," AMOUNT:"); switch(h)
- {
- case 1: mvw(11,28," RS. 50/- (can be paid while returning the disk)"); break;
- case 2: mvw(11,28," RS. 50/- UNPAID. COLLECT IT NOW"); break;
- case 3: mvw(11,28," RS. 50/- PAID ALREADY."); break;
- } cr0(); rfr(); } int inv_id; char invdt[20];
- void rent()
- {
- do
- {
- scr();
- mvw(3,35," RENT A LD/VCD "); ihd(1); i28(8); m(8,35); spc(40); m(9,35); spc(40);
- dbcmd(dbproc,"select max(inv_id) from invoices"); doit(0); if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *)&inv_id); dbn(); inv_id++; sprintf(invidstr,"%d",inv_id); m(6,28); addstr(invidstr); m(7,28); strcpy(invdt,curdate); addstr(invdt);
- dbcmd(dbproc,"select convert(varchar(8),dateadd(dd,3,getdate()),3)"); doit(0); if (ret_flag==2) return;
- dbbind(dbproc,1,STRINGBIND,0,(CS_BYTE *) &dtdue); m(10,28); dbn();
- addstr(dtdue);
- cr0(); rfr(); inputstr(8,28,8);
- dbfcmd(dbproc,"select rtrim(first_name)+' '+rtrim(last_name) from customers where cust_id=%s",cidstr); doit(1);
- if (ret_flag==2) return;
- dbbind(dbproc,1,STRINGBIND,0,str); dbn(); mvwr(8,35,str); inputstr(9,28,9);
- dbfcmd(dbproc,"select rtrim(movie_title),copies from movies where movie_id=%s",midstr); doit(2);
- if (ret_flag==2) return;
- dbbind(dbproc,1,STRINGBIND,0,mtit); dbbind(dbproc,2,INTBIND,0,(CS_BYTE *) &cps_int); dbn(); mvw(9,35,mtit);
- if (cps_int==0)
- {
- mvwr(20,2," Movie not available for renting. (Stock - 0 copies)."); m(21,2); wt(); return;
- }
- mvwr(14,2," Commit this transaction? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- m(14,2); clrtoeol();
- mvwr(14,2, " Does customer pay now? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- m(14,2); clrtoeol();
- dbfcmd(dbproc,"insert invoices(inv_id,cust_id,movie_id,amount) values(%d,%s,%s,50)",inv_id,cidstr,midstr); doit(0);
- if (ret_flag==2) return; amt+=50;
- prntinv(1);
- mvwr(14,2," RS. 50/- COLLECTED. TRANSACTION ENTERED OK");
- } else {
- m(14,2); clrtoeol();
- dbfcmd(dbproc,"insert invoices(inv_id,cust_id,movie_id,amount) values(%d,%s,%s,0)", inv_id,cidstr,midstr); doit(0);
- if (ret_flag==2) return; prntinv(2);
- mvwr(14,2," RS. 50/- TO BE COLLECTED. TRANSACTION ENTERED OK");
- }
- } else {
- m(14,2); clrtoeol();
- mvwr(14,2," TRANSACTION CANCELLED. ");
- }
- mvwr(20,2," Add more transactions? [Y/N]: "); ch=getch();
- } while (ch=='y'||ch=='Y');
- }
- int irent,fine; void getinvid(); //forward void showi(); //forward void retvcd()
- { getinvid(); if (ret_flag==2) return;
- scr(); i28(8); cr0();
- mvw(3,35," RETURN A LD/VCD "); showi();
- dbfcmd(dbproc,"select 10*datediff(dd,(select date_due from invoices where inv_id=%s),getdate())",invidstr); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE*) &fine); dbn(); if (fine <= 0) { fine=0; }
- else
- {
- sprintf(buff,"%d",fine);
- mvwr(15,2," FINE IS PAYABLE. FINE=RS. "); addstr(buff);
- }
- mvwr(17,2," Commit this transaction? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
- {
- dbfcmd(dbproc,"update invoices set date_returned=getdate() where inv_id=%s",invidstr); doit(0);
- if (ret_flag==2) return; if (fine != 0)
- { prntinv(3); amt+=fine;
- dbfcmd(dbproc, "update invoices set fine=%d where inv_id=%s", fine, invidstr); doit(0);
- if (ret_flag==2) return;
- }
- if (irent==0)
- { prntinv(1); amt+=50;
- dbfcmd(dbproc,"update invoices set amount=50 where inv_id=%s",invidstr); doit(0);
- if (ret_flag==2) return;
- }
- m(17,2); clrtoeol();
- mvw(17,2," Transaction committed. ");
- }
- else
- {
- m(17,2);
- clrtoeol();
- mvw(17,2," Transaction not committed. ");
- } wt();
- }
- void showi()
- {
- dbbind(dbproc,1,STRINGBIND,0,(CS_BYTE *) &invdt); dbbind(dbproc,2,INTBIND,0,(CS_BYTE *) &cid); dbbind(dbproc,3,INTBIND,0,(CS_BYTE *) &mov_id); dbbind(dbproc,4,STRINGBIND,0,dtdue); dbbind(dbproc,5,INTBIND,0,(CS_BYTE *) & irent); dbn();
- mvw(6,28,invidstr); mvw(7,28,invdt); sprintf(cidstr,"%d",cid); mvw(8,28,cidstr); sprintf(midstr,"%d",mov_id); mvw(9,28,midstr); mvwr(10,28,dtdue);
- dbfcmd(dbproc,"select rtrim(first_name) + ' ' + rtrim(last_name) from customers where cust_id=%s",cidstr); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,STRINGBIND,0,str); dbn();
- dbfcmd(dbproc,"select rtrim(movie_title) from movies where movie_id=%s",midstr); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,STRINGBIND,0,mtit); dbn(); if (irent==0)
- { ihd(2); } else {ihd(3);}
- }
- void getinvid()
- {
- scr();
- mvw(3,35," RETURN A LD/VCD "); cr1();
- mvw(6,15,"INVOICE ID :"); cr3(); m(6,28); spc(5); m(6,28); rfr(); getstr(invidstr);
- dbfcmd(dbproc,"select convert(varchar(8),inv_date,3),cust_id,movie_id,convert(varchar(8),date_due,3),amount from invoices where inv_id=%s",invidstr); doit(3);
- if (ret_flag==2) return;
- }
- void sybquit(int); //forward void monthly()
- {
- int p=6;
- DBPROCESS *dbproc1; dbproc1 = dbopen(login,NULL); if (dbproc1==NULL) sybquit(3);
- #ifdef NIIT_CIT dbuse(dbproc1,"f4");
- #endif
- #ifdef DROME
- dbuse(dbproc1,"pubs2");
- #endif scr();
- dbcmd(dbproc,"select datename(mm,getdate())");
- doit(0); if (ret_flag==2) return; dbbind(dbproc,1,STRINGBIND,0,str); dbn();
- mvw(4,10," For the month of: "); addstr(str);
- dbcmd(dbproc,"select convert(varchar(8),datepart(yy,getdate()))"); doit(0); if (ret_flag==2) return; char yrstr[10];
- dbbind(dbproc,1,STRINGBIND,0,yrstr); dbn();
- mvw(4,40,yrstr);
- rfr();
- mvw(3,10," MONTHLY RENTAL TRANSACTIONS REPORT "); mvw(5,2,"Movie ID:"); mvw(5,14,"Movie Title:"); mvw(5,40,"Times Rented:");
- mvw(5,55,"Total Chges.(Inc.Fine):"); rfr();
- dbcmd(dbproc,"select distinct movie_id from invoices where datepart(mm,date_due)=datepart(mm,getdate()) order by 1"); doit(0);
- if (ret_flag==2) return; cr1();
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &mov_id); while (dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- sprintf(midstr,"%d",mov_id); mvw(p,6,midstr);
- dbfcmd(dbproc1,"select movie_title from movies where movie_id=%s",midstr); dbsqlexec(dbproc1); dbresults(dbproc1);
- dbbind(dbproc1,1,STRINGBIND,0,mtit); dbnextrow(dbproc1); mvw(p,10,mtit);
- dbfcmd(dbproc1,"select count(movie_id) from invoices where movie_id=%s and datepart(mm,date_due) = datepart(mm,getdate())",midstr);
- dbsqlexec(dbproc1); dbresults(dbproc1); int count;
- dbbind(dbproc1,1,INTBIND,0,(CS_BYTE *) &count); dbnextrow(dbproc1); sprintf(buff,"%d",count); mvw(p,45,buff);
- dbfcmd(dbproc1,"select sum(amount)+sum(fine) from invoices where movie_id=%s and datepart(mm,date_due)=datepart(mm,getdate())",midstr); dbsqlexec(dbproc1); dbresults(dbproc1); int tchg;
- dbbind(dbproc1,1,INTBIND,0,(CS_BYTE *) &tchg); dbnextrow(dbproc1); sprintf(buff,"%d",tchg); mvw(p,72,buff); p++;
- }
- dbcmd(dbproc1,"select sum(amount) + sum(fine) from invoices where datepart(mm,date_due)=datepart(mm,getdate())"); dbsqlexec(dbproc1);
- dbresults(dbproc1);
- int tot;
- dbbind(dbproc1,1,INTBIND,0,(CS_BYTE *) &tot); dbnextrow(dbproc1); sprintf(buff,"%d",tot); mvw(20,72,buff);
- mvw(20,2," Total for the month of: "); cr0(); mvw(20,30,str); mvw(20,40,yrstr); m(21,2); cr2(); wt(); dbclose(dbproc1);
- }
- void curstk()
- {
- dbcmd(dbproc,"select movie_id,movie_title,copies from movies"); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &mov_id); dbbind(dbproc,2,STRINGBIND,0,mtit); dbbind(dbproc,3,INTBIND,0,(CS_BYTE *) &cps_int); newpg:scr();
- mvw(2,30," CURRENT STOCK REPORT "); int p=5; mvw(4,2,"Movie ID:"); mvw(4,20,"Movie Title:"); mvw(4,55,"Copies:");
- cr1();
- while(dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- sprintf(midstr,"%d",mov_id); mvw(p,4,midstr); mvw(p,20,mtit); sprintf(cps,"%d",cps_int); mvw(p,60,cps);
- p++; if (p>=15) { cr0(); m(22,2); wt(); goto newpg; }
- }
- cr0(); m(20,2); wt();
- }
- void des()
- { scr();
- mvw(2,30," DAILY CASH TRANSACTIONS "); mvw(3,30,"DATE:"); mvw(3,37,curdate);
- mvw(5,10,"Amount collected today is Rs. "); sprintf(str,"%d",amt); mvw(5,39,str); m(20,2); wt();
- }
- void todayhdr()
- { scr();
- mvw(3,20," TODAY'S TRANSACTIONS "); addstr(curdate); mvw(5,2,"TYPE"); mvw(5,10,"INV_ID"); mvw(5,20,"CUST_ID"); mvw(5,28,"MOVIE ID"); mvw(5,37,"DATE DUE"); mvw(5,49,"RETURN DATE"); mvw(5,61,"AMOUNT");
- mvw(5,69,"FINE"); cr1();
- }
- void today()
- {
- todayhdr();
- dbcmd(dbproc,"select inv_id,cust_id,movie_id,convert(varchar(8),date_due,3),amount from invoices where convert(varchar(8),inv_date,3)=convert(varchar(8),getdate(),3) order by 1"); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE*) &inv_id); dbbind(dbproc,2,INTBIND,0,(CS_BYTE *) &cid); dbbind(dbproc,3,INTBIND,0,(CS_BYTE *) &mov_id); dbbind(dbproc,4,STRINGBIND,0,dtdue); dbbind(dbproc,5,INTBIND,0,(CS_BYTE *) &irent); int p=7;
- while (dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- sprintf(invidstr,"%d",inv_id); sprintf(cidstr,"%d",cid); sprintf(midstr,"%d",mov_id);
- sprintf(str,"%d",irent); mvw(p,2,"RENTED"); mvw(p,10,invidstr); mvw(p,20,cidstr); mvw(p,28,midstr); mvw(p,37,dtdue); mvw(p,61,str); p++;
- if (p>=15) { m(22,2); wt(); todayhdr(); p=7; }
- } cr0(); m(22,2); wt(); todayhdr(); p=7;
- dbcmd(dbproc,"select
- inv_id,cust_id,movie_id,convert(varchar(8),date_due,3),convert(varchar(8),date_returned,3),amount,fine from invoices where convert(varchar(8),date_returned,3)=convert(varchar(8),getdate(),3) order by 1"); doit(0);
- if (ret_flag==2) return;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &inv_id); dbbind(dbproc,2,INTBIND,0,(CS_BYTE *) &cid); dbbind(dbproc,3,INTBIND,0,(CS_BYTE *) &mov_id); dbbind(dbproc,4,STRINGBIND,0,dtdue); dbbind(dbproc,5,STRINGBIND,0,str); dbbind(dbproc,6,INTBIND,0,(CS_BYTE *) &irent); dbbind(dbproc,7,INTBIND,0,(CS_BYTE *) &fine);
- char rentstr[20],finestr[20];
- while (dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- sprintf(invidstr,"%d",inv_id); sprintf(cidstr,"%d",cid); sprintf(midstr,"%d",mov_id); sprintf(rentstr,"%d",irent); sprintf(finestr,"%d",fine); mvw(p,2,"RETURNED"); mvw(p,12,invidstr); mvw(p,20,cidstr); mvw(p,28,midstr); mvw(p,37,dtdue); mvw(p,49,str); mvw(p,61,rentstr); mvw(p,69,finestr); p++; if (p>=15)
- { m(22,2); wt(); todayhdr(); p=7; }
- }
- cr0(); m(22,2); wt();
- }
- void sybquit(int p)
- {
- char s[100];
- switch(p)
- {
- case 1:strcpy(s," DB-Library initialization failed. "); break;
- case 2:strcpy(s," Unable to allocate memory for LOGINREC. "); break;
- case 3:strcpy(s," Connection with the Sybase SQL Server could not be established."); break;
- } cr0(); mvwr(20,2,s); m(21,1); alarm(0); endwin();
- exit(ERREXIT);
- }
- void ovrduehdr()
- { scr();
- mvw(3,35," OVERDUE MOVIES AS ON "); addstr(curdate); mvw(5,2," INV_ID"); mvw(5,9," CUST_ID"); mvw(5,17," MOVIE_ID"); mvw(5,27," TITLE"); mvw(5,62," DUE ON");
- mvw(5,71," OVRD BY");
- rfr();
- }
- void overdue()
- {
- ovrduehdr(); dbcmd(dbproc,"select
- inv_id,cust_id,invoices.movie_id,movie_title,convert(varchar(8),date_due,3),datediff(dd,date_due,getdate()) from invoices,movies where invoices.movie_id = movies.movie_id and date_returned is null and convert(varchar(8),date_due,3)<convert(varchar(8),getdate(),3) order by 1"); doit(0);
- if (ret_flag==2) return;
- int dtdif; int p=7;
- dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &inv_id); dbbind(dbproc,2,INTBIND,0,(CS_BYTE *) &cid); dbbind(dbproc,3,INTBIND,0,(CS_BYTE *) &mov_id); dbbind(dbproc,4,STRINGBIND,0,mtit); dbbind(dbproc,5,STRINGBIND,0,dtdue); dbbind(dbproc,6,INTBIND,0,(CS_BYTE *) &dtdif); cr1();
- while (dbnextrow(dbproc) != NO_MORE_ROWS)
- {
- sprintf(invidstr,"%d",inv_id); sprintf(cidstr,"%d",cid); sprintf(midstr,"%d",mov_id); sprintf(buff,"%d",dtdif); mvw(p,5,invidstr); mvw(p,11,cidstr); mvw(p,19,midstr); mvw(p,27,mtit); mvw(p,62,dtdue); mvw(p,72,buff);
- addstr(" Day(s)"); p++;
- }
- if (p>=22)
- { cr0(); m(22,2); wt(); ovrduehdr(); p=7; } cr0(); m(22,2); wt();
- }
- void initsyb()
- {
- if (dbinit()==FAIL) sybquit(1);
- if ((login=dblogin())==NULL) sybquit(2);
- #ifdef NIIT_CIT
- DBSETLUSER(login,"syb6");
- DBSETLPWD(login,"sybase");
- #endif
- #ifdef DROME
- DBSETLUSER(login,"syb3");
- DBSETLPWD(login,"sybase3");
- #endif
- DBSETLAPP(login,"videolibrary v.2.0"); dbproc=dbopen(login,NULL); if (dbproc==NULL) sybquit(3);
- #ifdef NIIT_CIT dbuse(dbproc,"f4"); #endif
- #ifdef DROME dbuse(dbproc,"pubs2");
- #endif #ifdef NIIT_CIT system("nwlogout > tmp"); system("nwlogin niit_cit/user1");
- #endif
- dbcmd(dbproc,"select convert(varchar(8),getdate(),3)"); doit(0);
- if (ret_flag==2) sybquit(3); dbbind(dbproc,1,STRINGBIND,0,curdate); dbn();
- }
- void ctrlbksp()
- {
- signal(SIGINT,&ctrlbksp); signal(SIGQUIT,&ctrlbksp); alarm(0); scr();
- mvw(15,9," You pressed Ctrl+Bksp or Ctrl+\\. You really wanna quit? [Y/N]: "); ch=getch();
- if ((ch=='y')||(ch=='Y')) exitall(); else { alarm(1); mu(); }
- } void timer()
- { time(&t); tp=localtime(&t); ts=asctime(tp); mvwr(1,50,ts); signal(SIGALRM,&timer); alarm(1);
- } int main()
- { initscr(); initsyb(); itd(); readid(); signal(SIGINT,&ctrlbksp); signal(SIGQUIT,&ctrlbksp); signal(SIGALRM,&timer); alarm(1); mu(); retun (0); }
Add Comment
Please, Sign In to add comment