Assignment3 (GUI Based)
Assignment3 (GUI Based)
Submitted By:
Ayesha Zulfiqar (20021519-023)
Amina Tariq (20021519-035)
Noor Ul Ain (20021519-069)
Insharah Farooq (20021519-096)
Submitted To:
Dr. Usman Ali
Course Code (Course Title):
CS-303 (Advance Programming Techniques
University Of Gujrat
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();
}
}
}
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]$";
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;
}
}
if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox2.Text = textBox2.Text.Remove(textBox2.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.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;
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();
}
}
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.");
}
if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox10.Text = textBox10.Text.Remove(textBox10.Text.Length -
1);
}
}
}
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);
}
}
}
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;
}
}
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;
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();
}
textBox7.Text = (string)row.Cells[6].Value;
textBox6.Text = (string)row.Cells[7].Value;
}
}
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 = "";
}
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);
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;
}
}
}
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();
}
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();
}
}
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;
}
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]$";
userName = username;
// MessageBox.Show(userName);
}
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;
if (result == DialogResult.Yes)
{
teacher.Add(newteacher);
}
}
if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox1.Text = textBox1.Text.Remove (textBox1.Text.Length - 1);
}
}
}
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;
}
}
}
}
}
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]$";
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.");
}
}
textBox8.Text = "";
comboBox4.SelectedItem = null;
textBox7.Text = "";
textBox6.Text = "";
if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox10.Text = textBox10.Text.Remove(textBox10.Text.Length -
1);
}
}
}
if (containsNonLetters)
{
MessageBox.Show("Please enter only alphabetic characters.");
textBox9.Text = textBox9.Text.Remove(textBox9.Text.Length - 1);
}
}
}
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();
}
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();
}
}
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;
}
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();
}
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;
}
else if (dataGridView2.Visible == true && SearchYear != 2023)
{
button4.Visible = false;
button5.Visible= false;
button6.Visible= false;
// button7.Visible = false;
dataGridView2.Visible= false;
}
}
ChangeTeacher changeTeacher = new ChangeTeacher(className,
SecName, TeacherName, CourseName,teacherId);
changeTeacher.Show();
}
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;
}
}
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>();
studentSectionList = studentSections.GetAllstudentsection();
comboBox2.Text = "";
StudentIds.Clear();
StudIds.Clear();
StId.Clear();
string studentClass = Class;
if (s.StudentID == ss)
{
studentInfo.Add(s);
}
}
dataGridView1.DataSource = studentInfo;
}
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.");
}
}
}
}
}
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();
}
}
SecId = SecList.Count;
foreach(var s in sectionlist)
{
if (SecId == s.sectionId)
{
textBox3.Text=s.SectionName;
}
}
}
}
}
comboBox1.DataSource = courseList;
comboBoxColumn.Name = "TeacherId";
comboBoxColumn.HeaderText = "Teacher Id";
comboBoxColumn.DataSource = teach;
dataGridView1.DataSource = listA;
//dataGridView1.Columns.Add(column);
dataGridView1.Columns.Add(comboBoxColumn);
}
DataGridViewComboBoxCell comboBoxCell =
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] as
DataGridViewComboBoxCell;
string selectedItem = comboBoxCell.Value.ToString();
}
}
}
}
DataBase Queries
//SELECT classcourse.FKClassID,class.Name from classcourse join class on
classcourse.FKClassID = class.ClassID =class.ClassID ;
Model
Student.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class Student
{
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
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class Classes
{
public int ClassID { get; set; }
public string ClassName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public List<string> CourseName { get; set; }
}
}
ClassCourse.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class ClassCourse
{
public string className { get; set; }
public string courseName { get; set; }
}
}
ClassSection.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class ClassSection
{
public int SectionID { get; set; }
public int ClassID { get; set; }
Studentsection.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class studentsection
{
}
}
TeacherClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class TeacherClass
{ public int ClassId { get; set; }
StudentCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class StudentCollection : ICollection<Student>
{
return list;
}
command.ExecuteNonQuery();
}
conn.Close();
students.Add(item);
}
public void DeleteStudent(int id, Student item, List<Student> students)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`student` SET `IsActive`
= '0' WHERE (`StudentID` = @id);";
command.Parameters.AddWithValue("@id", id);
command.ExecuteNonQuery();
students.Remove(item);
}
conn.Close();
}
conn.Close();
}
public void UpdatePhone(int id, string phone)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`student` SET `Phone` =
@phone WHERE(`StudentID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@phone", phone);
command.ExecuteNonQuery();
}
conn.Close();
}
list.Add(student);
}
conn.Close();
return list;
}
public List<Student> SearchByName(string SearchName)
{
List<Student> list = new List<Student>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM student WHERE FirstName =
@SearchName;";
command.Parameters.AddWithValue("@SearchName", SearchName);
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Student student = new Student();
student.StudentID = reader.GetInt32(0);
student.FirstName = reader.GetString(1);
student.LastName = reader.GetString(2);
student.Gender = reader.GetChar(3);
student.ClassName = reader.GetString(4);
student.Email = reader.GetString(5);
student.Phone = reader.GetString(6);
student.DateOfBirth = reader.GetDateTime(7);
student.DateOfAdmission = reader.GetDateTime(8);
list.Add(student);
}
conn.Close();
return list;
}
}
}
TeacherCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class TeacherCollection : ICollection<Teacher>
{
private List<Teacher> teachers = new List<Teacher>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
}
conn.Close();
return list;
}
public int Count => teachers.Count;
conn.Close();
}
public void UpdateEmail(int id, string email)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`teacher` SET `Email` =
@email WHERE(`TeacherID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@email", email);
command.ExecuteNonQuery();
}
conn.Close();
}
public void UpdatePhone(int id, string phone)
{
conn.Open();
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = "UPDATE `schooldb`.`teacher` SET `Phone` =
@phone WHERE(`TeacherID` = @id)";
command.Parameters.AddWithValue("@id", id);
command.Parameters.AddWithValue("@phone", phone);
command.ExecuteNonQuery();
}
conn.Close();
}
public List<Teacher> SearchByID(int SearchID)
{
List<Teacher> list = new List<Teacher>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM teacher WHERE TeacherID =
@SearchID;";
command.Parameters.AddWithValue("@SearchID", SearchID);
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Teacher teacher = new Teacher();
teacher.TeacherID = reader.GetInt32(0);
teacher.FirstName = reader.GetString(1);
teacher.LastName = reader.GetString(2);
teacher.Gender = reader.GetChar(3);
teacher.Email = reader.GetString(4);
teacher.Phone = reader.GetString(5);
teacher.Course = reader.GetString(6);
teacher.DateOfJoining = reader.GetDateTime(7);
list.Add(teacher);
}
conn.Close();
return list;
}
public List<Teacher> SearchByName(string SearchName)
{
List<Teacher> list = new List<Teacher>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM teacher WHERE FirstName =
@SearchName;";
command.Parameters.AddWithValue("@SearchName", SearchName);
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Teacher teacher = new Teacher();
teacher.TeacherID = reader.GetInt32(0);
teacher.FirstName = reader.GetString(1);
teacher.LastName = reader.GetString(2);
teacher.Gender= reader.GetChar(3);
teacher.Email = reader.GetString(4);
teacher.Phone = reader.GetString(5);
teacher.Course = reader.GetString(6);
teacher.DateOfJoining = reader.GetDateTime(7);
list.Add(teacher);
}
conn.Close();
return list;
}
}
}
classesCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class classesCollection : ICollection<Classes>
{
private List<Classes> classes = new List<Classes>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
public List<Classes> GetAllClasses()
{
List<Classes> list = new List<Classes>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT * FROM schooldb.class;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
Classes classs = new Classes();
classs.ClassID = reader.GetInt32(0);
classs.ClassName = reader.GetString(1);
classs.StartDate = reader.GetDateTime(2);
classs.EndDate = reader.GetDateTime(2);
list.Add(classs);
}
conn.Close();
return list;
}
public int Count => classes.Count;
}
}
ClassSectionCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class ClassSectionCollection : ICollection<ClassSection>
{ private List<ClassSection> ClassSections = new List<ClassSection>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
return list;
}
public void Add(ClassSection item)
{
conn.Open();
string Query = "INSERT INTO `schooldb`.`sectionclass` (`Id-Section`,
`Class-Id`, `NoOfStudent`) VALUES (@SI, @CI, @NOStudent);";
using (MySqlCommand command = conn.CreateCommand())
{
command.CommandText = Query;
command.Parameters.AddWithValue("@CI", item.ClassID);
command.Parameters.AddWithValue("@SI", item.SectionID);
command.Parameters.AddWithValue("@NOStudent", item.NoOfStudent);
command.ExecuteNonQuery();
}
conn.Close();
ClassSections.Add(item);
}
conn.Close();
}
}
}
StudentSectionCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class StudentSectionCollection : ICollection<studentsection>
{
private List<studentsection> studentsections = new List<studentsection>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
public List<studentsection> GetAllstudentsection()
{
List<studentsection> list = new List<studentsection>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT student.FirstName, class.Name,
section.SectionName FROM registerstudent JOIN student ON registerstudent.StudID
= student.StudentID JOIN class ON registerstudent.ClasID =class.ClassID JOIN
section ON registerstudent.SectionId =section.SectionID;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
studentsection studentsection= new studentsection();
studentsection.StudentName = reader.GetString(0);
studentsection.ClassName = reader.GetString(1);
studentsection.sectionName = reader.GetString(2);
list.Add(studentsection);
conn.Close();
return list;
}
public int Count => studentsections.Count;
TeacherClassCollection.cs
using MySqlConnector;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FinalSMS
{
internal class TeacherClassCollection : ICollection<TeacherClass>
{ private List<TeacherClass> Teacherclasses = new List<TeacherClass>();
static string connString =
"Server=localhost;Database=schooldb;Uid=root;Pwd=amina23";
MySqlConnection conn = new MySqlConnection(connString);
public List<TeacherClass> GetAllTeacherClass()
{
List<TeacherClass> list = new List<TeacherClass>();
conn.Open();
MySqlCommand command = conn.CreateCommand();
string Query = "SELECT teacherclass.TeacherID, teacher.FirstName,
teacherclass.ClassID, class.Name, teacherclass.SectionID, section.SectionName,
teacherclass.CourseID, course.Name FROM teacherclass JOIN teacher ON
teacherclass.TeacherID = teacher.TeacherID JOIN class ON teacherclass.ClassID =
class.ClassID\r\nJOIN section ON teacherclass.SectionID = section.SectionID JOIN
course ON teacherclass.CourseID = course.CourseID;";
command.CommandText = Query;
var reader = command.ExecuteReader();
while (reader.Read())
{
TeacherClass classsCourse = new TeacherClass();
classsCourse.TeacherID = reader.GetInt32(0);
classsCourse.TeacherName = reader.GetString(1);
classsCourse.ClassId= reader.GetInt32(2);
classsCourse.ClassName = reader.GetString(3);
classsCourse.sectionID= reader.GetInt32(4);
classsCourse.SectionName= reader.GetString(5);
classsCourse.CourseID= reader.GetInt32(6);
classsCourse.courseName= reader.GetString(7);
list.Add(classsCourse);
}
conn.Close();
return list;
}
public int Count => Teacherclasses.Count;
command.ExecuteNonQuery();
}
conn.Close();
Teacherclasses.Add(item);
}