Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Subject subjectInForm = new Subject
            {
                SubjectId   = Convert.ToInt32(txtID.Text),
                SubjectCode = txtCode.Text,
                SubjectName = txtTitle.Text,
                Description = txtDescription.Text,
                GradeLevel  = cbGradeLevel.SelectedText
            };

            Subject subjectInDb = _context.Subjects.SingleOrDefault(t => t.SubjectId == Convert.ToInt32(txtID.Text));

            if (subjectInDb == null)
            {
                _context.Subjects.Add(subjectInForm);
            }
            else
            {
                subjectInDb.SubjectCode = subjectInForm.SubjectCode;
                subjectInDb.SubjectName = subjectInForm.SubjectName;
                subjectInDb.Description = subjectInForm.Description;
                subjectInDb.GradeLevel  = subjectInForm.GradeLevel;
            }

            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Section sectionInForm = new Section();

            sectionInForm.SectionName = txtSectionName.Text;
            sectionInForm.GradeLevel  = cbGradeLevel.Text;
            sectionInForm.Teacher     = _context.Teachers.FirstOrDefault(t => t.TeacherId == (int)cbAdviser.SelectedValue);

            try
            {
                if (_section == null)
                {
                    _context.Sections.Add(sectionInForm);
                }
                else
                {
                    _section.SectionName = sectionInForm.SectionName;
                    _section.GradeLevel  = sectionInForm.GradeLevel;
                    _section.Teacher     = sectionInForm.Teacher;
                }
                _context.SaveChanges();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Saving record failed.");
            }
        }
Ejemplo n.º 3
0
 private void deleteSchedule_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (MessageBox.Show("Are you sure, you want to delete this section?", "Confirmation", MessageBoxButtons.OKCancel) != DialogResult.OK)
     {
         return;
     }
     try
     {
         if (dgvListOfClasses.SelectedCells.Count > 0)
         {
             var sectionId       = Convert.ToInt32(dgvListOfClasses.Rows[sectionRowIndex].Cells["SectionId"].Value.ToString());
             var sectionToRemove = _context.Sections.FirstOrDefault(t => t.SectionId == sectionId);
             _context.Sections.Remove(sectionToRemove);
             _context.SaveChanges();
         }
         MessageBox.Show("Record removed successfully");
         LoadSection();
     }
     catch (Exception exception)
     {
         MessageBox.Show("Transaction failed");
     }
 }
 private void SaveRecord(Student student, StudentDetails details, Requirement requirement)
 {
     try
     {
         student.StudentDetails = details;
         student.Requirement    = requirement;
         _context.Students.Add(student);
         _context.SaveChanges();
         MessageBox.Show("Record saved successfully");
     }
     catch (Exception exception)
     {
         MessageBox.Show("Saving record failed" + exception.Message);
     }
 }