Ignore:
Timestamp:
02/08/21 16:39:25 (3 years ago)
Author:
Dimitar Slezenkovski <dslezenkovski@…>
Branches:
master
Children:
8eb1e21, dae4cde
Parents:
0a694bb
Message:

Fix all bugs

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;
     1using FarmatikoData.Models;
    42using Newtonsoft.Json;
    53using Newtonsoft.Json.Linq;
     
    1311using OfficeOpenXml;
    1412using System.IO;
    15 using Microsoft.VisualBasic;
     13using GemBox.Spreadsheet;
     14using System.Text;
    1615
    1716namespace FarmatikoServices.Services
     
    2827        }
    2928        //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)
    3842                    {
    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                    }
    4553                    return true;
    4654                }
    47             }
     55
     56            }
     57           
    4858            return false;
    49         }
    50         public async void DownloadPharmaciesExcel()
     59
     60        }
     61        public void DownloadPharmaciesExcel()
    5162        {
    5263            try
     
    5667                string pathToSave2 = Directory.GetCurrentDirectory() + @"\ExcellDocs\2.xlsx";
    5768                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";*/
    6071                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 = await ReadPharmaciesFromExcel(pathToSave1);
     72                //Uri uri2 = new Uri(url2);
     73                client.DownloadFileAsync(uri1, pathToSave1);
     74                //client.DownloadFile(uri2, @pathToSave2);
     75
     76
     77                bool Success = ReadPharmaciesFromExcel(pathToSave1);
    6778                _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.");
    7586            }
    7687        }
Note: See TracChangeset for help on using the changeset viewer.