示例#1
0
        private void GenerateUpdateXml(SheetRowSource sheetSource, XmlElement record)
        {
            foreach (string eachField in Context.SelectedFields)
            {
                ImportField field    = Context.SupportFields[eachField];
                XmlElement  xmlField = CreateChild(record, field.InternalName);
                xmlField.InnerText = sheetSource.GetFieldData(eachField);
            }

            XmlElement condition = CreateChild(record, "Condition");

            foreach (ImportField each in Context.IdentifyField.Fields)
            {
                XmlElement xmlField = CreateChild(condition, each.InternalName);
                xmlField.InnerText = sheetSource.GetFieldData(each.FieldName);
            }
        }
示例#2
0
 private void GenerateInsertXml(SheetRowSource sheetSource, XmlElement record)
 {
     foreach (string eachField in Context.SelectedFields)
     {
         ImportField field    = Context.SupportFields[eachField];
         XmlElement  xmlField = CreateChild(record, field.InternalName);
         xmlField.InnerText = sheetSource.GetFieldData(eachField);
     }
 }
示例#3
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);
            }
        }