home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / DATABASE / DPG.ZIP / VRENT.C < prev    next >
C/C++ Source or Header  |  1992-05-12  |  11KB  |  521 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <fcntl.h>
  5. #include    <io.h>
  6. #include    "video.h"
  7. #include    "files.h"
  8.  
  9. short fieldno;
  10.  
  11. typedef struct
  12. {
  13.     long next;
  14.     long prev;
  15.     
  16.     long customerptr;
  17.     long customernext;
  18.     long customerprev;
  19.     
  20.     char type[1];
  21.     unsigned short transaction_date;
  22.     char title[20];
  23. } transaction;
  24.  
  25. transaction blanktransaction =
  26. {
  27.     -1,
  28.     -1,
  29.     
  30.     -1,
  31.     -1,
  32.     -1,
  33.     
  34.     ' ',
  35.     BLANKDATE,
  36.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  37. };
  38.  
  39. transaction transaction;
  40. int transactionfile;
  41. long transactionptr;
  42.  
  43. #define    transactionmiscoff    0
  44.  
  45. typedef struct
  46. {
  47.     long next;
  48.     long prev;
  49.     
  50.     char account_name[20];
  51.     
  52.     long transactionfirst;
  53.     long transactionlast;
  54.     
  55.     char address_3[20];
  56.     char address_2[20];
  57.     char address_1[20];
  58.     char full_name[20];
  59. } customer;
  60.  
  61. customer blankcustomer =
  62. {
  63.     -1,
  64.     -1,
  65.     
  66.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  67.     
  68.     -1,
  69.     -1,
  70.     
  71.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  72.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  73.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  74.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  75. };
  76.  
  77. customer customer;
  78. int customerfile;
  79. long customerptr;
  80. int customerindexfile;
  81.  
  82. #define    customermiscoff    12
  83.  
  84. typedef struct
  85. {
  86.     long next;
  87.     long prev;
  88.     
  89.     char title[20];
  90.     
  91.     unsigned short release_date;
  92.     double rent;
  93.     signed char in_stock;
  94.     signed char copies;
  95.     char category[20];
  96. } video;
  97.  
  98. video blankvideo =
  99. {
  100.     -1,
  101.     -1,
  102.     
  103.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  104.     
  105.     BLANKDATE,
  106.     0,
  107.     0,
  108.     0,
  109.     ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
  110. };
  111.  
  112. video video;
  113. int videofile;
  114. long videoptr;
  115. int videoindexfile;
  116.  
  117. #define    videomiscoff    28
  118.  
  119. void wait (void)
  120. {
  121.     printstr (30,20,"Press any key to continue",25);
  122.     cursor (56,20);
  123.     getkey ();
  124. }
  125.  
  126. void show_video (void)
  127. {
  128.     printstr (10,6,"Category",8);
  129.     printstr (10,7,"Copies",6);
  130.     printstr (10,8,"Copies in Stock",15);
  131.     printstr (10,9,"Rental Charge",13);
  132.     printstr (10,10,"Release Date",12);
  133.     printstr (30,5,video.title,20);
  134.     printstr (30,6,video.category,20);
  135.     printint (30,7,video.copies,2);
  136.     printint (30,8,video.in_stock,2);
  137.     printfloat (30,9,video.rent,2,2);
  138.     printdate (30,10,video.release_date);
  139. }
  140.  
  141. void alter_video (void)
  142. {
  143.     show_video ();
  144.  
  145. CATEGORY:
  146.     editstr (video.category,20,30,6,DF_RETURN | DF_ESC | DF_DOWN);
  147.     switch (dir)
  148.     {
  149.         case DIR_ESC:
  150.             goto END;
  151.     }
  152.  
  153. COPIES:
  154.     editbyte (&video.copies,2,30,7,DF_RETURN | DF_ESC | DF_UP | DF_DOWN);
  155.     switch (dir)
  156.     {
  157.         case DIR_ESC:
  158.             goto END;
  159.         case DIR_UP:
  160.             goto CATEGORY;
  161.     }
  162.  
  163. IN_STOCK:
  164.     editbyte (&video.in_stock,2,30,8,DF_RETURN | DF_ESC | DF_UP | DF_DOWN);
  165.     switch (dir)
  166.     {
  167.         case DIR_ESC:
  168.             goto END;
  169.         case DIR_UP:
  170.             goto COPIES;
  171.     }
  172.  
  173. RENT:
  174.     editfloat (&video.rent,2,2,30,9,DF_RETURN | DF_ESC | DF_UP | DF_DOWN);
  175.     switch (dir)
  176.     {
  177.         case DIR_ESC:
  178.             goto END;
  179.         case DIR_UP:
  180.             goto IN_STOCK;
  181.     }
  182.  
  183. RELEASE_DATE:
  184.     editdate (&video.release_date,30,10,DF_RETURN | DF_ESC | DF_UP);
  185.     switch (dir)
  186.     {
  187.         case DIR_UP:
  188.             goto RENT;
  189.     }
  190.  
  191. END:
  192.     Write (videofile,videoptr,&video,sizeof video);
  193. }
  194.  
  195. void add_video (void)
  196. {
  197.     printstr (10,5,"Title",5);
  198.     video = blankvideo;
  199.     createindex (videofile,&videoptr,&video,sizeof video,videomiscoff,video.title,20,videoindexfile,30,5,DF_RETURN | DF_ESC);
  200.     switch (dir)
  201.     {
  202.         case DIR_ESC:
  203.             goto CANCEL;
  204.     }
  205.     alter_video ();
  206.     return;
  207.  
  208. CANCEL:
  209.     deleteindex (videofile,videoptr,&video,videomiscoff,video.title,20,videoindexfile);
  210. }
  211.  
  212. void edit_video (void)
  213. {
  214.     printstr (10,5,"Title",5);
  215.     select (videofile,videoindexfile,&videoptr,&video,sizeof video,video.title,20,30,5,DF_RETURN | DF_ESC);
  216.     switch (dir)
  217.     {
  218.         case DIR_ESC:
  219.             goto CANCEL;
  220.     }
  221.     alter_video ();
  222.  
  223. CANCEL:;
  224. }
  225.  
  226. void display_video (void)
  227. {
  228.     printstr (10,5,"Title",5);
  229.     select (videofile,videoindexfile,&videoptr,&video,sizeof video,video.title,20,30,5,DF_RETURN | DF_ESC);
  230.     switch (dir)
  231.     {
  232.         case DIR_ESC:
  233.             goto CANCEL;
  234.     }
  235.     show_video ();
  236.     wait ();
  237.  
  238. CANCEL:;
  239. }
  240.  
  241. void remove_video (void)
  242. {
  243.     char sure[1];
  244.     
  245.     printstr (10,5,"Title",5);
  246.     select (videofile,videoindexfile,&videoptr,&video,sizeof video,video.title,20,30,5,DF_RETURN | DF_ESC);
  247.     switch (dir)
  248.     {
  249.         case DIR_ESC:
  250.             goto CANCEL;
  251.     }
  252.     show_video ();
  253.     printstr (30,20,"Are you sure? (Y/N) ",20);
  254.     cursor (50,20);
  255.     sure[0] = getkey ();
  256.     if (!memicmp (sure,"Y",1))
  257.         deleteindex (videofile,videoptr,&video,videomiscoff,video.title,20,videoindexfile);
  258.  
  259. CANCEL:;
  260. }
  261.  
  262. void show_customer (void)
  263. {
  264.     printstr (10,6,"Full Name",9);
  265.     printstr (10,7,"Address",7);
  266.     printstr (30,5,customer.account_name,20);
  267.     printstr (30,6,customer.full_name,20);
  268.     printstr (30,7,customer.address_1,20);
  269.     printstr (30,8,customer.address_2,20);
  270.     printstr (30,9,customer.address_3,20);
  271. }
  272.  
  273. void alter_customer (void)
  274. {
  275.     show_customer ();
  276.  
  277. FULL_NAME:
  278.     editstr (customer.full_name,20,30,6,DF_RETURN | DF_ESC | DF_DOWN);
  279.     switch (dir)
  280.     {
  281.         case DIR_ESC:
  282.             goto END;
  283.     }
  284.  
  285. ADDRESS_1:
  286.     editstr (customer.address_1,20,30,7,DF_RETURN | DF_ESC | DF_UP | DF_DOWN);
  287.     switch (dir)
  288.     {
  289.         case DIR_ESC:
  290.             goto END;
  291.         case DIR_UP:
  292.             goto FULL_NAME;
  293.     }
  294.  
  295. ADDRESS_2:
  296.     editstr (customer.address_2,20,30,8,DF_RETURN | DF_ESC | DF_UP | DF_DOWN);
  297.     switch (dir)
  298.     {
  299.         case DIR_ESC:
  300.             goto END;
  301.         case DIR_UP:
  302.             goto ADDRESS_1;
  303.     }
  304.  
  305. ADDRESS_3:
  306.     editstr (customer.address_3,20,30,9,DF_RETURN | DF_ESC | DF_UP);
  307.     switch (dir)
  308.     {
  309.         case DIR_UP:
  310.             goto ADDRESS_2;
  311.     }
  312.  
  313. END:
  314.     Write (customerfile,customerptr,&customer,sizeof customer);
  315. }
  316.  
  317. void add_customer (void)
  318. {
  319.     printstr (10,5,"Account Name",12);
  320.     customer = blankcustomer;
  321.     createindex (customerfile,&customerptr,&customer,sizeof customer,customermiscoff,customer.account_name,20,customerindexfile,30,5,DF_RETURN | DF_ESC);
  322.     switch (dir)
  323.     {
  324.         case DIR_ESC:
  325.             goto CANCEL;
  326.     }
  327.     alter_customer ();
  328.     return;
  329.  
  330. CANCEL:
  331.     deleteindex (customerfile,customerptr,&customer,customermiscoff,customer.account_name,20,customerindexfile);
  332. }
  333.  
  334. void edit_customer (void)
  335. {
  336.     printstr (10,5,"Account Name",12);
  337.     select (customerfile,customerindexfile,&customerptr,&customer,sizeof customer,customer.account_name,20,30,5,DF_RETURN | DF_ESC);
  338.     switch (dir)
  339.     {
  340.         case DIR_ESC:
  341.             goto CANCEL;
  342.     }
  343.     alter_customer ();
  344.  
  345. CANCEL:;
  346. }
  347.  
  348. void display_customer (void)
  349. {
  350.     printstr (10,5,"Account Name",12);
  351.     select (customerfile,customerindexfile,&customerptr,&customer,sizeof customer,customer.account_name,20,30,5,DF_RETURN | DF_ESC);
  352.     switch (dir)
  353.     {
  354.         case DIR_ESC:
  355.             goto CANCEL;
  356.     }
  357.     show_customer ();
  358.     wait ();
  359.  
  360. CANCEL:;
  361. }
  362.  
  363. void remove_customer (void)
  364. {
  365.     char sure[1];
  366.     
  367.     printstr (10,5,"Account Name",12);
  368.     select (customerfile,customerindexfile,&customerptr,&customer,sizeof customer,customer.account_name,20,30,5,DF_RETURN | DF_ESC);
  369.     switch (dir)
  370.     {
  371.         case DIR_ESC:
  372.             goto CANCEL;
  373.     }
  374.     show_customer ();
  375.     printstr (30,20,"Are you sure? (Y/N) ",20);
  376.     cursor (50,20);
  377.     sure[0] = getkey ();
  378.     if (!memicmp (sure,"Y",1))
  379.         deleteindex (customerfile,customerptr,&customer,customermiscoff,customer.account_name,20,customerindexfile);
  380.  
  381. CANCEL:;
  382. }
  383.  
  384. void enter_transactions_show (void)
  385. {
  386.     printstr (0,(-1),transaction.title,20);
  387.     printdate (30,(-1),transaction.transaction_date);
  388.     printstr (50,(-1),transaction.type,1);
  389. }
  390.  
  391. void enter_transactions_edit (void)
  392. {
  393.     switch (fieldno)
  394.     {
  395.         case 0:
  396.             goto TITLE;
  397.         case 1:
  398.             goto LOAN_DATE;
  399.         case 2:
  400.             goto TYPE;
  401.     }
  402.  
  403. TITLE:
  404.     editstr (transaction.title,20,0,(-1),DF_RETURN | DF_ESC | DF_UP | DF_DOWN | DF_RIGHT | DF_PGUP | DF_PGDN | DF_HOME | DF_END | DF_INS | DF_DEL);
  405.     switch (dir)
  406.     {
  407.     }
  408.     return;
  409.  
  410. LOAN_DATE:
  411.     editdate (&transaction.transaction_date,30,(-1),DF_RETURN | DF_ESC | DF_UP | DF_DOWN | DF_LEFT | DF_RIGHT | DF_PGUP | DF_PGDN | DF_HOME | DF_END | DF_INS | DF_DEL);
  412.     switch (dir)
  413.     {
  414.     }
  415.     return;
  416.  
  417. TYPE:
  418.     editstr (transaction.type,1,50,(-1),DF_RETURN | DF_ESC | DF_UP | DF_DOWN | DF_LEFT | DF_PGUP | DF_PGDN | DF_HOME | DF_END | DF_INS | DF_DEL);
  419.     switch (dir)
  420.     {
  421.     }
  422.     return;
  423. }
  424.  
  425. void enter_transactions (void)
  426. {
  427.     printstr (10,5,"Account Name",12);
  428.     select (customerfile,customerindexfile,&customerptr,&customer,sizeof customer,customer.account_name,20,30,5,DF_RETURN | DF_ESC);
  429.     switch (dir)
  430.     {
  431.         case DIR_ESC:
  432.             goto CANCEL;
  433.     }
  434.     show_customer ();
  435.     printstr (0,11,"Film Title",10);
  436.     printstr (30,11,"Transaction Date",16);
  437.     printstr (50,11,"Type (L/R)",10);
  438.     scrolledit (transactionfile,&transactionptr,&transaction,foffset (transaction,customerptr),sizeof transaction,customerfile,customerptr,&customer,foffset (customer,transactionfirst),sizeof customer,&blanktransaction,transactionmiscoff,3,enter_transactions_show,enter_transactions_edit,0,13,80,12);
  439.  
  440. CANCEL:;
  441. }
  442.  
  443. void display_transactions (void)
  444. {
  445.     printstr (10,5,"Account Name",12);
  446.     select (customerfile,customerindexfile,&customerptr,&customer,sizeof customer,customer.account_name,20,30,5,DF_RETURN | DF_ESC);
  447.     switch (dir)
  448.     {
  449.         case DIR_ESC:
  450.             goto CANCEL;
  451.     }
  452.     show_customer ();
  453.     printstr (0,11,"Film Title",10);
  454.     printstr (30,11,"Transaction Date",16);
  455.     printstr (50,11,"Type (L/R)",10);
  456.     scrolledit (transactionfile,&transactionptr,&transaction,foffset (transaction,customerptr),sizeof transaction,customerfile,customerptr,&customer,foffset (customer,transactionfirst),sizeof customer,&blanktransaction,transactionmiscoff,3,enter_transactions_show,0,0,13,80,12);
  457.  
  458. CANCEL:;
  459. }
  460.  
  461. execmenuitem menu00[] =
  462. {
  463.     "Add a Video",0,add_video,
  464.     "Edit a Video",0,edit_video,
  465.     "Display a Video",0,display_video,
  466.     "Remove a Video",0,remove_video,
  467.     0
  468. };
  469.  
  470. execmenuitem menu01[] =
  471. {
  472.     "Add a Customer",0,add_customer,
  473.     "Edit a Customer",0,edit_customer,
  474.     "Display a Customer",0,display_customer,
  475.     "Remove a Customer",0,remove_customer,
  476.     0
  477. };
  478.  
  479. execmenuitem menu02[] =
  480. {
  481.     "Enter Transactions",0,enter_transactions,
  482.     "Display Transactions",0,display_transactions,
  483.     0
  484. };
  485.  
  486. execmenuitem menu[] =
  487. {
  488.     "Videos",menu00,0,
  489.     "Customers",menu01,0,
  490.     "Transactions",menu02,0,
  491.     0
  492. };
  493.  
  494. main (void)
  495. {
  496.     long r;
  497.     
  498.     transactionfile = opencreate ("transaction.dat");
  499.     customerfile = opencreate ("customer.dat");
  500.     customerindexfile = opencreate ("customer.idx");
  501.     videofile = opencreate ("video.dat");
  502.     videoindexfile = opencreate ("video.idx");
  503.     
  504.     miscfile = open ("misc.dat",O_RDWR);
  505.     if (miscfile < 0)
  506.     {
  507.         miscfile = open ("misc.dat",O_CREAT | O_TRUNC | O_RDWR,0777);
  508.         if (miscfile < 0)
  509.         {
  510.             printf ("Can't create file misc.dat\n");
  511.             return 1;
  512.         }
  513.         mblank3 ();
  514.         mblank4 ();
  515.         mblank4 ();
  516.     }
  517.     
  518.     initvideo ();
  519.     execmenu (menu,-1,-1,0,0);
  520.     return 0;
  521. }