Take great care over how you indent your code and errors will sometimes leap out at you.
For example look at the segment...
}
{
if (Row.Column0 == b)
{
BatchHeaderBuffer.AddRow();
}
- That random open brace { on a line by itself is not necessary, but importantly
Row.Column0
can never equal
b
because to get to this part of the code
Row.Column0 == a
. Check it out by debugging your code - this article will get you started
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
You are inconsistent in your structure - if the column == a you add a row then populate it in the same statement. But if it == b you only add a row and attempt to populate it outside the statement block ... which would just overwrite the previous values if the column != b. And thereby hangs your problem I believe - try putting the closing brace in the right place...
if (Row.Column0 == a)
{
FileHeaderBuffer.AddRow();
}
It's also a lot easier to follow the flow of your code if you break stuff out into subroutines ... for example all of those switch statements can be extracted out to subroutines e.g.
public override void UpdateFileHeader(string testString, string valueString)
{
switch (testString)
{
case "recordtypecode":
FileHeaderBuffer.recordtypecode = valueString;
break;
...etc.
Your
Input0_ProcessInputRow
then starts to look like...
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string a = "-- ChoETL.NACHA.ChoNACHAFileHeaderRecord State --".ToLower().Trim();
string b = "-- ChoETL.NACHA.ChoNACHABatchHeaderRecord State --".ToLower().Trim();
string c = "-- ChoETL.NACHA.ChoNACHAEntryDetailRecord State -- ".ToLower().Trim();
string d = "-- ChoETL.NACHA.ChoNACHAAddendaRecord State --".ToLower().Trim();
string e = "-- ChoETL.NACHA.ChoNACHABatchControlRecord State --".ToLower().Trim();
string f = "-- ChoETL.NACHA.ChoNACHAFileControlRecord State --".ToLower().Trim();
if (Row.Column0.ToLower().Trim() == a)
{
FileHeaderBuffer.AddRow();
}
UpdateFileHeader(Row.Column0.ToLower().Trim(), Row.Column1.Trim());
if (Row.Column0 == b)
{
BatchHeaderBuffer.AddRow();
}
UpdateBatchHeader(Row.Column0.ToLower().Trim(), Row.Column1.Trim());
if (Row.Column0 == c)
{
EntryDetailBuffer.AddRow();
}
UpdateEntryDetail(Row.Column0.ToLower().Trim(), Row.Column1.Trim());
if (testString == d)
{
AddendaRecordBuffer.AddRow();
}
UpdateAddendaRecord(Row.Column0.ToLower().Trim(), Row.Column1.Trim());
...etc
Now it becomes quite clear that you are attempting to update
each buffer for
every row in your file. You need to keep track of which "section" of the file you are processing and only call the
appropriate subroutine. For example (NB untested)
const string a = "-- ChoETL.NACHA.ChoNACHAFileHeaderRecord State --";
const string b = "-- ChoETL.NACHA.ChoNACHABatchHeaderRecord State --";
const string c = "-- ChoETL.NACHA.ChoNACHAEntryDetailRecord State -- ";
const string d = "-- ChoETL.NACHA.ChoNACHAAddendaRecord State --";
const string e = "-- ChoETL.NACHA.ChoNACHABatchControlRecord State --";
const string f = "-- ChoETL.NACHA.ChoNACHAFileControlRecord State --";
public override void Input0_ProcessInputRow(Input0Buffer Row, out section)
{
switch(Row.Column0.ToLower().Trim())
{
case a:
FileHeaderBuffer.AddRow();
section = 1;
return;
case b:
BatchHeaderBuffer.AddRow();
section = 2;
return;
case c:
EntryDetailBuffer.AddRow();
section = 3;
return;
case d:
AddendaRecordBuffer.AddRow();
section = 4;
return;
case e:
BatchControlBuffer.AddRow();
section = 5;
return;
case f:
FileControlBuffer.AddRow();
section = 6;
return;
default:
string col0 = Row.Column0.ToLower().Trim();
string col1 = Row.Column0.Trim();
switch case (section)
{
case 1:
UpdateFileHeader(col0,col1);
break;
case 2:
UpdateBatchHeader(col0, col1);
break;
case 3:
UpdateEntryDetail(col0,col1);
break;
case 4:
UpdateAddendaRecord(col0,col1);
break;
case 5:
UpdateBatchControl(col0,col1);
break;
case 6:
UpdateFileControl(col0,col1);
break;
}
}
}