Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["name"] != null)
                {
                }
                else
                {
                    Response.Redirect("http://localhost:60542/", true);
                }

                String         serviceurl = string.Format("http://bd1-p1.azurewebsites.net/api/Maestro");
                HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(serviceurl);

                // Set some reasonable limits on resources used by this request
                // Set credentials to use for this request.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();


                // Get the stream associated with the response.
                Stream receiveStream = response.GetResponseStream();

                // Pipes the stream to a higher level stream reader with the required encoding format.
                StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);


                string strsb = readStream.ReadToEnd();
                System.Diagnostics.Debug.WriteLine("Response stream received.");
                System.Diagnostics.Debug.WriteLine(strsb);
                var model = JsonConvert.DeserializeObject <List <Maestro> >(strsb);
                maestros = new List <Maestro>();
                foreach (Maestro act in model)
                {
                    maestros.Add(act);
                }
                response.Close();
                readStream.Close();
                Lista_Maestro.DataSource     = maestros;
                Lista_Maestro.DataTextField  = "Nombres";
                Lista_Maestro.DataValueField = "Id_maestro";
                Lista_Maestro.DataBind();
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //if (Session["name"] != null)
                //{

                //}
                //else
                //{
                //    Response.Redirect("http://localhost:60542/", true);http://bd1-p1.azurewebsites.net/api/Carrera
                //}


                ///// MAESTROS
                ////-----------------------------------------------------------------------------
                String         serviceurl = string.Format("http://bd1-p1.azurewebsites.net/api/Maestro");
                HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(serviceurl);

                // Set some reasonable limits on resources used by this request
                // Set credentials to use for this request.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();


                // Get the stream associated with the response.
                Stream receiveStream = response.GetResponseStream();

                // Pipes the stream to a higher level stream reader with the required encoding format.
                StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);



                string strsb = readStream.ReadToEnd();
                System.Diagnostics.Debug.WriteLine("Response stream received.");
                System.Diagnostics.Debug.WriteLine(strsb);
                var model = JsonConvert.DeserializeObject <List <Maestro> >(strsb);
                maestros = new List <Maestro>();

                foreach (Maestro act in model)
                {
                    maestros.Add(act);
                }
                response.Close();
                readStream.Close();
                Lista_Maestro.DataSource     = maestros;
                Lista_Maestro.DataTextField  = "Nombres";
                Lista_Maestro.DataValueField = "Id_maestro";
                Lista_Maestro.DataBind();

                //// MAESTROS -------------------------------------------------------------------------------------

                ///// Carreras
                ////-----------------------------------------------------------------------------
                String         serviceurl2 = string.Format("http://bd1-p1.azurewebsites.net/api/Carrera");
                HttpWebRequest request2    = (HttpWebRequest)WebRequest.Create(serviceurl2);

                // Set some reasonable limits on resources used by this request
                // Set credentials to use for this request.
                HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();


                // Get the stream associated with the response.
                Stream receiveStream2 = response2.GetResponseStream();

                // Pipes the stream to a higher level stream reader with the required encoding format.
                StreamReader readStream2 = new StreamReader(receiveStream2, Encoding.UTF8);



                string strsb2 = readStream2.ReadToEnd();
                System.Diagnostics.Debug.WriteLine("Response stream received.");
                System.Diagnostics.Debug.WriteLine(strsb2);
                var model2 = JsonConvert.DeserializeObject <List <Carrera> >(strsb2);
                carreras = new List <Carrera>();

                foreach (Carrera act in model2)
                {
                    carreras.Add(act);
                }
                response2.Close();
                readStream2.Close();
                Lista_Carrera.DataSource     = carreras;
                Lista_Carrera.DataTextField  = "Nombre";
                Lista_Carrera.DataValueField = "Id_carrera";
                Lista_Carrera.DataBind();


                Lista_Grado.Items.Insert(0, "---");
                Lista_Grado.Items.Insert(1, "Cuarto Primaria");

                Lista_Grado.Items.Insert(2, "Quinto Primaria");

                Lista_Grado.Items.Insert(3, "Sexto Primaria");
                Lista_Grado.Items.Insert(4, "Primero Basico");
                //DropDownListNombre.Items.Insert([Nº donde quiero insertar, si es el primero = 0], "CONTENIDO")
            }
        }