public List <CovidResult> ReadRowAndReturnCovidResult(int row) { // This method Reads every row available and returns the results as a list of CovidResult Objects row++; string conuntry = ""; string province = ""; int counter = 0; List <CovidResult> listOfObjectsToReturn = new List <CovidResult>(); if (ws.Rows[row].Value2 != null) { foreach (var value in ws.Rows[row].Value2) { CovidResult newResult = new CovidResult(); // Assigns the Province/State value to be used for instanciating the CovidResult Object later if (value != null && counter == 0) { province = value.ToString(); } // Assigns the Country/Region value to be used for instanciating the CovidResult Object later else if (value != null && counter == 1) { conuntry = value.ToString(); } else if (value != null && value > 0 && counter > 1) { // Instaciates the newResult object of CovidResult to be added to the list of CovidResults, which will be returned newResult.countryRegion = conuntry; newResult.provinceState = province; newResult.numberOfRecovered = value.ToString(); newResult.recordDates = ws.Cells[1, counter + 1].Value; } counter++; if (newResult.countryRegion != null) { // Adds the object to the returning list of CovidResults -ONLY- if it does not contain null values listOfObjectsToReturn.Add(newResult); } } return(listOfObjectsToReturn); } else { return(listOfObjectsToReturn); } }
private void insertButton_Click(object sender, RoutedEventArgs e) { // Create new CovidResult Object to Add to the grid CovidResult newInsertedData = new CovidResult(); newInsertedData.countryRegion = countryRegionDropDown.Text; newInsertedData.provinceState = provinceTxt.Text ?? null; newInsertedData.recordDates = newRecordDate.DisplayDate; newInsertedData.numberOfRecovered = numberOfRecovered.Text; CovidDataGrid.Items.Add(newInsertedData); // After adding clear all the boxes clearBoxes(); // Scoll to the location where the information was added CovidDataGrid.ScrollIntoView(newInsertedData); }