/// <summary> /// This adds the equipment to the first list in the base list /// </summary> /// <param name="processing"></param> internal void addEquipment(Processing processing, DataTransfer dataTransfer) { //creates list List <string> sublistU = new List <string>(); //adds the laser user to the list sublistU.Add(processing.CurrentLine[processing.headingPostitions.EquipmentPosition]); //adds the entry if (dataTransfer.commercial) { processing.projectListC[dataTransfer.posProjectC].UseageList.Add(sublistU); } else { processing.projectList[dataTransfer.posProject].UseageList.Add(sublistU); } }
/// <summary> /// Sorts data by project /// </summary> /// <param name="length"></param> /// <param name="pos"></param> /// <param name="input"></param> /// <param name="formObject"></param> /// <param name="k"></param> internal void writeEntry(int length, int pos, string input, Processing formObject, int k) { Processing processing = formObject; //tests whether the heading positions have been found yet if (processing.headingsRead == false) { //reads heading positions findHeadingPostitons(processing.CurrentLine, processing); //marks the tracking variable as complete processing.headingsRead = true; } //Otherwise proceeds to enter data else { projectEntry(processing); equipmentEntry(processing); } }
/// <summary> /// adds the equipment useage data specifically /// </summary> /// <param name="processing"></param> private void equipmentEntry(Processing processing) { //sets the position for equipment by the length of the existing list posEquipment = processing.equipmentList.Count - 1; //tests whether the current equipment exists testExist.testExistingEquipmentList(processing, this); //if not adds the equipment to the list if (addE) { addData.addEquipmentList(processing, this); } //adds the hours addData.addEquipmentListHours(processing, this); //resets the variables posEquipment = 1; addE = true; }
/// <summary> /// Tests if the project already exists /// </summary> /// <param name="processing"></param> internal void testExistingProject(Processing processing, DataTransfer dataTransfer) { //tests whether project is commercial or not if (processing.CurrentLine[processing.headingPostitions.CommercialPosition] == "Commercial") { dataTransfer.commercial = true; } else { dataTransfer.commercial = false; } //if it is commercial if (dataTransfer.commercial) { //look for an existing project with the same name for (int i = 0; i < processing.projectListC.Count; i++) { if (processing.CurrentLine[processing.headingPostitions.ProjectPosition] == processing.projectListC[i].ProjectName) { //if so tell it not to add project and record the position of the project dataTransfer.add = false; dataTransfer.posProjectC = i; } } } else { for (int i = 0; i < processing.projectList.Count; i++) { if (processing.CurrentLine[processing.headingPostitions.ProjectPosition] == processing.projectList[i].ProjectName) { dataTransfer.add = false; dataTransfer.posProject = i; } } } }
/// <summary> /// initialises stream, then calls functions to write the different project sections /// </summary> /// <param name="processing"></param> /// <param name="form1"></param> internal void initialiseStream(Processing processing, Form1 form1) { //initialises the file path to save the processed file string filePath = form1.textBoxOutputLoc.Text + "\\Photon Factory Usage " + form1.textBox_Period.Text + ".csv"; using (StreamWriter output = new StreamWriter(filePath)) { //writes the header header(form1, output); //write the number of hours either academic or commercial academicCommercial(processing, output); //writes out the academic projects academicProjectsDW(processing, output); //writes out the commercial projects commercialProjectDW(processing, output); //writes out the equipmwnt useage equipmentUseage(processing, output); } }
/// <summary> /// Adds the hours at the specified position by posUser and posEquipment /// </summary> /// <param name="processing"></param> internal void addHours(Processing processing, DataTransfer dataTransfer, TestExist testExist) { //calculates hours float hours = dataTransfer.hoursCalc(processing); //test if there is already an entry at posUser,posEquipment testExist.testHourPosExists(processing, dataTransfer); //adds the hours variable to that given point hours = dataTransfer.sumHours(processing, hours); //sets the given coordinate to the hours output if (dataTransfer.commercial) { processing.projectListC[dataTransfer.posProjectC].UseageList[dataTransfer.posEquipment][dataTransfer.posUser] = Convert.ToString(hours); processing.commercialHour = processing.commercialHour + hours; } else { processing.projectList[dataTransfer.posProject].UseageList[dataTransfer.posEquipment][dataTransfer.posUser] = Convert.ToString(hours); processing.academicHours = processing.academicHours + hours; } }
/// <summary> /// Tests if given user entry already exists /// </summary> /// <param name="processing"></param> internal void testExistingUser(Processing processing, DataTransfer dataTransfer) { if (dataTransfer.commercial) { //iterates through the existing list matrix for (int i = 0; i < processing.projectListC[dataTransfer.posProjectC].UseageList[0].Count; i++) { //tests whether for a match, if so sets addU and stores user position if (processing.CurrentLine[processing.headingPostitions.LaserUserPosition] == processing.projectListC[dataTransfer.posProjectC].UseageList[0][i]) { dataTransfer.addU = false; dataTransfer.posUser = i; } } if (dataTransfer.addU) { dataTransfer.posUser = processing.projectListC[dataTransfer.posProjectC].UseageList[0].Count - 1; } } else { //iterates through the existing list matrix for (int i = 0; i < processing.projectList[dataTransfer.posProject].UseageList[0].Count; i++) { //tests whether for a match, if so sets addU and stores user position if (processing.CurrentLine[processing.headingPostitions.LaserUserPosition] == processing.projectList[dataTransfer.posProject].UseageList[0][i]) { dataTransfer.addU = false; dataTransfer.posUser = i; } } if (dataTransfer.addU) { dataTransfer.posUser = processing.projectList[dataTransfer.posProject].UseageList[0].Count; } } }
/// <summary> /// Writes out the commercial projects in the same grid as they are saved /// </summary> /// <param name="processing"></param> /// <param name="output"></param> private void commercialProjectDW(Processing processing, StreamWriter output) { output.WriteLine(); output.WriteLine("***COMMERCIAL PROJECTS***"); output.WriteLine(); foreach (var project in processing.projectListC) { string projectName = "---" + project.ProjectName + "---,"; output.WriteLine(projectName); foreach (var row in project.UseageList) { foreach (var column in row) { output.Write(column + ","); } output.WriteLine(); } output.WriteLine(); output.WriteLine(); output.WriteLine(); } }
/// <summary> /// writes out the number of hours and percent for academic and commercial /// </summary> /// <param name="processing"></param> /// <param name="output"></param> private void academicCommercial(Processing processing, StreamWriter output) { //calculates and writes total hours output.WriteLine(); float totalHours = processing.academicHours + processing.commercialHour; string totalHoursS = "Total Hours," + Convert.ToString(totalHours); output.WriteLine(totalHoursS); //calculates and writes academic hours and % string academicHoursS = "Academic Hours," + Convert.ToString(processing.academicHours); float academicHoursPercent = (processing.academicHours / totalHours) * 100; output.WriteLine(academicHoursS + "," + academicHoursPercent + "%"); //calculates and writes commercial hours and % string commercialHoursS = "Commercial Hours," + Convert.ToString(processing.commercialHour); float commercialHoursPercent = (processing.commercialHour / totalHours) * 100; output.WriteLine(commercialHoursS + "," + commercialHoursPercent + "%"); output.WriteLine(); output.WriteLine("***"); }
/// <summary> /// Writes out the academic projects in the same grid as they are saved /// </summary> /// <param name="processing"></param> /// <param name="output"></param> private void academicProjectsDW(Processing processing, StreamWriter output) { output.WriteLine(); output.WriteLine("***ACADEMIC PROJECTS***"); output.WriteLine(); foreach (var project in processing.projectList) { string projectName = "---" + project.ProjectName + "---,"; output.WriteLine(projectName); foreach (var row in project.UseageList) { foreach (var column in row) { output.Write(column + ","); } output.WriteLine(); } output.WriteLine(); output.WriteLine(); output.WriteLine(); } }
/// <summary> /// adds the equipment to the list /// </summary> /// <param name="processing"></param> /// <param name="dataTransfer"></param> internal void addEquipmentList(Processing processing, DataTransfer dataTransfer) { processing.equipmentList.Add(new Equipment(null)); processing.equipmentList[processing.equipmentList.Count - 1].EquipmentS[0] = processing.CurrentLine[processing.headingPostitions.EquipmentPosition]; }
/// <summary> /// Calculates the number of hours for a given bookinh /// </summary> /// <param name="formObject"></param> /// <returns></returns> internal float hoursCalc(Processing processing) { //variable positions initialised where xS denotes start, xF denotes finish, and x denotes sum int dayS; int dayF; int day; int monthS; int monthF; int month; int yearS; int yearF; int year; int hourS; int hourF; int hour; float minuteS; float minuteF; float minute; //total hours float hoursTotal; //variables customised to the position that the file stores data - this could perhaps be improved to be more automated int yearStart = 0; int yearLength = 4; int monthStart = 5; int otherLength = 2; int dayStart = 8; int hourStart = 13; int minuteStart = 16; //factor, how many hours in a given entry int yearFactor = 8760; float monthFactor = 730; int dayFactor = 24; int minuteInvFactor = 60; //reads length of each entry type yearS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(yearStart, yearLength)); yearF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(yearStart, yearLength)); year = yearF - yearS; monthS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(monthStart, otherLength)); monthF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(monthStart, otherLength)); month = monthF - monthS; dayS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(dayStart, otherLength)); dayF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(dayStart, otherLength)); day = dayF - dayS; try { hourS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(hourStart, otherLength)); minuteS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(minuteStart, otherLength)); } catch (System.FormatException) { hourS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(hourStart, otherLength - 1)); minuteS = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.StartPosition].Substring(minuteStart - 1, otherLength)); } try { hourF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(hourStart, otherLength)); minuteF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(minuteStart, otherLength)); } catch (System.FormatException) { hourF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(hourStart, otherLength - 1)); minuteF = Convert.ToInt32(processing.CurrentLine[processing.headingPostitions.FinishPosition].Substring(minuteStart - 1, otherLength)); } hour = hourF - hourS; minute = minuteF - minuteS; //sums total hours from all types hoursTotal = year * yearFactor + month * monthFactor + day * dayFactor + hour + minute / minuteInvFactor; //returns this return(hoursTotal); }