广工C#与NET课程设计.docx

上传人:b****5 文档编号:5016504 上传时间:2022-12-12 格式:DOCX 页数:27 大小:538.41KB
下载 相关 举报
广工C#与NET课程设计.docx_第1页
第1页 / 共27页
广工C#与NET课程设计.docx_第2页
第2页 / 共27页
广工C#与NET课程设计.docx_第3页
第3页 / 共27页
广工C#与NET课程设计.docx_第4页
第4页 / 共27页
广工C#与NET课程设计.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

广工C#与NET课程设计.docx

《广工C#与NET课程设计.docx》由会员分享,可在线阅读,更多相关《广工C#与NET课程设计.docx(27页珍藏版)》请在冰豆网上搜索。

广工C#与NET课程设计.docx

广工C#与NET课程设计

1.

NET结构与C#程序设计

课程设计

题目年度月历备忘录

学院计算机学院

专业计算机科学与技术

年级班别12级4班

学号3112005901

学生姓名柏石先

指导教师杨劲涛

 

 

目录

一、软件说明:

3

功能说明3

解决什么样的实际问题3

性能说明3

程序类型说明3

二、软件设计4

软件整体结构图及模块划分4

在VS的“解决方案资源管理器”中的文件说明;4

各模块对应的主要对象或方法;5

数据库设计或数据文件说明;9

算法分析10

三、测试13

测试用例列表;13

软件运行截图;14

测试情况分析17

四、小结17

五、附录18

用到的第三方控件或组件说明18

程序的主要代码18

一、软件说明:

功能说明

(1)实现万年历的基本功能,可按年份查看每年的月历。

并且每月的日期排布作为一个页面显示;

(2)能够正确展示星期、一周一行,红色显示节假日、周末。

并且加入了更符合实际需求的农历显示和中国的节假日,二十四节气以及传统节日的显示等等。

(3)在月历显示界面,鼠标点击任何一天的对应的号码,都可以打开一个小文本框,作简单记事,所记内容存入本地的文件,并且按记录的日期进行命名,方便用户进行查找。

(4)如果某天已经有了记事内容,可以提供直接查看以往记录的内容并且提供及时修改,及时保存,便再次查看的功能。

解决什么样的实际问题

在日历的原有功能的基础上,增加了农历显示,传统节假日和节气的提示。

也整合了备忘录的功能。

做到了简洁明了的方便用户记录每一天的备忘,并且能够快捷的方便用户修改和查看。

性能说明

能较快的响应用户的操作,并且实时刷新界面的显示内容。

窗体的切换基本流畅,画面过度无明显卡顿。

数据保存基本可靠,整体流程可行性高,对系统性能要求不高,无需网络和数据库的的连接。

程序类型说明

是单机版的windows窗体程序,文件是以.exe结尾的可执行程序。

二、软件设计

软件整体结构图及模块划分

在VS的“解决方案资源管理器”中的文件说明;

解决方案管理器相关文件说明:

Program.cs则是程序的入口

DateSources目录下的则是资源数据文件和展示的中间对象

CalendarException.cs是自定义的月历的异常处理机制的异常类

ChineseDate.cs是对农历处理的类,主要是转化公历转化为农历

ChineseCalender.cs是处理节日的类,主要是根据日期计算节假日和节气

Calendar.cs是月历显示已经交互操作的窗体代码

show.cs是备忘录编辑和保存的操作的窗体代码

各模块对应的主要对象或方法;

在panel2容器里面绘制自定义的日历控件,主要功能是绘制出5行7列的日历网格布局,再让布局网格中加载根据选择的当前年份和月份的日期数据。

也就是改一个月的日期排序。

按照计算每一天的只是星期几进行相应位置的填充。

privatevoidpanel2_Paint(objectsender,PaintEventArgse)

{

intnum;

Graphicsgraphics=e.Graphics;

Penpen=newPen(Color.Blue,2f);

Penpen2=newPen(Color.FromArgb(0xff,0xeb,0xd3),1f);

TextureBrushbrush=newTextureBrush(Resources.hehe,WrapMode.TileFlipXY);

graphics.FillRectangle(brush,0,0,750,0x1db);

graphics.FillRectangle(newSolidBrush(Color.White),5,40,740,400);

SolidBrushbrush2=newSolidBrush(Color.FromArgb(50,0xff,0xf7,0xf1));

graphics.FillRectangle(brush2,10,0x2d,560,30);

graphics.DrawLine(pen2,10,0x2d,570,0x2d);

graphics.DrawLine(pen2,10,0x4b,570,0x4b);

for(num=1;num<7;num++)

{

graphics.DrawLine(pen2,10,0x4b+(60*num),570,0x4b+(60*num));

}

for(num=0;num<8;num++)

{

graphics.DrawLine(pen2,10+(80*num),0x2d,10+(80*num),0x1b3);

}

SolidBrushbrush3=newSolidBrush(Color.Gray);

SolidBrushbrush4=newSolidBrush(Color.Chocolate);

graphics.DrawString("日",newFont("微软雅黑",12f),brush4,(float)35f,(float)50f);

graphics.DrawString("一",newFont("微软雅黑",12f),brush3,(float)115f,(float)50f);

graphics.DrawString("二",newFont("微软雅黑",12f),brush3,(float)195f,(float)50f);

graphics.DrawString("三",newFont("微软雅黑",12f),brush3,(float)275f,(float)50f);

graphics.DrawString("四",newFont("微软雅黑",12f),brush3,(float)355f,(float)50f);

graphics.DrawString("五",newFont("微软雅黑",12f),brush3,(float)435f,(float)50f);

graphics.DrawString("六",newFont("微软雅黑",12f),brush4,(float)515f,(float)50f);

if(this.flag)

{

his.GetWeekInfo(refthis.weekOfFirstDay,refthis.daysOfMonth,this.dtNow.Year,this.dtNow.Month,1);

this.DrawDateNum(this.weekOfFirstDay,this.daysOfMonth,this.dtNow.Year,this.dtNow.Month);

}

}

