Exemplo n.º 1
0
        private void btnAddSubject_Click(object sender, EventArgs e)
        {
            lblValidation.Text = string.Empty;
            Institute institute = null;
            if (!cbInstitute.SelectedItem.ToString().Equals("Brak"))
                institute = InstituteController.Instance.GetInstitute(cbInstitute.SelectedItem.ToString(), plan.DepartamentID);

            if (institute == null && !cbInstitute.SelectedItem.ToString().Equals("Brak"))
            {
                MessageBox.Show("Wybrany instytut ju¿ nie istnieje");
                FillWithInstitutes();
                return;
            }

            Semester semester = SemesterController.Instance.GetSemester(cbSemester.SelectedItem.ToString());
            
            if(semester == null)
            {
                MessageBox.Show("Wybrany semestr ju¿ nie istnieje");
                FillWithSemesters();
                return;
            }

            List<NewSubjectTypeData> nstdlist = new List<NewSubjectTypeData>();
            for (int i = 0; i < dgSubjectTypes.Rows.Count; i++)
            { 
                if(Convert.ToInt32(dgSubjectTypes.Rows[i].Cells["hours"].Value) > 0)
                {
                    SubjectType st = SubjectTypeController.Instance.GetSubjectType(dgSubjectTypes.Rows[i].Cells["subjectType"].Value.ToString());
                    if (st != null)
                    {
                        NewSubjectTypeData nstd = new NewSubjectTypeData()
                        {
                            Hours = Convert.ToInt32(dgSubjectTypes.Rows[i].Cells["hours"].Value),
                            SubjectTypeId = st.SubjectTypeID
                        };

                        nstdlist.Add(nstd);
                    }
                }
            }

            List<NewSpecializationData> nspdlist = new List<NewSpecializationData>();
            if (dgSpecializations.Enabled == true)
                for (int i = 0; i < dgSpecializations.Rows.Count; i++)
                {
                    if (dgSpecializations.Rows[i].Cells["specialization"].Value != null)
                    {
                        SpecializationEdit s = SpecializationController.Instance.GetSpecializationEdit(dgSpecializations.Rows[i].Cells["specialization"].Value.ToString());
                        if (s != null)
                        {
                            NewSpecializationData nspd = new NewSpecializationData()
                            {
                                IsElective = Convert.ToBoolean(dgSpecializations.Rows[i].Cells["elective"].Value),
                                IsGenereal = Convert.ToBoolean(dgSpecializations.Rows[i].Cells["general"].Value),
                                SpecializationId = s.SpecializationID
                            };

                            nspdlist.Add(nspd);
                        }
                    }
                }

            NewSubject subject = new NewSubject()
            {
                DepartamentId = plan.DepartamentID,
                Ects = Convert.ToDouble(seEcts.Value),
                FacultyId = plan.FacultyID,
                InstituteId = institute == null ? 0 : institute.InstituteID,
                IsExam = ckbxExam.Checked, 
                Name = tbSubjectName.Text,
                SemesterId = semester.SemesterID,
                SubjectTypes = nstdlist,
                PlanId = plan.PlanID,
                Specializations = nspdlist.Count > 0 ? nspdlist : null,
                IsElective = cbElective.Checked,
                IsGeneral = cbGeneral.Checked
            };

            if ((plan.SemesterStart.HasValue && plan.SemesterStart.Value > semester.Semester1)
                || (plan.SemesterEnd.HasValue && plan.SemesterEnd.Value < semester.Semester1))
                subject.AddError("W planie nie mo¿e\nbyæ przedmiotu na takim semestrze");

            if (SubjectController.Instance.AddSubject(subject))
                RadMessageBox.Show("Przedmiot zosta³ dodany", "Wiadomoœæ");
            else
            {
                string errors = string.Empty;
                foreach (string error in subject.Errors)
                    errors = errors + error + "\n";

                lblValidation.Text = errors;
            }
        }
        public void CopyArchivePlan(int sourcePlanId, int targetPlanId)
        {
            Plan source = this.repository.GetPlan(sourcePlanId);
            Plan target = this.repository.GetPlan(targetPlanId);
            
            if (source != null && target != null)
            {
                foreach (SubjectsData sd in source.SubjectsDatas)
                {
                    if (target.SemesterStart <= sd.Semester.Semester1 && target.SemesterEnd >= sd.Semester.Semester1)
                    {
                        NewSubject ns = new NewSubject()
                                            {
                                                PlanId = targetPlanId,
                                                DepartamentId = sd.DepartamentID,
                                                Ects = sd.Ects,
                                                FacultyId = sd.FacultyID,
                                                IsElective = sd.IsElective,
                                                IsExam = sd.IsExam,
                                                IsGeneral = sd.IsGeneral,
                                                Name = sd.Subject.Name,
                                                SemesterId = sd.SemesterID,
                                            };

                        if (sd.SpecializationsData != null)
                        {
                            List<NewSpecializationData> specList = new List<NewSpecializationData>();
                            NewSpecializationData nsd = new NewSpecializationData()
                                                            {
                                                                IsElective = sd.SpecializationsData.IsElective,
                                                                IsGenereal = sd.SpecializationsData.IsGeneral,
                                                                SpecializationId =
                                                                    sd.SpecializationsData.SpecializationID
                                                            };

                            specList.Add(nsd);
                            ns.Specializations = specList.AsEnumerable();
                        }

                        List<NewSubjectTypeData> nstdList = new List<NewSubjectTypeData>();

                        foreach (SubjectTypesData std in sd.SubjectTypesDatas)
                        {
                            NewSubjectTypeData nstd = new NewSubjectTypeData()
                                                          {
                                                              Hours = (float) std.Hours,
                                                              SubjectTypeId = std.SubjectTypeID
                                                          };

                            nstdList.Add(nstd);
                        }

                        ns.SubjectTypes = nstdList.AsEnumerable();

                        if (sd.InstituteID > 0)
                            ns.InstituteId = (int) sd.InstituteID;
                        else
                            sd.InstituteID = null;

                        SubjectController.Instance.AddSubject(ns);
                    }
                }
            }
        }