public void ClearOurDataList() { OurDataList.Clear(); }
public void PopulateOurDataList(FileInfo ourFileInfo) { // Validate input exists if (!ourFileInfo.Exists) { throw new ArgumentException( "The file name given to populate our data list doesn't exist.", "ourFileInfo", new Exception( string.Format("Given File for Our Data: {0}", ourFileInfo))); } using (var sl = new SLDocument(ourFileInfo.FullName)) { #if true var OurDataCells = sl.GetCells(); var sharedStrings = sl.GetSharedStrings(); // Gather the headers OurHeaders.Clear(); var row = OurDataCells[1]; for (int i = 1; i <= row.Count; i++) { var cell = row[i]; OurHeaders.Add( ConvertCellToString( cell, sharedStrings) .Trim() .ToUpper()); } OurDataList.Clear(); for (int i = 2; i < OurDataCells.Count; i++) { OurDataList.Add(ConvertCellsToOurData(i, OurDataCells, sharedStrings)); } #else var headerIndex = 1; var row = 2; var value = sl.GetCellValueAsString(1, headerIndex); var header = new List <string>(); // Gather all the headers while (!string.IsNullOrWhiteSpace(value)) { header.Add(value.Trim().ToUpper()); value = sl.GetCellValueAsString(1, ++headerIndex); } OurHeaders = new List <string>(header); // Validate headers match expected values if (header.Count < 3 || string.Compare(header[0], "id", true) != 0 || string.Compare(header[1], "name", true) != 0 || string.Compare(header[2], "TrackingID", true) != 0) { throw new Exception( string.Format( "Failed to read Our Data file because the format didn't match. Header Format in file: {0}", string.Join(",", header))); } while (!string.IsNullOrWhiteSpace(sl.GetCellValueAsString(row, 1))) { var element = new OurNameAndTrackingIdData(); element.ID = sl.GetCellValueAsInt32(row, 1); element.Name = sl.GetCellValueAsString(row, 2).ToUpper().Trim(); // For our purposes, a NULL string is effectively am empty string // we don't want to search for "NULL" in their data over and over again element.TrackingID = sl.GetCellValueAsString(row, 3).Replace("NULL", string.Empty).ToUpper().Trim(); OurDataList.Add(element); // Setup for next loop row++; } #endif } }