Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need some Help! on Record please.. Posted by plaync on 28 Oct 2009 at 5:55 AM
Hello! I need some help on my program... I am making a program which is about a certain shop, with 3 records which is : Stock records, Employee records, and Customer records. I have already made procedures on each of this records which is, add, view, list, delete, search, sort, modify, backup, and restore. Each record in 3 menu's "Stocks, Employee, and Customer.."

My problem is that... my teacher ask me to make my program do some real programing like computing and stuff or external sort i think it was he said.. But I choose to add another program which is called receipt

where I add new procedure called receipt. where the user will ask for the customer's ID, then its name will display on the screen.
(Using seek and read from customerfile.) after that the user will ask which item number of the stockfile the customer pick(again using seek and read from stockfile) then the info of the stock item will be displayed on the screen (from stock records) along with the name of the customer(from the customer record). It will then ask how many? then multiply the total and receive the payment and calculate the change... <-- which is a new var in this procedure.

Now what I want is after making another menu for this procedure, called receipt. I want to copy all the information above to this new record/a 4th record where it will store the info on which customer, what items he bought and how many he bought, total and change..
so that in the sub menu I could use the procedure which displays the customers recent transaction. But I dont know how to copy a certain file on the 2 record files which is stock and customer in order to save it to the new record called receipt.




---------------------------------------------------------------------
procedure buy;

var which_customer_num: integer;
which_stock_num: integer;
howmany: integer;
proceed: char;
payment: real;
change:real;
fs: integer;
total:integer;
line:integer;


begin
line:=14;
fs:=filesize(cachefile);
cache.number:=fs+1;
clrscr;
cache.total:=cache.total;
banner;
title('Cache Menu');
gotoxy(1,9);
write('Customer number #: ');
readln(which_customer_num);

seek(customerfile,0);

while not eof(customerfile) do

begin
read(customerfile,customer);
if (customer.status='A') AND (which_customer_num=customer.customnumber) then
begin
writeln('CUSTOMER NAME: ',customer.forename,' ',customer.surname);
begin
which_stock_num:=-1;
while which_stock_num <>0 do
begin
write('Item number : ');
readln(which_stock_num);
gotoxy(1,13);write('ITEM NO.');
gotoxy(11,13);write('GUITAR BRAND');
gotoxy(25,13);write('STOCK TYPE ');
gotoxy(38,13);write('PRICE');
gotoxy(47,13);write('STATUS ');
gotoxy(57,13);write('NO.OF.ITEMS ');
gotoxy(72,13);write('TOTAL ');
seek(stockfile,0);
while not eof(stockfile) do
begin
read(stockfile,stock);
if (stock.status='I') AND (which_stock_num=stock.stocknumber) then
begin
gotoxy(1,line);
writeln(stock.stocknumber);
gotoxy(11,line);
writeln(stock.description);
gotoxy(25,line);
writeln(stock.stocktype);
gotoxy(38,line);
writeln('œ',stock.sellprice:0:0);
gotoxy(47,line);
writeln(stock.status);
gotoxy(57,line);
write('x');
read(howmany);
cache.total:=cache.total+stock.sellprice*howmany;
gotoxy(72,line);
writeln('œ',cache.total:0:0);
end;
end;
end;
end;
end;
end;
writeln('Please input the total amount.');
readln(payment);
cache.total:=payment-cache.total;
writeln('Change: ',cache.total:0:2);
writeln('Purchase successful. Tnx');
cache.status:='A';
seek(cachefile,cache.number-1);
write(cachefile,cache);
repeat until keypressed;
end;
---------------------------------------------------------------------

this is the procedure I made so far for the receipt.. please need help on how to copy a certain files from 2 record to a new record file so I can view the customers recent transaction and stuff like this.. need it few days from now so i can study and understand it further more... T,T HOPE anyone could help me with this
Report
Re: Need some Help! on Record please.. Posted by Atex on 28 Oct 2009 at 11:00 PM
I would create a subrecord for each costumer for the purchases and just save it back to the costumer file ( seek backward 1 record length (bytes)). Then each time the costumer data is read the purchase record is retrieved instantly...
Here you can find a well written database program: http://www.programmersheaven.com/mb/pasprog/384937/384937/dos-pascal-dat-service-request/?S=B20000#384937
Report
Re: Need some Help! on Record please.. Posted by plaync on 3 Nov 2009 at 3:17 PM
I'm sorry about the late reply Atex... I've tried understanding the link you gave me but nothing goes through my mind... Im still new to pascal programming and still learning.
I was some what posting all this help to other pascal programing site forums assking for help but still got nothing.
I didnt notice I could attach files here... would you mind checking my program, Im sorta still in the basic its about making some sort of recciept from a guitar shop... and still a lil confused on using records... or maybe could you help me fix the problem please... I just dontk now how to copy a file from the customerrecord e.g.(customer name), and another files from stockrecord e.g.(item no., brand, sell price, status, no. of items) to another new reccord of some sort.
So that I could use the 2nd procedure (Display recent Transaction)
--->> where it will display (customers name), (information of the stock the customer bought, total, and change.)
So far this is what I got...

Hope you could fix the problem.. T,T

Report
Re: Need some Help! on Record please.. Posted by Atex on 4 Nov 2009 at 9:19 PM
Time permitting will go through your code and see what can I come up with...

Report
Re: Need some Help! on Record please.. Posted by plaync on 6 Nov 2009 at 6:57 PM
Yes please, I'd really appreciate it. =>
Report
Re: Need some Help! on Record please.. Posted by Atex on 13 Nov 2009 at 8:57 PM
You could try:
type transaction_record=record
                         field_a:customerrec;
                         field_b:stockrec;
                        end;

var transaction_record_file:file of transaction_record;




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.