cascading commesse
This commit is contained in:
parent
d0d6f66f96
commit
6b0e4dcef0
@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using VirtualTask.Models;
|
||||
using X.PagedList;
|
||||
@ -104,7 +105,7 @@ namespace VirtualTask.Controllers
|
||||
|
||||
ViewBag.Admin = admin;
|
||||
|
||||
ViewBag.Impianti = getImpianti();
|
||||
//ViewBag.Impianti = getImpianti();
|
||||
ViewBag.Anag = getClienti();
|
||||
return View();
|
||||
}
|
||||
@ -390,7 +391,28 @@ namespace VirtualTask.Controllers
|
||||
|
||||
return selectItems;
|
||||
}
|
||||
private List<Impianto> getImpiantiALL()
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
token = helper.GetStringValue("tok");
|
||||
//apiUrl = helper.GetStringValue("")
|
||||
urlBase = apiUrl + "impiantiListMngr";
|
||||
urlBase = urlBase + "?token=" + token;
|
||||
Uri baseAddress = new Uri(urlBase);
|
||||
client = new HttpClient();
|
||||
client.BaseAddress = baseAddress;
|
||||
|
||||
List<SelectListItem> selectItems = new List<SelectListItem>();
|
||||
List<Impianto> modelList = new List<Impianto>();
|
||||
HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string data = response.Content.ReadAsStringAsync().Result;
|
||||
modelList = JsonConvert.DeserializeObject<List<Impianto>>(data);
|
||||
}
|
||||
return modelList;
|
||||
}
|
||||
private List<SelectListItem> getClienti()
|
||||
{
|
||||
SessionHelper helper = new SessionHelper(this);
|
||||
@ -492,33 +514,63 @@ namespace VirtualTask.Controllers
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, ErrMsg = e });
|
||||
}
|
||||
|
||||
//private bool checkAziendaPresente(string azienda)
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region CASCADING
|
||||
|
||||
public IActionResult Cascading()
|
||||
{
|
||||
Cascading model = new Cascading();
|
||||
model.Clienti = getClienti();
|
||||
return View(model);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Cascading(string lacodcli)
|
||||
{
|
||||
Cascading model = new Cascading();
|
||||
model.Clienti = getClienti();
|
||||
|
||||
if (!string.IsNullOrEmpty(lacodcli))
|
||||
{
|
||||
List<Impianto> impianti = new List<Impianto>();
|
||||
impianti = getImpiantiALL();
|
||||
var impiaCli = impianti.Where(x => x.imultcli.Equals(lacodcli)).ToList();
|
||||
foreach (Impianto i in impiaCli)
|
||||
{
|
||||
SelectListItem listItem = new SelectListItem();
|
||||
string s = i.imcodimp + " - " + i.imdescri;
|
||||
listItem.Value = i.imcodimp;
|
||||
listItem.Text = s;
|
||||
model.Impianti.Add(listItem);
|
||||
//model.Impianti.Add(new SelectListItem { Text = i.imcodimp, Value = i.imcodimp });
|
||||
|
||||
}
|
||||
}
|
||||
//string data = JsonConvert.SerializeObject(model.Impianti);
|
||||
//return Json(data);
|
||||
return Json(new SelectList(model.Impianti, "Value", "Text"));
|
||||
}
|
||||
//[HttpPost]
|
||||
//public ActionResult GetDistrict(string ancodice)
|
||||
//{
|
||||
// bool trovato = false;
|
||||
// bool bAziPres = false;
|
||||
|
||||
// //urlBase = "http://10.0.0.187:8000/api/Polo/AziendePresentiList";
|
||||
// urlBase = apiUrl + "AziendePresentiList";
|
||||
// Uri baseAddress = new Uri(urlBase);
|
||||
// client = new HttpClient();
|
||||
// client.BaseAddress = baseAddress;
|
||||
|
||||
// List<AziendaPres> modelList = new List<AziendaPres>();
|
||||
// HttpResponseMessage response = client.GetAsync(baseAddress).Result;
|
||||
// if (response.IsSuccessStatusCode)
|
||||
// int statId;
|
||||
// List<SelectListItem> districtNames = new List<SelectListItem>();
|
||||
// if (!string.IsNullOrEmpty(stateId))
|
||||
// {
|
||||
// string data = response.Content.ReadAsStringAsync().Result;
|
||||
// modelList = JsonConvert.DeserializeObject<List<AziendaPres>>(data);
|
||||
// foreach (AziendaPres a in modelList)
|
||||
// statId = Convert.ToInt32(stateId);
|
||||
// List<DistrictMaster> districts = schoolEntity.DistrictMasters.Where(x => x.StateId == statId).ToList();
|
||||
// districts.ForEach(x =>
|
||||
// {
|
||||
// if (!string.IsNullOrEmpty(a.tccodazi) && a.tccodazi.Trim().Equals(azienda))
|
||||
// trovato = true;
|
||||
// }
|
||||
// bAziPres = trovato;
|
||||
// districtNames.Add(new SelectListItem { Text = x.DistrictName, Value = x.DistrictId.ToString() });
|
||||
// });
|
||||
// }
|
||||
// return bAziPres;
|
||||
// return Json(districtNames, JsonRequestBehavior.AllowGet);
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#endregion ALTRI METODI
|
||||
}
|
||||
}
|
||||
|
||||
21
Models/Cascading.cs
Normal file
21
Models/Cascading.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
|
||||
namespace VirtualTask.Models
|
||||
{
|
||||
public class Cascading
|
||||
{
|
||||
public Cascading()
|
||||
{
|
||||
this.Clienti = new List<SelectListItem>();
|
||||
this.Impianti = new List<SelectListItem>();
|
||||
}
|
||||
|
||||
public List<SelectListItem> Clienti { get; set; }
|
||||
public List<SelectListItem> Impianti { get; set; }
|
||||
|
||||
public string? lacodcli { get; set; }
|
||||
public string? ancodice { get; set; }
|
||||
public string? imcodimp { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
61
Views/CommesseVT/Cascading.cshtml
Normal file
61
Views/CommesseVT/Cascading.cshtml
Normal file
@ -0,0 +1,61 @@
|
||||
@model VirtualTask.Models.Cascading
|
||||
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<script src="~/assets/js/jquery.min.js"></script>
|
||||
|
||||
<h2>Cascading Dropdownlist</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<label>Clienti</label>
|
||||
</td>
|
||||
<td>
|
||||
@Html.DropDownListFor(x => x.ancodice, Model.Clienti, "--Select--", new { @id="ddlClienti"});
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>Impianti</label>
|
||||
</td>
|
||||
<td id="District">
|
||||
@Html.DropDownListFor(x => x.imcodimp, new List<SelectListItem>(), "--Select--", new { @id="ddlImpianti"});
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('#ddlClienti').change(function () {
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/CommesseVT/Cascading",
|
||||
data: { ancodice: $('#ddlClienti').val() },
|
||||
datatype: "json",
|
||||
traditional: true,
|
||||
success: function (states) {
|
||||
|
||||
//alert(states.length);
|
||||
//alert(JSON.stringify(states));
|
||||
|
||||
var district = "<select id='ddlImpianti' class='form-control'>";
|
||||
district = district + '<option value="">--Seleziona--</option>';
|
||||
for (var i = 0; i < states.length; i++) {
|
||||
district = district + '<option value="' + states[i].value + '">' + states[i].text + '</option>';
|
||||
//alert(states[i].text);
|
||||
//alert(states[i].value);
|
||||
//alert(district);
|
||||
}
|
||||
|
||||
district = district + '</select>';
|
||||
alert(district);
|
||||
$('#District').html(district);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@ -29,12 +29,16 @@
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-12"> </div>
|
||||
<div class="form-group">
|
||||
@Html.DropDownListFor(x => x.lacodcli,(IEnumerable<SelectListItem>)ViewBag.Anag, new{@class = "form-control"})
|
||||
@* @Html.DropDownListFor(x => x.lacodcli,(IEnumerable<SelectListItem>)ViewBag.Anag, new{@class = "form-control"})*@
|
||||
@Html.DropDownListFor(x => x.lacodcli, (IEnumerable<SelectListItem>)ViewBag.Anag, "--Seleziona un cliente--", new { @id="ddlClienti",@class = "form-control"})
|
||||
<span asp-validation-for="lacodcli" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-12"> </div>
|
||||
<div class="form-group">
|
||||
@Html.DropDownListFor(x => x.lacodimp,(IEnumerable<SelectListItem>)ViewBag.Impianti, new{@class = "form-control"})
|
||||
@* @Html.DropDownListFor(x => x.lacodimp,(IEnumerable<SelectListItem>)ViewBag.Impianti, new{@class = "form-control"})*@
|
||||
<div id="District">
|
||||
@Html.DropDownListFor(x => x.lacodimp, new List<SelectListItem>(), "--Seleziona un impianto--", new { @id="ddlImpianti",@class = "form-control"})
|
||||
</div>
|
||||
<span asp-validation-for="lacodimp" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-12"> </div>
|
||||
@ -59,7 +63,35 @@
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<script src="~/assets/js/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('#ddlClienti').change(function () {
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "/CommesseVT/Cascading",
|
||||
data: { lacodcli: $('#ddlClienti').val() },
|
||||
datatype: "json",
|
||||
traditional: true,
|
||||
success: function (states) {
|
||||
|
||||
|
||||
|
||||
var district = "<select id='ddlImpianti' class='form-control'>";
|
||||
district = district + '<option value="">--Seleziona--</option>';
|
||||
for (var i = 0; i < states.length; i++) {
|
||||
district = district + '<option value="' + states[i].value + '">' + states[i].text + '</option>';
|
||||
|
||||
}
|
||||
|
||||
district = district + '</select>';
|
||||
|
||||
$('#District').html(district);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@* <div class="agy-project-wrapper agy-project-page-wrapper">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user