Exemple #1
0
        public static MereFile <T> CacheCheckSubRec <T>(MereFileField fileFieldForSubRecord) where T : new()
        {
            var f = CacheCheckFile <T>();

            f.MereFileFieldForSubRecord = fileFieldForSubRecord;
            return(f);
        }
Exemple #2
0
 public static string ParseFieldForWrite(List <MereFileParsingOption> options, string toStringFormat, MereFileField field, object value, bool fixedWidth)
 {
     return(ParseFieldForWrite(field.MereColumnForField, toStringFormat, options,
                               field.FieldLength, field.PadChar, value, fixedWidth));
 }
Exemple #3
0
        public static string Parse(MereFileField field, string value, bool delimited)
        {
            var toReturn = value.Trim();
            var options  = field.FileFieldParsingOptions;

            if (options != null)
            {
                var l = string.IsNullOrEmpty(toReturn) ? ' ' : toReturn.Last();

                if (options.Contains(MereFileParsingOption.Ebcidic))
                {
                    var pos = new[] { '{', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', ' ' };
                    var neg = new[] { '}', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', ' ' };
                    if (neg.Contains(l) || pos.Contains(l))
                    {
                        var isNeg = neg.Contains(l);
                        var i     = isNeg ? Array.IndexOf(neg, l) : Array.IndexOf(pos, l);

                        if (isNeg)
                        {
                            toReturn = "-" + toReturn;
                        }

                        toReturn = string.Join("", toReturn.Take(toReturn.Length - 1)) + i;
                    }
                }

                foreach (var option in options)
                {
                    int precision;
                    switch (option)
                    {
                    case MereFileParsingOption.TrailingNegative:

                        if (l == '-')
                        {
                            return("-" + toReturn.TrimEnd('-'));
                        }
                        break;
                    //case MereFileParsingOption.RemoveAllSpaces:
                    //var regex = new Regex("\s/g");
                    //case MereFileParsingOption.TrimStartSpaces:

                    //case MereFileParsingOption.TrimEndSpaces:

                    //case MereFileParsingOption.Trim:

                    //case MereFileParsingOption.RemoveDoubleSpaces:

                    case MereFileParsingOption.RemovedDecimal1:
                        precision = 1;
                        toReturn  = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(toReturn.Length - precision));
                        break;

                    case MereFileParsingOption.RemovedDecimal2:
                        precision = 2;
                        toReturn  = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(toReturn.Length - precision));
                        break;

                    case MereFileParsingOption.RemovedDecimal3:
                        precision = 3;
                        toReturn  = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(toReturn.Length - precision));
                        break;

                    case MereFileParsingOption.RemovedDecimal4:
                        precision = 4;
                        toReturn  = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(toReturn.Length - precision));
                        break;

                    case MereFileParsingOption.RemovedDecimal5:
                        precision = 5;
                        toReturn  = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(toReturn.Length - precision));
                        break;

                    case MereFileParsingOption.RemovedDecimal6:
                        precision = 6;
                        toReturn  = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(toReturn.Length - precision));
                        break;
                        //don't that these are needed here just for writing maybe round?
                        //case MereFileParsingOption.DecimalPrecision1:
                        //    precision = 1;
                        //    toReturn = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(precision));
                        //    break;
                        //case MereFileParsingOption.DecimalPrecision2:
                        //    precision = 2;
                        //    toReturn = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(precision));
                        //    break;
                        //case MereFileParsingOption.DecimalPrecision3:
                        //    precision = 3;
                        //    toReturn = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(precision));
                        //    break;
                        //case MereFileParsingOption.DecimalPrecision4:
                        //    precision = 4;
                        //    toReturn = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(precision));
                        //    break;
                        //case MereFileParsingOption.DecimalPrecision5:
                        //    precision = 5;
                        //    toReturn = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(precision));
                        //    break;
                        //case MereFileParsingOption.DecimalPrecision6:
                        //    precision = 6;
                        //    toReturn = string.Join("", toReturn.Take(toReturn.Length - precision)) + "." + string.Join("", toReturn.Skip(precision));
                        //    break;
                        //end don't that these are needed here just for writing maybe round?
                    }
                }//end foreach option
            }



            var toStringFormat = field.ToStringFormat;

            if (!string.IsNullOrEmpty(toReturn) && toStringFormat != null)
            {
                if (field.MereColumnForField.PropertyDescriptor.PropertyType == typeof(DateTime) || field.MereColumnForField.PropertyDescriptor.PropertyType == typeof(DateTime?))
                {
                    DateTime d;
                    if (DateTime.TryParseExact(toReturn, toStringFormat, new CultureInfo("en-US"), DateTimeStyles.None, out d)) // field.Get(value);
                    {
                        toReturn = d.ToString();
                    }
                }
            }

            if (options != null && options.Contains(MereFileParsingOption.WrapWithDoubleQuotes))
            {
                toReturn = "\"" + toReturn + "\"";
            }

            return(toReturn);
        }