Here is an excerpt from my event handler.
The Accept button will save the record.  If the record is already
in the database, it removes it and then puts it in sorted order.
If the record is brand new, it makes one and puts it in sorted order.

The Delete button displays a confirm and then deletes the record.
Enjoy


case PatientEntryAcceptButton:
   {
    VoidHand recordH = 0;
    UInt  recordIndex = prefs.patientEntryFormData.recordIndex;
    FormPtr  frmP = FrmGetActiveForm();
    UInt  attr;   // record attributes (category)

    // Save the form to our main record...
    PatientEntryFormSave (frmP);
    if (
#if PROVINCE == PROVINCE_MB
     !*prefs.patientEntryFormData.patient.lastName &&
     !*prefs.patientEntryFormData.patient.firstName
#endif
     )
    {
     // This is an invalid record
     FrmAlert (InvalidPatientAlert);
    }
    else
    {
     // Modify the patient status and open/create the db record
     switch (prefs.patientEntryFormData.patient.ivals.status)
     {
     case PatientNewUnsaved:
     {
      prefs.patientEntryFormData.patient.ivals.status = PatientNew;
      //
      // We need to assign a palmID.
      // Get/increment the next PalmID from the AppInfo block
      //
      prefs.patientEntryFormData.patient.ivals.palmID
= -(++gPatientAppInfo.lastPalmID);
      //
      // Save this appInfo information...
      //
      savePatientAppInfo();
      recordIndex = 0;
      //
      // Allocate some space for the data
      //
      recordH = DmNewHandle (gPatientDB, packedPatientSize
(&prefs.patientEntryFormData.patient));
      break;
     }
     default:
     {
      // The patient already exists, so detach it from the database
      // because it might move in its sort order
      DmDetachRecord (gPatientDB, recordIndex, &recordH);
      break;
     }
     }
     if (recordH)
     {
      // Now save the record
      packPatient (&prefs.patientEntryFormData.patient, recordH);
      // Now figure out where it goes in the database.
      recordIndex = DmFindSortPosition (gPatientDB, MemHandleLock (recordH),
0, patientSortCmp, 0);
      MemHandleUnlock (recordH);
      // Add the record to the DB
      DmAttachRecord (gPatientDB, &recordIndex, recordH, 0);

      // Set the category of the record to the correct category.
      DmRecordInfo (gPatientDB, recordIndex, &attr, NULL, NULL);
      attr &= ~dmRecAttrCategoryMask;    // Remove all category bits
      attr |= patientCategory (&prefs.patientEntryFormData.patient);
      DmSetRecordInfo (gPatientDB, recordIndex, &attr, NULL);
     }
     // Go to the PListForm
     FrmGotoForm (PListForm);
    }
    handled = true;
    break;
   }
  case PatientEntryDeleteButton:
   {
    char * m3;
    FormPtr frmP = FrmGetActiveForm ();
    PatientEntryFormSave (frmP);

    if (prefs.patientEntryFormData.patient.ivals.status == PatientNew)
    {
     m3 = "This patient will be gone forever.";
    }
    else
    {
     m3 = "The patient can still be viewed on the PC.";
    }
    if (FrmCustomAlert (PDeleteAlert,
#if PROVINCE == PROVINCE_MB
      prefs.patientEntryFormData.patient.lastName,
      prefs.patientEntryFormData.patient.firstName,
#endif
      m3) == 0)
    {
     // The user has confirmed...
     UInt  recordIndex = prefs.patientEntryFormData.recordIndex;
     DmArchiveRecord (gPatientDB, recordIndex);
     FrmGotoForm (PListForm);
    }
    handled = true;
    // Confirm the delete message
    break;
   }



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to