private void frmTeachers_Load(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { var teachers = (from c in db.Teachers select c).ToList(); cboState.DisplayMember = "state"; cboState.ValueMember = "state"; cboStateUp.DisplayMember = "state"; cboStateUp.ValueMember = "state"; var states = new[] { new { state = "VIC" }, new { state = "QLD" }, new { state = "SA" }, new { state = "TAS" }, new { state = "WA" }, new { state = "NSW" }, new { state = "NT" }, new { state = "ACT" }, }; cboState.DataSource = states; cboStateUp.DataSource = states; } this.updateTeacher(); Clear(); }
public void updateMarks() { using (SchoolEntities db = new SchoolEntities()) { var m = (from s in db.Students select new { s.SID }).ToList(); var n = (from c in db.Courses select new { c.CID }).ToList(); cboCIDEdit.DisplayMember = "CID"; cboCIDEdit.ValueMember = "CID"; cboCIDEdit.DataSource = n; int cno = Convert.ToInt32(cboCIDEdit.Text); var g = (from d in db.Student_Course where d.CID == cno select d).ToList(); dGVMarks.DataSource = g; dGVMarks.Columns[3].Visible = false; dGVMarks.Columns[4].Visible = false; dGVMarks.Columns["SID"].ReadOnly = true; dGVMarks.Columns["CID"].ReadOnly = true; cboCIDAdd.DisplayMember = "CID"; cboCIDAdd.ValueMember = "CID"; cboCIDAdd.DataSource = n; cboSIDAdd.DisplayMember = "SID"; cboSIDAdd.ValueMember = "SID"; cboSIDAdd.DataSource = m; } }
private void btnEdit_Click(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int cno = Convert.ToInt32(cboCIDEdit.Text); int[] sid = (from c in db.Student_Course where c.CID == cno select c.SID).ToArray(); int sct = sid.Length; for (int i = 0; i < sct; i++) { int studentid = sid[i]; Student_Course cou = (from c in db.Student_Course where c.CID == cno && c.SID == studentid select c).FirstOrDefault(); string markInput = dGVMarks.Rows[i].Cells[MarkCol].Value.ToString(); string output = val.valMark(markInput); int markEd = Convert.ToInt32(markInput); if (!(output == "")) { MessageBox.Show(output); } cou.Mark = markEd; db.SaveChanges(); } } updateMarks(); }
private void btnAddMarks_Click(object sender, EventArgs e) { string mark = val.valMark(txtMarkAdd.Text); if (!(mark == "")) { MessageBox.Show(mark); } using (SchoolEntities db = new SchoolEntities()) { int sno = Convert.ToInt32(cboSIDAdd.Text); int cno = Convert.ToInt32(cboCIDAdd.Text); Student_Course course = (from c in db.Student_Course where sno == c.SID && cno == c.CID select c).FirstOrDefault(); if (course != null) { MessageBox.Show("Mark Exists Already. Cannot Add Marks."); } else { course = new Student_Course(); course.SID = sno; course.CID = cno; course.Mark = Convert.ToInt32(txtMarkAdd.Text); db.Student_Course.Add(course); db.SaveChanges(); MessageBox.Show("Mark Added."); } updateMarks(); } }
public void refreshForm() { using (SchoolEntities db = new SchoolEntities()) { var students = (from c in db.Students select c).ToList(); cboState.DisplayMember = "state"; cboState.ValueMember = "state"; cboStateUp.DisplayMember = "state"; cboStateUp.ValueMember = "state"; var states = new[] { new { state = "VIC" }, new { state = "QLD" }, new { state = "SA" }, new { state = "TAS" }, new { state = "WA" }, new { state = "NSW" }, new { state = "NT" }, new { state = "ACT" }, }; cboState.DataSource = states; cboStateUp.DataSource = states; } }
public string validCID(string s) { using (SchoolEntities db = new SchoolEntities()) { string output = ""; int value; bool CIDisInt = int.TryParse(s, out value); var list = (from c in db.Courses where c.CID == value select c).FirstOrDefault(); if (string.IsNullOrEmpty(s)) { return(output = "Course ID cannot be Empty!"); } if (!CIDisInt) { return(output = "Course ID must be Interger!"); } if (list != null) { return(output = "ID exists already. Please check!"); } return(output); } }
private void btnLogin_Click(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int uname; string inputUname = txtUsername.Text; bool isInt = int.TryParse(inputUname, out uname); string pass = txtPassword.Text; if (string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("Please type username and password."); return; } if (!isInt) { MessageBox.Show("Please type integer for username."); return; } if (cboUser.Text == "Teachers") { Teacher teacher = (from c in db.Teachers where c.TID == uname select c).FirstOrDefault(); if (teacher == null) { MessageBox.Show("Username cannot be found in the Teacher Table."); return; } if (teacher.TID == uname && teacher.Password == pass) { new frmTeacherDash().ShowDialog(); } else { MessageBox.Show("Wrong Username or Password for Teachers!"); return; } } else { Administrator admin = (from c in db.Administrators where c.AID == uname select c).FirstOrDefault(); if (admin == null) { MessageBox.Show("Username cannot be found in the Admin Table."); return; } if (admin.AID == uname && admin.Password == pass) { new frmAdminDash().ShowDialog(); } else { MessageBox.Show("Wrong Username or Password for Admins!"); return; } } } }
private void cboCIDEdit_SelectedIndexChanged(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int cid = Convert.ToInt32(cboCIDEdit.Text); var course = (from c in db.Student_Course where c.CID == cid select c).ToList(); dGVMarks.DataSource = course; } }
public void updateStudent() { using (SchoolEntities db = new SchoolEntities()) { var students = (from c in db.Students select c).ToList(); cboSIDUp.DisplayMember = "SID"; cboSIDUp.ValueMember = "SID"; cboSIDUp.DataSource = students; } }
private void updateTeacher() { using (SchoolEntities db = new SchoolEntities()) { var teachers = (from c in db.Teachers select c).ToList(); cboTIDUp.DisplayMember = "TID"; cboTIDUp.ValueMember = "TID"; cboTIDUp.DataSource = teachers; } }
public void refreshForm() { using (SchoolEntities db = new SchoolEntities()) { var courses = (from c in db.Courses select c).ToList(); cboCourseID.DisplayMember = "CID"; cboCourseID.ValueMember = "CID"; cboCourseID.DataSource = courses; } }
public void updateAdmin() { using (SchoolEntities db = new SchoolEntities()) { var admins = (from c in db.Administrators select c).ToList(); cboAIDUp.DisplayMember = "AID"; cboAIDUp.ValueMember = "AID"; cboAIDUp.DataSource = admins; } }
private void cboAIDUp_SelectedIndexChanged(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int ano = Convert.ToInt32(cboAIDUp.Text); Administrator admins = (from c in db.Administrators where c.AID == ano select c).First(); txtFNameUp.Text = admins.FName; txtLNameUp.Text = admins.LName; txtPasswordUp.Text = admins.Password; } }
public void updateTeacher() { using (SchoolEntities db = new SchoolEntities()) { var courses = (from c in db.Teachers select c).ToList(); cboAlloTeacher.DisplayMember = "TID"; cboAlloTeacher.ValueMember = "TID"; cboAlloTeacher.DataSource = courses; cboAllodTeacher.DisplayMember = "TID"; cboAllodTeacher.ValueMember = "TID"; cboAllodTeacher.DataSource = courses; } }
private void cboCourseID_SelectedIndexChanged(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int cno = Convert.ToInt32(cboCourseID.Text); Course courses = (from c in db.Courses where c.CID == cno select c).First(); txtCourseNameUp.Text = courses.CName; cboAllodTeacher.Text = courses.TID.ToString(); txtYearUp.Text = courses.Year.ToString(); txtSemUp.Text = courses.Semester.ToString(); } }
private void btnDelete_Click(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int cno = Convert.ToInt32(cboCourseID.Text); Course cor = (from c in db.Courses where c.CID == cno select c).First(); db.Courses.Remove(cor); db.SaveChanges(); MessageBox.Show("Course Deleted!"); } this.updateTeacher(); this.refreshForm(); }
private void btnDelete_Click(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int tno = Convert.ToInt32(cboTIDUp.Text); Teacher teach = (from c in db.Teachers where c.TID == tno select c).First(); db.Teachers.Remove(teach); db.SaveChanges(); MessageBox.Show("Teacher Deleted!"); } this.updateTeacher(); }
private void btnDelete_Click(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int sno = Convert.ToInt32(cboSIDUp.Text); Student stud = (from c in db.Students where c.SID == sno select c).First(); db.Students.Remove(stud); db.SaveChanges(); MessageBox.Show("Student Deleted!"); } this.updateStudent(); }
private void btnDelete_Click(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int ano = Convert.ToInt32(cboAIDUp.Text); Administrator admins = (from c in db.Administrators where c.AID == ano select c).First(); db.Administrators.Remove(admins); db.SaveChanges(); MessageBox.Show("Admin Deleted!"); } this.updateAdmin(); }
private void btnUpdate_Click(object sender, EventArgs e) { string msgFName = val.valFName(txtFNameUp.Text); string msgLName = val.valLName(txtLNameUp.Text); string msgDate = val.validDateStart(dateSDUp.Value); string msgDateDOB = val.validDateDOB(dateSUp.Value); string msgPhone = val.valPhone(txtPhoneUp.Text); string msgAdd1 = val.valAdd1(txtAddressLine1Up.Text); string msgAdd2 = val.valAdd2(txtAddressLine2Up.Text); string msgSuburb = val.valSub(txtSuburbUp.Text); string msgPost = val.valPostcode(txtPostcodeUp.Text); if (msgFName == "" && msgLName == "" && msgDate == "" && msgDateDOB == "" && msgPhone == "" && msgAdd1 == "" && msgAdd2 == "" && msgSuburb == "" && msgPost == "") { using (SchoolEntities db = new SchoolEntities()) { int sno = Convert.ToInt32(cboSIDUp.Text); Student students = (from c in db.Students where c.SID == sno select c).First(); students.FName = txtFNameUp.Text; students.LName = txtLNameUp.Text; students.SDate = dateSDUp.Value; students.DOB = dateSUp.Value; students.Phone = txtPhoneUp.Text; students.Add1 = txtAddressLine1Up.Text; students.Add2 = txtAddressLine2Up.Text; students.Suburb = txtSuburbUp.Text; students.State = cboStateUp.Text; students.Postcode = txtPostcodeUp.Text; db.SaveChanges(); MessageBox.Show("Student Updated!"); } } else { MessageBox.Show(msgFName + "\r\n" + msgLName + "\r\n" + msgPhone + "\r\n" + msgAdd1 + "\r\n" + msgAdd2 + "\r\n" + msgSuburb + "\r\n" + msgPost); } this.updateStudent(); }
private void cboSIDUp_SelectedIndexChanged(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int sno = Convert.ToInt32(cboSIDUp.Text); Student students = (from c in db.Students where c.SID == sno select c).First(); txtFNameUp.Text = students.FName; txtLNameUp.Text = students.LName; dateSUp.Value = students.DOB; txtPhoneUp.Text = students.Phone; txtAddressLine1Up.Text = students.Add1; txtAddressLine2Up.Text = students.Add2; txtSuburbUp.Text = students.Suburb; cboStateUp.Text = students.State; txtPostcodeUp.Text = students.Postcode; dateSDUp.Value = students.SDate; } }
private void btnUpdate_Click(object sender, EventArgs e) { string msgFName = val.valFName(txtFNameUp.Text); string msgLName = val.valLName(txtLNameUp.Text); string msgDate = val.validDateDOB(dateTUp.Value); string msgPhone = val.valPhone(txtPhoneUp.Text); string msgAdd1 = val.valAdd1(txtAddressLine1Up.Text); string msgAdd2 = val.valAdd2(txtAddressLine2Up.Text); string msgSuburb = val.valSub(txtSuburbUp.Text); string msgPost = val.valPostcode(txtPostcodeUp.Text); string msgRego = val.valRegoNo(txtRegNoUp.Text); string msgPass = val.valPassword(txtPasswordUp.Text); if (msgFName == "" && msgLName == "" && msgDate == "" && msgPhone == "" && msgAdd1 == "" && msgAdd2 == "" && msgSuburb == "" && msgPost == "" && msgRego == "" && msgPass == "") { using (SchoolEntities db = new SchoolEntities()) { int tno = Convert.ToInt32(cboTIDUp.Text); Teacher teachers = (from c in db.Teachers where c.TID == tno select c).First(); teachers.FName = txtFNameUp.Text; teachers.LName = txtLNameUp.Text; teachers.DOB = dateTUp.Value; teachers.Phone = txtPhoneUp.Text; teachers.Add1 = txtAddressLine1Up.Text; teachers.Add2 = txtAddressLine2Up.Text; teachers.Suburb = txtSuburbUp.Text; teachers.State = cboStateUp.Text; teachers.Postcode = txtPostcodeUp.Text; teachers.RegNo = txtRegNoUp.Text; teachers.Password = txtPasswordUp.Text; db.SaveChanges(); MessageBox.Show("Teacher Updated!"); } this.updateTeacher(); } else { MessageBox.Show(msgFName + "\r\n" + msgLName + "\r\n" + msgPhone + "\r\n" + msgAdd1 + "\r\n" + msgAdd2 + "\r\n" + msgSuburb + "\r\n" + msgPost + "\r\n" + msgRego + "\r\n" + msgPass); } }
private void cboTIDUp_SelectedIndexChanged(object sender, EventArgs e) { using (SchoolEntities db = new SchoolEntities()) { int tno = Convert.ToInt32(cboTIDUp.Text); Teacher teachers = (from c in db.Teachers where c.TID == tno select c).First(); txtFNameUp.Text = teachers.FName; txtLNameUp.Text = teachers.LName; dateTUp.Value = teachers.DOB; txtPhoneUp.Text = teachers.Phone; txtAddressLine1Up.Text = teachers.Add1; txtAddressLine2Up.Text = teachers.Add2; txtSuburbUp.Text = teachers.Suburb; cboStateUp.Text = teachers.State; txtPostcodeUp.Text = teachers.Postcode; txtRegNoUp.Text = teachers.RegNo; txtPasswordUp.Text = teachers.Password; } }
private void btnAdd_Click(object sender, EventArgs e) { string msgFName = val.valFName(txtFName.Text); string msgLName = val.valLName(txtLName.Text); string msgDate = val.validDateStart(dateSD.Value); string msgDateDOB = val.validDateDOB(dateS.Value); string msgPhone = val.valPhone(txtPhone.Text); string msgAdd1 = val.valAdd1(txtAddressLine1.Text); string msgAdd2 = val.valAdd2(txtAddressLine2.Text); string msgSuburb = val.valSub(txtSuburb.Text); string msgPost = val.valPostcode(txtPostcode.Text); if (msgFName == "" && msgLName == "" && msgDate == "" && msgDateDOB == "" && msgPhone == "" && msgAdd1 == "" && msgAdd2 == "" && msgSuburb == "" && msgPost == "") { using (SchoolEntities db = new SchoolEntities()) { Student students = new Student(); students.FName = txtFName.Text; students.LName = txtLName.Text; students.DOB = dateS.Value; students.Phone = txtPhone.Text; students.Add1 = txtAddressLine1.Text; students.Add2 = txtAddressLine2.Text; students.Suburb = txtSuburb.Text; students.State = cboState.Text; students.Postcode = txtPostcode.Text; students.SDate = dateSD.Value; db.Students.Add(students); db.SaveChanges(); MessageBox.Show("New Student Added! ID:" + students.SID); } } else { MessageBox.Show(msgFName + "\r\n" + msgLName + "\r\n" + msgPhone + "\r\n" + msgDate + "\r\n" + msgAdd1 + "\r\n" + msgDateDOB + "\r\n" + msgAdd2 + "\r\n" + msgSuburb + "\r\n" + msgPost); } this.refreshForm(); this.updateStudent(); }
private void btnAdd_Click(object sender, EventArgs e) { string msgFName = val.valFName(txtFName.Text); string msgLName = val.valLName(txtLName.Text); string msgDate = val.validDateDOB(dateT.Value); string msgPhone = val.valPhone(txtPhone.Text); string msgAdd1 = val.valAdd1(txtAddressLine1.Text); string msgAdd2 = val.valAdd2(txtAddressLine2.Text); string msgSuburb = val.valSub(txtSuburb.Text); string msgPost = val.valPostcode(txtPostcode.Text); string msgRego = val.valRegoNo(txtRegNo.Text); string msgPass = val.valPassword(txtPassword.Text); if (msgFName == "" && msgLName == "" && msgDate == "" && msgPhone == "" && msgAdd1 == "" && msgAdd2 == "" && msgSuburb == "" && msgPost == "" && msgRego == "" && msgPass == "") { using (SchoolEntities db = new SchoolEntities()) { Teacher teachers = new Teacher(); teachers.FName = txtFName.Text; teachers.LName = txtLName.Text; teachers.DOB = dateT.Value; teachers.Phone = txtPhone.Text; teachers.Add1 = txtAddressLine1.Text; teachers.Add2 = txtAddressLine2.Text; teachers.Suburb = txtSuburb.Text; teachers.State = cboState.Text; teachers.Postcode = txtPostcode.Text; teachers.RegNo = txtRegNo.Text; teachers.Password = txtPassword.Text; db.Teachers.Add(teachers); db.SaveChanges(); MessageBox.Show("New Teacher Added! ID:" + teachers.TID); } } else { MessageBox.Show(msgFName + "\r\n" + msgLName + "\r\n" + msgPhone + "\r\n" + msgAdd1 + "\r\n" + msgAdd2 + "\r\n" + msgSuburb + "\r\n" + msgPost + "\r\n" + msgRego + "\r\n" + msgPass); } }