Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string archivo = Server.MapPath("productos.json");

                if (File.Exists(archivo))
                {
                    StreamReader jsonStream = File.OpenText(archivo);

                    //se lee todo el contenido del archivo y el contenido se guarda en la variable json
                    string json = jsonStream.ReadToEnd();

                    jsonStream.Close();

                    //Se deserializa (convierte) la cadena json en la estructura que tiene la lista universidades
                    productos = JsonConvert.DeserializeObject <List <Producto> >(json);

                    GridViewProductos.DataSource = productos;
                    GridViewProductos.DataBind();

                    GridView1.DataSource = productos;
                    GridView1.DataBind();
                }
            }
        }
        protected void BTN_Eliminar_Click(object sender, EventArgs e)
        {
            string idFactura = Session["idFactura"].ToString();

            var sqlConn5 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionSQL"].ConnectionString);

            var strSQL5 = "delete from CARRITO where idFacturaF='" + idFactura + "'";

            var cmd5 = new SqlCommand(strSQL5, sqlConn5);

            sqlConn5.Open();
            cmd5.ExecuteNonQuery();
            sqlConn5.Close();



            var sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionSQL"].ConnectionString);

            var strSQL = "select p.nombreProducto Nombre, p.precioProducto Precio, c.cantidadProducto Cantidad, c.PuntosTotales TotalPuntos, c.precioProductoT PrecioTotal from PRODUCTO p, CARRITO c, FACTURA f where p.idProducto=c.idProductoF and c.idFacturaF=f.idFactura and f.idFactura='" + idFactura + "'";
            var cmd    = new SqlCommand(strSQL, sqlConn);

            var ds = new DataSet();
            var da = new SqlDataAdapter(cmd);

            sqlConn.Open();
            da.Fill(ds, "PRODUCTO");
            sqlConn.Close();

            var dt = ds.Tables[0];

            GridViewProductos.DataSource = dt;
            GridViewProductos.DataBind();
        }
Пример #3
0
        protected void ButtonEliminar_Click(object sender, EventArgs e)
        {
            productos.RemoveAt(indice);
            GuardarJson();

            Response.Write("<script>alert('Producto eliminado!')</script>");
            GridViewProductos.DataSource = productos;
            GridViewProductos.DataBind();
            // Limpiar
            txtBuscarProducto.Text = "";
            indice = -1;
        }
Пример #4
0
        protected void ButtonRegistrar_Click(object sender, EventArgs e)
        {
            Producto pro = productos.Find(u => u.Codigo == txtCodigo.Text);

            if (pro != null)
            {
                Response.Write("<script>alert('Este código ya fue registrado!')</script>");
            }
            else
            {
                Producto producto = new Producto();
                producto.Codigo      = txtCodigo.Text;
                producto.Nombre      = txtNombre.Text;
                producto.Descripcion = txtDescripcion.Text;
                producto.Marca       = cmbMarca.SelectedValue;
                producto.Precio      = float.Parse(txtPrecio.Text);
                producto.Existencia  = int.Parse(txtExistencia.Text);
                // Cargar una imagen
                string archivoOrigen = Path.GetFileName(FileUploadImagen.FileName);
                try
                {
                    FileUploadImagen.SaveAs(Server.MapPath("~/Imagenes/") + archivoOrigen);
                    LabelEstado.Text = "Exitosamente Subido";
                }
                catch (Exception ex)
                {
                    LabelEstado.Text = "No se pudo subir, se generó el siguiente error:  " + ex.Message;
                }
                string archivo = "~/imagenes/" + FileUploadImagen.FileName;
                // Lo agregamos a las propiedades de nuestra lista
                producto.Imagen = archivo;

                productos.Add(producto);
                GuardarJson();
                Limpiar();
                Response.Write("<script>alert('Producto registrado!')</script>");
            }

            // Actualizar la tabla con los productos
            GridViewProductos.DataSource = productos;
            GridViewProductos.DataBind();
            // Hacer visible comandos
            LabelBuscarProducto.Visible = true;
            txtBuscarProducto.Visible   = true;
            ButtonBuscar.Visible        = true;
            //
        }
