artistunknown
New member
- Joined
- Dec 15, 2011
- Messages
- 4
- Programming Experience
- 1-3
Well I have gotten this far on my own but i would lilke to make the program where I just update the master.txt instead changing everything if anyone knows a better way to make the PrintDetailLine() method that would be great here's the code
C#:
using System;
using System.IO;
using System.Text.RegularExpressions;
namespace GladRagsCompany
{
class Set
{
const string INPUTFILE = "C:\\MyProjects\\GladRagsCompany\\GladRagsCompany\\Master.txt";
const string OUTPUTFILE = "C:\\MyProjects\\GladRagsCompany\\GladRagsCompany\\Report.txt";
static uint pageCount = 1;
static uint maxDetailLines = 30;
static uint maxData = 45;
static string[] customerNumber = new string[100];
static StreamReader fileIn;
static StreamWriter fileOut;
static void Main()
{
if (OpenFiles())
{
InputValues();
PrintReportProgram();
}
CloseFiles();
Console.ReadKey();
}
static bool OpenFiles()
{
bool sucessOpeningFiles = true;
if (File.Exists(INPUTFILE))
{
fileIn = File.OpenText(INPUTFILE);
Console.WriteLine("{0} was opened", INPUTFILE);
}
else
{
Console.WriteLine("Error: {0} does not exist\n", INPUTFILE);
sucessOpeningFiles = false;
}
fileOut = File.CreateText(OUTPUTFILE);
if (File.Exists(OUTPUTFILE))
Console.WriteLine("{0} was created\n", OUTPUTFILE);
else
{
Console.WriteLine("Error: {0} could not be created\n", OUTPUTFILE);
sucessOpeningFiles = false;
}
return sucessOpeningFiles;
}
static void InputValues()
{
uint i;
string lineIn;
i = 0;
while ((lineIn = fileIn.ReadLine()) != null)
{
i++;
ParseLineIn(lineIn, i);
}
maxData = i;
}
static void ParseLineIn(string lineIn, uint i)
{
string[] words;
lineIn = lineIn.Trim();
while(Regex.IsMatch(lineIn,"[ ]{2}"))
lineIn = lineIn.Replace(" "," ");
words = lineIn.Split(' ');
customerNumber[i] = words[0];
}
static void PrintReportProgram()
{
ProcessThisRecord();
}
static void PrintPageHeadings()
{
fileOut.WriteLine();
fileOut.WriteLine(" GLAD RAGS CLOTHING COMPANY ");
fileOut.WriteLine(" CURRENT ACCOUNT BALANCES PAGE: {0}", pageCount);
fileOut.WriteLine("CUSTOMER CUSTOMER NAME CUSTOMER ADDRESS ACCOUNT");
fileOut.WriteLine("NUMBER BALANCE");
fileOut.WriteLine();
pageCount++;
}
static void ProcessThisRecord()
{
PrintDetailLine();
}
static void PrintDetailLine()
{
uint i = 1;
PrintPageHeadings();
for(i=1; i <= maxDetailLines; i++)
fileOut.WriteLine("{0,-15}", customerNumber[i]);
PrintPageHeadings();
for (i = 1; i <= maxData - maxDetailLines; i++)
fileOut.WriteLine("{0,-15}", customerNumber[i]);
}
static void CloseFiles()
{
fileIn.Close(); fileOut.Close();
}
}
}