Personal I have a following problem.
I had to create an audit page of my system, where it displays the edits that were made on a certain form.
When a form is populated for the first time, it shows all form variables, as you can see in the picture below.
Whenthesameformisedited,itdisplaysthefollowingscreen.
Asyoucansee,inthissecondscreen,itdoesnotdisplayallthevariables.
Andmyproblemisthis,Ineeditonthissecondscreen,itchecksallthevariables.
Thismodalisonlydisplayingthevariablesthathavebeenedited,Ineedittodisplayeverything,eventhoughitdoesnothavedatainthefieldasthephotoaboveshows.
MyJS
$(document).ready(function(){$('[name="btn_detalhes"]').click(function () {
var altaUtiId = $(this).attr('id');
var patientId = $(this).attr('data-content');
$.ajax({
method: 'POST',
url: '/Formulario/AltaUTI/VerificaDiff',
data: { 'PatientId': patientId, 'AltaUtiId': altaUtiId },
success: function (response) {
var t1 = response[0];
var t2 = response[1];
var registro = response[2];
if (t1.length > 0 || t2.length > 0) {
$('#msgLoading').fadeIn(0);
$('.modal.Detalhes').modal({
closable: false,
blurring: true,
}).modal('show');
for (var i = 0; i < t1.length; i++) {
$('#trInser1').append('<p> ' + t1[i] + ' </p>');
if (t2.length > 0) {
$('#tdInser2').append('<p> ' + t2[i] + ' </p>');
$('#tdInser2').removeClass('display-none');
$('#colAtual').removeClass('display-none');
$('#colAtual').fadeIn();
$('#tdInser2').fadeIn();
}
else {
if (registro.length > 0)
$('#colAlterado').text('Usuário alterado');
else
$('#colAlterado').text('Usuário atual');
$('#tdInser2').addClass('display-none');
$('#colAtual').addClass('display-none');
}
}
$('#msgLoading').fadeOut(0);
} else {
notif({
'type': 'error',
'msg': 'Não foi encontrado modificações no formulário!',
'position': 'center'
});
}
},
error: function (response) {
notif({
'type': 'error',
'msg': 'Erro na resposta do servidor!',
'position': 'center'
});
}
})
});
$('.btn_ok').click(function () {
$("p").remove();
$("#colAtual").css({ display: "none" });
$("#tdInser2").css({ display: "none" });
$('.modal.Detalhes').modal('hide');
});
});
My Controller
[HttpPost]
public ActionResult VerificaDiff(int AltaUtiId, int PatientId)
{
DataSet query = _altaUtiService.RetornaFormulario(AltaUtiId, PatientId);
DataSet query2 = _altaUtiService.RetornaFormulario2(AltaUtiId, PatientId);
DataSet query3 = _altaUtiService.RetornaQuantidadeRegistro(PatientId);
List<string> list = new List<string>();
List<string> list2 = new List<string>();
List<string> Result = new List<string>();
List<string> Result2 = new List<string>();
List<string> Registro = new List<string>();
int j = 0;
foreach (DataRow dr in query.Tables[0].Rows)
{
if (query2.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr2 in query2.Tables[0].Rows)
{
foreach (var item in dr2.ItemArray.ToArray())
{
list.Add(item.ToString());
j = j + 1;
}
foreach (var item in dr.ItemArray.ToArray())
{
list2.Add(item.ToString());
}
for (int i = 0; i < j; i++)
{
if (list[i] != list2[i])
{
Result.Add(queryAuditoriaAlta[i] + ": " + list[i].ToString());
Result2.Add(queryAuditoriaAlta[i] + ": " + list2[i].ToString());
}
}
}
}
else
{
foreach (var item in dr.ItemArray.ToArray())
{
list.Add(item.ToString());
Result.Add(queryAuditoriaAlta[j] + ": " + list[j].ToString());
j = j + 1;
if (query3.Tables[0].Rows.Count > 1 && Registro.Count < 1)
Registro.Add("Sim");
}
}
}
var resultado = new[] { Result, Result2, Registro };
return Json(resultado, JsonRequestBehavior.AllowGet);
}