Пример #1
0
        public List <Ruta> GetRutas(String categoria)
        {
            List <Ruta> rutas = new List <Ruta>();

            String sql = "SELECT rutas.* FROM rutas right join categorias on categorias.name='" + categoria + "' where idCategoria=categorias.id ";

            MySqlCommand cmd = new MySqlCommand(sql, connection);

            MySqlDataReader mdr = cmd.ExecuteReader();

            while (mdr.Read())
            {
                Ruta r = new Ruta
                {
                    id          = Convert.ToInt32(mdr[0].ToString()),
                    Origen      = mdr[1].ToString(),
                    Destino     = mdr[2].ToString(),
                    idCategoria = Convert.ToInt32(mdr[3].ToString())
                };
                rutas.Add(r);
            }
            mdr.Close();

            return(rutas);
        }
Пример #2
0
        private void B_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            int    rutaID = Convert.ToInt32(button.ID);
            Ruta   ruta   = bd.GetRuta(rutaID);

            Session["ruta"] = ruta;
            Response.Redirect("ruta.aspx");
        }
Пример #3
0
        public Ruta GetRuta(int id)
        {
            Ruta   r   = new Ruta();
            String sql = "SELECT * FROM rutas where idruta='" + id + "'";

            MySqlCommand cmd = new MySqlCommand(sql, connection);

            MySqlDataReader mdr = cmd.ExecuteReader();

            mdr.Read();
            r.id          = int.Parse(mdr[0].ToString());
            r.Origen      = mdr[1].ToString();
            r.Destino     = mdr[2].ToString();
            r.idCategoria = int.Parse(mdr[3].ToString());
            mdr.Close();
            return(r);
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("loginForm.aspx");
            }
            else if (Session["ruta"] == null)
            {
                Response.Redirect("user.aspx");
            }
            else
            {
            }
            bd = new BD();
            bd.Connect();
            Ruta ruta = (Ruta)Session["ruta"];

            List <Coment> coments = bd.GetComents(ruta.id);
            string        html    = "";

            foreach (Coment c in coments)
            {
                html += "<div>";
                html += "<h4>";
                html += c.nick = bd.GetNick(c.userID) + ":";
                html += "</h4>";
                html += "<p> ";
                html += c.comentarioTexto;
                html += "</p>";
                if (c.imgPath != "")
                {
                    html += "<img src='img/" + c.imgPath + "' alt='Not Found' style='width:200px; heigth:200px'/>";
                }
                html += "<br />";
                html += "</div>";
            }
            divComents.InnerHtml = html;
        }
Пример #5
0
        protected void newComent_Click(object sender, EventArgs e)
        {
            Coment c = new Coment();

            c.comentarioTexto = comment.InnerText;

            if (Uploader.HasFile)
            {
                try
                {
                    if (Uploader.PostedFile.ContentType == "image/jpeg" || Uploader.PostedFile.ContentType == "image/png" || Uploader.PostedFile.ContentType == "image/jpg")
                    {
                        if (Uploader.PostedFile.ContentLength < 102400000)
                        {
                            string filename = Uploader.FileName;
                            Uploader.SaveAs(MapPath("~/img/") + filename);
                            c.imgPath       = filename;
                            labelError.Text = "Upload status: File uploaded!";
                        }
                    }
                    else
                    {
                        labelError.Text = "Upload status: Only Images are accepted!";


                        System.IO.StreamWriter fp;

                        try
                        {
                            fp = System.IO.File.AppendText(Server.MapPath("~/img/") + "log.txt");
                            fp.WriteLine("File is not an image");
                            labelError.Text = "File Succesfully created!";
                            fp.Close();
                        }
                        catch (Exception ex)
                        {
                            labelError.Text = "File Creation failed. Reason is as follows" + ex.ToString();
                        }
                    }
                }
                catch (Exception ex)
                {
                    labelError.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
            else
            {
                c.imgPath = null;
            }
            Ruta ruta = (Ruta)Session["ruta"];

            c.idRuta = ruta.id;
            Usuari user = (Usuari)Session["user"];

            c.userID = int.Parse(user.id);
            if (Page.IsPostBack)
            {
                bd.NewComent(c);
            }
            bd.NewRating(ruta.id, int.Parse(user.id), int.Parse(rating.Text));
            Response.Redirect(Request.Url.AbsoluteUri);
        }