/* Class		SchedLoads.cc 
	Purpose:	the Contax Scheduler uses a temporary table (SchedTemp.dbf) to manage
   			display of calendars on the startup page of Scheduler.wfm

            The methods of SchedLoads.cc update the temporary table when 
            appointments are added or deleted or edited.

	Methods:	LoadSched() ///// loads temp file for column 1, 2, or 3. Loads
   			everything for one day and employee

   Note:		You may have to refresh controls onscreen after doing this update
   			That may depend on NotifyControls and other properties.
            You'll probably have to experiment to get it right.

   Version:	1.0 01/30.2000

   Author	A. A. Katz, dBASE Inc. All rights reserved

*/



class SchedLoad

   ////////// Method: :LoadTempFile /////////////////////////////////////////
   ////////// Params:	cEmployeeName - employee whose appts to load
   //////////				dDate - date for appts to be loaded
   //////////				nColumn - which of the three display columns to 
   //////////				update. /////////////////////////////////////////////

   function loadTempFile(cEmployeeName,dDate,nColumn)

      private d,qS,qA,n

      ///// Pad employee name out to 24 spaces
      cEmployeeName = substr(cEmployeeName+space(24),1,24)

      ///// Create database object
      d  = new dataBase()
      with (d)
         databaseName = 'dBASECONTAX'
         active =true
      endwith

      ////// Create Query for Scheduler
      qS = new query()
      with (qS)
         database = d
         sql = 'Select * from "SchedTemp.dbf"'
         active = true
         notifyControls = false
      endwith

      ////// Create Query for appointments
      qA = new query()
      with (qA)
         database = d
         sql = 'Select * from "Appoints.dbf"'
         active = true
         rowset.indexName = 'DateSlotEmployee'
         rowset.notifyControls = false
      endWith

      private n

      


      ////// Update all time slots in SchedTemp.dbf through
      ////// lookups into appoints.dbf

      qS.rowset.first()           		// go top

      do while not qS.rowset.endOfSet  // check out all time slots

         // if you find an appointment
         
         if qA.rowset.findKey(dtos(dDate)+cEmployeeName+;
                               str(qS.rowset.fields["slot"].value))

            ////// determine how long it lasts
            n = this.NTON(qA.rowset.fields["Units"].value)
            n = iif(n <=0,1,n) //// ensure at least one unit of time

            ////// update ont timeslot for each unit it lasts
            do while n > 0 and not qS.rowset.endOfSet
                 
               qS.rowset.fields["type"+str(nColumn,1)].value = ;
                  qA.rowset.fields["Type"].value
  
               qS.rowset.fields["fullname"+str(nColumn,1)].value = ;
                      qA.rowset.fields["With Whom"].value

                qS.rowset.fields["AppointKey"+str(nColumn,1)].value = ;
                      qA.rowset.fields["Key"].value

               qS.rowset.save()

               n --

               qS.rowset.next()

            enddo

         else
            qS.rowset.fields["type"+str(nColumn,1)].value = ""
            qS.rowset.fields["fullname"+str(nColumn,1)].value = ""
            qS.rowset.fields["appointkey"+str(nColumn,1)].value = 0
            qS.rowset.save()

            qS.rowset.next() 
               
         endif

      enddo


      d.active = false     // clean up
      qA.active = false
      qS.active = false

      d = null
      qA = null
      qS = null
      return true

   function nToN(nullvar) //// converts null to numeric
   return iif(nullVar = null,0,nullVar)

endclass