/// <summary>
        /// get project pages (from pages.dbf)
        /// </summary>
        /// <param name="path"></param>
        public void GetProjectPages(string path, bool retrievePageANs = true)
        {
            using (var dbfTable = new DbfTable(path, System.Text.Encoding.UTF8))
            {
                var skipDeleted = true;
                var dbfRecord   = new DbfRecord(dbfTable);
                while (dbfTable.Read(dbfRecord))
                {
                    if (skipDeleted && dbfRecord.IsDeleted)
                    {
                        continue;
                    }

                    CitectPages.Add(new CitectPages {
                        PageName = dbfRecord.Values[0].ToString(), ObjectANs = new List <int>()
                    });
                }
            }
            var subdir = path.Substring(0, path.LastIndexOf('\\'));

            if (retrievePageANs)
            {
                GetPageAns(subdir + @"\pgdynobj.dbf");
            }
        }
Пример #2
0
        private List <fakeDB> GetFakeDBs()
        {
            var fakeDBs = new List <fakeDB>();

            var        dbfPath = "../../SvgFile/Seoul.dbf";
            List <int> list    = new List <int>();

            for (i = 0; i < 500; i++)
            {
                list.Add(i);
            }

            using (var dbf = new DbfTable(dbfPath, DbfDataReader.EncodingProvider.UTF8))
            {
                var dbfRecord = new DbfRecord(dbf);
                i = 0;
                while (dbf.Read(dbfRecord))//480번 반복
                {
                    fakeDB fakeDB = new fakeDB();
                    fakeDB.emd_cd = int.Parse(dbfRecord.Values[0].ToString());
                    fakeDB.eng    = dbfRecord.Values[1].ToString();
                    fakeDB.val1   = int.Parse(dbfRecord.Values[3].ToString());
                    //fakeDB.val1 = list[i++];
                    fakeDB.val2 = int.Parse(dbfRecord.Values[4].ToString());
                    fakeDB.val3 = int.Parse(dbfRecord.Values[5].ToString());
                    fakeDBs.Add(fakeDB);
                }
            }
            return(fakeDBs);
        }
Пример #3
0
        private static void PrintCsv(Options options)
        {
            var encoding = GetEncoding();

            using (var dbfTable = new DbfTable(options.Filename, encoding))
            {
                var columnNames = string.Join(",", dbfTable.Columns.Select(c => c.ColumnName));
                if (!options.SkipDeleted)
                {
                    columnNames += ",Deleted";
                }

                Console.WriteLine(columnNames);

                var dbfRecord = new DbfRecord(dbfTable);

                while (dbfTable.Read(dbfRecord))
                {
                    if (options.SkipDeleted && dbfRecord.IsDeleted)
                    {
                        continue;
                    }

                    var values = string.Join(",", dbfRecord.Values.Select(v => EscapeValue(v)));
                    if (!options.SkipDeleted)
                    {
                        values += $",{dbfRecord.IsDeleted}";
                    }

                    Console.WriteLine(values);
                }
            }
        }
Пример #4
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            if (this.data_path == null)
            {
                DialogCompanySelect comp = new DialogCompanySelect(this);
                if (comp.ShowDialog() == DialogResult.OK)
                {
                    this.data_path        = comp.selected_comp.RewriteDataPath();
                    this.lblDataPath.Text = DbfTable.GetIsinfo(this.data_path).thinam + " ( " + this.data_path.TrimEnd('\\') + " )";

                    this.LoadStatusComboboxItem();
                    this.cbStatus.SelectedItem = this.cbStatus.Items.Cast <ComboboxItem>().Where(i => ((TransactionStatus.STATUS)i.Value) == TransactionStatus.STATUS.WARRANTY).First();

                    this.iv_list          = new BindingList <ArtrnMin>(DbfTable.InvoiceList(this.data_path, this.status, DbfTable.INVOICE_TYPE.IV));
                    this.dgvIV.DataSource = this.iv_list;
                    this.tabIV.Text       = "  ขายเชื่อ (" + this.iv_list.Count.ToString() + ") <F6>  ";
                }
                else
                {
                    Application.Exit();
                }
            }
            else
            {
                this.lblDataPath.Text = DbfTable.GetIsinfo(this.data_path).thinam + " ( " + this.data_path.TrimEnd('\\') + " )";

                this.LoadStatusComboboxItem();
                this.cbStatus.SelectedItem = this.cbStatus.Items.Cast <ComboboxItem>().Where(i => ((TransactionStatus.STATUS)i.Value) == TransactionStatus.STATUS.WARRANTY).First();

                this.iv_list          = new BindingList <ArtrnMin>(DbfTable.InvoiceList(this.data_path, this.status, DbfTable.INVOICE_TYPE.IV));
                this.dgvIV.DataSource = this.iv_list;
                this.tabIV.Text       = "  ขายเชื่อ (" + this.iv_list.Count.ToString() + ") <F6>  ";
            }
        }
Пример #5
0
        private void ShowWarrantyForm()
        {
            var st = (StcrdMin)this.dgvSTCRD.Rows[this.dgvSTCRD.CurrentCell.RowIndex].Cells[this.col_stcrdmin.Name].Value;

            DialogWarranty war = new DialogWarranty(this, st);

            if (war.ShowDialog() == DialogResult.OK)
            {
                if (this.tabControl2.SelectedTab == this.tabIV)
                {
                    this.curr_invoice = DbfTable.InVoice(this.data_path, this.curr_invoice.artrn.docnum.Trim());
                }
                else
                {
                    this.curr_invoice = DbfTable.InVoice(this.data_path, this.curr_invoice.artrn.docnum.Trim());
                }

                this.FillForm(this.curr_invoice);

                if (this.dgvSTCRD.Rows.Count > 0)
                {
                    this.dgvSTCRD.Rows.Cast <DataGridViewRow>().Where(r => ((StcrdMin)r.Cells[this.col_stcrdmin.Name].Value).seqnum == st.seqnum).First().Cells[this.col_stkcod.Name].Selected = true;
                }
            }
        }
Пример #6
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (this.txtSearchDocnum.Text.Trim().Length == 0)
            {
                return;
            }

            List <ArtrnMin> iv_list = DbfTable.InvoiceList(this.data_path, TransactionStatus.STATUS.ALL, DbfTable.INVOICE_TYPE.IV);
            List <ArtrnMin> hs_list = DbfTable.InvoiceList(this.data_path, TransactionStatus.STATUS.ALL, DbfTable.INVOICE_TYPE.HS);

            ArtrnMin target_invoice = null;

            if (iv_list.Where(i => i.docnum.Trim() == this.txtSearchDocnum.Text.Trim()).FirstOrDefault() != null)
            {
                target_invoice = iv_list.Where(i => i.docnum.Trim() == this.txtSearchDocnum.Text.Trim()).First();
                this.tabControl2.SelectedTab = this.tabIV;
                this.cbStatus.SelectedItem   = this.cbStatus.Items.Cast <ComboboxItem>().Where(c => (TransactionStatus.STATUS)c.Value == TransactionStatus.STATUS.ALL).First();
                this.dgvIV.Rows.Cast <DataGridViewRow>().Where(r => ((string)r.Cells[this.col_iv_docnum.Name].Value).Trim() == this.txtSearchDocnum.Text.Trim()).First().Cells[this.col_iv_docnum.Name].Selected = true;
            }
            else if (hs_list.Where(i => i.docnum.Trim() == this.txtSearchDocnum.Text.Trim()).FirstOrDefault() != null)
            {
                target_invoice = hs_list.Where(i => i.docnum.Trim() == this.txtSearchDocnum.Text.Trim()).First();
                this.tabControl2.SelectedTab = this.tabHS;
                this.cbStatus.SelectedItem   = this.cbStatus.Items.Cast <ComboboxItem>().Where(c => (TransactionStatus.STATUS)c.Value == TransactionStatus.STATUS.ALL).First();
                this.dgvHS.Rows.Cast <DataGridViewRow>().Where(r => ((string)r.Cells[this.col_hs_docnum.Name].Value).Trim() == this.txtSearchDocnum.Text.Trim()).First().Cells[this.col_hs_docnum.Name].Selected = true;
            }
            else
            {
                MessageBox.Show("ค้นหาบิลขายเลขที่ " + this.txtSearchDocnum.Text.Trim() + " ไม่พบ");
                return;
            }
        }
Пример #7
0
        private static void PrintSummaryInfo(Options options)
        {
            var encoding = GetEncoding();

            using (var dbfTable = new DbfTable(options.Filename, encoding))
            {
                var header = dbfTable.Header;

                Console.WriteLine($"Filename: {options.Filename}");
                Console.WriteLine($"Type: {header.VersionDescription}");
                Console.WriteLine($"Memo File: {dbfTable.Memo != null}");
                Console.WriteLine($"Records: {header.RecordCount}");
                Console.WriteLine();
                Console.WriteLine("Fields:");
                Console.WriteLine("Name             Type       Length     Decimal");
                Console.WriteLine("------------------------------------------------------------------------------");

                foreach (var dbfColumn in dbfTable.Columns)
                {
                    var name         = dbfColumn.ColumnName;
                    var columnType   = ((char)dbfColumn.ColumnType).ToString();
                    var length       = dbfColumn.Length.ToString();
                    var decimalCount = dbfColumn.DecimalCount;
                    Console.WriteLine(
                        $"{name.PadRight(16)} {columnType.PadRight(10)} {length.PadRight(10)} {decimalCount}");
                }
            }
        }
Пример #8
0
        private void GetBojData()
        {
            this.isinfo = DbfTable.GetIsinfo(this.main_form.selected_comp);
            using (LocalDbEntities db = DBX.DataSet(this.main_form.selected_comp))
            {
                this.boj5_header = db.boj5_header.FirstOrDefault();
                if (this.boj5_header == null)
                {
                    db.boj5_header.Add(new boj5_header
                    {
                        accSource          = ACC_SOURCE.B.ToString(),
                        foreignShareholder = 0,
                        headerStatus       = "A",
                        meetingNo          = "",
                        meetingType        = MEETING_TYPE.B.ToString(),
                        parValue           = 0,
                        sourceDate         = null,
                        thaiShareholder    = 0,
                        totalCapital       = 0,
                        totalForeignShare  = 0,
                        totalShare         = 0,
                        totalThaiShare     = 0,
                        userId             = "",
                        yearEnd            = null
                    });
                    db.SaveChanges();

                    this.boj5_header = db.boj5_header.First();
                }

                this.boj5_detail = db.boj5_detail.Include("boj5_person").OrderBy(d => d.itemNo).ToList();
            }
        }
Пример #9
0
        /// <summary>
        /// find reference of function name in dbf
        /// </summary>
        /// <param name="path"></param>
        /// <param name="functionName"></param>
        /// <returns></returns>
        private static int FunctionRefExistsInDBF(string path, string functionName)
        {
            var skipDeleted = true;

            //DbfDataReader.DbfDataReader reader = new DbfDataReader.DbfDataReader(kvp.Key);
            using (var dbfTable = new DbfTable(path, System.Text.Encoding.UTF8))
            {
                try
                {
                    var dbfRecord = new DbfRecord(dbfTable);
                    var found     = 0;
                    while (dbfTable.Read(dbfRecord))
                    {
                        if (skipDeleted && dbfRecord.IsDeleted)
                        {
                            continue;
                        }

                        if (dbfRecord.Values.Any(s => s.GetValue().ToString().Contains(functionName)))
                        {
                            found++;
                            break;
                        }
                    }
                    return(found);
                }
                catch (Exception ex)
                {
                    log.Error("error:", ex);
                    return(0);
                }
            }
        }
Пример #10
0
        private static void PrintSchema(Options options)
        {
            var encoding = GetEncoding();

            using (var dbfTable = new DbfTable(options.Filename, encoding))
            {
                var tableName = Path.GetFileNameWithoutExtension(options.Filename);
                Console.WriteLine($"CREATE TABLE [dbo].[{tableName}]");
                Console.WriteLine("(");

                foreach (var dbfColumn in dbfTable.Columns)
                {
                    var columnSchema = ColumnSchema(dbfColumn);
                    Console.Write($"  {columnSchema}");

                    if (dbfColumn.ColumnOrdinal < dbfTable.Columns.Count ||
                        !options.SkipDeleted)
                    {
                        Console.Write(",");
                    }
                    Console.WriteLine();
                }

                if (!options.SkipDeleted)
                {
                    Console.WriteLine("  [deleted] [bit] NULL DEFAULT ((0))");
                }

                Console.WriteLine(")");
            }
        }
Пример #11
0
 static void DisplayTest4DFields(DbfTable table)
 {
     foreach (DbfRow row in table)
     {
         DisplayTest4DField(row);
     }
 }
Пример #12
0
        public Form1()
        {
            foreach (var fi in new System.IO.DirectoryInfo(".").GetFiles("*.ndx"))
            {
                fi.Delete();
            }

            InitializeComponent();
            individuals = new DbfTable <Individual>(@"individuals.dbf", Encoding.ASCII, DbfVersion.dBaseIV);


            listView1.View = View.Details;
            listView1.Columns.Add("Record Number", 80);
            for (int i = 1; i < individuals.Columns.Count; i++)
            {
                var c = individuals.Columns[i];
                listView1.Columns.Add(c.mFieldInfo.Name, 120);
            }

            listView1.VirtualMode     = true;
            listView1.VirtualListSize = individuals.RecordCount;

            this.addToolStripMenuItem.Text = string.Format("Add {0:0,0} individuals", ADD_INDIVIDUALS_COUNT);
            RefreshBar();
        }
Пример #13
0
		public static void FillOrder(string filename, ulong[] ids)
		{
			var table = new DbfTable();
			table.Columns(
				Column.Numeric("NUMZ", 8),
				Column.Date("DATEZ"),
				Column.Char("CODEPST", 12),
				Column.Numeric("PAYID", 2),
				Column.Date("DATE"),
				Column.Char("PODR", 40),
				Column.Numeric("QNT", 8),
				Column.Numeric("PRICE", 9, 2),
				Column.Char("PODRCD", 12),
				Column.Char("NAME", 80)); // расширение протокола

			table.Row(
				Value.For("NUMZ", 2001),
				Value.For("DATEZ", DateTime.Now),
				Value.For("CODEPST", ids[0]),
				Value.For("PAYID", 1), // по колонке PRICE1 прайслиста
				Value.For("DATE", DateTime.Now),
				Value.For("PODR", "аптека"),
				Value.For("QNT", 1),
				Value.For("PRICE", 39.94),
				Value.For("PODRCD", "1"),
				Value.For("NAME", "АНАЛЬГИН АМП. 50% 2МЛ N10 РОССИЯ")
				);

			Dbf2.SaveAsDbf4(table.ToDataTable(), filename);
		}
Пример #14
0
        private static void PrintSchema(Options options)
        {
            var encoding = GetEncoding();

            using (var dbfTable = new DbfTable(options.Filename, encoding))
            {
                var tableName = Path.GetFileNameWithoutExtension(options.Filename);
                Write(options, $"CREATE TABLE [dbo].[{tableName}]");
                Write(options, "(");

                foreach (var dbfColumn in dbfTable.Columns)
                {
                    var columnSchema = ColumnSchema(dbfColumn);
                    var line         = $"  {columnSchema}";

                    if (dbfColumn.ColumnOrdinal < dbfTable.Columns.Count ||
                        !options.SkipDeleted)
                    {
                        line += ",";
                    }
                    Write(options, line);
                }

                if (!options.SkipDeleted)
                {
                    Write(options, "  [deleted] [bit] NULL DEFAULT ((0))");
                }

                Write(options, ")");
            }

            SetOutputFileTimestampToInputFile(options.Filename);
        }
Пример #15
0
        private void btnOpenFolder_Click(object sender, EventArgs e)
        {
            DialogSelectComp selcomp = new DialogSelectComp(this);

            if (selcomp.ShowDialog() != DialogResult.OK)
            {
                if (this.selected_comp == null)
                {
                    Application.Exit();
                }
                return;
            }

            this.selected_comp = selcomp.selected_comp;
            this.glacc_list    = DbfTable.GetGlaccList(this.selected_comp);

            if (this.selected_comp != null)
            {
                SQLiteDbPrepare.EnsureDbCreated(this.selected_comp);
                options opt = HelperClass.GetOptions(OPTIONS.EFILING_TMP_DIR, this.selected_comp);
                if (opt.value_str != null && opt.value_str.Trim().Length > 0 && File.Exists(opt.value_str.Trim()))
                {
                    this.cZipFilePath.Text = opt.value_str.Trim();
                }
                else
                {
                    this.cZipFilePath.Text = string.Empty;
                }
            }

            this.FillForm();
        }
Пример #16
0
        private static void PrintSummaryInfo(Options options)
        {
            var encoding = GetEncoding();

            using (var dbfTable = new DbfTable(options.Filename, encoding))
            {
                var header = dbfTable.Header;

                WriteAllLines(options, new[] {
                    $"Filename: {options.Filename}",
                    $"Type: {header.VersionDescription}",
                    $"Memo File: {dbfTable.Memo != null}",
                    $"Records: {header.RecordCount}",
                    "",
                    "Fields:",
                    "Name                                             Type       Length     Decimal",
                    "------------------------------------------------------------------------------"
                });

                foreach (var dbfColumn in dbfTable.Columns)
                {
                    var name         = dbfColumn.ColumnName;
                    var columnType   = ((char)dbfColumn.ColumnType).ToString();
                    var length       = dbfColumn.Length.ToString();
                    var decimalCount = dbfColumn.DecimalCount;
                    Write(options,
                          $"{name.PadRight(71 - 22)} {columnType.PadRight(10)} {length.PadRight(10)} {decimalCount}");
                }
            }

            SetOutputFileTimestampToInputFile(options.Filename);
        }
        /// <summary>
        /// open pgdynobject.dbf to get ANs
        /// </summary>
        /// <param name="path"></param>
        private void GetPageAns(string path)
        {
            using (var dbfTable = new DbfTable(path, System.Text.Encoding.UTF8))
            {
                var skipDeleted = true;
                var dbfRecord   = new DbfRecord(dbfTable);

                var cols     = dbfTable.Columns.ToList();
                var ANColIdx = 0;
                if (cols.FirstOrDefault(s => s.Name.Contains("AN")) != null)
                {
                    ANColIdx = cols.FirstOrDefault(s => s.Name.Contains("AN")).Index;
                }

                while (dbfTable.Read(dbfRecord))
                {
                    if (skipDeleted && dbfRecord.IsDeleted)
                    {
                        continue;
                    }

                    //get citectpage object from list
                    var citectPage = CitectPages.Find(s => s.PageName.Equals(dbfRecord.GetValue(0).ToString()));
                    citectPage.ObjectANs.Add(int.Parse(dbfRecord.GetValue(ANColIdx).ToString()));
                }
            }
        }
Пример #18
0
        protected DataTable FillOrder(object[] ids)
        {
            var table = new DbfTable();

            table.Columns(
                Column.Numeric("NUMZ", 8),
                Column.Date("DATEZ"),
                Column.Char("CODEPST", 12),
                Column.Numeric("PAYID", 2),
                Column.Date("DATE"),
                Column.Char("PODR", 40),
                Column.Numeric("QNT", 8),
                Column.Numeric("PRICE", 9, 2),
                Column.Char("PODRCD", 12),
                Column.Char("NAME", 80),
                Column.Numeric("XCODE", 20));                 // расширение протокола

            table.Row(
                Value.For("NUMZ", 2001),
                Value.For("DATEZ", DateTime.Now),
                Value.For("CODEPST", "135"),
                Value.For("PAYID", 1),                 // по колонке PRICE1 прайслиста
                Value.For("DATE", DateTime.Now),
                Value.For("PODR", "аптека"),
                Value.For("QNT", 1),
                Value.For("PRICE", 39.94),
                Value.For("PODRCD", "1"),
                Value.For("NAME", "АНАЛЬГИН АМП. 50% 2МЛ N10 РОССИЯ"),
                Value.For("XCODE", ids[0])
                );

            return(table.ToDataTable());
        }
Пример #19
0
        public void Should_dispose_stream()
        {
            const string fixturePath = "../../../../fixtures/dbase_30.dbf";

            var dbfTable = new DbfTable(fixturePath, Encoding.GetEncoding(1252));

            dbfTable.Stream.ShouldNotBeNull();

            dbfTable.Dispose();

            dbfTable.Stream.ShouldBeNull();
        }
Пример #20
0
        public void Should_dispose_memo()
        {
            const string fixturePath = "../../../../fixtures/dbase_30.dbf";

            var dbfTable = new DbfTable(fixturePath);

            dbfTable.Memo.ShouldNotBeNull();

            dbfTable.Dispose();

            dbfTable.Memo.ShouldBeNull();
        }
Пример #21
0
        public void Should_dispose_binary_reader()
        {
            const string fixturePath = "../../../../fixtures/dbase_30.dbf";

            var dbfTable = new DbfTable(fixturePath);

            dbfTable.BinaryReader.ShouldNotBeNull();

            dbfTable.Dispose();

            dbfTable.BinaryReader.ShouldBeNull();
        }
Пример #22
0
        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();
            }
        }
Пример #23
0
        public string GetInsertHeader(DbfTable dbfTable, string tableName)
        {
            // Create a string representing all the columns in the TABLE for our INSERT statement
            string columnPart = "";

            foreach (var dbfColumn in dbfTable.Columns)
            {
                columnPart += "[" + dbfColumn.Name + "],";
            }
            columnPart += "[IMPORTDETAILID]";

            // Create the first part of our INSERT statement
            return("INSERT INTO " + tableName + " (" + columnPart + ") VALUES ");
        }
Пример #24
0
 private void GetInvoiceList()
 {
     if (this.tabControl2.SelectedTab == this.tabIV)
     {
         this.iv_list          = new BindingList <ArtrnMin>(DbfTable.InvoiceList(this.data_path, this.status, DbfTable.INVOICE_TYPE.IV));
         this.dgvIV.DataSource = this.iv_list;
         this.tabIV.Text       = "  ขายเชื่อ (" + this.iv_list.Count.ToString() + ") <F6>  ";
     }
     else
     {
         this.hs_list          = new BindingList <ArtrnMin>(DbfTable.InvoiceList(this.data_path, this.status, DbfTable.INVOICE_TYPE.HS));
         this.dgvHS.DataSource = this.hs_list;
         this.tabHS.Text       = "  ขายสด (" + this.hs_list.Count.ToString() + ") <F7>  ";
     }
 }
Пример #25
0
        private void DialogCompanySelect_Load(object sender, EventArgs e)
        {
            this.dgv.ColumnHeadersDefaultCellStyle.BackColor          = Misc.MAIN_BG;
            this.dgv.ColumnHeadersDefaultCellStyle.SelectionBackColor = Misc.MAIN_BG;

            this.sccomp         = new BindingList <SccompVM>(DbfTable.Sccomp(this.main_form.secure_path).ToViewModel().OrderBy(sc => sc.compnam).ToList());
            this.dgv.DataSource = this.sccomp;

            if (this.sccomp.Count > 0)
            {
                this.dgv.Rows[0].Cells[this.col_compnam.Name].Selected = true;
                this.btnOK.Enabled     = true;
                this.btnSearch.Enabled = true;
            }
        }
Пример #26
0
        public ICollection <Location> GetAllFromDbf()
        {
            var locals            = new List <Location>();
            var coordinateRecords = new List <Tuple <int, int> >
            {
                new Tuple <int, int>(2, 3),
                new Tuple <int, int>(57, 58),
                new Tuple <int, int>(62, 63),
                new Tuple <int, int>(71, 72),
                new Tuple <int, int>(84, 85),
                new Tuple <int, int>(89, 90),
                new Tuple <int, int>(92, 93),
                new Tuple <int, int>(96, 97),
                new Tuple <int, int>(100, 101)
            };

            using var table = new DbfTable("Data/OD_2017.dbf", EncodingProvider.UTF8);

            var record = new DbfRecord(table);

            var personId = 1;

            while (table.Read(record))
            {
                foreach (var coordinate in coordinateRecords)
                {
                    try
                    {
                        if (record.Values[coordinate.Item1].GetValue() != null &&
                            record.Values[coordinate.Item2].GetValue() != null)
                        {
                            var x = (int)record.Values[coordinate.Item1].GetValue();
                            var y = (int)record.Values[coordinate.Item2].GetValue();

                            AddCoordinate(personId, x, y, locals);
                        }
                    }
                    catch
                    {
                    }
                }
                personId++;
            }

            return(locals);
        }
Пример #27
0
        public async Task <List <ExpandoObject> > ReadFoxTb(string file, Encoding encoding)
        {
            var tbdata      = new List <ExpandoObject>();
            var skipDeleted = true;

            using (var dbfTable = new DbfTable(file, encoding))
            {
                var columns   = dbfTable.Columns;
                var dbfRecord = new DbfRecord(dbfTable);

                while (dbfTable.Read(dbfRecord))
                {
                    if (skipDeleted && dbfRecord.IsDeleted)
                    {
                        continue;
                    }

                    var obj = new ExpandoObject();
                    foreach (var col in columns)
                    {
                        var val = dbfRecord.Values[col.Index].GetValue();
                        if (val == null)
                        {
                            ((IDictionary <string, object>)obj).Add(col.Name, null);
                        }
                        else if (col.ColumnType == DbfColumnType.Character)
                        {
                            ((IDictionary <string, object>)obj).Add(col.Name, (val ?? "").ToString().Trim());
                        }
                        else if (col.ColumnType == DbfColumnType.SignedLong)
                        {
                            ((IDictionary <string, object>)obj).Add(col.Name, Convert.ToInt32(val));  // (int)(long)
                        }
                        else
                        {
                            ((IDictionary <string, object>)obj).Add(col.Name, val);
                        }
                    }
                    tbdata.Add(obj);
                }
                dbfTable.Close();
            }
            return(tbdata);
        }
Пример #28
0
        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);
            }
        }
Пример #29
0
        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---");
            }
        }
Пример #30
0
        public string GetCreateTableScript(DbfTable tbl, string tableName)
        {
            throw new NotImplementedException();

            /*
             * string sql = "CREATE TABLE IF NOT EXISTS " + tableName + " (\n";
             * string cols = "";
             * foreach (var dbfColumn in tbl.Columns)
             * {
             *  if (cols != "") cols += ",\n";
             *  cols += GetColumnDefinition(dbfColumn.ColumnType, dbfColumn.Length, dbfColumn.Name);
             * }
             * cols += ", IMPORTDETAILID INT";
             *
             * sql += cols + "\n)";
             *
             * return sql;
             */
        }