private async void btnSave_Click(object sender, EventArgs e) { if (ValidateFomControls.CheckTextboxes(this, errorProvider1) && ValidateFomControls.CheckPassword(_txtPassword.Text, _txtConfirmPassword.Text)) { var principal = CreatePrincipal(); if (principal != null) { try { _unitOfWork = new UnitOfWork(new Model1()); _unitOfWork.PrincipalRepository.Add(principal); await _unitOfWork.Save(); _unitOfWork.Dispose(); MessageBox.Show("Admin added"); } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact Admin"); } } else { MessageBox.Show("Error occured. Contact support"); } } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { try { var _class = cBoxClass.Text; var _session = cBoxSession.Text; var _term = cBoxTerm.Text; var _subj = cBoxSubject.Text; Cursor = Cursors.WaitCursor; using (var db = new Model1()) { results = db.results1.Where(x => x._class == _class && x.session == _session && x.term == _term && x.subjects == _subj).ToList(); dGridStudents.DataSource = results; } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error has occured. Please contact support"); } } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var subj = new sss() { sss_subjects = cBoxSubject.Text, upload_date = DateTime.Now.ToString("d"), upload_time = DateTime.Now }; try { using (var db = new Model1()) { var isExist = db.ssses.Any(x => x.sss_subjects == subj.sss_subjects); if (!isExist) { db.ssses.Add(subj); db.SaveChanges(); dGridSubjecs.DataSource = db.ssses.ToList(); } else { MessageBox.Show("Subject already exists"); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var _class = cBoxClass.Text; var _subject = cBoxSubject.Text; var _term = cBoxTerm.Text; var _session = cBoxSession.Text; try { var subList = _unitOfWork.SubjectsRepository.FindAll().Where( s => s._class == _class && s.subjects == _subject && s.term == _term && s.session == _session).ToList(); if (subList.Any()) { dGridStudents.DataSource = subList; } else { MessageBox.Show("No information to display"); } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } } }
private async void btnSave_ClickEventAsync(object sender, EventArgs e) { if (ValidateFomControls.CheckTextboxes(this, errorProvider1) && ValidateFomControls.CheckPassword(_txtPassword.Text, _txtConfirmPassword.Text) && ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { try { var teacher = CreateTeacher(); if (teacher != null) { _unitOfWork = new UnitOfWork(new Model1()); _unitOfWork.TeacherRepository.Add(teacher); await _unitOfWork.Save(); _unitOfWork.Dispose(); MessageBox.Show("Teacher added"); } else { ArgumentNullException ex = new ArgumentNullException("Teacher object", "Teacher object is null"); Utils.LogException(ex); MessageBox.Show("Error occured. Contact support"); } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact support"); } } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var tc = CreateTeacherClass(); try { var _unitOfWork = new UnitOfWork(new Model1()); _unitOfWork.Teachers_ClassesRepository.Add(tc); _unitOfWork.Save(); _unitOfWork.Dispose(); MessageBox.Show("Added"); using (var db = new Model1()) { TnCs = db.teachers_classes.ToList(); dGridTeachers_Class.DataSource = TnCs; } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } } }
private void btnSave_ClickEvent(object sender, EventArgs e) { try { if (ValidateFomControls.CheckTextboxes(this, errorProvider1)) { _unitOfWork = new UnitOfWork(new Model1()); var ss = _unitOfWork.School_SubjectsRepository.FindById(_id).Result; ss.subjects = txtSubject.Text; _unitOfWork.Save(); dGridAllClass.DataSource = _unitOfWork.School_SubjectsRepository.FindAll().ToList(); _unitOfWork.Dispose(); btnSave.Enabled = false; txtSubject.Text = string.Empty; txtSubject.Enabled = false; MessageBox.Show("Subject Updated"); } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var class_ = cBoxClass.Text; var term_ = cBoxTerm.Text; var session_ = cBoxSession.Text; try { using (var db = new Model1()) { dGridBehaviour.Cursor = Cursors.WaitCursor; var bhv = db.behaviorals.Where(x => x._class == class_ && x.term == term_ && x.session == session_).ToList(); if (bhv != null) { dGridBehaviour.DataSource = bhv; dGridBehaviour.Cursor = Cursors.Arrow; } else { MessageBox.Show("No records found."); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("No records found."); } } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { try { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var _class = cBoxClass.Text; var _session = cBoxSession.Text; var _term = cBoxTerm.Text; using (var db = new Model1()) { var positions = db.positions.Where(x => x._class == _class && x.session == _session && x.term == _term).ToList(); if (positions == null) { MessageBox.Show("No Found."); return; } dgridPResults.DataSource = positions; } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An Error Occured. Please, Contact Support."); } }
private void btnShow_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { Cursor = Cursors.WaitCursor; try { using (var db = new Model1()) { List <student_attendance> attendances = db.student_attendance.Where(x => x.session == cBoxSession.Text && x.term == cBoxTerm.Text && x._class == cBoxClass.Text).ToList(); dGridAttendance.DataSource = attendances; } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } Cursor = Cursors.Arrow; } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckTextboxes(this, errorProvider1)) { try { var _unitOfWork = new UnitOfWork(new Model1()); var sch_subj = CreateSchoolSubject(); if (!_unitOfWork.School_SubjectsRepository.CheckIfItExists(_txtSubject.Text)) { _unitOfWork.School_SubjectsRepository.Add(sch_subj); _unitOfWork.Save(); _unitOfWork.Dispose(); MessageBox.Show("New Subject Added"); } else { MessageBox.Show("Already Added"); } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact support"); } } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { students = _unitOfWork.StudentRepository.FindAll().Where(x => x._class == cBoxClass.Text).ToList(); dgridStudents.DataSource = students; } }
private void btnSave_ClickEvent(object sender, EventArgs e) { try { if (ValidateFomControls.CheckTextboxes(this, errorProvider1)) { if (string.IsNullOrWhiteSpace(_logoLocation) || string.IsNullOrWhiteSpace(_stampLocation)) { MessageBox.Show("Please Enter the School Logo and Stamp."); return; } var admin = new administrative() { school_logo = _logoLocation, school_motto = _stampLocation, school_name = _txtName.Text, school_stamp = _txtAddress.Text, upload_date = DateTime.Now.Date.ToString("d"), upload_time = DateTime.Now, }; using (var db = new Model1()) { if (db.administratives.Count() < 1) { db.administratives.Add(admin); } else { var cur = db.administratives.First(); cur.school_logo = _logoLocation; cur.school_motto = _stampLocation; cur.school_name = _txtName.Text; cur.school_stamp = _txtAddress.Text; cur.upload_date = DateTime.Now.Date.ToString("d"); cur.upload_time = DateTime.Now; } db.SaveChanges(); } MessageBox.Show("Scho0l Info was saved successfully."); } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured.\n"); } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { Cursor = Cursors.WaitCursor; try { using (var db = new Model1()) { List <student> students = db.students.Where(x => x._class == cBoxClass.Text).ToList(); behaviorals = new List <behavioral>(); foreach (var s in students) { behaviorals.Add(new behavioral() { name = s.Fullname, reg_number = s.reg_number, term = cBoxTerm.Text, session = cBoxSession.Text, _class = cBoxClass.Text, attentiveness = "1", attitude_to_work = "1", hand_writting = "1", health = "1", musical_skills = "1", politeness = "1", sports = "1", }); } dGridStudentsBehaviour.DataSource = behaviorals; } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } Cursor = Cursors.Arrow; } }
private void btnSaveJss_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { try { using (var db = new Model1()) { var jssnum = db.jss_subject_number.FirstOrDefault(); if (jssnum != null) { jssnum.number_of_subject = Convert.ToInt32(cBoxNum.Text); db.SaveChanges(); lblJSSNum.Text = string.Format("JSS Students must offer {0} subjects", cBoxNum.Text); MessageBox.Show("Jss Subject Number updated"); cBoxNum.SelectedIndex = -1; } else { var _jnum = new jss_subject_number() { declared_date = DateTime.Now.ToString("d"), declared_time = DateTime.Now, number_of_subject = Convert.ToInt32(cBoxNum.Text) }; db.jss_subject_number.Add(_jnum); db.SaveChanges(); lblJSSNum.Text = string.Format("JSS Students must offer {0} subjects", cBoxNum.Text); MessageBox.Show("Jss Subject Number added"); cBoxNum.SelectedIndex = -1; } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { try { using (var db = new Model1()) { var cls = cBoxClass.Text; dGridStudents.DataSource = db.students.Where(x => x._class == cls).ToList(); } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } } }
private void btnSearch_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { try { Cursor = Cursors.WaitCursor; using (var db = new Model1()) { var Students = db.students.Where(x => x._class == cBoxClass.Text); var Reg = new List <subject>(); foreach (var s in Students) { var stuReg = new subject() { name = s.Fullname, reg_number = s.reg_number, session = cBoxSession.Text, subjects = cBoxSubject.Text, term = cBoxTerm.Text, _class = cBoxClass.Text, }; Reg.Add(stuReg); } dGridStudReg.DataSource = Reg; } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } finally { Cursor = Cursors.Arrow; } } }
private async void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckTextboxes(this, errorProvider1)) { if (RegexCheckTextbox(_txtSession.Text) && CheckIfSessionIsValid(_txtSession.Text)) { try { _unitOfWork = new UnitOfWork(new Model1()); if (_unitOfWork.SessionRepository.CheckIfItExists(_txtSession.Text)) { MessageBox.Show("This session already exists."); return; } var Session = new session() { sessions = _txtSession.Text, date_added = DateTime.Today.ToString("d"), time_added = DateTime.Now, }; _unitOfWork.SessionRepository.Add(Session); await _unitOfWork.Save(); _unitOfWork.Dispose(); MessageBox.Show($"Session {_txtSession.Text} was added successfully."); } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Contact support"); } } else { MessageBox.Show("Please enter the session in the approved format"); } } }
private void btnDelete_ClickEvent(object sender, EventArgs e) { try { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var rtn = MessageBox.Show("Are you sure you want to delete these data?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rtn != DialogResult.Yes) { return; } var _class = cBoxClass.Text; var _session = cBoxSession.Text; var _term = cBoxTerm.Text; using (var db = new Model1()) { var positions = db.positions.Where(x => x._class == _class && x.session == _session && x.term == _term); if (positions == null) { MessageBox.Show("No Found."); return; } else { db.positions.RemoveRange(positions); db.SaveChanges(); } dgridPResults.DataSource = new position(); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An Error Occured. Please, Contact Support."); } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckTextboxes(this, errorProvider1)) { try { var _unitOfWork = new UnitOfWork(new Model1()); if (_unitOfWork.dClassRepository.CheckIfItExists(_txtClassName.Text.Trim())) { MessageBox.Show("This class already exists."); return; } var cl = new _class() { classes = _txtClassName.Text.Trim(), date_added = DateTime.Today.ToString("d"), time_added = DateTime.Now }; _unitOfWork.dClassRepository.Add(cl); _unitOfWork.Save(); _unitOfWork.Dispose(); MessageBox.Show("Class Added Successfully"); using (var db = new Model1()) { classes = db.classes.ToList(); dGridAllClass.DataSource = classes; } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Contact support"); } } }
private void btnDelete_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var class_ = cBoxClass.Text; var term_ = cBoxTerm.Text; var session_ = cBoxSession.Text; try { using (var db = new Model1()) { dGridBehaviour.Cursor = Cursors.WaitCursor; var bhv = db.behaviorals.Where(x => x._class == class_ && x.term == term_ && x.session == session_); if (bhv != null) { db.behaviorals.RemoveRange(bhv); db.SaveChanges(); dGridBehaviour.Cursor = Cursors.Arrow; MessageBox.Show("Records deleted"); dGridBehaviour.DataSource = new List <behavioral>(); } else { MessageBox.Show("No records to delete."); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error ocurred. Please contact support"); } } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { Cursor = Cursors.WaitCursor; try { using (var db = new Model1()) { var students = db.students.Where(x => x._class == cboxFrom.Text); if (students.Count() < 1) { MessageBox.Show("No student in this class."); } else { foreach (var s in students) { s._class = cboxToClass.Text; } db.SaveChanges(); MessageBox.Show("Students promoted successfully."); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } Cursor = Cursors.Arrow; } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { var term = cBoxTerm.Text; var sess = cBoxSession.Text; try { using (var db = new Model1()) { var seas = db.current_season.FirstOrDefault(); if (seas != null) { seas.current_session = sess; seas.current_term = term; seas.date_declared = DateTime.Now.ToString("d"); seas.time_declared = DateTime.Today; db.SaveChanges(); MessageBox.Show("Term And Session Updated"); } else { MessageBox.Show("Term And Session not yet set"); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error has occured. Please contact support"); } } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckTextboxes(this, errorProvider1) && ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { if (btnFind.Enabled) { MessageBox.Show("Click Find to make sure the reg number exists first."); return; } var rtn = MessageBox.Show($"Are you sure you want to move this student from {_txtCurClass.Text} to {cboxToClass.Text}?", "", MessageBoxButtons.YesNo); if (rtn == DialogResult.Yes) { try { using (var db = new Model1()) { var stu = db.students.FirstOrDefault(x => x.reg_number == _txtRegNumber.Text); if (stu == null) { MessageBox.Show("No student was found with this reg number."); } else { stu._class = cboxToClass.Text; db.SaveChanges(); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } } } }
private void btnSave_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1) && ValidateFomControls.CheckTextboxes(this, errorProvider1)) { if (cboxType.Text == "Student") { try { using (var db = new Model1()) { var stud = db.students.FirstOrDefault(x => x.reg_number == _txtUsername.Text); if (stud != null) { stud.gen_password = _txtPassword.Text; db.SaveChanges(); MessageBox.Show("Password changed"); } else { MessageBox.Show("No user found"); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact admin"); } } else if (cboxType.Text == "Teacher") { try { using (var db = new Model1()) { var tech = db.teachers.FirstOrDefault(x => x.username == _txtUsername.Text); if (tech != null) { tech.password = _txtPassword.Text; db.SaveChanges(); MessageBox.Show("Password changed"); } else { MessageBox.Show("No user found"); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact admin"); } } else if (cboxType.Text == "Principal") { try { using (var db = new Model1()) { var prp = db.principals.FirstOrDefault(x => x.username == _txtUsername.Text); if (prp != null) { prp.password = _txtPassword.Text; db.SaveChanges(); MessageBox.Show("Password changed"); } else { MessageBox.Show("No user found"); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact admin"); } } else if (cboxType.Text == "Admin") { try { using (var db = new Model1()) { var ad = db.users.FirstOrDefault(x => x.email == _txtUsername.Text); if (ad != null) { ad.password = _txtPassword.Text; db.SaveChanges(); MessageBox.Show("Password changed"); } else { MessageBox.Show("User not found"); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("An error occured. Please contact admin"); } } } }
private void btnExport_ClickEvent(object sender, EventArgs e) { if (ValidateFomControls.CheckComboBoxes(this, errorProvider1)) { Cursor = Cursors.WaitCursor; try { using (var db = new Model1()) { List <student> students = db.students.Where(x => x._class == cBoxClass.Text).ToList(); if (students.Count < 1) { MessageBox.Show("No student in the selected class, Try again."); Cursor = Cursors.Arrow; return; } using (ExcelPackage excel = new ExcelPackage()) { excel.Workbook.Worksheets.Add("Worksheet1"); var headerRow = new List <string[]>() { new string[] { "S/N", "Reg No", "Name", "Class", "Term", "Session", "Hand Writing", "Musical Skills", "Sports", "Attentiveness", "Attitude to work", "Health", "Politeness" } }; var bodyRow = new List <string[]>(); for (int i = 0; i < students.Count; i++) { var s = students[i]; bodyRow.Add(new string[] { (i + 1).ToString(), s.reg_number, s.Fullname, cBoxClass.Text, cBoxTerm.Text, cBoxSession.Text, "", "", "", "", "", "", "" }); } string headerRange = "A1:" + char.ConvertFromUtf32(headerRow[0].Length + 64) + "1"; string bodyRange = "A2:" + char.ConvertFromUtf32(headerRow[0].Length + 64) + (bodyRow.Count + 1).ToString(); var workSheet = excel.Workbook.Worksheets["Worksheet1"]; workSheet.Cells[headerRange].LoadFromArrays(headerRow); workSheet.Cells[bodyRange].LoadFromArrays(bodyRow); workSheet.Cells[headerRange].Style.Font.Bold = true; var fPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), cBoxClass.Text + "Behaviour.xlsx"); FileInfo excelFile = new FileInfo(fPath); excel.SaveAs(excelFile); MessageBox.Show("Excel file saved at : \n" + fPath); } } } catch (Exception ex) { Utils.LogException(ex); MessageBox.Show("Error occured. Please contact support."); } Cursor = Cursors.Arrow; } }