Пример #1
0
        private static void CreateTableAndWriteRows()
        {
            {
                string fileName1 = "createdTest1.dbf";
                string fileName2 = "createdTest2.dbf";

                File.Delete(fileName1);                                        // DbfTable.Create can't overwrite exists file - it's a precautionary measure.
                File.Delete(fileName2);                                        // according to plan --''--
                File.Delete("createdTest2.dbt");                               // according to plan: CreateHeader_Memo can't overwrites existing DBT file.

                var columns = new List <ColumnDefinitionForCreateTable>();

                columns.Add(ColumnDefinitionForCreateTable.StringField("AAA", 10));
                columns.Add(ColumnDefinitionForCreateTable.NumericField("BBB", 8, 3));
                columns.Add(ColumnDefinitionForCreateTable.DateField("CCC"));
                columns.Add(ColumnDefinitionForCreateTable.LogicalField("DDD"));

                using (var dbfTable = DbfTable.Create(fileName1, columns, DbfTable.CodepageCodes.CP_852, DbfTableType.DBF_Ver3_dBase))
                {
                    Console.WriteLine("{0} file created.", Path.GetFullPath(fileName1));
                }

                columns.Add(ColumnDefinitionForCreateTable.MemoField("EEE"));

                using (var dbfTable = DbfTable.Create(fileName2, columns, Encoding.GetEncoding(852), DbfTableType.DBF_Ver3))
                {
                    Console.WriteLine("{0} file created.", Path.GetFullPath(fileName2));
                }

                //--- There isn't write code to add rows... yet
            }

            // TODO: !!!

            //{
            //  string fileName3 = "createdTest3.dbf";
            //  string fileName4 = "createdTest4.dbf";

            //  File.Delete(fileName3);                                                // DbfTable.Create can't overwrite exists file - it's a precautionary measure.
            //  File.Delete(fileName4);                                                // according to plan --''--
            //  File.Delete("createdTest4.dbt");                                       // according to plan: CreateHeader_Memo can't overwrites existing DBT file.

            //  var columns = new List<ColumnDefinitionForCreateTable>();

            //  columns.Add(ColumnDefinitionForCreateTable.StringField("AAAAAAAAAAAAAAA", 10, false));         // Name length more then 10
            //  columns.Add(ColumnDefinitionForCreateTable.NumericField("BBBBBBBBBBBBBBB", 8, 3, false));
            //  columns.Add(ColumnDefinitionForCreateTable.DateField("CCCCCCCCCCCCCCC", false));
            //  columns.Add(ColumnDefinitionForCreateTable.LogicalField("DDDDDDDDDDDDDDD", false));

            //  using (var dbfTable = DbfTable.Create(fileName3, columns, DbfTable.CodepageCodes.CP_852, DbfTableType.DBF_Ver7))
            //  {

            //  }

            //  columns.Add(ColumnDefinitionForCreateTable.MemoField("EEEEEEEEEEEEEEE", false));
            //  columns.Add(ColumnDefinitionForCreateTable.NumericField("FFFFFFFFFFFFFFF", 4, false));

            //  using (var dbfTable = DbfTable.Create(fileName4, columns, Encoding.GetEncoding(852), DbfTableType.DBF_Ver7))
            //  {

            //  }

            //  //--- There isn't write code to add rows... yet
            //}
        }