设置日历控件的鼠标单次点击事件,并且获取当前点击的日期。

并进行备忘录模块的调转。

privatevoidpanel2_MouseClick(objectsender,MouseEventArgse)

{

if(e.Button==MouseButtons.Left)

{

if(((e.X<10)||(e.X>0x23f))||((e.Y<0x4b)||(e.Y>0x1b3)))

{

return;

}

intnum=(e.X-10)/80;

intnum2=(e.Y-0x4b)/60;

if(this.dateArray[num,num2]==null)

{

return;

}

DateTimetime=DateTime.Parse(this.dateArray[num,num2]);

this.dtInfo=time;

intyear=time.Year;

intmonth=time.Month;

intday=time.Day;

stringsendmsg=year+"年"+month+"月"+day;

Formsf=newshow(sendmsg);

sf.Show();

}

//this.panel3.Refresh();

}

//将星期几转成数字表示

privateintConvertDayOfWeek(DayOfWeekdayOfWeek)

{

switch(dayOfWeek)

{

caseDayOfWeek.Sunday:

return1;

caseDayOfWeek.Monday:

return2;

caseDayOfWeek.Tuesday:

return3;

caseDayOfWeek.Wednesday:

return4;

caseDayOfWeek.Thursday:

return5;

caseDayOfWeek.Friday:

return6;

caseDayOfWeek.Saturday:

return7;

default:

return0;

}

}

获取农历日期的方法,运用现在的公历日期时间,计算得到相应的农历日期时间。

publicstaticstringGetChinaDate(DateTimedt)

