private bool ImportOffer(string filepath) { bool isOfferData = false; //Get all the info from the CSV file string[] data = File.ReadAllLines(filepath, Encoding.GetEncoding("iso-8859-1")); //Check if there are 8 columns for the Offers if (data[0].Split(';').Length == 8) { isOfferData = true; } if (isOfferData) { //Go through every row on the CSV file data after the headers (i=1) for (int i = 1; i < data.Length; i++) { string row = data[i]; //Get every column in that row string[] collumns = row.Split(';'); string offerId = collumns[0]; int routeNumber = int.Parse(collumns[1]); double price = double.Parse(collumns[2]); string contractorEmail = collumns[5]; Contractor contractor = ListOfContractors[contractorEmail]; int priority = 10; if (collumns[7] != "") { priority = int.Parse(collumns[7]); } Offer newOffer = new Offer(offerId, ListOfRoutes[routeNumber], price, contractor, priority); ListOfOffers.Add(newOffer); ListOfRoutes[routeNumber].AddToList(newOffer); } } if (ListOfOffers.Count <= 0) { isOfferData = false; } return(isOfferData); }
private bool ImportContractor(string filepath) { bool isContractorData = false; //Get all the info from the CSV file string[] data = File.ReadAllLines(filepath, Encoding.GetEncoding("iso-8859-1")); //Check if these are columns for the Contractor if (data[0].Split(';').Length == 9) { isContractorData = true; } if (isContractorData) { //Go through every row on the CSV file data after the headers (i=1) for (int i = 1; i < data.Length; i++) { string row = data[i]; //Get every column in that row string[] collumns = row.Split(';'); string number = collumns[0]; string name = collumns[1]; string companyName = collumns[2]; string email = collumns[3]; int type2 = int.Parse(collumns[4]); int type3 = int.Parse(collumns[5]); int type5 = int.Parse(collumns[6]); int type6 = int.Parse(collumns[7]); int type7 = int.Parse(collumns[8]); Contractor newContractor = new Contractor(number, companyName, name, email, type2, type3, type5, type6, type7); ListOfContractors.Add(email, newContractor); } } if (ListOfContractors.Count <= 0) { isContractorData = false; } return(isContractorData); }