} // end onFinished private bool CheckForGraphReports() { List <ReportsDO> selReports = bslyr.GetSelectedReports(); int nthRow = selReports.FindIndex( delegate(ReportsDO r) { return(r.ReportID.Substring(0, 2) == "GR"); }); if (nthRow >= 0) { return(true); } else { return(false); } } // end CheckForGraphReports
} // end onFile private void onButton1Click(object sender, EventArgs e) { CPbusinessLayer bslyr = new CPbusinessLayer(); bslyr.DAL = DAL; if (this.DAL_V3 != null) { bslyr.DAL_V3 = this.DAL_V3; }//end if if (whichProcess == 1) // equations { VolumeEquations volEqObj = new VolumeEquations(); volEqObj.bslyr.fileName = fileName; volEqObj.bslyr.DAL = DAL; if (this.DAL_V3 != null) { volEqObj.bslyr.DAL_V3 = DAL_V3; }//end if if (templateFlag == 0) { int nResult = volEqObj.setupDialog(); if (nResult != -1) { volEqObj.ShowDialog(); } } else if (templateFlag == 1) { int nResult = volEqObj.setupTemplateDialog(); if (nResult == 1) { volEqObj.templateFlag = templateFlag; volEqObj.ShowDialog(); } // endif } // endif } else if (whichProcess == 2) // reports { // calls routine to add standard and regional reports List <ReportsDO> currentReports = new List <ReportsDO>(); if (templateFlag == 1) { bslyr.fileName = newTemplateFile; bslyr.DAL = new DAL(newTemplateFile); } else { bslyr.fileName = fileName; } // get all reports currentReports = bslyr.GetReports(); // and get the all reports array allReportsArray ara = new allReportsArray(); // then check for various conditions to know what to do with the reports list if (currentReports.Count == 0) { currentReports = ReportMethods.fillReportsList(); bslyr.SaveReports(currentReports); if (DAL_V3 != null) { bslyr.insertReportsV3(); } }//end if else if (currentReports.Count < ara.reportsArray.GetLength(0)) { // old or new list? Check title if (currentReports[0].Title == "" || currentReports[0].Title == null) { // old reports -- update list currentReports = ReportMethods.updateReportsList(currentReports, ara); bslyr.SaveReports(currentReports); } else { // new reports -- just add currentReports = ReportMethods.addReports(currentReports, ara); bslyr.SaveReports(currentReports); } // endif //if the reports are out of sync delete and refresh V3. if (DAL_V3 != null) { bslyr.insertReportsV3(); } } // endif // now get reports selected currentReports = ReportMethods.deleteReports(currentReports, bslyr); currentReports = bslyr.GetSelectedReports(); // Get selected reports ReportsDialog rd = new ReportsDialog(); rd.fileName = fileName; rd.bslyr.fileName = bslyr.fileName; rd.bslyr.DAL = bslyr.DAL; //add version 3 ref for saving back. rd.bslyr.DAL_V3 = bslyr.DAL_V3; rd.reportList = currentReports; rd.templateFlag = templateFlag; rd.setupDialog(); rd.ShowDialog(); } else if (whichProcess == 4) // output { // Pull reports selected bslyr.fileName = fileName; // See if volume has been calculated (sum expansion factor since those are calculated before volume) // July 2014 -- However it looks like expansion factors could be present but volume is not // need to pull calculated values as well and sum net volumes List <TreeDO> tList = bslyr.getTrees(); double summedEF = tList.Sum(t => t.ExpansionFactor); List <TreeCalculatedValuesDO> tcvList = bslyr.getTreeCalculatedValues(); double summedNetBDFT = tcvList.Sum(tc => tc.NetBDFTPP); double summedNetCUFT = tcvList.Sum(tc => tc.NetCUFTPP); if (summedEF == 0 && summedNetBDFT == 0 && summedNetCUFT == 0) { MessageBox.Show("Looks like volume has not been calculated.\nReports cannot be produced without calculated volume.\nPlease calculate volume before continuing.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // endif no volume for reports List <ReportsDO> selectedReports = bslyr.GetSelectedReports(); // no reports? let user know to go back and select reports if (selectedReports.Count == 0) { MessageBox.Show("No reports selected.\nReturn to Reports section and select reports.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // endif no reports // Show dialog creating text file TextFileOutput tfo = new TextFileOutput(); tfo.selectedReports = selectedReports; tfo.fileName = fileName; tfo.currRegion = currentRegion; tfo.bslyr = bslyr; tfo.setupDialog(); tfo.ShowDialog(); string outFile = tfo.outFile; int retrnState = tfo.retrnState; // Let user know the file is complete // This shows only when the Finished button is clicked // X-button click just closes the window if (retrnState == 0) { StringBuilder message = new StringBuilder(); message.Append("Text output file is complete and can be found at:\n"); message.Append(outFile); MessageBox.Show(message.ToString(), "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); processButton2.Enabled = true; processButton3.Enabled = true; processButton4.Enabled = true; processButton5.Enabled = true; processButton6.Enabled = true; return; } // endif } // endif whichProcess } // endif onButton1Click
public void CreateHTMLfile() { int[] eqTables = new int[4] { 0, 0, 0, 0 }; string outputFileName; string HTMLoutFile; // need list of reports selected to build index List <ReportsDO> reportsSelected = bslyr.GetSelectedReports(); // check for equation tables with records to output List <VolumeEquationDO> veList = bslyr.getVolumeEquations(); List <ValueEquationDO> vaList = bslyr.getValueEquations(); List <QualityAdjEquationDO> qaList = bslyr.getQualAdjEquations(); List <BiomassEquationDO> bsList = bslyr.getBiomassEquations(); if (veList.Count > 0) { eqTables[0] = 1; } if (vaList.Count > 0) { eqTables[1] = 1; } if (qaList.Count > 0) { eqTables[2] = 1; } if (bsList.Count > 0) { eqTables[3] = 1; } // fix the output filename outputFileName = System.IO.Path.ChangeExtension(fileName, "out"); // does it exist? if (!File.Exists(outputFileName)) { MessageBox.Show("Cannot create HTML file because the output file cannot be found.\nMake sure the output file has been created\nfor the current cruise file.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // endif if does not exist // create HTML filename HTMLoutFile = System.IO.Path.ChangeExtension(fileName, "html"); // need the index ArrayList HTMLindex = BuildTheIndex(eqTables, reportsSelected); // Output records from the output file using (StreamWriter strWriteOut = new StreamWriter(HTMLoutFile)) { // output index first foreach (object obj in HTMLindex) { strWriteOut.WriteLine(obj); } // Read/Write records from OUT file string line; string currentRecord; string currentReport = "**"; string previousReport = "**"; using (StreamReader strRead = new StreamReader(outputFileName)) { while ((line = strRead.ReadLine()) != null) { if (line == "\f") { // don't put "back to index"; just a new page strWriteOut.WriteLine(HTMLcommands[2]); } else if (line == "" || line == " ") { strWriteOut.WriteLine(line); } else if (line != "" && line != " ") { if (line.Contains("CRUISE REPORT HEADER")) { strWriteOut.WriteLine(HTMLcommands[3]); strWriteOut.WriteLine(line); } else if (line.Contains("VOLUME EQUATION TABLE")) { currentReport = "VOLUME EQUATION TABLE"; if (previousReport != currentReport) { strWriteOut.WriteLine(HTMLcommands[5]); previousReport = currentReport; strWriteOut.WriteLine(HTMLcommands[2]); } else { strWriteOut.WriteLine(HTMLcommands[2]); } currentRecord = HTMLcommands[4]; currentRecord = currentRecord.Replace("XXXX", "VolEq"); currentRecord = currentRecord.Replace("XX", "Volume Equation Table"); strWriteOut.WriteLine(currentRecord); strWriteOut.WriteLine(line); } else if (line.Contains("VALUE EQUATION TABLE")) { currentReport = "VALUE EQUATION TABLE"; if (previousReport != currentReport) { strWriteOut.WriteLine(HTMLcommands[5]); previousReport = currentReport; strWriteOut.WriteLine(HTMLcommands[2]); } else { strWriteOut.WriteLine(HTMLcommands[2]); } currentRecord = HTMLcommands[4]; currentRecord = currentRecord.Replace("XXXX", "ValEq"); currentRecord = currentRecord.Replace("XX", "Value Equation Table"); strWriteOut.WriteLine(currentRecord); strWriteOut.WriteLine(line); } else if (line.Contains("QUALITY ADJUSTMENT")) { currentReport = "QUALITY ADJUSTMENT EQUATION TABLE"; if (previousReport != currentReport) { strWriteOut.WriteLine(HTMLcommands[5]); previousReport = currentReport; strWriteOut.WriteLine(HTMLcommands[2]); } else { strWriteOut.WriteLine(HTMLcommands[2]); } currentRecord = HTMLcommands[4]; currentRecord = currentRecord.Replace("XXXX", "QAEq"); currentRecord = currentRecord.Replace("XX", "Quality Adjustment Equation Table"); strWriteOut.WriteLine(currentRecord); strWriteOut.WriteLine(line); } else if (line.Contains("BIOMASS EQUATION TABLE")) { currentReport = "BIOMASS EQUATION TABLE"; if (previousReport != currentReport) { strWriteOut.WriteLine(HTMLcommands[5]); previousReport = currentReport; strWriteOut.WriteLine(HTMLcommands[2]); } else { strWriteOut.WriteLine(HTMLcommands[2]); } currentRecord = HTMLcommands[4]; currentRecord = currentRecord.Replace("XXXX", "BiomassEq"); currentRecord = currentRecord.Replace("XX", "Biomass Equation Table"); strWriteOut.WriteLine(currentRecord); strWriteOut.WriteLine(line); } else if (line.Contains(':')) { // find out if this is a report int nthRow = reportsSelected.FindIndex( delegate(ReportsDO rdo) { return(rdo.ReportID == line.Substring(0, line.IndexOf(':'))); }); if (nthRow >= 0) { // it's definitely a report currentReport = reportsSelected[nthRow].ReportID; if (previousReport != currentReport) { strWriteOut.WriteLine(HTMLcommands[5]); previousReport = currentReport; strWriteOut.WriteLine(HTMLcommands[2]); } else { strWriteOut.WriteLine(HTMLcommands[2]); } currentRecord = HTMLcommands[4]; currentRecord = currentRecord.Replace("XXXX", currentReport); currentRecord = currentRecord.Replace("XX", currentReport); strWriteOut.WriteLine(currentRecord); strWriteOut.WriteLine(line); } else { strWriteOut.WriteLine(line); } } else { strWriteOut.WriteLine(line); } // endif line contains } // endif } // end while read } // end using read strWriteOut.WriteLine(HTMLcommands[5]); strWriteOut.WriteLine(HTMLcommands[6]); } // end using write // show user where it is StringBuilder sb = new StringBuilder(); sb.Append("HTML File has been created.\nIt can be found at:\n"); sb.Append(HTMLoutFile); MessageBox.Show(sb.ToString(), "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // end CreateHTMLfile
public void outputBannerPage(string fileName, StreamWriter strWriteOut, string currentDate, string currentVersion, string DLLversion, CPbusinessLayer bslyr) { int flagBLM = 0; // Data arrays for the banner page string[] bannerTitle = new string[2] { "CRUISE REPORT HEADER & CERTIFICATION", "CRUISE REPORT HEADER" }; string[] bannerYFD = new string[2] { "Year: yyyy Region: rr Forest: ff District: dd", "Year: yyyy Agency: BLM Forest: ff District: dd" }; string[] cruiseCertification = new string[17] { " **************************** CRUISE CERTIFICATION ****************************", "", " I certify that the timber for the XXXXXXXX timber sale", " has been designated and cruised by the procedures and standards in", " FSH 2409.12, Timber Cruising Handbook. Records of checks are on file", " at the District Ranger Office,", "", "", "", " ___________________ ___________________________________", " RANGER DISTRICT (name of headquarters town)", "", "", " ___________________ ______________", " DISTRICT RANGER DATE", "", " *****************************************************************************" }; string[] BLMcertification = new string[23] { " *************** B L M C R U I S E C E R T I F I C A T I O N ***************", " *******************************************************************************", "", " I certify that the timber for the XXXXXXXX timber sale", " has been cruised according to the procedures and standards set", " forth in the BLM Timber Cruising Handbook 5310-1.", "", "", "", "", " ___________________________ ___________________", " Principal Area Cruiser Date", "", "", " ___________________________ ___________________", " District Cruiser Appraiser Date", "", "", " ___________________________ ___________________", " Field Manager Date", "", " *****************************************************************************", " *****************************************************************************" }; string[] bannerFooter = new string[4] { "Developed and Maintained By:", "USDA FOREST SERVICE VERSION: ", "WASHINGTON OFFICE TIMBER MANAGEMENT VOLUME LIBRARY VERSION: ", "FORT COLLINS, COLORADO (970)295-5776 NATIONAL CRUISE PROCESSING PROGRAM" }; // open sale table List <SaleDO> saleList = bslyr.getSale(); // need to capture region and forest string currRegion = ""; string currForest = ""; foreach (SaleDO sl in saleList) { // Is this a BLM file? if (sl.Region == "7" || sl.Region == "07") { flagBLM = 1; } // Output header portion if (flagBLM == 1) { strWriteOut.WriteLine(bannerTitle[1]); } else { strWriteOut.WriteLine(bannerTitle[0]); } sb.Clear(); sb.Append("CRUISE#: "); sb.Append(sl.SaleNumber); sb.Append(" SALE#: "); sb.Append(sl.SaleNumber); strWriteOut.WriteLine(sb.ToString()); // save cruise "name" for later cruiseName = sl.SaleNumber; sb.Clear(); sb.Append("SALENAME: "); sb.Append(sl.Name); strWriteOut.WriteLine(sb.ToString()); // save salename for later saleName = sl.Name.TrimEnd(' '); sb.Clear(); sb.Append("RUN DATE & TIME: "); sb.Append(currentDate); strWriteOut.WriteLine(sb.ToString()); strWriteOut.WriteLine(" "); // Output remaining portion of upper left corner sb.Clear(); // replace fields as needed if (flagBLM == 1) { bannerYFD[flagBLM] = bannerYFD[flagBLM].Replace("yyyy", sl.CalendarYear.ToString()); bannerYFD[flagBLM] = bannerYFD[flagBLM].Replace("ff", sl.Forest.PadLeft(2, ' ')); bannerYFD[flagBLM] = bannerYFD[flagBLM].Replace("dd", sl.District.PadLeft(2, ' ')); strWriteOut.WriteLine(bannerYFD[flagBLM]); } else { bannerYFD[0] = bannerYFD[0].Replace("yyyy", sl.CalendarYear.ToString()); bannerYFD[0] = bannerYFD[0].Replace("rr", sl.Region.PadLeft(2, '0')); bannerYFD[0] = bannerYFD[0].Replace("ff", sl.Forest.PadLeft(2, ' ')); if (sl.District == "" || sl.District == " " || sl.District == null) { bannerYFD[0] = bannerYFD[0].Replace("dd", " "); } else { bannerYFD[0] = bannerYFD[0].Replace("dd", sl.District.PadLeft(2, ' ')); } strWriteOut.WriteLine(bannerYFD[0]); } // endif sb.Clear(); sb.Append("Remarks: "); sb.Append(sl.Remarks ?? (" ")); strWriteOut.WriteLine(sb.ToString()); currRegion = sl.Region; currForest = sl.Forest; } // end foreach loop sb.Clear(); sb.Append("FILENAME: "); sb.Append(fileName); strWriteOut.WriteLine(sb.ToString()); // Reports list List <ReportsDO> rList = bslyr.GetSelectedReports(); sb.Clear(); sb.Append("REPORTS: "); int numReports = 0; foreach (ReportsDO rd in rList) { numReports++; if (numReports <= 20) { sb.Append(rd.ReportID); sb.Append(" "); } else if (numReports == 21) { numReports = 0; strWriteOut.WriteLine(sb.ToString()); sb.Clear(); sb.Append(" "); sb.Append(rd.ReportID); sb.Append(" "); numReports++; } // endif } // end foreach loop // output BLM line if (flagBLM == 1) { // write reports line strWriteOut.WriteLine(sb.ToString()); sb.Clear(); sb.Append("VOLUME BASED ON "); // need volume equation type for BLM here List <VolumeEquationDO> vList = bslyr.getVolumeEquations(); int nthRow = vList.FindIndex( delegate(VolumeEquationDO ved) { return(ved.VolumeEquationNumber.Substring(3, 4) == "B32W"); }); if (nthRow >= 0) { sb.Append("32 "); } else { sb.Append("16"); } sb.Append(" FOOT EQUATIONS"); strWriteOut.WriteLine(sb.ToString()); } else { strWriteOut.WriteLine(sb.ToString()); } // Output note for Region 9 as to whether International or Scribner for board foot volume if (currRegion == "9" || currRegion == "09") { switch (currForest) { case "03": case "3": // Chippewa case "09": case "9": // Superior case "13": case "10": // Chequamegon-Nicolet and Hiawatha case "07": case "7": // Ottawa sb.Clear(); sb.Append("Scribner rule was used for board foot volumes shown in the selected reports."); break; case "04": case "4": // Huron-Manistee case "05": case "5": // Mark Twain case "08": case "8": // Shawnee case "12": case "14": // Hoosier and Wayne case "19": case "21": // Allegheny and Monongahela case "20": case "22": // Green Mountain/Finger Lakes and White Mountain sb.Clear(); sb.Append("International 1/4 inch rule was used for board foot volumes in the selected reports."); break; } // end switch strWriteOut.WriteLine(sb.ToString()); } // endif region 9 // Several blank lines now for (int k = 0; k < 6; k++) { strWriteOut.WriteLine(); } // Certification part if (flagBLM == 1) { for (int k = 0; k < 23; k++) { if (k == 3) { BLMcertification[k] = BLMcertification[k].Replace("XXXXXXXX", saleName); } strWriteOut.WriteLine(BLMcertification[k]); } // end for k loop } else { for (int k = 0; k < 17; k++) { if (k == 2) { cruiseCertification[k] = cruiseCertification[k].Replace("XXXXXXXX", saleName); } strWriteOut.WriteLine(cruiseCertification[k]); } // end for loop for certification } // endif // last portion for (int k = 0; k < 8; k++) { strWriteOut.WriteLine(); } strWriteOut.WriteLine(bannerFooter[0]); sb.Clear(); sb.Append(bannerFooter[1]); sb.Append(currentVersion); strWriteOut.WriteLine(sb.ToString()); sb.Clear(); sb.Append(bannerFooter[2]); sb.Append(DLLversion); strWriteOut.WriteLine(sb.ToString()); strWriteOut.WriteLine(bannerFooter[3]); } // end outputBannerPage