📄 dateday.c
字号:
// Clip the meeting's end date to just before the displayed date
repeatInfo.repeatEndDate = Date;
DateAdjust (&repeatInfo.repeatEndDate, -1);
// Fill part of apptRec with the new repeat info and mark the field
// as modified. Only marked fields will be used by ApptChangeRecord.
apptRec.repeat = &repeatInfo;
apptFlags.repeat = true;
err = ApptChangeRecord (ApptDB, &recordNum, &apptRec, apptFlags);
break;
case dateRangeAll:
// Display an alert to comfirm the delete operation.
alert = FrmInitForm (DeleteApptDialog);
ctlIndex = FrmGetObjectIndex (alert, DeleteApptSaveBackup);
FrmSetControlValue (alert, ctlIndex, SaveBackup);
alertButton = FrmDoDialog (alert);
archive = FrmGetControlValue (alert, ctlIndex);
FrmDeleteForm (alert);
if (alertButton == DeleteApptCancel)
{
dateRange = dateRangeNone;
}
else
{
SaveBackup = archive;
// if the event to be deleted had an alarm, be sure to remove it
// from the posted alarm queue before the event is deleted.
if (hasAlarm)
DeleteAlarmIfPosted(recordNum);
// Delete or archive the record
if (archive)
DmArchiveRecord (ApptDB, recordNum);
else
DmDeleteRecord (ApptDB, recordNum);
// move it to the end of the DB
DmMoveRecord (ApptDB, recordNum, DmNumRecords (ApptDB));
}
break;
}
if (dateRange != dateRangeNone)
{
if (err)
{
FrmAlert (DeviceFullAlert);
return (false);
}
// If the event to be delete had an alarm, be sure to remove it
// from the posted alarm queue before the event is deleted and
// reschedule the next alarm.
if (hasAlarm)
RescheduleAlarms (ApptDB);
}
return (dateRange != dateRangeNone);
}
/***********************************************************************
*
* FUNCTION: CreateException
*
* DESCRIPTION: This routine creates an exception record. It does not
* add the exception to the exceptions list of the original
* record.
*
* PARAMETERS: newRec - new record
* indexP - passed: index of record being excepted
* returned: index of exception record created
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 11/22/95 Initial Revision
*
***********************************************************************/
static Err CreateException (ApptDBRecordPtr newRec, UInt16* indexP)
{
Err err;
UInt16 attr;
// Get the secert setting of the record.
DmRecordInfo (ApptDB, *indexP, &attr, NULL, NULL);
err = ApptNewRecord (ApptDB, newRec, indexP);
if (! err)
{
if (attr & dmRecAttrSecret)
{
DmRecordInfo (ApptDB, *indexP, &attr, NULL, NULL);
attr |= dmRecAttrSecret;
DmSetRecordInfo (ApptDB, *indexP, &attr, NULL);
}
}
return (err);
}
/***********************************************************************
*
* FUNCTION: CreateNote
*
* DESCRIPTION: This routine adds an empty note to the current record.
*
* PARAMETERS: prompt - if true, ask if an exception should be created.
*
* RETURNED: true if the note was added, false if it was not.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 8/4/95 Initial Revision
* ryw 2/18/00 Added casts to satisfy const cstring checking, should be safe
*
***********************************************************************/
static Boolean CreateNote (Boolean prompt)
{
Err err;
FormPtr alert;
UInt16 alertButton;
Boolean exception = false;
Boolean splitEvent = false;
MemHandle recordH;
ApptDateTimeType when;
ApptDBRecordType apptRec;
ApptDBRecordType newRec;
ApptDBRecordFlags changedFields;
if (CurrentRecord == noRecordSelected) return (false);
ApptGetRecord (ApptDB, CurrentRecord, &apptRec, &recordH);
MemHandleUnlock (recordH);
// If the record already has a note, exit
if (apptRec.note) return (true);
// If we're changing a repeating appointment, check if all occurrences
// are being changed, current & future occurrences are being changed,
// or if and exception is being created.
if (apptRec.repeat && prompt)
{
alert = FrmInitForm (RangeDialog);
alertButton = FrmDoDialog (alert);
FrmDeleteForm (alert);
if (alertButton == RangeCancelButton)
return (false);
else if (alertButton == RangeCurrentButton)
exception = true;
else if (alertButton == RangeFutureButton)
splitEvent = true;
}
if (exception)
{
// Add an exception to the current record.
err = ApptAddException (ApptDB, &CurrentRecord, Date);
if (err) goto Exit;
// Create a new record on the current day that contains
// the same description, time, and alarm setting as the
// repeating event.
ApptGetRecord (ApptDB, CurrentRecord, &apptRec, &recordH);
when.startTime = apptRec.when->startTime;
when.endTime = apptRec.when->endTime;
when.date = Date;
MemSet (&newRec, sizeof (newRec), 0);
newRec.when = &when;
newRec.description = apptRec.description;
newRec.alarm = apptRec.alarm;
newRec.note = (char *)"";
err = CreateException (&newRec, &CurrentRecord);
MemHandleUnlock (recordH);
if (err) goto Exit;
}
else
{
// Clear all changed fields flags.
MemSet (&changedFields, sizeof (changedFields), 0);
if (splitEvent)
{
// Split off the previous occurrences of the event
err = SplitRepeatingEvent (&CurrentRecord);
if (err) goto Exit;
// Set the new start date for the event
when.date = Date;
when.startTime = apptRec.when->startTime;
when.endTime = apptRec.when->endTime;
newRec.when = &when;
changedFields.when = true;
}
// Add the note to the record.
newRec.note = (char *)"";
changedFields.note = true;
err = ApptChangeRecord (ApptDB, &CurrentRecord, &newRec, changedFields);
if (err) goto Exit;
}
return (true);
Exit:
FrmAlert (DeviceFullAlert);
return (false);
}
/***********************************************************************
*
* FUNCTION: DeleteNote
*
* DESCRIPTION: This routine deletes the note field from an
* appointment record.
*
* PARAMETERS: exception - true if a new record, an exception, should be
* created.
* splitEvent - true if only deleting note from current and
* future occurrences of the specified event.
*
* RETURNED: true if the note was deleted.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 10/13/95 Initial Revision
*
***********************************************************************/
static Boolean DeleteNote (Boolean exception, Boolean splitEvent)
{
Err err;
MemHandle recordH;
ApptDBRecordType newRec;
ApptDBRecordType apptRec;
ApptDateTimeType when;
ApptDBRecordFlags changedFields;
if (exception)
{
// Add an exception to the current record.
err = ApptAddException (ApptDB, &CurrentRecord, Date);
if (err) goto Exit;
// Create a new record on the current day that contains
// the same description, time, and alarm settings as the
// repeating event, but not the note.
ApptGetRecord (ApptDB, CurrentRecord, &apptRec, &recordH);
when.startTime = apptRec.when->startTime;
when.endTime = apptRec.when->endTime;
when.date = Date;
MemSet (&newRec, sizeof (newRec), 0);
newRec.when = &when;
newRec.description = apptRec.description;
newRec.alarm = apptRec.alarm;
err = CreateException (&newRec, &CurrentRecord);
MemHandleUnlock (recordH);
if (err) goto Exit;
}
else
{
// Clear all changed fields flags.
MemSet (&changedFields, sizeof (changedFields), 0);
ApptGetRecord (ApptDB, CurrentRecord, &apptRec, &recordH);
if (splitEvent)
{
// Split off the previous occurrences of the event
err = SplitRepeatingEvent (&CurrentRecord);
if (err) goto Exit;
// Set the new start date for the event
when.date = Date;
when.startTime = apptRec.when->startTime;
when.endTime = apptRec.when->endTime;
newRec.when = &when;
changedFields.when = true;
}
// Remove the note from the record.
newRec.note = NULL;
changedFields.note = true;
err = ApptChangeRecord (ApptDB, &CurrentRecord, &newRec, changedFields);
if (err) goto Exit;
}
return (true);
Exit:
FrmAlert (DeviceFullAlert);
return (false);
}
/***********************************************************************
*
* FUNCTION: SplitRepeatingEvent
*
* DESCRIPTION: This routine splits a repeating appointment into two
* repeating appointment. The orginal record record is
* copied and the end date of the new record is set to
* yesterday or the day before the current date, which ever
* earlier.
*
* PARAMETERS: indexP - passed: index of records split.
* returned: index of records orginal record.
*
* RETURNED: error code
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/25/96 Initial Revision
*
***********************************************************************/
static Err SplitRepeatingEvent (UInt16* indexP)
{
Err err = 0;
UInt16 index;
UInt32 uniqueID;
MemHandle recordH;
DateType endDate;
DateType repeatDate;
// DateTimeType today;
RepeatInfoType repeat;
ApptDBRecordType apptRec;
// Get yesterday's date or the date of the day before the current date,
// which ever earlier.
// TimSecondsToDateTime (TimGetSeconds(), &today);
// endDate.year = today.year - firstYear;
// endDate.month = today.month;
// endDate.day = today.day;
// if (DateToInt (endDate) > DateToInt (Date))
endDate = Date;
DateAdjust (&endDate, -1);
ApptGetRecord (ApptDB, *indexP, &apptRec, &recordH);
// Check for past occurrecnes of the event.
repeatDate = apptRec.when->date;
ApptNextRepeat (&apptRec, &repeatDate, true);
if (DateToDays (repeatDate) <= DateToDays (endDate))
{
// Creating the new record may move a current record, so get its
// unique id so we can find it after the record is created.
DmRecordInfo (ApptDB, *indexP, NULL, &uniqueID, NULL);
repeat = *apptRec.repeat;
repeat.repeatEndDate = endDate;
apptRec.repeat = &repeat;
err = ApptNewRecord (ApptDB, &apptRec, &index);
DmFindRecordByID (ApptDB, uniqueID, indexP);
}
MemHandleUnlock (recordH);
return (err);
}
/***********************************************************************
*
* FUNCTION: MoveEvent
*
* DESCRIPTION: This routine changes the date and / or time of the
* specified event
*
* PARAMETERS: recordNumP -
* startTime -
* startTime -
* date -
* splitEvent -
* moved - (returned) true if moved
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 4/01/96 Initial Revision
* gap 9/08/99 Add support for moving only current, current & future,
* or all occurrences of the event.
* gap 9/15/99 Clean up Current/Future/All handling for weekview.
*
***********************************************************************/
Err MoveEvent (UInt16* recordNumP, TimeType startTime, TimeType endTime,
DateType startDate, Boolean timeChangeOnly, Boolean* moved)
{
Err err;
UInt16 id;
UInt16 dayOfWeek;
UInt16 alertButton;
Int32 adjust;
FormPtr alert;
Boolean exception = false;
Boolean splitEvent = false;
Boolean applyToAll = false;
MemHandle recordH;
RepeatInfoType repeat;
ApptDBRecordType newRec;
ApptDBRecordType apptRec;
ApptDateTimeType when;
ApptDBRecordFlags changedFields;
DateType date = startDate;
Boolean hasAlarm, isRepeating;
ApptGetRecord (ApptDB, *recordNumP, &apptRec, &recordH);
hasAlarm = (apptRec.alarm != NULL);
isRepeating = (apptRec.repeat != NULL);
*moved = false;
// If we're changing a repeating appointmemt, check if the changes will
// be applied to:
// - all occurrences of the event
// - the current and all future occurrences of the event
// - only the current event (create an expection)
if (isRepeating)
{
alert = FrmInitForm (RangeDialog);
alertButton = FrmDoDialog (alert);
FrmDeleteForm (alert);
// If the alert was canceled don't apply any of the changes.
if (alertButton == RangeCancelButton)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -