예제 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            clsDepartamento departamentoTemp = lstDepartamentos.Find(es => es.NoIdentificacion == txtNoIdentificacion.Text);

            if (departamentoTemp == null)
            {
                string nombre = txtNombre.Text.Trim();
                if (txtNoIdentificacion.Text.Trim().Length > 0 && !(nombre == ""))
                {
                    if (departamentoTemp == null && Convert.ToInt32(txtNoIdentificacion.Text) > 0)
                    {
                        string     fileName = Server.MapPath("Departamentos.txt");
                        FileStream stream;
                        if (lstDepartamentos.Count == 0)
                        {
                            stream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
                        }
                        else
                        {
                            stream = new FileStream(fileName, FileMode.Append, FileAccess.Write);
                        }
                        StreamWriter    writer            = new StreamWriter(stream);
                        clsDepartamento nuevoDepartamento = new clsDepartamento();
                        nuevoDepartamento.NoIdentificacion = txtNoIdentificacion.Text.Trim();
                        nuevoDepartamento.Nombre           = txtNombre.Text.Trim();
                        writer.WriteLine(nuevoDepartamento.NoIdentificacion);
                        writer.WriteLine(nuevoDepartamento.Nombre);
                        writer.Close();
                        this.lstDepartamentos.Add(nuevoDepartamento);
                        GridView1.DataSource = null;
                        GridView1.DataSource = lstDepartamentos;
                        GridView1.DataBind();
                        string script = "alert(\"Se ha registrado el departamento exitosamente.\");";
                        ScriptManager.RegisterStartupScript(this, GetType(),
                                                            "ServerControlScript", script, true);
                        txtNoIdentificacion.Text = "";
                        txtNombre.Text           = "";
                    }
                    else
                    {
                        string script = "alert(\"El numero de identificacion no es valido.\");";
                        ScriptManager.RegisterStartupScript(this, GetType(),
                                                            "ServerControlScript", script, true);
                    }
                }
                else
                {
                    string script = "alert(\"Debe llenar todos los datos.\");";
                    ScriptManager.RegisterStartupScript(this, GetType(),
                                                        "ServerControlScript", script, true);
                }
            }
            else
            {
                string script = "alert(\"El no. de identificación de departamento ya existe.\");";
                ScriptManager.RegisterStartupScript(this, GetType(),
                                                    "ServerControlScript", script, true);
                txtNoIdentificacion.Text = "";
            }
        }
예제 #2
0
        public void mostrarTemp()
        {
            double          tempP   = 0;
            int             cont    = 0;
            clsDepartamento depTemp = lstDepartamentos.Find(d => d.Nombre == DropDownList1.SelectedItem.ToString());

            if (depTemp != null)
            {
                foreach (var t in lstTemperaturas)
                {
                    if (depTemp.NoIdentificacion.Equals(t.NoIdentificacion))
                    {
                        tempP += t.Grados;
                        cont++;
                    }
                }
            }
            lblTempPromedio.Text = "Temperatura promedio en el departamento: " + tempP / cont + "°C";
        }
예제 #3
0
        private void loadData()
        {
            lstDepartamentos = new List <clsDepartamento>();
            string       fileName = Server.MapPath("Departamentos.txt");
            FileStream   stream   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader reader   = new StreamReader(stream);

            while (reader.Peek() > -1)
            {
                clsDepartamento departamentoTemp = new clsDepartamento();
                departamentoTemp.NoIdentificacion = reader.ReadLine();
                departamentoTemp.Nombre           = reader.ReadLine();
                lstDepartamentos.Add(departamentoTemp);
            }
            reader.Close(); if (!IsPostBack)
            {
                if (lstDepartamentos.Count > 0)
                {
                    GridView1.DataSource = null;
                    GridView1.DataSource = lstDepartamentos;
                    GridView1.DataBind();
                }
            }
        }
