1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FileHelpers;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FileHelperEngine engine = new FileHelperEngine(typeof(MyFile));
//lecture
MyFile[] result = engine.ReadFile("C:\\EVENT.DAT") as MyFile[];
DataTable table = new DataTable();
table.Columns.Add("Date", typeof(DateTime));
table.Columns.Add("Code", typeof(string));
table.Columns.Add("Message", typeof(string));
foreach (MyFile row in result)
{
Console.WriteLine(row.dob.ToString("d") + " " + row.code + "" + row.message);
table.Rows.Add(row.dob,row.code, row.message);
}
this.dataGridView1.DataSource = table;
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
[DelimitedRecord(" ")]
//[DelimitedRecord(" ")]
//[DelimitedRecord(" ")]
public class MyFile
{
[FieldConverter(ConverterKind.Date, "dd/MM/yyyy hh:mm:ss")]
public DateTime dob;
public string code;
public string message;
}
}
} |
Partager