Пример #1
0
        public ExportTable Export()
        {
            // 取得匯出規則描述
            XmlElement        descElement      = TeacherBulkProcess.GetExportDescription();
            IFieldFormater    fieldFormater    = new BaseFieldFormater();
            IResponseFormater responseFormater = new ResponseFormater();

            FieldCollection       fieldCollection = fieldFormater.Format(descElement);
            ExportFieldCollection exportFields    = responseFormater.Format(descElement);

            fieldCollection = FieldUtil.Match(fieldCollection, _selectFields);
            exportFields    = FieldUtil.Match(exportFields, _selectFields);

            IRequestGenerator reqGenerator = new ExportStudentRequestGenerator();

            reqGenerator.SetSelectedFields(_selectFields);

            ICondition condition = new BaseCondition("ID", "-1");

            reqGenerator.AddCondition(condition);
            foreach (string id in _conditions)
            {
                ICondition condition2 = new BaseCondition("ID", id);
                reqGenerator.AddCondition(condition2);
            }

            DSRequest  request  = reqGenerator.Generate();
            DSResponse response = TeacherBulkProcess.GetExportList(request);

            ExportTable table = new ExportTable();

            foreach (ExportField field in exportFields)
            {
                table.AddColumn(field);
            }

            foreach (XmlElement record in response.GetContent().GetElements("Teacher"))
            {
                ExportRow row = table.AddRow();
                foreach (ExportField column in table.Columns)
                {
                    int        columnIndex = column.ColumnIndex;
                    ExportCell cell        = row.Cells[columnIndex];
                    XmlNode    cellNode    = record.SelectSingleNode(column.XPath);
                    if (cellNode != null)
                    {
                        cell.Value = cellNode.InnerText;
                    }
                }
            }
            return(table);
        }
Пример #2
0
        public static ExportFieldCollection Match(ExportFieldCollection ruleFields, FieldCollection selectedFields)
        {
            ExportFieldCollection collection = new ExportFieldCollection();

            foreach (ExportField field in ruleFields)
            {
                foreach (Field sField in selectedFields)
                {
                    if (sField.FieldName != field.RequestName)
                    {
                        continue;
                    }
                    collection.Add(field);
                }
            }
            return(collection);
        }
Пример #3
0
        public ExportFieldCollection Format(XmlElement source)
        {
            ExportFieldCollection _collection = new ExportFieldCollection();

            foreach (XmlNode node in source.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                XmlElement element = (XmlElement)node;
                if (element.Name == "Field")
                {
                    string name        = element.GetAttribute("Name");
                    string displaytext = element.GetAttribute("DisplayText");
                    string converter   = element.GetAttribute("Converter");
                    string dataType    = element.GetAttribute("DataType");

                    ExportField field = new ExportField();
                    field.FieldName   = name;
                    field.DisplayText = displaytext;
                    field.XPath       = name;
                    field.RequestName = name;
                    field.Converter   = converter;
                    field.DataType    = dataType;

                    _collection.Add(field);
                }
                else if (element.Name == "XmlField")
                {
                    XmlNode baseNode = element.SelectSingleNode("Element");
                    if (baseNode == null)
                    {
                        continue;
                    }

                    string name = element.GetAttribute("Name");
                    //string displaytext = element.GetAttribute("DisplayText");

                    //ExportField field = new ExportField();
                    //field.FieldName = name;
                    //field.DisplayText = displaytext;
                    XmlElement         baseElement = (XmlElement)baseNode;
                    List <ExportField> fields      = GetFields(baseElement, "", name, name, 1);
                    foreach (ExportField f in fields)
                    {
                        _collection.Add(f);
                    }
                    //foreach (XmlNode recNode in baseElement.SelectNodes("Element"))
                    //{
                    //    XmlElement recElement = (XmlElement)recNode;

                    //    int recIndex = 1;
                    //    foreach (XmlElement fieldNode in recElement.SelectNodes("Field"))
                    //    {
                    //        XmlElement fieldElement = (XmlElement)fieldNode;
                    //        ExportField field = new ExportField();
                    //        string baseDisplay = baseElement.GetAttribute("DisplayText");
                    //        string recDisplay = recElement.GetAttribute("DisplayText");
                    //        string fieldDisplay = fieldElement.GetAttribute("DisplayText");
                    //        string display = baseDisplay + ":" + recDisplay + (string.IsNullOrEmpty(recDisplay) ? "" : ":") + fieldDisplay;
                    //        field.DisplayText = display;

                    //        string baseName = baseElement.GetAttribute("Name");
                    //        string recName = recElement.GetAttribute("Name");
                    //        string fieldName = fieldElement.GetAttribute("Name");
                    //        string xpath = baseName + "/" + recName + "[" + recIndex + "]/" + fieldName;
                    //        field.XPath = xpath;

                    //        field.FieldName = element.GetAttribute("Name");
                    //        recIndex++;
                    //    }
                    //}
                }
            }
            return(_collection);
        }
