private void FillPanelMonth(int firstDayInWeek, int endMontyDay, int year, int month)
{
try
{
DateTime today = DateTime.Today;
Color cWeekdays = Color.Navy; //周一到周五
Color cWeekend = Color.Red; //周六周日
Color cNotHoliday = Color.DarkGray; //农历非节日
Color cIsHoliday = Color.Red; //农历节日
Color cSolarTerm = Color.Blue; //农历二十四节气
Color cTodayBG = Color.LightSalmon;//当天背景色
DataTable dtMonth = _data.GetRiliDataByMonth(year, month);
int num = 1;
string strMonth = string.Empty;
string strDay = string.Empty;
string strHoliday = string.Empty;
for (int j = 0; j < 6; j++)
{
for (int i = 0; i < 7; i++)
{
if (j == 0 && i < firstDayInWeek) //找到一号是星期几
{
continue;
}
else
{
if (num > endMontyDay) //超过这个月的最大天数,退出
{
break;
}
DateTime date = DateTime.Parse(year + "-" + month + "-" + num);
TimeSpan ts = date - today;
strMonth = ChineseDate.GetMonth(date);
strDay = ChineseDate.GetDay(date);
string strJieqi = ChineseDate.GetSolarTerm(date);
string strCHoliday = ChineseDate.GetChinaHoliday(date);
strHoliday = strJieqi + (string.IsNullOrEmpty(strJieqi) ? "" : " ")
+ strCHoliday + (string.IsNullOrEmpty(strCHoliday) ? "" : " ")
+ ChineseDate.GetHoliday(date);
if (i > 0 && i < 6) //周一到周五
{
//if (strHoliday.Length > 3)
if (!string.IsNullOrEmpty(strJieqi))
{
iDays[j, i].iOldText = strHoliday;
if (string.IsNullOrEmpty(strJieqi))
{
iDays[j, i].iOldColor = cIsHoliday;
}
else
{
iDays[j, i].iOldColor = cSolarTerm;
}
}
else
{
iDays[j, i].iOldText = strDay == "初一" ? strMonth : strDay;
iDays[j, i].iOldColor = cNotHoliday;
}
iDays[j, i].iNewText = num.ToString(CultureInfo.InvariantCulture);
iDays[j, i].iNewColor = cWeekdays;
}
else
{
//if (strHoliday.Length > 3)
if (!string.IsNullOrEmpty(strJieqi))
{
iDays[j, i].iOldText = strHoliday;
if (string.IsNullOrEmpty(strJieqi))
{
iDays[j, i].iOldColor = cIsHoliday;
}
else
{
iDays[j, i].iOldColor = cSolarTerm;
}
}
else
{
iDays[j, i].iOldText = strDay == "初一" ? strMonth : strDay;
iDays[j, i].iOldColor = cNotHoliday;
}
iDays[j, i].iNewText = num.ToString(CultureInfo.InvariantCulture);
iDays[j, i].iNewColor = cWeekend;
}
iDays[j, i].Jieri = strHoliday;
DataRow[] dr = dtMonth.Select(string.Format("Yangli = '{0}'", date.ToString("yyyy年M月d日")));
if (dr != null && dr.Length == 1)
{
iDays[j, i].Yangli = dr[0]["Yangli"].ToString() + " " + dr[0]["Xingqi"].ToString();
iDays[j, i].Nongli = dr[0]["Nongli"].ToString();
iDays[j, i].Zhigan = dr[0]["Zhigan"].ToString();
iDays[j, i].Xingzuo = dr[0]["Xingzuo"].ToString();
iDays[j, i].Yi = dr[0]["Yi"].ToString();
iDays[j, i].Ji = dr[0]["Ji"].ToString();
}
if (ts.Days == 0)
{
iDays[j, i].BackColor = cTodayBG;
SetDateDetail(iDays[j, i]);
}
iDays[j, i].Visible = true;
num++;
}
}
}
}
catch (Exception ex)
{
log.WriteLog(ex.ToString());
}
}