⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#task.c.1.29

📁 个人日程管理系统
💻 29
📖 第 1 页 / 共 5 页
字号:
/**************************************************************************** * Name : TaskGetSaved * Desc : get the (temporarily) saved record (copy from last index) * In   :  * 			-> index to put saved record * Out  :  * Auth : lb, 03.08.2000 * Rem  : doesn't handle err codes * Mod  : lb, 07.09.2000 * 			- keep the same uniqueID and attr ***************************************************************************/pgErr TaskGetSaved(UInt16 index){	MemHandle hNew, hOld;	TaskRecordType *pNew, *pOld;	UInt32 size = TaskRecordTypeSize, uniqueID;	UInt16 attr;	DBGMSG((DBB, "TaskGetSaved"));	// get a handle on the saved record	hOld = DmQueryRecord(gdbP, DmNumRecords(gdbP) - 1);	// calc the needed size	size = MemHandleSize(hOld);	// get a handle on a newly created record	hNew = DmNewRecord(gdbP, &index, size);	// get a pointer on the record	pNew = MemHandleLock(hNew);	// get a pointer on it	pOld = MemHandleLock(hOld);	// write the data	DmWrite(pNew, 0, pOld, size);	// unlock the pointers	MemHandleUnlock(hNew);	MemHandleUnlock(hOld);	// unlock the record	DmReleaseRecord(gdbP, index, true);	// to allow sync	// get the unique ID of original task	DmRecordInfo(gdbP, DmNumRecords(gdbP) - 1, &attr, &uniqueID, NULL);	// set the unique ID of the new task	DmSetRecordInfo(gdbP, index, &attr, &uniqueID);	// remove saved record	DmRemoveRecord(gdbP, DmNumRecords(gdbP) - 1);	// remove replaced record	DmRemoveRecord(gdbP, index + 1);	return pgOK;} // pgErr TaskGetSaved(UInt16 index)/**************************************************************************** * Name : TaskRemoveSaved * Desc : remove the (temporarily) saved record * In   :  * Out  :  * Auth : lb, 03.08.2000 * Rem  : doesn't handle err codes ***************************************************************************/pgErr TaskRemoveSaved(void){	DBGMSG((DBB, "TaskRemoveSaved"));	// remove replaced record	DmRemoveRecord(gdbP, DmNumRecords(gdbP) - 1);	return pgOK;} // pgErr TaskRemoveSaved(void)/**************************************************************************** * Name : TaskRemove * Desc : remove a task and all its children * In   :  * 			-> index of the task to remove * Out  :  * Auth : lb, 03.08.2000 * Rem  : doesn't handle err codes * Mod  : lb, 2001-01-21 * 			call DmRemoveRecord instead of DmDeleteRecord ***************************************************************************/pgErr TaskRemove(DmOpenRef dbP, UInt16 index){	Boolean stillChild = false;	pgErr returnValue;	DBGMSG((DBB, "TaskRemove"));	// +++ REMOVE THIS +++	DEBUG1("In TaskRemove");	// +++ REMOVE THIS +++	// as long as I have a child, remove it	while (TaskGetHasChild(dbP, index))	{		TaskRemove(dbP, index + 1);	}	if (TaskGetHasNext(dbP, index))	{		if (!TaskGetHasPrev(dbP, index))		{			TaskSetHasPrev(dbP, index + 1, false);		}		stillChild = true;	}	if (TaskGetHasPrev(dbP, index))	{		if (!TaskGetHasNext(dbP, index))		{			TaskSetHasNext(dbP, TaskGetPrevIndex(dbP, index), false);		}		stillChild = true;	}	if (!stillChild)	{		if (TaskGetLevel(dbP, index) != 1)		{			TaskSetHasChild(dbP, TaskGetFatherIndex(dbP, index), false);		}	}	// +++ REMOVE THIS +++	DEBUG1("About to remove task record");	// +++ REMOVE THIS +++	// then, remove me	returnValue = DmRemoveRecord(dbP, index);	// +++ REMOVE THIS +++	if (errNone != returnValue)		DEBUG1("Had error trying to remove task record");	// +++ REMOVE THIS +++	// we used this code in 0.23, but it's not needed to keep the record	// for the hotsync, so I prefer to remove the record, not to clutter the	// database with 0-length records	//DmDeleteRecord(dbP, index);	//DmMoveRecord(dbP, index, DmNumRecords(dbP));	//gNumDeleted++;	return pgOK;} // pgErr TaskRemove(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskRemoveDone * Desc : remove all done tasks * In   :  * Out  :  * Auth : lb, 29.08.2000 * Rem  : doesn't handle err codes ***************************************************************************/pgErr TaskRemoveChildren(DmOpenRef dbP, UInt16 index){	DBGMSG((DBB, "TaskRemoveChildren"));	// as long as I have a child, remove it	while (TaskGetHasChild(dbP, index))	{		TaskRemove(dbP, index + 1);	}	TaskSetHasChild(gdbP, index, false);	return pgOK;} // pgErr TaskRemoveChildren(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskRemoveDone * Desc : remove all done tasks * In   :  * Out  :  * Auth : lb, 29.08.2000 * Rem  : doesn't handle err codes * Mod	: lb, 2001-09-06 * 		  	adapt to 0.23 db format ***************************************************************************/pgErr TaskRemoveDone(DmOpenRef dbP){	UInt16 i = 1;	DBGMSG((DBB, "TaskRemoveDone"));	while (i < PgNumRecords(dbP))	{		if (TaskGetCompleted(dbP, i) == 10)		{			TaskRemove(dbP, i);		}		else		{			i++;		}	}	return pgOK;} // pgErr TaskRemoveDone(DmOpenRef dbP)/**************************************************************************** * Name : TaskRemoveDoneChildren * Desc : remove all done tasks in the children of given task * In   :  * Out  :  * Auth : lb, 29.08.2000 * Rem  : doesn't handle err codes * Mod	: lb, 2001-09-06 * 		  	adapt to 0.23 db format ***************************************************************************/pgErr TaskRemoveDoneChildren(DmOpenRef dbP, UInt16 index){	UInt16 i = index + 1, refLevel = TaskGetLevel(dbP, index);	DBGMSG((DBB, "TaskRemoveDoneChildren"));	while (i < (PgNumRecords(dbP)) && TaskGetLevel(dbP, i) > refLevel)	{		if (TaskGetCompleted(dbP, i) == 10)		{			TaskRemove(dbP, i);		}		else		{			i++;		}	}	return pgOK;} // pgErr TaskRemoveDoneChildren(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskRemoveDeletedRecords * Desc : Remove all records with the deleted flag * In   : -> dbP * Out  :  * Auth : lb, 2002-01-21 ***************************************************************************/void TaskRemoveDeletedRecords(DmOpenRef dbP){	Int32 i;	UInt16 attr;	DBGMSG((DBB, "Starting TaskRemoveDeletedRecords"));	i = PgNumRecords(dbP) - 1;	while (i > 0)	{		DmRecordInfo(dbP, i, &attr, NULL, NULL);		if (attr & dmRecAttrDelete)		{			DmRemoveRecord(dbP, i);		}		i--;	}	DBGMSG((DBB, "End of TaskRemoveDeletedRecords"));} // void TaskRemoveDeletedRecords(DmOpenRef dbP)/**************************************************************************** * Name : TaskExpandAll * Desc : set opened flag for all tasks * In   :  * Out  :  * Auth : lb, 04.08.2000 * Rem  : doesn't handle err codes ***************************************************************************/pgErr TaskExpand(DmOpenRef dbP, UInt16 index){	UInt16 i, num;	UInt8 level;	DBGMSG((DBB, "TaskExpand"));	level = TaskGetLevel(dbP, index);	num = PgNumRecords(dbP);	TaskSetOpened(dbP, index, true);	for (i = index + 1; i < num && TaskGetLevel(dbP, i) > level; i++)	{		TaskSetOpened(dbP, i, true);	}	return pgOK;} // pgErr TaskExpand(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskCollapseAll * Desc : unset opened flag for all tasks * In   :  * Out  :  * Auth : lb, 04.08.2000 * Rem  : doesn't handle err codes ***************************************************************************/pgErr TaskCollapse(DmOpenRef dbP, UInt16 index){	UInt16 i, num;	UInt8 level;	DBGMSG((DBB, "TaskCollapse"));	level = TaskGetLevel(dbP, index);	num = PgNumRecords(dbP);	// don't collapse task 0 !!!	if (index != 0)	{		TaskSetOpened(dbP, index, false);	}	for (i = index + 1; i < num && TaskGetLevel(dbP, i) > level; i++)	{		// don't collapse a task without child, or it'll be closed		// when it becomes a child		if (TaskGetHasChild(dbP, i))		{			TaskSetOpened(dbP, i, false);		}	}	return pgOK;} // pgErr TaskCollapse(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskCalcCompleted * Desc : calc and set completed by mean of the children * In   :  * 			-> database pointer * 			-> index of father to calc * Out  :  * Auth : lb, 04.08.2000 * Mod  : hcc, 04.28.2001 *          Preserve item's type. Ignore Informative children in calculation. * Mod  : lb, 2001-08-23 * 			Fix to be able to calc an item that has no children * 			useful to calc after a move * Mod	: lb, 2001-09-06 * 		  	adapt to 0.23 db format * Rem  : doesn't handle err codes * 		  warning : this one doesn't recurse down but UP ! You must call it * 		  			on a father whose children are up to date ! ***************************************************************************/pgErr TaskCalcCompleted(DmOpenRef dbP, UInt16 index){	UInt16 mean = 0, num = 0, tmp;	UInt16 subtask;	UInt8  level;	ItemType type = TaskGetType(dbP, index);	UInt8 myCompleted;	DBGMSG((DBB, "TaskCalcCompleted"));	/* If I am an informative task, don't change my type. */	if (type == informativeType)		return pgOK;	level = TaskGetLevel(dbP, index);	// nothing to calc for a task without children	// nothing to calc if index isn't a progress type	if (type == progressType && TaskGetHasChild(dbP, index))	{		subtask = index + 1;		while (subtask)		{			tmp = TaskGetCompleted(dbP, subtask);						// don't count informative type			if (TaskGetType(dbP, subtask) != informativeType)			{				mean += tmp;				num++;			}			// this one will return 0 if no brother is found			subtask = TaskGetNextIndex(dbP, subtask);		}		if (num != 0) // NOTE: Do nothing if all children are informative		{			myCompleted = mean / num;			TaskSetCompleted(dbP, index, myCompleted, false);		}				}	// recurse up, calc for the elders	if (level > 1)	{		TaskCalcCompleted(dbP, TaskGetFatherIndex(dbP, index));	}	return pgOK;} // pgErr TaskCalcCompleted(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskCalcCompletedAll * Desc : calc and set completed by mean of the children for all fathers * In   :  * 			-> database pointer * Out  :  * Auth : lb, 04.08.2000 * Rem  : doesn't handle err codes * 		  warning : this one can be lengthy !!!! * TODO : optimize it !!! ***************************************************************************/pgErr TaskCalcCompletedAll(DmOpenRef dbP){	UInt16 i;	DBGMSG((DBB, "TaskCalcCompletedAll"));	// children always comes after parents !	for (i = PgNumRecords(dbP) - 1; i > 0; i--)	{		TaskCalcCompleted(dbP, i); // this one controls if i has a child	}	return pgOK;} // pgErr TaskCalcCompletedAll(DmOpenRef dbP)/**************************************************************************** * Name : TaskToRight * Desc : task becomes a child of previous one * Prm  : index of future child * Out  :  * Auth : lb, 27.07.2000 * Mod  : lb, 28.07.2000 * 			new method, work by index * 		  lb, 24.08.2000 * 		  	fixed a bug when moving right the last task * 		  lb, 2001-08-23 * 		  	calc completed after move ***************************************************************************/pgErr TaskToRight(DmOpenRef dbP, UInt16 index){	UInt16 i;	UInt8 actualLevel;	UInt16 actual;	UInt16 numRec = PgNumRecords(dbP);	DBGMSG((DBB, "TaskToRight"));	// can't push the first one, he must be a first level one	if (index == FIRST_INDEX)		return pgError;	// can't push more than previous level + 1	if (TaskGetLevel(dbP, index - 1) < TaskGetLevel(dbP, index))		return pgError;	// if actual has no next, modify previous	if (!TaskGetHasNext(dbP, index))	{		TaskSetHasNext(dbP, actual = TaskGetPrevIndex(dbP, index), false);	}	// actual loose his next	TaskSetHasNext(dbP, index, false);	// inc level	TaskSetLevel(dbP, index, actualLevel = TaskGetLevel(dbP, index) + 1);	// if a previous exist	if (TaskGetPrevIndex(dbP, index) != dmMaxRecordIndex)	{		// tell him he has a next		TaskSetHasNext(dbP, TaskGetPrevIndex(dbP, index), true);		// actual has a prev		TaskSetHasPrev(dbP, index, true);	}	else	{		// no previous, actual is a first child		// update father		TaskSetHasChild(dbP, TaskGetFatherIndex(dbP, index), true);		// actual has no previous		TaskSetHasPrev(dbP, index, false);	}	// need to update the children	if (TaskGetHasChild(dbP, index))	{		i = index + 1;		// all children go to right without other modification		while (i < numRec && TaskGetLevel(dbP, i) >= actualLevel)		{			TaskSetLevel(dbP, i, TaskGetLevel(dbP, i) + 1);			i++;		}	}	TaskCalcCompleted(dbP, index);	return pgOK;} // pgErr TaskToRight(DmOpenRef dbP, UInt16 index)/****************************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -