Example #1
0
        public static TextFileDataFormat GetCurrentTextDataFormat()
        {
            TextFileDataFormat df = new TextFileDataFormat();
            df.TextFormat = TextDataFormat.Delimited;
            df.Delimiter = CultureInfo.CurrentCulture.TextInfo.ListSeparator;
            df.ColumnNameHeader = true;
            df.Encoding = Encoding.Default;
            df.MaxScanRows = 0;

            df.DateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
            df.DecimalSymbol = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
            df.NumberDigits = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalDigits;
            df.CurrencyDecimalSymbol = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;
            df.CurrencyThousandSymbol = CultureInfo.CurrentCulture.NumberFormat.CurrencyGroupSeparator;
            df.CurrencyDigits = CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits;
            df.CurrencyNegFormat = CultureInfo.CurrentCulture.NumberFormat.CurrencyNegativePattern;
            df.CurrencyPosFormat = CultureInfo.CurrentCulture.NumberFormat.CurrencyPositivePattern;
            df.CurrencySymbol = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol;
            return df;
        }
Example #2
0
 public static void ExportTextDataFormat(IniFile ini, string section, TextFileDataFormat df)
 {
     ini.SetValue(section, "DateTimeFormat", df.DateTimeFormat);
     ini.SetValue(section, "DecimalSymbol", df.DecimalSymbol);
     ini.SetValue(section, "CurrencySymbol", df.CurrencySymbol);
     ini.SetValue(section, "CurrencyThousandSymbol", df.CurrencyThousandSymbol);
     ini.SetValue(section, "CurrencyDecimalSymbol", df.CurrencyDecimalSymbol);
     ini.SetValue(section, "NumberDigits", df.NumberDigits.ToString());
     ini.SetValue(section, "CurrencyDigits", df.CurrencyDigits.ToString());
     ini.SetValue(section, "NumberLeadingZeros", df.NumberLeadingZeros ? "True" : "False");
     ini.SetValue(section, "CurrencyNegFormat", CurrencyNegativePatterns[df.CurrencyNegFormat]);
     ini.SetValue(section, "CurrencyPosFormat", CurrencyPositivePatterns[df.CurrencyPosFormat]);
 }
Example #3
0
 private void ParseIniCharacterSet(IniFile ini, string section, ref TextFileDataFormat df)
 {
     if (ini.HasEntry(section, "CharacterSet"))
     {
         string value = (string)ini.GetValue(section, "CharacterSet");
         if (value == "ANSI")
             df.Encoding = Encoding.Default;
         else 
             df.Encoding = Encoding.GetEncoding(value);
     }
 }
Example #4
0
 private void ParseCurrencyNegFormat(IniFile ini, string section, ref TextFileDataFormat df)
 {
     if (ini.HasEntry(section, "CurrencyNegFormat"))
     {
         string value = (string)ini.GetValue(section, "CurrencyNegFormat");
         int index = Array.IndexOf<String>(CurrencyNegativePatterns, value);
         if (index != -1)
             df.CurrencyPosFormat = index;
     }
 }
Example #5
0
 private void ParseIniTextDataFormat(IniFile ini, string section, ref TextFileDataFormat df)
 {
     if (ini.HasEntry(section, "Format"))
     {
         string value = (string)ini.GetValue(section, "Format");
         if (value == "TabDelimited")
         {
             df.TextFormat = TextDataFormat.TabDelimited;
             df.Delimiter = "\t";
         }
         else if (value == "CSVDelimited")
             df.TextFormat = TextDataFormat.Delimited;
         else if (value.StartsWith("Delimited("))
         {
             df.TextFormat = TextDataFormat.Delimited;
             string s = value.Substring(value.IndexOf('(') + 1, 1);
             if (s != "" && s != ")")
                 df.Delimiter = s;
         }
         else if (value == "FixedLength")
             df.TextFormat = TextDataFormat.FixedLength;
     }
 }
Example #6
0
        private DataTable CreateRowType(IniFile ini, string section, ref TextFileDataFormat df)
        {            
            ParseIniTextDataFormat(ini, section, ref df);
            ParseIniCharacterSet(ini, section, ref df);            
            
            df.DateTimeFormat = GetIniString(ini, section, "DateTimeFormat", df.DateTimeFormat);
            df.DecimalSymbol = GetIniString(ini, section, "DecimalSymbol", df.DecimalSymbol);
            df.CurrencySymbol = GetIniString(ini, section, "CurrencySymbol", df.CurrencySymbol);
            df.CurrencyThousandSymbol = GetIniString(ini, section, "CurrencyThousandSymbol", df.CurrencyThousandSymbol);
            df.CurrencyDecimalSymbol = GetIniString(ini, section, "CurrencyDecimalSymbol", df.CurrencyDecimalSymbol);

            df.NumberDigits = GetIniNumber(ini, section, "NumberDigits", df.NumberDigits);
            df.CurrencyDigits = GetIniNumber(ini, section, "CurrencyDigits", df.CurrencyDigits);

            df.ColumnNameHeader = GetIniBoolean(ini, section, "ColNameHeader", df.ColumnNameHeader);
            df.NumberLeadingZeros = GetIniBoolean(ini, section, "NumberLeadingZeros", df.NumberLeadingZeros);
            df.SequentialProcessing = GetIniBoolean(ini, section, "SequentialProcessing", df.SequentialProcessing);

            ParseCurrencyNegFormat(ini, section, ref df);
            ParseCurrencyPosFormat(ini, section, ref df);

            df.NullValue = GetIniString(ini, section, "NullValue", null);

            List<string> names = new List<string>();
            List<int> length = new List<int>();
            DataProviderHelper helper = new DataProviderHelper();
            DataTable dt = RowType.CreateSchemaTable();

            string[] keys = ini.GetEntryNames(section);
            Regex regex = new Regex("^Col[0-9]+$");
            StringBuilder sb = new StringBuilder();
            string[] values = new string[4];
            int ordinal = 0;
            for (int k = 0; k < keys.Length; k++)
                if (regex.IsMatch(keys[k]))
                {
                    CsvParser parser = new CsvParser(' ');
                    if (parser.Get((string)ini.GetValue(section, keys[k]), values) > 0)
                    {
                        DataRow dr = dt.NewRow();
                        dr["ColumnOrdinal"] = ordinal++;
                        dr["ColumnName"] = Util.CreateUniqueName(names, helper.NativeFormatIdentifier(values[0]));
                        dr["DataType"] = DecodeDataType(values[1]);
                        if (values[2] == "Width" && values[3] != null)
                        {
                            int size = Int32.Parse(values[3]);
                            if ((System.Type)dr["DataType"] == typeof(System.String))
                                dr["ColumnSize"] = size;
                            length.Add(size);
                        }
                        else
                            if (df.TextFormat == TextDataFormat.FixedLength)
                                throw new ESQLException(Properties.Resources.ExpectedWidthInSchemaIni, values[0]);
                        dt.Rows.Add(dr);                        
                    }
                }
            if (df.TextFormat == TextDataFormat.FixedLength)
            {
                if (dt.Rows.Count == 0)
                    throw new ESQLException(Properties.Resources.ColumnDataTypeRequred);
                df.Width = length.ToArray();
            }
            return dt;
        }
Example #7
0
 private DataTable CreateRowType(string fileName, ref TextFileDataFormat format)
 {
     string iniFileName = Path.Combine(Path.GetDirectoryName(fileName), "schema.ini");
     if (File.Exists(iniFileName))
     {
         IniFile ini = new IniFile(iniFileName);
         string[] sections = ini.GetSectionNames();
         string name = Path.GetFileName(fileName);
         foreach (string s in sections)
             if (s.IndexOfAny(new char[] { '?', '*' }) != -1)
             {
                 String[] files = Directory.GetFiles(Path.GetDirectoryName(fileName), s);
                 for (int k = 0; k < files.Length; k++)
                     files[k] = Path.GetFileName(files[k]);
                 if (Array.IndexOf<String>(files, name) != -1)
                     return CreateRowType(ini, s, ref format);
             }
             else
                 if (String.Compare(s, name, true) == 0)
                     return CreateRowType(ini, s, ref format);
     }
     return null;
 }
Example #8
0
 private DateTimeFormatInfo GetDateTimeFormatInfo(TextFileDataFormat df)
 {
     DateTimeFormatInfo dfi = new CultureInfo(CultureInfo.CurrentCulture.Name, false).DateTimeFormat;
     dfi.SetAllDateTimePatterns(new string[] { df.DateTimeFormat }, 'd');
     return dfi;
 }
Example #9
0
 private NumberFormatInfo GetNumberFormatInfo(TextFileDataFormat df)
 {
     NumberFormatInfo nfi = new CultureInfo(CultureInfo.CurrentCulture.Name, false).NumberFormat;
     nfi.NumberDecimalSeparator = df.DecimalSymbol;
     nfi.NumberDecimalDigits = df.NumberDigits;
     nfi.CurrencyDecimalSeparator = df.CurrencyDecimalSymbol;
     nfi.CurrencyGroupSeparator = df.CurrencyThousandSymbol;
     nfi.CurrencyDecimalDigits = df.CurrencyDigits;
     nfi.CurrencyPositivePattern = df.CurrencyPosFormat;
     nfi.CurrencyNegativePattern = df.CurrencyNegFormat;
     nfi.CurrencySymbol = df.CurrencySymbol;
     return nfi;
 }