This commit is contained in:
2023-02-22 12:12:38 +01:00
parent 4ce7d62433
commit 185746ee72
54 changed files with 3701 additions and 3701 deletions

View File

@@ -1,53 +1,53 @@
using CsvHelper;
using CsvHelper.Configuration;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Formats.Asn1;
using System.Globalization;
using System.Text;
using WebAPI.Models;
namespace WebAPI.dataParsers
{
public class csvParser
{
public List<Record> parse(IFormFile file)
{
var info = CultureInfo.CurrentCulture;
List<Record> records = new List<Record>();
var stream = new StreamReader(file.OpenReadStream());
string content = stream.ReadToEnd();
List<string> lines = content.Split("\n").ToList();
List<List<string>> data = new List<List<string>>();
foreach (string line in lines)
{
data.Add(line.Split(";").ToList());
}
for (int i = 1; i < data[0].Count; i++)
{
for (int j = 1; j < data.Count; j++) {
if (data[j][0].Length > 0)
{
float value = float.Parse(data[j][i], CultureInfo.GetCultureInfo("pl-PL"));
if (value > 0)
{
Record record = new Record();
record.Id = Guid.NewGuid();
record.Code = data[0][i];
record.Desc1 = data[j][0];
record.Value = value;
record.CreatedAt = DateTime.UtcNow;
record.ModifiedAt= DateTime.UtcNow;
records.Add(record);
}
}
};
}
return records;
}
}
}
using CsvHelper;
using CsvHelper.Configuration;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.Formats.Asn1;
using System.Globalization;
using System.Text;
using WebAPI.Models;
namespace WebAPI.dataParsers
{
public class csvParser
{
public List<Record> parse(IFormFile file)
{
var info = CultureInfo.CurrentCulture;
List<Record> records = new List<Record>();
var stream = new StreamReader(file.OpenReadStream());
string content = stream.ReadToEnd();
List<string> lines = content.Split("\n").ToList();
List<List<string>> data = new List<List<string>>();
foreach (string line in lines)
{
data.Add(line.Split(";").ToList());
}
for (int i = 1; i < data[0].Count; i++)
{
for (int j = 1; j < data.Count; j++) {
if (data[j][0].Length > 0)
{
float value = float.Parse(data[j][i], CultureInfo.GetCultureInfo("pl-PL"));
if (value > 0)
{
Record record = new Record();
record.Id = Guid.NewGuid();
record.Code = data[0][i];
record.Desc1 = data[j][0];
record.Value = value;
record.CreatedAt = DateTime.UtcNow;
record.ModifiedAt= DateTime.UtcNow;
records.Add(record);
}
}
};
}
return records;
}
}
}

View File

@@ -1,49 +1,49 @@
using Google.Apis.Sheets.v4;
using System.Globalization;
using WebAPI.Models;
namespace WebAPI.dataParsers
{
public class googleSheetParser
{
private SpreadsheetsResource.ValuesResource googleSheetValues;
public googleSheetParser(SpreadsheetsResource.ValuesResource _googleSheetValues)
{
googleSheetValues = _googleSheetValues;
}
public dynamic parse(string sheetId)
{
var range = "Arkusz1!A:B";
var request = googleSheetValues.Get(sheetId, range);
var response = request.Execute();
var data = response.Values;
List<Record> records = new List<Record>();
string date = (string)data[0][0];
for (int i = 1; i < data.Count; i++)
{
float value = float.Parse(data[i][1].ToString(), CultureInfo.GetCultureInfo("pl-PL"));
if (value > 0)
{
Record record = new Record();
record.Id = Guid.NewGuid();
record.Code = data[i][0].ToString();
record.Value = value;
record.CreatedAt = DateTime.UtcNow;
record.ModifiedAt = DateTime.UtcNow;
records.Add(record);
}
}
return new
{
records = records,
date = date
};
}
}
}
using Google.Apis.Sheets.v4;
using System.Globalization;
using WebAPI.Models;
namespace WebAPI.dataParsers
{
public class googleSheetParser
{
private SpreadsheetsResource.ValuesResource googleSheetValues;
public googleSheetParser(SpreadsheetsResource.ValuesResource _googleSheetValues)
{
googleSheetValues = _googleSheetValues;
}
public dynamic parse(string sheetId)
{
var range = "Arkusz1!A:B";
var request = googleSheetValues.Get(sheetId, range);
var response = request.Execute();
var data = response.Values;
List<Record> records = new List<Record>();
string date = (string)data[0][0];
for (int i = 1; i < data.Count; i++)
{
float value = float.Parse(data[i][1].ToString(), CultureInfo.GetCultureInfo("pl-PL"));
if (value > 0)
{
Record record = new Record();
record.Id = Guid.NewGuid();
record.Code = data[i][0].ToString();
record.Value = value;
record.CreatedAt = DateTime.UtcNow;
record.ModifiedAt = DateTime.UtcNow;
records.Add(record);
}
}
return new
{
records = records,
date = date
};
}
}
}