Exemple #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string url = fu_url.FileName;

            if (fu_url.HasFile)
            {
                fu_url.SaveAs(Server.MapPath("/images/" + url));
            }
            url = "/images/" + url;



            clases.Productos p   = new clases.Productos(DropDownList2.SelectedValue, detalleproducto.Text, precioproducto.Text, nombreproducto.Text, url, "");
            float            pre = 0;


            if (detalleproducto.Text != string.Empty && precioproducto.Text != string.Empty && DropDownList2.SelectedValue != "")
            {
                try
                {
                    pre = float.Parse(precioproducto.Text);
                    precioproducto.Text = precioproducto.Text.Replace(",", ".");
                }
                catch (Exception)
                {
                    Session["error"] = "Recuerde que en precio van solo numeros, enteros o con coma";
                }
                if (pre != 0)
                {
                    if (p.insert_into() == 1)
                    {
                        Session["msj"] = "Articulo dado de alta exitosamente";
                        Response.Redirect("Productos.aspx");
                    }
                    else
                    {
                        Session["error"] = "No se ha podido dar de alta al articulo";
                    }
                }
                else
                {
                    Session["error"] = "Recuerde que el precio debe ser un numero y puede tener , o .";
                }
            }
            else
            {
                Session["error"] = "No se permiten campos vacios.";
            }
        }
Exemple #2
0
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //actualizar la wea

            string tipo    = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue;
            string detalle = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;
            string precio  = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox2")).Text;
            string codigo  = ((Label)GridView1.Rows[e.RowIndex].FindControl("l_articulo2")).Text;
            //string url = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("tb_url")).Text;

            string url = ((FileUpload)GridView1.Rows[e.RowIndex].FindControl("fu_url2")).FileName;

            if (((FileUpload)GridView1.Rows[e.RowIndex].FindControl("fu_url2")).HasFile)
            {
                ((FileUpload)GridView1.Rows[e.RowIndex].FindControl("fu_url2")).SaveAs(Server.MapPath("/images/" + url));
            }
            url = "/images/" + url;


            float p = 0;

            try
            {
                p      = float.Parse(precio);
                precio = precio.Replace(",", ".");
            }
            catch (Exception)
            {
                Session["error"] = "Recuerde que en precio van solo numeros, enteros o con coma";
            }

            if (p != 0)
            {
                clases.Productos s = new clases.Productos(tipo, detalle, precio, url, codigo);
                if (s.update() != 1)
                {
                    this.Session["error"] = "No se ha actualizado correctamente el producto";
                }
                else
                {
                    this.Session["msj"] = "Cambio hecho correctamente.";
                    GridView1.EditIndex = -1;
                    cargartabla();
                }
            }
        }