Está en la página 1de 34

SECRETARIA DE EDUCACIÓN DEL GOBIERNO DEL ESTADO

INSTITUTO TECNOLÓGICO SUPERIOR DE SAN LUIS POTOSÍ,


CAPITAL

INGENIERÍA EN SISTEMAS COMPUTACIONALES

Programación web

PROYECTO:

ENFERMERIA

3° avance de Proyecto

INTEGRANTES
ARROYOS RODRÍGUEZ MIREYA NOEMI
SALDIVAR GONZALES KARLA JOSEFINA

IBARRA HERRERA KARINA GUADALUPE

ENERO – JUN 2018


Diseño y modelo de BD (Diseño de tablas, relaciones,
distribución)

create database Enfermeria


go
DROP DATABASE Enfermeria
GO
use Enfermeria
go

create table enfermera(


id_enfermera INT IDENTITY,nombre varchar(20) NOT NULL,
apellido_pa varchar(20) NOT NULL,
apellido_ma varchar(20) NOT NULL,
telefono_cub varchar(20) NOT NULL,
telefono_cel varchar(20) NOT NULL,
turno varchar(20) NOT NULL);
go

create table estudiante(


id_estudiante INT IDENTITY,
nombre varchar(20) NOT NULL,
apellido_pa varchar(20) NOT NULL,
apellido_ma varchar(20) NOT NULL,
no_control varchar(20) NOT NULL,
carrera varchar(20)
check (carrera IN ('administracion','industria','sistemas','mecatronica')));
go

create table historial_medico(


id_historial INT IDENTITY,
tipo_sangre varchar(10) NOT NULL,
alergias_med varchar(30) NOT NULL,
tipoSeguro varchar(20) NOT NULL);

create table medicamento(


id_medicamento INT IDENTITY,
nombre_medicamento varchar(30) NOT NULL,
clasificacion varchar(55) NOT NULL,
fecha_cad date NOT NULL,
cantidad int NOT NULL,
marca varchar(30));

create table registro(


id_registro int IDENTITY,
id_estudiante int NOT NULL,
id_medicamento int NOT NULL,
id_enfermera int NOT NULL,
id_historial int NOT NULL,
fecha date NOT NULL,
hora time NOT NULL);

sp_tables
go
--implementando las llaves primarias
ALTER TABLE ENFERMERA ADD PRIMARY KEY NONCLUSTERED (id_enfermera)
ALTER TABLE ESTUDIANTE ADD PRIMARY KEY NONCLUSTERED (id_estudiante)
ALTER TABLE HISTORIAL_MEDICO ADD PRIMARY KEY NONCLUSTERED (id_historial)
ALTER TABLE MEDICAMENTO ADD PRIMARY KEY NONCLUSTERED (id_medicamento)
ALTER TABLE REGISTRO ADD PRIMARY KEY NONCLUSTERED (id_registro)
go

--Implementando las llaves Secundarias


ALTER TABLE REGISTRO
ADD FOREIGN KEY (id_enfermera) REFERENCES ENFERMERA
GO
ALTER TABLE REGISTRO
ADD FOREIGN KEY (id_estudiante) REFERENCES ESTUDIANTE
GO
ALTER TABLE REGISTRO
ADD FOREIGN KEY (id_historial) REFERENCES HISTORIAL_MEDICO
GO
ALTER TABLE REGISTRO
ADD FOREIGN KEY (id_medicamento) REFERENCES medicamento
GO
ALTER TABLE BITACORA
ADD FOREIGN KEY (id_enfermera) REFERENCES enfermera
GO

--CRecaion de vistas
create view informaciongeneral as
select estudiante.nombre,estudiante.apellido_pa,
estudiante.apellido_ma,historial_medico.alergias_med,
medicamento.nombre_medicamento,registro.fecha,registro.hora,
estudiante.carrera from estudiante,medicamento,registro,
historial_medico where estudiante.id_estudiante=registro.id_estudiante
and historial_medico.id_historial=registro.id_historial and
medicamento.id_medicamento=registro.id_medicamento;

Insert into estudiante values('Margarita','Lopez','Carrillo','14070050','Sistemas');


insert into enfermera
values('dulce','martinez','zavala','8041242','4444890989','matutino');
insert into historial_medico values('o positivo','nada','IMSS');
insert into medicamento values('paracetamol','antibiotico','2016-07-
02','25','blendox');
insert into registro values(2,2,2,2,'2016-04-10','10:59:59');
Modelo Relacional
Distribución 4 capas

Aplicación es .net Solo navegador

Réplica de la
maquina 192.168.1.66
192.168.1.65 Base de datos enfermería

 Tabla estudiantes
 Información general
 Enfermera
 Historial
medicamento
 medicamento
Clases de conexión y operación de la
BD(Select,Insert,Delete,Update)

Las clases de conexión que se crearon fueron la de login

namespace Enfermeria

public partial class Login : System.Web.UI.Page

string strConSQL = @"Data Source=NOEMI;Initial Catalog=Enfermeria;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

lblStatus.Visible = false;

protected void btnLogin_Click(object sender, EventArgs e)

//LLamar Metodo ValidarLogin()

ValidarLogin();

//Metodo ValidarLogin()

protected void ValidarLogin()

try

{
//Crear y usar objeto de conexion SQL

using (SqlConnection conSQL = new SqlConnection(strConSQL))

//Abrir conexion SQL

conSQL.Open();

//String del query SQL

string strSQL = "SELECT COUNT(1) FROM [Enfermeria].[dbo].[usu] WHERE usunom =


@usuario AND usupwd = @password";

//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL, conSQL);

//Parametrizar valores

cmdSQL.Parameters.AddWithValue("@usuario", txtUsuario.Text.Trim());

cmdSQL.Parameters.AddWithValue("@password", txtPassword.Text.Trim());

//Revisar si existe registro

int count = Convert.ToInt32(cmdSQL.ExecuteScalar());

if (count == 1)

//Si existe registro, crear sesion de usuario

Session["usuario"] = txtUsuario.Text.Trim();

Response.Redirect("Enfermera.aspx");

}
else

lblStatus.Visible = true;

lblStatus.Text = "Usuario y/o Password Incorrecto";

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

catch (Exception ex)

lblStatus.Visible = true;

lblStatus.Text = ex.Message;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

La de estudiantes
namespace Enfermeria

public partial class Estudiante1 : System.Web.UI.Page


{

string strConSQL = @"Data Source=NOEMI;Initial Catalog=Enfermeria;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

if (!IsPostBack)

IniciarLlenado();

protected void BtnEnviar_Click(object sender, EventArgs e)

if (Page.IsValid)

Registrar();

else

lblStatus.Text = "Validacion Incorrecta. Existen Datos Incorrectos";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Font.Bold = true;

private void IniciarLlenado()

carrera.DataSource = Consultar("SELECT carrera from estudiante");

carrera.DataTextField = "carrera";

carrera.DataValueField = "carrera";

carrera.DataBind();

carrera.Items.Insert(0, new ListItem("[Seleccionar]", "0"));

protected void Registrar()

try

//string datoSeleccionado = carrera.SelectedItem.Text;

//Console.Write(datoSeleccionado);

//Crear y usar objeto de conexion SQL (conSQL)

using (SqlConnection conSQL = new SqlConnection(strConSQL))

//Abrir Conexion SQL

conSQL.Open();
//String Query SQL

string strSQL = "INSERT INTO [Estudiante].[dbo].[Enfermeria] " +

"(nombre, apellido_pa, apellido_ma, no_control,carrera) VALUES" +

" (@Nombre, @Paterno, @Materno, @NoControl,@Carrera)";

//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL, conSQL);

//Parametrizar comando SQL

cmdSQL.Parameters.AddWithValue("@Nombre", txtNombre.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Paterno", txtAppa.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Materno", txtApma.Text.Trim());

cmdSQL.Parameters.AddWithValue("@NoControl", txtNumc.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Carrera",(carrera.SelectedValue));

//Ejecutar comando SQL

cmdSQL.ExecuteNonQuery();

//Liberar Recursos

cmdSQL.Dispose();

}
//Mensaje Registro Correcto

lblStatus.Text = "Registro Correcto";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Green;

lblStatus.Font.Bold = true;

catch (Exception ex)

//Mensaje Excepcion

lblStatus.Text = ex.Message;

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

public DataSet Consultar(String strSQL)

SqlConnection con = new SqlConnection(strConSQL);

con.Open();

SqlCommand cmd = new SqlCommand(strSQL, con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();


da.Fill(ds);

con.Close();

return ds;

La de enfermera
namespace Enfermeria

public partial class Enfermera : System.Web.UI.Page

string strConSQL = @"Data Source=NOEMI;Initial Catalog=Enfermeria;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

protected void BtnEnviar_Click(object sender, EventArgs e)

if (Page.IsValid)

Registrar();

}
else

lblStatus.Text = "Validacion Incorrecta. Existen Datos Incorrectos";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

protected void Registrar()

try

//Crear y usar objeto de conexion SQL (conSQL)

using (SqlConnection conSQL = new SqlConnection(strConSQL))

//Abrir Conexion SQL

conSQL.Open();

//String Query SQL

string strSQL = "INSERT INTO [Enfermeria].[dbo].[Enfermera] (nombre, apellido_pa,


apellido_ma, telefono_cub, telefono_cel, turno) VALUES (@Nombre, @Paterno,@Materno,
@Telefono, @Celular,@Turno)";

//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL, conSQL);


//Convertir Tipos de Dato

//Parametrizar comando SQL

cmdSQL.Parameters.AddWithValue("@Nombre", txtNombre.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Paterno", txtAppa.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Materno", txtApma.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Telefono", txtTel.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Celular", txtcel.Text.Trim());

string turno = string.Empty;

if(RaMat.Checked)

turno = "matutino";

else

turno = "vespertino";

cmdSQL.Parameters.AddWithValue("@Turno", turno);

//Ejecutar comando SQL

cmdSQL.ExecuteNonQuery();

//Liberar Recursos
cmdSQL.Dispose();

//Mensaje Registro Correcto

lblStatus.Text = "Registro Correcto";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Green;

lblStatus.Font.Bold = true;

catch (Exception ex)

//Mensaje Excepcion

lblStatus.Text = ex.Message;

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

La de información general para que se muestre la tabla de la


relación del registro diario esta tabla también se puede imprimir
en documento pdf.
namespace Enfermeria

{
public partial class informaciongeneral : System.Web.UI.Page

//String de conexion a SQL Server

string strConSQL = @"Data Source=NOEMI;Initial Catalog=Enfermeria;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

protected void btnConsultar_Click(object sender, EventArgs e)

//Llamar Metodo Consulta()

Consulta();

//Metodo Consulta()

protected void Consulta()

try

//Crear y usar objeto de conexion SQL

using (SqlConnection conSQL = new SqlConnection(strConSQL))

//Abrir conexion SQL

conSQL.Open();
//String Query SQL

string strSQL = "SELECT nombre,apellido_pa ,apellido_ma,alergias_med," +

"nombre_medicamento,fecha,hora,carrera FROM[dbo].[informaciongeneral]";

//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL, conSQL);

//Crear Adaptador de Datos

SqlDataAdapter adaptadorSQL = new SqlDataAdapter(cmdSQL);

//Crear Tabla de Datos

DataTable tablaSQL = new DataTable();

//Llenar la Tabla de Datos

adaptadorSQL.Fill(tablaSQL);

//Recuperar los valores de las campos de la tabla

//DataRow row = tablaSQL.Rows[0];

//lblNombre.Text = row["regnom"].ToString();

//txtNombre.Text = row["nombre"].ToString();

//txtApellido.Text = row["apellido"].ToString();

//lblNombre.Text = tablaSQL.Rows[0][0].ToString();

//Recorrer DataTable
//foreach(DataRow dtRow in tablaSQL.Rows)

//{

// foreach(DataColumn dtCol in tablaSQL.Columns)

// {

// string dato = dtRow[dtCol].ToString();

// Response.Write(dato);

// }

//}

//Asignar el origen de datos al GridView

GV_Consulta.DataSource = tablaSQL;

//Enlazar el origen de datos al GridView

GV_Consulta.DataBind();

//Liberar Recursos

cmdSQL.Dispose();

adaptadorSQL.Dispose();

tablaSQL.Dispose();

//Mensaje de Exito

lblStatus.Text = "Consulta realizada con exito";

lblStatus.ForeColor = System.Drawing.Color.Green;

lblStatus.Font.Bold = true;
}

catch (Exception ex)

lblStatus.Text = ex.Message;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

Historial medico

namespace Enfermeria

public partial class historial_medico : System.Web.UI.Page

string strConSQL = @"Data Source=NOEMI;Initial Catalog=Enfermeria;Integrated


Security=True";

protected void Page_Load(object sender, EventArgs e)

protected void BtnEnviar_Click(object sender, EventArgs e)

if (Page.IsValid)
{

Registrar();

else

lblStatus.Text = "Validacion Incorrecta. Existen Datos Incorrectos";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

protected void Registrar()

try

//Crear y usar objeto de conexion SQL (conSQL)

using (SqlConnection conSQL = new SqlConnection(strConSQL))

//Abrir Conexion SQL

conSQL.Open();

//String Query SQL

string strSQL = "INSERT INTO [Enfermeria].[dbo].[historial_medico]


(tipo_sangre,alergias_med,tipoSeguro)" +

" VALUES (@Sangre, @Alergias,@Seguro)";


//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL, conSQL);

//Convertir Tipos de Dato

//Parametrizar comando SQL

cmdSQL.Parameters.AddWithValue("@Sangre", txtSangre.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Alergias", txtAlergias.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Seguro", txtSeguro.Text.Trim());

//Ejecutar comando SQL

cmdSQL.ExecuteNonQuery();

//Liberar Recursos

cmdSQL.Dispose();

//Mensaje Registro Correcto

lblStatus.Text = "Registro Correcto";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Green;

lblStatus.Font.Bold = true;

catch (Exception ex)


{

//Mensaje Excepcion

lblStatus.Text = ex.Message;

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

La de registro la medicamento

namespace Enfermeria

public partial class medicamento : System.Web.UI.Page

string strConSQL = @"Data Source=NOEMI;Initial


Catalog=Enfermeria;Integrated Security=True";

protected void Page_Load(object sender, EventArgs e)

}
protected void BtnEnviar_Click(object sender, EventArgs e)

if (Page.IsValid)

Registrar();

else

lblStatus.Text = "Validacion Incorrecta. Existen Datos


Incorrectos";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

protected void Registrar()

try

//Crear y usar objeto de conexion SQL (conSQL)

using (SqlConnection conSQL = new


SqlConnection(strConSQL))
{

//Abrir Conexion SQL

conSQL.Open();

//String Query SQL

string strSQL = "INSERT INTO [Enfermeria].[dbo].


[medicamento] (nombre_medicamento,clasificacion,
fecha_cad,cantidad, marca) " +

"VALUES (@Nombremed,
@Clasificacion,@Fecha_cad, @Cantidad, @marca)";

//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL,


conSQL);

//Convertir Tipos de Dato

//Parametrizar comando SQL

cmdSQL.Parameters.AddWithValue("@Nombremed",
txtNomMed.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Clasificacion",
txtClasi.Text.Trim());

cmdSQL.Parameters.AddWithValue("@Fecha_cad",
txtFec.Text.Trim());
cmdSQL.Parameters.AddWithValue("@Cantidad",
txtCant.Text.Trim());

cmdSQL.Parameters.AddWithValue("@marca",
txtMarca.Text.Trim());

//Ejecutar comando SQL

cmdSQL.ExecuteNonQuery();

//Liberar Recursos

cmdSQL.Dispose();

//Mensaje Registro Correcto

lblStatus.Text = "Registro Correcto";

lblStatus.Visible = true;

lblStatus.ForeColor = System.Drawing.Color.Green;

lblStatus.Font.Bold = true;

catch (Exception ex)

//Mensaje Excepcion

lblStatus.Text = ex.Message;

lblStatus.Visible = true;
lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;

La de reporte
namespace Enfermeria

public partial class Reporte : System.Web.UI.Page

string strConSQL = @"Data Source=NOEMI;Initial Catalog=Enfermeria;Integrated


Security=True";

//Tabla de Datos

DataTable tablaDatos = new DataTable();

protected void Page_Load(object sender, EventArgs e)

protected void LlenarTabla()

try

{
//Crear y usar objeto de conexion SQL

using (SqlConnection conSQL = new SqlConnection(strConSQL))

//Abrir conexion SQL

conSQL.Open();

//String Query SQL

string strSQL = "SELECT nombre,apellido_pa ,apellido_ma,alergias_med," +

"nombre_medicamento,fecha,hora,carrera FROM[dbo].[informaciongeneral]";

//Crear comando SQL

SqlCommand cmdSQL = new SqlCommand(strSQL, conSQL);

//Crear Adaptador de Datos

SqlDataAdapter adaptadorSQL = new SqlDataAdapter(cmdSQL);

//Llenar la Tabla de Datos

adaptadorSQL.Fill(tablaDatos);

catch (Exception ex)

lblStatus.Text = ex.Message;

lblStatus.ForeColor = System.Drawing.Color.Red;

lblStatus.Font.Bold = true;
}

protected void btnMostrarPDF_Click(object sender, EventArgs e)

//Crear Documento

Document doc = new Document(PageSize.LETTER);

//Definir la escritura y salilda del documento

PdfWriter writer = PdfWriter.GetInstance(doc,

new FileStream(@"C:\Users\Mireya Noemi\Documents\8


SEMESTRE\PROGRAMACION WEB\Reportes\prueba.pdf", FileMode.Create, FileAccess.ReadWrite,
FileShare.None));

// Le colocamos el título y el autor (MetaDatos)

// **Nota: Esto no será visible en el documento

doc.AddAuthor("Mireya Noemi");

doc.AddTitle("Reporte de registro de administración de medicamentos");

//Abrir Documento

doc.Open();

// Creamos el tipo de Font que vamos utilizar

iTextSharp.text.Font _standardFont = new


iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8,
iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
// doc.Add(new Paragraph("Reporte de registro de administración de medicamentos"));

// Creamos la imagen y le ajustamos el tamaño

iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(@"C:\Users\Mireya


Noemi\Documents\8 SEMESTRE\PROGRAMACION WEB\Reportes\banner_1.png");

imagen.BorderWidth = 0;

imagen.Alignment = Element.ALIGN_RIGHT;

float percentage = 0.0f;

percentage = 150 / imagen.Width;

imagen.ScalePercent(percentage * 100);

//Insertar imagen en el documento

doc.Add(imagen);

// Escribimos el encabezamiento en el documento

doc.Add(new Paragraph("Reporte de registro de administración de medicamentos"));

doc.Add(Chunk.NEWLINE);

//Metodo LlenarTabla

LlenarTabla();

//Crear Tabla PDF


PdfPTable tablaPDF = new PdfPTable(5);

foreach (DataColumn col in tablaDatos.Columns)

tablaPDF.AddCell(new Phrase(col.Caption));

foreach (DataRow ren in tablaDatos.Rows)

tablaPDF.AddCell(new Phrase(ren[0].ToString()));

tablaPDF.AddCell(new Phrase(ren[1].ToString()));

tablaPDF.AddCell(new Phrase(ren[2].ToString()));

tablaPDF.AddCell(new Phrase(ren[3].ToString()));

tablaPDF.AddCell(new Phrase(ren[4].ToString()));

tablaPDF.AddCell(new Phrase(ren[5].ToString()));

//Agregamos la Tabla PDF al Documento

doc.Add(tablaPDF);

/*

// Creamos una tabla que contendrá el nombre, apellido y país

// de nuestros visitante.

PdfPTable tblPrueba = new PdfPTable(3);

tblPrueba.WidthPercentage = 100;
// Configuramos el título de las columnas de la tabla

PdfPCell clNombre = new PdfPCell(new Phrase("Nombre", _standardFont));

clNombre.BorderWidth = 0;

clNombre.BorderWidthBottom = 0.75f;

PdfPCell clApellido = new PdfPCell(new Phrase("Apellido", _standardFont));

clApellido.BorderWidth = 0;

clApellido.BorderWidthBottom = 0.75f;

PdfPCell clPais = new PdfPCell(new Phrase("País", _standardFont));

clPais.BorderWidth = 0;

clPais.BorderWidthBottom = 0.75f;

// Añadimos las celdas a la tabla

tblPrueba.AddCell(clNombre);

tblPrueba.AddCell(clApellido);

tblPrueba.AddCell(clPais);

// Llenamos la tabla con información

clNombre = new PdfPCell(new Phrase("Cesar Augusto", _standardFont));

clNombre.BorderWidth = 0;

clApellido = new PdfPCell(new Phrase("Villela Muñoz", _standardFont));

clApellido.BorderWidth = 0;
clPais = new PdfPCell(new Phrase("Mexico", _standardFont));

clPais.BorderWidth = 0;

// Añadimos las celdas a la tabla

tblPrueba.AddCell(clNombre);

tblPrueba.AddCell(clApellido);

tblPrueba.AddCell(clPais);

// Finalmente, añadimos la tabla al documento PDF y cerramos el documento

doc.Add(tblPrueba);

*/

//Cerrar Documento

doc.Close();

writer.Close();

También podría gustarte