예제 #1
0
 public static bool CheckFileFormat(string file)
 {
     using (var reader = new StreamReader(file, Encoding.GetEncoding(1251))) {
         var parser     = new HeaderBodyParser(reader, CommentSymbol.ToString());
         var headerLine = parser.Header().FirstOrDefault();
         if (headerLine == null)
         {
             return(false);
         }
         var      header = headerLine.Split(';');
         DateTime dt;
         if (!DateTime.TryParse(header[1], out dt))
         {
             return(false);
         }
         if (header.Length != 9 && header.Length != 18 && header.Length != 11 && header.Length != 10 && header.Length != 17 && header.Length != 6)
         {
             return(false);
         }
         var bodyLine = parser.Body().FirstOrDefault();
         if (bodyLine == null)
         {
             return(false);
         }
         var body = bodyLine.Split(';');
         if (body.Length != 22 && body.Length != 24 && body.Length != 27 && body.Length != 26 && body.Length != 21 && body.Length != 31 && body.Length != 20 && body.Length != 32 && body.Length != 25)
         {
             return(false);
         }
         // http://redmine.analit.net/issues/53074
         if (header.Length == 9 && body.Length == 22)
         {
             var s = "";
             for (int i = 3; i < 9; i++)
             {
                 s += header[i];
             }
             if (s.Length == 0)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #2
0
        public Document ParseIndexingMethod(StreamReader reader, Document document)
        {
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            reader.DiscardBufferedData();

            var parser = new HeaderBodyParser(reader, CommentSymbol.ToString());
            var line   = parser.Header().FirstOrDefault();

            if (line == null)
            {
                throw new Exception("Не найден заголовок накладной");
            }

            var header = line.Split(';');

            document.ProviderDocumentId = header[0];
            if (!String.IsNullOrEmpty(header[1]))
            {
                document.DocumentDate = Convert.ToDateTime(header[1]);
            }

            foreach (var body in parser.Body())
            {
                var parts   = body.Split(';');
                var docLine = document.NewLine();
                docLine.Code         = parts[0];
                docLine.Product      = parts[1];
                docLine.Producer     = parts[2];
                docLine.Country      = parts[3];
                docLine.Quantity     = Convert.ToUInt32(ToDecimal(parts[4]));
                docLine.Certificates = parts[12];
                docLine.SerialNumber = parts[13];
                docLine.RegistryCost = String.IsNullOrEmpty(parts[18]) ? null : ToDecimal(parts[18]);
                docLine.SupplierCost = ToDecimal(parts[5]);
                var supplierCos = ToDecimal(parts[7]);
                if (supplierCos != null)
                {
                    docLine.SetSupplierCostWithoutNds(supplierCos.Value);
                }
                docLine.SupplierPriceMarkup = String.IsNullOrEmpty(parts[9]) ? null : ToDecimal(parts[9]);
                docLine.Period = parts[15];
                docLine.ProducerCostWithoutNDS = ToDecimal(parts[6]);
                if (parts.Length >= 26 && !String.IsNullOrEmpty(parts[25]) && (ToDecimal(parts[25]) <= 1))
                {
                    docLine.VitallyImportant = (ToDecimal(parts[25]) == 1);
                }
                //авеста хранит в колонке 11 хранит признак жизненно важный
                else if (parts[10] == "0" || parts[10] == "1")
                {
                    docLine.VitallyImportant = (ToDecimal(parts[10]) == 1);
                }
                // http://redmine.analit.net/issues/60333
                else if (parts[19] == "0" || parts[19] == "1")
                {
                    docLine.VitallyImportant = (ToDecimal(parts[19]) == 1);
                }
                if (parts[16].Length == 13)
                {
                    docLine.EAN13 = NullableConvert.ToUInt64(parts[16]);
                }
            }
            return(document);
        }