private static void DisplayRealTest() { var dbfName = "Seged7.dbf"; using (DbfTable test = DbfTable.Open(dbfName)) { // dbfName isn't closed but reopen an other dbf class DisplayHeader(dbfName); More(); DisplayRows(dbfName, false); More(); } }
private static void OpenNDX() { Console.WriteLine("Isn't realized fully yet!"); string dbfName = "test_ix.dbf"; string ndxName = "test_ix.ndx"; using (DbfTable test = DbfTable.Open(dbfName, Encoding.GetEncoding(437))) { Console.WriteLine(); Console.WriteLine("Open index: " + ndxName); IIndexFile ndx = test.JoinIndexFile(ndxName); Console.WriteLine("Index key : " + ndx.KeyExpression); Console.WriteLine(); var row = ndx.Top(); Console.WriteLine("----------------------------- 'AAA' field --------------------------------------"); Console.WriteLine("Top() : '" + row.GetString("AAA") + "'"); row = ndx.Bottom(); Console.WriteLine(); Console.WriteLine("Bottom(): '" + row.GetString("AAA") + "'"); Console.WriteLine("All rows:"); row = ndx.Top(); // dBase/Clipper style read int rowCount = 0; while (!ndx.eof) { rowCount++; Console.WriteLine(rowCount.ToString("00000") + ": '" + row.GetString("AAA") + "'"); row = ndx.Next(); } Console.WriteLine("---eof---"); } }
private static void DisplayMemo(bool dBase3File) { string dbfFile; if (dBase3File) { dbfFile = "BDE_TEST_3_512.dbf"; // created by DBF Viewer Plus (by http://www.alexnolan.net/) } else { dbfFile = "BDE_TEST_4_512.dbf"; // created by BDE (Borland Database Engine) } DisplayHeader(dbfFile); More(); DisplayRows(dbfFile, false); More(); DisplayRows(dbfFile, true); More(); List <DbfRow> rows = new List <DbfRow>(); if (dBase3File) { using (DbfTable test = DbfTable.Open(dbfFile, Encoding.GetEncoding(437))) { foreach (DbfRow row in test) { // Store for detached mode rows.Add(row); } DisplayTest4DFields(rows); More(); } Console.WriteLine("Detached rows:"); DisplayTest4DFields(rows); } }
static void DisplayHeader(string filename) { Console.WriteLine("'" + filename + "':"); using (DbfTable test = DbfTable.Open(filename, Encoding.GetEncoding(437))) { foreach (var column in test.columns) { string name = "'" + column.name + "'"; char type = Convert.ToChar(column.dbfType); int offset = ((Column)column).offset; Console.WriteLine("{0,-12} {1} {2,4}.{3,-2} {4} [{5}]", name, type, column.size, column.dec, column.type.ToString(), offset); } } Console.WriteLine("==============================================================================="); }
private List <Item> getBlocks(string path, DatabaseType GeneralType) { //NDbfReaderEx --------------------------------- List <Item> Blocks = new List <Item>(); using (DbfTable table = DbfTable.Open(path, encoding)) { foreach (DbfRow row in table) { try { //row.CacheMemos(); Item block = new Item(row, GeneralType, path); Blocks.Add(block); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } sortItemList(Blocks, GeneralType); return(Blocks); }
public ICollection <Mix> GetMixesFromDBF(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException($"Файла {fileName} не существует!"); } var result = new List <Mix>(); using (DbfTable table = DbfTable.Open(fileName, Encoding.GetEncoding(437))) { for (int i = 0; i < table.recCount - 3; i++) { var row = table.GetRow(i + 3); var mix = new Mix { Number = int.Parse(row.GetString("0001")), DateTime = DateTime.Parse(row.GetString("0002")), FormNumber = int.Parse(row.GetString("0003")), RecipeNumber = int.Parse(row.GetString("0004")), MixerTemperature = float.Parse(row.GetString("0005")), SetRevertMud = float.Parse(row.GetString("0006")), ActRevertMud = float.Parse(row.GetString("0007")), SetSandMud = float.Parse(row.GetString("0008")), ActSandMud = float.Parse(row.GetString("0009")), SetColdWater = float.Parse(row.GetString("0010")), ActColdWater = float.Parse(row.GetString("0011")), SetHotWater = float.Parse(row.GetString("0012")), ActHotWater = float.Parse(row.GetString("0013")), SetMixture1 = float.Parse(row.GetString("0014")), ActMixture1 = float.Parse(row.GetString("0015")), SetMixture2 = float.Parse(row.GetString("0016")), ActMixture2 = float.Parse(row.GetString("0017")), SetCement1 = float.Parse(row.GetString("0022")), ActCement1 = float.Parse(row.GetString("0023")), SetCement2 = float.Parse(row.GetString("0024")), ActCement2 = float.Parse(row.GetString("0025")), SetAluminium1 = float.Parse(row.GetString("0026")), ActAluminium1 = float.Parse(row.GetString("0027")), SetAluminium2 = float.Parse(row.GetString("0028")), ActAluminium2 = float.Parse(row.GetString("0029")), SandInMud = float.Parse(row.GetString("0060")), DensityRevertMud = float.Parse(row.GetString("0038")), DensitySandMud = float.Parse(row.GetString("0039")), Normal = true, }; if (i > 0 && mix.SetRevertMud < 0.1 && mix.ActRevertMud < 0.1 && mix.SetSandMud < 0.1 && mix.ActSandMud < 0.1 && mix.SetColdWater < 0.1 && mix.ActColdWater < 0.1) { mix.SetRevertMud = result[i - 1].SetRevertMud; mix.ActRevertMud = result[i - 1].ActRevertMud; mix.SetSandMud = result[i - 1].SetSandMud; mix.ActSandMud = result[i - 1].ActSandMud; mix.SetColdWater = result[i - 1].SetColdWater; mix.ActColdWater = result[i - 1].ActColdWater; mix.SetHotWater = result[i - 1].SetHotWater; mix.ActHotWater = result[i - 1].ActHotWater; mix.SetMixture1 = result[i - 1].SetMixture1; mix.ActMixture1 = result[i - 1].ActMixture1; mix.SetMixture2 = result[i - 1].SetMixture2; mix.ActMixture2 = result[i - 1].ActMixture2; mix.SetCement1 = result[i - 1].SetCement1; mix.ActCement1 = result[i - 1].ActCement1; mix.SetCement2 = result[i - 1].SetCement2; mix.ActCement2 = result[i - 1].ActCement2; mix.SetAluminium1 = result[i - 1].SetAluminium1; mix.ActAluminium1 = result[i - 1].ActAluminium1; mix.SetAluminium2 = result[i - 1].SetAluminium2; mix.ActAluminium2 = result[i - 1].ActAluminium2; mix.SandInMud = result[i - 1].SandInMud; mix.DensityRevertMud = result[i - 1].DensityRevertMud; mix.DensitySandMud = result[i - 1].DensitySandMud; } result.Add(mix); } } return(result); }
static void DisplayRows(string filename, bool rawDataToo = false) { Console.WriteLine("'" + filename + "':"); bool nullFound = false; using (DbfTable test = DbfTable.Open(filename, null)) // null: test codepage byte from DBF header { } using (DbfTable test = DbfTable.Open(filename, Encoding.GetEncoding(437))) { int[] columnWidth = new int[test.columns.Count]; for (int i = 0; (i < test.columns.Count); i++) { int width = test.columns[i].displayWidth; if (width == 0) { width = 20; // variable length data, for example Memo } columnWidth[i] = Math.Max(width, test.columns[i].name.Length); if (test.columns[i].type == typeof(bool)) { if (columnWidth[i] < 5) { columnWidth[i] = 5; } } } string line = String.Empty; for (int i = 0; (i < test.columns.Count); i++) { string format = "|{0," + (test.columns[i].leftSideDisplay ? "-" : "") + columnWidth[i] + "}"; line += String.Format(format, test.columns[i].name); } line += "|"; Console.WriteLine(line); foreach (DbfRow row in test) { line = String.Empty; for (int i = 0; (i < test.columns.Count); i++) { IColumn col = test.columns[i]; string format = "|{0," + (col.leftSideDisplay ? "-" : "") + columnWidth[i] + "}"; if (col.type == typeof(DateTime)) { format = "|{0:yyyy-MM-dd}"; } object output = row.GetValue(col); if (row.IsNull(col)) { output = "¤"; if (col.type == typeof(DateTime)) { format = "|{0,10}"; } nullFound = true; } line += String.Format(format, output); } line += "|"; Console.WriteLine(line); // if (rawDataToo) { line = String.Empty; for (int i = 0; (i < test.columns.Count); i++) { string format = "|{0,-" + columnWidth[i] + "}"; string output = row.GetRawString(test.columns[i]); if (output.Length < columnWidth[i]) { output += "˘"; } line += String.Format(format, output); } line += "| <RAW"; Console.WriteLine(line); } } if (nullFound) { Console.WriteLine("['¤' means null field state]"); } } Console.WriteLine("==============================================================================="); }