private void ForParseIDxlsx(string filePath, ProductID productID) { var dataFromFile = GetRowSheetData(filePath); if (dataFromFile.Count() > 1) { int idIndex = 0; for (int i = 0; i < dataFromFile.First().ItemArray.Length; i++) { if (dataFromFile.First().ItemArray[i].ToString() == "Product ID") { idIndex = i; } } foreach (var row in dataFromFile) { productID.ProdID.Add(row[idIndex].ToString()); } } else { foreach (var row in dataFromFile) { productID.ProdID.Add(row[0].ToString()); } } }
private void ForParseIDcsv(string filePath, ProductID productID) { using (StreamReader reader = new StreamReader(filePath)) { var firstLine = reader.ReadLine().Split('|'); if (firstLine.Count() > 1) { int idIndex = 0; int makeIndex = 0; int modelIndex = 0; int yearsIndex = 0; for (int i = 0; i < firstLine.Length; i++) { switch (firstLine[i]) { case "Product ID": idIndex = i; break; case "Make": makeIndex = i; break; case "Model": modelIndex = i; break; case "Years": yearsIndex = i; break; } } while (!reader.EndOfStream) { if (productID.ProdIDMMY == null) { productID.ProdIDMMY = new HashSet <string>(); } var line = reader.ReadLine().Split('|'); productID.ProdID.Add(line[idIndex]); productID.ProdIDMMY.Add(line[idIndex] + '|' + line[makeIndex] + '|' + line[modelIndex] + '|' + line[yearsIndex]); } } else { while (!reader.EndOfStream) { var line = reader.ReadLine(); productID.ProdID.Add(line); } } } }
private ProductID ParsIDs(List <string> path) { message.MessageTriger("Чтение старых продукт айди..."); ProductID productID = new ProductID(); productID.ProdIDMMY = null; productID.ProdID = new HashSet <string>(); foreach (string filePath in path) { if (Path.GetExtension(filePath) == ".csv") { ForParseIDcsv(filePath, productID); } else if (Path.GetExtension(filePath) == ".xlsx") { ForParseIDxlsx(filePath, productID); } } return(productID); }