loadBooksOffFile( ) updating ;					// a method of UC_LoadInBulk::loadBooksOffFile

vars	
	fileOpener			: CMDFileOpen ;				// A 'Windows Common Dialog' object
	fil							: File ;									// A file object
	st, st2					: String ;								// Strings to hold 'records'		
	book						: Book ;		
	bweh  					: BookWeHold ;
	isOKBuk, scrap: String ;
	errCount, indx	: Integer ;
	libr							: PubLibrary ;
	
	auth, bClas, editn, isNumb, titl, acc,  ord, bSellStr : String;
	costA, costE		: Decimal[9,2];
	datE, datO 		: Date;
	bSellr 					: BookSeller;
	
begin
	libr := PubLibrary.firstInstance ;
	errCount	:= 0 ;
					// (a) Open the file ==============================
	create fileOpener ;								// Create an Open File dialog for the user
																			// Set a filter to display only the libB*.txt files
	fileOpener.filter := "Book for library | LibB*.txt" ;
	if fileOpener.open = 0 then				// A zero returned means user clicked OK
		create fil ;												// So create an object to represent the file
		fil.fileName := fileOpener.fileName ;	// called fileName
		fil.open ;													// And open it (using a file's own open method)

					// (b) Loop through the file ==========================
		while not fil.endOfFile do				// Until the file ends do ...
			st	:= fil.readLine ;						// Read line #1 of the Book-data pair
			st2 := fil.readLine ;						// Read line #2 (not used yet)

					// (c) Pick the facts (tokens) out of the record using nam :=  st1.scanUntil("|", indx) 
					// Pick them out in the order below-the order they have within each record
			indx :=1;
			scrap		:=	st.scanUntil( '%', indx); 					indx := indx +1;		// find start
			acc			:=	st.scanUntil( '%', indx); 					indx := indx +1;		// accessionNo
			costA		:=	st.scanUntil( '%', indx).Decimal; indx := indx +1;		// costActual
			costE		:=	st.scanUntil( '%', indx).Decimal; indx := indx +1;		// costExpected
			datE			:=	st.scanUntil( '%', indx).Date; 		indx := indx +1;		// dateExpected
			datO			:=	null;																									// dateOrdered
			ord				:=	st.scanUntil( '%', indx); 					indx := indx +1;		// ourOrderNo
			auth 			:=   st.scanUntil( '%', indx); 					indx := indx +1;		// author
			bClas		:=	st.scanUntil( '%', indx); 					indx := indx +1;		// bookclass
			editn			:=	st.scanUntil( '%', indx); 					indx := indx +1;		// editnData
			isNumb	:=	st.scanUntil( '%', indx); 					indx := indx +1;		// isbn
			bSellStr	:= 	st.scanUntil( '%', indx); 					indx := indx +1;		// BookSeller's name as string 
			bSellr		:= 	libr.allBookSellers.getAtKey(bSellStr); 							// look up BookSeller oid
			titl		 		:=	st.scanUntil( '%', indx); 					indx := indx +1;		// title 
			//			
			beginTransaction;
			create book;													// create Book object
			create bweh; 												// create BookWeHold object
			isOKBuk := book.editBook(					// Call on Book's edit method.
							auth, bClas, editn, isNumb, bSellr, bweh,  null, titl);
			isOKBuk := isOKBuk & bweh.editBookWeHold( // Call on BookWeHold's edit.
																			acc, datE, datO, false, book, null, libr, 0);

									
										// To suppress the running report, comment out this msgBox 
				app.msgBox (	acc & CrLf & costA.String & ",  " & costE.String & CrLf & datE.String & CrLf &ord & CrLf & auth & 
												CrLf &  bClas & CrLf & editn & CrLf & isNumb & CrLf & bSellStr & CrLf & titl,	
												"Another book" , 0) ;	
			

			if ( isOKBuk = "" ) then	// no edit error?
										//  then feed the same data to the .load
										//  methods and create the objects
				book.loadBook (auth, bClas, editn, isNumb, bSellr, bweh,  null, titl);
				bweh.loadBookWeHold (acc, datE, datO, false, book, null, libr, 0);
				commitTransaction ;
			else
				abortTransaction ;
			endif ;
			// Keep a running count of faulty records
			if isOKBuk<>null then errCount := errCount +1; endif;
			
		endwhile ;												//  Loop until the file ends

					// ( c ) When the file ends, close it and  ===================
		fil.close;
		delete fil ;												// We don't need the file object, fil, any more
	endif ;
	delete fileOpener ;								// Nor the fileOpener object
	if errCount>0 then 								// Final report 
		app.msgBox ( errCount.String & " book records were faulty", 
										"Some books failed", 0 ) ;
	endif ;
end ;
========================================

