您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > C#――教师信息管理系统
usingSystem;usingSystem.IO;usingSystem.Text;usingSystem.Runtime.Serialization.Formatters.Binary;namespaceMyTest{[Serializable]publicclassscore{publicstringtno;publicstringname;publicstringsex;publicstringage;publicstringdegree;publicstringtitle;publicstringsalary;publicstringaddress;publicstringmobile;publicstringemail;publicoverridestringToString(){returntno+\t+name+\t+sex+\t+age+\t+degree+\t+title+\t+salary+\t+address+\t+mobile+\t+email+\n;}};publicclassInsertClass{publicvoidInsert(){Console.Clear();Console.WriteLine(请按以下顺序输入(以table键隔开):);Console.WriteLine(编号\t姓名\t性别\t年龄\t学历\t职称\t工资\t地址\t电话\tEmail);stringrec=Console.ReadLine();string[]str=rec.Split('\t');scoredat=newscore();dat.tno=str[0];dat.name=str[1];dat.sex=str[2];dat.age=str[3];dat.degree=str[4];dat.title=str[5];dat.salary=str[6];dat.address=str[7];dat.mobile=str[8];dat.email=str[9];BinaryFormatterbinFormat=newBinaryFormatter();Streamfs=newFileStream(Information.dat,FileMode.Append,FileAccess.Write,FileShare.None);binFormat.Serialize(fs,dat);fs.Close();Console.WriteLine(\n是否继续输入?(Y/N));stringpd;pd=Console.ReadLine();switch(pd){caseY:Insert();break;caseN:Mainclassma=newMainclass();break;}}}publicclassBrowse{publicstaticscores;publicstaticinti=0;publicvoidOpenFile(){Console.Clear();BinaryFormatterbinFormat=newBinaryFormatter();Streamfs;fs=File.OpenRead(Information.dat);try{while((s=(score)binFormat.Deserialize(fs))!=null){++i;}}catch(Exceptione){Console.WriteLine(e.Message+对象已经全部读取111.);}fs.Close();fs=File.OpenRead(Information.dat);intj=0;score[]ss=newscore[i];i=0;try{while((ss[j]=(score)binFormat.Deserialize(fs))!=null){++j;}}catch(Exceptione){Console.WriteLine(e.Message+对象已经全部读取222.);}fs.Close();Display(ss);}publicvirtualvoidDisplay(score[]s3){Console.Clear();Console.WriteLine(编号\t姓名\t性别\t年龄\t学历\t职称\t工资\t地址\t电话\tEmail);foreach(scoreseins3){Console.WriteLine(se);}}}publicclassModify:Browse{publicoverridevoidDisplay(score[]s3){Console.Clear();Console.WriteLine(请输入您想要修改教师的教师编号:);stringnum;intcon=0;num=Console.ReadLine();for(intj=0;js3.Length;j++){if(s3[j].tno==num){con++;Console.WriteLine(输入你想要修改的信息:);Console.WriteLine(1.教师编号);Console.WriteLine(2.教师姓名);Console.WriteLine(3.教师性别);Console.WriteLine(4.教师年龄);Console.WriteLine(5.教师学历);Console.WriteLine(6.教师职称);Console.WriteLine(7.教师工资);Console.WriteLine(8.教师地址);Console.WriteLine(9.教师电话);Console.WriteLine(10.教师Email);Console.WriteLine(11.返回);stringc=Console.ReadLine();switch(c){case1:Console.Clear();Console.WriteLine(请输入新的教师编号:);s3[j].tno=Console.ReadLine();MoWrite(s3);break;case2:Console.Clear();Console.WriteLine(请输入新的教师姓名);s3[j].name=Console.ReadLine();MoWrite(s3);break;case3:Console.Clear();Console.WriteLine(请输入新的教师性别:);s3[j].sex=Console.ReadLine();MoWrite(s3);break;case4:Console.Clear();Console.WriteLine(请输入新的教师年龄:);s3[j].age=Console.ReadLine();MoWrite(s3);break;case5:Console.Clear();Console.WriteLine(请输入新的教师学历:);s3[j].degree=Console.ReadLine();MoWrite(s3);break;case6:Console.Clear();Console.WriteLine(请输入新的教师职称:);s3[j].title=Console.ReadLine();MoWrite(s3);break;case7:Console.Clear();Console.WriteLine(请输入新的教师工资:);s3[j].salary=Console.ReadLine();MoWrite(s3);break;case8:Console.Clear();Console.WriteLine(请输入新的教师地址:);s3[j].address=Console.ReadLine();MoWrite(s3);break;case9:Console.Clear();Console.WriteLine(请输入新的教师电话:);s3[j].mobile=Console.ReadLine();MoWrite(s3);break;case10:Console.Clear();Console.WriteLine(请输入新的教师Email:);s3[j].email=Console.ReadLine();MoWrite(s3);break;case11:Console.Clear();Mainclassma=newMainclass();break;}}}if(con==0){Console.WriteLine(对不起,不存在你想要修改的教师信息!);Console.ReadLine();}}publicvoidMoWrite(score[]s4){BinaryFormatterbinFormat=newBinaryFormatter();Streamfs=newFileStream(Information.dat,FileMode.Truncate,FileAccess.Write,FileShare.None);for(intj=0;js4.Length;j++){binFormat.Serialize(fs,s4[j]);}fs.Close();Console.WriteLine(修改成功!);Console.ReadLine();Console.Clear();stringpd;Console.WriteLine(是否继续修改?(Y/N));pd=Console.ReadLine();switch(pd){caseY:Display(s4);break;caseN:Mainclassma=newMainclass();break;}}}publicclassDelete:Browse{publicoverridevoidDisplay(score[]s3){Console.Clear();Console.WriteLine(请输入要删除的教师编号:);stringnum;num=Console.ReadLine();for(intj=0;js3.Length;j++){if(s3[j].tno==num){if(j!=s3.Length-1){for(intn=j;ns3.Length-1;n++){s3[n]=s3[n+1];}}}}ReWrite(s3);}publicvoidReWrite(score[]s4){BinaryFormatterbinFormat=newBinaryFormatter();Streamfs=newFileStream(Information.dat,FileMode.Truncate,FileAccess.Write,FileShare.None);for(intj=0;js4.Length-1;j++){binFormat.Serialize(fs,s4[j]);}fs.Close();Console.WriteLine(删除成功!);Console.ReadLine();Console.Clear();stringpd;Console.WriteLine(是否继续删除?(Y/N));pd=Console.ReadLine();switch(pd){caseY:Display(s4);break;caseN:Mainclassma=newMainclass();break;}}}publicclassQuery:Browse{publicoverridevoidDisplay(score[]s3){Console.Clear();Console.WriteLine(请输入你要进行的查询种类:);Console.WriteLine(1.按教师编号查询);Console.WriteLine(2.按教师工资查询);Console.WriteLine(3.按教师学历查询);Console.WriteLine(4.按教师职称查询);Console.WriteLine(5.返回);stringc=Console.ReadLine();switch(c){case1:Conso
本文标题:C#――教师信息管理系统
链接地址:https://www.777doc.com/doc-4890994 .html