You are on page 1of 99

DESIGN GUI FORMS

(ASSIGNMENT#3……SEMESTER FALL- 2022)


Submission date (February 23, 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
Home.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SchoolManagementSystem
{
public partial class Home : Form
{
TeacherCollection teacher = new TeacherCollection();
List<TeacherModel> teacherList = new List<TeacherModel>();
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
string username = Login.Username;

public Home()
{
InitializeComponent();
teacherList = teacher.GetAllTeacher();
studentList = student.GetAllStudent();
label3.Text = studentList.Count.ToString();
label4.Text = teacherList.Count.ToString();

private void StudentButton_Click(object sender, EventArgs e)


{
StudentMenu.Show(StudentButton, new Point(0,
StudentButton.Height));
}

private void Teacherbutton_Click(object sender, EventArgs e)


{
TeacherMenu.Show(Teacherbutton, new Point(0,
Teacherbutton.Height));
}

private void Registration_Click(object sender, EventArgs e)


{
new StudentRegistration(username).Show();
}

private void Update_Click(object sender, EventArgs e)


{
new UpdateStudent(username).Show();
}

private void Delete_Click(object sender, EventArgs e)


{
new DeleteStudent(username).Show();
}

private void Search_Click(object sender, EventArgs e)


{
new SearchStudent().Show();
}

private void Veiw_Click(object sender, EventArgs e)


{
new StudentList().Show();
}

private void toolStripMenuItem1_Click(object sender, EventArgs e)


{
new AddTeacher(username).Show();
}

private void toolStripMenuItem2_Click(object sender, EventArgs e)


{
new UpdateTeacher(username).Show();
}

private void toolStripMenuItem3_Click(object sender, EventArgs e)


{
new DeleteTeacher(username).Show();
}

private void toolStripMenuItem4_Click(object sender, EventArgs e)


{new SearchTeacher().Show();

private void toolStripMenuItem5_Click(object sender, EventArgs e)


{
new TeacherList().Show();
}

private void Classbutton_Click(object sender, EventArgs e)


{
ClassForm classForm = new ClassForm();
classForm.Show();
}

private void pictureBox1_Click(object sender, EventArgs e)


{
Login login = new Login();
login.Show();
this.Close();
}

private void label1_Click(object sender, EventArgs e)


{
Login login = new Login();
login.Show();
this.Close();
}

private void Home_Load(object sender, EventArgs e)


{

}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace SchoolManagementSystem
{
public partial class StudentRegistration : Form
{
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
string userName = string.Empty;
private static Regex email_validation()
{
string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";

return new Regex(pattern, RegexOptions.IgnoreCase);


}

static Regex validate_emailaddress = email_validation();


public StudentRegistration(string username)
{
InitializeComponent();
userName = username;
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{

StudentModel newstudent = new StudentModel();


if (FirstName.Text != "")
{
string inputText = FirstName.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newstudent.FirstName = formattedText;
}
else
{
MessageBox.Show("Please enter FirstName.");
FirstName.Focus();
return;
}

if (textBox2.Text != "")
{
string inputText = textBox2.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newstudent.LastName = formattedText;
}
else
{
MessageBox.Show("Please enter LastName.");
textBox2.Focus();
return;
}
if ((string)comboBox1.SelectedItem != "")
{
newstudent.Gender = (string)comboBox1.SelectedItem;

}
else
{
MessageBox.Show("Please select Gender");
comboBox1.Focus();
return;
}

if ((string)comboBox2.SelectedItem != "")
{
newstudent.ClassName = (string)comboBox2.SelectedItem;
newstudent.ClassId = comboBox2.SelectedIndex + 1;

}
else
{
MessageBox.Show("Please select Class");
comboBox2.Focus();
return;
}

if (validate_emailaddress.IsMatch(textBox3.Text) != true)
{
MessageBox.Show("Invalid Email Address!", "Invalid",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox3.Focus();
return;
}
else
{
newstudent.Email = textBox3.Text;
}

if (textBox4.Text != "")
{
newstudent.Phone = textBox4.Text;
}
else
{
MessageBox.Show("Please enter Phone No.");
textBox4.Focus();
return;
}

if (textBox5.Text != "")
{
string inputText = textBox5.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newstudent.Address = formattedText;
}
else
{
MessageBox.Show("Please enter Address");
textBox5.Focus();
return;
}

if (dateTimePicker1.Value != null)
{
newstudent.DateOfBirth = dateTimePicker1.Value;
}
else
{
MessageBox.Show("Please enter Address");
dateTimePicker1.Focus();
return;
}
newstudent.DateOfAdmission = DateTime.Today;
newstudent.AddedBy = userName;
DialogResult result = MessageBox.Show("Are you sure you want to add
a student?", "Add Student", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
student.Add(newstudent);
MessageBox.Show("Student added successfully.");
FirstName.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
comboBox1.SelectedItem = null;
comboBox2.SelectedItem = null;
dateTimePicker1 = null;
}
}

private void FirstName_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(FirstName.Text))
{
bool containsNonLetters = false;
foreach (char c in FirstName.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}
if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
FirstName.Text = FirstName.Text.Remove(FirstName.Text.Length
- 1);
}
}
}

private void textBox2_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox2.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox2.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox2.Text = textBox2.Text.Remove(textBox2.Text.Length - 1);
}
}
}

private void textBox4_Validating(object sender, CancelEventArgs e)


{
if (!string.IsNullOrEmpty(textBox4.Text))
{
if (textBox4.Text.Length != 13 || textBox4.Text[0] != '+')
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox4.Focus();
e.Cancel = true;
}
else
{
for (int i = 1; i < textBox4.Text.Length; i++)
{
if (!char.IsDigit(textBox4.Text[i]))
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox4.Focus();
e.Cancel = true;
break;
}
}
}
}
}

private void button3_Click(object sender, EventArgs e)


{
//Clear
FirstName.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
comboBox1.SelectedItem = null;
comboBox2.SelectedItem = null;
dateTimePicker1 = null;

}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace SchoolManagementSystem
{
public partial class UpdateStudent : Form
{
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
string userName = string.Empty;

private static Regex email_validation()


{
string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";

return new Regex(pattern, RegexOptions.IgnoreCase);


}

static Regex validate_emailaddress = email_validation();


public UpdateStudent(string username)
{
InitializeComponent();
studentList = student.GetAllStudent();
userName = username;
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{
// search
List<StudentModel> stud = new List<StudentModel>();

string searchText = "";


int searchID = 0;
{
if (textBox11.Text != "")
{
searchID = int.Parse(textBox11.Text);
}
if (textBox1.Text != "")
{
string inputText = textBox1.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

searchText = formattedText;
}
}
if (searchID != null && searchText != "" && searchID != 0)
{
stud = student.SearchByNameandId(searchID, searchText);
dataGridView1.DataSource= stud;

}
else if (searchText != "")
{
stud = student.SearchByName(searchText);
dataGridView1.DataSource = stud;
}
else if (searchID != null && searchID != 0)
{
stud=student.SearchByID(searchID);
dataGridView1.DataSource = stud;
}

else
{
MessageBox.Show("Student not found.");
textBox11.Focus();
}
}

private void button3_Click(object sender, EventArgs e)


{
//Update Student
StudentModel newstudent = new StudentModel();
if(textBox2.Text != "")
{
newstudent.StudentID= int.Parse(textBox2.Text);
}
if (textBox10.Text != "")
{
string inputText = textBox10.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newstudent.FirstName = formattedText;
}
else
{
MessageBox.Show("Please enter FirstName.");
textBox10.Focus();
return;
}

if (textBox9.Text != "")
{
string inputText = textBox9.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

newstudent.LastName = formattedText;
}
else
{
MessageBox.Show("Please enter LastName.");
textBox9.Focus();
return;
}
if ((string)comboBox4.SelectedItem != "")
{
newstudent.Gender = (string)comboBox4.SelectedItem;

}
else
{
MessageBox.Show("Please select Gender");
comboBox4.Focus();
return;
}

if ((string)comboBox3.SelectedItem != "")
{
newstudent.ClassName = (string)comboBox3.SelectedItem;
newstudent.ClassId = comboBox3.SelectedIndex + 1;

}
else
{
MessageBox.Show("Please select Class");
comboBox3.Focus();
return;
}

if (validate_emailaddress.IsMatch(textBox8.Text) != true)
{
MessageBox.Show("Invalid Email Address!", "Invalid",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox8.Focus();
return;
}
else
{
newstudent.Email = textBox8.Text;
}

if (textBox7.Text != "")
{
newstudent.Phone = textBox7.Text;
}
else
{
MessageBox.Show("Please enter Phone No.");
textBox7.Focus();
return;
}

if (textBox6.Text != "")
{
string inputText = textBox6.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newstudent.Address = formattedText;
}
else
{
MessageBox.Show("Please enter Address");
textBox6.Focus();
return;
}
newstudent.UpdatedBy = userName;
DialogResult result = MessageBox.Show("Are you sure you want to
Update ?", "Update Student", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
student.Update(newstudent);
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
selectedRow.Cells[1].Value = textBox10.Text;
selectedRow.Cells[2].Value = textBox9.Text;
selectedRow.Cells[4].Value = textBox8.Text;
selectedRow.Cells[3].Value = comboBox3.SelectedItem;
selectedRow.Cells[5].Value = comboBox4.SelectedItem;
selectedRow.Cells[6].Value = textBox7.Text;
selectedRow.Cells[7].Value = textBox6.Text;

dataGridView1.Refresh();
MessageBox.Show("Data is Updated successfully.");
}

private void textBox10_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox10.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox10.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox10.Text = textBox10.Text.Remove(textBox10.Text.Length -
1);
}
}
}

private void textBox9_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox9.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox9.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox9.Text = textBox9.Text.Remove(textBox9.Text.Length - 1);
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox1.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
}

private void textBox11_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox11.Text))
{
int result;
double doubleResult;
if (!int.TryParse(textBox11.Text, out result) && !
double.TryParse(textBox11.Text, out doubleResult))
{
MessageBox.Show("Please enter a valid ID.");
textBox11.Text = string.Empty;
}
}
}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)


