using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace PayRoll_Reader
{
static class Writer
{
public static void Write(ref Employee[] emps)
{
ToScreen(NumberOfDeparts(ref emps), NumberOfBranch(ref emps), NumberOfDivision(ref emps), ref emps);
}
static int[] NumberOfDeparts(ref Employee[] emps)
{
int[] DepartNums = new int[0]; // Make an array to hold all of the DIFFERENT department numbers
int departInt = 0; // Last Checked Department number
for (int i = 0; i < emps.Length; i++) // For how ever long that the employee array is
{
bool check = true; // is the value able to be added?
for (int j = i; j <= i; j++) //not sure but seems useless actually
{
if (departInt == emps[j].DepartNum) // if the last department Number is the same as the new one
{ //make it so that it is not added to the array
check = false;
}
}
if (check) //If our boolean is still true go and do stuff
{
int[] temp = new int[DepartNums.Length + 1]; //temporary array to make our array ever expanding
for (int k = 0; k < DepartNums.Length; k++) //run to the size of our original array
{
temp[k] = DepartNums[k]; //copy out original array values into our new temp
}
DepartNums = new int[temp.Length]; //increase the size of our original array by 1
for (int k = 0; k < DepartNums.Length; k++) //Run through it again
{
DepartNums[k] = temp[k]; //copy everything back
}
DepartNums[DepartNums.Length - 1] = emps[i].DepartNum; //Set the New open spot at the end of original Array to the depart num
departInt = emps[i].DepartNum; //Set out last checked and succeded departNum to the current one
}
}
return DepartNums; //Return the array
}
static int[] NumberOfBranch(ref Employee[] emps) //same as above just changes Variables
{
int[] BranchNums = new int[0];
int branchInt = 0;
for (int i = 0; i < emps.Length; i++)
{
bool check = true;
for (int j = i; j <= i; j++)
{
if (branchInt == emps[j].BranchNum)
{
check = false;
}
}
if (check)
{
int[] temp = new int[BranchNums.Length + 1];
for (int k = 0; k < BranchNums.Length; k++)
{
temp[k] = BranchNums[k];
}
BranchNums = new int[temp.Length];
for (int k = 0; k < BranchNums.Length; k++)
{
BranchNums[k] = temp[k];
}
BranchNums[BranchNums.Length - 1] = emps[i].BranchNum;
branchInt = emps[i].BranchNum;
}
}
return BranchNums;
}
static int[] NumberOfDivision(ref Employee[] emps) //same as above just changes Variables
{
int[] DivNums = new int[0];
int divInt = 0;
for (int i = 0; i < emps.Length; i++)
{
bool check = true;
for (int j = i; j <= i; j++)
{
if (divInt == emps[j].DivNum)
{
check = false;
}
}
if (check)
{
int[] temp = new int[DivNums.Length + 1];
for (int k = 0; k < DivNums.Length; k++)
{
temp[k] = DivNums[k];
}
DivNums = new int[temp.Length];
for (int k = 0; k < DivNums.Length; k++)
{
DivNums[k] = temp[k];
}
DivNums[DivNums.Length - 1] = emps[i].DivNum;
divInt = emps[i].DivNum;
}
}
return DivNums;
}
static void ToScreen(int[] Departs, int[] Branch, int[] Div, ref Employee[] emps)
{
double DepartTot = 0; //Depart Total
double DivTot = 0; //Div Total
double BranchTot = 0; //Branch Total
int TempLine = 0; //Temporary line place holder
int LastDepart = 0; //Last depart checked
int LastDiv = 0; //Last Div Checked
int LastBranch = 0; //Last Branch Checked
double FinalTot = 0; //Final Total
bool PrintDepart = false; //Print Department info
bool PrintDiv = false; //Print Division info
bool PrintBranch = false; //Pring branch info
StreamWriter write = new StreamWriter("report.dat"); //open the report.dat file for reading
Console.SetOut(write); //Set the output of the console to goto the file instead of the screen
// // // // //
Console.WriteLine("Branch Division Depart Employee Name GrossPay"); //Write out the top info
for (int i = 0; i < Branch.Length; i++) //For loop for Branch
{
for (int j = i; j < Div.Length; j++) //For loop for Division, starts at the current Branch Number
{
for (int k = j; k < Departs.Length; k++) //For loop for Departments starting at current Division Number
{
for (int l = k; l < emps.Length; l++) //For Loop to go through the employees starting at the department number
{
if (Branch[i] == emps[l].BranchNum && Div[j] == emps[l].DivNum && Departs[k] == emps[l].DepartNum) //if we haven't checked this one yet continue
{
if (LastDepart != emps[l].DepartNum) //if last department checked is not equal to the current employee department number
{
PrintDepart = true; // set print department to true
LastDepart= emps[l].DepartNum; // now set out last department checked to current
}
if (LastDiv != emps[l].DivNum) // same as above just with Division numbers
{
PrintDiv = true;
LastDiv = emps[l].DivNum;
}
if (LastBranch != emps[l].DivNum) //Same as above just with Branch numbers
{
PrintBranch = true;
LastBranch = emps[l].BranchNum;
}
TempLine += 1; //Templine +1
Console.Write(emps[l].BranchNum); //Writeout the branch num
addWhite(9 - emps[l].BranchNum.ToString().Length); //Add spaces to the next item of data
Console.Write(emps[l].DivNum); //
addWhite(9 - emps[l].DivNum.ToString().Length);
Console.Write(emps[l].DepartNum);
addWhite(9 - emps[l].DepartNum.ToString().Length);
Console.Write(emps[l].EmpFName);
addWhite(11 - emps[l].EmpFName.Length);
Console.Write(emps[l].EmpLName);
addWhite(11 - emps[l].EmpLName.Length);
Console.Write(emps[l].GrossPay.ToString("c") + Console.Out.NewLine);
DepartTot += emps[l].GrossPay;
}
}
if (PrintDepart)
{
TempLine += 2;
Console.Write(Console.Out.NewLine);
addWhite(30);
Console.Write("Depart Total");
addWhite(7);
Console.Write(DepartTot.ToString("c") + Console.Out.NewLine);
TempLine += 1;
PrintDepart = false;
DivTot += DepartTot;
Console.Write(Console.Out.NewLine);
DepartTot = 0;
}
}
if (PrintDiv)
{
TempLine += 2;
addWhite(28);
Console.Write("Division Total");
addWhite(7);
Console.Write(DivTot.ToString("c") + Console.Out.NewLine);
TempLine += 1;
Console.Write(Console.Out.NewLine);
PrintDiv = false;
BranchTot += DivTot;
DivTot = 0;
}
}
if (PrintBranch)
{
TempLine += 2;
addWhite(30);
Console.Write("Branch Total");
addWhite(7);
Console.Write(BranchTot.ToString("c") + Console.Out.NewLine);
TempLine += 1;
PrintDiv = false;
FinalTot += BranchTot;
Console.Write(Console.Out.NewLine);
BranchTot = 0;
}
}
write.Close();
}
static void addWhite(int amntSpace)
{
for (int i = 0; i < amntSpace; i++)
{
Console.Write(" ");
}
}
}
}