public int Compare(AbstractImportCommonAttrInfo info1, AbstractImportCommonAttrInfo info2) { string index1 = ExcelStringUtil.SafeTrim(info1.Index); string index2 = ExcelStringUtil.SafeTrim(info2.Index); if (ExcelStringUtil.IsEmpty(index1) || !ExcelStringUtil.isNumber(index1)) { return(1); } if (ExcelStringUtil.IsEmpty(index2) || !ExcelStringUtil.isNumber(index2)) { return(-1); } if (ExcelStringUtil.isNumber(index1) && ExcelStringUtil.isNumber(index2)) { return(Convert.ToInt32(index1) - Convert.ToInt32(index2)); } return(0); }
/// <summary> /// ExportConfigInfo /// </summary> /// <param name="document"> </param> /// <param name="id"></param> private ImportConfigInfo readExcelInfo(XmlDocument document, string id) { // ========================================================= // 讀取設定資訊 // ========================================================= XmlNode excelNode = document.SelectSingleNode( "//" + Constant.ELEMENT_EXCEL + "[@" + Constant.ATTRIBUTE_ID + "=\"" + id + "\"]"); //XmlNode excelNode = document.SelectSingleNode("//" + Constant.ELEMENT_EXCEL + "[" + Constant.ATTRIBUTE_ID + "=\"" + configID + "\"]"); if (excelNode == null) { throw new ExcelOperateException("設定資訊:[" + id + "] 不存在!"); } // ========================================================= // 讀取 excel 標籤屬性 // ========================================================= ImportConfigInfo importConfigInfo = new ImportConfigInfo(); //configID importConfigInfo.Desc = ExcelStringUtil.GetNodeAttr(excelNode, Constant.ATTRIBUTE_ID); //sheetNum string sheetNum = ExcelStringUtil.GetNodeAttr(excelNode, Constant.ATTRIBUTE_SHEETNUM, "1"); if (!ExcelStringUtil.isNumber(sheetNum)) { throw new ExcelOperateException("屬性 sheetNum 設定錯誤! sheetNum:[" + sheetNum + "]"); } importConfigInfo.SheetNum = Convert.ToInt32(sheetNum); //startRow string startRow = ExcelStringUtil.GetNodeAttr(excelNode, Constant.ATTRIBUTE_STARTROW); if (!ExcelStringUtil.isNumber(startRow)) { throw new ExcelOperateException("屬性 startRow 設定錯誤! startRow:[" + startRow + "]"); } importConfigInfo.StartRow = Convert.ToInt32(startRow); //CheckEmptyRow importConfigInfo.CheckEmptyRow = ExcelStringUtil.GetNodeAttr(excelNode, Constant.ATTRIBUTE_CHECK_EMPTY_ROW); //check duplicate importConfigInfo.CheckDuplicate = ExcelStringUtil.GetNodeAttr(excelNode, Constant.ATTRIBUTE_CHECK_DUPLICATE); //desc importConfigInfo.Desc = ExcelStringUtil.GetNodeAttr(excelNode, Constant.ATTRIBUTE_DESC); // ========================================================= // 讀取 excel/read 標籤 下的 column // ========================================================= //讀取 node list XmlNodeList columnNodeList = excelNode.SelectNodes(Constant.ELEMENT_READ + "/" + Constant.ELEMENT_COLUMN); //檢核 if (ExcelStringUtil.IsEmpty(columnNodeList)) { throw new ExcelOperateException("未找到任何 <column> (config/excel/read/column)"); } //收集屬性設定list IList <ColumnInfo> columnInfoList = new List <ColumnInfo>(); importConfigInfo.ColumnInfoList = columnInfoList; //紀錄KEY避免重複 var keySet = new HashSet <string>(); //逐筆讀取 if (columnNodeList != null) { foreach (XmlNode columnNode in columnNodeList) { //未設定 key 代表要略過的欄位 //if (ExcelStringUtil.GetNodeAttr(columnNode, Constant.ATTRIBUTE_KEY, "@@xx") == "@@xx") //{ // continue; //}; //初始化物件 ColumnInfo columnInfo = new ColumnInfo(); //讀取共通屬性 columnInfo.readCommonAttr(columnNode); //FormatId columnInfo.FormatId = ExcelStringUtil.GetNodeAttr(columnNode, Constant.ATTRIBUTE_FORMATID); //regexp columnInfo.Regex = ExcelStringUtil.GetNodeAttr(columnNode, Constant.ATTRIBUTE_REGEX); //RegexErrorMsg columnInfo.RegexErrorMsg = ExcelStringUtil.GetNodeAttr(columnNode, Constant.ATTRIBUTE_REGEX_ERROR_MSG); //isNull columnInfo.CheckNull = ExcelStringUtil.GetNodeAttr(columnNode, Constant.ATTRIBUTE_CHECK_NULL); //pass columnInfo.Pass = "******".Equals(ExcelStringUtil.GetNodeAttr(columnNode, Constant.ATTRIBUTE_PASS), StringComparison.CurrentCultureIgnoreCase); //add to list columnInfoList.Add(columnInfo); //檢核Key 是否重複 this.checkKey(keySet, columnInfo.Key); } } // ========================================================= // 讀取 excel/params 標籤 下的 param // ========================================================= //讀取 node list XmlNodeList paramNodeList = excelNode.SelectNodes(Constant.ELEMENT_PARAMS + "/" + Constant.ELEMENT_PARAM); //收集屬性設定list IList <ParamInfo> paramInfoList = new List <ParamInfo>(); importConfigInfo.ParamInfoList = paramInfoList; //逐筆讀取 if (paramNodeList != null) { foreach (XmlNode paramNode in paramNodeList) { //初始化物件 ParamInfo paramInfo = new ParamInfo(); //讀取共通屬性 paramInfo.readCommonAttr(paramNode); //add to list paramInfoList.Add(paramInfo); //檢核Key 是否重複 this.checkKey(keySet, paramInfo.Key); } } return(importConfigInfo); }