protected void rowUpdatingEvent(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow fila   = Grid.Rows[e.RowIndex];
            int         codigo = Convert.ToInt32(Grid.DataKeys[e.RowIndex].Values[0]);

            string clinica     = (fila.FindControl("TextClinica") as TextBox).Text;
            string descripcion = (fila.FindControl("TextDescripcion") as TextBox).Text;


            if (Grid.DataKeys[e.RowIndex].Value.ToString() == null)
            {
            }
            else
            {
                string       sql           = "update CLINICAS set CLINICA = '" + clinica + "', DESCRIPCION = '" + descripcion + "' where ID_CLINICA = " + Grid.DataKeys[e.RowIndex].Value.ToString();
                MostrarDatos clas_consulta = new MostrarDatos();

                if (clas_consulta.non_query(sql))
                {
                    obtenerClinica();
                    Response.Write("<script>alert('MODIFICACIÓN REALIZADA EXITOSAMENTE')</script>");
                }
                else
                {
                    Response.Write("<script>alert('NO SE HA PODIDO MODIFICAR')</script>");
                }
            }

            Grid.EditIndex = -1;
            obtenerClinica();
        }
        protected string ObtnerDatosMunicipio()
        {
            MostrarDatos  md          = new MostrarDatos();
            string        con         = MostrarDatos.CadenaConexion;
            SqlConnection conexionSQL = new SqlConnection(con);
            SqlCommand    cmd         = new SqlCommand();

            cmd.CommandText = "SELECT  MUNICIPIO, COUNT(MUNICIPIO) AS CANTIDAD FROM PACIENTES " +
                              "WHERE FECHA_INGRESO between '" + fechaini4.Value + "' and '" + fechafin4.Value + "' GROUP BY MUNICIPIO;";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conexionSQL;
            conexionSQL.Open();

            DataTable Datos = new DataTable();

            Datos.Load(cmd.ExecuteReader());
            conexionSQL.Close();



            string strDatos;

            strDatos = "[['Genero', 'Cantidad'],";

            foreach (DataRow dr in Datos.Rows)
            {
                strDatos = strDatos + "[";
                strDatos = strDatos + "'" + dr[0] + "'" + "," + dr[1];
                strDatos = strDatos + "],";
            }

            strDatos = strDatos + "]";

            return(strDatos);
        }
        public void llenarTurnos()
        {
            MostrarDatos md = new MostrarDatos();

            md.clinica1();

            lbldocclinica1.Text  = md.doc;
            lblpaclinica1.Text   = md.paciente;
            Lblcontclinica1.Text = md.turno;

            md.clinica2();

            lbldocclinica2.Text  = md.doc2;
            lblpaclinica2.Text   = md.paciente2;
            lblcontclinica2.Text = md.turno2;

            md.clinica3();
            lbldocclinica3.Text  = md.doc3;
            lblpaclinica3.Text   = md.paciente3;
            lblcontclinica3.Text = md.turno3;

            md.clinica4();
            Lbldocclinica4.Text  = md.doc4;
            Lblpaclinica4.Text   = md.paciente4;
            Lblcontclinica4.Text = md.turno4;

            md.clinica5();
            Lbldocclinica5.Text  = md.doc5;
            Lblpaclinica5.Text   = md.paciente5;
            Lblcontclinica5.Text = md.turno5;
        }
        protected string ObtnerDatosGeneroConRango()
        {
            MostrarDatos  md          = new MostrarDatos();
            string        con         = MostrarDatos.CadenaConexion;
            SqlConnection conexionSQL = new SqlConnection(con);
            SqlCommand    cmd         = new SqlCommand();

            cmd.CommandText = "SELECT CASE P.GENERO WHEN 'Masculino' THEN 'Masculino' WHEN 'Femenino' THEN 'Femenino' ELSE '' END AS GENERO, " +
                              "COUNT(case when DATEDIFF(YEAR, FECHA_NAC, GETDATE()) >= 0 AND DATEDIFF(YEAR, FECHA_NAC, GETDATE()) <= 10 then 1 end) AS DE_0_A_10," +
                              " COUNT(case when DATEDIFF(YEAR, FECHA_NAC, GETDATE()) >= 11 AND DATEDIFF(YEAR, FECHA_NAC, GETDATE()) <= 25 then 1 end) AS DE_11_A_25, " +
                              "COUNT(case when DATEDIFF(YEAR, FECHA_NAC, GETDATE()) >= 26 AND DATEDIFF(YEAR, FECHA_NAC, GETDATE()) <= 50 then 1 end) AS DE_26_A_50, " +
                              "COUNT(case when DATEDIFF(YEAR, FECHA_NAC, GETDATE()) >= 51 AND DATEDIFF(YEAR, FECHA_NAC, GETDATE()) <= 65 then 1 end) AS DE_51_A_65, " +
                              "COUNT(case when DATEDIFF(YEAR, FECHA_NAC, GETDATE()) >= 66 then 1 end) AS MAYOR_A_66  " +
                              "FROM PACIENTES P WHERE P.FECHA_INGRESO between '" + fechaini2.Value + "' and '" + fechafin2.Value + "' group by GENERO";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conexionSQL;
            conexionSQL.Open();

            DataTable Datos = new DataTable();

            Datos.Load(cmd.ExecuteReader());
            conexionSQL.Close();

            string strDatos;

            strDatos = "[['Genero', '0 - 10 Años', '11 - 25 Años', '26 - 50 Años', '51 - 65 Años', 'Mayor a 66 Años'],";

            foreach (DataRow dr in Datos.Rows)
            {
                strDatos = strDatos + "[";
                strDatos = strDatos + "'"
                           + dr[0] + "', "
                           + dr[1] + ", "
                           + dr[2] + ", "
                           + dr[3] + ", "
                           + dr[4] + ", "
                           + dr[5];
                strDatos = strDatos + "],";
            }
            strDatos = strDatos + "]";
            return(strDatos);
        }
        protected string ObtnerDatosTurnosMedicos()
        {
            MostrarDatos  md          = new MostrarDatos();
            string        con         = MostrarDatos.CadenaConexion;
            SqlConnection conexionSQL = new SqlConnection(con);
            SqlCommand    cmd         = new SqlCommand();

            cmd.CommandText = "SELECT(d.NOMBRE + ' ' + d.APELLIDO)AS MEDICO," +
                              " COUNT (CASE WHEN t.ESTADO = 2 then 1 end) as Atendidos,	" +
                              "COUNT(CASE WHEN t.ESTADO = 3 then 1 end) as Suspendidos," +
                              "COUNT(CASE WHEN t.ESTADO = 4 then 1 end) as Cancelados FROM MEDICO d " +
                              "inner join TURNOS t on(t.ID_MEDICO = d.ID_MEDICO)" +
                              "WHERE t.FECHA_INGRESO between '" + fechaini5.Value + "' and '" + fechafin5.Value + "'" +
                              " group by t.ID_MEDICO, d.NOMBRE, d.APELLIDO; ";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conexionSQL;
            conexionSQL.Open();

            DataTable Datos = new DataTable();

            Datos.Load(cmd.ExecuteReader());
            conexionSQL.Close();

            string strDatos;

            strDatos = "[['Medico', 'Atendidos', 'Suspendidos', 'Cancelados'],";

            foreach (DataRow dr in Datos.Rows)
            {
                strDatos = strDatos + "[";
                strDatos = strDatos + "'"
                           + dr[0] + "', "
                           + dr[1] + ", "
                           + dr[2] + ", "
                           + dr[3];
                strDatos = strDatos + "],";
            }
            strDatos = strDatos + "]";
            return(strDatos);
        }
        protected void Grid_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (Grid.DataKeys[e.RowIndex].Value.ToString() == null)
            {
            }
            else
            {
                string       sql           = "update CLINICAS set ESTADO ='2' where ID_CLINICA =" + Grid.DataKeys[e.RowIndex].Value.ToString();
                MostrarDatos clas_consulta = new MostrarDatos();

                if (clas_consulta.non_query(sql))
                {
                    obtenerClinica();
                    Response.Write("<script>alert('ELIMINADO EXITOSAMENTE')</script>");
                }
                else
                {
                    Response.Write("<script>alert('NO SE HA PODIDO ELIMINAR')</script>");
                }
            }

            obtenerClinica();
        }
        protected string ObtnerDatosNiñoAdulto()
        {
            MostrarDatos  md          = new MostrarDatos();
            string        con         = MostrarDatos.CadenaConexion;
            SqlConnection conexionSQL = new SqlConnection(con);
            SqlCommand    cmd         = new SqlCommand();

            cmd.CommandText = " SELECT CASE P.GENERO WHEN 'Masculino' THEN 'Masculino' WHEN 'Femenino' THEN 'Femenino'" +
                              " ELSE ''END AS GENERO," +
                              "COUNT(CASE WHEN DATEDIFF(YEAR, FECHA_NAC, GETDATE()) < 18 then 1 end) as Niños," +
                              "COUNT(CASE WHEN DATEDIFF(YEAR, FECHA_NAC, GETDATE()) >= 18 then 1 end) as Adultos" +
                              " FROM PACIENTES P WHERE P.FECHA_INGRESO between '" + fechaini3.Value + "' and '" + fechafin3.Value + "' group by GENERO";
            cmd.CommandType = CommandType.Text;
            cmd.Connection  = conexionSQL;
            conexionSQL.Open();

            DataTable Datos = new DataTable();

            Datos.Load(cmd.ExecuteReader());
            conexionSQL.Close();

            string strDatos;

            strDatos = "[['Genero','Niños', 'Adultos'],";

            foreach (DataRow dr in Datos.Rows)
            {
                strDatos = strDatos + "[";
                strDatos = strDatos + "'" + dr[0] + "'" + "," + dr[1] + "," + dr[2];
                strDatos = strDatos + "],";
            }

            strDatos = strDatos + "]";

            return(strDatos);
        }