home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l216 / 2.ddi / XREPORT.PRO < prev    next >
Encoding:
Text File  |  1987-03-23  |  4.0 KB  |  149 lines

  1. /****************************************************************
  2.  
  3.      Turbo Prolog Toolbox
  4.      (C) Copyright 1987 Borland International.
  5.  
  6.         Demo of report generation
  7.  
  8.  The report generator makes it possible to design a page layout
  9.  as if it were to be a screen layout, and then print that page.
  10. ****************************************************************/
  11.  
  12. include "tdoms.pro"
  13.  
  14. DOMAINS
  15.   FNAME=SYMBOL
  16.   TYPE = int(); str(); real()
  17.   FIELD = field(STRING,COL)
  18.   FIELDLIST = FIELD*
  19.  
  20. DATABASE
  21.   /* Database declarations used in scrhnd */
  22.   insmode            /* Global insertmode */
  23.   actfield(FNAME)        /* Actual field */
  24.   screen(SYMBOL,DBASEDOM)    /* Saving different screens */
  25.   value(FNAME,STRING)        /* value of a field */
  26.   field(FNAME,TYPE,ROW,COL,LEN) /* Screen definition */
  27.   txtfield(ROW,COL,LEN,STRING)
  28.   windowsize(ROW,COL).
  29.   notopline
  30.  
  31.   /* Database declarations used in scrhnd */
  32.   windstart(ROW,COL)
  33.   mycursord(ROW,COL)
  34.  
  35.   /* Database declarations used in lineinp */
  36.   lineinpstate(STRING,COL)
  37.  
  38.   /* SPECIFIC FOR THIS APPLICATION */
  39.   payment(STRING)
  40.   delivery
  41.   warranty
  42.  
  43. include "tpreds.pro"
  44. include "report.pro"
  45.  
  46. GOAL
  47.     consult("xreport.scr"),
  48.     makewindow(1,31,0,"",0,0,25,80),
  49.     /* writedevice(printer), */
  50.     report(20).
  51.  
  52. PREDICATES
  53.   nondeterm product(STRING,STRING,REAL)
  54.  
  55. CLAUSES
  56.   product("1111","Washing Machine",200.35).
  57.   product("2222","Dishwasher",239.67).
  58.   product("3333","Fridge and Freezer",456.78).  
  59.   product("4444","Radio",456.78).  
  60.   product("5555","Television",456.78).  
  61.  
  62. PREDICATES
  63.   index(INTEGER,STRINGLIST,STRING)
  64.   concatlist(STRINGLIST,STRING)
  65.  
  66. CLAUSES
  67.   index(1,[H|_],H):-!.
  68.   index(N,[_|T],X):-N>1,N1=N-1,index(N1,T,X).
  69.  
  70.   concatlist([],"").
  71.   concatlist([H|T],S):-
  72.     concatlist(T,S1),concat(H,S1,S).
  73.  
  74. CLAUSES
  75. /*******************************************************************
  76.              Field_value
  77. *******************************************************************/
  78.  
  79. PREDICATES
  80.   price(FNAME,REAL)
  81.  
  82. CLAUSES
  83.   price(FNAME,PRICE):-
  84.     value(FNAME,CODE),product(CODE,_,PRICE),!.
  85.   price(_,0).
  86.  
  87.   field_value(time,TIME):-!,
  88.     time(H,M,S,_),
  89.     str_int(HS,H),str_int(MS,M),str_int(SS,S),
  90.     concatlist([HS,":",MS,":",SS],TIME).
  91.  
  92.   field_value(date,DATE):-!,
  93.          date(Y,M,D),
  94.          str_int(DS,D),str_int(MS,M),str_int(YS,Y),
  95.          concatlist([MS,"/",DS,"/",YS],DATE).
  96.  
  97.   field_value(total,TotalS):-!,
  98.         price(item1,P1),
  99.         price(item2,P2),
  100.         price(item3,P3),
  101.         Total=P1+P2+P3,
  102.         str_real(TotalS,Total).
  103.  
  104.   field_value(change,CS):-!,
  105.     value(money,MM),!,str_real(MM,M),
  106.         price(item1,P1),
  107.         price(item2,P2),
  108.         price(item3,P3),
  109.         Total=M-(P1+P2+P3),
  110.         str_real(CS,Total).
  111.  
  112.   field_value(item1,CODE):-!,value(item1,CODE),!.
  113.   field_value(item2,CODE):-!,value(item2,CODE),!.
  114.   field_value(item3,CODE):-!,value(item3,CODE),!.
  115.  
  116.   field_value(make1,DESC):-!,value(item1,Code),product(Code,Desc,_),!.
  117.   field_value(make2,DESC):-!,value(item2,Code),product(Code,Desc,_),!.
  118.   field_value(make3,DESC):-!,value(item3,Code),product(Code,Desc,_),!.
  119.  
  120.   field_value(price1,PRICEs):-!,
  121.     value(item1,Code),product(Code,_,PRICE),!,str_real(PRICEs,PRICE).
  122.   field_value(price2,PRICEs):-!,
  123.     value(item2,Code),product(Code,_,PRICE),!,str_real(PRICEs,PRICE).
  124.   field_value(price3,PRICEs):-!,
  125.     value(item3,Code),product(Code,_,PRICE),!,str_real(PRICEs,PRICE).
  126.  
  127.   field_value(payment,P):- payment(P),!.
  128.  
  129.   field_value(delivery,yes):-delivery,!.
  130.   field_value(delivery,no):-!.
  131.  
  132.   field_value(warranty,yes):-warranty,!. 
  133.   field_value(warranty,no):-!. 
  134.  
  135.   /* Catch other values from the database */
  136.   field_value(Fn,X):-value(Fn,X),!.
  137.  
  138.   value("name","J B Gruntfuttock").
  139.   value("street","3 Railway Terrace").
  140.   value("city","Seattle").
  141.   value("state","Washington").
  142.   value("tel","222 333 4444").
  143.   value("item1","1111").
  144.   value("item2","2222").
  145.   value("item3","3333").
  146.   value("money","1000.00").
  147.   payment("Check").
  148.   delivery.
  149.