Ejemplo n.º 1
0
        private void FrmImportStudents_Load(object sender, EventArgs e)
        {
            ExternalExamination.ExamCachePopulate();

            var references = MisCache.SelectedStudents.Select(x => x.Reference).ToList();

            studentReferenceMapping = Students.GetStudentsByRef(references).ToDictionary(v => v.Reference, v => v);
            if (!studentReferenceMapping.Any())
            {
                MessageBoxHelper.ShowError("System can not mapp student by aplication reference number. Please accept/admit your application");
                btnFinish.Enabled = false;
                return;
            }
            var obj = new MyWorkerClass();

            if (!backgroundWorker1.IsBusy)
            {
                TotalRecords         = GetStudents().Count;
                progressBar1.Maximum = TotalRecords;
                backgroundWorker1.RunWorkerAsync(obj);
                btnFinish.Enabled = false;
                btnFinish.Text    = "Processing ...";
            }
        }
Ejemplo n.º 2
0
        public void ProcessData(MyWorkerClass obj)
        {
            List <StudentItem> students = GetStudents();
            int i = 0;

            foreach (StudentItem student in students)
            {
                obj.Name     = student.first_name + " " + student.last_name;
                obj.PersonId = student.id;
                obj.Index    = i;
                var referenceNumber = student.application_reference_number;
                obj.classes = new List <ClassWorkerItem>();
                obj.exams   = new List <ExaminationWorkerItem>();

                #region import external

                if (MisCache.IsImportExamResults && student.exam_results != null && student.exam_results.Any())
                {
                    if (studentReferenceMapping.ContainsKey(referenceNumber))
                    {
                        var studentId = studentReferenceMapping[referenceNumber].PersonId;

                        //loop each exams of student
                        foreach (var exam in student.exam_results)
                        {
                            var workerItem = new ExaminationWorkerItem();
                            workerItem.name = exam.qan + " - " + exam.subject_code + " - " + exam.board_code + " - " + exam.level;
                            //for testing
                            exam.level  = "ABQ/B";
                            exam.result = "P";
                            SimsResult addExamResult = ExternalExamination.AddResult(
                                int.Parse(exam.year),
                                exam.subject_code,
                                exam.board_code,
                                exam.level,
                                exam.qan,
                                exam.result_type,
                                exam.result,
                                exam.school,
                                studentId);

                            workerItem.result = addExamResult;
                            obj.exams.Add(workerItem);
                        }
                    }
                    else
                    {
                        var workerItem = new ExaminationWorkerItem();
                        workerItem.message = "Exam - Could not mapping REFERENCE NUMBER for " + student.first_name +
                                             " " + student.last_name + "( " +
                                             student.application_reference_number + " )";
                        obj.exams.Add(workerItem);
                    }
                }

                #endregion

                #region import classes data

                if (MisCache.IsImportClasses && student.clazzs != null && student.clazzs.Any())
                {
                    string admissionNumber = string.Empty;

                    if (studentReferenceMapping.ContainsKey(referenceNumber))
                    {
                        admissionNumber = studentReferenceMapping[referenceNumber].Reference;
                        //loop each class of student
                        foreach (var classItem in student.clazzs)
                        {
                            int admissionClassId   = classItem.id;
                            var classMappingConfig =
                                MisCache.ClassesMapping.FirstOrDefault(x => x.AdmissionClassId == admissionClassId);

                            var workerItem = new ClassWorkerItem();
                            workerItem.name = admissionClassId + " - " + classItem.name + "-" + classItem.code;
                            if (classMappingConfig != null)
                            {
                                var simsClassName = classMappingConfig.SchemaType + " - " +
                                                    classMappingConfig.SchemaName + " - " +
                                                    classMappingConfig.ClassName;
                                workerItem.name += " - SIMS class :  (" + simsClassName + ") ";
                                SimsResult addClassResult = ClassProcess.AttachClassToStudent(
                                    classMappingConfig.SchemaType, classMappingConfig.SchemaName, admissionNumber,
                                    classMappingConfig.ClassName);
                                workerItem.result = addClassResult;
                            }
                            else
                            {
                                workerItem.message = "FAILED: class [" + workerItem.name + "]  is not config in class mapping.";
                            }

                            obj.classes.Add(workerItem);
                        }
                    }
                    else
                    {
                        var workerItem = new ClassWorkerItem();
                        workerItem.message = "Classes - Could not mapping REFERENCE NUMBER for " + student.first_name +
                                             " " + student.last_name + "( " +
                                             student.application_reference_number + " )";
                        obj.classes.Add(workerItem);
                    }
                }

                #endregion

                backgroundWorker1.ReportProgress(i, obj);
                i++;
                Thread.Sleep(100);
            }
        }