public void ImportExcelTrawl() { String path = Server.MapPath(Request["file"]); if (File.Exists(path) == false) { die("File not found: " + path); } fileColums = GetFileColumns(path); mappedColumns = new Dictionary <string, uint>(); // resolve indicators Dictionary <uint, int> findicators = new Dictionary <uint, int>(); if (Request["indicators"] != null && Request["indicators"] != "") { String[] sindicators = Request["indicators"].Split('~'); foreach (String indicator in sindicators) { String[] indic = indicator.Split('|'); int indicatorID = int.Parse(indic[0]); uint column = fileColums[indic[1]]; findicators[column] = indicatorID; } } IWorkbook genericWB = WorkbookFactory.GetExcel2007Reader(path); IWorksheet genericWS = genericWB.Worksheets.GetWorksheetByIndex(0); for (uint r = genericWS.FirstRow + 1; r <= genericWS.LastRow; r++) { IRow row = genericWS.Rows.GetRow(r); String survey = GetCellValue(row, "fieldSurvey"); String cruise = GetCellValue(row, "fieldCruise"); String trawl = GetCellValue(row, "fieldTrawl"); String Station = GetCellValue(row, "fieldStation"); String sLatHour = GetCellValue(row, "sLatHour"); String sLatMin = GetCellValue(row, "sLatMin"); String sLonHour = GetCellValue(row, "sLonHour"); String sLonMin = GetCellValue(row, "sLonMin"); String eLatHour = GetCellValue(row, "eLatHour"); String eLatMin = GetCellValue(row, "eLatMin"); String eLonHour = GetCellValue(row, "eLonHour"); String eLonMin = GetCellValue(row, "eLonMin"); String comments = GetCellValue(row, "Comments"); int dateYear = int.Parse(GetCellValue(row, "dateYear")); int dateMonth = int.Parse(GetCellValue(row, "dateMonth")); int dateDay = int.Parse(GetCellValue(row, "dateDay")); double duration = double.Parse(GetCellValue(row, "Duration")); Dictionary <int, string> indicators = new Dictionary <int, string>(); foreach (uint col in findicators.Keys) { int indicator = findicators[col]; indicators[indicator] = GetCellValue(row, col); Response.Write("Row = " + r + ", Indicator: " + indicator + " = " + indicators[indicator] + "<br>"); } double lat1 = -ParseCoord(sLatHour, sLatMin); double lon1 = ParseCoord(sLonHour, sLonMin); double lat2 = -ParseCoord(eLatHour, eLatMin); double lon2 = ParseCoord(eLonHour, eLonMin); manSurveys sv = new manSurveys(); int nSurveyID = sv.GetSurveyID(2, survey); if (nSurveyID < 1) { die("Failed to create survey"); } manStations st = new manStations(); int nStationID = st.GetStationID(Station, lat1, lon1); if (nStationID < 1) { die("Failed to create station"); } manEvents ev = new manEvents(); ev.res = Response; int nEventID = ev.GetEventID(nSurveyID, nStationID, dateYear, dateMonth, dateDay, cruise, trawl, lat1, lon1, lat2, lon2, duration, comments, indicators); } Response.Write("cools!"); }
public void ImportExcelCatch() { String path = Server.MapPath(Request["file"]); if (File.Exists(path) == false) { die("File not found: " + path); } fileColums = GetFileColumns(path); mappedColumns = new Dictionary <string, uint>(); IWorkbook genericWB = WorkbookFactory.GetExcel2007Reader(path); IWorksheet genericWS = genericWB.Worksheets.GetWorksheetByIndex(0); for (uint r = genericWS.FirstRow + 1; r <= genericWS.LastRow; r++) { IRow row = genericWS.Rows.GetRow(r); String Cruise = GetCellValue(row, "catchCruise"); String Trawl = GetCellValue(row, "catchTrawl"); String Station = GetCellValue(row, "catchStation"); String Common = GetCellValue(row, "catchCommon"); String Genus = GetCellValue(row, "catchGenus"); String Species = GetCellValue(row, "catchSpecies"); String Abundance = GetCellValue(row, "catchAbundance"); String Biomass = GetCellValue(row, "catchBiomass"); String Description = GetCellValue(row, "catchDescription"); if (Abundance.Trim() == "") { Abundance = "0"; } if (Biomass.Trim() == "") { Biomass = "0"; } Response.Write(Common + " " + Genus + " " + Species + ": "); manSpecies ms = new manSpecies(); int species = ms.GetSpeciesID(Genus, Species, Common); if (species == 0) { Response.Write("Failed to add species"); } else { manEvents me = new manEvents(); int eventID = me.FindEventID(Cruise, Trawl, Station); if (eventID == 0) { die(String.Format("Event not found: {0}, {1}, {2}", Cruise, Trawl, Station)); } manEventSpecies mes = new manEventSpecies(); mes.addEventSpecies(eventID, species, double.Parse(Abundance), double.Parse(Biomass), Description); } Response.Write("<br>"); Response.Flush(); } }