Пример #1
0
        public static void Convert(Document document, DocumentReceiveLog log, WaybillFormat type, WaybillSettings settings)
        {
            if (String.IsNullOrEmpty(document.Log.FileName))
            {
                var extention = settings.GetExportExtension(type);
                log.IsFake = false;
                var id = (document.ProviderDocumentId ?? document.Log.Id.ToString()).Replace('/', '_');
                log.FileName = id + extention;
            }

            var filename = log.GetRemoteFileNameExt();

            if (type == WaybillFormat.ProtekDbf)
            {
                DbfExporter.SaveProtek(document, filename);
            }
            else if (type == WaybillFormat.LessUniversalDbf)
            {
                DbfExporter.SaveUniversalV1(document, filename);
            }
            else if (type == WaybillFormat.UniversalDbf)
            {
                DbfExporter.SaveUniversalV2(document, filename);
            }
            else if (type == WaybillFormat.LipetskFarmacia)
            {
                document.Log.IsFake = false;
                ExcelExporter.SaveLipetskFarmacia(document, filename);
            }
            else if (type == WaybillFormat.InfoDrugstoreXml)
            {
                using (var session = SessionHelper.GetSessionFactory().OpenSession())
                    XmlExporter.SaveInfoDrugstore(session, settings, document, filename);
            }
            else if (type == WaybillFormat.InproXml)
            {
                using (var session = SessionHelper.GetSessionFactory().OpenSession()) {
                    var map = session.Query <SupplierMap>().ToList();
                    XmlExporter.SaveInpro(document, log, filename, map);
                }
            }
            else
            {
                using (var fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite)) {
                    using (var sw = new StreamWriter(fs, Encoding.GetEncoding(1251))) {
                        if (type == WaybillFormat.Sst)
                        {
                            SstExport.SaveShort(document, sw);
                        }
                        else
                        {
                            SstExport.SaveLong(document, sw);
                        }
                    }
                }
            }

            log.DocumentSize = new FileInfo(filename).Length;
        }
        public void ConvertWaybillToDBFWithAssortmentCodes()
        {
            var doc = WaybillParser.Parse("9046752.DBF");

            settings.IsConvertFormat    = true;
            settings.AssortimentPriceId = price.Id;
            settings.Save();
            var order   = TestOrder.FindFirst();
            var address = Address.Find(client.Addresses[0].Id);
            var log     = new DocumentReceiveLog {
                Supplier     = Supplier.Find(supplier.Id),
                ClientCode   = settings.Id,
                Address      = address,
                MessageUid   = 123,
                DocumentSize = 100
            };

            doc.Log        = log;
            doc.OrderId    = order.Id;
            doc.Address    = address;
            doc.FirmCode   = log.Supplier.Id;
            doc.ClientCode = (uint)log.ClientCode;

            doc.SetProductId();

            var path = Path.GetDirectoryName(log.GetRemoteFileNameExt());

            Directory.Delete(path, true);

            Exporter.ConvertIfNeeded(doc, WaybillSettings.Find(doc.ClientCode));

            var files_dbf = Directory.GetFiles(path, "*.dbf");

            Assert.That(files_dbf.Count(), Is.EqualTo(1));
            var file_dbf = files_dbf[0];
            var data     = Dbf.Load(file_dbf, Encoding.GetEncoding(866));

            Assert.That(data.Rows.Count, Is.EqualTo(45));
            Assert.IsTrue(data.Columns.Contains("ID_ARTIS"));
            Assert.IsTrue(data.Columns.Contains("NAME_ARTIS"));
            Assert.IsTrue(data.Columns.Contains("NAME_POST"));
            Assert.That(data.Rows[0]["NAME_POST"], Is.EqualTo("Амоксициллин 500мг таб. Х20 (R)"));
            Assert.That(data.Rows[1]["NAME_POST"], Is.EqualTo("Андипал Таб Х10"));

            Assert.That(data.Rows[0]["ID_ARTIS"], Is.Not.EqualTo("100208"));
            Assert.That(data.Rows[0]["NAME_ARTIS"], Is.Not.EqualTo("МилдронатR р-р д/ин., 10 % 5 мл № 10"));

            Assert.That(data.Rows[1]["ID_ARTIS"], Is.Not.EqualTo("100208"));
            Assert.That(data.Rows[1]["NAME_ARTIS"], Is.Not.EqualTo("МилдронатR р-р д/ин., 10 % 5 мл № 10"));
        }
Пример #3
0
        public void CopyFileTest()
        {
            var fileName = "test1.dbf";
            var file     = File.Create(fileName);

            file.Close();
            var log = new DocumentReceiveLog()
            {
                Supplier = new Supplier {
                    Name = "Тестовый"
                },
                ClientCode    = 0,
                Address       = new Address(),
                MessageUid    = 123,
                DocumentSize  = 100,
                FileName      = fileName,
                LocalFileName = fileName
            };

            log.CopyDocumentToClientDirectory();
            Assert.That(File.Exists(log.GetRemoteFileNameExt()));
        }