Ejemplo n.º 1
0
 void LlenarGrid()
 {
     using (ProductService.ServiceProductClient cliente = new ServiceProductClient())
     {
         dtgProductos.DataSource = cliente.ListarProductos();
     }
 }
Ejemplo n.º 2
0
        // GET: Promocion
        public ActionResult Promociones()
        {
            ServiceProductClient sc = new ServiceProductClient();

            ViewBag.listProducto = sc.ListarProducto();
            return(View());
        }
Ejemplo n.º 3
0
 void LlenarGrid()
 {
     using (ProductService.ServiceProductClient cliente = new ServiceProductClient())
     {
         dtgCategorias.DataSource = cliente.ListarCategorias();
     }
 }
Ejemplo n.º 4
0
 private void btnBuscar_Click(object sender, EventArgs e)
 {
     if (txtBuscar.Text != "")
     {
         using (ServiceProductClient cliente = new ServiceProductClient())
         {
             dtgProductos.DataSource = cliente.Filtrar(txtBuscar.Text);
         }
     }
 }
Ejemplo n.º 5
0
        private void dtgCategorias_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dtgCategorias.CurrentRow.Cells[0].Value.ToString());

            using (ServiceProductClient cliente = new ServiceProductClient())
            {
                var categoria = cliente.VerCategoria(id);
                txtNombre.Text      = categoria.Nombre;
                txtDescripcion.Text = categoria.Descripcion;
                CategoriaId         = categoria.CategoriaId;
            }
            btnCrear.Text       = "Actualizar";
            btnEliminar.Visible = true;
        }
Ejemplo n.º 6
0
        private void dtgProductos_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dtgProductos.CurrentRow.Cells[0].Value.ToString());

            using (ServiceProductClient cliente = new ServiceProductClient())
            {
                var producto = cliente.VerProducto(id);
                txtNombre.Text      = producto.Nombre;
                txtDescripcion.Text = Convert.ToString(producto.Precio);
                txtStock.Text       = Convert.ToString(producto.Stock);
                ProductoId          = producto.ProductoId;
            }
            btnCrear.Text       = "Actualizar";
            btnEliminar.Visible = true;
        }
Ejemplo n.º 7
0
 private void btnCrear_Click(object sender, EventArgs e)
 {
     if (txtDescripcion.Text != "" && txtNombre.Text != "" && txtStock.Text != "")
     {
         Producto producto = new Producto();
         producto.Nombre = txtNombre.Text.Trim();
         producto.Precio = Convert.ToDecimal(txtDescripcion.Text.Trim());
         producto.Stock  = Convert.ToInt32(txtStock.Text.Trim());
         using (ServiceProductClient cliente = new ServiceProductClient())
         {
             if (btnCrear.Text == "Guardar")
             {
                 var exito = cliente.CrearProducto(producto);
                 if (exito)
                 {
                     MessageBox.Show("Producto creado con éxito", "Creado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     LlenarGrid();
                     LimpiarCampos();
                 }
                 else
                 {
                     MessageBox.Show("Algo salió mal, inténtelo nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 producto.ProductoId = ProductoId;
                 var exito = cliente.ActualizarProducto(producto);
                 if (exito)
                 {
                     MessageBox.Show("Producto actualizado con éxito", "Actualizado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     LlenarGrid();
                     LimpiarCampos();
                 }
                 else
                 {
                     MessageBox.Show("Algo salió mal, inténtelo nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Debe rellenar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 8
0
        private void btnCrear_Click(object sender, EventArgs e)
        {
            if (txtDescripcion.Text != "" && txtNombre.Text != "")
            {
                Categoria categoria = new Categoria();
                categoria.Nombre      = txtNombre.Text.Trim();
                categoria.Descripcion = txtDescripcion.Text.Trim();

                using (ServiceProductClient cliente = new ServiceProductClient())
                {
                    if (btnCrear.Text == "Guardar")
                    {
                        var exito = cliente.CrearCategoria(categoria);
                        if (exito)
                        {
                            MessageBox.Show("Categoría creada con éxito", "Creada", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LlenarGrid();
                            LimpiarCampos();
                        }
                        else
                        {
                            MessageBox.Show("Algo salió mal, inténtelo nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        categoria.CategoriaId = CategoriaId;
                        var exito = cliente.ActualizarCategoria(categoria);
                        if (exito)
                        {
                            MessageBox.Show("Categoría actualizada con éxito", "Actualizada", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LlenarGrid();
                            LimpiarCampos();
                        }
                        else
                        {
                            MessageBox.Show("Algo salió mal, inténtelo nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Debe rellenar todos los campos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 9
0
 private void btnEliminar_Click(object sender, EventArgs e)
 {
     using (ServiceProductClient cliente = new ServiceProductClient())
     {
         var exito = cliente.EliminarProducto(ProductoId);
         if (exito)
         {
             MessageBox.Show("Producto eliminado con éxito", "Eliminado", MessageBoxButtons.OK, MessageBoxIcon.Information);
             LlenarGrid();
             LimpiarCampos();
             btnEliminar.Visible = false;
         }
         else
         {
             MessageBox.Show("Algo salió mal, inténtelo nuevamente", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Ejemplo n.º 10
0
        // GET: Catalogo
        public ActionResult Productos()
        {
            //    List<Producto> product = new List<Producto>();
            //    string urlAction = String.Format("/ServiceProductos.svc/rest/listar-productos");
            //    product = await GetWSObject<Producto>(urlAction);

            ServiceProductClient sc = new ServiceProductClient();

            ViewBag.listProducto = sc.ListarProducto();

            //ViewData["productos"] = sc.ListarProducto();



            return(View());
            //WebClient proxy = new WebClient();
            //byte[] data = proxy.DownloadData("http://lplaparis.azurewebsites.net/ServiceProductos.svc/rest/listar-productos");
            //Stream stream = new MemoryStream(data);
            //DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(Producto));

            //var re = obj.ReadObject(stream) as Producto;
            //string Result = obj.ReadObject(stream).ToString();



            //List<Categoria> c = new List<Categoria>();
            ////c.Add(new Categoria("Nombre"));
            //c.Add(new Categoria("Nombre"));
            //c.Add(new Categoria("Nombre"));
            //c.Add(new Categoria("Nombre"));
            //c.Add(new Categoria("Nombre"));
            //c.Add(new Categoria("Nombre"));

            //ViewData["categoria"] = Result.ToList();


            //List<Producto> p = new List<Producto>();
        }