📄 calendarpage.cpp
字号:
iCompartFlag = 1;
break;
}
}
// 然后查看是否寒食节(4.3-4.5)、清明节(4.4-4.6)、大年夜(腊月二十九或三十)
if (4 == uiCalendarSolarMonth && uiCalendarSolarDay < 10 )
{
unsigned int iFirstJQTemp = GetFirstSolarTerm();
if ( iFirstJQTemp-1 == uiCalendarSolarDay )
{
if ( 1 == iCompartFlag )
{
//_tcscat(clunarcalendar, _T(",寒食节"));
strFeast += _T(",寒食节");
}
else
{
//_tcscat(clunarcalendar, _T("寒食节"));
strFeast += _T("寒食节");
iCompartFlag = 1;
}
}
if ( iFirstJQTemp == uiCalendarSolarDay )
{
if (1 == iCompartFlag )
{
//_tcscat(clunarcalendar, _T(",清明节"));
strFeast += _T(",清明节");
}
else
{
//_tcscat(clunarcalendar, _T("清明节"));
strFeast += _T("清明节");
iCompartFlag = 1;
}
}
}
// 阴历二十九的时候,判断是否大年三十
if (12 == uiCalendarLunarMonth && 29 == uiCalendarLunarDay )
{
unsigned int uiYearFlag = yearchangetable[uiCalendarLunarYear - BEGIN_YEAR];
if ( (uiYearFlag & 0x10) <= 0 )
{
if (1 == iCompartFlag)
{
//_tcscat(clunarcalendar, _T(",除夕"));
strFeast += _T(",除夕");
}
else
{
//_tcscat(clunarcalendar, _T("除夕"));
strFeast += _T("除夕");
iCompartFlag = 1;
}
}
}
if (12 == uiCalendarLunarMonth && 30 == uiCalendarLunarDay )
{
if ( 1 == iCompartFlag )
{
//_tcscat(clunarcalendar, _T(",除夕"));
strFeast += _T(",除夕");
}
else
{
//_tcscat(clunarcalendar, _T("除夕"));
strFeast += _T("除夕");
iCompartFlag = 1;
}
}
// 添加上外国节日
iTemp = uiCalendarSolarMonth*100 + uiCalendarSolarDay;
for ( int j = 0; j < WORLD_FEAST_COUNT; j++)
{
if (iTemp == iWorldFeastNum[j])
{
// 如果前面已经有节日了
if (1 == iCompartFlag )
{
//_tcscat(clunarcalendar, _T(","));
strFeast += _T(",");
}
// 显示文本加上该节日
//_tcscat(clunarcalendar, wcWorldFeastName[j]);
strFeast += wcWorldFeastName[j];
iCompartFlag = 1;
//break;
}
}
if ( strFeast.GetLength() > 15 )
{
strLunarCalendar += strFeast.Left(15);
//strLunarCalendar += _T("\r\n");
//strLunarCalendar += _T(" ");
strLunarCalendar += strFeast.Right(strFeast.GetLength() - 15);
}
else
{
strLunarCalendar += strFeast;
}
if (strLunarCalendar.GetLength() > 0)
{
m_sticLunar.SetWindowText(strLunarCalendar);
}
else
{
m_sticLunar.SetWindowText(_T("不能显示阴历信息"));
}
return 0;
}
/******************************************************************************
* 函数名称: GetLunarDate
* 功能描述: 获得指定阳历日期的阴历日期
* 访问的表: 无
* 修改的表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 0:成功;-1:失败
* 其它说明:
* 修改日期 版本号 修改人 修改内容
* ---------------------------------------------------------
* 2006/11/30 V1.0 Dragon Cai 创建该函数
******************************************************************************/
int CCalendarPage::GetLunarDate(void)
{
unsigned int itotaldays = 0; // 存放开始日期到选定日期的总天数
unsigned int iyearnum = 0; // 计算阴历时用,计算间隔的年数
unsigned int idaynum = 0;
// 先计算间隔的所有年的天数
for ( unsigned int i = BEGIN_YEAR; i < uiCalendarSolarYear; i++ )
{
if ( (0 == (i % 4) && i % 100 != 0) || 0 == (i % 400) )
{
itotaldays += 366;
}
else
{
itotaldays += 365;
}
}
// 计算选中年的间隔月的天数
for ( unsigned int j = 1; j < uiCalendarSolarMonth; j++ )
{
switch ( j )
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
itotaldays += 31;
break;
}
case 2:
{
// 判断时候闰年
if ( (0 == (uiCalendarSolarYear % 4) && uiCalendarSolarYear % 100 != 0)
|| 0 == (uiCalendarSolarYear % 400))
{
itotaldays += 29;
}
else
{
itotaldays += 28;
}
break;
}
case 4:
case 6:
case 9:
case 11:
{
itotaldays += 30;
break;
}
}// end of switch
}// end of for
// 输入日期与1901-01-01的间隔天数计算出来了
itotaldays += uiCalendarSolarDay - 1;
// 如果是1901年要单独算
if ( uiCalendarSolarYear == BEGIN_YEAR && itotaldays < 49 )
{
uiCalendarLunarYear = BEGIN_YEAR - 1;
uiCalendarLunarMonth = 11 + itotaldays / 19;
uiCalendarLunarDay = 11 + itotaldays - 29*(itotaldays / 19);
return -1;
}
// 减去阴历的1901年以前的天数
itotaldays -= 49;
unsigned int iyear; // 存放某一年的阴历特征字
unsigned int imonth = 0; // 存放每年的月份
unsigned int ileapmonth = 0; // 存放闰月的月份,0表示没有闰月
int isign = -1; // 存放闰月的大小月标志
unsigned int idaytemp = 0; // 存放每月的天数
int iflagtemp; // 用来判断当前的日子还够不够减,如果不够减就
// 通过判断该标志位跳出循环
while ( itotaldays >= 0 )
{
iyear = yearchangetable[iyearnum];
ileapmonth = iyear & 0x0f; // 取出闰月的月份
iflagtemp = 0;
// 判断是否有闰月
if ( ileapmonth > 0 )
{
isign = (iyear & 0x10000) > 0 ? 1:0; // 取出闰月的月大小标志
for ( imonth = 1; imonth < 13; imonth++ )
{
idaytemp = 29 + (((0x10000 >> imonth) & iyear) > 0 ? 1:0);
if ( idaytemp > itotaldays )
{
iflagtemp = 1;
break;
}
itotaldays -= idaytemp;
if ( imonth == ileapmonth ) // 本月是闰月
{
ileapmonthflag = ileapmonth; // 标志算到了闰月
idaytemp = 29 + isign;
if ( idaytemp > itotaldays )
{
iflagtemp = 1;
break;
}
itotaldays -= idaytemp;
// 闰月的日子已经减掉了,说明对应的月份不是闰月
ileapmonthflag = 0;
}
}// end of for(imonth) 减完了一年的日子
}// end of if( ileapmonth > 0 )
else
{
for ( imonth = 1; imonth < 13; imonth++ )
{
idaytemp = 29 + (((0x10000 >> imonth) & iyear) > 0 ? 1:0);
if ( idaytemp > itotaldays )
{
iflagtemp = 1;
break;
}
itotaldays -= idaytemp;
idaytemp = 0;
}
}
if ( 1 == iflagtemp)
{
break;
}
iyearnum++;
}// end of while
uiCalendarLunarYear = BEGIN_YEAR + iyearnum;
uiCalendarLunarMonth = imonth;
uiCalendarLunarDay = itotaldays + 1;
return 0;
}
/******************************************************************************
* 函数名称: GetSecondSolarTerm
* 功能描述: 获得指定阳历月的第二个节气的日子
* 访问的表: 无
* 修改的表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 指定阳历月的第二个节气的日子
* 其它说明: 用到了函数头部定义的阳历年、月和常量数据表
* 修改日期 版本号 修改人 修改内容
* ---------------------------------------------------------
* 2006/11/30 V1.0 Dragon Cai 创建该函数
******************************************************************************/
int CCalendarPage::GetSecondSolarTerm()
{
unsigned int done_index;
unsigned int solar_term;
done_index = 0;
while (uiCalendarSolarYear-BEGIN_YEAR
>= calendar_solar_term_year_02[uiCalendarSolarMonth - 1][done_index])
{
done_index++;
}
solar_term = calendar_solar_term_table_02[uiCalendarSolarMonth - 1]
[4*done_index + uiCalendarSolarYear%4];
if ( (171 == uiCalendarSolarYear) && (3 == uiCalendarSolarMonth) )
solar_term = 21;
if ( (181 == uiCalendarSolarYear) && (5 == uiCalendarSolarMonth) )
solar_term = 21;
return(solar_term);
}
/******************************************************************************
* 函数名称: GetFirstSolarTerm
* 功能描述: 获得指定阳历月的第一个节气的日子
* 访问的表: 无
* 修改的表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 指定阳历月的第一个节气的日子
* 其它说明: 用到了函数头部定义的阳历年、月和常量数据表
* 修改日期 版本号 修改人 修改内容
* ---------------------------------------------------------
* 2006/11/30 V1.0 Dragon Cai 创建该函数
******************************************************************************/
int CCalendarPage::GetFirstSolarTerm()
{
unsigned int done_index = 0;
unsigned int solar_term;
while ( uiCalendarSolarYear-BEGIN_YEAR >= calendar_solar_term_year_01[uiCalendarSolarMonth - 1][done_index])
{
done_index++;
}
solar_term = calendar_solar_term_table_01[uiCalendarSolarMonth - 1][4*done_index + uiCalendarSolarYear%4];
if ( (121 == uiCalendarSolarYear)&&(4 == uiCalendarSolarMonth) )
solar_term = 5;
if ( (132 == uiCalendarSolarYear)&&(4 == uiCalendarSolarMonth) )
solar_term = 5;
if ( (194 == uiCalendarSolarYear)&&(6 == uiCalendarSolarMonth) )
solar_term = 6;
return(solar_term);
}
/**
*************************************************************
* 函 数 名: OnBtnOk()
* 描 述: 用户点击OK按钮(修改系统日期<年、月、日>)时触发该事件
* 数 据 库: 无
* 数据库表: 无
* 输入参数: 无
* 输出参数: 无
* 返 回 值: 无
* 创 建 人: 袁军
* 日 期: 2007/06/01
* 修改记录:
* 修改人 修改日期 修改描述
*************************************************************
*/
void CCalendarPage::OnBtnOk()
{
//获取系统信息
TIME_ZONE_INFORMATION sysTime;
GetSystemTime(&sysTime.DaylightDate);
//将用户选择的日期信息赋值给sysTime的相应变量
sysTime.DaylightDate.wYear = m_iYear;
sysTime.DaylightDate.wMonth = m_iMonth;
sysTime.DaylightDate.wDay = m_iDay;
//设置系统信息
SetSystemTime(&sysTime.DaylightDate);
/*
TIME_ZONE_INFORMATION sysTime;
GetSystemTime(&sysTime.DaylightDate);
sysTime.DaylightDate.wYear = 2006;
sysTime.DaylightDate.wMonth = 11;
sysTime.DaylightDate.wDay = 23;
sysTime.DaylightDate.wHour = sysTime.DaylightDate.wHour;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -