Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
58 views

Assignment2 (Console Based)

The document is an assignment submission for a console application course. It includes the student names submitting the assignment, the course code, program title, and department. It also includes the source code for a school management system console application with classes for students, teachers, classes, and other school related entities. The application allows the user to view, add, update, delete and search student and teacher information as well as view class information.

Uploaded by

Amina Tariq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Assignment2 (Console Based)

The document is an assignment submission for a console application course. It includes the student names submitting the assignment, the course code, program title, and department. It also includes the source code for a school management system console application with classes for students, teachers, classes, and other school related entities. The application allows the user to view, add, update, delete and search student and teacher information as well as view class information.

Uploaded by

Amina Tariq
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

BUILDING CONSOLE APPLICATION

(ASSIGNMENT#2……SEMESTER FALL- 2022)


Submission date (February 17, 2023)

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

Degree Program Title and Section:


BS-V Computer Science (A)
Department of Computer Science

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>();

static void Main(string[] args)


{
Console.Title = "School Management System";

string logo1 = @" __ __ _ _


/ / /\ \ \___| | ___ ___ _ __ ___ ___ | |_ ___
\ \/ \/ / _ \ |/ __/ _ \| '_ ` _ \ / _ \ | __/ _ \
\ /\ / __/ | (_| (_) | | | | | | __/ | || (_) |
\/ \/ \___|_|\___\___/|_| |_| |_|\___| \__\___/
";
string logo = @"
*****************************************************************
***********************************************
* ____ _ _ *
* / ___| ___| |__ ___ ___ | | *
* \___ \ / __| '_ \ / _ \ / _ \| | *
* ___) | (__| | | | (_) | (_) | | *
* _ _ |____/ \___|_| |_|\___/ \___/|_| _
*
* | \/ | __ _ _ __ __ _ __ _ ___ _ __ ___ ___ _ __ | |_
*
* | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '_ ` _ \ / _ \ '_ \| __| *
* | | | | (_| | | | | (_| | (_| | __/ | | | | | __/ | | | |_ *
* |_| |_|\__,_|_| |_|\__,_|\__, |\___|_| |_| |_|\___|_| |_|\__|
*
* ____ |___/ _ *
* / ___| _ _ ___| |_ ___ _ ___ __
*
* \___ \| | | / __| __/ _ \ '_ ` _ \ *
* ___) | |_| \__ \ || __/ | | | | | *
* |____/ \__, |___/\__\___|_| |_| |_|
*
* |___/ *

*****************************************************************
***********************************************";
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 ");

for (int process = 0; process < 25; process++)


{
System.Threading.Thread.Sleep(50);
Console.Write(".");
}

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\t1:View Students Info");


Console.WriteLine("\n\t2:Delete Student Info");
Console.WriteLine("\n\t3:Update Student Info");
Console.WriteLine("\n\t4:Search Student Info");

Console.WriteLine("\n\t6: Back");
Console.Write("\n\tEnter your choice: ");

int choiceForStudent = int.Parse(Console.ReadLine());

if (choiceForStudent == 1)
{
Console.Clear();
DisplayStudents(studentList);

}
if (choiceForStudent == 2)
{
Console.Clear();

Console.Write("Enter ID for Deletion: ");


int id = int.Parse(Console.ReadLine());
Student stud = studentList.Find(s => s.StudentID == id);
if (student != null)
{
Console.WriteLine("Are you sure you want to delete this
student?");
Console.WriteLine("1. yes");
Console.WriteLine("2. No");
int ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
student.DeleteStudent(id, stud, studentList);
Console.WriteLine("Data is deleted successfully.");
break;
case 2:
break;
default:
Console.WriteLine("Invalid choice. Please try again.");
break;
}
}
else
{
Console.WriteLine("Student with ID " + id + " was not
found.");
}

}
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;
}

Console.WriteLine("Date is updated successfully.");


}
else
{
Console.WriteLine("Student with ID " + id + " was not
found.");
}

}
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();

Console.WriteLine("Register New Student");


Student newstudent = new Student();
ClassSection newClassSection = new ClassSection();
Console.Write("Enter First Name: ");
newstudent.FirstName = Console.ReadLine();
Console.Write("Enter Last Name: ");
newstudent.LastName = Console.ReadLine();
Console.Write("Enter Gender: ");
newstudent.Gender = char.Parse(Console.ReadLine());
Console.Write("Enter Class ID: ");
newClassSection.ClassID= int.Parse(Console.ReadLine());
foreach(var Cs in ClassSectionList)
{
if(newClassSection.ClassID==Cs.ClassID) {
if (Cs.NoOfStudent < 15)
{
newClassSection.SectionID=Cs.SectionID;
Cs.NoOfStudent++;

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);

Console.WriteLine("Student added successfully.");

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;

Console.Write("Enter Phone Number: ");


newteacher.Phone = Console.ReadLine();
newteacher.DateOfJoining= DateTime.Today;

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)
{

Console.WriteLine("What you want to update");


Console.WriteLine("1. Email");
Console.WriteLine("2. Phone");
Console.WriteLine("3. Back");
Console.Write("Enter your choice: ");

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;
}

Console.WriteLine("Date is updated successfully.");


}
else
{
Console.WriteLine("Teacher with ID " + id + " was not
found.");
}

}
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)
{

Console.WriteLine("\n\t{0} ", c.courseName );


}
}
Console.ReadKey();
Console.Clear();
}
if (ct == 5)
{
Console.Clear();
DisplayTeacherClass(teacherClassList);
Console.ReadKey();
Console.Clear();

}
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)
{

Console.WriteLine("\t{0} \t{1} \t{2} ", t.ClassName,


t.SectionName, t.courseName);
}
}
Console.ReadKey();
Console.Clear();
}
if (ct == 7)
{
Console.Clear();
DisplayStudentSection(studentsectionList);
Console.ReadKey();
Console.Clear();

}
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;

} while (choice != 0);


}

//Student Functions

// Display Student Data


static public void DisplayStudents(List<Student> students)
{
Console.WriteLine("\tID \tFirstName \tLastName \tGender \tClass\t \
tEmail\t\t \t\tPhoneNo \tDateOfBirth \tDateOfAdmission");
foreach (var student in students)
{
string onlyDate = student.DateOfBirth.ToShortDateString();
string DateOfAdmission =
student.DateOfAdmission.ToShortDateString();
Console.WriteLine("\t{0} \t{1}\t \t{2}\t \t{3} \t{4} \t{5}\t \t\t{6} \t{7}
\t{8}", student.StudentID, student.FirstName, student.LastName,
student.Gender, student.ClassName, student.Email, student.Phone, onlyDate,
DateOfAdmission);
}
}

//Teacher Functions

// Display Teachers
static public void DisplayTeachers(List<Teacher> teachers)
{

Console.WriteLine("\tID \tFirstName \tLastName \tGender \tEmail\t \


tPhoneNo \tDateOfJoining ");
foreach (var teacher in teachers)
{
string onlyDate = teacher.DateOfJoining.ToShortDateString();
Console.WriteLine("\t{0} \t{1}\t \t{2}\t \t{3} \t{4} \t{5} \t{6} ",
teacher.TeacherID, teacher.FirstName, teacher.LastName, teacher.Gender,
teacher.Email, teacher.Phone,onlyDate);
}
}

//Class Functions

// Display Class Data


static public void DisplayClasses(List<Classes> classes)
{
Console.WriteLine(" \tClass \tStartDate \tEndDate ");
foreach (var classs in classes)
{
string onlyDate = classs.StartDate.ToShortDateString();
string EndDate = classs.EndDate.ToShortDateString();
Console.WriteLine("\t{0} \t{1} \t{2} ",classs.ClassName, onlyDate,
EndDate);
}
}

//Class Functions

// Display ClassCourse Data


static public void DisplayClassCourse(List<ClassCourse> classesCourse)
{
Console.WriteLine(" \tClass \tCourse ");
foreach (var classCourse in classesCourse)
{

Console.WriteLine("\t{0} \t{1} ", classCourse.className,


classCourse.courseName);
}
}
// Display Teacher Class Data
static public void DisplayTeacherClass(List<TeacherClass>
teacherClassList)
{
Console.WriteLine("\tTeacher Class \t\tSection \tCourse ");
foreach (var tc in teacherClassList)
{

Console.WriteLine("\t{0} \t{1} \t{2} \t{3} ", tc.TeacherName,


tc.ClassName,tc.SectionName,tc.courseName);
}
}

// Display Student Section Data


static public void DisplayStudentSection(List<studentsection>
StudentSectionList)
{
Console.WriteLine("\tStudent \tClass\t \tSection ");
foreach (var tc in StudentSectionList)
{

Console.WriteLine("\t{0} \t\t{1} \t{2} ", tc.StudentName,


tc.ClassName, tc.sectionName);
}
}
}
}

DataBase Queries
//SELECT classcourse.FKClassID,class.Name from classcourse join class on
classcourse.FKClassID = class.ClassID =class.ClassID ;

//SELECT class.Name, course.Name


//FROM class
//JOIN classcourse ON class.ClassID = classcourse.FKClassID
//JOIN course ON classcourse.FKCourseID = course.CourseID;

//SELECT teacher.FirstName, class.Name


//FROM teacher
//JOIN teacherclass ON teacher.TeacherID = teacherclass.TeacherID
//JOIN class ON teacherclass.ClassID = class.ClassID;

// Query for registerstudent


//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;

// Query for teacherclass


//SELECT teacher.FirstName, class.Name, section.SectionName, course.Name
//FROM teacherclass
//JOIN teacher ON teacherclass.TeacherID = teacher.TeacherID
//JOIN class ON teacherclass.ClassID = class.ClassID
//JOIN section ON teacherclass.SectionID = section.SectionID
//JOIN course ON teacherclass.CourseID = course.CourseID;

//SELECT class.Name , section.SectionName, sectionclass.NoOfStudent


//FROM sectionclass
//JOIN class ON sectionclass.IdC = class.ClassID
//JOIN section ON sectionclass.IdS = section.SectionID;

Model
Student.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinalSMS
{
internal class Student
{

public int StudentID { get; set; }


public string FirstName { get; set; }
public string LastName { get; set; }
public string ClassName { get; set; }
public string Email { get; set; }
public char Gender { get; set; }
public string Phone { get; set; }
public DateTime DateOfBirth { get; set; }
public DateTime DateOfAdmission { get; set; }
public bool IsActive { get; set; }

}
}

Teacher.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FinalSMS
{
internal class Teacher
{

public int TeacherID { get; set; }


public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Course { get; set; }
public DateTime DateOfJoining { get; set; }
public char Gender { get; set; }

public bool IsActive { get; set; }

}
}
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; }

public int NoOfStudent { 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
{

public string StudentName { get; set; }


public string ClassName { get; set; }
public string sectionName { get; set; }

}
}
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; }

public string ClassName { get; set; }


public int TeacherID { get; set; }
public string TeacherName { get; set; }

public int sectionID { get; set; }


public string SectionName { get; set; }

public int CourseID { get; set; }


public string courseName { get; set; }
}
}
Collections

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>
{

private List<Student> students = new List<Student>();


static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);

//Get Data from Database


public List<Student> GetAllStudent()
{
List<Student> list = new List<Student>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM schooldb.student;";
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);
student.IsActive=reader.GetBoolean(9);
if (student.IsActive == true)
{
list.Add(student);
}
}
conn.Close();

return list;
}

public int Count => students.Count;

public bool IsReadOnly => false;


public void Add(Student item)
{
StudentCollection collection = new StudentCollection();
students = collection.GetAllStudent();
conn.Open();
string Query = "INSERT INTO `schooldb`.`student` (`FirstName`,
`LastName`,`Gender`, `ClassName`, `Email`, `Phone`,
`DateOfBirth`,`DateOfAdmission`) VALUES
(@fn,@ln,@gender,@Class,@email,@phone,@DOB,@DOA);";
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = Query;
command.Parameters.AddWithValue("@fn", item.FirstName);
command.Parameters.AddWithValue("@ln", item.LastName);
command.Parameters.AddWithValue("@gender", item.Gender);
command.Parameters.AddWithValue("@Class", item.ClassName);
command.Parameters.AddWithValue("@email", item.Email);
command.Parameters.AddWithValue("@phone", item.Phone);
command.Parameters.AddWithValue("@DOB", item.DateOfBirth);
command.Parameters.AddWithValue("@DOA", item.DateOfAdmission);

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();
}

public void UpdateEmail(int id, string email)


{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`student` SET `Email` =
@email WHERE(`StudentID` = @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`.`student` SET `Phone` =
@phone WHERE(`StudentID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@phone", phone);
command.ExecuteNonQuery();
}

conn.Close();
}

public List<Student> SearchByID(int SearchID)


{
List<Student> list = new List<Student>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM student WHERE StudentID =
@SearchID;";
command.Parameters.AddWithValue("@SearchID", SearchID);
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;
}
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);

// Get data from Database


public List<Teacher> GetAllTeacher()
{
List<Teacher> list = new List<Teacher>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM schooldb.teacher;";
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);
teacher.IsActive= reader.GetBoolean(8);
if (teacher.IsActive)
{
list.Add(teacher);
}

}
conn.Close();

return list;
}
public int Count => teachers.Count;

public bool IsReadOnly => false;


public void Add(Teacher item)
{
conn.Open();
string Query = "INSERT INTO `schooldb`.`teacher` (`FirstName`,
`LastName`,`Gender`, `Email`, `Phone`,`Course` ,`DateOfJoining`) VALUES
(@fn,@ln,@gender,@email,@phone,@cou,@DateOfJoining);";
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = Query;
command.Parameters.AddWithValue("@fn", item.FirstName);
command.Parameters.AddWithValue("@ln", item.LastName);
command.Parameters.AddWithValue("@gender", item.Gender);
command.Parameters.AddWithValue("@email", item.Email);
command.Parameters.AddWithValue("@phone", item.Phone);
command.Parameters.AddWithValue("@cou", item.Course);
command.Parameters.AddWithValue("@DateOfJoining",
item.DateOfJoining);
command.ExecuteNonQuery();

}
conn.Close();
teachers.Add(item);
}

public void DeleteTeacher(int id, Teacher item, List<Teacher> teachers)


{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`teacher` SET `IsActive`
= '0' WHERE (`TeacherID` = @id);";
command.Parameters.AddWithValue("@id", id);
command.ExecuteNonQuery();
teachers.Remove(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;

public bool IsReadOnly => false;

}
}

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);

public List<ClassSection> GetAllClassSection()


{
List<ClassSection> list = new List<ClassSection>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM schooldb.sectionclass;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
ClassSection classsection = new ClassSection();
classsection.SectionID = reader.GetInt32(0);
classsection.ClassID = reader.GetInt32(1);
classsection.NoOfStudent= reader.GetInt32(2);
list.Add(classsection);
}
conn.Close();

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);
}

public void UpdateNoOfStudent(int NoOfStudent, int classID, int sectionID)


{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`sectionclass` SET
`NoOfStudent` = @NoOfStudent WHERE (`Id-Section` = @sectionID) and (`Class-
Id` = @classID);";
command.Parameters.AddWithValue(" @NoOfStudent", NoOfStudent);
command.Parameters.AddWithValue("@sectionID", sectionID);
command.Parameters.AddWithValue("@classID", classID);
command.ExecuteNonQuery();
}

conn.Close();
}

public int Count => ClassSections.Count;

public bool IsReadOnly => false;

}
}

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;

public bool IsReadOnly => false;

}
}

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;

public bool IsReadOnly => false;


public void Add(TeacherClass item)
{
conn.Open();
string Query = "INSERT INTO `schooldb`.`teacherclass` (`TeacherID`,
`ClassID`, `SectionID`, `CourseID`) VALUES (@TId,@CId,@SId,@CourseId);\r\
n;";
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = Query;
command.Parameters.AddWithValue("@TId", item.TeacherID);
command.Parameters.AddWithValue("@CId", item.ClassId);
command.Parameters.AddWithValue("@SId", item.sectionID);
command.Parameters.AddWithValue("@CourseId", item.CourseID);

command.ExecuteNonQuery();

}
conn.Close();
Teacherclasses.Add(item);
}

public void Clear()


{
Teacherclasses.Clear();
}

Output

You might also like