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 57 58 59 60 61
|
public static void Main()
{
trame oTrame = new trame();
ITrame trameDAO = new TrameDAO();
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("trame.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
char[] sep = new Char[] { ',' };
string[] tab = line.Split(sep, 15);
if (tab[0].Equals("$GPRMC"))
{
Console.WriteLine("La trame est bien reçue");
oTrame.type_trame = tab[0];
oTrame.id_boitier = 1;
oTrame.heure = tab[1];
oTrame.validite = tab[2];
oTrame.latitude = float.Parse(tab[3].Replace(".",","));
oTrame.sens_latitude = tab[4];
oTrame.longitude = float.Parse(tab[5].Replace(".",","));
oTrame.sens_longitude = tab[6];
oTrame.vitesse = float.Parse(tab[7].Replace(".",","));
oTrame.cap = float.Parse(tab[8].Replace(".",","));
string sDate = tab[9];
System.Globalization.CultureInfo provider = System.Globalization.CultureInfo.InvariantCulture;
DateTime.ParseExact(sDate, "ddMMyy", provider);
Console.WriteLine(oTrame.date);
oTrame.checksum = tab[10];
try
{trameDAO.AjouterTrame(oTrame);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
else
{
Console.WriteLine("La trame est erronnée");
} |