using System;
class classtoday
{
private int year;
private int month;
private static int day=1;
classtoday()
{
DateTime today = DateTime.Now;
this.year = today.Year;
this.month = today.Month;
}
public static void Main()
{
classtoday show = new classtoday();
show.display();
show.view();
Console.Read();
}
public string returnmonth(int month)
{
string[] monthname ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
return monthname [month-1];
}
public void view()
{
string choice;
bool done = true;
do
{
Console.WriteLine("日历菜单");
Console.WriteLine("========================");
Console.WriteLine("1,[>] 下月");
Console.WriteLine("2,[<] 上月");
Console.WriteLine("3,[〈〈] 去年");
Console.WriteLine("4, [〉〉] 明年");
Console.WriteLine("[*] 退出");
Console.Write("输入你的选择:");
choice = Console.ReadLine();
switch (choice.ToLower())
{
case ">": if (month == 12)
{ month = 1; year = year + 1; }
else month += 1;
break;
case "<": if (month == 1)
{ year -= 1; month = 12; }
else month -= 1;
break;
case "<<": year -= 1; break;
case ">>": year += 1; break;
case "*": done = false; break;
default:
Console.WriteLine("无效的选择");
break;
}
if (done)
display();
} while (true);
}
public void display()
{
int []arrday=new int [42];
int dayindex;
DateTime objdate=new DateTime(year,month,day);
Console.WriteLine("{0}年-{1}月", year, returnmonth(month));
int startdayindex = Convert.ToInt32(objdate.DayOfWeek);
for (int i = 0; i < 31; i++)
{
if(i<DateTime.DaysInMonth(year,month))
arrday[startdayindex + i] = i + 1;
}
Console.WriteLine(new String('*',64));
Console.WriteLine("/t周日/t周一/t周二/t周三/t周四/t周五/t周六");
Console.WriteLine(new String('*',64));
for (int j = 0; j < 6; j++)
{
Console.Write("/t");
for (int i = 0; i < 7; i++)
{
if (arrday[j * 7 + i] > 0)
Console.Write("{0,-2}/t", arrday[j * 7 + i]);
else
Console.Write("{0,-2}/t", "");
}
Console.WriteLine();
}
}
}