public static string EnsureDataTableQualify(DataTable dt, string schemapath, Hashtable param) { if (param == null) { param = new Hashtable(); } try { IntegrationContext context = new IntegrationContext(param); context.Schema = ValidationUtils.GetDataSchemaFromFile(schemapath); if (context.Schema == null) { return(string.Format("无法解析出[{0}]的schema", schemapath)); } DataTableStorage.GetDataFromSourceDataTable(dt, context); return(context.Message); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// 初始化 /// </summary> private void Init() { if (headerRow > 0) { rowFlag = headerRow; for (int i = 1; i <= totalColumn; i++) { string columnName = worksheet.Cells[headerRow, i].Text.ToLower(); if (!String.IsNullOrEmpty(columnName) && !columnMapping.ContainsKey(columnName)) { columnMapping[columnName] = i; } } } else { rowFlag = 0; } if (!String.IsNullOrEmpty(schemaPath)) { schema = ValidationUtils.GetDataSchemaFromFile(schemaPath); foreach (var field in schema.Fields) { destinationSourceMapping[field.Destination.ToLower()] = field.Source.ToLower(); if (!columnMapping.ContainsKey(field.Source.ToLower())) { throw new ArgumentException(String.Format("列 [{0}] 在Excel中不存在", field.Source)); } var requireAttribute = field.GetAnyAttributeValue("required"); if (!String.IsNullOrEmpty(requireAttribute)) { try { if (Convert.ToBoolean(requireAttribute)) { requiredColumns.Add(field.Source.ToLower()); } } catch { } } var nonSpecialCharsAttribute = field.GetAnyAttributeValue("nonspecialchars"); if (!String.IsNullOrEmpty(nonSpecialCharsAttribute)) { try { if (Convert.ToBoolean(nonSpecialCharsAttribute)) { nonSpecialCharsColumns.Add(field.Source.ToLower()); } } catch { } } var maxlengthAttribute = field.GetAnyAttributeValue("maxlength"); if (!String.IsNullOrEmpty(maxlengthAttribute)) { try { int maxLength = Convert.ToInt32(maxlengthAttribute); maxLengthColumns[field.Source.ToLower()] = maxLength; } catch { } } var typeAttribute = field.Type; if (!String.IsNullOrEmpty(typeAttribute)) { try { columnTypes[field.Source.ToLower()] = typeAttribute; } catch { } } } } }