📄 monthex.cs
字号:
using System;
namespace Opportune.CalEx
{
class MonthEx
{
public enum IN_WHICH_MONTH
{
IN_PREV_MONTH = -1,
IN_CURRENT_MONTH = 0,
IN_NEXT_MONTH = 1
}
public struct MyDate
{
public DateTime date;
public IN_WHICH_MONTH month;
}
static public int DATECOUNT = 42;
private MyDate[] _dates;
private int _year;
private int _month;
public MonthEx(int year, int month)
{
DateTime first;
try
{
first = new DateTime(year, month, 1);
}
catch (Exception exc)
{
throw exc;
}
_year = year;
_month = month;
_dates = new MyDate[DATECOUNT];
int i, c;
if (first.DayOfWeek == DayOfWeek.Monday)
c = 1;
else if (first.DayOfWeek == DayOfWeek.Tuesday)
c = 2;
else if (first.DayOfWeek == DayOfWeek.Wednesday)
c = 3;
else if (first.DayOfWeek == DayOfWeek.Thursday)
c = 4;
else if (first.DayOfWeek == DayOfWeek.Friday)
c = 5;
else if (first.DayOfWeek == DayOfWeek.Saturday)
c = 6;
else
c = 7;
for (i = 0; i < c; i++)
{
TimeSpan aaa = new TimeSpan(c - i, 0, 0, 0, 0);
_dates[i].date = first - aaa;
_dates[i].month = IN_WHICH_MONTH.IN_PREV_MONTH;
}
for (; i < 42; i++)
{
TimeSpan bbb = new TimeSpan(i - c, 0, 0, 0, 0);
_dates[i].date = first + bbb;
if (_dates[i].date.Month == month)
_dates[i].month = IN_WHICH_MONTH.IN_CURRENT_MONTH;
else
_dates[i].month = IN_WHICH_MONTH.IN_NEXT_MONTH;
}
}
public int Year
{
get
{
return _year;
}
}
public int Month
{
get
{
return _month;
}
}
public MyDate[] Dates
{
get
{
return _dates;
}
}
public MonthEx PrevMonth
{
get
{
DateTime t = new DateTime(_year, _month, 1);
TimeSpan s = new TimeSpan (1,0,0,0);
DateTime d = t - s;
return new MonthEx(d.Year, d.Month);
}
}
public MonthEx NextMonth
{
get
{
DateTime t = new DateTime(_year, _month, 1);
TimeSpan s = new TimeSpan(31, 0, 0, 0);
DateTime d = t + s;
return new MonthEx(d.Year, d.Month);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -