Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 49 additions & 25 deletions WebLab/Protocolos/MedicoSel.aspx.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Business.Data;
using Business.Data.Laboratorio;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
Expand All @@ -19,14 +20,14 @@ public partial class MedicoSel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

if (!Page.IsPostBack)
{
Session["matricula"] = null;
Session["apellidoNombre"] = null;
}

}



protected void btnBuscar_Click(object sender, EventArgs e)
{
Expand All @@ -43,28 +44,23 @@ protected void btnBuscar_Click(object sender, EventArgs e)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(s_url);
HttpWebResponse ws1 = (HttpWebResponse)request.GetResponse();
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();

Stream st = ws1.GetResponseStream();
StreamReader sr = new StreamReader(st);

string s = sr.ReadToEnd();
if (s != "0")
{

//List<ProtocoloEdit2.ProfesionalMatriculado> pro = jsonSerializer.Deserialize<List<ProtocoloEdit2.ProfesionalMatriculado>>(s);

DataTable t = GetJSONToDataTableUsingMethod(s);
DataTable t = GetDataTableMatriculaciones(s); //GetJSONToDataTableUsingMethod(s);
gvMedico.DataSource = t;
gvMedico.DataBind();


}
}
catch (Exception ex)
{

}


}
public static DataTable GetJSONToDataTableUsingMethod(string JSONData)
Expand Down Expand Up @@ -119,13 +115,41 @@ public static DataTable GetJSONToDataTableUsingMethod(string JSONData)
}
return dtUsingMethodReturn;
}

private static DataTable GetDataTableMatriculaciones(string json)
{
//Pasa de JSON al tipo de objeto ProfesionalMatriculado
List<Protocolos.ProtocoloEdit2.ProfesionalMatriculado> personas = JsonConvert.DeserializeObject<List<Protocolos.ProtocoloEdit2.ProfesionalMatriculado>>(json);
DataTable dt = new DataTable();

if (personas.Count > 0)
{
//Guardo solo en la tabla aquellos datos que necesito
dt.Columns.Add("nombre");
dt.Columns.Add("apellido");
dt.Columns.Add("titulo");
dt.Columns.Add("matriculaNumero");

foreach (Protocolos.ProtocoloEdit2.ProfesionalMatriculado persona in personas)
{
foreach (Protocolos.ProtocoloEdit2.Profesiones prof in persona.profesiones)
{
foreach (Protocolos.ProtocoloEdit2.Matricula mat in prof.matriculacion)
{
if (DateTime.Compare(mat.fin, DateTime.Now) > 0) //Solo agrega las matriculas no vencidas
{
dt.Rows.Add(persona.nombre, persona.apellido, prof.titulo, mat.matriculaNumero);
}
}
}
}
}
return dt;
}
protected void gvMedico_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 1)
{



if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton CmdModificar = (LinkButton)e.Row.Cells[3].Controls[1];
Expand All @@ -134,21 +158,21 @@ protected void gvMedico_RowDataBound(object sender, GridViewRowEventArgs e)
CmdModificar.ToolTip = "Seleccionar";


// Valor adicional (Nombre y apellido)
DataRow rowData = ((DataRowView)e.Row.DataItem).Row;
CmdModificar.Attributes["nombre"] = rowData.ItemArray[0].ToString();
CmdModificar.Attributes["apellido"] = rowData.ItemArray[1].ToString();
}


}
}

protected void gvMedico_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName== "Seleccionar")
if (e.CommandName == "Seleccionar")
{

Session["matricula"] = e.CommandArgument.ToString();



Session["matricula"] = e.CommandArgument.ToString();
LinkButton boton = (LinkButton)e.CommandSource;
Session["apellidoNombre"] = boton.Attributes["apellido"] + " " + boton.Attributes["nombre"];
}
}
}
Expand Down
Loading