예제 #4
0
        private void leer()
        {
            lstDepartamentos = new List <clsDepartamento>();
            lstTemperaturas  = new List <clsTemperatura>();
            lstAux           = new List <clsTemp>();
            string       fileName = Server.MapPath("Departamentos.txt");
            FileStream   stream   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader reader   = new StreamReader(stream);

            while (reader.Peek() > -1)
            {
                clsDepartamento departamentoTemp = new clsDepartamento();
                departamentoTemp.NoIdentificacion = reader.ReadLine();
                departamentoTemp.Nombre           = reader.ReadLine();
                lstDepartamentos.Add(departamentoTemp);
            }
            reader.Close();
            string       fileName2 = Server.MapPath("Temperaturas.txt");
            FileStream   stream2   = new FileStream(fileName2, FileMode.Open, FileAccess.Read);
            StreamReader reader2   = new StreamReader(stream2);

            while (reader2.Peek() > -1)
            {
                clsTemperatura temperaturaTemp = new clsTemperatura();
                temperaturaTemp.NoIdentificacion = reader2.ReadLine();
                temperaturaTemp.Grados           = Convert.ToInt32(reader2.ReadLine());
                temperaturaTemp.Fecha            = Convert.ToDateTime(reader2.ReadLine());
                lstTemperaturas.Add(temperaturaTemp);
            }
            reader2.Close();
            foreach (var l in lstTemperaturas)
            {
                foreach (var d in lstDepartamentos)
                {
                    if (l.NoIdentificacion == d.NoIdentificacion)
                    {
                        clsTemp aux = new clsTemp();
                        aux.Temp   = l.Grados;
                        aux.Nombre = d.Nombre;
                        aux.Cent   = aux.Temp + "°C";
                        lstAux.Add(aux);
                    }
                }
            }
            if (!IsPostBack)
            {
                if (lstDepartamentos.Count > 0)
                {
                    DropDownList1.Items.Clear();
                    DropDownList1.DataValueField = "NoIdentificacion";
                    DropDownList1.DataTextField  = "NoIdentificacion";
                    DropDownList1.DataSource     = lstDepartamentos;
                    DropDownList1.DataBind();
                    mostrarDep();
                }
            }
            if (lstTemperaturas.Count > 0)
            {
                GridView1.DataSource = null;
                GridView1.DataSource = lstTemperaturas;
                GridView1.DataBind();
            }
        }
예제 #5
0
        public void mostrarDep()
        {
            clsDepartamento depTemp = lstDepartamentos.Find(d => d.NoIdentificacion == DropDownList1.SelectedItem.ToString());

            txtNombre.Text = depTemp.Nombre;
        }
예제 #6
0
        private void leer()
        {
            lstDepartamentos = new List <clsDepartamento>();
            lstTemperaturas  = new List <clsTemperatura>();
            lstAux           = new List <clsTemp>();
            string       fileName = Server.MapPath("Departamentos.txt");
            FileStream   stream   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader reader   = new StreamReader(stream);

            while (reader.Peek() > -1)
            {
                clsDepartamento departamentoTemp = new clsDepartamento();
                departamentoTemp.NoIdentificacion = reader.ReadLine();
                departamentoTemp.Nombre           = reader.ReadLine();
                lstDepartamentos.Add(departamentoTemp);
            }
            reader.Close();
            string       fileName2 = Server.MapPath("Temperaturas.txt");
            FileStream   stream2   = new FileStream(fileName2, FileMode.Open, FileAccess.Read);
            StreamReader reader2   = new StreamReader(stream2);

            while (reader2.Peek() > -1)
            {
                clsTemperatura temperaturaTemp = new clsTemperatura();
                temperaturaTemp.NoIdentificacion = reader2.ReadLine();
                temperaturaTemp.Grados           = Convert.ToInt32(reader2.ReadLine());
                temperaturaTemp.Fecha            = Convert.ToDateTime(reader2.ReadLine());
                lstTemperaturas.Add(temperaturaTemp);
            }
            reader2.Close();
            temperaturaProm = 0;
            foreach (var l in lstTemperaturas)
            {
                foreach (var d in lstDepartamentos)
                {
                    if (l.NoIdentificacion == d.NoIdentificacion)
                    {
                        clsTemp aux = new clsTemp();
                        aux.Temp   = l.Grados;
                        aux.Nombre = d.Nombre;
                        aux.Cent   = aux.Cent + "°C";// solo aparecera °C
                        // antes: aux.Grados + "°C" para que apareciera valor°C
                        // no se pudo poner una columna en visible false, entonces
                        // se modificó este código para que solo aparezca el "°C"
                        lstAux.Add(aux);
                    }
                }
            }
            if (lstAux2 != null)
            {
                dtgDatos.DataSource = null;
                dtgDatos.DataSource = lstAux2;
                dtgDatos.DataBind();
                lstAux2 = null;
            }
            if (!IsPostBack)
            {
                if (lstDepartamentos.Count > 0)
                {
                    DropDownList1.Items.Clear();
                    DropDownList1.DataValueField = "NoIdentificacion";
                    DropDownList1.DataTextField  = "Nombre";
                    DropDownList1.DataSource     = lstDepartamentos;
                    DropDownList1.DataBind();
                    mostrarTemp();
                    dtgDatos.DataSource = null;
                    dtgDatos.DataSource = lstAux;
                    dtgDatos.DataBind();
                }
            }
            foreach (var l in lstTemperaturas)
            {
                temperaturaProm += l.Grados;
            }
            temperaturaProm = temperaturaProm / lstTemperaturas.Count;
            lblTemp.Text    = temperaturaProm + " °C";
        }