private void SaveBtn_Click(object sender, EventArgs e) { try { using (var db = new AcademyEntities()) { var answerId = Convert.ToInt32(AnswersView.CurrentRow.Cells["Id"].Value); var correctAnswer = db.Answers.Find(answerId); if (!(db.Answers.Where(a => a.QuestionId == id).Where(c => c.Correct == true).Any())) { correctAnswer.Correct = true; db.SaveChanges(); var answers = from a in db.Answers where a.QuestionId == id select new { Id = a.Id, Answer = a.AnswerText, Correct = a.Correct }; AnswersView.DataSource = answers.ToList(); } else { var previousCorrect = db.Answers.Where(a => a.QuestionId == id).Where(c => c.Correct == true).Single(); previousCorrect.Correct = false; correctAnswer.Correct = true; db.SaveChanges(); var answers = from a in db.Answers where a.QuestionId == id select new { Id = a.Id, Answer = a.AnswerText, Correct = a.Correct }; AnswersView.DataSource = answers.ToList(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Btn_positionfrm_save_Click(object sender, EventArgs e) { Position pstn = new Position(); Regex rgxName = new Regex("[A-z]"); //Regex rgxEmployee = new Regex("[A-z]"); if (!rgxName.IsMatch(pstntxtbxemplote_name.Text)) { MessageBox.Show("Fill in the form"); } //else if (!rgxEmployee.IsMatch(pstntxtbxemplote.Text)) //{ // MessageBox.Show("Not enter Letters"); //} else { using (AcademyEntities aem = new AcademyEntities()) { Employee employe = aem.Employees.FirstOrDefault(g => g.Id == selectedId); //pstn.Employees = employe; if (employe != null) { pstn.Employees.Add(employe); } pstn.Name = pstntxtbxemplote_name.Text; //pstn.PositionId =Convert.ToInt32(pstntxtbxemploteId.Text); aem.Positions.Add(pstn); position_datagridview.DataSource = aem.Positions.ToList(); aem.SaveChanges(); } } }
private void SaveBtn_Click(object sender, EventArgs e) { try { using (AcademyEntities academyDb = new AcademyEntities()) { var editedQuestion = academyDb.Questions.Find(id); if (QuestionText.Text != "") { editedQuestion.Name = QuestionText.Text; editedQuestion.SubjectId = Convert.ToInt32(SubjectsView.CurrentRow.Cells["Id"].Value); academyDb.SaveChanges(); this.Owner.Show(); this.Close(); } //else if () //{ // MessageBox.Show("Do not leave any field empty!"); //} else { MessageBox.Show("Do not leave any field empty!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Owner.Show(); this.Close(); } }
private void Delete_Click(object sender, EventArgs e) { try { using (AcademyEntities academyDb = new AcademyEntities()) { if (academyDb.Subjects.Any()) { var id = Convert.ToInt32(SubjectsView.CurrentRow.Cells["Id"].Value); var subject = academyDb.Subjects.Find(id); if (academyDb.RSGs.Where(rs => rs.SubjectId == id).Any()) { academyDb.RSGs.RemoveRange(academyDb.RSGs.Where(rg => rg.SubjectId == id)); } academyDb.Subjects.Remove(subject); academyDb.SaveChanges(); MessageBox.Show("Subject " + subject.Name + " was deleted"); } else { MessageBox.Show("No subjects existed!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Remove_Click(object sender, EventArgs e) { try { using (var db = new AcademyEntities()) { //var studentsOfGroup = db.Users.Where(d => d.RoleId == 3).Where(f => f.GroupId == id).FirstOrDefault(); //var subjectsOfGroup = db.RSGs.Where(g => g.GroupId == id).FirstOrDefault(); var testQuestion = db.REQs.Where(t => t.ExamId == id).FirstOrDefault(); if (testQuestion != null) { //var subjectToDelete = AddedSubjects.CurrentRow.Cells["Id"].Value; int questionToRemoveId = Convert.ToInt32(AddedQuestions.CurrentRow.Cells["Id"].Value); //int subjectToDeleteId = Convert.ToInt32(db.RSGs.Where(s => s.GroupId == id). // Where(g => g.Subject.Name == subjectToDelete).Select(i=>i.Id)); var questionToRemove = db.REQs.Find(questionToRemoveId); //MessageBox.Show(subjectToDelete.ToString()); db.REQs.Remove(questionToRemove); db.SaveChanges(); var addedQuestions = from rq in db.REQs where rq.ExamId == id select new { Id = rq.Id, Text = rq.Question.Name, Subject = rq.Question.Subject.Name }; AddedQuestions.DataSource = addedQuestions.ToList(); var exam = db.Exams.Find(id); var questions = from q in db.Questions where q.SubjectId == exam.SubjectId select new { Id = q.Id, Text = q.Name, Subject = q.Subject.Name }; AllQuestions.DataSource = questions.ToList(); } else { MessageBox.Show("No questions for the exam left!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void SaveBtn_Click(object sender, EventArgs e) { try { using (AcademyEntities academyDb = new AcademyEntities()) { var editedGroup = academyDb.Groups.Find(id); if (GroupName.Text != "") { editedGroup.Name = GroupName.Text; academyDb.SaveChanges(); this.Owner.Show(); this.Close(); } //else if () //{ // MessageBox.Show("Do not leave any field empty!"); //} else { MessageBox.Show("Do not leave any field empty!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Owner.Show(); this.Close(); } }
private void Btn_task_save_Click(object sender, EventArgs e) { AcademyMngtSystem.Model.Task tsk = new AcademyMngtSystem.Model.Task(); Regex rgxName = new Regex("[A-z]"); Regex rgxDeadline = new Regex(@"\[0\-9\]\{2\}\.\[0\-9\]\{2\}\.\[0\-9\]\{4\}"); Regex rgxGroup = new Regex("[A-z]"); if (!rgxName.IsMatch(task_txbx_name.Text)) { MessageBox.Show("Fill in the form"); } else if (!rgxGroup.IsMatch(task_txbx_grp.Text)) { MessageBox.Show("Fill in the form"); } using (AcademyEntities aem = new AcademyEntities()) { tsk.Name = task_txbx_name.Text; tsk.Deadline = Convert.ToDateTime(task_txbx_deadline.Text); //tsk.Groups = task_txbx_grp.Text; aem.Tasks.Add(tsk); aem.SaveChanges(); frm_task_datagridview.DataSource = aem.Tasks.ToList(); } }
private void Btn_teacher_save_Click(object sender, EventArgs e) { AcademyMngtSystem.Model.ClassRoom clsrm = new AcademyMngtSystem.Model.ClassRoom(); Regex rgxName = new Regex("[A-z]"); Regex rgxCapacity = new Regex("[0-9A-z]"); if (!rgxCapacity.IsMatch(clsrm_grp_capacity.Text)) { MessageBox.Show("Not enter Letters"); } if (!rgxName.IsMatch(clsrm_stdnt_name.Text)) { MessageBox.Show("Fill in the form"); } else { using (AcademyEntities aem = new AcademyEntities()) { AcademyMngtSystem.Model.Group group = aem.Groups.FirstOrDefault(c => c.Id == selectedId); if (group != null) { clsrm.Groups.Add(group); } clsrm.Name = clsrm_stdnt_name.Text; clsrm.Capacity = clsrm_grp_capacity.Text; aem.ClassRooms.Add(clsrm); aem.SaveChanges(); clsrmdatagrid.DataSource = aem.ClassRooms.ToList(); } } }
private void SaveBtn_Click(object sender, EventArgs e) { try { using (var db = new AcademyEntities()) { if (QuestionText.Text != "") { // int teacherId = Convert.ToInt32(TeachersView.CurrentRow.Cells["Id"].Value); var nameTest = db.Questions.FirstOrDefault(l => l.Name.Contains(QuestionText.Text)); if (nameTest == null) { var name = QuestionText.Text; int subjectId = Convert.ToInt32(SubjectsView.CurrentRow.Cells["Id"].Value); db.Questions.Add(new Question { Name = name, SubjectId = subjectId }); db.SaveChanges(); // var questionId = from q in db.Questions // where q.Name == name // select q; //var qId=Convert.ToInt32(questionId.Select(i => i.Id)); // MessageBox.Show(qId.ToString()); // //db.REQs.Add(new REQ { QuestionId = qId, ExamId = examId }); this.Owner.Show(); this.Close(); } else { MessageBox.Show("A question with the same text already exists!"); } } else { MessageBox.Show("Fill in all fields!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Owner.Show(); this.Close(); } }
private void Btn_grpfrm_save_Click(object sender, EventArgs e) { Model.Group grp = new Model.Group(); Regex rgxName = new Regex("[A-z]"); //Regex rgxClassroom = new Regex("[A-z]"); Regex rgxTeacher = new Regex("[A-z]"); Regex rgxMentor = new Regex("[A-z]"); //Regex rgxCapacity = new Regex(@"\[0\-9\]\{0,15\}"); if (!rgxName.IsMatch(frm_txtbox_Name.Text)) { MessageBox.Show("Enter Name"); } //else if (!rgxClassroom.IsMatch(frm_txtbox_ClassRoom.Text)) //{ // MessageBox.Show("Enter ClassRoom"); //} else if (!rgxTeacher.IsMatch(frm_txtbox_Teacher.Text)) { MessageBox.Show("Fill in the form"); } //else if (!rgxCapacity.IsMatch(frm_txtbox_Capacity.Text)) //{ // MessageBox.Show("Enter Capactiy"); //} else { using (AcademyEntities aem = new AcademyEntities()) { AcademyMngtSystem.Model.ClassRoom classrm = aem.ClassRooms.FirstOrDefault(c => c.Id == selectedClassRoomId); //if (classrm != null) //{ // grp.ClassRoom.Add(classrm); //} grp.ClassRoom1 = classrm; //grp.Classroom = frm_txtbox_ClassRoom.Text; grp.Teacher = frm_txtbox_Teacher.Text; grp.Mentor = selectedMentorId; //grp.Teacher = new i grp.ClassRoom1 = classrm; grp.Name = frm_txtbox_Name.Text; grp.Capacity = Convert.ToInt32(frm_txtbox_Capacity.Text); aem.Groups.Add(grp); frm_grp_datagrid.DataSource = aem.Groups.ToList(); //grp.Employee aem.SaveChanges(); } } }
private static void ClearDisciplines(AcademyEntities academyEntities) { IEnumerable <Discipline> disciplines = academyEntities.Disciplines.ToList(); foreach (var discipline in disciplines) { academyEntities.Disciplines.Remove(discipline); } academyEntities.SaveChanges(); }
public void GenerateDisciplines() { ClearDisciplines(academyEntities); IEnumerable <Discipline> disciplines = GetTestDisciplines(); foreach (Discipline discipline in disciplines) { academyEntities.Disciplines.Add(discipline); } academyEntities.SaveChanges(); }
private void Remove_Click(object sender, EventArgs e) { try { using (var db = new AcademyEntities()) { //var studentsOfGroup = db.Users.Where(d => d.RoleId == 3).Where(f => f.GroupId == id).FirstOrDefault(); var subjectsOfGroup = db.RSGs.Where(g => g.GroupId == id).FirstOrDefault(); if (subjectsOfGroup != null) { //var subjectToDelete = AddedSubjects.CurrentRow.Cells["Id"].Value; int subjectToDelete = Convert.ToInt32(AddedSubjects.CurrentRow.Cells["Id"].Value); //int subjectToDeleteId = Convert.ToInt32(db.RSGs.Where(s => s.GroupId == id). // Where(g => g.Subject.Name == subjectToDelete).Select(i=>i.Id)); var subjectToRemove = db.RSGs.Find(subjectToDelete); //MessageBox.Show(subjectToDelete.ToString()); db.RSGs.Remove(subjectToRemove); db.SaveChanges(); var groupSubjects = from r in db.RSGs where r.GroupId == id select new { Id = r.Id, Name = r.Subject.Name, GroupId = r.Group.Name }; AddedSubjects.DataSource = groupSubjects.ToList(); var subjects = from s in db.Subjects select new { Id = s.Id, Name = s.Name }; AllSubjects.DataSource = subjects.ToList(); } else { MessageBox.Show("No subjects for the group!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Add_Click(object sender, EventArgs e) { using (var db = new AcademyEntities()) { var freeStudents = db.Users.Where(d => d.RoleId == 3).Where(f => f.GroupId == null).FirstOrDefault(); if (freeStudents != null) { int studentId = Convert.ToInt32(StudentsChoiceView.CurrentRow.Cells["Id"].Value); var addedStudent = db.Users.Find(studentId); addedStudent.GroupId = id; db.SaveChanges(); var students = from u in db.Users where u.RoleId == 3 where u.GroupId == null select new { Id = u.Id, FName = u.FName, LName = u.LName, Phone = u.Phone }; StudentsChoiceView.DataSource = students.ToList(); var addedStudents = from u in db.Users where u.RoleId == 3 where u.GroupId == id select new { Id = u.Id, FName = u.FName, LName = u.LName, Phone = u.Phone }; AddedStudents.DataSource = addedStudents.ToList(); } else { MessageBox.Show("No free students!"); } } }
private void Button1_Click(object sender, EventArgs e) { string Name = txtName.Text; string Surname = txtSurname.Text; string Email = txtEmail.Text; string Phone = txtPhone.Text; bool statusdefault = true; string letters = @"^[a-zA-Z]+$"; string emailreg = @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$"; string phonereg = @"^(?<countryCode>[\+][1-9]{1}[0-9]{0,2}\s)?(?<areaCode>0?[1-9]\d{0,4})(?<number>\s[1-9][\d]{5,12})(?<extension>\sx\d{0,4})?$"; Match result = Regex.Match(Name, letters); Match surnameMath = Regex.Match(Surname, letters); Match emailMatch = Regex.Match(Email, emailreg); Match phoneMatch = Regex.Match(Phone, phonereg); if (!result.Success) { MessageBox.Show("Adi duzgun daxil edin."); } if (!surnameMath.Success) { MessageBox.Show("Soyadi duzgun daxil edin."); } if (!emailMatch.Success) { MessageBox.Show("Emaili duzgun daxil edin."); } if (!phoneMatch.Success) { MessageBox.Show("Nomreni duzgun daxil edin."); } else { using (AcademyEntities db = new AcademyEntities()) { Models.Teacher teacher = new Teacher() { Name = Name, Surname = Surname, Email = Email, Phone = Phone, Speciality = comSpeciality.Text, Status = statusdefault }; db.Teachers.Add(teacher); db.SaveChanges(); } } ResetTxt(); dataGridView1.Rows.Clear(); FillTeacher(); }
private void Button3_Click(object sender, EventArgs e) { using (AcademyEntities db = new AcademyEntities()) { teacherUpdated.Status = false; var entry = db.Entry(teacherUpdated); entry.State = EntityState.Modified; db.SaveChanges(); } ResetTxt(); FillTeacher(); MessageBox.Show("Emeliyyat ugurla yerine yetirildi." + teacherUpdated.Name + " " + teacherUpdated.Surname + " statusu deaktiv edildi."); }
private static void CreateDiscipline( AcademyEntities entities, string name, Discipline parent) { var discipline = CreateDiscipline(name, parent); entities.Disciplines.Add(discipline); entities.SaveChanges(); foreach (var child in Directory.GetDirectories(name)) { CreateDiscipline(entities, child, discipline); } }
private void Btn_teacher_save_Click(object sender, EventArgs e) { AcademyMngtSystem.Model.Teacher tch = new AcademyMngtSystem.Model.Teacher(); Regex regexName = new Regex("[A-z]"); Regex regexSurname = new Regex("[A-z]"); //Regex regexSpeciality = new Regex("[A-z]"); Regex regexEmail = new Regex(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"); //Regex regexPhone = new Regex(@"(\+[0-9]{3})([0-9]{9})"); if (!regexEmail.IsMatch(frm2txtbx_email.Text)) { MessageBox.Show("Email is not true !"); } else if (!regexName.IsMatch(frm2txtbx_name.Text)) { MessageBox.Show("Fill in the form"); } else if (!regexSurname.IsMatch(frm2txtbx_surname.Text)) { MessageBox.Show("Fill in the form"); } //else if (!regexSpeciality.IsMatch(frm2cmbbx_spclty.Text)) //{ // MessageBox.Show("Fill in the form"); //} //else if (!regexPhone.IsMatch(frm2txtbx_phn.Text)) //{ // MessageBox.Show("Please Enter Correct Phone Number !"); //} else { using (AcademyEntities aem = new AcademyEntities()) { AcademyMngtSystem.Model.Education edctn = aem.Educations.FirstOrDefault(x => x.Id == selectedId); tch.Education = edctn; tch.Name = frm2txtbx_name.Text; tch.Surname = frm2txtbx_surname.Text; tch.Email = frm2txtbx_email.Text; tch.Phone = frm2txtbx_phn.Text; aem.Teachers.Add(tch); teacher_datagridview.DataSource = aem.Teachers.ToList(); aem.SaveChanges(); } } }
private void Add_Click(object sender, EventArgs e) { try { using (var db = new AcademyEntities()) { int subjectId = Convert.ToInt32(AllSubjects.CurrentRow.Cells["Id"].Value); var testName = db.RSGs.Where(gr => gr.GroupId == id).Where(sj => sj.SubjectId == subjectId).FirstOrDefault(); if (testName == null) { db.RSGs.Add(new RSG { SubjectId = subjectId, GroupId = id }); db.SaveChanges(); var groupSubjects = from r in db.RSGs where r.GroupId == id select new { Id = r.Id, Name = r.Subject.Name, GroupId = r.Group.Name }; AddedSubjects.DataSource = groupSubjects.ToList(); var subjects = from s in db.Subjects select new { Id = s.Id, Name = s.Name }; AllSubjects.DataSource = subjects.ToList(); } else { MessageBox.Show("Such subject has already been added!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Owner.Show(); this.Close(); } }
private void Button1_Click(object sender, EventArgs e) { using (AcademyEntities db = new AcademyEntities()) { if (textBox1.Text != "" && dateTimePicker1.Text != "") { Group group = db.Groups.Where(c => c.Name == comboBox1.Text).FirstOrDefault(); Models.Task task = new Models.Task() { Name = textBox1.Text, Deadline = dateTimePicker1.Value, GroupId = group.Id, Status = true }; db.Tasks.Add(task); db.SaveChanges(); List <Student> students = db.Students.Where(s => s.Group.Name == comboBox1.Text).ToList(); foreach (var item in students) { GroupTask groupTask = new GroupTask() { TaskId = task.Id, StudentId = item.Id, }; db.GroupTasks.Add(groupTask); db.SaveChanges(); } } FillTasks(); textBox1.Text = ""; dateTimePicker1.Text = ""; comboBox1.Text = ""; } }
private void Button1_Click(object sender, EventArgs e) { using (AcademyEntities db = new AcademyEntities()) { decimal mark = Convert.ToDecimal(textBox1.Text); GroupTask groupTask = db.GroupTasks.Where(g => g.TaskId == task.Id && g.StudentId == selectedStudent).FirstOrDefault(); groupTask.Mark = mark; var entry = db.Entry(groupTask); entry.State = EntityState.Modified; db.SaveChanges(); } textBox1.Text = ""; FillStudent(); }
private void Button2_Click(object sender, EventArgs e) { string Name = txtName.Text; string Surname = txtSurname.Text; string Email = txtEmail.Text; string Phone = txtPhone.Text; string letters = @"^[a-zA-Z]+$"; string emailreg = @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$"; string phonereg = @"^(?<countryCode>[\+][1-9]{1}[0-9]{0,2}\s)?(?<areaCode>0?[1-9]\d{0,4})(?<number>\s[1-9][\d]{5,12})(?<extension>\sx\d{0,4})?$"; Match result = Regex.Match(Name, letters); Match surnameMath = Regex.Match(Surname, letters); Match emailMatch = Regex.Match(Email, emailreg); Match phoneMatch = Regex.Match(Phone, phonereg); if (!result.Success) { MessageBox.Show("Adi duzgun daxil edin."); } if (!surnameMath.Success) { MessageBox.Show("Soyadi duzgun daxil edin."); } if (!emailMatch.Success) { MessageBox.Show("Emaili duzgun daxil edin."); } if (!phoneMatch.Success) { MessageBox.Show("Nomreni duzgun daxil edin."); } else { using (AcademyEntities db = new AcademyEntities()) { teacherUpdated.Name = txtName.Text; teacherUpdated.Surname = txtSurname.Text; teacherUpdated.Email = txtEmail.Text; teacherUpdated.Phone = txtPhone.Text; teacherUpdated.Speciality = comSpeciality.Text; var entry = db.Entry(teacherUpdated); entry.State = EntityState.Modified; db.SaveChanges(); } ResetTxt(); FillTeacher(); MessageBox.Show("Emeliyyat ugurla yerine yetirildi."); } }
private void Btn_stndt_save_Click(object sender, EventArgs e) { Student st = new Student(); Regex rgxName = new Regex("[A-z]"); Regex rgxSurname = new Regex("[A-z]"); Regex rgxEmail = new Regex(@"[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"); Regex rgxPhone = new Regex(@"\(\\\+\[0\-9\]\{3\}\)\(\[0\-9\]\{9\}\)"); Regex rgxGroups = new Regex("[A-z]"); Regex rgxTask = new Regex("[A-z]"); if (!rgxName.IsMatch(stdntfrm_name.Text)) { MessageBox.Show("Fill in the form"); } else if (!rgxSurname.IsMatch(stdntfrm_surname.Text)) { MessageBox.Show("Fill in the form"); } else if (!rgxEmail.IsMatch(stdntfrm_email.Text)) { MessageBox.Show("Email is not true !"); } else if (!rgxPhone.IsMatch(stdntfrm_phn.Text)) { MessageBox.Show("Format Is Not True !"); } else { using (AcademyEntities aem = new AcademyEntities()) { AcademyMngtSystem.Model.Student stdnt = aem.Students.FirstOrDefault(x => x.Id == selectedGroupId); st.Name = stdntfrm_name.Text; st.Surname = stdntfrm_surname.Text; st.Email = stdntfrm_email.Text; st.Phone = stdntfrm_phn.Text; st.Groups = selectedGroupId; //st.Groups = stdntfrm_grp.Text; //st.Tasks = stdntfrm_task.Text; aem.Students.Add(st); student_datagridview.DataSource = aem.Students.ToList(); aem.SaveChanges(); } } }
private void SaveBtn_Click(object sender, EventArgs e) { try { using (var db = new AcademyEntities()) { if (ExamName.Text != "") { // int teacherId = Convert.ToInt32(TeachersView.CurrentRow.Cells["Id"].Value); var nameTest = db.Exams.FirstOrDefault(l => l.Name == ExamName.Text); if (nameTest == null) { var name = ExamName.Text; DateTime eDate = dateTimePicker1.Value; int subjectId = Convert.ToInt32(SubjectsView.CurrentRow.Cells["Id"].Value); db.Exams.Add(new Exam { Name = name, Date = eDate, SubjectId = subjectId }); db.SaveChanges(); this.Owner.Show(); this.Close(); } else { MessageBox.Show("An exam with the same name already exists!"); } } else { MessageBox.Show("Fill in all fields!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Owner.Show(); this.Close(); } }
private void SaveBtn_Click(object sender, EventArgs e) { using (AcademyEntities academyDb = new AcademyEntities()) { try { bool exists = (from g in academyDb.Groups where g.Name == GroupName.Text select g).Any(); if (GroupName.Text != "") { if (!exists) { var name = GroupName.Text; academyDb.Groups.Add(new Group { Name = name }); academyDb.SaveChanges(); MessageBox.Show("New group has been successfully created!"); this.Owner.Show(); this.Close(); } else { MessageBox.Show("A group with the same name already exists!"); } } else { MessageBox.Show("Fill in all fields!"); } } catch (Exception ex) { this.Owner.Show(); this.Close(); MessageBox.Show(ex.Message); } } }
private void CreateSubj_Click(object sender, EventArgs e) { using (AcademyEntities academyDb = new AcademyEntities()) { try { if (SubjName.Text != "") { // int teacherId = Convert.ToInt32(TeachersView.CurrentRow.Cells["Id"].Value); var nameTest = academyDb.Subjects.FirstOrDefault(l => l.Name == SubjName.Text); if (nameTest == null) { var name = SubjName.Text; int teacherId = Convert.ToInt32(TeachersView.CurrentRow.Cells["Id"].Value); academyDb.Subjects.Add(new Subject { Name = name, TeacherId = teacherId }); academyDb.SaveChanges(); this.Owner.Show(); this.Close(); } else { MessageBox.Show("A subject with the same name already exists!"); } } else { MessageBox.Show("Fill in all fields!"); } } catch (Exception ex) { this.Owner.Show(); this.Close(); MessageBox.Show(ex.Message); } } }
private void SaveChanges_Click(object sender, EventArgs e) { try { using (AcademyEntities academyDb = new AcademyEntities()) { var editedDUser = academyDb.Users.Find(id); if (Login.Text != "" && Password.Text != "" && LName.Text != "" && FName.Text != "" && Phone.Text != "" && RolesChoice.Text != "") { editedDUser.LName = LName.Text; editedDUser.FName = FName.Text; editedDUser.Phone = Phone.Text; editedDUser.Login = Login.Text; editedDUser.Password = Password.Text; if (editedDUser.Id == 1) { editedDUser.RoleId = editedDUser.RoleId; MessageBox.Show("You cannot change your role! Leave it as Admin!"); } else { editedDUser.RoleId = RolesChoice.SelectedIndex + 1; } academyDb.SaveChanges(); this.Owner.Show(); this.Close(); } else { MessageBox.Show("Do not leave any field empty!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); } }
private void Delete_Click(object sender, EventArgs e) { using (AcademyEntities academyDb = new AcademyEntities()) { if (academyDb.Groups.Any()) { var grId = Convert.ToInt32(GroupsView.CurrentRow.Cells["Id"].Value); var group = academyDb.Groups.Find(grId); if (academyDb.RSGs.Where(rg => rg.GroupId == grId).Any()) { academyDb.RSGs.RemoveRange(academyDb.RSGs.Where(rg => rg.GroupId == grId)); } if (academyDb.Users.Where(u => u.GroupId == grId).Any()) { var studentsOfgroup = academyDb.Users.Where(u => u.GroupId == grId); foreach (var student in studentsOfgroup) { student.GroupId = null; } } academyDb.Groups.Remove(group); academyDb.SaveChanges(); MessageBox.Show("Group " + group.Name + " was deleted"); var groups = from g in academyDb.Groups select new { Id = g.Id, Name = g.Name }; GroupsView.DataSource = groups.ToList(); } else { MessageBox.Show("No groups existed!"); } } }
private void Delete_Click(object sender, EventArgs e) { try { using (AcademyEntities academyDb = new AcademyEntities()) { if (academyDb.Exams.Any()) { var id = Convert.ToInt32(ExamsView.CurrentRow.Cells["Id"].Value); var exam = academyDb.Exams.Find(id); if (!(academyDb.Marks.Where(exm => exm.ExamId == id).Any())) { if (academyDb.REQs.Where(exm => exm.ExamId == id).Any()) { academyDb.REQs.RemoveRange(academyDb.REQs.Where(exm => exm.ExamId == id)); } academyDb.Exams.Remove(exam); academyDb.SaveChanges(); MessageBox.Show("Exam " + exam.Name + " was deleted"); } else { MessageBox.Show("Exam " + exam.Name + " cannot be deleted as it was passed by some of the students"); } } else { MessageBox.Show("No exams existed!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Save_Click_1(object sender, EventArgs e) { try { using (AcademyEntities academyDb = new AcademyEntities()) { var editedSubject = academyDb.Subjects.Find(id); if (SNameTextBox.Text != "" && TeachersBox.Text != "") { editedSubject.Name = SNameTextBox.Text; string selectedState = TeachersBox.SelectedItem.ToString(); int end = selectedState.IndexOf('.'); var newTeacherId = selectedState.Substring(0, end); editedSubject.TeacherId = Convert.ToInt32(newTeacherId); academyDb.SaveChanges(); this.Owner.Show(); this.Close(); } else { MessageBox.Show("Do not leave any field empty!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); this.Owner.Show(); this.Close(); } }