public void Formalize_dbf() { priceItem.Format.PriceFormat = PriceFormatType.NativeDbf; file = "test.dbf"; priceItem.Format.FOptimizationSkip = "F5"; var table = new DataTable(); table.Columns.Add("F1"); table.Columns.Add("F2"); table.Columns.Add("F3"); table.Columns.Add("F4"); table.Columns.Add("F5"); var lines = Data(); for (var i = 0; i < lines.Length; i++) { var parts = lines[i]; var row = table.NewRow(); table.Rows.Add(row); for (var j = 0; j < parts.Length; j++) { row["F" + (j + 1)] = parts[j]; } } Dbf.Save(table, file); AssertFormalization(); }
public void ApplyTest() { _modified.Records.Add(_modified.Records[0]); // add _modified.DeleteRecord(_modified.Records[1]); // delete _modified.Records[0][_modified.Fields[1]] = "401"; // update _modified.Records[2]["OPIS"] = _modified.CreateMemoEntry("This is a new memo entry!"); // update memo var diff = new DbfDiff(_original, _modified); // serialize to string string serializedDiff = diff.Serialize(); // get instance from json diff = DbfDiff.Deserialize(_original.Fields, serializedDiff); diff.ApplyTo(_original); _original.Save(); Assert.IsFalse(diff.HasChanges); _original = new Dbf(Path.Combine(".\\fixtures\\_Original", DbfName), _encoding); diff = new DbfDiff(_original, _modified); Assert.IsFalse(diff.HasChanges); }
public override string FormatOutputFile(string InputFile, DataRow drSource) { string outFile = Path.GetDirectoryName(InputFile) + Path.DirectorySeparatorChar + "out.dbf"; if (File.Exists(outFile)) { File.Delete(outFile); } var dsDocument = new DataSet(); dsDocument.ReadXml(InputFile); if (Convert.ToInt32(dsDocument.Tables["Header"].Rows[0][HeaderTable.colBrecQ]) != dsDocument.Tables["Body"].Rows.Count) { throw new Exception("Количество позиций в документе не соответствует значению в заголовке документа с " + HeaderTable.colMsgNum + " = " + dsDocument.Tables["Header"].Rows[0][HeaderTable.colMsgNum].ToString()); } var dtResult = GetResultTable(); var drHeader = dsDocument.Tables["Header"].Rows[0]; foreach (DataRow drBody in dsDocument.Tables["Body"].Rows) { var drResult = dtResult.NewRow(); drResult[ResultTable.colDocumentID] = Convert.ToString(drHeader[HeaderTable.colInvNum]); drResult[ResultTable.colDocumentDate] = Convert.ToDateTime(drHeader[HeaderTable.colInvDt]); //Эти два поля не заполняются, т.к. СИА Москва не может их заполнить в реальном времени //drResult[ResultTable.colBillingNumber] = drHeader[HeaderTable.colInvNum]; //drResult[ResultTable.colBillingDate] = Convert.ToDateTime(drHeader[HeaderTable.colInvDt]); drResult[ResultTable.colFirmName] = drSource[WaybillSourcesTable.colShortName]; drResult[ResultTable.colPositionID] = drBody[BodyTable.colLocalCod]; drResult[ResultTable.colPositionName] = drBody[BodyTable.colItemId]; drResult[ResultTable.colQuantity] = Convert.ToInt32(drBody[BodyTable.colItemQty]); drResult[ResultTable.colCost] = Convert.ToDecimal(drBody[BodyTable.colCatPrNV], System.Globalization.CultureInfo.InvariantCulture.NumberFormat); drResult[ResultTable.colStavkaNDS] = Convert.ToDecimal(drBody[BodyTable.colVAT], System.Globalization.CultureInfo.InvariantCulture.NumberFormat); drResult[ResultTable.colNdsAmount] = Convert.ToDecimal(drBody[BodyTable.colCatVat], System.Globalization.CultureInfo.InvariantCulture.NumberFormat); drResult[ResultTable.colCostWithNDS] = Convert.ToDecimal(drBody[BodyTable.colCatTot], System.Globalization.CultureInfo.InvariantCulture.NumberFormat); drResult[ResultTable.colSeria] = drBody[BodyTable.colSeries]; drResult[ResultTable.colPeriod] = Convert.ToDateTime(drBody[BodyTable.colUseBefor]); drResult[ResultTable.colCertificat] = drBody[BodyTable.colSerNumID]; drResult[ResultTable.colProducerName] = drBody[BodyTable.colFirmId]; drResult[ResultTable.colCountry] = drBody[BodyTable.colLandId]; drResult[ResultTable.colGCHDN] = drBody[BodyTable.colGCHDN]; drResult[ResultTable.colBarCode] = drBody[BodyTable.colBarCod]; dtResult.Rows.Add(drResult); } using (var file = new StreamWriter(File.Create(outFile), Encoding.GetEncoding(866))) { Dbf.Save(dtResult, file); } return(outFile); }
private static void Patch(string pathToDb, string pathToPatch, Encoding encoding) { var dbf = new Dbf(pathToDb, encoding); DbfDiff diff = DbfDiff.Deserialize(dbf.Fields, File.ReadAllText(pathToPatch)); diff.ApplyTo(dbf); dbf.Save(); }
private void Formalize() { FlushAndCommit(); var file = Path.GetTempFileName(); Dbf.Save(data, file); var formalizer = PricesValidator.Validate(file, Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()), priceItem.Id); formalizer.Formalize(); }
public void Apply() { if (!File.Exists(Path)) { return; } var dbf = new Dbf(Path, Encoding.GetEncoding(1252)); var diff = DbfDiff.Deserialize(dbf.Fields, _serializedDiff); diff.ApplyTo(dbf); dbf.Save(); }
public void DbfReaderTest() { CommonReaderTest(testFile => { var table = new DataTable("testTable"); table.Columns.Add("testCollumn"); var row = table.NewRow(); row["testCollumn"] = "тестовая информация"; table.Rows.Add(row); Dbf.Save(table, testFile, Encoding.GetEncoding(1251)); var ruleRow = GetFormRuleRow(); ruleRow[FormRules.colPriceEncode] = 1251; var parser = new TestDbfParser(testFile, new PriceFormalizationInfo(ruleRow, new Price())); var resultTable = parser.TestParser.Parse(testFile); Assert.AreEqual(resultTable.Rows[0]["TESTCOLLUM"].ToString(), "тестовая информация"); ruleRow[FormRules.colPriceEncode] = 866; parser = new TestDbfParser(testFile, new PriceFormalizationInfo(ruleRow, new Price())); resultTable = parser.TestParser.Parse(testFile); Assert.AreEqual(resultTable.Rows[0]["TESTCOLLUM"].ToString(), "ЄхёЄютр шэЇюЁьрЎш "); }); }
public void Document_parser() { var file = Guid.NewGuid() + ".dbf"; var productNameColumn = "test_name"; var quantityNameColumn = "test_qt"; var supplierCostColumn = "test_sc"; var supplierCostWithoutNDS = "test_scn"; var table = new DataTable(); table.Columns.Add(productNameColumn); table.Columns.Add(quantityNameColumn, typeof(int)); table.Columns.Add(supplierCostColumn, typeof(decimal)); table.Columns.Add(supplierCostWithoutNDS, typeof(decimal)); table.Rows.Add("0,2л\"Сады Придонья\"сок ябл-виноградный восст.осв.", 27, 19.12, 17.38); Dbf.Save(table, file); var parser = new Inforoom.PriceProcessor.Models.Parser("Тестовый парсер", appSupplier); parser.Add(productNameColumn, "Product"); parser.Add(quantityNameColumn, "Quantity"); parser.Add(supplierCostColumn, "SupplierCost"); parser.Add(supplierCostWithoutNDS, "SupplierCostWithoutNDS"); session.Save(parser); var ids = ParseFile(file); var doc = session.Load <Document>(ids[0]); Assert.AreEqual(1, doc.Lines.Count); var line = doc.Lines[0]; Assert.AreEqual("0,2л\"Сады Придонья\"сок ябл-виноградный восст.осв.", line.Product); Assert.AreEqual(27, line.Quantity); Assert.AreEqual(19.12, line.SupplierCost); Assert.AreEqual(17.38, line.SupplierCostWithoutNDS); }
private static string MergeFiles(DocumentReceiveLog headerFile, DocumentReceiveLog bodyFile) { var tableHeader = Dbf.Load(headerFile.GetFileName()); var tableBody = Dbf.Load(bodyFile.GetFileName()); var commonColumns = new List <string>(); foreach (DataColumn column in tableHeader.Columns) { if (tableBody.Columns.Contains(column.ColumnName)) { commonColumns.Add(column.ColumnName); } else { tableBody.Columns.Add(column.ColumnName); } } var headerColumnName = String.Empty; var bodyColumnName = String.Empty; if (commonColumns.Count != 1) { headerColumnName = "DOCNUMBER"; if (!tableHeader.Columns.Contains(headerColumnName)) { headerColumnName = "DOCNUM"; } bodyColumnName = "DOCNUMDER"; if (!tableBody.Columns.Contains(bodyColumnName)) { bodyColumnName = "DOCNUMBER"; } } else { headerColumnName = commonColumns[0]; bodyColumnName = commonColumns[0]; } if (!tableHeader.Columns.Contains(headerColumnName) || !tableBody.Columns.Contains(bodyColumnName)) { throw new Exception(String.Format(@" При объединении двух DBF файлов возникла ошибка. Количество общих колонок отличается от 1 и нет колонок {2} или {3}. Файл-заголовок: {0} Файл-тело: {1}", headerFile.FileName, bodyFile.FileName, headerColumnName, bodyColumnName)); } foreach (DataRow headerRow in tableHeader.Rows) { foreach (DataRow bodyRow in tableBody.Rows) { if (!headerRow[headerColumnName].Equals(bodyRow[bodyColumnName])) { continue; } foreach (DataColumn column in tableHeader.Columns) { if (commonColumns.Contains(column.ColumnName)) { continue; } bodyRow[column.ColumnName] = headerRow[column.ColumnName]; } } } tableBody.AcceptChanges(); // Path.GetFileName(headerFilePath).Substring(1) потому что первая буква "h" нам не нужна var mergedFileName = Path.Combine(Path.GetTempPath(), MergedPrefix + Path.GetFileName(headerFile.FileName).Substring(1)); if (File.Exists(mergedFileName)) { File.Delete(mergedFileName); } Dbf.Save(tableBody, mergedFileName); return(mergedFileName); }
public static void SaveProtek(Document document, string filename) { var table = new DataTable(); table.Columns.AddRange(new[] { new DataColumn("ID"), new DataColumn("Date", typeof(DateTime)), new DataColumn("Address"), new DataColumn("Org"), new DataColumn("SupID"), new DataColumn("SupDate", typeof(DateTime)), new DataColumn("Product"), new DataColumn("Code"), new DataColumn("Cert"), new DataColumn("CertDate"), new DataColumn("Period"), new DataColumn("Producer"), new DataColumn("Country"), new DataColumn("ProdCost", typeof(decimal)), new DataColumn("RegCost", typeof(decimal)), new DataColumn("CostMarkup", typeof(decimal)), new DataColumn("CostWoNds", typeof(decimal)), new DataColumn("CostWNds", typeof(decimal)), new DataColumn("Quantity", typeof(int)), new DataColumn("VI", typeof(bool)), new DataColumn("Nds", typeof(int)), new DataColumn("Seria"), new DataColumn("Sum", typeof(decimal)), new DataColumn("NdsSum", typeof(decimal)), new DataColumn("Unit"), new DataColumn("ExciseTax", typeof(decimal)), new DataColumn("Entry"), new DataColumn("Ean13") }); foreach (var line in document.Lines) { var row = table.NewRow(); row.SetField("ID", document.Log.Id); row.SetField("Date", document.Log.LogTime); row.SetField("Address", document.Address.Name); row.SetField("Org", document.Address.Org.FullName); row.SetField("SupID", document.ProviderDocumentId); row.SetField("SupDate", document.DocumentDate); row.SetField("Product", line.Product); row.SetField("Code", line.Code); row.SetField("Cert", line.Certificates); row.SetField("CertDate", line.CertificatesDate); row.SetField("Period", line.Period); row.SetField("Producer", line.Producer); row.SetField("Country", line.Country); row.SetField("ProdCost", line.ProducerCost); row.SetField("RegCost", line.RegistryCost); row.SetField("CostMarkup", line.SupplierPriceMarkup); row.SetField("CostWoNds", line.SupplierCostWithoutNDS); row.SetField("CostWNds", line.SupplierCost); row.SetField("Quantity", line.Quantity); row.SetField("VI", line.VitallyImportant); row.SetField("Nds", line.Nds); row.SetField("Seria", line.SerialNumber); row.SetField("Sum", line.Amount); row.SetField("NdsSum", line.NdsAmount); row.SetField("Unit", line.Unit); row.SetField("ExciseTax", line.ExciseTax); row.SetField("Entry", line.BillOfEntryNumber); row.SetField("Ean13", line.EAN13); table.Rows.Add(row); } Dbf.Save(table, filename); }
public static void SaveUniversalV1(Document document, string filename) { var table = new DataTable(); table.Columns.AddRange(new[] { new DataColumn("postid_af"), new DataColumn("post_name_af"), new DataColumn("apt_af"), new DataColumn("aname_af"), new DataColumn("ttn"), new DataColumn("ttn_date"), new DataColumn("id_artis"), new DataColumn("name_artis"), new DataColumn("przv_artis"), new DataColumn("name_post"), new DataColumn("przv_post"), new DataColumn("seria"), new DataColumn("sgodn"), new DataColumn("sert"), new DataColumn("sert_date"), new DataColumn("prcena_bnds"), new DataColumn("gr_cena"), new DataColumn("pcena_bnds"), new DataColumn("nds"), new DataColumn("pcena_nds"), new DataColumn("kol_tov"), new DataColumn("ean13") }); foreach (var line in document.Lines) { var row = table.NewRow(); row["postid_af"] = document.FirmCode; row["post_name_af"] = document.Log.Supplier.FullName; row["apt_af"] = document.Address.Id; row["aname_af"] = document.Address.Name; row["ttn"] = document.ProviderDocumentId; row["ttn_date"] = document.DocumentDate; if (line.AssortimentPriceInfo != null && line.AssortimentPriceInfo.Code != null) { row["id_artis"] = line.AssortimentPriceInfo.Code; } if (line.AssortimentPriceInfo != null && line.AssortimentPriceInfo.Synonym != null) { row["name_artis"] = line.AssortimentPriceInfo.Synonym; } if (line.AssortimentPriceInfo != null && line.AssortimentPriceInfo.SynonymFirmCr != null) { row["przv_artis"] = line.AssortimentPriceInfo.SynonymFirmCr; } row["name_post"] = line.Product; row["przv_post"] = line.Producer; row["seria"] = line.SerialNumber; row["sgodn"] = line.Period; row["sert"] = line.Certificates; row["sert_date"] = line.CertificatesDate; row["prcena_bnds"] = line.ProducerCostWithoutNDS; row["gr_cena"] = line.RegistryCost; row["pcena_bnds"] = line.SupplierCostWithoutNDS; row["nds"] = line.Nds; row["pcena_nds"] = line.SupplierCost; row["kol_tov"] = line.Quantity; row["ean13"] = line.EAN13; table.Rows.Add(row); } Dbf.Save(table, filename); }
protected virtual void DataTableToDbf(DataTable dtExport, string fileName) { using (var writer = new StreamWriter(fileName, false, Encoding.GetEncoding(866))) Dbf.Save(dtExport, writer); }