lmohanarun

For your kids Sybase/C++/UNIX knowledge.

Dec 20th, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.47 KB | None | 0 0
  1. Date: 12/21/15
  2. Hi Kristen Stewart,
  3. This was a project I did in 1998 when I was studying in NIIT Computer Training.
  4. So the rights of this source code is mine.
  5. May be you want to teach your kids something similar yourself.
  6. We cannot allow other nationals to take our US's well-paying, decent full time jobs depriving
  7. means of livelihood for American workers first.
  8. Employers should be hiring AMerican workers first and priority is American workers.
  9. Don't let your kids lose out in this mad race.
  10. 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.
  11.  
  12. Personally, Take it as a token of affection for ya, regardless of who you are what do you do.
  13. ok
  14. 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
  15.  
  16. Sybase Table Creation Script
  17. /* tables.vi */
  18. /* Sybase SQL Server System 10 */ use f4 go
  19. set nocount on go
  20. /* drop dependent tables first */
  21. if exists(select name from sysobjects where name='invoices') drop table invoices go
  22. if exists(select name from sysobjects where name='customers') drop table customers go
  23. if exists(select name from sysobjects where name='movies') drop table movies go
  24. create table customers
  25. (
  26. cust_id int constraint pk primary key, first_name char(30), last_name char(30) null, phone char(20) null,
  27. address char(50) null, deposit smallmoney default 300,
  28. doj smalldatetime default getdate()) go
  29. create table movies
  30. (
  31. movie_id int constraint pk primary key, movie_title char(40), movie_cast char(45), copies smallint default 3,
  32. theme char(15) constraint t check (theme in ("Action","Comedy","Drama","Fiction","Documentary",
  33. "Horror","Musical","ScienceFiction","Sports","Suspense","Porn","Romance")), movie_rating char(2) default "G" constraint m check
  34. (movie_rating in ("PG","12","18","G"))
  35. )
  36. go
  37. create table invoices
  38. (
  39. inv_id constraint pk primary key, inv_date smalldatetime default getdate(), cust_id int, movie_id int,
  40. date_due smalldatetime default dateadd(dd,3,getdate()), date_returned smalldatetime null, amount smallmoney default 50,
  41. fine smallmoney default 0
  42. )
  43. go
  44. if exists(select name from sysobjects where type='P' and name='inscust') drop proc inscust
  45. go
  46. create proc inscust(@custid int, @fname char(30), @lname char(30), @ph char(20), @addr char(30)) as
  47. /* check whether the customer exists */
  48. if (select count(*) from customers where cust_id=@custid) > 0 begin return 1000 end
  49. insert customers values(@custid,@fname,@lname,@ph,@addr,300,getdate()) return go
  50. if exists(select name from sysobjects where type='P' and name='insmovie') drop proc insmovie go
  51. create proc insmovie(@mid int, @mtitle char(40), @mcast char(40), @copies int,
  52. @theme char(20), @mrating char(2)) as
  53. /* check whether the movie already exists */ if (select count(*) from movies where movie_id=@mid) > 0 begin return 1001 end
  54. insert movies values(@mid,@mtitle,@mcast,@copies,@theme,@mrating) return go
  55. if exists(select name from sysobjects where type='P' and name='addtrans')
  56. drop proc addtrans
  57. go
  58. create proc addtrans(@invid int, @custid int, @mid int) as
  59. /* check whether the customer exists */ if (select count(*) from customers where cust_id=@custid)=0 begin return 1002
  60. end
  61. /* check whether the movie exists */ if (select count(*) from movies where movie_id=@mid)=0) begin return 1003
  62. end
  63. /* check that the invoice id does not already exist */ if (select count(*) from invoices where inv_id=@invid) > 0 begin return 1004
  64. end
  65. /* check whether the movie is available */
  66. if (select copies from movies where movie_id=@mid)=0 begin return 1005
  67. end
  68. insert invoices(inv_id,cust_id,movie_id,amount) values(@invid,@custid,@mid,50) return go
  69. if exists(select name from sysobjects where name='cust_del') drop trigger cust_del go
  70. create trigger cust_del on customers
  71. for delete as
  72. if (select count(*) from invoices,deleted where invoices.cust_id=deleted.cust_id)>0
  73. begin
  74. delete invoices from invoices,deleted
  75. where invoices.cust_id=deleted.cust_id end
  76. return go
  77. if exists(select name from sysobjects where name='movie_del') drop trigger movie_del go
  78. create trigger movie_del
  79. on movies for delete as
  80. if (select count(*) from invoices,deleted where invoices.movie_id=deleted.movie_id) > 0
  81. begin
  82. delete invoices from invoices,deleted where invoices.movie_id=deleted.movie_id end
  83. return go
  84. if exists(select name from sysobjects where name='inv_ins') drop trigger inv_ins go
  85. create trigger inv_ins on invoices
  86. for insert
  87. as update movies set copies=copies-1 from inserted
  88. where movies.movie_id=inserted.movie_id return go
  89. if exists(select name from sysobjects where name ='inv_upd')
  90. drop trigger inv_upd
  91. go
  92. create trigger inv_upd on invoices
  93. for update as
  94. if update(date_returned) begin update movies
  95. set copies=copies+1
  96. from inserted
  97. where movies.movie_id=inserted.movie_id end
  98. return go
  99. /****** INSERT TEST RECORDS *********/ truncate table customers
  100. go
  101. exec inscust 1, 'Mike', 'Kasem', '19340343','3b marine drive' go
  102. ...
  103. truncate table movies
  104. go
  105. exec insmovie 1, 'City Hall',
  106. 'Al Pacino, Jack Cusack, Bridget Fonda',3,'Action','PG' go
  107. ...
  108. truncate table invoices go
  109. exec addtrans 1,1,1 go
  110. ...
  111. /* Have disk(s) returned */
  112. update invoices set date_returned = getdate() where inv_id=1 go
  113. /* Overdue movies */
  114. update invoices set inv_date=dateadd(dd,-2,getdate()), date_due=dateadd(dd,-2,getdate()) where inv_id=8 go
  115. ...
  116. C Program Video Library Maintenance
  117. /***
  118. video.cc
  119. Compile with g++ 2.5.7
  120. g++ -l. -l$SYBASE/include $1.cc -L$SYBASE/lib -lsybdb -lcurses -lnsl -lm -o $1
  121. **/
  122. #define NIIT_CIT
  123. #include <fstream.h>
  124. #include <curses.h>
  125. #include <stdio.h>
  126. #include <string.h>
  127. #ifdef NIIT_CIT
  128. #include <sybcc.h>
  129. #endif
  130. #ifdef DROME
  131. #include <sybase.h>
  132. #endif
  133. #include <stdlib.h>
  134. #include <time.h>
  135. #include <sys/types.h>
  136. #include <signal.h> #include <unistd.h>
  137. char cMenu1[7][50] = { " Customer Details ",
  138. " Movie Details ",
  139. " Transactions ",
  140. " Reports ",
  141. " Lock Terminal ",
  142. " About ... / Credits ",
  143. " Exit (ESCAPE) "
  144. };
  145. char help1[7][50] =
  146. { " Add/Modify/Delete/View Customer(s) ",
  147. " Add/Modify/Delete/View Movie(s) ",
  148. " Rent/Return a LD/VCD ",
  149. " Various Reports ",
  150. " Lock the terminal with a password ",
  151. " View Credits of Video Library v. 2.0 ",
  152. " Exit from this program "
  153. };
  154. char cMenu2[5][50] = { " Add Customer(s) ",
  155. " Modify Customer(s) ",
  156. " Delete Customer(s) ",
  157. "View Customer(s) ",
  158. " Return to Main Menu (ESCAPE) "
  159. };
  160. char help2[5][50] = { " Add Customer(s) record(s) ",
  161. " Modify Customer(s) record(s) ",
  162. " Delete Customer(s) record(s) ",
  163. " Search for Customer(s) ",
  164. " Return to the Main Menu "
  165. };
  166. char cMenu3[7][50] = { " Add Movie(s) ",
  167. " Modify Movie(s) ",
  168. " Delete Movie(s) ",
  169. " Find Movie(s) by Name/Theme ",
  170. " List Movies in Circulation ",
  171. " Check Movie Availability ",
  172. " Return to Main Menu ",
  173. };
  174. char help3[7][50] = { " Add Movie(s) record(s) ",
  175. " Modify Movie(s) record(s) ", " Delete Movie(s) record(s) ",
  176. " Search for Movie(s) by Name/Theme ",
  177. " List all Movie(s) in Circulation ",
  178. " Check Movie Availability ",
  179. " Return to Main Menu "
  180. };
  181. char cMenu4[4][50] = { " Rent a LD/VCD ",
  182. " Return a LD/VCD ",
  183. " View Today's Transactions ",
  184. " Return to Main Menu (ESCAPE) "
  185. };
  186. char help4[4][50] = { "Rent a disk to a customer ",
  187. "Customer returns a disk ",
  188. " View today's transactions ",
  189. " Return to Main Menu "
  190. };
  191. char cMenu5[6][50] = { " Monthly Rental Transactions Report ",
  192. " Current Stock Report ",
  193. " Movies in Circulation ",
  194. " Daily Cash Summary ",
  195. " Movies that are overdue ",
  196. " Return to Main Menu (ESCAPE) "
  197. };
  198. char help5[6][50] = { "Shows monthly transaction summary ",
  199. " Shows current stock ",
  200. " List movie(s) in circulation ",
  201. " Daily Cash Summary ",
  202. " Shows movies that are overdue ",
  203. " Return to Main Menu "
  204. };
  205. int cho; inline void rtr() { refresh(); } char str[255];
  206. void spc(int no)
  207. {
  208. char tempstr[255]; strcpy(tempstr, " "); for(int i=2; i<= no; i++) strcat(tempstr," ");
  209. addstr(tempstr);
  210. }
  211. #ifdef NIIT_CIT
  212. inline void cr0() { attrset(A_BOLD); } inline void cr1() { attrset(0); }
  213. inline void cr2()
  214. { attrset(A_COLOR|A_DIM|A_UNDERLINE); }
  215. inline void cr3()
  216. { attrset(A_REVERSE); }
  217. inline void cr4()
  218. { attrset(A_COLOR&A_BOLD&A_BLINK); }
  219. #endif
  220. #ifdef DROME
  221. inline void cr0()
  222. { attrset(A_REVERSE); } inline void cr1() { attrset(0); } inline void cr2() { cr0(); } inline void cr3() { cr0(); } inline void cr4()
  223. { cr0(); } #endif
  224. inline void mvw(int a, int b, char *s) { mvprintw(a,b,s); }
  225. inline void mvwr(int a, int b, char *s)
  226. {
  227. mvw(a,b,s);
  228. rfr(); }
  229. inline void c()
  230. {
  231. wclear(stdscr);
  232. } void remov(int i, int k)
  233. {
  234. int x=10, y=0; char s[255], t[255];
  235. switch(i)
  236. {
  237. 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;
  238. }
  239. cho=i; switch(k)
  240. {
  241. case 1: strcpy(s,cMenu1[i-1]);
  242. 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;
  243. }
  244. mvwr(y,x,s); cr3();
  245. mvwr(19,19,t); cr2();
  246. }
  247. inline void highlt(int i, int k)
  248. { cr0(); remov(i,k); cr2(); }
  249. void sel(int i, int j, int k)
  250. { int l;
  251. remov(i,k); switch(k)
  252. {
  253. 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;
  254. }
  255. switch(j)
  256. {
  257. case 1: /* SEL_NEXT */ if (cho==l) cho=1; else cho++; break; case 2: /* SEL_PREV */
  258. if (cho==1) cho=l; else cho--; break;
  259. } highlt(cho,k);
  260. }
  261. inline void wt()
  262. {
  263. addstr(" PRESS ANY KEY TO CONTINUE... ");
  264. rfr();
  265. noecho(); getch(); echo();
  266. }
  267. inline void b()
  268. {
  269. wattrset(stdscr,A_ALTCHARSET);
  270. box(stdscr, ACS_VLINE, ACS_HLINE);
  271. }
  272. inline void m(int r, int c) { move(r,c); }
  273. inline void scr() { cr1(); c(); b(); cr0();
  274. }
  275. inline void scr2() { cr1(); c(); b(); cr1(); }
  276. inline void jbanner()
  277. { 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");
  278. }
  279. void itd() { scr(); jbanner(); cr0(); mvw(7,10," Video Library v 2.0 "); cr1(); jbanner(); cr0();
  280. 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();
  281. }
  282. char buff[50]; int x,y; void uaf()
  283. {
  284. beep();
  285. mvw(20,3," User Authorisation Failure."); wt(); m(20,1);
  286. clrtoeol();
  287. }
  288. int ok=0; int match=1; char passw1[10],passw2[10];
  289. void unlocktrml()
  290. {
  291. do { scr2();
  292. mvw(12,30,"PASSWORD:");
  293. cr0(); m(12,40); spc(10);
  294. mvw(7,25," Enter password to unlock the terminal."); m(12,40); noecho(); getstr(passw1); echo();
  295. if (strcmp(passw1,passw2) != 0)
  296. { uaf(); continue;
  297. }
  298. else {ok=1;}
  299. } while (!ok);
  300. }
  301. void locktrml()
  302. {
  303. do {scr2();
  304. mvw(12,30,"PASSWORD:");
  305. mvw(14,30,"CONFIRM :");
  306. cr0(); m(12,40); spc(10); m(14,40); spc(10);
  307. 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;
  308. if (strcmp(passw1,passw2) != 0)
  309. {
  310. match = 0; beep();
  311. mvw(20,3," Passwords dont match."); wt(); m(20,1);
  312. clrtoeol();
  313. }
  314. } while (!match);
  315. unlocktrml();
  316. }
  317. void readid()
  318. {
  319. int ok=0; do { scr2(); mvw(10,30,"USER ID:");
  320. mvw(12,30,"PASSWORD:");
  321. cr0(); m(10,40); spc(10); m(12,40); spc(10);
  322. mvw(6,25, " Enter your User ID and Password "); m(10,40); char uname[8]; rfr();
  323. getstr(uname); m(12,40); char passw[8]; noecho(); getstr(passw); echo(); #ifdef NIIT_CIT if (strcmp(uname,"syb6") != 0)
  324. #endif #ifdef DROME
  325. if (strcmp(uname,"syb3") != 0)
  326. #endif
  327. { uaf(); continue;
  328. }
  329. else { #ifdef NIIT_CIT
  330. if (strcmp(passw,"sybase") != 0)
  331. #endif
  332. #ifdef DROME
  333. if (strcmp(passw,"sybase3") != 0)
  334. #endif
  335. { uaf(); continue;
  336. }
  337. else {ok=1;}
  338. }
  339. } while (!ok);
  340. }
  341. chtype ch;
  342. DBPROCESS *dbproc; LOGINREC *login; int mflag=0; void exitall() { dbexit(); cr1();c(); cr4(); alarm(0);
  343. mvw(16,5," Video Library v.2.0 *** Program exited normally"); rfr(); cr1(); alarm(0); endwin(); #ifdef NIIT_CIT system("nwlogout>tmp");
  344. #endif system("rm rcpt 2>tmp"); system("rm tmp 2>tmp");
  345. exit(STDEXIT);
  346. }
  347. void mhead(int k)
  348. { int items; mflags=0;
  349. scr();cr1(); jbanner(); cr0();
  350. switch(k)
  351. {
  352. case 1: mvwr(3,19," Jurassic Video Rental--Main Menu "); items=7; break;
  353. case 2: mvwr(3,19," Customer Details Submenu "); items=5; break;
  354. case 3: mvwr(3,19," Movie Details Submenu "); items=7; break;
  355. case 4: mvwr(3,19," Transactions Submenu "); items=4; break;
  356. case 5: mvwr(3,19," Reports Submenu "); items=6; break;
  357. }
  358. cr1(); for(int z=1; z<=78; z++) mvw(20,z,"-"); cr3();
  359. 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);
  360. highlt(1,k); keypad(stdscr,TRUE); slk_init(1); int l=0; curs_set(0); do { noecho(); ch=getch(); echo(); switch(ch)
  361. {
  362. case KEY_RIGHT:
  363. case KEY_DOWN: sel(cho,1,k); break; case KEY_LEFT:
  364. case KEY_UP: sel(cho,2,k); break; case 32:
  365. case 10:l=1; break;
  366. case 27: if (k==1) exitall(); else { mflag=1; return; } default: beep(); continue;
  367. }
  368. } while (l==0); curs_set(1); keypad(stdscr,FALSE);
  369. }
  370. void ma(); //forward
  371. void mu()
  372. {
  373. do
  374. {
  375. mhead(1); ma(); } while (1);
  376. } void custdet(); //forward void movdet(); //forward void tran(); //forward void rep(); //forward
  377. void ma()
  378. {
  379. alarm(0); //show timer only when main menu shows switch(cho)
  380. {
  381. 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();
  382. }
  383. alarm(1); return; } int sflag=1; void cma(); //forward
  384. void custdet()
  385. {
  386. sflag=1; while(sflag)
  387. {
  388. mhead(2);
  389. if (!mflag) cma(); else return;
  390. }
  391. }
  392. void cadd(); //forward void cmodf(); //forward void cdel(); //forward void cview(); //forward void cma()
  393. {
  394. sflag=1; switch(cho)
  395. {
  396. case 1:cadd(); break; case 2:cmodf(); break; case 3:cdel(); break; case 4:cview(); break; case 5:sflag=0 ; return;
  397. }
  398. }
  399. void mma(); //forward void movdet()
  400. {
  401. sflag=1; while (sflag)
  402. {
  403. mhead(3);
  404. if (!mflag) mma(); else return;
  405. }
  406. }
  407. void madd(); //forward void mmodf(); //forward void mdel(); //forward void mclist(); //forward void mavbl(); //forward void mfind(); //forward void mma()
  408. {
  409. sflag=1; switch(cho)
  410. {
  411. 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;
  412. }
  413. }
  414. void tma(); //forward void tran()
  415. {
  416. sflag=1; while (sflag)
  417. {
  418. mhead(4);
  419. if (!mflag) tma(); else return;
  420. }
  421. } void rent(); //forward void retvcd(); //forward void today(); //forward
  422. void tma()
  423. {
  424. sflag=1; switch(cho)
  425. { case 1: rent(); break; case 2:retvcd(); break; case 3:today(); break;
  426. case 4:sflag=0; return;
  427. }
  428. }
  429. void rma(); //forward
  430. void rep()
  431. {
  432. sflag=1; while (sflag)
  433. {
  434. mhead(5);
  435. if (!mflag) rma(); else return;
  436. }
  437. }
  438. void monthly(); //forward void curstk(); //forward void dcs(); //forward void overdue(); //forward
  439. void rma()
  440. {
  441. switch(cho)
  442. {
  443. case 1: monthly(); break; case 2: curstk(); break; case 3: mclist(); break; case 4: dcs(); break; case 5: overdue(); break;
  444. case 6: sflag=0; return;
  445. }
  446. }
  447. inline void m15(int ln, char *s)
  448. {
  449. mvw(ln,15,s);
  450. }
  451. inline void m28(int ln)
  452. {
  453. 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);
  454. }
  455. void custhd()
  456. {
  457. cr1();
  458. m15(6,"CUSTOMER ID:"); mvw(6,35, "DATE OF JOIN:"); m15(7," FIRST NAME:");
  459. m15(8,"LAST NAME:"); m15(9,"PHONE NO:") m15(10,"ADDRESS:"); m15(11,"DEPOSIT:"); mvw(11,28,"RS. 300/-");
  460. cr0(); m(6,48); spc(10);
  461. m28(7);
  462. rfr(); } int cid; int ret_flag=0;
  463. void disperr(int z)
  464. {
  465. switch(z)
  466. {
  467. case 0: mvwr(18,2," SQL statement failure.... "); break;
  468. case 1: mvwr(20,2," That customer ID does not exist.... ");
  469. break;
  470. case 2: mvwr(20,2," That movie ID does not exist... ");
  471. break;
  472. case 3: mvwr(20,2," That invoice ID does not exist... "); break;
  473. case 10: mvwr(19,2," No data exists that match these criteria... "); break;
  474. }
  475. ret_flag=2; wt(); }
  476. void doit(int z)
  477. {
  478. ret_flag=1;
  479. 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
  480. if (DBROWS(dbproc) != SUCCEED) { disperr(z); return; }
  481. //chk whether there are rows
  482. }
  483. inline void dbn() { dbnextrow(dbproc); }
  484. int amt=0; char fn[30],ln[30],ph[20],ad[45]; char cidstr[10], curdate[9]; ofstream rcpt; inline void line()
  485. {
  486. rcpt<<"------------------------------------------------------------------"<<"\n";
  487. }
  488. long t; struct tm *tp; char *ts; inline void phdr()
  489. {
  490. mvwr(16,20," Printing receipt... "); line();
  491. rcpt<<" ** JURASSIC VIDEO RENTAL STORE **"<<"\n"; rcpt<<"\n";
  492. rcpt<<" ** RECEIPT **"<<"\n"; time(&t); tp=localtime(&t); ts=asctime(tp); rcpt<<ts<<"\n";
  493. }
  494. inline void ropen()
  495. { rcpt.open("rcpt");
  496. }
  497. inline void rclose() { rcpt.close();
  498. }
  499. inline void do_lp()
  500. {
  501. system("lp rcpt>tmp");
  502. mvwr(16,40," Receipt printed... ");
  503. }
  504. void prntrcpt()
  505. {
  506. ropen(); phdr(); rcpt<<"Customer ID:"<<cidstr<<"\n"; rcpt<<"Name:"<<fn<<" "<<ln<<"\n"; rcpt<<"Address:"<<ad<<"\n"; rcpt<<"Phone:"<<ph<<"\n";
  507. rcpt<<"Deposit:": Rs.300/-"<<"\n";
  508. line(); rclose(); do_lp();
  509. }
  510. char invidstr[10]; char dtdue[20]; char midstr[10]; char mtit[41]; char joindt[10]; void printinv(int q)
  511. {
  512. 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)
  513. {
  514. rcpt << "Amount: Rs. 50/-";
  515. switch(q)
  516. {
  517. case 1: rcpt<<" Received W/Thanks"; break;
  518. case 2: rcpt<<" TO-PAY"; break;
  519. } rcpt<<"\n";
  520. }
  521. if (q==3)
  522. {
  523. rcpt<<"Fine: Rs. "<<buff<<" Collected W/Thanks"<<"\n";
  524. } line(); rclose(); do_lp();
  525. }
  526. char mcst[46]; char cps[3];
  527. void inputstr(int row, int col, int id)
  528. { char s[255]; int no;
  529. switch(id)
  530. {
  531. 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;
  532. }
  533. m(row,col); cr3();
  534. spc(no); rfr(); m(row,col); getstr(s); switch(id)
  535. {
  536. 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;
  537. case 9: strcpy(midstr,s); break;
  538. }
  539. m(row,col); cr0(); spc(no);
  540. mvwr(row,col,s);
  541. }
  542. int q; void getcust(int no)
  543. {
  544. if (no==1) q=7; else q=13; for (int v=1;v<=4; v++)
  545. inputstr(q++,28,v);
  546. }
  547. void getmov(int no)
  548. {
  549. if (no==1) q=7; else q=13; for (int v=5; v<=7; v++)
  550. inputstr(q++,28,v);
  551. }
  552. void cadd()
  553. {
  554. do
  555. {
  556. scr();
  557. mvw(3,30," ADD CUSTOMER(s) ");
  558. custhd();
  559. dbcmd(dbproc,"select max(cust_id) from customers"); doit(0);
  560. if (ret_flag==2) return;
  561. dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &cid); dbn(); cid++;
  562. sprintf(cidstr,"%d",cid); m(6,28); addstr(cidstr); mvw(6,48,curdate); rfr(); getcust(1);
  563. mvwr(12,20," Insert this record? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  564. {
  565. dbfcmd(dbproc,"insert customers values(%d,'%s','%s','%s','%s',300,getdate())",cid,fn,ln,ph,ad); doit(0);
  566. if (ret_flag==2) return; amt+=300;
  567. prntrcpt();mvw(20,2," Record added. ");
  568. }
  569. else { mvw(20,2," Record not added. ");
  570. }
  571. addstr(" Add more customer records? [Y/N]: "); rfr();
  572. ch=getch();
  573. } while(ch=='Y'||ch=='y');
  574. }
  575. void showc()
  576. {
  577. 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);
  578. mvwr(6,48,joindt);
  579. }
  580. void getcid(int p)
  581. {
  582. scr(); switch(p)
  583. {
  584. case 1: mvw(3,35," MODIFY CUSTOMER(S) "); break;
  585. case 2: mvw(3,35," DELETE CUSTOMER(S) "); break;
  586. }
  587. cr1();
  588. mvw(6,15,"CUSTOMER ID:"); cr3(); m(6,28); spc(5); m(6,28);
  589. 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;
  590. }
  591. void cmodf()
  592. {
  593. do
  594. { getcid(1); if (ret_flag==2) return; scr();
  595. mvw(3,35," MODIFY CUSTOMER(S) "); custhd();
  596. mvw(5,10," OLD DETAILS "); mvwr(6,28,cidstr);
  597. showc();
  598. mvw(12,10," ENTER NEW DETAILS "); cr1(); m15(13," FIRST NAME:"): m15(14," LAST NAME :"); m15(15," PHONE NO :");
  599. m15(16," ADDRESS :");
  600. cr0();
  601. m28(13);
  602. rfr();
  603. getcust(2);
  604. mvwr(18,20," Modify this record? [Y/N]: "); ch=getch();
  605. if (ch=='y' || ch=='Y')
  606. {
  607. 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);
  608. if (ret_flag==2) return;
  609. mvw(20,2," Record modified. ");
  610. }
  611. else { mvw(20,2," Record not modified. "); }
  612. addstr(" Modify more customer records? [Y/N]: "); rfr();
  613. ch=getch();
  614. } while (ch=='Y'||ch=='y');
  615. }
  616. void cdel()
  617. {
  618. do
  619. { getcid(2);
  620. if (ret_flag==2) return; scr();
  621. mvw(3,35," DELETE CUSTOMER(S) "); custhd(); mvwr(6,28,cidstr);
  622. showc();
  623. mvwr(12,20," Delete this customer? [Y/N]: " ); ch=getch();
  624. if (ch=='y' || ch=='Y')
  625. {
  626. dbfcmd(dbproc,"delete customers where cust_id=%s",cidstr); doit(0); if (ret_flag==2) return;
  627. mvw(20,2," Record deleted. ");
  628. } else {
  629. mvw(20,2," Record not deleted. ");
  630. }
  631. addstr(" Delete more customer records? [Y/N]: "); rfr();
  632. ch=getch();
  633. } while (ch=='Y'||ch=='y');
  634. }
  635. void cview()
  636. { scr();
  637. mvw(3,35," VIEW CUSTOMER(S) ");
  638. mvw(4,5," To view all customers, put a %% in the column "); cr1();
  639. mvw(6,15,"Look for customer named:"); cr0(); m(6,40); spc(20); m(6,40); rfr(); getstr(str);
  640. 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);
  641. if (ret_flag==2) return;
  642. 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);
  643. dbbind(dbproc,5,STRINGBIND,0,joindt); scr();
  644. mvw(2,30," Query Results: "); mvw(4,2,"Cust ID:"); mvw(4,7,"First Name:"); mvw(4,22,"Last Name:"); mvw(4,35,"Phone:");
  645. mvw(4,55,"JOIN DATE:");
  646. cr1(); int p=5;
  647. while (dbnextrow(dbproc)!= NO_MORE_ROWS)
  648. {
  649. 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++;
  650. }
  651. m(20,2); wt();
  652. }
  653. void me28(int ln); //forward void mhd()
  654. { cr1();
  655. m15(6,"MOVIE ID :");
  656. m15(7,"MOVIE TITLE :"); m15(8,"MOVIE CAST :"); m15(9,"COPIES :"); m15(10,"THEME :"); m15(11,"MOVIE RATING :");
  657. cr0();
  658. me28(7);
  659. rfr();
  660. }
  661. void me28(int ln)
  662. {
  663. 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);
  664. }
  665. int mov_id; char mtheme[20], mrtng[3]; int cps_int; int x2; int x1; char crtng[4][3] = {"G","12","18","PG"};
  666. char cthm[12][15]=
  667. { "Action ",
  668. "Comedy ",
  669. "Drama ", "Fiction ",
  670. "Documentary ",
  671. "Horror ",
  672. "Musical ",
  673. "ScienceFiction ",
  674. "Sports ",
  675. "Suspense ",
  676. "Porn ",
  677. "Romance "
  678. };
  679. void rmv2(int i) { int y=0; y=i+4; x2=i; mvwr(y,1,cthm[x2-1]);
  680. }
  681. void hgh2(int i) { cr0(); rmv2(i); cr2(); }
  682. void s12(int i, int j)
  683. {
  684. rmv2(i); switch(j)
  685. {
  686. case 1: /* SEL NEXT */ if (x2==12) x2=1; else x2++; break; case 2: /* SEL PREV */ if (x2==1) x2=12; else x2--; break;
  687. }
  688. hgh2(x2);
  689. }
  690. void rmv1(int i,int row) { int y=0; switch(i)
  691. {
  692. case 1: y = 28; break; case 2: y = 31; break; case 3: y = 34; break; case 4: y = 37; break;
  693. }
  694. x1=i; mvwr(row,y,crtng[x1-1]);
  695. }
  696. void hghl(int i, int row) { cr0(); rmv1(i, row); cr2(); }
  697. void sl1(int i, int j, int row)
  698. {
  699. rmv1(i, row); switch (j)
  700. {
  701. case 1: /* SEL_NEXT */ if (x1==4) x1=1; else x1++; break; case 2: /* SEL_PREV */
  702. if (x1==1) x1=4; else x1--; break;
  703. }
  704. hghl(x1,row);
  705. }
  706. void getmovrtng(int row)
  707. { 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)
  708. {
  709. case KEY_RIGHT: case KEY_DOWN:
  710. sl1(x1,1,row); break; case KEY_LEFT: case KEY_UP:
  711. sl1(x1,2,row); break; case 32: case 10: l=1; break; case 27: ret_flag=2; return; default: beep(); continue;
  712. }
  713. } while (l==0); curs_set(1); keypad(stdscr,FALSE); if (x1==1) strcpy(mrtng,"G"); else strcpy(mrtng,crtng[x1-1]); cr0();
  714. }
  715. void getmovthm(int row)
  716. {
  717. 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
  718. {
  719. noecho(); ch=getch(); echo(); switch(ch)
  720. {
  721. case KEY_RIGHT:
  722. case KEY_DOWN: sl2(x2,1); break; case KEY_LEFT:
  723. case KEY_UP: sl2(x2,2); break; case 32:
  724. case 10: l=1; break; case 27: ret_flag=2; return;
  725. default: beep(); continue;
  726. }
  727. } while(l==0); curs_set(1); keypad(stdscr,FALSE); int xyz=0; while (*cthm[xyz++] != ' ') continue; *cthm[xyz]='\0'; strcpy(mtheme,cthm[x2-1]);
  728. cr0(); m(row,28); spc(15); mvwr(row,28,mtheme);
  729. }
  730. void madd()
  731. {
  732. do
  733. {
  734. scr(); mvw(3,35," ADD MOVIE(S) "); mhd();
  735. dbcmd(dbproc,"Select max(movie_id) from movies"); doit(0);
  736. if (ret_flag==2) return;
  737. dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &mov_id); dbn(); mov_id++;
  738. sprintf(buff,"%d",mov_id);
  739. m(6,28); addstr(buff); rfr(); getmov(1);
  740. if (strcmp(cps,"")==0)
  741. {
  742. strcpy(cps,"3"); mvwr(9,28,cps);
  743. mvwr(9,35," Using Default-3 Copies ");
  744. }
  745. getmovthm(10);
  746. if (ret_flag==2) return; getmovrtng(11); if (ret_flag==2) return;
  747. mvwr(13,20," Insert this record? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  748. {
  749. dbfcmd(dbproc,"insert movies values(%d,'%s','%s','%s','%s','%s')",mov_id,mtit,mcst,cps,mtheme,mrtng); doit(0);
  750. if (ret_flag==2) return;
  751. mvw(20,2," Record added. ");
  752. }
  753. else { mvw(20,2," Record not added. "); }
  754. addstr(" Add more movie records? [Y/N]: "); rfr();
  755. ch=getch();
  756. } while(ch=='Y'||ch=='y');
  757. }
  758. void showm()
  759. {
  760. 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);
  761. mvw(11,28,mrtng);
  762. }
  763. void getmovid(int p)
  764. {
  765. scr(); switch(p)
  766. {
  767. case 1:mvw(3,35," MODIFY MOVIE(S) "); break;
  768. case 2:mvw(3,35," DELETE MOVIE(S) "); break;
  769. case 3:mvw(3,25," MOVIE AVAILABILITY/VIEW MOVIE DETAILS "); break;
  770. } cr1();
  771. mvw(6,15,"MOVIE ID :");
  772. cr3(); m(6,28);
  773. spc(5); m(6,28); rfr(); getstr(midstr);
  774. 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;
  775. }
  776. void mmodf()
  777. {
  778. do { getmovid(1); if (ret_flag==2) return; scr();
  779. mvw(3,35," MODIFY MOVIE(S) "); mhd();
  780. mvw(5,40," OLD DETAILS "); mvwr(6,28,midstr); showm();
  781. mvw(12,40," ENTER NEW DETAILS "); cr1();
  782. m15(13,"MOVIE TITLE :"); m15(14,"MOVIE CAST :"); m15(15,"COPIES :"); m15(16,"THEME :"); m15(17,"MOVIE RATING :"); cr0(); me28(13); rfr(); getmov(13);
  783. if (strcmp(cps,"")==0)
  784. {
  785. strcpy(cps,"3"); mvwr(15,28,cps);
  786. mvwr(15,35," Using Default=3 Copies ");
  787. }
  788. getmovthm(16);
  789. if (ret_flag==2) return; getmovrtng(17); if (ret_flag==2) return;
  790. mvwr(19,20," Modify this record? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  791. {
  792. 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);
  793. if (ret_flag==2) return;
  794. mvw(20,2," Record modified. ");
  795. }
  796. else
  797. { mvw(20,2," Record not modified. "); } addstr(" Modify more movie records? [Y/N]: "); rfr();
  798. ch=getch();
  799. } while (ch=='Y'||ch=='y');
  800. }
  801. void mdel()
  802. {
  803. do { getmovid(2); if (ret_flag==2) return; scr();
  804. mvw(3,35," DELETE MOVIE(S) "); mhd(); mvwr(6,28,midstr); showm();
  805. mvwr(14,20," Delete this movie? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  806. {
  807. dbfcmd(dbproc,"delete movies where movie_id=%s",midstr); doit(0);
  808. if (ret_flag==2) return;
  809. mvw(20,2," Record deleted.");
  810. } else {
  811. mvw(20,2," Record not deleted. ");
  812. }
  813. addstr(" Delete more movie records? [Y/N]: "); rfr();
  814. ch=getch();
  815. } while(ch=='y'||ch=='Y');
  816. }
  817. void mfind()
  818. { scr(); strcpy(mtit,""); strcpy(mtheme,""); mvw(3,35," FIND MOVIE(S) ");
  819. 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();
  820. 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,"%");
  821. 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)
  822. return;
  823. 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();
  824. 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");
  825. cr1();
  826. int p=4;
  827. while (dbnextrow(dbproc) != NO_MORE_ROWS)
  828. {
  829. 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);
  830. p++; if (p>=17) { cr0(); m(22,2); wt(); goto ten; }
  831. } cr0();
  832. 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();
  833. } void mclist()
  834. { scr();
  835. mvw(3,35," MOVIES IN CIRCULATION AS ON "); addstr(curdate);
  836. 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);
  837. twenty:scr(); mvw(2,30," Query Results: "); int p=5; mvw(4,2,"Movie Title:");
  838. mvw(4,50,"Date Due:"); cr1();
  839. while (dbnextrow(dbproc) != NO_MORE_ROWS)
  840. {
  841. mvw(p,2,mtit); mvw(p,50,dtdue);
  842. p++; if (p>=22) goto twenty;
  843. }
  844. m(20,2); cr0(); wt();
  845. }
  846. void mavbl()
  847. {
  848. getmovid(3); if (ret_flag==2) return; scr();
  849. mvw(3,35," MOVIE AVAILABILITY/VIEW MOVIE DETAILS "); mhd(); mvwr(6,28,midstr); showm();
  850. if (cps_int==0)
  851. {
  852. mvwr(14,2," Movie not available for renting right now. Check again if you want to."); m(16,20); wt();
  853. }
  854. else
  855. {
  856. mvw(14,10," Movie available for renting. "); cr1();
  857. mvwr(16,2," Go to the add transaction screen to rent this movie? [Y/N]: ");
  858. ch=getch();
  859. if (ch=='y' || ch=='Y') rent();
  860. }
  861. } void i28(int ln)
  862. {
  863. m(ln-2,28); spc(5); m(ln,28); spc(5);
  864. m(ln+1,28); spc(5);
  865. } void ihd(int h)
  866. {
  867. 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)
  868. {
  869. case 1: mvw(11,28," RS. 50/- (can be paid while returning the disk)"); break;
  870. case 2: mvw(11,28," RS. 50/- UNPAID. COLLECT IT NOW"); break;
  871. case 3: mvw(11,28," RS. 50/- PAID ALREADY."); break;
  872. } cr0(); rfr(); } int inv_id; char invdt[20];
  873. void rent()
  874. {
  875. do
  876. {
  877. scr();
  878. mvw(3,35," RENT A LD/VCD "); ihd(1); i28(8); m(8,35); spc(40); m(9,35); spc(40);
  879. dbcmd(dbproc,"select max(inv_id) from invoices"); doit(0); if (ret_flag==2) return;
  880. 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);
  881. dbcmd(dbproc,"select convert(varchar(8),dateadd(dd,3,getdate()),3)"); doit(0); if (ret_flag==2) return;
  882. dbbind(dbproc,1,STRINGBIND,0,(CS_BYTE *) &dtdue); m(10,28); dbn();
  883. addstr(dtdue);
  884. cr0(); rfr(); inputstr(8,28,8);
  885. dbfcmd(dbproc,"select rtrim(first_name)+' '+rtrim(last_name) from customers where cust_id=%s",cidstr); doit(1);
  886. if (ret_flag==2) return;
  887. dbbind(dbproc,1,STRINGBIND,0,str); dbn(); mvwr(8,35,str); inputstr(9,28,9);
  888. dbfcmd(dbproc,"select rtrim(movie_title),copies from movies where movie_id=%s",midstr); doit(2);
  889. if (ret_flag==2) return;
  890. dbbind(dbproc,1,STRINGBIND,0,mtit); dbbind(dbproc,2,INTBIND,0,(CS_BYTE *) &cps_int); dbn(); mvw(9,35,mtit);
  891. if (cps_int==0)
  892. {
  893. mvwr(20,2," Movie not available for renting. (Stock - 0 copies)."); m(21,2); wt(); return;
  894. }
  895. mvwr(14,2," Commit this transaction? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  896. {
  897. m(14,2); clrtoeol();
  898. mvwr(14,2, " Does customer pay now? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  899. {
  900. m(14,2); clrtoeol();
  901. dbfcmd(dbproc,"insert invoices(inv_id,cust_id,movie_id,amount) values(%d,%s,%s,50)",inv_id,cidstr,midstr); doit(0);
  902. if (ret_flag==2) return; amt+=50;
  903. prntinv(1);
  904. mvwr(14,2," RS. 50/- COLLECTED. TRANSACTION ENTERED OK");
  905. } else {
  906. m(14,2); clrtoeol();
  907. dbfcmd(dbproc,"insert invoices(inv_id,cust_id,movie_id,amount) values(%d,%s,%s,0)", inv_id,cidstr,midstr); doit(0);
  908. if (ret_flag==2) return; prntinv(2);
  909. mvwr(14,2," RS. 50/- TO BE COLLECTED. TRANSACTION ENTERED OK");
  910. }
  911. } else {
  912. m(14,2); clrtoeol();
  913. mvwr(14,2," TRANSACTION CANCELLED. ");
  914. }
  915. mvwr(20,2," Add more transactions? [Y/N]: "); ch=getch();
  916. } while (ch=='y'||ch=='Y');
  917. }
  918. int irent,fine; void getinvid(); //forward void showi(); //forward void retvcd()
  919. { getinvid(); if (ret_flag==2) return;
  920. scr(); i28(8); cr0();
  921. mvw(3,35," RETURN A LD/VCD "); showi();
  922. dbfcmd(dbproc,"select 10*datediff(dd,(select date_due from invoices where inv_id=%s),getdate())",invidstr); doit(0);
  923. if (ret_flag==2) return;
  924. dbbind(dbproc,1,INTBIND,0,(CS_BYTE*) &fine); dbn(); if (fine <= 0) { fine=0; }
  925. else
  926. {
  927. sprintf(buff,"%d",fine);
  928. mvwr(15,2," FINE IS PAYABLE. FINE=RS. "); addstr(buff);
  929. }
  930. mvwr(17,2," Commit this transaction? [Y/N]: "); ch=getch(); if (ch=='y'||ch=='Y')
  931. {
  932. dbfcmd(dbproc,"update invoices set date_returned=getdate() where inv_id=%s",invidstr); doit(0);
  933. if (ret_flag==2) return; if (fine != 0)
  934. { prntinv(3); amt+=fine;
  935. dbfcmd(dbproc, "update invoices set fine=%d where inv_id=%s", fine, invidstr); doit(0);
  936. if (ret_flag==2) return;
  937. }
  938. if (irent==0)
  939. { prntinv(1); amt+=50;
  940. dbfcmd(dbproc,"update invoices set amount=50 where inv_id=%s",invidstr); doit(0);
  941. if (ret_flag==2) return;
  942. }
  943. m(17,2); clrtoeol();
  944. mvw(17,2," Transaction committed. ");
  945. }
  946. else
  947. {
  948. m(17,2);
  949. clrtoeol();
  950. mvw(17,2," Transaction not committed. ");
  951. } wt();
  952. }
  953. void showi()
  954. {
  955. 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();
  956. 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);
  957. dbfcmd(dbproc,"select rtrim(first_name) + ' ' + rtrim(last_name) from customers where cust_id=%s",cidstr); doit(0);
  958. if (ret_flag==2) return;
  959. dbbind(dbproc,1,STRINGBIND,0,str); dbn();
  960. dbfcmd(dbproc,"select rtrim(movie_title) from movies where movie_id=%s",midstr); doit(0);
  961. if (ret_flag==2) return;
  962. dbbind(dbproc,1,STRINGBIND,0,mtit); dbn(); if (irent==0)
  963. { ihd(2); } else {ihd(3);}
  964. }
  965. void getinvid()
  966. {
  967. scr();
  968. mvw(3,35," RETURN A LD/VCD "); cr1();
  969. mvw(6,15,"INVOICE ID :"); cr3(); m(6,28); spc(5); m(6,28); rfr(); getstr(invidstr);
  970. 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);
  971. if (ret_flag==2) return;
  972. }
  973. void sybquit(int); //forward void monthly()
  974. {
  975. int p=6;
  976. DBPROCESS *dbproc1; dbproc1 = dbopen(login,NULL); if (dbproc1==NULL) sybquit(3);
  977. #ifdef NIIT_CIT dbuse(dbproc1,"f4");
  978. #endif
  979. #ifdef DROME
  980. dbuse(dbproc1,"pubs2");
  981. #endif scr();
  982. dbcmd(dbproc,"select datename(mm,getdate())");
  983. doit(0); if (ret_flag==2) return; dbbind(dbproc,1,STRINGBIND,0,str); dbn();
  984. mvw(4,10," For the month of: "); addstr(str);
  985. dbcmd(dbproc,"select convert(varchar(8),datepart(yy,getdate()))"); doit(0); if (ret_flag==2) return; char yrstr[10];
  986. dbbind(dbproc,1,STRINGBIND,0,yrstr); dbn();
  987. mvw(4,40,yrstr);
  988. rfr();
  989. mvw(3,10," MONTHLY RENTAL TRANSACTIONS REPORT "); mvw(5,2,"Movie ID:"); mvw(5,14,"Movie Title:"); mvw(5,40,"Times Rented:");
  990. mvw(5,55,"Total Chges.(Inc.Fine):"); rfr();
  991. dbcmd(dbproc,"select distinct movie_id from invoices where datepart(mm,date_due)=datepart(mm,getdate()) order by 1"); doit(0);
  992. if (ret_flag==2) return; cr1();
  993. dbbind(dbproc,1,INTBIND,0,(CS_BYTE *) &mov_id); while (dbnextrow(dbproc) != NO_MORE_ROWS)
  994. {
  995. sprintf(midstr,"%d",mov_id); mvw(p,6,midstr);
  996. dbfcmd(dbproc1,"select movie_title from movies where movie_id=%s",midstr); dbsqlexec(dbproc1); dbresults(dbproc1);
  997. dbbind(dbproc1,1,STRINGBIND,0,mtit); dbnextrow(dbproc1); mvw(p,10,mtit);
  998. dbfcmd(dbproc1,"select count(movie_id) from invoices where movie_id=%s and datepart(mm,date_due) = datepart(mm,getdate())",midstr);
  999. dbsqlexec(dbproc1); dbresults(dbproc1); int count;
  1000. dbbind(dbproc1,1,INTBIND,0,(CS_BYTE *) &count); dbnextrow(dbproc1); sprintf(buff,"%d",count); mvw(p,45,buff);
  1001. 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;
  1002. dbbind(dbproc1,1,INTBIND,0,(CS_BYTE *) &tchg); dbnextrow(dbproc1); sprintf(buff,"%d",tchg); mvw(p,72,buff); p++;
  1003. }
  1004. dbcmd(dbproc1,"select sum(amount) + sum(fine) from invoices where datepart(mm,date_due)=datepart(mm,getdate())"); dbsqlexec(dbproc1);
  1005. dbresults(dbproc1);
  1006. int tot;
  1007. dbbind(dbproc1,1,INTBIND,0,(CS_BYTE *) &tot); dbnextrow(dbproc1); sprintf(buff,"%d",tot); mvw(20,72,buff);
  1008. mvw(20,2," Total for the month of: "); cr0(); mvw(20,30,str); mvw(20,40,yrstr); m(21,2); cr2(); wt(); dbclose(dbproc1);
  1009. }
  1010. void curstk()
  1011. {
  1012. dbcmd(dbproc,"select movie_id,movie_title,copies from movies"); doit(0);
  1013. if (ret_flag==2) return;
  1014. 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();
  1015. mvw(2,30," CURRENT STOCK REPORT "); int p=5; mvw(4,2,"Movie ID:"); mvw(4,20,"Movie Title:"); mvw(4,55,"Copies:");
  1016. cr1();
  1017. while(dbnextrow(dbproc) != NO_MORE_ROWS)
  1018. {
  1019. sprintf(midstr,"%d",mov_id); mvw(p,4,midstr); mvw(p,20,mtit); sprintf(cps,"%d",cps_int); mvw(p,60,cps);
  1020. p++; if (p>=15) { cr0(); m(22,2); wt(); goto newpg; }
  1021. }
  1022. cr0(); m(20,2); wt();
  1023. }
  1024. void des()
  1025. { scr();
  1026. mvw(2,30," DAILY CASH TRANSACTIONS "); mvw(3,30,"DATE:"); mvw(3,37,curdate);
  1027. mvw(5,10,"Amount collected today is Rs. "); sprintf(str,"%d",amt); mvw(5,39,str); m(20,2); wt();
  1028. }
  1029. void todayhdr()
  1030. { scr();
  1031. 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");
  1032. mvw(5,69,"FINE"); cr1();
  1033. }
  1034. void today()
  1035. {
  1036. todayhdr();
  1037. 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);
  1038. if (ret_flag==2) return;
  1039. 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;
  1040. while (dbnextrow(dbproc) != NO_MORE_ROWS)
  1041. {
  1042. sprintf(invidstr,"%d",inv_id); sprintf(cidstr,"%d",cid); sprintf(midstr,"%d",mov_id);
  1043. 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++;
  1044. if (p>=15) { m(22,2); wt(); todayhdr(); p=7; }
  1045. } cr0(); m(22,2); wt(); todayhdr(); p=7;
  1046. dbcmd(dbproc,"select
  1047. 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);
  1048. if (ret_flag==2) return;
  1049. 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);
  1050. char rentstr[20],finestr[20];
  1051. while (dbnextrow(dbproc) != NO_MORE_ROWS)
  1052. {
  1053. 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)
  1054. { m(22,2); wt(); todayhdr(); p=7; }
  1055. }
  1056. cr0(); m(22,2); wt();
  1057. }
  1058. void sybquit(int p)
  1059. {
  1060. char s[100];
  1061. switch(p)
  1062. {
  1063. case 1:strcpy(s," DB-Library initialization failed. "); break;
  1064. case 2:strcpy(s," Unable to allocate memory for LOGINREC. "); break;
  1065. case 3:strcpy(s," Connection with the Sybase SQL Server could not be established."); break;
  1066. } cr0(); mvwr(20,2,s); m(21,1); alarm(0); endwin();
  1067. exit(ERREXIT);
  1068. }
  1069. void ovrduehdr()
  1070. { scr();
  1071. 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");
  1072. mvw(5,71," OVRD BY");
  1073. rfr();
  1074. }
  1075. void overdue()
  1076. {
  1077. ovrduehdr(); dbcmd(dbproc,"select
  1078. 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);
  1079. if (ret_flag==2) return;
  1080. int dtdif; int p=7;
  1081. 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();
  1082. while (dbnextrow(dbproc) != NO_MORE_ROWS)
  1083. {
  1084. 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);
  1085. addstr(" Day(s)"); p++;
  1086. }
  1087. if (p>=22)
  1088. { cr0(); m(22,2); wt(); ovrduehdr(); p=7; } cr0(); m(22,2); wt();
  1089. }
  1090. void initsyb()
  1091. {
  1092. if (dbinit()==FAIL) sybquit(1);
  1093. if ((login=dblogin())==NULL) sybquit(2);
  1094. #ifdef NIIT_CIT
  1095. DBSETLUSER(login,"syb6");
  1096. DBSETLPWD(login,"sybase");
  1097. #endif
  1098. #ifdef DROME
  1099. DBSETLUSER(login,"syb3");
  1100. DBSETLPWD(login,"sybase3");
  1101. #endif
  1102. DBSETLAPP(login,"videolibrary v.2.0"); dbproc=dbopen(login,NULL); if (dbproc==NULL) sybquit(3);
  1103. #ifdef NIIT_CIT dbuse(dbproc,"f4"); #endif
  1104. #ifdef DROME dbuse(dbproc,"pubs2");
  1105. #endif #ifdef NIIT_CIT system("nwlogout > tmp"); system("nwlogin niit_cit/user1");
  1106. #endif
  1107. dbcmd(dbproc,"select convert(varchar(8),getdate(),3)"); doit(0);
  1108. if (ret_flag==2) sybquit(3); dbbind(dbproc,1,STRINGBIND,0,curdate); dbn();
  1109. }
  1110. void ctrlbksp()
  1111. {
  1112. signal(SIGINT,&ctrlbksp); signal(SIGQUIT,&ctrlbksp); alarm(0); scr();
  1113. mvw(15,9," You pressed Ctrl+Bksp or Ctrl+\\. You really wanna quit? [Y/N]: "); ch=getch();
  1114. if ((ch=='y')||(ch=='Y')) exitall(); else { alarm(1); mu(); }
  1115. } void timer()
  1116. { time(&t); tp=localtime(&t); ts=asctime(tp); mvwr(1,50,ts); signal(SIGALRM,&timer); alarm(1);
  1117. } int main()
  1118. { 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