Exemplo n.º 1
0
        public async Task LoadData()
        {
            // load the lookups and picker lists
            await azureService.LoadCourseLookup();

            await azureService.LoadCompetitionLookup(Preferences.Get("SocietyId", string.Empty));


            // set up  picker list
            CoursePicker = Common.Pickers.PickerCourse.ToList();
            // set course picker to current course, if editing
            if (Round.CourseId != null)
            {
                SelectedCourse = CoursePicker.FirstOrDefault(o => o.CourseId == Round.CourseId.ToString());
            }
        }
Exemplo n.º 2
0
        private void UpdateTeacherInformation(SheetHelper sheet)
        {
            Dictionary <string, string> selectedFields = new Dictionary <string, string>();

            foreach (string each in Context.SelectedFields)
            {
                selectedFields.Add(each, each);
            }

            if (!UpdateRequired(selectedFields))
            {
                return;
            }
            bool doAddRequired = false;

            ImportCondition condition   = GetIdentifyField();
            CourseLookup    lookup      = new CourseLookup(condition);
            TeacherLookup   tlookup     = Context.Extensions[TeacherLookup.Name] as TeacherLookup;
            SheetRowSource  sheetSource = new SheetRowSource(sheet, Context);

            XmlElement removeReq = DSXmlHelper.LoadXml("<Request/>");
            XmlElement addReq    = DSXmlHelper.LoadXml("<Request/>");

            int firstRow = sheet.FirstDataRowIndex, maxRow = sheet.MaxDataRowIndex;

            for (int rowIndex = firstRow; rowIndex <= maxRow; rowIndex++)
            {
                sheetSource.BindRow(rowIndex);

                string courseId = lookup.GetCourseID(sheetSource);

                if (string.IsNullOrEmpty(courseId))
                {
                    throw new Exception("資料更新過程中,資料可能被另一使用者更改,匯入資料失敗。");
                }

                if (selectedFields.ContainsKey("授課教師一"))
                {
                    XmlElement removeItem = CreateChild(removeReq, "Course");
                    CreateChild(removeItem, "CourseID").InnerText = courseId;
                    CreateChild(removeItem, "Sequence").InnerText = "1";
                }

                if (selectedFields.ContainsKey("授課教師二"))
                {
                    XmlElement removeItem = CreateChild(removeReq, "Course");
                    CreateChild(removeItem, "CourseID").InnerText = courseId;
                    CreateChild(removeItem, "Sequence").InnerText = "2";
                }

                if (selectedFields.ContainsKey("授課教師三"))
                {
                    XmlElement removeItem = CreateChild(removeReq, "Course");
                    CreateChild(removeItem, "CourseID").InnerText = courseId;
                    CreateChild(removeItem, "Sequence").InnerText = "3";
                }

                if (selectedFields.ContainsKey("授課教師一"))
                {
                    string teacherId = tlookup.GetTeacherID(sheetSource.GetFieldData("授課教師一"));
                    if (!string.IsNullOrEmpty(teacherId))
                    {
                        XmlElement addItem = CreateChild(addReq, "CourseTeacher");
                        CreateChild(addItem, "RefCourseID").InnerText  = courseId;
                        CreateChild(addItem, "RefTeacherID").InnerText = teacherId;
                        CreateChild(addItem, "Sequence").InnerText     = "1";
                        doAddRequired = true;
                    }
                }

                if (selectedFields.ContainsKey("授課教師二"))
                {
                    string teacherId = tlookup.GetTeacherID(sheetSource.GetFieldData("授課教師二"));
                    if (!string.IsNullOrEmpty(teacherId))
                    {
                        XmlElement addItem = CreateChild(addReq, "CourseTeacher");
                        CreateChild(addItem, "RefCourseID").InnerText  = courseId;
                        CreateChild(addItem, "RefTeacherID").InnerText = teacherId;
                        CreateChild(addItem, "Sequence").InnerText     = "2";
                        doAddRequired = true;
                    }
                }

                if (selectedFields.ContainsKey("授課教師三"))
                {
                    string teacherId = tlookup.GetTeacherID(sheetSource.GetFieldData("授課教師三"));
                    if (!string.IsNullOrEmpty(teacherId))
                    {
                        XmlElement addItem = CreateChild(addReq, "CourseTeacher");
                        CreateChild(addItem, "RefCourseID").InnerText  = courseId;
                        CreateChild(addItem, "RefTeacherID").InnerText = teacherId;
                        CreateChild(addItem, "Sequence").InnerText     = "3";
                        doAddRequired = true;
                    }
                }
            }

            ImportDataAccess da = Context.DataSource as ImportDataAccess;

            da.RemoveCourseTeachers(removeReq);

            if (doAddRequired)
            {
                da.AddCourseTeachers(addReq);
            }
        }