Assignment2 (Console Based)
Assignment2 (Console Based)
Submitted By:
Ayesha Zulfiqar (20021519-023)
Amina Tariq (20021519-035)
Noor Ul Ain (20021519-069)
Insharah Farooq (20021519-096)
Submitted To:
Dr. Usman Ali
Course Code (Course Title):
CS-303 (Advance Programming Techniques
University Of Gujrat
Program.cs
using FinalSMS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using static System.Collections.Specialized.BitVector32;
namespace FinalSMS
{
internal class Program
{
static public List<Student> studentList = new List<Student>();
static public List<Teacher> teacherList = new List<Teacher>();
static public List<Classes> classList = new List<Classes>();
static public List<ClassCourse> classCourseList = new
List<ClassCourse>();
static public List<TeacherClass> teacherClassList = new
List<TeacherClass>();
static public List<studentsection> studentsectionList= new
List<studentsection>();
static public List<ClassSection> ClassSectionList = new
List<ClassSection>();
*****************************************************************
***********************************************";
StudentCollection student = new StudentCollection();
TeacherCollection teacher = new TeacherCollection();
classesCollection classs = new classesCollection();
TeacherClassCollection teacherClass = new TeacherClassCollection();
StudentSectionCollection studentsection = new
StudentSectionCollection();
ClassSectionCollection classSection = new ClassSectionCollection();
Console.WriteLine(logo1); Console.WriteLine(logo);
Console.ReadKey();
Console.Clear();
Console.WriteLine("\n\n\n\n\n\t\t\t\t\t --------------------------");
Console.WriteLine("\t\t\t\t\t| SCHOOL MANAGEMENT SYSTEM | ");
Console.WriteLine("\t\t\t\t\t -------------------------- ");
Console.WriteLine("\n\t\t\t\t\tPrepared By:\n");
Console.WriteLine("\t\t\t\t\tAyesha Zulfiqar (20021519-023) ");
Console.WriteLine("\t\t\t\t\tAmina Tariq (20021519-035) ");
Console.WriteLine("\t\t\t\t\tNoor Ul Ain (20021519-069) ");
Console.WriteLine("\t\t\t\t\tInsharah Farooq (20021519-096) ");
Console.WriteLine("\n\n\t\t\t\t\tPress Enter to continue...... ");
Console.ReadKey();
Console.Clear();
Console.Write("\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tLoading ");
Console.Clear();
int choice;
do
{
Console.WriteLine("\n\n\n\n\tPress");
Console.WriteLine("\n\t0: Exit");
Console.WriteLine("\n\t1: Student Info");
Console.WriteLine("\n\t2: Register Student");
Console.WriteLine("\n\t3: Teacher Info");
Console.WriteLine("\n\t4: Classes");
Console.Write("\n\tEnter your choice: ");
choice = int.Parse(Console.ReadLine());
switch (choice)
{
case 1:
//Student
Console.Clear();
studentList = student.GetAllStudent();
Console.WriteLine("\n\n\n\n\tPress");
Console.WriteLine("\n\t6: Back");
Console.Write("\n\tEnter your choice: ");
if (choiceForStudent == 1)
{
Console.Clear();
DisplayStudents(studentList);
}
if (choiceForStudent == 2)
{
Console.Clear();
}
if (choiceForStudent == 3)
{
Console.Clear();
int c;
Console.Write("Enter ID for updation: ");
int id = int.Parse(Console.ReadLine());
Student stud = studentList.Find(t => t.StudentID == id);
if (stud != null)
{
Console.WriteLine("What you want to update");
Console.WriteLine("1. Email");
Console.WriteLine("2. Phone");
Console.WriteLine("3. Exit");
Console.Write("Enter your choice: ");
c = int.Parse(Console.ReadLine());
switch (c)
{
case 1:
Console.WriteLine("Enter new Email: ");
string email = Console.ReadLine();
student.UpdateEmail(id,email);
studentList.Clear();
studentList = student.GetAllStudent();
break;
case 2:
Console.WriteLine("Enter new PhoneNo");
string phone = Console.ReadLine();
student.UpdatePhone(id,phone);
studentList.Clear();
studentList = student.GetAllStudent();
break;
case 3:
break;
default:
Console.WriteLine("Invalid choice. Please try
again.");
break;
}
}
if (choiceForStudent == 4)
{
Console.Clear();
// StudentCollection Searchstudent = new StudentCollection();
List<Student> Searchstudent = new List<Student>();
Console.WriteLine("Search By:");
Console.WriteLine("1. ID");
Console.WriteLine("2. Name");
Console.WriteLine("3. Exit");
Console.Write("Enter your choice: ");
int s = int.Parse(Console.ReadLine());
switch (s)
{
case 1:
Console.WriteLine("Enter ID: ");
int SearchID = int.Parse(Console.ReadLine());
Searchstudent = student.SearchByID(SearchID);
if (Searchstudent.Count < 1)
{
Console.WriteLine("Student with ID " + SearchID + "
was not found.");
}
else if (Searchstudent != null) {
DisplayStudents(Searchstudent);
}
break;
case 2:
Console.WriteLine("Enter First Name : ");
string SearchName = Console.ReadLine();
Searchstudent = student.SearchByName(SearchName);
if (Searchstudent.Count < 1)
{
Console.WriteLine("Student with Name " +
SearchName + " was not found.");
}
else if (Searchstudent != null)
{
DisplayStudents(Searchstudent);
}
break;
case 3:
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
if (choiceForStudent == 6)
{
break;
}
Console.ReadKey();
Console.Clear();
break;
case 2:
Console.Clear();
ClassSectionList = classSection.GetAllClassSection();
Console.WriteLine("Register Student");
Console.WriteLine("\n\n\n\n\tPress");
Console.WriteLine("\n\t1: Register New Student");
Console.WriteLine("\n\t2: Back");
Console.Write("\n\tEnter your choice: ");
int choiceForRegisterStudent = int.Parse(Console.ReadLine());
switch (choiceForRegisterStudent)
{
case 1:
Console.Clear();
classSection.UpdateNoOfStudent(Cs.NoOfStudent,Cs.ClassID, Cs.SectionID);
}
else if(Cs.NoOfStudent >= 15)
{
newClassSection.SectionID=Cs.SectionID+1;
// Console.WriteLine(newClassSection.SectionID);
newClassSection.NoOfStudent++;
//
Console.WriteLine(newClassSection.NoOfStudent);
classSection.Add(newClassSection);
}
}
}
Console.Write("Enter Class Name: ");
newstudent.ClassName = Console.ReadLine();
Console.Write("Enter Email: ");
newstudent.Email = Console.ReadLine();
Console.Write("Enter Phone Number: ");
newstudent.Phone = Console.ReadLine();
Console.Write("Enter Student DOB: ");
newstudent.DateOfBirth =
DateTime.Parse(Console.ReadLine());
// Console.Write("Enter Student Date Of Admission: ");
newstudent.DateOfAdmission = DateTime.Today;
student.Add(newstudent);
break;
case 2:
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
Console.ReadKey();
Console.Clear();
break;
case 3:
// Teacher
Console.Clear();
teacherList = teacher.GetAllTeacher();
teacherClassList = teacherClass.GetAllTeacherClass();
Console.WriteLine("\n\n\n\n\tPress");
Console.WriteLine("\n\t1:Add Teacher");
Console.WriteLine("\n\t2:Delete Teacher Info");
Console.WriteLine("\n\t3:Update Teacher Info");
Console.WriteLine("\n\t4:Search Teacher Info");
Console.WriteLine("\n\t5:View Teachers Info");
Console.WriteLine("\n\t6: Back");
Console.Write("\n\tEnter your choice: ");
int choiceForTeacher = int.Parse(Console.ReadLine());
if (choiceForTeacher == 1)
{
Console.Clear();
Teacher newteacher = new Teacher();
TeacherClass teacherClass1= new TeacherClass();
Console.Write("Enter First Name: ");
newteacher.FirstName = Console.ReadLine();
Console.Write("Enter Last Name: ");
newteacher.LastName = Console.ReadLine();
Console.Write("Enter Gender: ");
newteacher.Gender = char.Parse(Console.ReadLine());
Console.Write("Enter Email: ");
newteacher.Email = Console.ReadLine();
Console.Write("Enter Course: ");
newteacher.Course = Console.ReadLine();
foreach(var tc in teacherClassList)
{
if (tc.courseName == newteacher.Course)
{
teacherClass1.CourseID = tc.CourseID;
}
}
Console.Write("Enter Class ID : ");
teacherClass1.ClassId = int.Parse(Console.ReadLine());
foreach (var tc in teacherClassList)
{
if(teacherClass1.ClassId==tc.ClassId)
{
teacherClass1.ClassName=tc.ClassName;
}
}
Console.Write("Enter Section : ");
teacherClass1.SectionName = Console.ReadLine();
foreach(var tc in teacherClassList)
{
if(teacherClass1.SectionName==tc.SectionName)
{
teacherClass1.sectionID = tc.sectionID;
}
}
//teacherClass1.TeacherID = newteacher.TeacherID;
teacherClass1.TeacherID= teacherList.Last().TeacherID++;
teacherClass1.TeacherName = newteacher.FirstName;
teacher.Add(newteacher);
teacherClass.Add(teacherClass1);
Console.WriteLine("Teacher added successfully.");
}
if (choiceForTeacher == 2)
{
Console.Clear();
Console.Write("Enter ID for Deletion: ");
int id = int.Parse(Console.ReadLine());
Teacher teach = teacherList.Find(t => t.TeacherID == id);
if (teacher != null)
{
Console.Clear();
Console.WriteLine("Are you sure you want to delete this
Teacher?");
Console.WriteLine("1. yes");
Console.WriteLine("2. No");
int ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
teacher.DeleteTeacher(id, teach, teacherList);
Console.WriteLine("Data is deleted successfully.");
break;
case 2:
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
else
{
Console.WriteLine("Teacher with ID " + id + " was not
found.");
}
}
if (choiceForTeacher == 3)
{
Console.Clear();
int chh;
Console.Write("Enter ID for updation: ");
int id = int.Parse(Console.ReadLine());
Teacher teach = teacherList.Find(t => t.TeacherID == id);
if (teach != null)
{
chh = int.Parse(Console.ReadLine());
switch (chh)
{
case 1:
Console.Write("Enter new Email: ");
string em = Console.ReadLine();
teacher.UpdateEmail(id, em);
teacherList.Clear();
teacherList = teacher.GetAllTeacher();
break;
case 2:
Console.Write("Enter new PhoneNo");
string ph = Console.ReadLine();
teacher.UpdatePhone(id, ph);
teacherList.Clear();
teacherList = teacher.GetAllTeacher();
break;
case 3:
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
if (choiceForTeacher == 4)
{
Console.Clear();
// StudentCollection Searchstudent = new StudentCollection();
List<Teacher> Searchteacher = new List<Teacher>();
Console.WriteLine("Search By:");
Console.WriteLine("1. ID");
Console.WriteLine("2. Name");
Console.WriteLine("3. Exit");
Console.Write("Enter your choice: ");
int st = int.Parse(Console.ReadLine());
switch (st)
{
case 1:
Console.Write("Enter ID: ");
int SearchIDT = int.Parse(Console.ReadLine());
Searchteacher = teacher.SearchByID(SearchIDT);
if (Searchteacher.Count < 1)
{
Console.WriteLine("Teacher with ID " + SearchIDT + "
was not found.");
}
else if (Searchteacher != null)
{
DisplayTeachers(Searchteacher);
}
break;
case 2:
Console.Write("Enter First Name : ");
string SearchNameT = Console.ReadLine();
Searchteacher = teacher.SearchByName(SearchNameT);
if (Searchteacher.Count < 1)
{
Console.WriteLine("Student with Name " +
SearchNameT + " was not found.");
}
else if (Searchteacher != null)
{
DisplayTeachers(Searchteacher);
}
break;
case 3:
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
if (choiceForTeacher == 5)
{
Console.Clear();
DisplayTeachers(teacherList);
}
if (choiceForTeacher == 6)
{
break;
}
Console.ReadKey();
Console.Clear();
break;
// Class
case 4:
Console.Clear();
classList = classs.GetAllClasses();
ClassCourseCollection classCourse = new
ClassCourseCollection();
classCourseList = classCourse.GetAllClassCourse();
teacherClassList = teacherClass.GetAllTeacherClass();
studentsectionList = studentsection.GetAllstudentsection();
Console.WriteLine("\n\n\n\n\tPress");
Console.WriteLine("\n\t1:Search Class");
Console.WriteLine("\n\t2:View Classes");
Console.WriteLine("\n\t3:View Class Courses");
Console.WriteLine("\n\t4:Search Class Courses");
Console.WriteLine("\n\t5:View Teacher Class ");
Console.WriteLine("\n\t6:Search Class Teacher");
Console.WriteLine("\n\t7:View Student Class ");
Console.WriteLine("\n\t8:Search Student Class ");
Console.WriteLine("\n\t9: Back");
Console.Write("\n\tEnter your choice: ");
int ct = int.Parse(Console.ReadLine());
if (ct == 1)
{
Console.Clear();
Console.WriteLine("Enter Class Name for Search: ");
string SearchClass= Console.ReadLine();
Console.WriteLine(" \tClassName \tStartDate \tEndDate ");
foreach (var c in classList)
{
if (c.ClassName == SearchClass) {
string onlyDate = c.StartDate.ToShortDateString();
string EndDate = c.EndDate.ToShortDateString();
Console.WriteLine("\t{0} \t{1} \t{2} ", c.ClassName,
onlyDate, EndDate);
}
}
Console.ReadKey();
Console.Clear();
}
if (ct == 2)
{
Console.Clear();
DisplayClasses(classList);
Console.ReadKey();
Console.Clear();
}
if (ct == 3)
{
Console.Clear();
DisplayClassCourse(classCourseList);
Console.ReadKey();
Console.Clear();
}
if (ct == 4)
{
Console.Clear();
Console.WriteLine("Enter Class Name for Search: ");
string SearchClass = Console.ReadLine();
Console.WriteLine(" \tCourse Name \n");
foreach (var c in classCourseList)
{
if (c.className == SearchClass)
{
}
if (ct == 6)
{
Console.Clear();
Console.WriteLine("Enter Teacher Name for Search: ");
string SC = Console.ReadLine();
Console.WriteLine(" \tClass \tSection \tCourse \n");
foreach (var t in teacherClassList)
{
if (t.TeacherName == SC)
{
}
if (ct == 8)
{
Console.Clear();
Console.WriteLine("Enter Student Name for Search: ");
string SC = Console.ReadLine();
Console.WriteLine(" \tClass \tSection \n");
foreach (var t in studentsectionList)
{
if (t.StudentName == SC)
{
Console.WriteLine("\t{0} \t{1} ", t.ClassName,
t.sectionName);
}
}
Console.ReadKey();
Console.Clear();
}
if (ct == 9)
{
break;
}
break;
case 0:
Console.Clear();
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
//Student Functions
//Teacher Functions
// Display Teachers
static public void DisplayTeachers(List<Teacher> teachers)
{
//Class Functions
//Class Functions
DataBase Queries
//SELECT classcourse.FKClassID,class.Name from classcourse join class on
classcourse.FKClassID = class.ClassID =class.ClassID ;
Model
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class Student
{
}
}
Teacher.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class Teacher
{
}
}
Classes.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class Classes
{
public int ClassID { get; set; }
public string ClassName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public List<string> CourseName { get; set; }
}
}
ClassCourse.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class ClassCourse
{
public string className { get; set; }
public string courseName { get; set; }
}
}
ClassSection.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class ClassSection
{
public int SectionID { get; set; }
public int ClassID { get; set; }
Studentsection.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class studentsection
{
}
}
TeacherClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class TeacherClass
{ public int ClassId { get; set; }
StudentCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class StudentCollection : ICollection<Student>
{
return list;
}
command.ExecuteNonQuery();
}
conn.Close();
students.Add(item);
}
public void DeleteStudent(int id, Student item, List<Student> students)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`student` SET `IsActive`
= '0' WHERE (`StudentID` = @id);";
command.Parameters.AddWithValue("@id", id);
command.ExecuteNonQuery();
students.Remove(item);
}
conn.Close();
}
conn.Close();
}
public void UpdatePhone(int id, string phone)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`student` SET `Phone` =
@phone WHERE(`StudentID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@phone", phone);
command.ExecuteNonQuery();
}
conn.Close();
}
list.Add(student);
}
conn.Close();
return list;
}
public List<Student> SearchByName(string SearchName)
{
List<Student> list = new List<Student>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM student WHERE FirstName =
@SearchName;";
command.Parameters.AddWithValue("@SearchName", SearchName);
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Student student = new Student();
student.StudentID = reader.GetInt32(0);
student.FirstName = reader.GetString(1);
student.LastName = reader.GetString(2);
student.Gender = reader.GetChar(3);
student.ClassName = reader.GetString(4);
student.Email = reader.GetString(5);
student.Phone = reader.GetString(6);
student.DateOfBirth = reader.GetDateTime(7);
student.DateOfAdmission = reader.GetDateTime(8);
list.Add(student);
}
conn.Close();
return list;
}
}
}
TeacherCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class TeacherCollection : ICollection<Teacher>
{
private List<Teacher> teachers = new List<Teacher>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
}
conn.Close();
return list;
}
public int Count => teachers.Count;
}
conn.Close();
teachers.Add(item);
}
conn.Close();
}
public void UpdateEmail(int id, string email)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`teacher` SET `Email` =
@email WHERE(`TeacherID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@email", email);
command.ExecuteNonQuery();
}
conn.Close();
}
public void UpdatePhone(int id, string phone)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`teacher` SET `Phone` =
@phone WHERE(`TeacherID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@phone", phone);
command.ExecuteNonQuery();
}
conn.Close();
}
public List<Teacher> SearchByID(int SearchID)
{
List<Teacher> list = new List<Teacher>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM teacher WHERE TeacherID =
@SearchID;";
command.Parameters.AddWithValue("@SearchID", SearchID);
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Teacher teacher = new Teacher();
teacher.TeacherID = reader.GetInt32(0);
teacher.FirstName = reader.GetString(1);
teacher.LastName = reader.GetString(2);
teacher.Gender = reader.GetChar(3);
teacher.Email = reader.GetString(4);
teacher.Phone = reader.GetString(5);
teacher.Course = reader.GetString(6);
teacher.DateOfJoining = reader.GetDateTime(7);
list.Add(teacher);
}
conn.Close();
return list;
}
public List<Teacher> SearchByName(string SearchName)
{
List<Teacher> list = new List<Teacher>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM teacher WHERE FirstName =
@SearchName;";
command.Parameters.AddWithValue("@SearchName", SearchName);
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Teacher teacher = new Teacher();
teacher.TeacherID = reader.GetInt32(0);
teacher.FirstName = reader.GetString(1);
teacher.LastName = reader.GetString(2);
teacher.Gender= reader.GetChar(3);
teacher.Email = reader.GetString(4);
teacher.Phone = reader.GetString(5);
teacher.Course = reader.GetString(6);
teacher.DateOfJoining = reader.GetDateTime(7);
list.Add(teacher);
}
conn.Close();
return list;
}
}
}
classesCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class classesCollection : ICollection<Classes>
{
private List<Classes> classes = new List<Classes>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
public List<Classes> GetAllClasses()
{
List<Classes> list = new List<Classes>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM schooldb.class;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Classes classs = new Classes();
classs.ClassID = reader.GetInt32(0);
classs.ClassName = reader.GetString(1);
classs.StartDate = reader.GetDateTime(2);
classs.EndDate = reader.GetDateTime(2);
list.Add(classs);
}
conn.Close();
return list;
}
public int Count => classes.Count;
}
}
ClassSectionCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class ClassSectionCollection : ICollection<ClassSection>
{ private List<ClassSection> ClassSections = new List<ClassSection>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
return list;
}
public void Add(ClassSection item)
{
conn.Open();
string Query = "INSERT INTO `schooldb`.`sectionclass` (`Id-Section`,
`Class-Id`, `NoOfStudent`) VALUES (@SI, @CI, @NOStudent);";
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = Query;
command.Parameters.AddWithValue("@CI", item.ClassID);
command.Parameters.AddWithValue("@SI", item.SectionID);
command.Parameters.AddWithValue("@NOStudent", item.NoOfStudent);
command.ExecuteNonQuery();
}
conn.Close();
ClassSections.Add(item);
}
conn.Close();
}
}
}
StudentSectionCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class StudentSectionCollection : ICollection<studentsection>
{
private List<studentsection> studentsections = new List<studentsection>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
public List<studentsection> GetAllstudentsection()
{
List<studentsection> list = new List<studentsection>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT student.FirstName, class.Name,
section.SectionName FROM registerstudent JOIN student ON registerstudent.StudID
= student.StudentID JOIN class ON registerstudent.ClasID =class.ClassID JOIN
section ON registerstudent.SectionId =section.SectionID;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
studentsection studentsection= new studentsection();
studentsection.StudentName = reader.GetString(0);
studentsection.ClassName = reader.GetString(1);
studentsection.sectionName = reader.GetString(2);
list.Add(studentsection);
conn.Close();
return list;
}
public int Count => studentsections.Count;
}
}
TeacherClassCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class TeacherClassCollection : ICollection<TeacherClass>
{ private List<TeacherClass> Teacherclasses = new List<TeacherClass>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
public List<TeacherClass> GetAllTeacherClass()
{
List<TeacherClass> list = new List<TeacherClass>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT teacherclass.TeacherID, teacher.FirstName,
teacherclass.ClassID, class.Name, teacherclass.SectionID, section.SectionName,
teacherclass.CourseID, course.Name FROM teacherclass JOIN teacher ON
teacherclass.TeacherID = teacher.TeacherID JOIN class ON teacherclass.ClassID =
class.ClassID\r\nJOIN section ON teacherclass.SectionID = section.SectionID JOIN
course ON teacherclass.CourseID = course.CourseID;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
TeacherClass classsCourse = new TeacherClass();
classsCourse.TeacherID = reader.GetInt32(0);
classsCourse.TeacherName = reader.GetString(1);
classsCourse.ClassId= reader.GetInt32(2);
classsCourse.ClassName = reader.GetString(3);
classsCourse.sectionID= reader.GetInt32(4);
classsCourse.SectionName= reader.GetString(5);
classsCourse.CourseID= reader.GetInt32(6);
classsCourse.courseName= reader.GetString(7);
list.Add(classsCourse);
}
conn.Close();
return list;
}
public int Count => Teacherclasses.Count;
command.ExecuteNonQuery();
}
conn.Close();
Teacherclasses.Add(item);
}
Output