Tuesday, September 4, 2012

building software application

Tutorial on how to create complete installer for windows. In this tutorial, it will show on how to include .net framework 3.5(for window XP)
required software: visual studio 2008
1. Add new project. choose "other project types", "setup and deployment", "setup project".



2. add all exe and dll file into application folder
3. from .exe file, right click, "create shortcut to xxx.exe . cut this shortcut to user's desktop and user's programs menu
4.right click on  project, click properties.
5. Click on "Prerequisites". Choose Crystal report basics for visual studio 2008(x86,x64) and "microsoft visual studio 2008 report viewer". Choose Download prerequisites from the same location as my application. Click ok.


6. At last, click build. Done.

Thursday, May 10, 2012

Bind Datatable with Database


Recently research on datatable bind with database.  Those programmers are brilliant to create binding method.
Let’s see how to use it.

database structure:
CREATE TABLE  testdecimal (
  `c1` decimal(10,8) DEFAULT NULL,
  `c2` decimal(10,8) DEFAULT NULL,
  `id` double NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

insert some data to test


code look like this:

MySqlConnection conn = new MySqlConnection();
            conn.ConnectionString = "server=testbed-pc;user id=root;password=123;Database=test;charset=utf8;";
            try
            {
                MySqlDataAdapter da = new MySqlDataAdapter();
                da.SelectCommand = new MySqlCommand("select * from testdecimal where c1 =10", conn);
                MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
                da.Fill(testdecimal);
                while (i < testdecimal.Rows.Count)
                {
                    testdecimal.Rows[i]["c2"] = 2 + i ;
                    i++;
                }
                da.Update(testdecimal);
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
                conn.Close();
            }
            finally
            {
                conn.Close();
            }


when execute, all rows with c1 =10 updated! database update successfully! fast and convenient way!

Saturday, April 7, 2012

Import csv file to MySql Database


Recently looking for ways to Import data from csv file to MySql database. Mysql  database has powerful feature that allows user to import csv file directly to database. Sample code shows below:

create table statement:
DROP TABLE IF EXISTS `share_market`.`klse`;
CREATE TABLE  `share_market`.`klse` (
  `dates` date DEFAULT NULL,
  `opens` decimal(10,4) DEFAULT '0.0000',
  `highs` decimal(10,4) DEFAULT '0.0000',
  `lows` decimal(10,4) DEFAULT '0.0000',
  `closes` decimal(10,4) DEFAULT '0.0000',
  `volumn` decimal(20,4) DEFAULT '0.0000'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


command to import csv file:
LOAD DATA LOCAL INFILE 'd:\klci analysis.csv'
into table klse
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(dates, opens, highs,lows,closes, volumn);

where table name is "klse", field name is "dates", "opens", "highs","lows","closes" and  "volumn"
Use "s" for each field to avoid reserve word "open" and "close"

Tuesday, April 3, 2012

Float, Double and Decimal

There are many ways to store number value. Let’s pick three variable types of numbers that we always use: float, double and decimal. What are those differences?


decimal dd = 1234567890.123456789712345678971234567897M;

            double db = Convert.ToDouble(dd) * 1;
            float fl = (float)dd * 1;
            decimal dc = dd * 1;
            txtdecimal.Text = dc.ToString("f20");
            txtdouble.Text = db.ToString("f20");
            txtfloat.Text = fl.ToString("f20");


result:


1. float able to store 7 digit precision
2. double can store 16 digit precision
3. decimal can store up to 27 digit precision -> this is a surprise. even decimal can be out of range with less then 30 digit precision!

Currently I am researching on OpenCL and OpenCL allows ONLY double and float variable. Therefore graphic card is not suitable for task that requires high precision. OpenCL is more suitable for simulation or mass calculation like CAD CAM tools. Will update more information on OpenCL + c# when research is done.



Wednesday, March 28, 2012

DataTable vs List


  Recently just make in depth research about DataTable. DataTable is easy to use variable which allows user to pool data into it with consistence format, embed with other properties that allow us to do sorting, search etc. Currently I am researching on high performance application, which need to store large amount of data into memory. Soon I hit a bottleneck with DataTable. When inserting more than 5 million of records into DataTable, my desktop starts to struggle, even with 5G Ram So I need to find an alternative.

  The main purpose of my tool  is analyzing large amount of data. It uses to compare ID and do heavy calculation on selected field. After do some research, I found list can on par with DataTable’s needed function, at the same time increase efficiency.
So lets prove it!

DataTable button click event
private void button3_Click(object sender, EventArgs e)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            DataTable dt = new DataTable();
            dt.Columns.Add("a");
            dt.Columns.Add("b");
            dt.Columns.Add("c");
            dt.Columns.Add("d");
            dt.Columns.Add("e");
            long i = 0;
            while (i < 1000000)
            {
                dt.Rows.Add("a" + i.ToString(),"b" + i.ToString(), "c" + i.ToString(), "d" + i.ToString(), "e" + i.ToString());
                i++;
            }
            stopwatch.Stop();
            MessageBox.Show(stopwatch.Elapsed.TotalMilliseconds.ToString());
        }

List button click event
private void button4_Click(object sender, EventArgs e)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            List<List<lst>> lists = new List<List<lst>>();
            long i = 0;
            while (i < 1000000)
            {
                List<lst> list = new List<lst>();
                lst superlist = new lst
                {
                    field1 = "a" + i.ToString(),
                    field2 = "b" + i.ToString(),
                    field3 = "c" + i.ToString(),
                    field4 = "d" + i.ToString(),
                    field5 = "e" + i.ToString()
                };
                lists.Add(list);
                i++;
            }
            stopwatch.Stop();
            MessageBox.Show(stopwatch.Elapsed.TotalMilliseconds.ToString());
        }
        class lst
        {
            public string field1 { get; set; }
            public string field2 { get; set; }
            public string field3 { get; set; }
            public string field4 { get; set; }
            public string field5 { get; set; }         
        }

Benchmark result:
datatable memory usage


list memory usage


time taken in milisecond, for DataTable

time taken in milisecond, for List

List is 4X faster then datatable
DataTable uses 6X more memory then list

Conclusion:
there are some performance tweak can be done on source code.