📄 apptalm.c
字号:
#include <math.h>
#include <string.h>
#include "asixapp.h"
#include "asix_lb.h"
#include "bitmap.h"
#include "schemedb.h"
#include "scheme.h"
#include "schfunc.h"
#include "schdb.h"
#include "ApptAlm.H"
static TIMER_LIST_STRU *TIMER_LIST = NULL; //定时器列表
static U8 appoint_box_num = 1 ; //未确认的约会提醒数
static void Appoint_Alarm( void );
static void CreateTimerList( void );
static void AlarmTimerProc( TIMER_LIST_STRU *pt_timer );
static void AddTimer( U32 scheme_index, U8 reserved );
static void DelTimer( U32 scheme_index, U8 reserved );
static U32 CountTime( TIME_STRU *time );
static U8 IsRenNian( void );
static LOCALSEARCHLIST* GetCurSchemeList( DBLACB *lacb );
static SCHEME_STRU* ReadSchemeRecord( DBLACB *lacb, U32 index, U8 reserved);
static STATUS CreateSchemeRcord( DBLACB *lacb, SCHEME_STRU *scheme_stru, U8 reversed );
static STATUS ModifySchemeRecord( DBLACB *lacb, U32 index, SCHEME_STRU *scheme_stru, U8 reserved );
static STATUS DelSchemeRecord( DBLACB *lacb, U32 index, U8 reserved );
//**********************TASKDESCRIPTION*********************
DWORD appoint_alarm_stk[STACK_SIZE];
TASKDESCRIPTION AppointAlarmTskDesp =
{"约会提醒", ASIX_SERVICE, NOT_IN_ANYGROUP, NULL, STACK_SIZE, 1, PHY_LCD_W, PHY_LCD_H, Appoint_Alarm, SERVICE_PRI};
TASKDESCRIPTIONLIST AppointAlarmTskDespLst =
{NULL, NULL, &AppointAlarmTskDesp, APPTALMSERVER_ID, appoint_alarm_stk};
//**********************END TASKDESCRIPTION****************
extern DWORD EveryDayTimer;
void Appoint_Alarm( void )
{
MSG msg;
MSG switchmsg;
U8 *caption="7:30AM"; //假设标题栏为时间信息
U8 *content="您要阅读吗?"; //假设content栏为约会提醒信息
U32 scheme_index; //日程安排(约会)在数据库中的索引号
// U32 timer_id;
TIMER_LIST_STRU *pt_timer, *pre_timer, *select_timer;
CreateTimerList( ); //得到当天需提醒的定时器列表
while( 1 )
{
ASIXGetMessage( &msg, NULL, 0, 0 );
switch( msg.message )
{
case WM_ALARM:
scheme_index = msg.lparam; //整个约会记录中的索引号
switch( msg.wparam )
{
case ADD_TIMER:
AddTimer( scheme_index, 0 );
break;
case DEL_TIMER:
DelTimer( scheme_index, 0 );
break;
case MODIFY_TIMER:
DelTimer( scheme_index, 0 ); //删除原来的定时器
AddTimer( scheme_index, 0 ); //添加新的定时器
break;
}
break;
case WM_TIMER:
if( msg.lparam == EveryDayTimer ) //换天的定时器
{
//清掉前一天所有定时器
pre_timer = pt_timer = TIMER_LIST;
while( pt_timer != NULL )
{
pre_timer = pt_timer->next;
FreeTimer( pt_timer->timer_id );
Lfree( pt_timer );
pt_timer = pre_timer;
}
TIMER_LIST = NULL;
CreateTimerList( ); //重新计算新一天的定时器列表
}else{ //当天的定时器提醒
pre_timer = pt_timer = TIMER_LIST;
while( pt_timer != NULL ) //找到到期的定时器
{
if( msg.lparam == pt_timer->timer_id )
{
select_timer = pt_timer;
break;
}else{
pre_timer = pt_timer;
pt_timer = pt_timer->next;
}
}
//根据timer_id从定时器列表中找出该项
if( pt_timer != NULL )
{
if( pt_timer == TIMER_LIST ) //找到的是链表头
{
TIMER_LIST = pt_timer->next;
}else
// if( pt_timer->next != NULL )
{
pre_timer->next = pt_timer->next;
}
}
if( select_timer != NULL )
{
AlarmTimerProc( select_timer );
switchmsg.messageType = ASIX_MESSAGE; //切换窗口
switchmsg.message = SM_SWITCH;
switchmsg.lparam = APPTALMSERVER_ID;
switchmsg.wparam = SWAP_TO_BACKGROUND;
SysSendMessage( SYSTASK_ID, &switchmsg );
}
}
break;
default:
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
}
/***********************************************************************************************/
//约会提醒框
void APPOINT_ALARM_BOX( char *caption, char *content )
{
U32 mainwin;
U32 infor , box_num;
// U32 read, cancel;
U32 ok;
U8 quit = 0;
U8 box_num_str[30]="目前共有1条未确认的约会!";
MSG msg;
U32 hgc;
U32 hbmp;
// MSG read_appoint;
MSG switchmsg;
TIMER_LIST_STRU *pt_timer, *pre_timer, *select_timer = NULL;
sprintf( box_num_str, "目前有%u条约会提醒!", appoint_box_num );
mainwin = CreateWindow(WNDCLASS_WIN, caption, WS_CAPTION|WS_BORDER|WS_POPUP, 0, 60, 159, 120, 0, 0, NULL);
box_num = CreateWindow(WNDCLASS_STATIC, box_num_str, WS_CHILD|SS_TEXT, 30, 85, 125, 20, mainwin, 0, NULL);
infor = CreateWindow(WNDCLASS_STATIC, content, WS_CHILD|SS_TEXT, 30, 110, 125, 40, mainwin, 0, NULL);
// read = CreateWindow(WNDCLASS_BUTTON, "阅读", WS_CHILD|BS_BOARD_REGULAR, 30, 140, 40, 20, mainwin, 0, NULL);
// cancel = CreateWindow(WNDCLASS_BUTTON, "取消", WS_CHILD|BS_BOARD_REGULAR, 90, 140, 40, 20, mainwin, 0, NULL);
ok = CreateWindow(WNDCLASS_BUTTON, "确定", WS_CHILD|BS_BOARD_REGULAR, 60, 155, 40, 20, mainwin, 0, NULL);
hgc = GetGC();
hbmp = LoadBitmap(question_icon, NULL);
DisplayBMP(hgc,5,95,hbmp);
FreeBitmap(hbmp);
PopUpWindow( mainwin, 0 );
while(!quit)
{
ASIXGetMessage(&msg,NULL,0,0);
switch (msg.message )
{
case WM_COMMAND:
/* if(msg.lparam == read)
{
//发"阅读约会"的消息给约会任务
appoint_box_num = 1 ; //确认后,提醒框的个数重新置1
quit = 1;
}
else if( msg.lparam == cancel )
{
//发消息给主界面
appoint_box_num = 1 ; //确认后,提醒框的个数重新置1
quit = 1 ;
}
*/
if( msg.lparam == ok )
{
//发消息给主界面
appoint_box_num = 1 ; //确认后,提醒框的个数重新置1
quit = 1 ;
}
break;
case WM_TIMER:
if( msg.lparam == EveryDayTimer ) //换天的定时器
{
//清掉前一天所有定时器
pre_timer = pt_timer = TIMER_LIST;
while( pt_timer != NULL )
{
pre_timer = pt_timer->next;
FreeTimer( pt_timer->timer_id );
Lfree( pt_timer );
pt_timer = pre_timer;
}
TIMER_LIST = NULL;
CreateTimerList( ); //重新计算新一天的定时器列表
}else{ //当天的定时器提醒
pre_timer = pt_timer = TIMER_LIST;
while( pt_timer != NULL ) //找到到期的定时器
{
if( msg.lparam == pt_timer->timer_id )
{
appoint_box_num ++;
select_timer = pt_timer;
break;
}else{
pre_timer = pt_timer;
pt_timer = pt_timer->next;
}
}
//根据timer_id从定时器列表中找出该项
if( pt_timer != NULL )
{
if( pt_timer == TIMER_LIST ) //找到的是链表头
{
TIMER_LIST = pt_timer->next;
}else
// if( pt_timer->next != NULL )
{
pre_timer->next = pt_timer->next;
}
}
if( select_timer != NULL )
{
AlarmTimerProc( select_timer );
switchmsg.messageType = ASIX_MESSAGE; //切换窗口
switchmsg.message = SM_SWITCH;
switchmsg.lparam = APPTALMSERVER_ID;
switchmsg.wparam = SWAP_TO_BACKGROUND;
SysSendMessage( SYSTASK_ID, &switchmsg );
}
}
break;
case WM_QUIT:
//发消息给主界面
appoint_box_num = 1 ; //确认后,提醒框的个数重新置1
quit = 1;
break;
case WM_ALARM: //将新的约会提醒消息发给约会提醒任务
//发消息给主界面
appoint_box_num++; //提醒框的个数加1;
SysSendMessage(APPTALMSERVER_ID, &msg);
break;
default:
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow(mainwin);
}
/***********************************************************************************************/
//得到当天需提醒的定时器列表
void CreateTimerList( void )
{
U16 i;
TIMER_LIST_STRU *pt_timer; //指向定时器列表的指针
char time_str[SCHEME_TIME_LEN] = {0};
LOCALSEARCHLIST *TODAY_SCHEME_LIST = NULL; //当天约会列表
DBLACB *lacb; //约会提醒数据库的局部访问控制块
// CreateDataBase(); //创建数据库文件
lacb = LinkDataBase( SCHEME_DATA_BASE ); //链接约会提醒数据库
//得到当天约会列表
TODAY_SCHEME_LIST = GetCurSchemeList( lacb );
//释放旧的定时器列表
pt_timer = TIMER_LIST;
while( pt_timer != NULL )
{
TIMER_LIST = TIMER_LIST->next;
Lfree( pt_timer );
pt_timer = TIMER_LIST;
}
//创建新的定时器列表
for( i = 0; i < TODAY_SCHEME_LIST->num; i++ )
AddTimer( TODAY_SCHEME_LIST->head[i].index, 0 ); //加入到定时器列表中
DetachDataBase( lacb );
}
/***********************************************************************************************/
//定时期到期处理函数
//void AlarmTimerProc( U32 timer_id )
void AlarmTimerProc( TIMER_LIST_STRU *pt_timer )
{
// U16 day;
U8 day_num[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
SCHEME_STRU *scheme_stru;
TIME_STRU conversion_time;
U8 flag = 0; //时间标志
CHAR i, count, k;
U16 total_num = 0;
char *alarm_repeat_num;
DBLACB *lacb; //约会提醒数据库的局部访问控制块
lacb = LinkDataBase( SCHEME_DATA_BASE ); //链接约会提醒数据库tttttttt
scheme_stru = ReadSchemeRecord( lacb, pt_timer->scheme_index, 0 );//从当天的约会列表中读取第i条记录
if( ( *(scheme_stru->type) == SCHEME_NO_MATURITY ) //当前提醒的到期标志为未到期
&& ( *(scheme_stru->alarm_type) != DO_NOT_ALARM ) ) //当前提醒需提醒
{
// APPOINT_ALARM_BOX( scheme_stru->name, scheme_stru->content ); //弹出警告框ttttttt
*(scheme_stru->type) = SCHEME_MATURITY; //更新到期标志
// CreateSchemeRcord( lacb, scheme_stru, 0 );//把当前到期提醒的记录保存, 添加新的提醒记录
//更新提醒次数
alarm_repeat_num = (char *)(scheme_stru->alarm_repeat_num);
count = (CHAR)strlen( alarm_repeat_num );
for( k = 0, i = (count-1); i >= 0; i-- )
{
total_num += (U16)( ( *(alarm_repeat_num + i) & 0x0f ) * pow( 10, k ) );
k++;
}
total_num--;
if( total_num == 0 )
{
ModifySchemeRecord( lacb, pt_timer->scheme_index, scheme_stru, 0 );
}else{//提醒次数不为0
CreateSchemeRcord( lacb, scheme_stru, 0 );//把当前到期提醒的记录保存, 添加新的提醒记录
if( total_num/1000 == 0 ) //计算提醒次数
{
if( total_num/100 == 0 )
{
if( total_num/10 == 0 )
{
if( total_num == 0 )
{
*(scheme_stru->alarm_repeat_num) = '0';
}else{
*(scheme_stru->alarm_repeat_num) = (U8)( total_num + 0x30 );
}
*(scheme_stru->alarm_repeat_num+1) = '\0';
}else{
*scheme_stru->alarm_repeat_num = (U8)( total_num/10 + 0x30 );
*(scheme_stru->alarm_repeat_num+1) = (U8)( total_num%10 + 0x30 );
*(scheme_stru->alarm_repeat_num+2) = '\0';
}
}else{
*scheme_stru->alarm_repeat_num = (U8)( total_num/100 + 0x30 );
*(scheme_stru->alarm_repeat_num+1) = (U8)( ( total_num%100 )/10 + 0x30 );
*(scheme_stru->alarm_repeat_num+2) = (U8)( ( total_num%100 )%10 + 0x30 );
*(scheme_stru->alarm_repeat_num+3) = '\0';
}
}else{
*scheme_stru->alarm_repeat_num = (U8)( total_num/1000 + 0x30 );
*(scheme_stru->alarm_repeat_num+1) = (U8)( ( total_num%1000 )/100 + 0x30 );
*(scheme_stru->alarm_repeat_num+2) = (U8)( ( ( total_num%1000 )%100 )/10 + 0x30 );
*(scheme_stru->alarm_repeat_num+3) = (U8)( ( ( total_num%1000 )%100 )%10 + 0x30 );
*(scheme_stru->alarm_repeat_num+4) = '\0';
}
*(scheme_stru->type) = SCHEME_NO_MATURITY; //更新到期标志
TimetoInt( (TIME_STRU *)scheme_stru->time, &conversion_time );
switch( *(scheme_stru->alarm_mode) )
{
case BY_YEAR:
conversion_time.year += 1;
break;
case BY_MONTH:
if( conversion_time.month == 12 )
{
conversion_time.month = 1;
conversion_time.year += 1;
}else
conversion_time.month += 1;
break;
case BY_WEEK:
if( ( conversion_time.month == 2 ) && ( IsRenNian() == TRUE ) )
{
if( conversion_time.day > day_num[conversion_time.month] + 1 - 7 )
{
conversion_time.day = conversion_time.day + 7 - day_num[conversion_time.month] - 1;
conversion_time.month += 1;
}else
conversion_time.day += 7;
}else{
if( conversion_time.day > day_num[conversion_time.month]-7)
{
conversion_time.day = conversion_time.day+7-day_num[conversion_time.month];
// day = day+7-day_num[conversion_time.month];
if(conversion_time.month==12)
{
conversion_time.month=1;
conversion_time.year+=1;
}else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -