public static void ShowStudents(List <StudentInfo> stuList) { CourseInfo cou = new CourseInfo(); if (stuList.Count > 0) { Console.WriteLine("学生信息如下:"); Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine("{0,-14}{1,-12}{2,-10}{3,-13}", "学号", "姓名", "班级", "选课记录"); foreach (StudentInfo item in stuList) { Console.WriteLine("{0,-15}{1,-10}{2,-10}", item.Id, item.Name, item.ClaName); try { foreach (string courseid in item.Kecheng) { cou = coubll.getCourseByCouId(courseid); Console.Write("{0,-5}", cou.Couname); } } catch { item.Kecheng = null; } Console.Write("\n"); } } else { Console.WriteLine("\n数据为空,请检查输入是否有误\n"); } }
/// <summary> /// 课程id查询 /// </summary> /// <param name="couid"></param> /// <returns></returns> public CourseInfo getCourseByCouId(string couid) { //XmlNode courseNode = this.getCourseNodeByCouId(couid); //if (courseNode != null) //{ //CourseInfo cou = new CourseInfo(courseNode.Attributes["课程id"].Value); //cou.Couname = courseNode.SelectSingleNode("couname").InnerText; //return cou; //} //else //{ // CourseInfo cou = null; // return cou; //} try { XmlNode courseNode = this.getCourseNodeByCouId(couid); CourseInfo cour = new CourseInfo(courseNode.Attributes["课程id"].Value); cour.Snum = Convert.ToInt32(courseNode.SelectSingleNode("Snum").InnerText); cour.Couname = courseNode.SelectSingleNode("couname").InnerText; return(cour); } catch (Exception) { return(null); } }
/// <summary> /// 修改课程 /// </summary> public void updateCourse() { Console.Write("请输入需要修改的课程id:"); string couid = Console.ReadLine(); CourseInfo cou = couDal.getCourseByCouId(couid); if (cou != null) { Common.showCourse(cou); Console.Write("请输入新课程名:"); string couname = Console.ReadLine(); cou.Couname = couname; if (couDal.updateCourse(cou)) { Console.WriteLine("修改成功"); Console.ReadKey(); } else { Console.WriteLine("修改失败"); Console.ReadKey(); } } else { Console.WriteLine("课程不存在"); Console.ReadKey(); } }
/// <summary> /// 课程添加 /// </summary> /// <param name="cou">课程名</param> /// <returns></returns> public bool AddCourse(CourseInfo cou) { XmlDocument Xml = XmlHelper.Xml; XmlNode Courses = Xml.SelectSingleNode("//Courses"); XmlElement courseNode = Xml.CreateElement("course"); courseNode.SetAttribute("课程id", cou.Couid); Courses.AppendChild(courseNode); XmlElement counameNode = Xml.CreateElement("couname"); counameNode.InnerText = cou.Couname; courseNode.AppendChild(counameNode); XmlElement snumNode = Xml.CreateElement("Snum"); snumNode.InnerText = cou.Snum.ToString(); courseNode.AppendChild(snumNode); //更改Course节点的值 Courses.Attributes["counum"].Value = cou.Couid; Xml.Save("data.xml"); return(true); }
public void AddSelCourse() { StudentInfo stu = new StudentInfo(); CourseInfo cou = new CourseInfo(); Console.Write("请输入学号:"); stu = stuDal.getStudentById(Console.ReadLine()); if (stu != null) { Console.Write("请输入课程号:"); cou = couDal.getCourseByCouId(Console.ReadLine()); if (cou != null) { if (stuDal.AddSelCourse(stu, cou)) { Console.WriteLine("添加成功"); Console.ReadKey(); } else { Console.WriteLine("添加失败"); Console.ReadKey(); } } else { Console.WriteLine("查无此课程"); Console.ReadKey(); } } else { Console.WriteLine("查无此人"); } }
public void getcoursebyid() { Console.WriteLine("请输入你想查询的课程id:"); string couid = Console.ReadLine(); CourseInfo cou = couDal.getCourseByCouId(couid); Common.showCourse(cou); Console.ReadKey(); }
/// <summary> /// 课程id查询 /// </summary> public CourseInfo getCourseByCouId(string couid) { //Console.WriteLine("请输入你想查询的课程id:"); // couid = Console.ReadLine(); CourseInfo cou = couDal.getCourseByCouId(couid); Common.showCourse(cou); //Console.ReadKey(); return(cou); }
/// <summary> /// 展示课程信息 /// </summary> /// <param name="cou"></param> public static void showCourse(CourseInfo cou) { Console.WriteLine("\n课程信息如下:"); Console.WriteLine("\n--------------------------------------------------------------------------------"); if (cou != null) { Console.WriteLine("{0,-8}{1,-10}", "课程id", "课程名"); Console.WriteLine("{0,-10}{1,-10}", cou.Couid, cou.Couname); } else { Console.WriteLine("\n数据为空,请检查输入是否有误\n"); } Console.WriteLine("\n--------------------------------------------------------------------------------"); }
/// <summary> /// 获得全部CourseInfo信息 /// </summary> /// <returns></returns> public List <CourseInfo> getCourses() { List <CourseInfo> couList = new List <CourseInfo>(); XmlNodeList courseNodeList = XmlHelper.Xml.SelectSingleNode("//Courses").ChildNodes; foreach (XmlNode item in courseNodeList) { string couid = item.Attributes["课程id"].Value; CourseInfo cou = new CourseInfo(couid); cou.Couname = item.SelectSingleNode("couname").InnerText; couList.Add(cou); } return(couList); }
/// <summary> /// 修改课程 /// </summary> /// <param name="cou"></param> /// <returns></returns> public bool updateCourse(CourseInfo cou) { XmlNode courseNode = this.getCourseNodeByCouId(cou.Couid); if (courseNode != null) { courseNode.SelectSingleNode("couname").InnerText = cou.Couname; XmlHelper.Xml.Save("data.xml"); return(true); } else { return(false); } }
/// <summary> /// 课程添加 /// </summary> public void AddCourse() { CourseInfo cou = new CourseInfo(); Console.Write("请输入你要添加的课程名:"); cou.Couname = Console.ReadLine(); if (couDal.AddCourse(cou)) { Console.WriteLine("添加成功"); Console.ReadKey(); } else { Console.WriteLine("添加失败"); Console.ReadKey(); } }
/// <summary> /// 输出StudentModel对象 /// </summary> /// <param name="stu"></param> public static void showStudnt(StudentInfo stu) { if (stu != null) { CourseInfo cour = new CourseInfo(); Console.WriteLine("\n学生信息如下:"); Console.WriteLine("\n--------------------------------------------------------------------------------"); Console.WriteLine("{0,-8}{1,-10}{2,-10}{3,-13}", "学号", "姓名", "班级", "选课记录"); Console.WriteLine("{0,-10}{1,-10}{2,-10}", stu.Id, stu.Name, stu.ClaName); foreach (string couid in stu.Kecheng) { cour = coubll.getCourseByCouId(couid); Console.WriteLine("{0,-5}", cour.Couname); } Console.WriteLine("\n--------------------------------------------------------------------------------"); } else { Console.WriteLine("\n数据为空,请检查输入是否有误\n"); } }
public bool AddSelCourse(StudentInfo stu, CourseInfo cour) { //找到并修改学生节点 XmlNode studentNode = this.getStudentNodeById(stu.Id); XmlNode stucourIdNode = studentNode.SelectSingleNode("CourseID"); XmlElement stucourNode = XmlHelper.Xml.CreateElement("courseId"); stucourNode.InnerText = cour.Couid; stucourIdNode.AppendChild(stucourNode); //找到并修改课程Snum节点 XmlNode courseNode = XmlHelper.Xml.SelectSingleNode("//course[@课程id='" + cour.Couid + "']/Snum"); if (courseNode != null) { courseNode.InnerText = (Convert.ToInt32(courseNode.InnerText) + 1).ToString(); } else { courseNode.InnerText = "1"; } XmlHelper.Xml.Save("data.xml"); return(true); }