📄 diary.c
字号:
DbGetDbInfo(g_DbHandle, &sdi);
/*已超过数据库最大记录数*/
if (DB_MAX_RECORDNUM <= sdi.uRecordNum)
{
MsgBoxRun((MWinView*)hWnd, NULL, "日记本已写满,不能再写日记了!"
, MAKE_ID(IDS_DIARY_TITLE_VIEW), MT_OK|MT_ICONINFO);
}
else
{
g_PreViewRecID = 0;
g_DiaryViewFont = SYSFONT_GBK12;
ApExit(AP_MODE_NEW);
}
}
pEvent->dwMsgType = EV_NOTHING;
return TRUE;
case DIARY_CMD_MODIFY: /*修改日记*/
ApExit(AP_MODE_MODIFY);
pEvent->dwMsgType = EV_NOTHING;
return TRUE;
case DIARY_CMD_DELETE: /*删除日记*/
{
INT nRecID;
UINT32 dwMode;
StructDbInfo sdi;
DbGetDbInfo(g_DbHandle, &sdi);
if (0 == sdi.uRecordNum) /*无日记可供删除,出错*/
{
return FALSE;
}
dwMode = MsgBoxRun((MWinView*)hWnd, NULL, MAKE_ID(IDS_DIARY_ASKDEL)
, MAKE_ID(IDS_DIARY_TITLE_VIEW), MT_YESNO|MT_ICONQUESTION);
if (QUIT_NO == dwMode || QUIT_POWEROFF == dwMode)
{
return FALSE;
}
StatusBoxStart(hWnd, MAKE_ID(IDS_DIARY_DELETE));
nRecID = DbRecordDelete(g_DbHandle, g_PreViewRecID);
if (nRecID < 0)
{
ApErrorMessage(nRecID);
return FALSE;
}
DbGetDbInfo(g_DbHandle, &sdi);
if (0 == sdi.uRecordNum)
{
/*删完所有日记,退出日记本*/
UINT32 dwResult;
g_PreViewRecID = -1;
dwResult = MsgBoxRun((MWinView*)hWnd, NULL
, MAKE_ID(IDS_DIARY_VIEW_ASKNEW)
, MAKE_ID(IDS_DIARY_TITLE_VIEW)
, MT_YESNO|MT_ICONINFO);
if (QUIT_YES == dwResult)
{
dwMode = AP_MODE_NEW;
}
else
{
dwMode = QUIT_DESKTOP;
}
}
else
{
if (0 != g_PreViewRecID)
{
g_PreViewRecID--;
}
dwMode = AP_MODE_VIEW;
}
ApExit(dwMode);
}
return TRUE;
case DIARY_CMD_FIND: /*查找日记*/
{
UINT nRtnCmd;
nRtnCmd = RadioMsgBoxRun((MWinView *)hWnd, NULL
, "请选择查找方式:", 0
, "按日期查找\r按内容查找");
/*按日期查找*/
if (CM_RADIOMSG_OK == nRtnCmd)
{
DateType dateTmp = g_Date;
UINT8 pSearchBuf[11] = {0};
CreateFindDialog((UINT8*)hWnd); /*弹出查找窗口*/
if (g_Date.dateYear ==0 && g_Date.dateMonth == 0 && g_Date.dateDay== 0)
{
/*用户取消查找*/
g_Date = dateTmp;
return TRUE;
}
sprintf(pSearchBuf,"%d-%02d-%02d", g_Date.dateYear
, g_Date.dateMonth, g_Date.dateDay);
pSearchBuf[10] = 0;
g_Date = dateTmp;
if (DiaryViewSearch((MWinView*)hWnd, 0, pSearchBuf) > 0)
{
/*找到要查找的日记,重新进入浏览日记*/
ApExit(AP_MODE_VIEW);
}
}
/*按内容查找*/
else if ((CM_RADIOMSG_OK + 1) == nRtnCmd)
{
UINT8 pSearch[MAX_SEARCHLEN] = {0};
if (QUIT_INPUT_OK == ApInputWindow(MAKE_ID(IDS_DIARY_TITLE_VIEW)
, "请输入要查找的内容:"
, pSearch, MAX_SEARCHLEN))
{
/*找到*/
if (DiaryViewSearch((MWinView*)hWnd, 0x3, pSearch) > 0)
{
MRect rect;
GuiGetUserFullRect(&rect);
g_Index_BGround =
GraphBackupRect((MDC*)hWnd, NULL
, rect.x, rect.y
, rect.x + rect.width - 1
, rect.y + rect.height - 1);
ApExit(AP_MODE_INDEX); /*退出到索引模式*/
}
}
}
}
return TRUE;
}
break;
}
return TRUE;
}
/*==========================================================
FUNCTION :DiaryViewSearch
DESCRIPTION:在数据库指定字段查找包含指定字符串的所有记录
INPUTS :
hApWnd:窗体句柄
wField:字段
pszChar:待查字符串
OUTPUTS :
RETURN :查找到的记录数,返回-1表示查找失败
____________________________________________________________
DATE AUTHOR VERSION DESCRIBE
------------------------------------------------------------
2004-08-XX 黄 猛 Ver1.00 Create
==========================================================*/
INT DiaryViewSearch(MWinView* hApWnd, UINT16 wField, UINT8* const pszChar)
{
UINT16* pIndex;
INT nScrhRec;
StructDbInfo sDbInfo;
DbGetDbInfo(g_DbHandle, &sDbInfo);
/*申请索引缓冲区*/
pIndex = MemAlloc((sDbInfo.uRecordNum + 1) * sizeof(UINT16));
if (NULL == pIndex)
{
/*索引缓冲区申请失败*/
if (AP_MODE_VIEW == ApGetMode())
{
MsgBoxRun(hApWnd, NULL, (UINT8*)IDS_DIARY_MEMORY_FULL
, MAKE_ID(IDS_DIARY_TITLE_VIEW), MT_ICONINFO);
}
if (AP_MODE_NEW == ApGetMode())
{
MsgBoxRun(hApWnd, NULL, (UINT8*)IDS_DIARY_CANNOT_SEARCH
, MAKE_ID(IDS_DIARY_TITLE_NEW), MT_ICONINFO);
}
return -1;
}
memset(pIndex, 0, sDbInfo.uRecordNum + 1);
/*得到编辑缓冲区进行查找*/
if (AP_MODE_VIEW == ApGetMode())
{
StatusBoxStart((MWindow*)hApWnd, MAKE_ID(IDS_DIARY_SEARCH));
}
nScrhRec = ApFindItems(g_DbHandle, wField, pszChar, pIndex);
if (AP_MODE_VIEW == ApGetMode())
{
StatusBoxEnd((MWindow*)hApWnd);
}
if (nScrhRec <= 0)
{
/*未找到,提示用户*/
if (AP_MODE_VIEW == ApGetMode())
{
MsgBoxRun(hApWnd, NULL, MAKE_ID(IDS_DIARY_UNSEARCHED)
, MAKE_ID(IDS_DIARY_TITLE_VIEW), MT_OK|MT_ICONINFO);
}
MemFree(pIndex);
}
else
{
if (0x03 == wField)
{
g_IndexBuf = pIndex;
}
else
{
g_PreViewRecID = DbRecordHandleToID(g_DbHandle, (INT)(*(pIndex+1+0))); /*记录找到的记录的ID*/
MemFree(pIndex);
}
}
return nScrhRec;
}
MWindow* DiaryCreateWin_INDEX(VOID)
{
MRect pRect;
MWindow* hWnd;
GuiGetUserFullRect(&pRect);
/* pRect.x += pRect.width/3;
pRect.width = pRect.width/3;
pRect.y += 19;
pRect.height -= 40;
*/ hWnd = WindowCreate(NULL, NULL, DIARY_WND_INDEX_ID, &pRect
, WS_TITLE, MAKE_ID(IDR_HELP_INDEX)
, MAKE_ID(IDS_DIARY_TITLE_INDEX), NULL, NULL);
if (NULL == hWnd)
{
g_IndexBuf = NULL;
return NULL;
}
/* WindowGetClientArea(hWnd, &pRect);
pRect.x += 3;
pRect.width -= 5;
pRect.height -= 2;
*/
pRect.x = 110;
pRect.y = 38;
pRect.width = 97;
pRect.height = 176;
if (!DiaryCreatList(hWnd, &pRect, LST_BORDER|LST_STORAGE, g_IndexBuf))
{
GuiDestroy((MView*)hWnd);
MemFree(g_IndexBuf);
g_IndexBuf = NULL;
return NULL;
}
if (!g_IndexStatus)
{
ApSetSelected((UINT32)g_PreViewRecID);
g_IndexStatus = TRUE;
}
((MView*)hWnd)->fpDrawBackGround = DiaryINDEX_BG_CallBack;
((MView*)hWnd)->fpHandleEvent = DiaryINDEX_EV_CallBack;
return hWnd;
}
BOOL DiaryCreatList(MWindow* hWnd, MRect* pRect, UINT32 dwStyle, UINT16* pIndexBuf)
{
UINT32 i;
MList* pList;
MListItem listItem;
StructDbData dbData;
MListColInfo pColInfo[]=
{
{pRect->width, LST_STRING, NULL}
};
pList = ListViewCreate((MView*)hWnd, NULL, DIARY_INDEX_LIST, pRect
, LST_STORAGE|LST_LOOPSEL|LST_BORDER /*风格*/
, (UINT32)*pIndexBuf /*行数*/
, 1 /*列数*/
, (UINT16)(SysGetFontHeight(SysGetFontLibID())+1) /*行高*/
, 11 /*行数据长度*/
, pColInfo);
if (NULL == pList)
{
return FALSE;
}
listItem.dwRow = LIST_LASTROW;
listItem.pbData = MemAlloc(11);
dbData.pBuf = MemAlloc(AP_MAX_EDITLEN);
if (NULL == listItem.pbData || NULL == dbData.pBuf)
{
return FALSE;
}
for (i=1; i<=*pIndexBuf; i++)
{
memset(listItem.pbData, 0, 11);
memset(dbData.pBuf, 0, AP_MAX_EDITLEN);
DbRecordRead(g_DbHandle, &dbData
, DbRecordHandleToID(g_DbHandle, (INT)(*(pIndexBuf + i)))
, -1);
memcpy(listItem.pbData, dbData.pBuf, 10);
ListAddItem(pList, &listItem);
}
MemFree(listItem.pbData);
MemFree(dbData.pBuf);
if (g_IndexStatus)
{
for (i=1; i<=*g_IndexBuf; i++)
{
if ( g_PreViewRecID == DbRecordHandleToID(g_DbHandle, (INT)(*(pIndexBuf + i))) )
{
ListSetCurrentRow(pList, *g_IndexBuf - i);
break;
}
}
}
else
{
ListSetCurrentRow(pList, 0);
}
return TRUE;
}
VOID DiaryINDEX_BG_CallBack(MDC* hDC)
{
if (NULL != g_Index_BGround)
{
GraphRestoreRect(hDC, hDC->dcX, hDC->dcY
, hDC->dcX + hDC->dcWidth - 1
, hDC->dcY + hDC->dcHeight - 1
, g_Index_BGround);
}
GraphClearRect(hDC, 106, 19, 211, 219);
GraphDrawBitmap(hDC, 109, 22, 17, 13, NULL, MAKE_ID(IDB_TITLE));
hDC->dcFontID = SYSFONT_GBK12;
GraphDrawText(hDC, 131, 23, 0, 0, NULL, MAKE_ID(IDS_DIARY_TITLE_INDEX));
hDC->dcFontID = SYSFONT_GBK16;
GraphDrawLine(hDC, 107, 19, 209, 19);
GraphDrawLine(hDC, 107, 217, 210, 217);
GraphDrawLine(hDC, 108, 218, 210, 218);
GraphDrawLine(hDC, 106, 20, 106, 216);
GraphDrawLine(hDC, 210, 20, 210, 216);
GraphDrawLine(hDC, 211, 21, 211, 217);
return;
}
UINT32 DiaryINDEX_EV_CallBack(MView* handle, MEvent* pEvent)
{
switch (pEvent->dwMsgType)
{
case EV_KEY_DOWN:
switch (pEvent->xParam)
{
case MJ_VK_ENTER:
{
MList* pList;
pList = (MList*)GetHandleFromID(handle, DIARY_INDEX_LIST);
g_PreViewRecID =
DbRecordHandleToID(g_DbHandle
, (INT32)*(g_IndexBuf + *g_IndexBuf - ListGetCurrentRow(pList)));
ApSetMode(AP_MODE_VIEW);
ApExit(AP_MODE_VIEW);
}
return 0;
case MJ_VK_ESCAPE:
{
MemFree(g_IndexBuf);
MemFree(g_Index_BGround);
g_IndexBuf = NULL;
g_Index_BGround = NULL;
g_PreViewRecID = (UINT16)ApGetSelected();
ApSetSelected(0);
g_IndexStatus = FALSE;
ApSetMode(AP_MODE_VIEW);
ApExit(AP_MODE_VIEW);
}
return 0;
}
break;
}
return WindowHandleEvent((MWindow*)handle, pEvent);
}
/*==========================================================
FUNCTION :DiaryCreateWin_CURVE
DESCRIPTION:创建创建心跳回忆主窗体
INPUTS :
OUTPUTS :
g_Date:隐式输出,保存要显示心跳曲线的月份。
RETURN :窗体句柄
____________________________________________________________
DATE AUTHOR VERSION DESCRIBE
------------------------------------------------------------
2004-08-XX 黄 猛 Ver1.00 Create
==========================================================*/
MWindow* DiaryCreateWin_CURVE(VOID)
{
MWindow* hWnd;
MRect rect;
MToolBar* pToolBar = (MToolBar*)Diary_Curve_ToolBar;
{
/*设置全局变量g_Date,即将要显示心跳曲线的月份*/
DateType minDate, maxDate;
StructDbInfo dbInf;
StructDbData DataTmp;
/*取得最后一篇日记的日期*/
DataTmp.pBuf = MemAlloc(AP_MAX_EDITLEN);
memset(DataTmp.pBuf, 0, AP_MAX_EDITLEN);
DbGetDbInfo(g_DbHandle, &dbInf);
DbRecordRead(g_DbHandle, &DataTmp, 0, KEYFIELD);
maxDate.dateYear = (*(DataTmp.pBuf) - 48)*1000
+ (*(DataTmp.pBuf + 1) - 48)*100
+ (*(DataTmp.pBuf + 2) - 48)*10
+ (*(DataTmp.pBuf + 3) - 48);
maxDate.dateMonth = (*(DataTmp.pBuf+5) - 48)*10
+ (*(DataTmp.pBuf + 6) - 48);
memset(DataTmp.pBuf, 0, AP_MAX_EDITLEN);
DbRecordRead(g_DbHandle, &DataTmp, dbInf.uRecordNum-1, KEYFIELD);
minDate.dateYear = (*(DataTmp.pBuf) - 48)*1000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -