using System.IO;
using System;
using blanco.sample.csv.io;
using blanco.sample.csv.record;

namespace blanco.sample.csv.io
{
    /// <summary>
    /// <newpara>blancoCsvDotNetのサンプルを試験するクラスです。</newpara>
    /// </summary>
    public class BlancoCsvSampleDotNetCsvTest
    {
        /// <summary>
        /// <newpara>エントリポイントです。</newpara>
        /// </summary>
        public static void Main(string[] args)
        {
            BlancoCsvSampleDotNetCsvWriter writer = new BlancoCsvSampleDotNetCsvWriter(
                new StreamWriter("test.txt", false, System.Text.Encoding.GetEncoding(932)));
            for (int index = 0; index < 10; index++)
            {
                BlancoCsvSampleDotNetCsvRecord record = new BlancoCsvSampleDotNetCsvRecord();
                record.SetField1("値その" + index);
                record.SetField2("1234");
                record.SetField3(index);
                record.SetField4(index);
                record.SetField5(DateTime.Now);
                writer.WriteRecord(record);
            }
            writer.Flush();
            writer.Close();

            BlancoCsvSampleDotNetCsvReader reader = new BlancoCsvSampleDotNetCsvReader(
                new StreamReader("test.txt", System.Text.Encoding.GetEncoding(932)));
            for (;;)
            {
                BlancoCsvSampleDotNetCsvRecord record = reader.ReadRecord();
                if (record == null)
                {
                    break;
                }
                Console.WriteLine("行を読み込みました。");
                Console.WriteLine(record.GetField1());
                Console.WriteLine(record.GetField2());
                Console.WriteLine(record.GetField3());
                Console.WriteLine(record.GetField4());
                Console.WriteLine(record.GetField5());
            }
            reader.Close();
        }
    }
}