Пример #4
0
        public ExportTable Export()
        {
            // 取得縣市對照表
            XmlElement schoolLocationList = Config.GetSchoolLocationList().GetContent().BaseElement;

            // 取得匯出規則描述
            XmlElement        descElement      = StudentBulkProcess.GetExportDescription();
            IFieldFormater    fieldFormater    = new BaseFieldFormater();
            IResponseFormater responseFormater = new ResponseFormater();

            FieldCollection       fieldCollection = fieldFormater.Format(descElement);
            ExportFieldCollection exportFields    = responseFormater.Format(descElement);



            fieldCollection = FieldUtil.Match(fieldCollection, _selectFields);
            exportFields    = FieldUtil.Match(exportFields, _selectFields);

            //// 有選狀態時加入
            //if (_selectFields.FindByDisplayText("狀態") != null)
            //{
            //    fieldCollection.Add(_selectFields.FindByDisplayText("狀態"));
            //    ExportField ex = new ExportField();
            //    ex.DisplayText = "狀態";
            //    ex.RequestName = "StudentStatus";
            //    ex.ColumnIndex = exportFields.Length;
            //    ex.DataType = "";
            //    ex.XPath = "";
            //    exportFields.Add(ex);

            //}


            IRequestGenerator reqGenerator = new ExportStudentRequestGenerator();

            _selectFieldsID = new FieldCollection();
            foreach (Field fd in _selectFields)
            {
                _selectFieldsID.Add(fd);
            }

            if (_selectFieldsID.Find("StudentID") == null)
            {
                Field fd1 = new Field();
                fd1.FieldName   = "StudentID";
                fd1.DisplayText = "學生系統編號";
                _selectFieldsID.Add(fd1);
            }
            reqGenerator.SetSelectedFields(_selectFieldsID);

            // 預設找-1, 不然會傳回所有學生
            ICondition condition = new BaseCondition("ID", "-1");

            reqGenerator.AddCondition(condition);
            foreach (string id in _conditions)
            {
                ICondition condition2 = new BaseCondition("ID", id);
                reqGenerator.AddCondition(condition2);
            }

            reqGenerator.AddOrder(new Order("GradeYear"));
            reqGenerator.AddOrder(new Order("Department"));
            reqGenerator.AddOrder(new Order("RefClassID"));
            reqGenerator.AddOrder(new Order("SeatNo"));

            DSRequest  request  = reqGenerator.Generate();
            DSResponse response = QueryStudent.GetExportList(request);

            ExportTable table = new ExportTable();



            foreach (ExportField field in exportFields)
            {
                table.AddColumn(field);
            }

            //// 取得學生狀態
            //Dictionary<string, string> StudStatusDic = new Dictionary<string, string>();
            //foreach (JHSchool.Data.JHStudentRecord stud in JHSchool.Data.JHStudent.SelectByIDs(K12.Presentation.NLDPanels.Student.SelectedSource ))
            //    StudStatusDic.Add(stud.ID, stud.Status.ToString());

            foreach (XmlElement record in response.GetContent().GetElements("Student"))
            {
                ExportRow row = table.AddRow();
                foreach (ExportField column in table.Columns)
                {
                    int        columnIndex = column.ColumnIndex;
                    ExportCell cell        = row.Cells[columnIndex];

                    XmlNode cellNode = record.SelectSingleNode(column.XPath);

                    //if(column.DisplayText !="狀態")
                    //    cellNode = record.SelectSingleNode(column.XPath);
                    // CustodianOtherInfo/CustodianOtherInfo[1]/EducationDegree[1]

                    #region 這段程式是處理匯入/匯出程式不一致問題
                    if (column.XPath.StartsWith("CustodianOtherInfo/Custodian"))
                    {
                        if (cellNode == null)
                        {
                            string x = column.XPath.Replace("CustodianOtherInfo/Custodian", "CustodianOtherInfo/CustodianOtherInfo");
                            cellNode = record.SelectSingleNode(x);
                            if (cellNode == null)
                            {
                                x        = column.XPath.Replace("CustodianOtherInfo/CustodianOtherInfo", "CustodianOtherInfo/Custodian");
                                cellNode = record.SelectSingleNode(x);
                            }
                        }
                    }
                    if (column.XPath.StartsWith("FatherOtherInfo/Father"))
                    {
                        if (cellNode == null)
                        {
                            string x = column.XPath.Replace("FatherOtherInfo/Father", "FatherOtherInfo/FatherOtherInfo");
                            cellNode = record.SelectSingleNode(x);
                            if (cellNode == null)
                            {
                                x        = column.XPath.Replace("FatherOtherInfo/FatherOtherInfo", "FatherOtherInfo/Father");
                                cellNode = record.SelectSingleNode(x);
                            }
                        }
                    }
                    if (column.XPath.StartsWith("MotherOtherInfo/Mother"))
                    {
                        if (cellNode == null)
                        {
                            string x = column.XPath.Replace("MotherOtherInfo/Mother", "MotherOtherInfo/MotherOtherInfo");
                            cellNode = record.SelectSingleNode(x);
                            if (cellNode == null)
                            {
                                x        = column.XPath.Replace("MotherOtherInfo/MotherOtherInfo", "MotherOtherInfo/Mother");
                                cellNode = record.SelectSingleNode(x);
                            }
                        }
                    }
                    #endregion

                    if (cellNode != null)
                    {
                        if (column.FieldName == "GraduateSchoolLocationCode")
                        {
                            cell.Value = GetCounty(schoolLocationList, cellNode.InnerText);
                        }
                        else if (column.FieldName == "DeptName") //處理科別繼承問題。
                        {
                            //這個欄位的資料一定會被回傳,因為設定了 Mandatory 屬性。
                            XmlNode selfDept = record.SelectSingleNode("SelfDeptName");
                            if (string.IsNullOrEmpty(selfDept.InnerText))
                            {
                                cell.Value = cellNode.InnerText;
                            }
                            else
                            {
                                cell.Value = selfDept.InnerText;
                            }
                        }
                        else if (column.FieldName == "Status")
                        {
                            cell.Value = GetStudStatusStr(cellNode.InnerText);
                        }
                        else
                        {
                            cell.Value = cellNode.InnerText;
                        }
                    }

                    //if (column.DisplayText == "狀態")//record.SelectSingleNode("StudentID")!=null )
                    //{
                    //    // 學生狀態
                    //    if (StudStatusDic.ContainsKey(record.SelectSingleNode("StudentID").InnerText))
                    //        cell.Value = StudStatusDic[record.SelectSingleNode("StudentID").InnerText];
                    //}
                }
            }
            return(table);
        }