The following code uses a text file as an input to a local SQL database by acting as if the text file is a table. But the problem here is that it is buggy given that using SQLEXecute
does not parse the data at all. This means that the table will not be created even if we use an actual text.
public void ParseRoutingFile()
{
using (StreamReader sr = new StreamReader(Engine.LIST_FILE_PATH + @"\ROUTING.TXT", Encoding.Default))
{
while (sr.Peek() >= 0)
{
string row = sr.ReadLine();
if (row != null)
{
string[] parts = row.Split(';');
if (parts.Length > 0)
{
// find records for the specific terminal
if (parts[0] == Engine.TerminalId)
{
string query = string.Format("INSERT INTO Routing (RId, Weeknum, Year, Days) " +
"VALUES ('{0}','{1}','{2}','{3}')",
parts[4].Trim(),
parts[1].Trim(),
parts[2].Trim(),
parts[3]
);
Engine.SqlExecute(query);
}
else continue;
}
}
}
}
}
At this point I just want to read the file without the fear of falling.
Now, the table should look like this for the user
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-0pky"></th>
<th class="tg-0pky">RID</th>
<th class="tg-0pky">Weeknum</th>
<th class="tg-0pky">Year</th>
<th class="tg-0pky">Days</th>
</tr>
<tr>
<td class="tg-0pky">□</td>
<td class="tg-0pky">11</td>
<td class="tg-0pky">45</td>
<td class="tg-0pky">2019</td>
<td class="tg-0pky">4</td>
</tr>
</table>