{

if(dt>china.MaxSupportedDateTime||dt

{//日期范围:

1901年2月19日-2101年1月28日

thrownewException(string.Format("日期超出范围!

必须在{0}到{1}之间!

",

china.MinSupportedDateTime.ToString("yyyy-MM-dd"),china.MaxSupportedDateTime.ToString("yyyy-MM-dd")));

}

stringstr=string.Format("{0}{1}{2}",GetYear(dt),GetMonth(dt),GetDay(dt));

stringstrJQ=GetSolarTerm(dt);

if(strJQ!

="")

{

str+="("+strJQ+")";

}

stringstrHoliday=GetHoliday(dt);

if(strHoliday!

="")

{

str+=""+strHoliday;

}

stringstrChinaHoliday=GetChinaHoliday(dt);

if(strChinaHoliday!

="")

{

str+=""+strChinaHoliday;

}

returnstr;

}

///获取农历月份的方法

publicstaticstringGetMonth(DateTimedt)

{

intyear=china.GetYear(dt);

intiMonth=china.GetMonth(dt);

intleapMonth=china.GetLeapMonth(year);

boolisLeapMonth=iMonth==leapMonth;

if(leapMonth!

=0&&iMonth>=leapMonth)

{

iMonth--;

}

stringszText="正二三四五六七八九十";

stringstrMonth=isLeapMonth?

"闰":

"";

if(iMonth<=10)

{

strMonth+=szText.Substring(iMonth-1,1);

}

elseif(iMonth==11)

{

strMonth+="十一";

}

else

{

strMonth+="腊";

}

returnstrMonth+"月";

}

数据库设计或数据文件说明;

采用了本地文件保存的形式来记录月历的备忘内容。

也就是当用户点击月历的某一天,并且决定保存自己的备忘内容时,程序会先自动检测用户当前电脑环境,之后在预先考虑的位子生成一个存放所有备忘内容的文件夹。

并且会依据日期来自动设定备忘的名字,也就是按日期记录备忘内容。

也就能在按照日期去查找已有记录进行修改保存。

//判断文件路径是否存在,不存在则创建文件夹

if(System.IO.Directory.Exists(@"D:

\")){

if(!

System.IO.Directory.Exists(@"D:

\CalendarNotes"))

{

System.IO.Directory.CreateDirectory(@"D:

\CalendarNotes");//不存在就创建目录

}

path=@"D:

\CalendarNotes\"+time+"日的备忘.txt";

}else

{

if(!

System.IO.Directory.Exists(@"E:

\CalendarNotes"))

{

System.IO.Directory.CreateDirectory(@"E:

\CalendarNotes");//不存在就创建目录

}

path=@"E:

\CalendarNotes\"+time+"日的备忘.txt";

}

文件的保存采用了TXT文本格式,便于用户可以修改,查看记录。

而且txt文本文档支持多种字符编码,减少出现格式错误,字符转换的异常。

StreamWriterwriter=null;

try

{

File.Delete(path);

label1.Text="以下是"+time+"日的备忘内容";

writer=newStreamWriter(path,true,System.Text.Encoding.Default);

for(inti=0;i

writer.WriteLine(richTextBox1.Lines[i]);

}

}

catch(Exceptionex){

MessageBox.Show(ex.Message);

}

finally

{

if(writer!

=null)

{

writer.Close();

}

//if(fs!

=null)fs.Close();

}

MessageBox.Show("保存备忘成功","提示");

this.Close();

算法分析

得到每周信息的算法,也就是得到月历每一行日期排布的算法。

主要思想就是通过解析日期得到位于一年的哪一周的周几。

privatevoidGetWeekInfo(refintweekOfFirstDay,refintdaysOfMonth,intyear=0x76c,intmonth=2,intday=1)

{

DateTimetime=DateTime.Parse(year.ToString(CultureInfo.InvariantCulture)+

"-"+month.ToString(CultureInfo.InvariantCulture)

+"-"+day.ToString(CultureInfo.InvariantCulture));

weekOfFirstDay=(int)time.DayOfWeek;

daysOfMonth=DateTime.DaysInMonth(year,month);

}

这个是自定义月历的控件的绘制日期信息的方法。

主要是要计算出当前月的日期排布以及要绘制出相应位置的日期的具体显示。

包括日期的数字,以及农历日和节假日以及节气的显示。

是程序最重要的算法。

privatevoidDrawDateNum(intfirstDayofWeek,intendMonthDay,intyear,intmonth)

{

DateTimetime=DateTime.Parse(DateTime.Now.ToShortDateString());

Fontfont=newFont("",14f);

SolidBrushbrush=newSolidBrush(Color.Gray);

SolidBrushbrush2=newSolidBrush(Color.Chocolate);

SolidBrushbrush3=newSolidBrush(Color.BurlyWood);

Graphicsgraphics=panel2.CreateGraphics();

intnum=1;

for(inti=0;i<6;i++)

{

for(intj=0;j<7;j++)

{

if((i!

=0)||(j>=firstDayofWeek))

{DateTimetime2;

TimeSpanspan;

if(num>endMonthDay)

{break;

}

stringstr=null;

stringday=null;

stringholiday=null;

strings=null;

if((j>0)&&(j<6))

{

time2=DateTime.Parse(string.Concat(newobject[]

{year,"-",month,"-",num}));

span=(TimeSpan)(time2-time);

this.dateArray[j,i]=time2.ToShortDateString();

if(span.Days==0)

{

graphics.DrawEllipse(newPen(Color.Chocolate,3f),15+(80*j),0x55+(60*i),30,15);

}

str=ChineseDate.GetMonth(time2);

day=ChineseDate.GetDay(time2);

holiday=ChineseDate.GetHoliday(time2);

s=ChineseDate.GetChinaHoliday(time2);

if(holiday!

=null)

{

graphics.DrawString((holiday.Length>3)?

holiday.Substring(0,3):

holiday,newFont("",9f),brush3,(float)(40+(80*j)),(float)(90+(60*i)));

}

if(s!

="")

{

graphics.DrawString(s,newFont("",10f),brush,(float)(0x19+(80*j)),(float)(0x73+(60*i)));

}

else

{

graphics.DrawString((day=="初一")?

str:

day,newFont("",10f),brush,(float)(0x19+(80*j)),(float)(0x73+(60*i)));

}

graphics.DrawString(num.ToString(CultureInfo.InvariantCulture),font,brush,(float)(15+(80*j)),(float)(80+(60*i)));}

else{

time2=DateTime.Parse(string.Concat(newobject[]{year,"-",month,"-",num}));

span=(TimeSpan)(time2-time);

this.dateArray[j,i]=time2.ToShortDateString();

if(span.Days==0)

{

graphics.DrawEllipse(newPen(Color.Chocolate,3f),15+(80*j),0x55+(60*i),30,15);

}

str=ChineseDate.GetMonth(time2);

day=ChineseDate.GetDay(time2);

holiday=ChineseDate.GetHoliday(time2);

s=ChineseDate.GetChinaHoliday(time2);

if(holiday!

=null)

{

graphics.DrawString((holiday.Length>3)?

holiday.Substring(0,3):

holiday,newFont("",9f),brush3,(float)(40+(80*j)),(float)(90+(60*i)));

}

if(s!

=""){

graphics.DrawString(s,newFont("",10f),brush2,(float)(0x19+(80*j)),(float)(0x73+(60*i)));}

else{

graphics.DrawString((day=="初一")?

str:

day,newFont("",10f),brush2,(float)(0x19+(80*j)),(float)(0x73+(60*i)));

}

graphics.DrawString(num.ToString(CultureInfo.InvariantCulture),font,brush2,(float)(15+(80*j)),(float)(80+

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 军事

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1