Views for excel/word.
This commit is contained in:
parent
6a587d523c
commit
8ef56e41f0
@ -1,7 +1,9 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using Microsoft.VisualBasic;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
@ -27,10 +29,7 @@ namespace ComputerStoreEmployeeApp
|
||||
var result = response.Content.ReadAsStringAsync().Result;
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(result, new JsonSerializerSettings()
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
||||
});
|
||||
return JsonConvert.DeserializeObject<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -38,6 +37,24 @@ namespace ComputerStoreEmployeeApp
|
||||
}
|
||||
}
|
||||
|
||||
public static Stream GetRequestFile<T>(string requestUrl, ReportComponentsBindingModel model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
var response = _client.PostAsync(requestUrl, data).Result;
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
response.Content.Headers.TryGetValues("content-type", out var type);
|
||||
|
||||
return response.Content.ReadAsStreamAsync().Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Something went wrong!");
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<bool> PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
@ -52,7 +69,10 @@ namespace ComputerStoreEmployeeApp
|
||||
throw new Exception(result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static async Task<bool> PatchRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
|
@ -319,7 +319,11 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
public IActionResult PCAdd(int? request)
|
||||
{
|
||||
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentslist").Result;
|
||||
ViewBag.Requests = APIClient.GetRequest<List<RequestViewModel>>($"api/main/getrequestlist?id={null}").Result;
|
||||
if(!APIClient.GetRequest<List<RequestComponentViewModel>>($"api/main/getrequestcomponentlist?id={null}").Result.Any())
|
||||
{
|
||||
return Redirect("PCMenu");
|
||||
}
|
||||
ViewBag.Requests = APIClient.GetRequest<List<RequestComponentViewModel>>($"api/main/getrequestcomponentlist?id={null}").Result.Select(x => new RequestViewModel { ID = x.RequestID}).ToList();
|
||||
ViewBag.PCComponents = APIClient.pcComponents;
|
||||
if(request == null)
|
||||
{
|
||||
|
@ -1,7 +1,10 @@
|
||||
using ComputerStoreContracts.BindingModels;
|
||||
using ComputerStoreContracts.SearchModels;
|
||||
using ComputerStoreContracts.ViewModels;
|
||||
using ComputerStoreDataModels.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ComputerStoreEmployeeApp.Controllers
|
||||
{
|
||||
@ -30,8 +33,15 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
[HttpPost]
|
||||
public IActionResult SaveExcel()
|
||||
{
|
||||
var model = new ReportComponentsBindingModel { FileName = "ReportConsignments", Components = APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name }).ToList() };
|
||||
return File(APIClient.GetRequest<byte[]>($"api/main/savereportconsignmentstoexcel?model={model}").Result,
|
||||
|
||||
var model = new ReportComponentsBindingModel
|
||||
{
|
||||
FileName = "ReportConsignments.xlsx" ,
|
||||
Components = APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name =x.Value.Component.Name}).ToList()
|
||||
};
|
||||
APIClient.productComponents.Clear();
|
||||
var mem = APIClient.GetRequestFile<ReportComponentsBindingModel>($"api/main/savereportconsignmentstoexcel",model);
|
||||
return File(mem,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"ReportConsignments.xlsx");
|
||||
|
||||
@ -40,31 +50,29 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
[HttpPost]
|
||||
public IActionResult SaveWord()
|
||||
{
|
||||
var model = new ReportComponentsBindingModel { FileName = "ReportConsignments", Components = APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name }).ToList() };
|
||||
return File(APIClient.GetRequest<byte[]>($"api/main/savereportconsignmentstoword?model={model}").Result,
|
||||
var model = new ReportComponentsBindingModel
|
||||
{
|
||||
FileName = "ReportConsignments.xlsx",
|
||||
Components = APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name }).ToList()
|
||||
};
|
||||
APIClient.productComponents.Clear();
|
||||
var mem = APIClient.GetRequestFile<ReportComponentsBindingModel>($"api/main/savereportconsignmentstoword", model);
|
||||
return File(mem,
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.document",
|
||||
"ReportConsignments.doc");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void ConsignmentComponents(int id, int componentquantity)
|
||||
public void ConsignmentComponents(int id)
|
||||
{
|
||||
var component = APIClient.GetRequest<ComponentViewModel>($"api/main/getcomponent?id={id}").Result;
|
||||
if (APIClient.productComponents.ContainsKey(component.ID))
|
||||
{
|
||||
if(componentquantity == 0)
|
||||
{
|
||||
APIClient.productComponents.Remove(component.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
APIClient.productComponents[component.ID] = (component, componentquantity);
|
||||
}
|
||||
|
||||
APIClient.productComponents[component.ID] = (component, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
APIClient.productComponents.Add(component.ID, (component, componentquantity));
|
||||
APIClient.productComponents.Add(component.ID, (component, 1));
|
||||
}
|
||||
|
||||
}
|
||||
@ -74,7 +82,9 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
{
|
||||
if(APIClient.productComponents.Any())
|
||||
{
|
||||
ViewBag.Consignments = APIClient.GetRequest<List<ReportConsignmentsViewModel>>($"api/main/getreportconsignmentslist?model={APIClient.productComponents.Select(x => new ComponentSearchModel { ID = x.Key, Name = x.Value.Component.Name })}").Result;
|
||||
|
||||
var str = ModelToStr();
|
||||
ViewBag.Consignments = APIClient.GetRequest<List<ReportConsignmentsViewModel>>($"api/main/GetReportConsignments?str={str}").Result;
|
||||
return View("ConsignmentsReport", APIClient.productComponents);
|
||||
}
|
||||
|
||||
@ -82,6 +92,17 @@ namespace ComputerStoreEmployeeApp.Controllers
|
||||
ViewBag.Components = APIClient.GetRequest<List<ComponentViewModel>>("api/main/getcomponentslist").Result;
|
||||
return View("ConsignmentsReport", APIClient.productComponents);
|
||||
}
|
||||
|
||||
public string ModelToStr()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
foreach (var component in APIClient.productComponents)
|
||||
{
|
||||
stringBuilder.Append($"{component.Key}|{component.Value.Component.Name};");
|
||||
}
|
||||
var str = stringBuilder.ToString();
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,11 @@
|
||||
<table>
|
||||
@foreach (var component in item.PCComponents)
|
||||
{
|
||||
<tr><td>@component.Value.Component.Name</td></tr>
|
||||
<tr>
|
||||
<td>@component.Value.Component.Name</td>
|
||||
<td></td>
|
||||
<td>@component.Value.Quantity</td>
|
||||
</tr>
|
||||
|
||||
}
|
||||
</table>
|
||||
|
@ -7,8 +7,8 @@
|
||||
<form method="post">
|
||||
<div class="flex-container" style="flex-direction: row; justify-content: space-between; display: flex; height: 100vh;">
|
||||
<div class="flex-containerB1" style="flex-direction: column; flex: 4; gap: 20px; display: flex; align-items: center; justify-content: center;">
|
||||
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(@ViewBag.PCs,"ID","Name"))"></select>
|
||||
<input type="submit" id="productbtn" value="DELETE" class="btn btn-primary" />
|
||||
<select id="pc" name="pc" class="form-control" asp-items="@(new SelectList(@ViewBag.PCs,"ID","Name"))"></select>
|
||||
<input type="submit" id="pcbtn" value="DELETE" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
@if (!string.IsNullOrEmpty(ViewBag.Message))
|
||||
|
@ -7,15 +7,15 @@
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Enter components</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div>
|
||||
|
||||
|
||||
@if(ViewBag.Components != null)
|
||||
{
|
||||
<div class="flex-container" style="flex-direction: row; justify-content: space-between; display: flex; height: 100vh; gap: 20px; align-items: center;">
|
||||
<div class="flex-containerB1" style="flex-direction: column; flex: 4; gap: 20px; display: flex; align-items: center; justify-content: center;">
|
||||
<h1>Component:</h1>
|
||||
<select id="component" name="component" class="form-control" asp-items="@(new SelectList(@ViewBag.Components,"ID","Name"))"></select>
|
||||
<div class="componentquantity" style="text-align: left; font-size: 15px;">Quantity:</div>
|
||||
<input type="text" id="componentquantity" name="componentquantity" />
|
||||
<select id="component" name="component" class="form-control" asp-items="@(new SelectList(@ViewBag.Components,"ID","Name"))"></select>
|
||||
<input type="button" id="componentbtn" value="ADD" class="btn btn-primary" />
|
||||
</div>
|
||||
<div class="flex-containerB2" style="flex-direction: column; flex: 4; gap: 20px; display: flex; align-items: center; justify-content: center;">
|
||||
@ -25,10 +25,7 @@
|
||||
|
||||
<th>
|
||||
Name
|
||||
</th>
|
||||
<th>
|
||||
Count
|
||||
</th>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -39,9 +36,6 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Value.Item1.Name)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Value.Item2)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
@ -80,8 +74,7 @@
|
||||
@foreach (var product in item.Products)
|
||||
{
|
||||
<tr>
|
||||
<td>@product.product</td>
|
||||
<td>@product.count</td>
|
||||
<td>@product.product</td>
|
||||
</tr>
|
||||
|
||||
}
|
||||
@ -91,27 +84,26 @@
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="flex-containerB2" style="flex-direction: column; flex: 4; gap: 20px; display: flex; align-items: center; justify-content: center;">
|
||||
<form method="post" asp-controller="Report" asp-action="SaveExcel">
|
||||
<input type="submit" id="consignmentreport" value="Save excel" class="btn btn-primary" style="font-size: 20pt; width: auto;" />
|
||||
</form>
|
||||
<form method="post" asp-controller="Report" asp-action="SaveWord">
|
||||
<input type="submit" id="consignmentreport" value="Save word" class="btn btn-primary" style="font-size: 20pt; width: auto;" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="flex-containerB2" style="flex-direction: column; flex: 4; gap: 20px; display: flex; align-items: center; justify-content: center;">
|
||||
<form method="post" action="@Url.Action("SaveWord","Report")">
|
||||
<input type="submit" id="wordbtn" value="Save word" class="btn btn-primary" style="font-size: 20pt; width: auto;" />
|
||||
</form>
|
||||
</div>
|
||||
<form method="post" action="@Url.Action("SaveExcel","Report")">
|
||||
<input type="submit" id="excelbtn" value="Save excel" class="btn btn-primary" style="font-size: 20pt; width: auto;" />
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
@if (!string.IsNullOrEmpty(ViewBag.Message))
|
||||
{
|
||||
<script>alert("@ViewBag.Message");</script>
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$('#componentbtn').on("click", function () {
|
||||
var count = $('#componentquantity').val();
|
||||
$('#componentbtn').on("click", function () {
|
||||
var id = $('#component').val();
|
||||
|
||||
$.when(ajax1(id, count)).done(function (a1) {
|
||||
$.when(ajax1(id)).done(function (a1) {
|
||||
window.location.href = '/Report/ConsignmentsReport'
|
||||
})
|
||||
});
|
||||
@ -122,14 +114,13 @@
|
||||
|
||||
});
|
||||
|
||||
function ajax1(id, count) {
|
||||
function ajax1(id) {
|
||||
|
||||
return $.ajax({
|
||||
method: "POST",
|
||||
url: "/Report/ConsignmentComponents",
|
||||
data: { id: id, componentquantity: count }
|
||||
data: { id: id}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user