createEmployee( whoCalledMe : Button ) updating;

vars	addr					: Address ;			emp	 				: Employee ;	dep : Department;
		isOKAddr			: String ;				isOKEmp	 	: String ;
		msMrsMr, sx 	: String ;				today				: Date ; 
		btn 						: Button;				libr						: PubLibrary;

begin
	libr := PubLibrary.firstInstance;
								// convert option buttons to string values
	if 	   obTitleMs.value then			msMrsMr := "Ms" ;
	elseif obTitleMrs.value then		msMrsMr := "Mrs" ;
	elseif obTitleMr.value then			msMrsMr := "Mr" ;
	else								msMrsMr := "" ;
	endif ;
											// convert more option buttons to string values
	if obSexFem.value then		sx := "F" ;		// If not Female must be Male (?)
	else												sx := "M" ;
	endif ;
	// ----------------------- start the edit ----------------------------------------
	beginTransaction;
	create addr ;								// create an empty Address object
	create emp; 								// create an empty Employee object
	isOKAddr := addr.editAddress( 
				tbAdrL1.text,					// pass in the values currently in the textboxes
				tbAdrL2.text,     
				tbAdrL3.text,
				tbPhone.text,
				tbZip.text ) ;
				
	dep	:= libr.allDepartments.getAtKey( tbEmpDept.text );			// Look up reference to dept
	if dep=null then app.msgBox( " The " & tbEmpDept.text & "department is not known" & CrLf &
																	"This is not treated as an error",
																	"Department unknown as yet",0); 	// We will not reject a null dept
	endif; 																
	isOKEmp:= emp.editEmployee(
									tbEmpNumb.text, tbJobDesc.text, null, dep, 						// boss and department  need oids, 
									libr, tbEmpPayRate.text.Decimal,											// Data for Employee
									tbEmpFamiliar.text, tbEmpFirst.text, msMrsMr, sx,		// Data for Person
									tbBirthDate.text.Date, addr, tbEmpName.text);							// Data for EconAgent

	if (isOKAddr = "" and isOKEmp = "") then						// were any errors found?
	// ----------------------- start the load ----------------------------------------
		addr.loadAddress					// No errors found: Start the load
				(tbAdrL1.text,					// load the address instance
				tbAdrL2.text,
				tbAdrL3.text,
				tbPhone.text,
				tbZip.text ) ;
		emp.loadEmployee(
									tbEmpNumb.text, tbJobDesc.text, null, dep, 					// boss and department  need oids, 
									libr, tbEmpPayRate.text.Decimal,											// Data for Employee
									tbEmpFamiliar.text, tbEmpFirst.text, msMrsMr, sx,		// Data for Person
									tbBirthDate.text.Date, addr, tbEmpName.text);					// Data for EconAgent
		commitTransaction;
				stBar.caption := "Employee '" & tbEmpNumb.text & "' && address created. "; // display success message
				app.doWindowEvents(2000);
				if whoCalledMe= bnNext then
						bnClear_click (btn);
				else
						bnClose_click (btn);
				endif;
	else
		stBar.caption := isOKAddr & isOKEmp ; // else display Error message
		abortTransaction;
	endif ;
end ;



==============================================================

createBookSeller( whoCalledMe : Button ) updating;

vars	addr				: Address ;			bSell  			: BookSeller;   sx : String;
		isOKAddr		: String ;				isOKbSell 	: String ;
		msMrsMr 		: String ;				today		 	: Date ; 	
		btn 					: Button;				libr					: PubLibrary;

begin
	libr := PubLibrary.firstInstance;
								// convert option buttons to string values
	if 	   obTitleMs.value 	then		msMrsMr := "Ms" ;
	elseif obTitleMrs.value 	then		msMrsMr := "Mrs" ;
	elseif obTitleMr.value		then		msMrsMr := "Mr" ;
	else															msMrsMr := "" ;
	endif ;
											// convert more option buttons to string values
	if obSexFem.value then		sx := "F" ;		// If not Female must be Male (?)
	else												sx := "M" ;
	endif ;
	// ----------------------- start the edit ----------------------------------------
	beginTransaction;
	create addr ;								// create an empty Address object
	create bSell ; 							// create an empty BookSeller object
	isOKAddr := addr.editAddress( 
				tbAdrL1.text,					// pass in the values currently in the textboxes
				tbAdrL2.text,     
				tbAdrL3.text,
				tbPhone.text,
				tbZip.text ) ;

	isOKbSell := bSell.editBookSeller(
									libr, tbContact.text, tbPosition.text,														// Data for BookSeller
									msMrsMr, sx,																				 					// Data for Person
									today, addr, tbBookSellerName.text);													// Data for EconAgent

	if (isOKAddr = "" and isOKbSell= "") then						// were any errors found?
	// ----------------------- start the load ----------------------------------------
		addr.loadAddress					// No errors found: Start the load
				(tbAdrL1.text,					// load the address instance
				tbAdrL2.text,
				tbAdrL3.text,
				tbPhone.text,
				tbZip.text ) ;
		bSell.loadBookSeller(
									libr, tbContact.text, tbPosition.text,														// Data for BookSeller
									msMrsMr, sx,																				 					// Data for Person
									today, addr, tbBookSellerName.text);												// Data for EconAgent
		commitTransaction;
				stBar.caption := "BookSeller '" & tbBookSellerName.text & "' && address created. "; // display success message
				app.doWindowEvents(2000);
				if whoCalledMe= bnNext then
						bnClear_click (btn);
				else
						bnClose_click (btn);
				endif;
	else
		stBar.caption := isOKAddr & isOKbSell; // else display Error message
		abortTransaction;
	endif ;
end ;


=============================================