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

📄 .#task.c.1.29

📁 个人日程管理系统
💻 29
📖 第 1 页 / 共 5 页
字号:
 * Name : TaskToLeft * Desc : move task index to the left * Prm  : index of item to be pushed to left * Out  :  * Auth : lb, 31.07.2000 * Rem  : Border effect : sets gActualTask to the new index !!! * Mod  : lb, 09.08.2000 * 			- update gActualTask for continuous moving * 		  lb, 24.08.2000 * 		  	fixed a bug when moving right the last task * 		  lb, 2001-08-23 * 		  	calc completed after move ***************************************************************************/pgErr TaskToLeft(DmOpenRef dbP, UInt16 index){	UInt16 i;	UInt8 actualLevel;	UInt16 prev;	UInt16 father;	UInt16 newIndex = index;	Boolean needMove = false;	UInt16 numRec = PgNumRecords(dbP);	DBGMSG((DBB, "TaskToLeft"));	// can't push the first one, he must be a first level one	if (index == FIRST_INDEX)		return pgError;	// can't push more than level 1	if (TaskGetLevel(dbP, index) == FIRST_LEVEL)		return pgError;	// to gain some time	father = TaskGetFatherIndex(dbP, index);	// return if I can't find the father or if it's the root	if (!father)		return pgError;	// if previous exists, update its next	if ((prev = TaskGetPrevIndex(dbP, index)) != dmMaxRecordIndex)	{		TaskSetHasNext(dbP, prev, TaskGetHasNext(dbP, index));	}	else	{		// no previous, actual is a first child		// update father		// father still has child if actual has a next		TaskSetHasChild(dbP, father, TaskGetHasNext(dbP, index));	}	// if actual has a next, next takes actual's prev status	if (TaskGetHasNext(dbP, index))	{		TaskSetHasPrev(dbP, TaskGetNextIndex(dbP, index), TaskGetHasPrev(dbP, index));		// actual must be moved outside its parent's scope		// that's before father's next		needMove = true;	}	// if father has no next, modify actual	if (!TaskGetHasNext(dbP, father))	{		TaskSetHasNext(dbP, index, false);	}	else	{		TaskSetHasNext(dbP, index, true);	}	TaskSetHasPrev(dbP, index, true);	if (needMove)	{		newIndex = TaskGetNextRelativeIndex(dbP, father);		if (newIndex == 0)		{			newIndex = numRec;		}		DmMoveRecord(dbP, index, newIndex);		// we insert after index, so newIndex becomes newIndex-- after insertion		newIndex--;		gActualTask = newIndex;	}	// dec level	TaskSetLevel(dbP, newIndex, actualLevel = TaskGetLevel(dbP, newIndex) - 1);	// father gain a next	TaskSetHasNext(dbP, father, true);	// need to update the children	if (TaskGetHasChild(dbP, newIndex))	{		newIndex++; // to insert children after actual		i = index + 1;		// if actual has moved, first child is now index		if (needMove)		{			i--;		}		// all children go to left, without other modification		while (i < numRec && TaskGetLevel(dbP, i) >= actualLevel + 2)		{			TaskSetLevel(dbP, i, TaskGetLevel(dbP, i) - 1);			if (needMove)			{				DmMoveRecord(dbP, i, newIndex);				gActualTask--;			}			else			{				i++;			}		}	}	TaskCalcCompleted(dbP, father);	return pgOK;} // pgErr TaskToLeft(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskUp * Desc : push a task up * Prm  :  * 			-> index of task to push * Out  : Err code * Auth : lb, 01.08.2000 * Rem  :  * Mod  : lb, 09.08.2000 * 			- update gActualTask for continuous moving ***************************************************************************/pgErr TaskUp(DmOpenRef dbP, UInt16 index){	UInt16 prev;	UInt8  level;	UInt16 numRec = PgNumRecords(dbP);	DBGMSG((DBB, "TaskUp"));	if (!TaskGetHasPrev(dbP, index))		return pgError;	// update flags	prev = TaskGetPrevIndex(dbP, index);	TaskSetHasNext(dbP, prev, TaskGetHasNext(dbP, index));	TaskSetHasPrev(dbP, index, TaskGetHasPrev(dbP, prev));	TaskSetHasPrev(dbP, prev, true);	TaskSetHasNext(dbP, index, true);	// move index	DmMoveRecord(dbP, index, prev);	// update actual task	gActualTask = prev;	// move children	if (TaskGetHasChild(dbP, prev))	{		level = TaskGetLevel(dbP, prev);		// move children behind actual		prev++;		index++;		// while it's a child		while (index < numRec && TaskGetLevel(dbP, index) > level)		{			DmMoveRecord(dbP, index, prev);			prev++;			index++;		}	}	return pgOK;} // pgErr TaskUp(UInt16 index)/**************************************************************************** * Name : TaskDown * Desc : push a task down * Prm  :  * 			-> index of task to push * Out  : Err code * Auth : lb, 02.08.2000 * Mod  : lb, 09.08.2000 * 			- update gActualTask for continuous moving * 		  lb, 17.08.2000 * 		    - fixed crash when moving a task that has children ***************************************************************************/pgErr TaskDown(DmOpenRef dbP, UInt16 index){	UInt16 next;	UInt32 uniqueID;	DBGMSG((DBB, "TaskDown"));	if (!TaskGetHasNext(dbP, index))		return pgError;	// to locate the task after it has moved	DmRecordInfo(dbP, gActualTask, NULL, &uniqueID, NULL);	next = TaskGetNextIndex(dbP, index);	TaskUp(dbP, next);	// locate the task	DmFindRecordByID(dbP, uniqueID, &gActualTask);	// update the table, because if the task moved down has children, its	// new index is not in the table, and SelectTask will crash with	// move = true	ProjectTableUpdate();	return pgOK;} // pgErr TaskDown(UInt16 index)/**************************************************************************** * Name : TaskPublishToDo * Desc : publish the actual task in the ToDo DB * Prm  :  * Out  :  * Auth : lb, 21.08.2000 * Mod  : rw, 30.12.2000 * 		  	support for syncing categories with ToDo * Mod	: lb, 2001-09-10 * 		  	adapt to 0.23 db format * 		  	also sync the note ***************************************************************************/pgErr TaskPublishToDo(DmOpenRef dbP, UInt16 index){	DmOpenRef ToDoDB;	ToDoItemType task;	MemHandle h;	TaskExtendedRecordType *p, *parent;	UInt16 todoIndex = 0;	Err err = errNone;	UInt32 uniqueID;	TaskFormatType format;	Char name[dmCategoryLength];	UInt16 category;	#define maxDescLen 256	Char descWithParents[maxDescLen]; // 256 from ToDoDB.c, maxDescLen	DBGMSG((DBB, "TaskPublishToDo"));	if (TaskGetFormat(dbP, index).hasToDo)		return pgOK;	// try to open the ToDo database	if (ToDoGetDatabase(&ToDoDB, dmModeReadWrite))	{		FrmCustomAlert(AltEmpty, "Can't open the todo database", " ", " ");		return pgError;	}	h = DmQueryRecord(dbP, index);	if (!h)		return pgError;	p = MemHandleLock(h);	// convert due date format if there's no due date	task.dueDate = StdFields(p)->dueDate;	if (task.dueDate.month == 0)	{		*((UInt16 *) &task.dueDate) = toDoNoDueDate;	}	// convert priority : no => 5	task.priority = StdFields(p)->priority;	if (!(task.priority > 0 && task.priority < NO_PRIORITY))	{		task.priority = 5;	}	if (1) // user wants complete desc ?	{		Char *pdesc;		UInt16 pindex = index;		UInt8 level = 2;		parent = p;		SafeCopy(descWithParents, &StdFields(p)->description,maxDescLen);		while (level > 1)		{			pindex = TaskGetFatherIndex(dbP, pindex); // get father			if (pindex == dmMaxRecordIndex) break; // check validity			level = TaskGetLevel(dbP, pindex); // get level for stop condition			pdesc = TaskGetDescription(dbP, pindex); // get description			if (StrLen(pdesc) + StrLen(descWithParents) < maxDescLen - 4) // 0:			{				StrCat(descWithParents, " | "); // separator				StrCat(descWithParents, pdesc);				MemPtrFree(pdesc);			}			else			{				MemPtrFree(pdesc);				break;			}		}	}	if (1) // complete desc	{		task.description = descWithParents;	}	else	{		task.description = &StdFields(p)->description;	}	if (TaskGetFormat(dbP, index).hasNote)	{		task.note = &StdFields(p)->description + 							StrLen(&StdFields(p)->description) + 1;	}	else	{		task.note = "";	}	// match the category name from the ToDoDB	category = TaskGetCategory(dbP, index);	CategoryGetName(dbP, category, name);	category = CategoryFind(ToDoDB, name);	// Task category not in ToDo - set ToDo category to Unfiled	if (category == dmAllCategories)	{		category = 0;	}	// create the ToDo entry	err = ToDoNewRecord(ToDoDB, &task, category, &todoIndex);	// Unlock the task, now that the ToDo is created	MemHandleUnlock(h);	if (err == errNone)	{		DmRecordInfo(ToDoDB, todoIndex, NULL, &uniqueID, NULL);		DBGMSG((DBB, "ToDo UID : %ld (hex next line)", uniqueID));		DBGMSGBIN((DBB, &uniqueID, sizeof(uniqueID)));		TaskSetExtraChunk(dbP, index, Extra_Link_ToDo, 0x00,						  &uniqueID, sizeof(uniqueID));		format = TaskGetFormat(dbP, index);		format.hasToDo = 1;		TaskSetFormat(dbP, index, format);	}	else	{		DEBUG1("Export failed !");	}	DmCloseDatabase(ToDoDB);	return pgOK;} // pgErr TaskPublishToDo(DmOpenRef dbP, UInt16 index)/**************************************************************************** * Name : TaskSetToDoStatus * Desc : update the sync todo * Prm  :  * 			-> database * 			-> index of task * 			-> field to update in : (one at a time) *				toDoPriority, *				toDoComplete, *				toDoDueDate, *				toDoDescription, not yet *				toDoNote, not yet *				toDoCategory, * 			-> value    (pass NULL if you don't want it) * 			-> priority (") * 			-> duedate  (") * 			-> category (") * Out  :  * Auth : lb, 30.08.2000 * Mod  : rw, 30.12.2000 * 		  	support for syncing categories with ToDo * Mod	: lb, 2001-09-06 * 		  	adapt to 0.23 db format ***************************************************************************/pgErr TaskSetToDoStatus(DmOpenRef dbP, UInt16 index, UInt16 field, 	UInt8 value, UInt16 priority, DateType dueDate, UInt16 category){	DmOpenRef ToDoDB;	UInt32 uniqueID;	UInt16 todoIndex;	UInt16 zero = 0, one = 1;	Err err;	Char name[dmCategoryLength];	DBGMSG((DBB, "TaskSetToDoStatus"));	uniqueID = TaskGetToDoUniqueID(dbP, index);	if (!uniqueID)		return pgError;	// try to open the ToDo database	if (ToDoGetDatabase(&ToDoDB, dmModeReadWrite))	{		FrmCustomAlert(AltEmpty, "Can't open the todo database", " ", " ");		return pgError;	}	if (DmFindRecordByID(ToDoDB, uniqueID, &todoIndex))	{		DmCloseDatabase(ToDoDB);		DEBUG1("The corresponding ToDo was not found, removing link.");		TaskRemoveHasToDo(dbP, index);		return pgError;	}	if (field == toDoPriority)	{		if (priority > 5 || priority < 1)			priority = 5;		err = ToDoChangeRecord(ToDoDB, &todoIndex, toDoPriority, 			&priority);	}	if (field == toDoComplete)	{		err = ToDoChangeRecord(ToDoDB, &todoIndex, toDoComplete, 			value == ACTION_DONE ? &one : &zero );	}	if (field == toDoDueDate)	{		if (dueDate.month == 0)			*((UInt16 *) &dueDate) = toDoNoDueDate;		err = ToDoChangeRecord(ToDoDB, &todoIndex, toDoDueDate, 			(UInt16*)&dueDate);	}	if (field == toDoCategory)	{		CategoryGetName(dbP, category, name);		category = CategoryFind(ToDoDB, name);		// Task category not in ToDo - set ToDo category to Unfiled		if (category == dmAllCategories)		{			category = 0;		}		err = ToDoChangeRecord(ToDoDB, &todoIndex, toDoCategory, 							   &category);	}//ToDoRecordFieldType //typedef enum  { 	//toDoPriority,	//toDoComplete,	//toDoDueDate,	//toDoDescription,	//toDoNote,	//toDoCategory } ToDoRecordFieldType;////#define completeFlag 	0x80//#define priorityOnly 	~completeFlag	DmCloseDatabase(ToDoDB);	return pgOK;} // pgErr TaskSetToDoStatus(DmOpenRef dbP, UInt16 index, UInt16 fields, // UInt8 value, UInt8 priority, DateType dueDate, UInt16 category)/**************************************************************************** * Name : TaskUpdateToDo * Desc : update the values of the ToDo * Prm  :  * 			-> database * 			-> index of task * Out  :  * Auth : lb, 30.08.2000 * Mod  : rw, 30.12.2000 * 		  	support for syncing categories with ToDo ***************************************************************************/Err TaskUpdateToDo(DmOpenRef dbP, UInt16 index){	Err err = errNone;	DBGMSG((DBB, "TaskUpdateToDo"));	// see if we're synchronized with a ToDo	if (TaskGetFormat(dbP, index).hasToDo)	{		Err err;		// check the status in ToDo and update this task		err = TaskSetToDoStatus(dbP, index, toDoComplete,			TaskGetCompleted(dbP, index),			0, gNoDate, 0);		err = TaskSetToDoStatus(dbP, index, toDoDueDate,			0, 0,			TaskGetDueDate(dbP, index),			0);		err = TaskSetToDoStatus(dbP, index, toDoPriority,			0,			TaskGetPriority(dbP, index),			gNoDate, 0);		err = TaskSetToDoStatus(dbP, index, toDoCategory,			0, 0, gNoDate,			Task

⌨️ 快捷键说明

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