Пример #5
0
 protected void lbtnConsultar_Click(object sender, EventArgs e)
 {
     if (txtCodProducto.Text == "" && txtNombreProd.Text == "" && ddlCategorias.SelectedItem.Text == "Seleccione")
     {
         GridViewProductos.DataSource = null;
         GridViewProductos.DataBind();
         lblerror.Visible = true;
         lblerror.Text    = "Ingrese alguno de los criterios de busqueda";
     }
     else
     {
         GridViewProductos.DataSource = LoPro.dtConsultarProducto(txtCodProducto.Text, txtNombreProd.Text, Convert.ToInt32(ddlCategorias.SelectedValue));
         GridViewProductos.DataBind();
         ddlCategorias.ClearSelection();
         lblerror.Visible = false;
     }
 }
Пример #6
0
    protected void lbtnActualizar_Click(object sender, EventArgs e)
    {
        bool respuesta = LoPro.ActualizarProducto(txtCodProducto.Text, Convert.ToInt32(ddlCategorias.SelectedValue), txtNombreProd.Text, Convert.ToInt32(txtExistenciaActuales.Text), Convert.ToInt32(txtStockMinimo.Text), Convert.ToInt32(txtStockMaximo.Text), Convert.ToInt32(txtCostoCompra.Text), Convert.ToInt32(txtCostoVenta.Text), Convert.ToInt32(TxtCostoXmayor.Text));

        if (respuesta)
        {
            lblMensaje.Text = "Se actualizó de forma correcta el producto";
            limpiar();
            lbtnConsultar.Visible        = true;
            GridViewProductos.DataSource = LoPro.dt_ListarProductos();
            GridViewProductos.DataBind();
        }
        else
        {
            lblerror.Visible = true;
            lblerror.Text    = "Error al actualizar el producto";
        }
    }
Пример #7
0
        protected void ButtonGuardar_Click(object sender, EventArgs e)
        {
            productos[indice].Nombre      = txtModificarNombre.Text;
            productos[indice].Descripcion = txtModificarDescripcion.Text;
            productos[indice].Precio      = float.Parse(txtModificarPrecio.Text);
            productos[indice].Existencia  = Convert.ToInt32(txtModificarExistencia.Text);
            GuardarJson();

            Response.Write("<script>alert('Datos del producto actualizado!')</script>");
            GridViewProductos.DataSource = productos;
            GridViewProductos.DataBind();
            // Mostrar comandos
            LabelBuscarProducto.Visible = true;
            txtBuscarProducto.Visible   = true;
            ButtonBuscar.Visible        = true;
            // Limpiar campo para buscar carné
            txtBuscarProducto.Text = "";
            indice = -1;
        }
Пример #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Leer los datos de la lista Json
                string       archivo    = Server.MapPath("Productos.json");
                StreamReader jsonStream = File.OpenText(archivo);
                string       json       = jsonStream.ReadToEnd();

                jsonStream.Close();
                productos = JsonConvert.DeserializeObject <List <Producto> >(json);
            }
            // Mostar datos
            GridViewProductos.DataSource = productos;
            GridViewProductos.DataBind();
            // Ocultar comandos
            Ocultar();
            // Evitar que se recargue la página hasta arriba
            MaintainScrollPositionOnPostBack = true;
        }
Пример #9
0
 protected void GridViewVentas_SelectedIndexChanged(object sender, EventArgs e)
 {
     indice = GridViewVentas.SelectedIndex;
     GridViewProductos.DataSource = ventas[indice].ProductosVendidos;
     GridViewProductos.DataBind();
 }
