Tuesday, January 28, 2020

ManagedDbf Server


Anyone who can access or has given the right from a shared folder across the local area network environment can delete or replace a file, Dbf files residing  on file servers can face this dilemma, but what if we can access the Dbf  file using IP address and port No. as a replacement to pipe shared directory name... yes, the life of Dbf file  format can be extended more with secured access.

Early test on my Managed Dbf Server of course I'm using my Managed Network Library which I already use on my Multi-player Pac-Man  : )


string m_ConnectionErrorString = "";


//--> Connection string creation
//

MDbf.DbfConnectionString m_DbfConnectionString = new MDbf.DbfConnectionString"10.0.1.1", "2006", "admin", "password", "","","" );


//--> Opening Customer.dbf using connection string
//

MDbf.Table _CUSTOMER_tbl = new MDbf.Tablem_DbfConnectionString "CUSTOMER.DBF", out m_ConnectionErrorString );
//
if ( m_ConnectionErrorString != "" )
{
   MessageBox.Show("Unable to open CUSTOMER table on Managed Dbf Server! \r\n "+m_ConnectionErrorString);
   MDbf.CloseAll();
   return;
}


//--> Opening Salesman.dbf using the same connection string
//

MDbf.Table _SALESMAN_tbl = new MDbf.Table( m_DbfConnectionString, "SALESMAN.DBF", out m_ConnectionErrorString );
//
if ( m_OutConnectionErrorString != "" )
{  
   MessageBox.Show( "Unable to open SALESMAN table on Managed Dbf Server! \r\n "+m_ConnectionErrorString );
   MDbf.CloseAll();
   return;
}

// Wala' you now can use the tables just like you opened it locally.


Managed Dbf Records Navigation



TABLE NAVIGATOR


One strength of  dBase, Clipper, FoxPro and other xBase products is how easy it is to navigate on records or rows on a particular table, below are some familiar commands and functions on navigating on records, that we used to write to scan records without using any Sql statement which is sometimes much more efficient and fast with the combination of Find/Seek when searching a record with index key.

In Managed Dbf table navigation  methods can be access even in different threads, all table navigation methods are thread safe, but of course make sure you should know what you are doing when accessing navigation methods on other threads.

The following are xBase command and it's equivalent table's method in Managed Dbf on navigating records on table:



The GO | GOTO command : table.Navigator.GoTo(  long pRecordRowNo  ) 

Specifies table physical record's row number to which you move the row pointer; pRecordRowNo parameter is long in type since Managed Dbf can support more than 2G of file size.



The GO TOP  command : table.Navigator.GoTop( ) 

Positions the record's row pointer on the first row in the table. If the table has an ascending index in use, the first record row is the row with the lowest key value. If the index is in descending order, the first record row is the row with the highest key value.


The GO BOTTOM command : table.Navigator.GoBottom( ) 

Positions the record's row pointer on the last row in the table. If the table has an ascending index in use, the last record row is the row with the highest key value. If the index is in descending order, the last record row is the row with the lowest key value.


The SKIP command : table.Navigator.Skip( long pRecords  ) 

Specifies the number of records to move the record pointer. The record pointer moves toward the end of the file pRecords records if pRecords evaluates to a positive number. The record pointer moves toward the beginning of the file pRecords records if pRecords evaluates to a negative number.RecordNo()  returns a value 1 greater than the number of records in the table and EOF( ) returns true (true). If the record pointer is positioned on the first record of a table and Skip( –1) is executed, RecordNo()  returns 1 and IsBOF( ) returns true (true).


The BOF() function : table.Navigator.IsBOF()

Use IsBOF( ) to test for a beginning-of-file condition for a table. IsBOF( ) returns true (true) if you have tried to move the record pointer to a position before the first record in the table.


The EOF() function : table.Navigator.IsEOF() 

Use IsEOF() method to determines whether the record pointer is positioned past the last record in the current table.

IsEOF( ) returns true  if the record pointer reaches the end of the table file. The end of the table is reached when the record pointer passes the last record in the table. For example, when a Find, or Locate, is unsuccessful, Managed Dbf moves the record pointer past the last record, and IsEOF( ) returns true. IsEOF( ) returns false. if the record pointer isn't at the end of the table.


The RECNO() function : table.Navigator.RecordNo() 

RecordNo returns the current row number on which the record-row pointer is positioned.





Example of using table navigator :


MDbf.Table _CustomerTbl = new MDbf.Table();


//-->  Open table
//
_CustomerTbl.File.Open( @"C:\DataTest\Customer.Dbf",TableShare.Shared,TableAccess.ReadOnly );



//-->  Scan from top to 100
//
_CustomerTbl.Navigator.GoTop( )

//
while( ! _CustomerTbl.Navigator.IsEOF()  &&  _CustomerTbl.Navigator.RecordNo() <= 100 )
{
    Console.WriteLine( _CustomerTbl.Record.C("CUST_NAME") );

      _CustomerTbl.Navigator.Skip( 1 );
}



Console.readkey();
Console.clear();


//-->  Scan from 100 to top
//
_CustomerTbl.Navigator.GoTo( 100 );
//
while(  ! _CustomerTbl.Navigator.IsBOF()  )

{
   
Console.WriteLine( _CustomerTbl.Record.C("CUST_NAME") ); 

      _CustomerTbl.Navigator.Skip( -1 );
}



Console.readkey();
Console.clear();


//-->  Close table

//
_CustomerTbl.Close();