Changeset e0cdea2 for FarmatikoServices/Services/ProcessJSONService.cs
- Timestamp:
- 02/08/21 16:39:25 (4 years ago)
- Branches:
- master
- Children:
- 8eb1e21, dae4cde
- Parents:
- 0a694bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/ProcessJSONService.cs
r0a694bb re0cdea2 1 using FarmatikoData.FarmatikoRepoInterfaces; 2 using FarmatikoData.Models; 3 using System.Collections.Generic; 1 using FarmatikoData.Models; 4 2 using Newtonsoft.Json; 5 3 using Newtonsoft.Json.Linq; … … 13 11 using OfficeOpenXml; 14 12 using System.IO; 15 using Microsoft.VisualBasic; 13 using GemBox.Spreadsheet; 14 using System.Text; 16 15 17 16 namespace FarmatikoServices.Services … … 28 27 } 29 28 //Excel reader 30 private async Task<bool> ReadPharmaciesFromExcel(string Path) 31 { 32 using (var package = new ExcelPackage(new FileInfo(Path))) 33 { 34 var Sheet = package.Workbook.Worksheets[1]; 35 for (int i = 2; i < Sheet.Dimension.End.Row; ++i) 36 { 37 Pharmacy pharmacy = new Pharmacy() 29 private bool ReadPharmaciesFromExcel(string Path) 30 { 31 string path = Directory.GetCurrentDirectory() + @"\ExcellDocs\1.xlsx"; 32 33 FileInfo fileInfo = new FileInfo(path); 34 if (fileInfo != null) 35 { 36 using (var package = new ExcelPackage(fileInfo)) 37 { 38 var Sheet = package.Workbook.Worksheets.First(); 39 //var table = Sheet.Tables.First(); 40 int rowCount = Sheet.Dimension.End.Row; 41 for (int i = 2; i < rowCount; ++i) 38 42 { 39 Name = Sheet.Cells[i, 2].Value.ToString(), 40 Address = Sheet.Cells[i, 3].Value.ToString(), 41 Location = Sheet.Cells[i, 4].Value.ToString(), 42 WorkAllTime = false 43 }; 44 await _service.AddPharmacy(pharmacy); 43 //Console.WriteLine(); 44 Pharmacy pharmacy = new Pharmacy() 45 { 46 Name = Sheet.Cells[i, 2].Value.ToString(), 47 Address = Sheet.Cells[i, 3].Value.ToString(), 48 Location = Sheet.Cells[i, 4].Value.ToString(), 49 WorkAllTime = false 50 }; 51 _service.AddPharmacy(pharmacy); 52 } 45 53 return true; 46 54 } 47 } 55 56 } 57 48 58 return false; 49 } 50 public async void DownloadPharmaciesExcel() 59 60 } 61 public void DownloadPharmaciesExcel() 51 62 { 52 63 try … … 56 67 string pathToSave2 = Directory.GetCurrentDirectory() + @"\ExcellDocs\2.xlsx"; 57 68 var client = new WebClient(); 58 string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx";59 string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";69 string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/4806b744-f6f6-42d0-b0f0-d82e66d3b177/download/-.xlsxs"; 70 /*string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";*/ 60 71 Uri uri1 = new Uri(url1); 61 Uri uri2 = new Uri(url2);62 client.DownloadFile (uri1, @pathToSave1);63 client.DownloadFile(uri2, @pathToSave2);64 65 66 bool Success = awaitReadPharmaciesFromExcel(pathToSave1);72 //Uri uri2 = new Uri(url2); 73 client.DownloadFileAsync(uri1, pathToSave1); 74 //client.DownloadFile(uri2, @pathToSave2); 75 76 77 bool Success = ReadPharmaciesFromExcel(pathToSave1); 67 78 _logger.LogInformation(Success.ToString() + "1"); 68 Success = await ReadPharmaciesFromExcel(pathToSave2);69 _logger.LogInformation(Success.ToString() + "2"); 70 } 71 catch (Exception e) 72 { 73 _logger.LogInformation(e.Message); 74 throw new Exception("Cannot process Medicines from Excel.");79 /* Success = await ReadPharmaciesFromExcel(pathToSave2); 80 _logger.LogInformation(Success.ToString() + "2");*/ 81 } 82 catch (Exception e) 83 { 84 _logger.LogInformation(e.Message); 85 throw new Exception("Cannot process Pharmacies from Excel."); 75 86 } 76 87 }
Note:
See TracChangeset
for help on using the changeset viewer.