예제 #1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            var  progarm       = cbProgram.SelectedItem as Programs;
            var  classSchedule = cbClassesSchedule.SelectedItem as ClassSchedule;
            bool updated       = false;

            if (classSchedule.Id == 1)
            {
                MorningShift student = new MorningShift
                {
                    StudentId       = int.Parse(txtSId.Text.Trim()),
                    Name            = txtName.Text.Trim(),
                    FatherName      = txtFatherName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    DateOfBirth     = dtpDoB.Value,
                    DateOfAdmission = dtpDoAdmission.Value,
                    ProgramID       = progarm.ProgramsId,
                    ClassScheduleID = classSchedule.Id
                };
                updated = studentCRUD.UpdateStudent(student);
            }
            else if (classSchedule.Id == 2)
            {
                EveningShift student = new EveningShift
                {
                    StudentId       = int.Parse(txtSId.Text.Trim()),
                    Name            = txtName.Text.Trim(),
                    FatherName      = txtFatherName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    DateOfBirth     = dtpDoB.Value,
                    DateOfAdmission = dtpDoAdmission.Value,
                    ProgramID       = progarm.ProgramsId,
                    ClassScheduleID = classSchedule.Id
                };
                updated = studentCRUD.UpdateStudent(student);
            }
            else if (classSchedule.Id == 3)
            {
                WeekendShift student = new WeekendShift
                {
                    StudentId       = int.Parse(txtSId.Text.Trim()),
                    Name            = txtName.Text.Trim(),
                    FatherName      = txtFatherName.Text.Trim(),
                    Address         = txtAddress.Text.Trim(),
                    DateOfBirth     = dtpDoB.Value,
                    DateOfAdmission = dtpDoAdmission.Value,
                    ProgramID       = progarm.ProgramsId,
                    ClassScheduleID = classSchedule.Id
                };
                updated = studentCRUD.UpdateStudent(student);
            }
            if (updated)
            {
                MessageBox.Show("Updated Successfully");
            }
        }
        public bool UpdateStudent(EveningShift _student)
        {
            var students = context.EveningShift.ToList();

            foreach (var studnet in students)
            {
                if (studnet.StudentId == _student.StudentId)
                {
                    var student = context.EveningShift.Single(s => s.StudentId == _student.StudentId);
                    student.Name            = _student.Name;
                    student.FatherName      = _student.FatherName;
                    student.Address         = _student.Address;
                    student.DateOfBirth     = _student.DateOfBirth;
                    student.DateOfAdmission = _student.DateOfAdmission;
                    student.ProgramID       = _student.ProgramID;
                    student.ClassScheduleID = _student.ClassScheduleID;

                    context.SaveChanges();
                    return(true);
                }
            }
            AddStudent(_student);
            return(true);
        }
 public bool AddStudent(EveningShift _EveningShift)
 {
     context.EveningShift.Add(_EveningShift);
     context.SaveChanges();
     return(true);
 }
예제 #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                Programs       program = cbProgram.SelectedItem as Programs;
                StudentFactory student;
                MorningShift   morningStudent = null;
                EveningShift   eveningStudent = null;
                WeekendShift   weeklyStudent  = null;
                bool           insert         = false;

                ClassSchedule classSchedule = cbClassesSchedule.SelectedItem as ClassSchedule;

                if (classSchedule.Id == 1)
                {
                    student        = new MorningShiftFactory();
                    morningStudent = (MorningShift)student.GetStudent();
                }
                else if (classSchedule.Id == 2)
                {
                    student        = new EveningShiftFactory();
                    eveningStudent = (EveningShift)student.GetStudent();
                }
                else if (classSchedule.Id == 3)
                {
                    student       = new WeekendShiftFactory();
                    weeklyStudent = (WeekendShift)student.GetStudent();
                }
                else
                {
                    student = null;
                }

                if (student != null)
                {
                    if (classSchedule.Id == 1)
                    {
                        morningStudent.Name            = txtName.Text.Trim();
                        morningStudent.FatherName      = txtFatherName.Text.Trim();
                        morningStudent.Address         = txtAddress.Text.Trim();
                        morningStudent.DateOfBirth     = dtpDoB.Value;
                        morningStudent.DateOfAdmission = dtpDoAdmission.Value;
                        morningStudent.ProgramID       = program.ProgramsId;
                        morningStudent.ClassScheduleID = classSchedule.Id;

                        insert = studentCRUD.AddStudent(morningStudent);
                        ClearTextBoxes();
                    }
                    else if (classSchedule.Id == 2)
                    {
                        eveningStudent.Name            = txtName.Text.Trim();
                        eveningStudent.FatherName      = txtFatherName.Text.Trim();
                        eveningStudent.Address         = txtAddress.Text.Trim();
                        eveningStudent.DateOfBirth     = dtpDoB.Value;
                        eveningStudent.DateOfAdmission = dtpDoAdmission.Value;
                        eveningStudent.ProgramID       = program.ProgramsId;
                        eveningStudent.ClassScheduleID = classSchedule.Id;

                        insert = studentCRUD.AddStudent(eveningStudent);
                        ClearTextBoxes();
                    }
                    else if (classSchedule.Id == 3)
                    {
                        weeklyStudent.Name            = txtName.Text.Trim();
                        weeklyStudent.FatherName      = txtFatherName.Text.Trim();
                        weeklyStudent.Address         = txtAddress.Text.Trim();
                        weeklyStudent.DateOfBirth     = dtpDoB.Value;
                        weeklyStudent.DateOfAdmission = dtpDoAdmission.Value;
                        weeklyStudent.ProgramID       = program.ProgramsId;
                        weeklyStudent.ClassScheduleID = classSchedule.Id;

                        insert = studentCRUD.AddStudent(weeklyStudent);
                        ClearTextBoxes();
                    }
                }
                else
                {
                    MessageBox.Show("Error!");
                }

                if (insert)
                {
                    MessageBox.Show("New Student added successfully.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }