public Form11_21() { InitializeComponent(); // List<StudentInfo> studentS = new List<StudentInfo>(); // intMapString gnameMapGid = null; gnameMapGid = calcAllClass(out this.gidMapGname); studentS = calcAll(this.gidMapGname); /// var gredeIdMapName = LearnDotNet.Program.calcAllClass(out gnameMapGid); /// studentS = LearnDotNet.Program.calcAll(gnameMapGid); ShellFor_11_21(studentS, gnameMapGid); }
public StringMapInt calcAllClass(out intMapString gidMapGname) { StringMapInt result = new StringMapInt(); intMapString gidMapGnameBuffer = new intMapString(); using (var context = new sail_heEntities()) { var ugradeList = context.ugrade.ToList(); ugradeList.ForEach(ele => { string gname = ele.gname; gidMapGnameBuffer.Add(ele.gid, ele.gname); result.Add(gname, ele.gid); }); } gidMapGname = gidMapGnameBuffer; return(result); }
public List <StudentInfo> calcAll(intMapString gidMapGname) { List <StudentInfo> studentS = new List <StudentInfo>(); StringMapInt result = new StringMapInt(); using (var context = new sail_heEntities()) { var resultList = context.ustudent.ToList(); resultList.ForEach(ele => { StudentInfo temp = new StudentInfo( ele.sname , (ele.ssexy) == "男" ? EnumGender.MALE : EnumGender.WOMAN , DateTime.Parse(ele.sbdate) , gidMapGname[int.Parse(ele.gid)] , ele.stele ); temp.setSduId(ele.sid); temp.ClassId = int.Parse(ele.gid); studentS.Add(temp); }); } return(studentS); }
private void SinInForm_Load(object sender, EventArgs e) { gnameMapGid = calcAllClass(out this.gidMapGname); studentS = calcAll(this.gidMapGname); }
// https://docs.microsoft.com/zh-cn/dotnet/framework/data/adonet/sql/linq/how-to-delete-rows-from-the-database // https://docs.microsoft.com/zh-cn/dotnet/framework/data/adonet/ void ShellFor_11_21(List <StudentInfo> studentS, StringMapInt gnameMapGid = null) { //查询 start: string input = "- "; do { Clear(); TipsWriteLine("姓名\t学号\t性别\t\t\t生日\t\t班级名\t联系电话"); if (input.Length < 2) { input += " "; } switch (input[0]) { // 按姓名查询 case '0': studentS.FindAll(ele => ele.getName().Contains(input.Substring(2))) .ForEach(ele => WriteLine(ele.tabString())); break; // 按班级查询 case '1': studentS.FindAll(ele => ele.ClassName.Contains(input.Substring(2))) .ForEach(ele => WriteLine(ele.tabString())); break; // 新增 case '2': { var temp = readAStudent(gnameMapGid); temp.resetSduId(); studentS.Add(temp); goto start; } // 更改 case '3': { string sidBuffer = ""; int index = -1; while (true) { WriteLine("输入需要更改者的学号 直接回车返回:"); sidBuffer = ReadLine(); index = -1; StudentInfo studentInfo = studentS.Find(ele => { ++index; return(ele.getStuId().Equals(sidBuffer)); }); if (studentInfo != null) { break; } else if (sidBuffer == "") { goto start; } else { WriteLine("学号不存在!请重输 或回车返回"); } } WriteLine("原信息: "); WriteLine(studentS[index].tabString()); var temp = readAStudent(gnameMapGid); temp.setSduId(int.Parse(studentS[index].getStuId())); studentS[index] = temp; goto start; } // 按学号查询 case '4': studentS.FindAll(ele => ele.getStuId().Contains(input.Substring(2))) .ForEach(ele => WriteLine(ele.tabString())); break; // 显示所有 default: studentS.ForEach(ele => WriteLine(ele.tabString())); break; } /*TipsWriteLine( * "Shell提示: \n\r" + * " 0 name: 按姓名查询;" + * " 1 className: 按班级查询;" + * " 2: 新增;" + * " 3: 更改;" + * " 4 学号: 按学号查询;" + * " else: 显示所有;" + * " 回车: 保存并退出" * );*/ } while ((input = ReadLine()) != string.Empty); }
StudentInfo readAStudent(StringMapInt gnameMapGid = null) { bool isVerifyed = true; EnumGender enumGender; DateTime birthDay; string className, phone = "15258989595", stuNameBuffer, birthDayBuffer; stuNameBuffer = textBox_name.Text; className = textBox_grade.Text; birthDayBuffer = textBox_birthDay.Text; //textBox_stuNum.Text; enumGender = textBox_sex.Text == "男" ? EnumGender.WOMAN : EnumGender.MALE; if (gnameMapGid != null) { if (gnameMapGid.ContainsKey(className)) { //break; } else { string allInMap = ""; int i = -1; foreach (KeyValuePair <string, int> kv in gnameMapGid) { allInMap += ++i == 0 ? "" : "; "; allInMap += kv.Key;// + ": " + kv.Value.ToString("0.") + "号"; } TipsWriteLine("班级不存在!请重输; 可用班级:"); TipsWriteLine(allInMap); isVerifyed = false; } } /*switch (ReadLine()) * { * case "男": enumGender = EnumGender.MALE; break; * case "女": enumGender = EnumGender.WOMAN; break; * default: enumGender = EnumGender.UNKNOWN; break; * }*/ if (Verify.IsDateTime(birthDayBuffer)) { //break; } else { TipsWriteLine("生日格式错误!请重输"); isVerifyed = false; } birthDay = DateTime.Parse(birthDayBuffer); if (Verify.IsPhoneNumber(phone)) { //break; } else { TipsWriteLine("电话格式错误!请重输"); isVerifyed = false; } StudentInfo result = null; if (isVerifyed) { TipsWriteLine("添加输入成功!"); result = new StudentInfo(stuNameBuffer, enumGender, birthDay, className, phone); result.ClassId = gnameMapGid[className]; } else { // do nothing } TipsWriteLine("================"); return(result); }