diff --git a/DataGeneratorMVC/Controllers/HomeController.cs b/DataGeneratorMVC/Controllers/HomeController.cs index e383337..1d9f6fa 100644 --- a/DataGeneratorMVC/Controllers/HomeController.cs +++ b/DataGeneratorMVC/Controllers/HomeController.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Net; using System.Text; using System.Text.Json.Serialization; +using System.Text.RegularExpressions; using Microsoft.AspNetCore.Mvc; using DataGeneratorMVC.Models; using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata; @@ -31,7 +32,7 @@ public class HomeController : Controller } [HttpPost] - public IActionResult Index(GeneratorDataViewModel model, string cmd) + public IActionResult Index(GeneratorDataViewModel model, string cmd, IFormFile? file) { if (ModelState.IsValid) { @@ -44,16 +45,45 @@ public class HomeController : Controller break; case "save": return File(Encoding.UTF8.GetBytes(model.Sql), "text/plain", "sql_insert.sql"); + case "upload": + Upload(model, file); + break; } } } return View(model); } - - private void GenerateNew(GeneratorDataViewModel model) + + private void Upload(GeneratorDataViewModel model, IFormFile up) { - var tmp = DataGenerator.Generate(model.Settings); + + var rgx = new Regex(@"(?<=\()(.*)(?=\))"); // Match only values of SQL Statement + var dict = new Dictionary(); + + using (var reader = new StreamReader(up.OpenReadStream())) + { + while (reader.Peek() >= 0) + { + string line = reader.ReadLine(); + line = rgx.Match(line).Value; + string[] inputs = line.Split(","); + dict.Add(DateTime.Parse(inputs[1].Replace("\'", "")), Double.Parse(inputs[2])); + } + } + + //var model = new GeneratorDataViewModel(); + GenerateNew(model, dict); + } + + private void GenerateNew(GeneratorDataViewModel model, Dictionary? input = null) + { + Dictionary tmp; + if (input != null) + tmp = input; + else + tmp = DataGenerator.Generate(model.Settings); + var labels = new List(); diff --git a/DataGeneratorMVC/Properties/launchSettings.json b/DataGeneratorMVC/Properties/launchSettings.json index d10247e..77e051d 100644 --- a/DataGeneratorMVC/Properties/launchSettings.json +++ b/DataGeneratorMVC/Properties/launchSettings.json @@ -12,7 +12,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7040;http://localhost:5143", + "applicationUrl": "https://localhost:7040;http://localhost:5143;", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/DataGeneratorMVC/Views/Home/Index.cshtml b/DataGeneratorMVC/Views/Home/Index.cshtml index 0af7809..6772a6f 100644 --- a/DataGeneratorMVC/Views/Home/Index.cshtml +++ b/DataGeneratorMVC/Views/Home/Index.cshtml @@ -16,103 +16,104 @@

Settings

- @using (Html.BeginForm("Index", "Home", FormMethod.Post)) - { - @Html.AntiForgeryToken() + @* @using (Html.BeginForm("Index", "Home", FormMethod.Post)) *@ + @* { *@ + @* @Html.AntiForgeryToken() *@ +
@Html.LabelFor(model => model.Settings.StartYear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.StartYear) - @Html.ValidationMessageFor(model => model.Settings.StartYear, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.StartYear, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.Years, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.Years) - @Html.ValidationMessageFor(model => model.Settings.Years, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.Years, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.StartTurnover, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.StartTurnover) - @Html.ValidationMessageFor(model => model.Settings.StartTurnover, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.StartTurnover, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.MaxDiff, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MaxDiff) - @Html.ValidationMessageFor(model => model.Settings.MaxDiff, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.MaxDiff, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.MinDiff, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MinDiff) - @Html.ValidationMessageFor(model => model.Settings.MinDiff, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.MinDiff, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.RSmoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.RSmoothing) - @Html.ValidationMessageFor(model => model.Settings.RSmoothing, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.RSmoothing, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.MaxSmoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MaxSmoothing) - @Html.ValidationMessageFor(model => model.Settings.MaxSmoothing, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.MaxSmoothing, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.MinSmoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MinSmoothing) - @Html.ValidationMessageFor(model => model.Settings.MinSmoothing, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.MinSmoothing, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.Smoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.Smoothing) - @Html.ValidationMessageFor(model => model.Settings.Smoothing, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.Smoothing, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.Linear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.Linear) - @Html.ValidationMessageFor(model => model.Settings.Linear, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.Linear, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.HasSin, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.HasSin) - @Html.ValidationMessageFor(model => model.Settings.HasSin, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.HasSin, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.SinLength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.SinLength) - @Html.ValidationMessageFor(model => model.Settings.SinLength, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.SinLength, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.SinStrength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.SinStrength) - @Html.ValidationMessageFor(model => model.Settings.SinStrength, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.SinStrength, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.SinNegative, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.SinNegative) - @Html.ValidationMessageFor(model => model.Settings.SinNegative, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.SinNegative, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.HasPeak, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.HasPeak) - @Html.ValidationMessageFor(model => model.Settings.HasPeak, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.HasPeak, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.PeakLength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.PeakLength) - @Html.ValidationMessageFor(model => model.Settings.PeakLength, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.PeakLength, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.PeakStrength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.PeakStrength) - @Html.ValidationMessageFor(model => model.Settings.PeakStrength, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.PeakStrength, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.RPeakInYear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.RPeakInYear) - @Html.ValidationMessageFor(model => model.Settings.RPeakInYear, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.RPeakInYear, "", new {@class = "text-danger"})
@Html.LabelFor(model => model.Settings.PeakInYear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.PeakInYear) - @Html.ValidationMessageFor(model => model.Settings.PeakInYear, "",new {@class = "text-danger"}) + @Html.ValidationMessageFor(model => model.Settings.PeakInYear, "", new {@class = "text-danger"})
@@ -120,12 +121,18 @@
+
+ + +
- } +
+ + @*}*@