{
if (dataGridView1.SelectedRows.Count > 0)
{
DataGridViewRow row = dataGridView1.SelectedRows[0];
int id = (int)row.Cells[0].Value;
textBox2.Text = id.ToString();
textBox10.Text = (string)row.Cells[1].Value;
textBox9.Text = (string)row.Cells[2].Value;

comboBox3.SelectedItem = (string)row.Cells[3].Value;
textBox8.Text = (string)row.Cells[4].Value;
comboBox4.SelectedItem = (string)row.Cells[5].Value;

textBox7.Text = (string)row.Cells[6].Value;
textBox6.Text = (string)row.Cells[7].Value;
}
}

private void textBox7_Validating(object sender, CancelEventArgs e)


{
if (!string.IsNullOrEmpty(textBox8.Text))
{
if (textBox7.Text.Length != 13 || textBox7.Text[0] != '+')
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox8.Focus();
e.Cancel = true;
}
else
{
for (int i = 1; i < textBox7.Text.Length; i++)
{
if (!char.IsDigit(textBox7.Text[i]))
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox7.Focus();
e.Cancel = true;
break;
}
}
}
}
}

private void button6_Click(object sender, EventArgs e)


{
//Clear
dataGridView1.DataSource = null;
textBox1.Text = "";
textBox11.Text = "";
textBox2.Text = "";
textBox10.Text = "";
textBox9.Text = "";

comboBox3.SelectedItem = null;
textBox8.Text = "";
comboBox4.SelectedItem = null;

textBox7.Text = "";
textBox6.Text = "";

}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
public partial class DeleteStudent : Form
{
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
List<StudentModel> stud = new List<StudentModel>();
string userName = string.Empty;

public DeleteStudent(string username)


{
InitializeComponent();
userName = username;
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{
// search

string searchText = "";


int searchID = 0;
{
if (textBox11.Text != "")
{
searchID = int.Parse(textBox11.Text);
}
if (textBox1.Text != "")
{
string inputText = textBox1.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

searchText = formattedText;
}
}
if (searchID != null && searchText != "" && searchID != 0)
{
stud = student.SearchByNameandId(searchID, searchText);
dataGridView1.DataSource = stud;

}
else if (searchText != "")
{
stud = student.SearchByName(searchText);
dataGridView1.DataSource = stud;
}
else if (searchID != null && searchID != 0)
{
stud = student.SearchByID(searchID);
dataGridView1.DataSource = stud;
}

else
{
MessageBox.Show("Student not found.");
textBox11.Focus();
}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)


{
if (dataGridView1.SelectedRows.Count > 0)
{
DataGridViewRow row = dataGridView1.SelectedRows[0];
int id = (int)row.Cells[0].Value;
textBox2.Text = id.ToString();
textBox10.Text = (string)row.Cells[1].Value;
textBox9.Text = (string)row.Cells[2].Value;
comboBox3.SelectedItem = (string)row.Cells[3].Value;
textBox8.Text = (string)row.Cells[4].Value;
comboBox4.SelectedItem = (string)row.Cells[5].Value;

textBox7.Text = (string)row.Cells[6].Value;
textBox6.Text = (string)row.Cells[7].Value;
}
}

private void button6_Click(object sender, EventArgs e)


{
//Clear
foreach (DataGridViewRow row in dataGridView1.Rows)
{

if (row.Selected)
{

row.Selected = false;

}
textBox1.Text = "";
textBox11.Text = "";
textBox2.Text = "";
textBox10.Text = "";
textBox9.Text = "";

comboBox3.SelectedItem = null;
textBox8.Text = "";
comboBox4.SelectedItem = null;
textBox7.Text = "";
textBox6.Text = "";
}

private void button3_Click(object sender, EventArgs e)


{
//Delete
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
int id = (int)selectedRow.Cells[0].Value;
StudentModel studt = studentList.Find(s => s.StudentID == id);
DialogResult result = MessageBox.Show("Are you sure you want to
delete a student?", "Delete Student", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
student.DeleteStudent(id, studt,userName);

textBox1.Text = "";
textBox11.Text = "";
textBox2.Text = "";
textBox10.Text = "";
textBox9.Text = "";

comboBox3.SelectedItem = null;
textBox8.Text = "";
comboBox4.SelectedItem = null;

textBox7.Text = "";
textBox6.Text = "";

dataGridView1.DataSource = null;
MessageBox.Show("Data is deleted successfully.");
}

//stud.Remove(studt);
//dataGridView1.Rows.Remove(selectedRow);

private void textBox11_TextChanged(object sender, EventArgs e)


{

if (!string.IsNullOrEmpty(textBox11.Text))
{
int result;
double doubleResult;
if (!int.TryParse(textBox11.Text, out result) && !
double.TryParse(textBox11.Text, out doubleResult))
{
MessageBox.Show("Please enter a valid ID.");
textBox11.Text = string.Empty;
}
}
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox1.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox1.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
public partial class SearchStudent : Form
{
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
List<StudentModel> stud = new List<StudentModel>();
public SearchStudent()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{
// search

string searchText = "";


int searchID = 0;
{
if (textBox11.Text != "")
{
searchID = int.Parse(textBox11.Text);
}
if (textBox1.Text != "")
{
string inputText = textBox1.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

searchText = formattedText;
}
}
if (searchID != null && searchText != "" && searchID != 0)
{
stud = student.SearchByNameandId(searchID, searchText);
dataGridView1.DataSource = stud;

}
else if (searchText != "")
{
stud = student.SearchByName(searchText);
dataGridView1.DataSource = stud;
}
else if (searchID != null && searchID != 0)
{
stud = student.SearchByID(searchID);
dataGridView1.DataSource = stud;
}

else
{
MessageBox.Show("Student not found.");
textBox11.Focus();
}
}

private void button3_Click(object sender, EventArgs e)


{
//Clear
textBox1.Text = "";
textBox11.Text = "";
dataGridView1.DataSource = null;
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
public partial class StudentList : Form
{
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
public StudentList()
{
InitializeComponent();
studentList = student.GetAllStudent();
dataGridView1.DataSource = studentList;
}

private void button1_Click(object sender, EventArgs e)


{ //Back
this.Hide();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace SchoolManagementSystem
{
public partial class AddTeacher : Form
{
TeacherCollection teacher = new TeacherCollection();
string userName = string.Empty;
private static Regex email_validation()
{
string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";

return new Regex(pattern, RegexOptions.IgnoreCase);


}

static Regex validate_emailaddress = email_validation();


private Home home;
public AddTeacher(string username)
{
InitializeComponent();

userName = username;

// MessageBox.Show(userName);
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{
//Add Teacher
TeacherModel newteacher = new TeacherModel();
if (textBox1.Text != "")
{
string inputText = textBox1.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newteacher.FirstName = formattedText;
}
else
{
MessageBox.Show("Please enter FirstName.");
textBox1.Focus();
return;
}

if (textBox2.Text != "")
{
string inputText = textBox2.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newteacher.LastName = formattedText;
}
else
{
MessageBox.Show("Please enter LastName.");
textBox2.Focus();
return;
}
if ((string)comboBox1.SelectedItem != "")
{

newteacher.Gender = (string)comboBox1.SelectedItem;

}
else
{
MessageBox.Show("Please select Gender");
comboBox1.Focus();
return;
}
if (validate_emailaddress.IsMatch(textBox3.Text) != true)
{
MessageBox.Show("Invalid Email Address!", "Invalid",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox3.Focus();
return;
}
else
{
newteacher.Email = textBox3.Text;
}

if (textBox4.Text != "")
{
newteacher.Phone = textBox4.Text;
}
else
{
MessageBox.Show("Please enter Phone No.");
textBox4.Focus();
return;
}

if (textBox5.Text != "")
{
string inputText = textBox5.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

newteacher.Address = formattedText;
}
else
{
MessageBox.Show("Please enter Address");
textBox5.Focus();
return;
}

newteacher.DateOfJoining = DateTime.Today;
newteacher.AddedBy = userName;

DialogResult result = MessageBox.Show("Are you sure you want to add


a Teacher?", "Add Teacher", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
teacher.Add(newteacher);

MessageBox.Show("Teacher added successfully.");


textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
comboBox1.SelectedItem = null;

}
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox1.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox1.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox1.Text = textBox1.Text.Remove (textBox1.Text.Length - 1);
}
}
}

private void textBox2_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox2.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox2.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox2.Text = textBox2.Text.Remove(textBox2.Text.Length - 1);
}
}
}
private void textBox4_Validating(object sender, CancelEventArgs e)
{
if (!string.IsNullOrEmpty(textBox4.Text))
{
if (textBox4.Text.Length != 13 || textBox4.Text[0] != '+')
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox4.Focus();
e.Cancel = true;
}
else
{
for (int i = 1; i < textBox4.Text.Length; i++)
{
if (!char.IsDigit(textBox4.Text[i]))
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox4.Focus();
e.Cancel = true;
break;
}
}
}
}
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
comboBox1.SelectedItem = null;
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace SchoolManagementSystem
{
public partial class UpdateTeacher : Form
{
TeacherCollection teacher = new TeacherCollection();
List<TeacherModel> teacherList = new List<TeacherModel>();
private static Regex email_validation()
{
string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
+ @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
+ @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";

return new Regex(pattern, RegexOptions.IgnoreCase);


}

static Regex validate_emailaddress = email_validation();


string userName = string.Empty;
public UpdateTeacher(string username)
{
InitializeComponent();
userName = username;
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{
List<TeacherModel> teach = new List<TeacherModel>();

string searchText = "";


int searchID = 0;
{
if (textBox11.Text != "")
{
searchID = int.Parse(textBox11.Text);
}
if (textBox1.Text != "")
{
string inputText = textBox1.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

searchText = formattedText;
}
}
if (searchID != null && searchText != "" && searchID != 0)
{
teach = teacher.SearchByNameandId(searchID, searchText);
dataGridView1.DataSource = teach;

}
else if (searchText != "")
{
teach = teacher.SearchByName(searchText);
dataGridView1.DataSource = teach;
}
else if (searchID != null && searchID != 0)
{
teach = teacher.SearchByID(searchID);
dataGridView1.DataSource = teach;
}

else
{
MessageBox.Show("Teacher not found.");
textBox11.Focus();
}

}
private void button3_Click(object sender, EventArgs e)
{
//Update Teacher
TeacherModel newteacher = new TeacherModel();
if (textBox2.Text != "")
{
newteacher.TeacherID = int.Parse(textBox2.Text);
}
if (textBox10.Text != "")
{
string inputText = textBox10.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newteacher.FirstName = formattedText;
}
else
{
MessageBox.Show("Please enter FirstName.");
textBox10.Focus();
return;
}

if (textBox9.Text != "")
{
string inputText = textBox9.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

newteacher.LastName = formattedText;
}
else
{
MessageBox.Show("Please enter LastName.");
textBox9.Focus();
return;
}
if ((string)comboBox4.SelectedItem != "")
{
newteacher.Gender = (string)comboBox4.SelectedItem;

}
else
{
MessageBox.Show("Please select Gender");
comboBox4.Focus();
return;
}

if (validate_emailaddress.IsMatch(textBox8.Text) != true)
{
MessageBox.Show("Invalid Email Address!", "Invalid",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
textBox8.Focus();
return;
}
else
{
newteacher.Email = textBox8.Text;
}

if (textBox7.Text != "")
{
newteacher.Phone = textBox7.Text;
}
else
{
MessageBox.Show("Please enter Phone No.");
textBox7.Focus();
return;
}

if (textBox6.Text != "")
{
string inputText = textBox6.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);
newteacher.Address = formattedText;
}
else
{
MessageBox.Show("Please enter Address");
textBox6.Focus();
return;
}
newteacher.UpdatedBy = userName;
DialogResult result = MessageBox.Show("Are you sure you want to
Update ?", "Update Teacher", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
teacher.Update(newteacher);
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
selectedRow.Cells[1].Value = textBox10.Text;
selectedRow.Cells[2].Value = textBox9.Text;
selectedRow.Cells[4].Value = textBox8.Text;

selectedRow.Cells[3].Value = comboBox4.SelectedItem;
selectedRow.Cells[5].Value = textBox7.Text;
selectedRow.Cells[6].Value = textBox6.Text;
dataGridView1.Refresh();
MessageBox.Show("Data is Updated successfully.");
}
}

private void button6_Click(object sender, EventArgs e)


{
//Clear
dataGridView1.DataSource = null;
textBox1.Text = "";
textBox11.Text = "";
textBox2.Text = "";
textBox10.Text = "";
textBox9.Text = "";

textBox8.Text = "";
comboBox4.SelectedItem = null;

textBox7.Text = "";
textBox6.Text = "";

private void dataGridView1_SelectionChanged(object sender, EventArgs e)


{
if (dataGridView1.SelectedRows.Count > 0)
{
DataGridViewRow row = dataGridView1.SelectedRows[0];
int id = (int)row.Cells[0].Value;
textBox2.Text = id.ToString();
textBox10.Text = (string)row.Cells[1].Value;
textBox9.Text = (string)row.Cells[2].Value;
textBox8.Text = (string)row.Cells[4].Value;
comboBox4.SelectedItem = (string)row.Cells[3].Value;
textBox7.Text = (string)row.Cells[5].Value;
textBox6.Text = (string)row.Cells[6].Value;
}
}

private void textBox10_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox10.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox10.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox10.Text = textBox10.Text.Remove(textBox10.Text.Length -
1);
}
}
}

private void textBox9_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox9.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox9.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox9.Text = textBox9.Text.Remove(textBox9.Text.Length - 1);
}
}
}

private void textBox7_Validating(object sender, CancelEventArgs e)


{
if (!string.IsNullOrEmpty(textBox8.Text))
{
if (textBox7.Text.Length != 13 || textBox7.Text[0] != '+')
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox8.Focus();
e.Cancel = true;
}
else
{
for (int i = 1; i < textBox7.Text.Length; i++)
{
if (!char.IsDigit(textBox7.Text[i]))
{
MessageBox.Show("Please enter a valid phone number with a
country code in the format +1234567890123.");
textBox7.Focus();
e.Cancel = true;
break;
}
}
}
}
}

private void textBox11_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox11.Text))
{
int result;
double doubleResult;
if (!int.TryParse(textBox11.Text, out result) && !
double.TryParse(textBox11.Text, out doubleResult))
{
MessageBox.Show("Please enter a valid ID.");
textBox11.Text = string.Empty;
}
}
}

private void textBox1_TextChanged(object sender, EventArgs e)


{
if (!string.IsNullOrEmpty(textBox1.Text))
{
bool containsNonLetters = false;
foreach (char c in textBox1.Text)
{
if (!char.IsLetter(c))
{
containsNonLetters = true;
break;
}
}

if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1);
}
}
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
public partial class SearchTeacher : Form
{
TeacherCollection teacher = new TeacherCollection();
List<TeacherModel> teacherList = new List<TeacherModel>();
public SearchTeacher()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}

private void button2_Click(object sender, EventArgs e)


{
//Search
List<TeacherModel> teach = new List<TeacherModel>();

string searchText = "";


int searchID = 0;
{
if (textBox11.Text != "")
{
searchID = int.Parse(textBox11.Text);
}
if (textBox1.Text != "")
{
string inputText = textBox1.Text; ;
string formattedText = inputText.ToLower();
formattedText = char.ToUpper(formattedText[0]) +
formattedText.Substring(1);

searchText = formattedText;
}
}
if (searchID != null && searchText != "" && searchID != 0)
{
teach = teacher.SearchByNameandId(searchID, searchText);
dataGridView1.DataSource = teach;

}
else if (searchText != "")
{
teach = teacher.SearchByName(searchText);
dataGridView1.DataSource = teach;
}
else if (searchID != null && searchID != 0)
{
teach = teacher.SearchByID(searchID);
dataGridView1.DataSource = teach;
}

else
{
MessageBox.Show("Teacher not found.");
textBox11.Focus();
}
}

private void button3_Click(object sender, EventArgs e)


{
//Clear
textBox1.Text = "";
textBox11.Text = "";
dataGridView1.DataSource = null;
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
public partial class TeacherList : Form
{
TeacherCollection teacher = new TeacherCollection();
List<TeacherModel> teacherList = new List<TeacherModel>();
public TeacherList()
{
InitializeComponent();
teacherList = teacher.GetAllTeacher();
dataGridView1.DataSource= teacherList;
}

private void button1_Click(object sender, EventArgs e)


{
this.Hide();
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;

namespace SchoolManagementSystem
{
public partial class ClassForm : Form
{ List<SchoolSectionName> sectionList = new List<SchoolSectionName>();
SchoolSectionNameCollection sectionName = new
SchoolSectionNameCollection();
List<schoolclassesModel> GradeList = new List<schoolclassesModel>();
schoolclassesCollection Grade = new schoolclassesCollection();
List<ClassModel> ClassList = new List<ClassModel>();
ClassCollection Classs = new ClassCollection();
List<String> Classes = new List<String>();
public static string className = "";
public static string SecName = "";
public static string TeacherName = "";
public static string CourseName = "";
public static int teacherId = 0;
int SearchYear = 0;
public ClassForm()
{
InitializeComponent();
sectionList = sectionName.GetAllSection();
ClassList=Classs.GetAllClasses();
// dataGridView1.DataSource = sectionList;
GradeList= Grade.GetAllSchoolClasses();
}

private void ClassForm_Load(object sender, EventArgs e)


{
GradeList = Grade.GetAllSchoolClasses();
sectionList = sectionName.GetAllSection();
foreach (var c in ClassList)
{
Classes.Add(c.ClassName);
}
comboBox2.DataSource = Classes;
comboBox2.SelectedItem = null; comboBox2.SelectedIndex = -1;
}

private void button2_Click(object sender, EventArgs e)


{
List<SchoolSectionName> secList = new List<SchoolSectionName>();

string SearchClass= "";


//Search
{
if (comboBox1.SelectedItem != null)
{
SearchYear = Convert.ToInt32(comboBox1.SelectedItem);
}
if (comboBox2.SelectedItem != null)
{
SearchClass = comboBox2.SelectedItem.ToString();
}
}
{
if (SearchClass != "" || SearchYear != 0)
{
button7.Visible = true;
}
}
foreach(var s in sectionList)
{
if (SearchYear == s.Year && SearchClass == s.ClassName)
{
secList.Add(s);
}
else if (SearchYear == s.Year && SearchClass == "")
{
secList.Add(s);
}
else if (SearchYear == 0 && SearchClass == s.ClassName)
{
secList.Add(s);
}
}
dataGridView1.DataSource= secList;
if (SearchYear == 2023)
{
button3.Visible = true;
}
else if (SearchYear != 2023)
{
button3.Visible = false;
}
}

private void button1_Click(object sender, EventArgs e)


{ //Back
this.Hide();
}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)


{
GradeList = Grade.GetAllSchoolClasses();
List<teacherAndCourse> listA = new List<teacherAndCourse>();

if (dataGridView1.SelectedRows.Count > 0)
{
DataGridViewRow row = dataGridView1.SelectedRows[0];
className = (string)row.Cells[0].Value;

SecName = (string)row.Cells[1].Value;
foreach (var g in GradeList)
{
if(className == g.ClassName && SecName==g.SectionName) {
listA.Add(new teacherAndCourse {TeacherID=g.teacherId,
Teacher = g.TeacherName, Course = g.courseName });

}
}

dataGridView2.DataSource= listA;
if( SearchYear==2023)
{
button4.Visible = true;
button5.Visible = true;
button6.Visible = true;
// button7.Visible = true;

// DataGridViewRow selectedRow = null;


TeacherName = "";
CourseName = string.Empty;

}
else if (dataGridView2.Visible == true && SearchYear != 2023)
{
button4.Visible = false;
button5.Visible= false;
button6.Visible= false;
// button7.Visible = false;
dataGridView2.Visible= false;
}

private void button3_Click(object sender, EventArgs e)


{
//Add New Section
AddNewSection addNewSection = new AddNewSection(className);
addNewSection.Show();

private void button4_Click(object sender, EventArgs e)


{ // Assign Section
AssignSection assignSection = new AssignSection(className,
SecName);
assignSection.Show();
}

private void button5_Click(object sender, EventArgs e)


{
if (dataGridView2.SelectedRows.Count > 0)
{

DataGridViewRow row = dataGridView2.SelectedRows[0];


teacherId = (int)row.Cells[0].Value;
TeacherName = (string)row.Cells[1].Value;
CourseName = (string)row.Cells[2].Value;

}
ChangeTeacher changeTeacher = new ChangeTeacher(className,
SecName, TeacherName, CourseName,teacherId);
changeTeacher.Show();
}

private void button7_Click(object sender, EventArgs e)


{
dataGridView2.Visible = true;
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace SchoolManagementSystem
{
public partial class ChangeTeacher : Form
{ string Class;
string Section;
string Teacher;
string cousre;
int teacherId;
List<schoolClassesID> schoolClassIDList = new
List<schoolClassesID>();
SchoolClassIDCollection schoolClassID = new
SchoolClassIDCollection();
List<TeacherModel> TeacherList = new List<TeacherModel>();
TeacherCollection Teachers = new TeacherCollection();
List<int> teach = new List<int>();
List<TeacherModel> AvailableTeacher = new List<TeacherModel>();
List<ClassModel> ClassList = new List<ClassModel>();
ClassCollection ClassCollection = new ClassCollection();
List<SectionModel> SectionList = new List<SectionModel>();
SectionCollection SectionCollection = new SectionCollection();
List<CourseModel> CourseList = new List<CourseModel>();
CourseCollection Courses = new CourseCollection();

int sId = 0;
int CId = 0;
int CouId = 0;

public int NoOfCousre = 0;

public ChangeTeacher(string classname, string secName, string


techerName, string cousre, int TeacherId)
{
InitializeComponent();
TeacherList = Teachers.GetAllTeacher();
ClassList = ClassCollection.GetAllClasses();
SectionList = SectionCollection.GetAllSection();
CourseList = Courses.GetAllCourse();
this.Class = classname;
this.Section= secName;
this.Teacher = techerName;
this .cousre = cousre;
this.teacherId = TeacherId;
textBox1.Text= cousre;
textBox2.Text = Class;
textBox3 .Text = Section;
textBox4 .Text = Teacher;
schoolClassIDList = schoolClassID.GetAllSchoolClasses();

private void button2_Click(object sender, EventArgs e)


{
// Check
foreach(var t in TeacherList)
{
if (t.NoOfCourse < 6)
{
teach.Add(t.TeacherID);
}
}
foreach(var t in TeacherList)
{
foreach( var te in teach)
{
if(te==t.TeacherID)
{
AvailableTeacher.Add(t);
}
}
}
comboBox1.DataSource = teach;
dataGridView1.DataSource = AvailableTeacher;
}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)


{
if (dataGridView1.SelectedRows.Count > 0)
{

DataGridViewRow row = dataGridView1.SelectedRows[0];


comboBox1.SelectedItem = (int)row.Cells[0].Value;
}
}

private void button3_Click(object sender, EventArgs e)


{
// Change
int selectedTeacher = 0;
selectedTeacher = (int)comboBox1.SelectedItem;
TeacherModel teacherr = new TeacherModel();
foreach(var t in TeacherList)
{
if (selectedTeacher == t.TeacherID)
{
textBox5.Text = t.FirstName;
NoOfCousre = t.NoOfCourse + 1;
Teachers.UpdateNoofCourse(selectedTeacher, NoOfCousre);

}
}
foreach(var c in ClassList)
{
if (c.ClassName == Class)
{
CId = c.ClassID;
}
}
foreach(var s in SectionList)
{
if (s.SectionName == Section)
{
sId = s.sectionId;
}
}
foreach(var co in CourseList)
{
if (co.courseName == cousre)
{
CouId = co.CourseId;
}
}
schoolClassesID newschoolClass = new schoolClassesID();
newschoolClass.SectionId = sId;
newschoolClass.CourseId = CouId;
newschoolClass.teacherId= (int)comboBox1.SelectedItem;
newschoolClass.classId = CId;
DialogResult result = MessageBox.Show("Are you sure you want to
Change Teacher?", "Change Teacher", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
comboBox1.DataSource = null;
dataGridView1.DataSource= null;
schoolClassID.Update(newschoolClass, teacherId);
this.Hide();

}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace SchoolManagementSystem
{
public partial class AssignSection : Form
{
string Class = "";
string section = "";
List<ClassModel> classlist = new List<ClassModel>();
ClassCollection classes = new ClassCollection();
List<string> ClassName = new List<string>();
// List<string> StudentName = new List<string>();
List<int> StudentIds = new List<int>();
List<int> StudIds = new List<int>();
List<int> StId = new List<int>();
List<StudentModel> studentList = new List<StudentModel>();
StudentCollection student = new StudentCollection();
List<SectionModel> sectionlist = new List<SectionModel>();
SectionCollection sections = new SectionCollection();
List<SchoolSectionName> sectionList = new List<SchoolSectionName>();
SchoolSectionNameCollection sectionName = new
SchoolSectionNameCollection();
List<StudentSectionModel> studentSectionList = new
List<StudentSectionModel>();
StudentSectionCollection studentSections = new
StudentSectionCollection();
List<StudentModel> studentInfo = new List<StudentModel>();

List<string> sec = new List<string>();


public AssignSection( string classname, string secName)
{
InitializeComponent();
this.Class = classname;
this.section = secName;
classlist = classes.GetAllClasses();
studentList = student.GetAllStudent();
sectionlist = sections.GetAllSection();
sectionList = sectionName.GetAllSection();
// ClassSectionlist = ClassSection.GetAllClassSection();
studentSectionList = studentSections.GetAllstudentsection();
}

private void AssignSection_Load(object sender, EventArgs e)


{
foreach (var c in classlist)
{
ClassName.Add(c.ClassName);
}
// comboBox1.SelectionMode = SelectionMode.MultiSimple;
textBox2.Text= Class;
textBox3.Text = section;
}

private void button2_Click(object sender, EventArgs e)


{

studentSectionList = studentSections.GetAllstudentsection();
comboBox2.Text = "";
StudentIds.Clear();
StudIds.Clear();
StId.Clear();
string studentClass = Class;

foreach (var s in studentList)


{
if (s.ClassName == studentClass)
{
StudentIds.Add(s.StudentID);
}
}

foreach (var ss in studentSectionList)


{
StudIds.Add(ss.StudentID);
}
StId = StudentIds.Except(StudIds).ToList();

comboBox2.DataSource = null; comboBox2.DisplayMember = null;


comboBox2.DataSource = StId;
comboBox2.DisplayMember = StId.ToString();
foreach(var s in studentList)
{ foreach (var ss in StId)
{

if (s.StudentID == ss)
{
studentInfo.Add(s);
}

}
dataGridView1.DataSource = studentInfo;
}

private void button3_Click(object sender, EventArgs e)


{
StudentSectionModel studentsection = new StudentSectionModel();
foreach (var s in studentList)
{
if (s.StudentID == (int)comboBox2.SelectedItem)
{
textBox1.Text = "";
textBox1.Text = s.FirstName;
}
}
studentsection.StudentID = (int)comboBox2.SelectedItem;
foreach(var s in sectionlist)
{
if (s.SectionName == section)
{
studentsection.SecId = s.sectionId;
}
}
foreach(var c in classlist)
{
if (c.ClassName == Class)
{
studentsection.ClassID = c.ClassID;
}
}
// studentsection.SecId = comboBox3.SelectedIndex + 1;
// studentsection.ClassID = comboBox1.SelectedIndex + 1;

DialogResult result = MessageBox.Show("Are you sure you want to


Assign Section?", "Assign Section", MessageBoxButtons.YesNo,
MessageBoxIcon.Question);

if (result == DialogResult.Yes)
{
// studentSections.UpdateNoOfStudent( studentsection.SecId,
studentsection.ClassID);
studentSections.Add(studentsection);
textBox1.Text = "";
comboBox2.Text = "";
StudentIds.Clear();
StudIds.Clear();
StId.Clear();
studentInfo.Clear();
dataGridView1.DataSource = null;
MessageBox.Show("Student added successfully.");
}

private void dataGridView1_SelectionChanged(object sender, EventArgs e)


{
if (dataGridView1.SelectedRows.Count > 0)
{

DataGridViewRow row = dataGridView1.SelectedRows[0];


comboBox2.SelectedItem= (int)row.Cells[0].Value;

}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
public partial class AddNewSection : Form
{
string Class = "";
string Section = "";
List<ClassModel> ClassList = new List<ClassModel>();
ClassCollection classes = new ClassCollection();
List<SchoolSectionID> SchoolSectionlist = new List<SchoolSectionID>();
SchoolSectionIDCollection shlSectionD = new
SchoolSectionIDCollection();
List<SectionModel> sectionlist = new List<SectionModel>();
SectionCollection sections = new SectionCollection();
List<SchoolSectionName> sectionList = new List<SchoolSectionName>();
SchoolSectionNameCollection sectionName = new
SchoolSectionNameCollection();
ClassCourseCollection classesCourse = new ClassCourseCollection();
List<ClassCourseModel> classCourseList = new
List<ClassCourseModel>();
List<TeacherModel> TeacherList = new List<TeacherModel>();
TeacherCollection Teachers = new TeacherCollection();
List<int> teach = new List<int>();
List<TeacherModel> AvailableTeacher = new List<TeacherModel>();
List<string> courseList = new List<string>();
List<int> SecList = new List<int>();
int SecId = 0;
string NewSection = "";
int ClassId = 0;
DataGridViewComboBoxColumn comboBoxColumn = new
DataGridViewComboBoxColumn();
public AddNewSection(string className)
{
InitializeComponent();
this.Class = className;

ClassList= classes.GetAllClasses();
sectionlist = sections.GetAllSection();
sectionList = sectionName.GetAllSection();
SchoolSectionlist = shlSectionD.GetAllTeacher();
classCourseList = classesCourse.GetAllClassCourse();
TeacherList = Teachers.GetAllTeacher();

private void AddNewSection_Load(object sender, EventArgs e)


{
textBox2.Text = Class;
foreach(var c in ClassList)
{
if (c.ClassName == Class)
{
ClassId = c.ClassID;
}
}
label3.Text = ClassId.ToString();

foreach (var s in SchoolSectionlist)


{
if (s.ClassId == ClassId)
{
SecList.Add(s.SectionId);

}
}

SecId = SecList.Count;
foreach(var s in sectionlist)
{
if (SecId == s.sectionId)
{
textBox3.Text=s.SectionName;
}
}

foreach (var t in TeacherList)


{
if (t.NoOfCourse < 6)
{
teach.Add(t.TeacherID);
}
}
foreach (var t in TeacherList)
{
foreach (var te in teach)
{
if (te == t.TeacherID)
{
AvailableTeacher.Add(t);

}
}
}

private void button2_Click(object sender, EventArgs e)


{
List<teacherAndCourse> listA = new List<teacherAndCourse>();
foreach (var c in classCourseList)
{
if ( Class ==c.className )
{
courseList.Add(c.courseName);
listA.Add(new teacherAndCourse { TeacherID = 1, Teacher =
"NewTeacher", Course = c.courseName });
}
}

comboBox1.DataSource = courseList;

comboBoxColumn.Name = "TeacherId";
comboBoxColumn.HeaderText = "Teacher Id";
comboBoxColumn.DataSource = teach;

dataGridView1.DataSource = listA;
//dataGridView1.Columns.Add(column);
dataGridView1.Columns.Add(comboBoxColumn);
}

private void dataGridView1_CellValueChanged(object sender,


DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == comboBoxColumn.Index && e.RowIndex >= 0)
{

DataGridViewComboBoxCell comboBoxCell =
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as
DataGridViewComboBoxCell;
string selectedItem = comboBoxCell.Value.ToString();

MessageBox.Show("Selected item: " + selectedItem);

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

You might also like