** END HEADER -- do not remove this line
//
// Generated on 01/31/2000
//
parameter bModal
local f
f = new EmployeeSetupForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class EmployeeSetupForm of FORM
   with (this)
      metric = 6	// Pixels
      height = 298
      left = 274
      top = 42
      width = 366
      text = "Employee Setup"
      mdi = false
   endwith


   this.CONTAX1 = new DATABASE()
   this.CONTAX1.parent = this
   with (this.CONTAX1)
      left = 27
      top = 273
      databaseName = "dBASEContax"
      active = true
   endwith


   this.EMPLOYEES1 = new QUERY()
   this.EMPLOYEES1.parent = this
   with (this.EMPLOYEES1)
      left = 10
      top = 264
      database = form.contax1
      sql = "select * from employees.dbf"
      active = true
   endwith




   this.RECTANGLE1 = new RECTANGLE(this)
   with (this.RECTANGLE1)
      left = 4
      top = 9
      width = 358
      height = 252
      text = "Rectangle1"
      colorNormal = "maroon/BtnFace"
      border = false
      borderStyle = 1	// Raised
   endwith


   this.NEWBUTTON = new PUSHBUTTON(this)
   with (this.NEWBUTTON)
      onClick = class::NEWBUTTON_ONCLICK
      height = 20
      left = 271
      top = 68
      width = 84
      text = "&New"
      fontSize = 9
      colorNormal = "maroon/BtnFace"
   endwith


   this.EMPLOYEEFIELD = new ENTRYFIELD(this)
   with (this.EMPLOYEEFIELD)
      dataLink = form.employees1.rowset.fields["name"]
      height = 18
      left = 78
      top = 209
      width = 183
      colorHighLight = "N/0x80ffff"
      fontSize = 9
   endwith


   this.PASSWORDFIELD = new ENTRYFIELD(this)
   with (this.PASSWORDFIELD)
      dataLink = form.employees1.rowset.fields["password"]
      height = 18
      left = 78
      top = 231
      width = 183
      colorHighLight = "N/0x80ffff"
      fontSize = 9
   endwith


   this.SAVEBUTTON = new PUSHBUTTON(this)
   with (this.SAVEBUTTON)
      onClick = class::SAVEBUTTON_ONCLICK
      height = 20
      left = 270
      top = 133
      width = 84
      text = "&Save"
      fontSize = 9
   endwith


   this.ABANDONBUTTON = new PUSHBUTTON(this)
   with (this.ABANDONBUTTON)
      onClick = class::ABANDONBUTTON_ONCLICK
      height = 20
      left = 271
      top = 157
      width = 84
      text = "&Abandon"
      fontSize = 9
   endwith


   this.DELETEBUTTON = new PUSHBUTTON(this)
   with (this.DELETEBUTTON)
      onClick = class::DELETEBUTTON_ONCLICK
      height = 20
      left = 271
      top = 182
      width = 84
      text = "&Delete"
      fontSize = 9
   endwith


   this.CLOSEBUTTON = new PUSHBUTTON(this)
   with (this.CLOSEBUTTON)
      onClick = class::CLOSEBUTTON_ONCLICK
      height = 20
      left = 271
      top = 271
      width = 84
      text = "&Close"
      fontSize = 9
   endwith


   this.LISTBOX = new LISTBOX(this)
   with (this.LISTBOX)
      height = 183
      left = 14
      top = 19
      width = 248
      id = 101
      fontSize = 9
      dataSource = form.employees1.rowset.fields["name"]
   endwith


   this.TEXTLABEL1 = new TEXTLABEL(this)
   with (this.TEXTLABEL1)
      height = 22
      left = 16
      top = 211
      width = 42
      text = "UserID"
   endwith


   this.TEXTLABEL2 = new TEXTLABEL(this)
   with (this.TEXTLABEL2)
      height = 22
      left = 16
      top = 232
      width = 62
      text = "Password"
   endwith


   this.rowset = this.employees1.rowset

   function NEWBUTTON_onClick
      form.rowset.beginappend()
      this.enabled = false
      form.employeefield.setfocus()
      return

   function ABANDONBUTTON_OnClick
      form.rowset.abandon()
      form.newbutton.enabled = true
      form.newbutton.setfocus()

   function CLOSEBUTTON_onClick
      form.close()
      return

   function DELETEBUTTON_OnClick
      if form.rowset.endOfSet
         return true
      endif
      if msgbox('Delete this entry, are you sure?','Confirm',26) # 6
         form.rowset.delete()
      endif
      form.newbutton.enabled = true
      form.newbutton.setfocus()

   function SAVEBUTTON_onClick
      if empty(form.employeefield.value+form.passwordfield.value)
         msgbox('Employee name and password required!','Missing Data',16)
         return false
      endif
      // check for duplicates
      d = new database()
      d.databaseName = 'dBASEContax'
      d.active = true

      dupe  = new query()
      dupe.database = d 
      dupe.sql = 'Select * from "employees.dbf"'
      dupe.active = true
        
      if (not form.newbutton.enabled)  and ;
         dupe.rowset.applylocate("name = '"+form.employeeField.value+"'") 

         msgbox('Entry already exists in table!','Duplicate',16)
         dupe.active = false
         d.active = false
         return false

      else

         form.rowset.save()
         form.newbutton.enabled = true
         form.newbutton.setfocus()
         dupe.active = false
         d.active = false

      endif
      return

   function datalink(rRowset,cFieldName,cTitle)

      form.rowset = rRowset
      form.fieldname = cFieldName 
      form.entryfield.datalink = form.rowset.fields[form.fieldname]
      form.listbox.datasource = form.rowset.fields[form.fieldname]
      form.text = cTitle

      return null
endclass
