private void ExportWizard_Load(object sender, EventArgs e) { XmlElement element = StudentBulkProcess.GetExportDescription(); BaseFieldFormater formater = new BaseFieldFormater(); FieldCollection collection = formater.Format(element); //// 加入可以匯出學生狀態 //Field fld1 = new Field(); //fld1.DisplayText = "狀態"; //fld1.FieldName = "StudentStatus"; //collection.Add(fld1); List <string> list = new List <string>(new string[] { "學生系統編號", "姓名", "學號", "身分證號", "狀態" }); //需遮蔽的欄位 List <string> avoids = new List <string>(new string[] { "帳號類型" }); foreach (Field field in collection) { //遮蔽欄位 if (avoids.Contains(field.DisplayText)) { continue; } ListViewItem item = listView.Items.Add(field.DisplayText); if (list.Contains(field.DisplayText)) { item.ForeColor = Color.Red; } item.Tag = field; item.Checked = true; } }
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); }