Fixed Format


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using FileHelpers;

namespace outputToTxt
{
class quarterlyUnemployementReport
{
static string year;
static int fiscalQtr = 0;
static string qtrConvert;
static string fedEIN = "", okAccountNum = "";
static bool sRecord;
static string month1, month2, month3;
static string qtrTotalWages, qtrTaxableWages, uiTaxRate, qtrUITaxesDue;

public static string getYear()
{
string strYear;

Console.WriteLine("Enter the fiscal year to be processed:  ");
strYear = Console.ReadLine();

return strYear;
}

public static int getQuarter()
{
string quarterNum;
int numVal = 0;

Console.WriteLine("Enter the number of the quarter to be reported:(1,2,3,4)  ");
quarterNum = Console.ReadLine();
numVal = Convert.ToInt32(quarterNum);

return numVal;
}

public static string getQtrConvert(int quarterNum)
{
string convertQtr;

if(quarterNum == 1)
convertQtr = "03";
else if(quarterNum == 2)
convertQtr = "06";
else if(quarterNum == 3)
convertQtr = "09";
else
convertQtr = "12";

return convertQtr;
}

public static void getTotals()
{
Console.WriteLine("Enter Total Wages paid this quarter:  ");
qtrTotalWages = Console.ReadLine();
Console.WriteLine("Enter Taxable Wages paid this quarter:  ");
qtrTaxableWages = Console.ReadLine();
Console.WriteLine("Enter UI Tax Rate:  ");
uiTaxRate = Console.ReadLine();
Console.WriteLine("Enter State Quarter Taxes due:  ");
qtrUITaxesDue = Console.ReadLine();
}

public static bool getSRec()
{
bool sRecord = false;
string answer;

Console.WriteLine("Do you have Employee Records? (y/n)");
answer = Console.ReadLine();

if (answer == "y")
{
sRecord = true;
getMonthEmpTot();            }
else
sRecord = false;

return sRecord;
}

public static void getMonthEmpTot()
{

Console.WriteLine("Enter Number of Employees for month 1: ");
month1 = Console.ReadLine();
Console.WriteLine("Enter number of Employees for month 2: ");
month2 = Console.ReadLine();
Console.WriteLine("Enter number of Employees for month 3: ");
month3 = Console.ReadLine();

}

static void Main(string[] args)
{
year = getYear();
fiscalQtr = getQuarter();
qtrConvert = getQtrConvert(fiscalQtr);
getTotals();
sRecord = getSRec();

Console.WriteLine("Current year is  {0}", year);
Console.WriteLine("Current quarter: {0}", fiscalQtr);
Console.WriteLine("Quarter conversion is {0}", qtrConvert);
Console.WriteLine("FED Ein is: {0}", fedEIN);
Console.WriteLine("State account # is: {0}", okAccountNum);
Console.WriteLine("Are there employee records? {0}", sRecord);

if(sRecord == true)
Console.WriteLine("Employee numbers for month 1 are {0}; month 2 {1}; and month {2}", month1, month2, month3);

Console.ReadLine();

if (sRecord == true)
{

FileTransformEngine link = new FileTransformEngine(typeof(fromEmpRecords), typeof(toQtrReport));

link.TransformFile(@"C:\tmp\unemploymentRecordNEW.csv", @"c:\tmp\unemploymentRecordOut.txt");
}

tRecord();
eRecord();
}

[DelimitedRecord(",")]
private class fromEmpRecords
{
/*         public int qtrNumber;
public int taxLimit;
public int fedNum;
public int stateNum;
public string districtName;
public string districtNum;
public int countyNum;            */
public string ssn;
public string lastName;
public string firstName;
public string middleInital;
public string quarterWages;
public string taxableWages;

[TransformToRecord(typeof(toQtrReport))]
public toQtrReport Transform()
{
toQtrReport res = new toQtrReport();

res.lastName = lastName;
res.firstName = firstName;
res.middleInital = middleInital;
res.ssn = ssn;
res.quarterWages = quarterWages;
res.taxableWages = taxableWages;

return res;
}
}

// enters S records from input file
[FixedLengthRecord()]
private class toQtrReport
{
[FieldFixedLength(1)]
public string recType = "S";

[FieldFixedLength(9)]
[FieldAlign(AlignMode.Right, '0')]
public string ssn;               // need to check for 0 at beginning

[FieldFixedLength(20)]
public string lastName;

[FieldFixedLength(12)]
public string firstName;

[FieldFixedLength(1)]
public string middleInital;

[FieldFixedLength(2)]
public string stateCode = "40";

[FieldFixedLength(18)]
public string blank1 = null;

[FieldFixedLength(14)]
[FieldAlign(AlignMode.Right, '0')]
public string quarterWages;

[FieldFixedLength(14)]
public string blank2 = null;

[FieldFixedLength(14)]
[FieldAlign(AlignMode.Right, '0')]
public string taxableWages;

[FieldFixedLength(37)]
public string blank3 = null;

[FieldFixedLength(4)]
public string utax = "utax";

[FieldFixedLength(15)]
public string okAccountNum = quarterlyUnemployementReport.okAccountNum;

[FieldFixedLength(53)]
public string blank4 = null;

[FieldFixedLength(6)]
public string qtrYear = String.Concat(qtrConvert, year);

[FieldFixedLength(55)]
public string blank5 = null;
}

// append e record to output file
public static void eRecord()
{
string recordType = "E";
string blank1 = null;
string employerName = "";
string blank2 = null;
string rField = "R";
string blank3 = null;
string blank4 = null;
string utax = "UTAX";
string stateCode = "40";
string employeeRecords;
string blank5 = null;

if (sRecord == true)
employeeRecords = "1";
else
employeeRecords = "0";

StreamWriter Output = File.AppendText(@"");

string[] ArrERecord = {recordType, year, fedEIN, blank1, employerName, blank2, rField, blank3, blank4, utax, stateCode, okAccountNum, qtrConvert, employeeRecords, blank5 };
String fmt = "{0,1}{1,4}{2,9}{3,9}{4,-50}{5,86}{6,1}{7,2}{8,4}{9,4}{10,2}{11,-15}{12,2}{13,1}{14,85}";
Output.WriteLine(fmt, ArrERecord);
Output.Close();
}

// append T record to output file
public static void tRecord()
{
string recordType = "T";
string blank1 = null;
string blank2 = null;
string blank3 = null;
string blank4 = null;
string utax = "UTAX";
string blank5 = null;

int convertTotalEmp1 = Convert.ToInt32(month1);
int convertTotalEmp2 = Convert.ToInt32(month2);
int convertTotalEmp3 = Convert.ToInt32(month3);
int addTotalEmp = convertTotalEmp1 + convertTotalEmp2 + convertTotalEmp3;
string totalEmployees = Convert.ToString(addTotalEmp);

StreamWriter Output = File.AppendText(@"");

string[] ArrTRecord = { recordType, totalEmployees, utax, blank1, qtrTotalWages, blank2, qtrTaxableWages, blank3, uiTaxRate, qtrUITaxesDue, blank4, month1, month2, month3, blank5 };
String fmt = "{0,1}{1,7}{2,4}{3,14}{4,14}{5,14}{6,14}{7,13}{8,6}{9,13}{10,126}{11,7}{12,7}{13,7}{14,29}";
Output.WriteLine(fmt, ArrTRecord);
Output.Close();
}
}
}
Garland MacNeill

About Garland MacNeill

Garland is a full time Systems Analyst for a school district in Tulsa, OK. Currently Garland is working on the completion of his masters degree from Capella University in Enterprise Software Architecture. In addition to working full time and going to school, Garland is married to his High School sweetheart Aj. Some of Garland's outside interests include motorcycles, spending time with nature, and enjoying the family cabin in Northern WI. In addition, Garland is also a fan of the Green Bay Packers and an avid fan of the Colorado Avalanche. He also enjoys watching MotoGP racing.