Пример #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            /////////////// El tray catch se hace en caso de que no haya ninguna factura
            try
            {
                string idFactura    = Session["idFactura"].ToString();
                double precioP      = 0;
                int    puntos       = 0;
                int    puntosCanjeo = 0;

                //////////////// Se consultan los datos que van a aparecer en el carrito
                var sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionSQL"].ConnectionString);

                var strSQL = "select p.nombreProducto Nombre, p.precioProducto Precio, c.cantidadProducto Cantidad, c.PuntosTotales TotalPuntos, c.precioProductoT PrecioTotal from PRODUCTO p, CARRITO c, FACTURA f where p.idProducto=c.idProductoF and c.idFacturaF=f.idFactura and f.idFactura='" + idFactura + "'";
                var cmd    = new SqlCommand(strSQL, sqlConn);

                var ds = new DataSet();
                var da = new SqlDataAdapter(cmd);

                sqlConn.Open();
                da.Fill(ds, "PRODUCTO");
                sqlConn.Close();

                var dt = ds.Tables[0];

                ////////// Se calculan los punton y el preciotal sumandolos de todos los productos del carrito
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    puntos  = puntos + int.Parse(dt.Rows[i][3].ToString());
                    precioP = precioP + double.Parse(dt.Rows[i][4].ToString());
                }

                /////////// Trae el email del cliente creada en el login
                string MailCliente = Session["CorreoUserLogin"].ToString();

                ////////////// Consulta los puntos acumulados del usuario
                var sqlConn6 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionSQL"].ConnectionString);
                var strSQL6  = "select puntosAcumulados from CUENTA where correoCuenta='" + MailCliente + "'";
                var cmd6     = new SqlCommand(strSQL6, sqlConn6);

                var ds6 = new DataSet();
                var da6 = new SqlDataAdapter(cmd6);

                sqlConn6.Open();
                da6.Fill(ds6, "PRODUCTO");
                sqlConn6.Close();

                var dt6 = ds6.Tables[0];

                int puntosAcumu = int.Parse(dt6.Rows[0][0].ToString());

                /////////// Convierte el precio total del carrito en puntos que son 50 puntos por cada mil pesos que desee comprar

                puntosCanjeo = (Convert.ToInt32(precioP) * 50) / 1000;

                Session["PuntosTo"]     = puntos;
                Session["PrecioTo"]     = precioP;
                Session["puntosCanjeo"] = puntosCanjeo;


                if (puntosCanjeo > puntosAcumu)
                {
                    RadioButtonMetodo.Items.FindByValue("Puntos").Enabled = false; ///////////////////////////////////////**********************************************************
                }

                ///////// Convierte e ingresa los datos del carrito en los label

                LabelPuntosActuales.Text = puntosAcumu.ToString();
                LabelPuntosNece.Text     = puntosCanjeo.ToString();
                TXT_Iva.Text             = (precioP - (precioP / 1.19)).ToString();
                Txt_Puntos.Text          = puntos.ToString();
                Txt_TotPa.Text           = (precioP * 1.19).ToString();

                GridViewProductos.DataSource = dt;
                GridViewProductos.DataBind();

                /////////////////////////////////////////////////////////////// Traer los datos del cliente
                string correo = Session["UserLogin"].ToString();
                var    sql    = new SqlConnection(ConfigurationManager.ConnectionStrings["ConexionSQL"].ConnectionString);
                var    Datos  = "SELECT numDocIdentidad, nombreCuenta, apellidoCuenta, celularUsu FROM CUENTA  WHERE nombreUsuario=" + "'" + correo + "'";
                var    cmdDa  = new SqlCommand(Datos, sql);
                var    dsDa   = new DataSet();
                var    daCo   = new SqlDataAdapter(cmdDa);
                sql.Open();
                daCo.Fill(dsDa, "CUENTA");
                sql.Close();
                var tabDa = dsDa.Tables[0];
                Txt_NumId.Text = tabDa.Rows[0][0].ToString();
                Txt_Nom.Text   = tabDa.Rows[0][1].ToString();
                Txt_Ape.Text   = tabDa.Rows[0][2].ToString();
                Txt_Cel.Text   = tabDa.Rows[0][3].ToString();

                Session["NumId"]  = Txt_NumId.Text;
                Session["Nom"]    = Txt_Nom.Text;
                Session["Ape"]    = Txt_Ape.Text;
                Session["Cel"]    = Txt_Cel.Text;
                Session["Ciudad"] = Txt_Ciudad.Text;
                Session["Dir"]    = Txt_Dir.Text;
                ///////////////////////////////////////////////////////////////
            }
            catch (System.NullReferenceException)
            {
                //Response.Write("<script>window.alert('No has seleccionado ningun producto para crear una factura, por favor selecciona al menos uno');</script>");
                Response.Redirect("~/Carrito/Productos.aspx");
            }
        }
Пример #11
0
 protected void GridViewProductos_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
     GridViewProductos.PageIndex  = e.NewPageIndex;
     GridViewProductos.DataSource = LoPro.dt_ListarProductos();
     GridViewProductos.DataBind();
 }
Пример #12
0
 protected void DropDownListCategoriasB_SelectedIndexChanged(object sender, EventArgs e)
 {
     GridViewProductos.DataSource = Buscar.BproductoCategoria(DropDownListCategoriasB.SelectedValue);
     GridViewProductos.DataBind();
 }