- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
} } }
public class Browse {
public static score s; puБайду номын сангаасlic static int i = 0; public void OpenFile() {
Console.Clear();
BinaryFormatter binFormat = new BinaryFormatter(); Stream fs; fs = File.OpenRead("Information.dat");
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];
public override string ToString() {
return tno + "\t" + name + "\t" + sex + "\t" +age + "\t"+degree + "\t" +title + "\t" +salary + "\t" +address + "\t" +mobile + "\t" + email
string c=Console.ReadLine(); switch(c) {
case "1": Console.Clear(); Console.WriteLine("请输入新的教师编号:"); s3[j].tno=Console.ReadLine(); MoWrite(s3); break;
case "2": Console.Clear(); Console.WriteLine("请输入新的教师姓名"); s3[j].name=Console.ReadLine();
try {
while ((s = (score)binFormat.Deserialize(fs)) !=null) {
++i; }
} catch (Exception e) {
Console.WriteLine(e.Message + "对象已经全部读取 111.");
} fs.Close();
case "5": Console.Clear(); Console.WriteLine("请输入新的教师学历:"); s3[j].degree=Console.ReadLine(); MoWrite(s3); break; case "6": Console.Clear(); Console.WriteLine("请输入新的教师职称:"); s3[j].title=Console.ReadLine(); MoWrite(s3); break; case "7": Console.Clear(); Console.WriteLine("请输入新的教师工资:"); s3[j].salary=Console.ReadLine(); MoWrite(s3); break; case "8": Console.Clear(); Console.WriteLine("请输入新的教师地址:"); s3[j].address=Console.ReadLine(); MoWrite(s3); break; case "9": Console.Clear(); Console.WriteLine("请输入新的教师电话:"); s3[j].mobile=Console.ReadLine(); MoWrite(s3); break; case "10": Console.Clear(); Console.WriteLine("请输入新的教师 Email:"); s3[j].email=Console.ReadLine(); MoWrite(s3); break;
using System; using System.IO; using System.Text; using System.Runtime.Serialization.Formatters.Binary;
namespace MyTest {
[Serializable] public class score
{ public string tno; public string name; public string sex; public string age; public string degree; public string title; public string salary; public string address; public string mobile; public string email;
case "11": Console.Clear(); Mainclass ma=new Mainclass(); break;
} } } if(con==0) {
Console.WriteLine("对不起,不存在你想要修改的教师信息!"); Console.ReadLine(); }
}
public void MoWrite(score[] s4)
case "Y": Display(s4); break;
} } }
case "N": Mainclass ma=new Mainclass(); break;
public class Delete : Browse {
public override void Display(score[] s3) {
Console.WriteLine(se); }
} }
public class Modify : Browse {
public override void Display(score[] s3) {
Console.Clear(); Console.WriteLine("请输入您想要修改教师的教师编号:"); string num; int con=0; num=Console.ReadLine(); for(int j=0;j<s3.Length;j++) {
} catch (Exception e) {
Console.WriteLine(e.Message + "对象已经全部读取 222."); }
fs.Close(); Display(ss); } public virtual void Display(score[] s3) { Console.Clear(); Console.WriteLine("编号\t 姓名\t 性别\t 年龄\t 学历\t 职称\t 工资\t 地址\t 电话\tEmail"); foreach (score se in s3) {
Console.Clear(); Console.WriteLine("请输入要删除的教师编号:"); string num; num = Console.ReadLine(); for (int j = 0; j < s3.Length; j++) {
if (s3[j].tno == num)
{
binFormat.Serialize(fs, s4[j]); }
fs.Close(); Console.WriteLine("修改成功!"); Console.ReadLine(); Console.Clear(); string pd; Console.WriteLine("是否继续修改?(Y/N)"); pd = Console.ReadLine(); switch (pd) {
MoWrite(s3); break;
case "3": Console.Clear(); Console.WriteLine("请输入新的教师性别:"); s3[j].sex=Console.ReadLine(); MoWrite(s3); break;
case "4": Console.Clear(); Console.WriteLine("请输入新的教师年龄:"); s3[j].age=Console.ReadLine(); MoWrite(s3); break;
fs = File.OpenRead("Information.dat"); int j = 0; score[] ss = new score[i]; i = 0; try {
while ((ss[j] = (score)binFormat.Deserialize(fs)) !=null) {
++j; }
+ "\n"; }
};
public class InsertClass {
public void Insert() {
Console.Clear(); Console.WriteLine("请按以下顺序输入(以 table 键隔开):"); Console.WriteLine("编号\t 姓名\t 性别\t 年龄\t 学历\t 职称\t 工资\t 地址\t 电话\tEmail"); string rec = Console.ReadLine(); string[] str = rec.Split('\t'); score dat = new score();
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.返回");
Stream
fs
=
new
FileStream("Information.dat",
FileMode.Truncate,FileAccess.Write, FileShare.None);
BinaryFormatter binFormat = new BinaryFormatter();
Stream
fs
=
new
FileStream("Information.dat",
FileMode.Append,FileAccess.Write, FileShare.None);
binFormat.Serialize(fs, dat);
{
BinaryFormatter binFormat = new BinaryFormatter();
Stream
fs
=
new
FileStream("Information.dat",
FileMode.Truncate,FileAccess.Write, FileShare.None);
for (int j = 0; j < s4.Length; j++) {
fs.Close();
Console.WriteLine("\n 是否继续输入?(Y/N)");
string pd;
pd = Console.ReadLine();
switch (pd)
{
case "Y": Insert(); break;
case "N": Mainclass ma=new Mainclass(); break;
if (j != s3.Length - 1)
{
for (int n = j; n < s3.Length - 1; n++)
{
s3[n] = s3[n + 1];
}
}
}
}
ReWrite(s3);
}
public void ReWrite(score[] s4)
{
BinaryFormatter binFormat = new BinaryFormatter();