четверг, 18 октября 2012 г.

NEW DbfFieldType USING EVAL

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhitePage.Data;
namespace TestDbfRecord
{
  class Program
  {
    static void Main(string[] args)
    {
      //NEW DbfFieldType
      //USING  EVAL
      //create table
      List<DbfFieldInfo> fields = new List<DbfFieldInfo>();

      fields.Add( new DbfFieldInfo("nickname", DbfFieldType.Character ,100 ));
      fields.Add( new DbfFieldInfo("note", DbfFieldType.Memo, 0));
      fields.Add(new DbfFieldInfo("DT", 'D', 8, 0));
      fields.Add(new DbfFieldInfo("NUM", 'N', 6, 2));
      fields.Add(new DbfFieldInfo("LOGI", 'L', 1, 0));

      DbfFieldInfo field = new DbfFieldInfo();
      field = new DbfFieldInfo();
      field.Name = "note";
      field.Type = DbfFieldType.Memo;
      fields.Add(field);

      string file = AppDomain.CurrentDomain.BaseDirectory +"\\demo.dbf";
      using (DbfRecordset rs = DbfRecordset.Create(file, fields))
      {
        eval(rs, "iif(1+1 > 2 , .T. , .F.)");
        eval(rs, ".t. and .t.");
        eval(rs, ".t. .and. .t.");
        eval(rs, ".t. .or. .F.");
        eval(rs, "-1");
        eval(rs, "--1");
        eval(rs, "---1");
        eval(rs, "----1 + -2");
        eval(rs, "! .t. ");
        eval(rs, "not .t. ");
        eval(rs, ".not. .t. ");
        eval(rs, "'abc' == 'abc'");
        eval(rs, "'abc' == 'ab'");
        eval(rs, "'abc' > 'ab'");
        eval(rs, " 200.92 >= 1000.23433");
        eval(rs, " 200.92 != 1000.23433");
        eval(rs, " 'nick' $ 'i'");
        eval(rs, " 'i' $ 'nick'");
        eval(rs, "UPPER('qwerty')");
        eval(rs, "str(100.23) + str(12.34)");
        eval(rs, "'[' + str(12.344, 10) + ']'");
        eval(rs, "'[' + str(12.344, 10,2) + ']'");
        eval(rs, "right('1234567',3)");
        eval(rs, "left('1234567',3)");
        eval(rs, "QUARTER(CTOD('11/12/2012'),1)");
        eval(rs, "day(CTOD('11/12/2012'))");
        eval(rs, "month(CTOD('11/12/2012'))");
        eval(rs, "CTOD('11/12/2012')");
        eval(rs, "STOD('20120131')");
        eval(rs, "empty('20120131')");
        eval(rs, "empty('')");
        eval(rs, "trim(' rwytuwyrt   ')");
        eval(rs, "ltrim(' rwytuwyrt   ')");
        eval(rs, "alltrim(' rwytuwyrt   ')");
        eval(rs, "'[' + padR('123',10) + ']'");
        eval(rs, "'[' + padR('123',10,'W') + ']'");
        eval(rs, "'[' + padL('123',10) + ']'");
        eval(rs, "'[' + padL('123',10,'W') + ']'");
        eval(rs, "soundex('word')");
        eval(rs, "len('word')");
        eval(rs, "val('12.34')");
        eval(rs, "abs(-12.34)");
        Random ran = new Random(1000);
        int recCount = 10;
       
        for (int i = 1; i <= recCount; i++)
        {
          int id = ran.Next(0,1000);
          string nick = "Jon ID :" +  id.ToString();
          System.Diagnostics.Debug.Print(nick);
          rs.AddNew(); // append black
          rs["nickname"] = nick;
          rs.Update(); // commit changes
        }
        rs.ForEach(r =>
          {
            eval(r, "substr(nickname,2,2) + upper(nickname)");
            return false; // only once
          });
        rs.Close();
      }
    }
    static void eval(DbfRecordset rs, string expr)
    {
      object value = rs.Eval(expr);
      System.Diagnostics.Debug.Print( expr + " : " + value.ToString()  );
    }
  }
}

среда, 17 октября 2012 г.

USING MEMO (DBT) and ForEach

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhitePage.Data;

namespace TestDbfRecord
{
  class Program
  {
    static void Main(string[] args)
    {
      //USING  MEMO (DBT) and ForEach
      //create table
      List<DbFieldInfo> fields = new List<DbFieldInfo>();
      DbFieldInfo field = new DbFieldInfo();
      field.Name = "nickname";
      field.Type = 'C';
      field.Len = 100;
      fields.Add(field);
      field = new DbFieldInfo();
      field.Name = "note";
      field.Type = 'M';
      fields.Add(field);

      string file = AppDomain.CurrentDomain.BaseDirectory +"\\demo.dbf";
      using (DbfRecordset rs = DbfRecordset.Create(file, fields))
      {
        Random ran = new Random(1000);
        int recCount = 10;
       
        for (int i = 1; i <= recCount; i++)
        {
          int id = ran.Next(0,1000);
          string nick = "Jon ID :" +  id.ToString();
          System.Diagnostics.Debug.Print(nick);
          rs.AddNew(); // append black
          rs["nickname"] = nick;
          rs["note"] = @"
fsog[apiofsdug[ opiug oiuergpo
e prioue[u[etguo[ieutg[oitroieutoi ogjdf;lkjg;lkdsf
dsopfgih[posdi h[podigh[psodgih
sdgoih[posdgihpo";
          rs.Update(); // commit changes
        }
        rs.ForEach(r =>
          {
            System.Diagnostics.Debug.Print(rs["nickname"].ToString());
            System.Diagnostics.Debug.Print(rs["note"].ToString());
            return true;
          });
        rs.Close();
      }
    }
  }
}

First Demo Using Of DBF CDX.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhitePage.Data;
namespace TestDbfRecord
{
  class Program
  {
    static void Main(string[] args)
    {
      //create table
      List<DbFieldInfo> fields = new List<DbFieldInfo>();
      DbFieldInfo field = new DbFieldInfo();
      field.Name = "nickname";
      field.Type = 'C';
      field.Len = 100;
      fields.Add(field);
      field = new DbFieldInfo();
      field.Name = "dt";
      field.Type = 'D';
      fields.Add(field);

      string file = AppDomain.CurrentDomain.BaseDirectory +"\\demo.dbf";
      using (DbfRecordset rs = DbfRecordset.Create(file, fields))
      {
        rs.CreateIndex("inick", "nickname", null);
        rs.CreateIndex("idt", "dt", null);
        Random ran = new Random(1000);
        int recCount = 10;
       
        for (int i = 1; i <= recCount; i++)
        {
          int days = ran.Next(0,1000);
          string nick = "Jon:" +  days.ToString();
          System.Diagnostics.Debug.Print(nick);
          rs.AddNew(); // append black
          rs["nickname"] = nick;
          rs["dt"] = DateTime.Now.AddDays(days);
          rs.Update(); // commit changes
        }
        // aplay index tag inick - sorted by nickname
        rs.Index = "inick";
        System.Diagnostics.Debug.Print("--- sorted by nickname ----");
        rs.MoveFirst();
        while (!rs.Eof)
        {
          System.Diagnostics.Debug.Print(rs["nickname"].ToString());
          rs.MoveNext();
        }
        rs.Index = "idt"; // aplay index tag idt
        System.Diagnostics.Debug.Print("--- sorted by nickname ----");
        rs.MoveFirst();
        while (!rs.Eof)
        {
          System.Diagnostics.Debug.Print(rs["nickname"].ToString() + " " +  rs["dt"].ToString());
          rs.MoveNext();
        }
        rs.Close();
      }
    }
  }
}

вторник, 16 октября 2012 г.

New Life of DBF file format. First article.

Hello to everyone. I developed "dll" to work with dbf file format that allows you to work with dbf files without VFPOLEDB provider and now you dont need to use ODBC driver. This utility is perfectly works at x64 OS. For first 100 customers it will costs just 1$. You can download trial version of the product from site  http://baybaksoft.ucoz.com/index/0-29