Ejemplo n.º 1
0
        public void WriteGB2312()
        {
            var dbf = new Dbf(encoding);

            fields.ForEach(x => dbf.Fields.Add(x));

            DbfRecord record = dbf.CreateRecord();

            foreach (var field in fields)
            {
                object item = null;
                try
                {
                    item = data[field.Name];
                }
                catch (Exception)
                {
                    // ignored
                }

                record.Data[fields.IndexOf(field)] = item;
            }

            // Act.
            dbf.Write("test.dbf", DbfVersion.FoxBaseDBase3NoMemo);

            // Assert.
            var dbfTest = new Dbf(encoding);

            dbfTest.Read("test.dbf");
            var rowStd = dbfTest.Records[0];

            Assert.AreEqual(rowStd["中文字段"], "股票代码");
            Assert.AreEqual(rowStd["中文字段2"], "股票代码股");      //should be truncated to 10 bytes
        }
Ejemplo n.º 2
0
        public void WriteFieldAndThreeRecords()
        {
            dbf = new Dbf();
            DbfField field = new DbfField("TEST", DbfFieldType.Character, 12);

            dbf.Fields.Add(field);
            DbfRecord record = dbf.CreateRecord();

            record.Data[0] = "HELLO";
            record         = dbf.CreateRecord();
            record.Data[0] = "WORLD";
            record         = dbf.CreateRecord();
            record.Data[0] = "OUT THERE";
            dbf.Write("test.dbf", DbfVersion.VisualFoxPro);

            dbf = new Dbf();
            dbf.Read("test.dbf");

            Assert.AreEqual("OUT THERE", dbf.Records[2][0], "Record content should be OUT THERE.");
        }
Ejemplo n.º 3
0
        public void DemoCode()
        {
            var       dbf       = new Dbf(DbfVersion.FoxPro2WithMemo);
            DbfField  testField = dbf.AddNewField("TEST", DbfFieldType.Character, 12);
            DbfRecord record    = dbf.CreateRecord();

            record[testField] = "HELLO";
            dbf.SaveTo("test.dbf");

            Assert.AreEqual(record.Data[0], record[testField]);
        }
Ejemplo n.º 4
0
        public void NumericField()
        {
            dbf = new Dbf();
            DbfField field = new DbfField("TEST", DbfFieldType.Numeric, 12, 2);

            dbf.Fields.Add(field);
            DbfRecord record = dbf.CreateRecord();

            record.Data[0] = 3.14;
            dbf.Write("test.dbf", DbfVersion.VisualFoxPro);

            dbf = new Dbf();
            dbf.Read("test.dbf");

            Assert.AreEqual(3.14, dbf.Records[0][0], "Record content should be 3.14.");
        }
Ejemplo n.º 5
0
        public void CurrencyField()
        {
            dbf = new Dbf();
            DbfField field = new DbfField("TEST", DbfFieldType.Currency, 4);

            dbf.Fields.Add(field);
            DbfRecord record = dbf.CreateRecord();

            record.Data[0] = 4.34F;
            dbf.Write("test.dbf", DbfVersion.VisualFoxPro);

            dbf = new Dbf();
            dbf.Read("test.dbf");

            Assert.AreEqual((float)4.34, dbf.Records[0][0], "Record content should be 4.34.");
        }
Ejemplo n.º 6
0
        public void DateTimeField()
        {
            dbf = new Dbf();
            DbfField field = new DbfField("TEST", DbfFieldType.DateTime, 8);

            dbf.Fields.Add(field);
            DbfRecord record = dbf.CreateRecord();

            record.Data[0] = new DateTime(2018, 8, 7, 20, 15, 8);
            dbf.Write("test.dbf", DbfVersion.VisualFoxPro);

            dbf = new Dbf();
            dbf.Read("test.dbf");

            Assert.AreEqual(new DateTime(2018, 8, 7, 20, 15, 8), dbf.Records[0][0], "Record content should be 2018-08-07 20:15:08.");
        }
Ejemplo n.º 7
0
        public void LogicalField()
        {
            dbf = new Dbf();
            DbfField field = new DbfField("TEST", DbfFieldType.Logical, 12);

            dbf.Fields.Add(field);
            DbfRecord record = dbf.CreateRecord();

            record.Data[0] = true;
            dbf.Write("test.dbf", DbfVersion.VisualFoxPro);

            dbf = new Dbf();
            dbf.Read("test.dbf");

            Assert.AreEqual(true, dbf.Records[0][0], "Record content should be TRUE.");
        }
Ejemplo n.º 8
0
        public void WriteCP866()
        {
            // Arrange.
            var standard = ReadStandard();

            var dbf = new Dbf(encoding);

            fields.ForEach(x => dbf.Fields.Add(x));

            DbfRecord record = dbf.CreateRecord();

            foreach (var field in fields)
            {
                object item = null;
                try
                {
                    item = data[field.Name];
                }
                catch (Exception)
                {
                    // ignored
                }

                record.Data[fields.IndexOf(field)] = item;
            }

            // Act.
            dbf.Write("test.dbf", DbfVersion.FoxBaseDBase3NoMemo);

            // Assert.
            var rowStd = standard.Records[0];
            var row    = dbf.Records[0];

            foreach (var field in fields)
            {
                Assert.AreEqual(rowStd[field.Name], row[field.Name]);
            }
        }