




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、宿舍管理查询软件一、需求分析宿舍管理人员需要对学生的入住情况进行登记(办理登记入住、办理退房),同时还需要在平时能够根据学号、姓名或宿舍号查询到学生的入住情况。宿舍信息的存储采用离线文件存储。二、系统设计1、系统所需的数据结构/宿舍使用记录/publicclassdormitoryrecord /学号/publicstring stuid get; set; /姓名/publicstring name get; set; /宿舍/publicstring dormitory get; set; /宿舍使用记录/publiclist records/宿舍使用记录中的字段名/publicenumd
2、ormitoryrecordwordtype stuid, name, dormitory注:宿舍记录在存入文件的时候按各字段最大长度存储,不足部分使用空格填充2、系统总体结构图办理查询保存和载入数据办理入住办理退房宿舍管理按宿舍查询按姓名查询按学号查询3、各模块功能描述/从文件读入宿舍使用记录/protectedvoid readfromfile() /将现有记录写入文件/publicvoid savetofile() /对宿舍使用记录进行排序/排序的关键字/排序后的记录publicdormitoryrecord sort(dormitoryrecordwordtype type)/根据给定
3、的关键字和键值进行查找/关键字/键值/null为查找失败publicdormitoryrecord find(dormitoryrecordwordtype type, string key)/根据给定的关键字和键值找到记录并删除/关键字/键值publicvoid delete(dormitoryrecordwordtype type, string key)/添加一条宿舍使用记录/学号/姓名/宿舍publicvoid add(string stuid, string name, string dormitory)4、各功能流程图三、测试1、测试方案在空数据的情况下,办理若干条记录的入住。然后
4、任选一条进行删除操作。接着对剩余的记录任选一条或几条分别进行按学号、按姓名和按宿舍查找。2、测试过程软件初始界面:办理入住:办理退房:查找操作:按学号:按姓名:按宿舍:四、用户使用手册软件初始界面:点击办理入住可以打开入住登记窗口,填入全部信息后按确认即可:点击查询入住会出现下拉菜单,可以根据提示选择以学号、姓名或宿舍号的一种进行检索:点击办理退房即出现办理退房的窗口,输入学号后即可删去该学生的宿舍使用记录:五、收获及体会六、附源程序清单1、mainform.csusing system;using system.collections.generic;using system.compone
5、ntmodel;using system.data;using system.drawing;using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;using system.threading;namespace宿舍管理publicpartialclassmainform : form protectedthread savetofilethread = newthread(newparameterizedthreadstart(savetofile);protec
6、teddelegatevoidrecordcountchangedhandler();protectedeventrecordcountchangedhandler onrecordcountchanged;protectedstaticvoid savetofile(object m) dormitorymanagement manage = (dormitorymanagement)m; manage.savetofile(); public mainform() initializecomponent(); onrecordcountchanged += refreshlabel; re
7、freshlabel(); protectedvoid refreshlabel() labelstatistic.text = 当前入住学生数: + dormitorymanagementpool.dm.count;/从dormitorymanagementpool.dm读出所有记录并写入gridviewdatatable dt = newdatatable(dormitoryrecords); dt.columns.add(newdatacolumn(学号, typeof(string); dt.columns.add(newdatacolumn(姓名, typeof(string); d
8、t.columns.add(newdatacolumn(宿舍, typeof(string);list records = dormitorymanagementpool.dm.records;dataset ds = newdataset();for (int i = 0; i records.count; i+) datarow dr = dt.newrow(); dr学号 = recordsi.stuid; dr姓名 = recordsi.name; dr宿舍 = recordsi.dormitory; dt.rows.add(dr); ds.tables.add(dt); datagr
9、idview1.datasource = ds; datagridview1.datamember = dormitoryrecords; privatevoid办理入住toolstripmenuitem_click(object sender, eventargs e) checkinform frm = newcheckinform();if (frm.showdialog() = system.windows.forms.dialogresult.ok) try dormitorymanagementpool.dm.add(frm.stuid, frm.stuname, frm.dorm
10、itory); frm.close(); savetofilethread.abort(); savetofilethread = newthread(newparameterizedthreadstart(savetofile); savetofilethread.start(dormitorymanagementpool.dm); catch (recordalreadyexistexception) messagebox.show(记录已经存在!, 办理入住失败, messageboxbuttons.ok, messageboxicon.error); /触发记录数改变事件 onreco
11、rdcountchanged(); privatevoid办理退房toolstripmenuitem_click(object sender, eventargs e) deleteform frm = newdeleteform();if (frm.showdialog() = system.windows.forms.dialogresult.ok) try dormitorymanagementpool.dm.delete(dormitoryrecordwordtype.stuid, frm.stuid); frm.close(); savetofilethread.abort(); s
12、avetofilethread = newthread(newparameterizedthreadstart(savetofile); savetofilethread.start(dormitorymanagementpool.dm); catch (recordnotfoundexception) messagebox.show(记录未找到!, 办理退房失败, messageboxbuttons.ok, messageboxicon.error); /触发记录数改变事件 onrecordcountchanged(); privatevoid按学号查询toolstripmenuitem_c
13、lick(object sender, eventargs e) searchform frm = newsearchform(dormitoryrecordwordtype.stuid); frm.showdialog(); privatevoid按姓名查询toolstripmenuitem_click(object sender, eventargs e) searchform frm = newsearchform(dormitoryrecordwordtype.name); frm.showdialog(); privatevoid按房号查询toolstripmenuitem_clic
14、k(object sender, eventargs e) searchform frm = newsearchform(dormitoryrecordwordtype.dormitory); frm.showdialog(); 2、searchform.csusing system;using system.collections.generic;using system.componentmodel;using system.data;using system.drawing;using system.linq;using system.text;using system.threadin
15、g.tasks;using system.windows.forms;namespace宿舍管理publicpartialclasssearchform : form dormitoryrecordwordtype key;public searchform(dormitoryrecordwordtype key) initializecomponent(); key = key;switch (key) casedormitoryrecordwordtype.stuid: label1.text = 学号:;break;casedormitoryrecordwordtype.name: la
16、bel1.text = 姓名:;break;casedormitoryrecordwordtype.dormitory: label1.text = 宿舍:;break; privatevoid buttonok_click(object sender, eventargs e) dormitoryrecord dr = dormitorymanagementpool.dm.findall(key, textboxkey.text);if (dr = null) messagebox.show(未找到记录!, 查询失败, messageboxbuttons.ok, messageboxicon
17、.error);return; datatable dt = newdatatable(dormitoryrecords); dt.columns.add(newdatacolumn(学号, typeof(string); dt.columns.add(newdatacolumn(姓名, typeof(string); dt.columns.add(newdatacolumn(宿舍, typeof(string);dataset ds = newdataset();for (int i = 0; i dr.count(); i+) datarow row = dt.newrow(); row学
18、号 = dri.stuid; row姓名 = dri.name; row宿舍 = dri.dormitory; dt.rows.add(row); ds.tables.add(dt); datagridview1.datasource = ds; datagridview1.datamember = dormitoryrecords; 3、deleteform.csusing system;using system.collections.generic;using system.componentmodel;using system.data;using system.drawing;usi
19、ng system.linq;using system.text;using system.threading.tasks;using system.windows.forms;namespace宿舍管理publicpartialclassdeleteform : form publicstring stuid = ;public deleteform() initializecomponent(); privatevoid buttonok_click(object sender, eventargs e) this.hide(); stuid = textboxstuid.text;thi
20、s.dialogresult = system.windows.forms.dialogresult.ok; 4、checkinform.csusing system;using system.collections.generic;using system.componentmodel;using system.data;using system.drawing;using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;namespace宿舍管理publicparti
21、alclasscheckinform : form publicstring stuid;publicstring stuname;publicstring dormitory;public checkinform() initializecomponent(); privatevoid buttonok_click(object sender, eventargs e) this.hide(); stuid = textboxstuid.text; stuname = textboxname.text; dormitory = textboxdormitory.text;this.dialo
22、gresult = system.windows.forms.dialogresult.ok; 5、dormitorymanagement.csusing system;using system.collections.generic;using system.linq;using system.text;using system.threading.tasks;using system.io;using system.threading;namespace宿舍管理/宿舍管理/classdormitorymanagement protectedlist records = newlist();
23、protectedstring filepath = dormitorydata.dat;/学号最大长度/protectedconstint stuidmaxlength = 10;/姓名最大长度/protectedconstint namemaxlength = 20;/宿舍最大长度/protectedconstint dormitorymaxlength = 20;protectedbool stringsmaller(string a, string b) int max = a.length b.length ? b.length : a.length;if (a.length = 0
24、)returntrue;if (b.length = 0)returnfalse;for (int i = 0; i max; i+) if (ai = bi)continue;else if (ai bi)returntrue;elsereturnfalse; if (a.length b.length ? b.length : a.length;if (a.length = 0)returnfalse;if (b.length = 0)returntrue;for (int i = 0; i bi)returntrue;elsereturnfalse; if (a.length b.len
25、gth)returntrue;elsereturnfalse; /从文件读入宿舍使用记录/protectedvoid readfromfile() /打开文件filestream fs = newfilestream(filepath, filemode.open);fileinfo fi = newfileinfo(filepath);streamreader sr = newstreamreader(fs);char buffer = newcharstuidmaxlength + namemaxlength + dormitorymaxlength;/读入记录/记录形式:学号,姓名,宿舍
26、,每个字段均采用最大长度存储,填充字符为空格try while (sr.endofstream = false) /读入一整行记录 sr.read(buffer, 0, stuidmaxlength + namemaxlength + dormitorymaxlength);string stuid = , name = , dormitory = ;stack tmp = newstack();bool found = false;/读入学号for (int i = stuidmaxlength - 1; i = 0; i-) if (bufferi = & found = false) c
27、ontinue; else found = true; tmp.push(bufferi); while (tmp.count != 0) stuid += tmp.pop(); /读入姓名 found = false;for (int i = stuidmaxlength + namemaxlength - 1; i stuidmaxlength - 1; i-) if (bufferi = & found = false) continue; else found = true; tmp.push(bufferi); while (tmp.count != 0) name += tmp.p
28、op(); /读入宿舍 found = false;for (int i = stuidmaxlength + namemaxlength + dormitorymaxlength - 1; i stuidmaxlength + namemaxlength - 1; i-) if (bufferi = & found = false) continue; else found = true; tmp.push(bufferi); while (tmp.count != 0) dormitory += tmp.pop(); /写入记录 records.add(newdormitoryrecord
29、(stuid, name, dormitory); catch (ioexception) thrownewdatafilecorruptedexception(); sr.close(); fs.close(); /将现有记录写入文件/publicvoid savetofile() /使用填充符号(空格)进行填充,使每项记录达到最大长度/构造数组dormitoryrecord tmp = newdormitoryrecordrecords.count;for (int i = 0; i records.count; i+) tmpi = newdormitoryrecord(recordsi
30、.stuid, recordsi.name, recordsi.dormitory); for (int i = 0; i tmp.count(); i+) if (tmpi.stuid.length stuidmaxlength) int time = stuidmaxlength - tmpi.stuid.length;for (int j = 0; j time; j+) tmpi.stuid += ; if (tmpi.name.length namemaxlength) int time = namemaxlength - tmpi.name.length;for (int j =
31、0; j time; j+) tmpi.name += ; if (tmpi.dormitory.length dormitorymaxlength) int time = dormitorymaxlength - tmpi.dormitory.length;for (int j = 0; j time; j+) tmpi.dormitory += ; /写入文件filestream fs = newfilestream(filepath, filemode.create);streamwriter sw = newstreamwriter(fs);for(int i = 0; i tmp.c
32、ount(); i+) sw.write(tmpi.stuid); sw.write(tmpi.name); sw.write(tmpi.dormitory); /关闭文件 sw.close(); fs.close(); /宿舍使用记录/publiclist records get return records; /宿舍使用记录数/publicint count get return records.count; public dormitorymanagement() /从文件初始化try readfromfile(); catch (filenotfoundexception) /对宿舍使
33、用记录进行排序/排序的关键字/排序后的记录publicdormitoryrecord sort(dormitoryrecordwordtype type) /构造数组dormitoryrecord result = newdormitoryrecordrecords.count;for (int i = 0; i records.count; i+) resulti = recordsi; /进行排序dormitoryrecord temp;switch (type) casedormitoryrecordwordtype.stuid:for (int i = 1; i = 0 & strin
34、gsmaller(temp.stuid, resultj.stuid); j-) resultj + 1 = resultj;/逆向寻找temp插入位置 resultj + 1 = temp; break;casedormitoryrecordwordtype.name:for (int i = 1; i = 0 & stringsmaller(temp.name, resultj.name); j-) resultj + 1 = resultj;/逆向寻找temp插入位置 resultj + 1 = temp; break;casedormitoryrecordwordtype.dormit
35、ory:for (int i = 1; i = 0 & stringsmaller(temp.dormitory, resultj.dormitory); j-) resultj + 1 = resultj;/逆向寻找temp插入位置 resultj + 1 = temp; break; return result; /根据给定的关键字和键值进行查找/关键字/键值/null为查找失败publicdormitoryrecord find(dormitoryrecordwordtype type, string key) dormitoryrecord origin = sort(type);int high = origin.count() - 1;int low = 0;int mid = 0;switch(type) casedormitoryrecordwordtype.stuid:while(low = high) mid = (low + high) / 2;/小于则向后查找if(stringsmaller(originmid.stuid, key) low = mid + 1;/大于则
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 证券从业资格证经济学对证券影响试题及答案
- 项目管理敏捷实践的考查要点试题及答案
- 注册会计师应试自信心提升试题及答案
- 项目管理稳步推进方法试题及答案
- 项目管理专业资格考试考核机制试题及答案
- 理财师如何进行资本运作的决策试题及答案
- 公共场地改造方案范本
- 2025年特许金融分析师考试职业规划试题及答案
- 新建果园施肥方案范本
- 证券从业资格证考试实战技巧试题及答案
- 《中医食疗药膳》课件
- 银行业审计服务方案
- 甲亢完整课件完整版
- 2025年湖北省高考数学模拟试卷(附答案解析)
- 电商平台合规管理制度分析
- 数智化转型背景下国企财务管理体系的优化分析
- 四年级语文下册 第16课《海上日出》同步训练题(含答案)(部编版)
- 汽车故障诊断技术教案(发动机部分)
- 《始得西山宴游记》名师课件1
- 2023技规选择题库(内附答案)
- 建筑物拆除场地清理垃圾外运施工方案
评论
0/150
提交评论