コード例 #1
0
        private async void btnGenOferta_Click(object sender, RoutedEventArgs e)
        {
            var     list = dgProd.Items.OfType <Producto>();
            Boolean pass = false;

            if (list.Count() > 0)
            {
                foreach (var item in list)
                {
                    if (item.Selec == true)
                    {
                        pass = true;
                    }
                }

                if (pass)
                {
                    ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
                    Oferta of = new Oferta();

                    string nombreImagen = txtNombre.Text + "_" + DateTime.Now.ToString();

                    var listaSuc          = dgSuc.Items.OfType <Sucursal>();
                    OfertaHasSucursal ohs = new OfertaHasSucursal();
                    int contOK            = 0;


                    of.ImagenOferta = nombreImagen;
                    of.MinProductos = int.Parse(txtMinProd.Text);
                    of.MaxProductos = int.Parse(txtMaxProd.Text);
                    of.PrecioAntes  = int.Parse(txtPrecioAntes.Text);
                    of.PrecioOferta = int.Parse(txtPrecio.Text);
                    if (chPubOf.IsChecked == true)
                    {
                        of.EstadoOferta = char.Parse(1.ToString());
                    }
                    else
                    {
                        of.EstadoOferta = char.Parse(0.ToString());
                    }
                    of.FechaOferta = dpFecha.SelectedDate;
                    of.IdSucursal  = mainwindow.UsuarioACtual.IdSucursal;

                    of.CategoriaIdOferta = (int)cbCatOf.SelectedValue;
                    of.Nombre            = txtNombre.Text;
                    of.Descripcion       = txtDescOf.Text;
                    of.OfertaDia         = char.Parse("1");

                    string json = of.Serializar();

                    if (proxy.CrearOferta(json))
                    {
                        // inserta tablaaproducto has ofertas

                        ProductoHasOferta pho = new ProductoHasOferta();
                        foreach (var item in list)
                        {
                            if (item.Selec == true)
                            {
                                pho.OfertaId   = of.IdOferta;
                                pho.ProductoId = item.IdProducto;
                                string jerson = pho.Serializar();
                                proxy.CrearProductoHasOferta(jerson);
                            }
                        }
                        // inserta tabla Oferta Has sucursal
                        foreach (var itemSuc in listaSuc)
                        {
                            if (itemSuc.Selec == true)
                            {
                                ohs.OfertaId   = of.IdOferta;
                                ohs.SucursalId = itemSuc.IdSucursal;
                                string jeson = ohs.Serializar();
                                proxy.CrearOfertaHasSucursal(jeson);
                                contOK++;
                            }
                        }



                        /*Envia por ftp imagen adjuntada*/

                        string user = "******";
                        string pw   = "789456123";
                        string FTP  = "ftp://adonisweb.cl/" + nombreImagen;

                        FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTP);
                        request.Method      = WebRequestMethods.Ftp.UploadFile;
                        request.Credentials = new NetworkCredential(user, pw);
                        request.UsePassive  = true;
                        request.UseBinary   = true;
                        request.KeepAlive   = true;
                        FileStream stream = File.OpenRead(rutaNombreImagenOferta);
                        byte[]     buffer = new byte[stream.Length];
                        stream.Read(buffer, 0, buffer.Length);
                        stream.Close();
                        Stream reqStream = request.GetRequestStream();
                        reqStream.Write(buffer, 0, buffer.Length);
                        reqStream.Flush();
                        reqStream.Close();


                        if (contOK > 0)
                        {
                            await this.ShowMessageAsync("Exito", "Oferta creada para " + contOK + " sucursales!");
                        }
                        else
                        {
                            await this.ShowMessageAsync("Error", "No se pudo crear la oferta");
                        }

                        LimpiarControles();

                        contOK = 0;
                    }
                }
                else
                {
                    await this.ShowMessageAsync("Error", "Debe seleccionar uno o mas productos de la lista");
                }
            }
            else
            {
                await this.ShowMessageAsync("Error", "Debe buscar almenos un producto en la lista");
            }
        }
コード例 #2
0
        private void btnGenOferta_Click(object sender, RoutedEventArgs e)
        {
            lblFechaOferta.Content = validador.validarFecha(dpFecha.Text);
            lblMaxProductos.Content = validador.validarMaxCantidad(txtMaxProd.Text);
            lblMinProductos.Content = validador.validarMinCantidad(txtMinProd.Text);
            lblNombre.Content = validador.validarNombre(txtNombre.Text);
            lblPrecioAnterior.Content = validador.validarPrecio(txtPrecioAntes.Text);
            lblPrecioOferta.Content = validador.validarPrecio(txtPrecio.Text);
           

            ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
            Oferta of = new Oferta();

            string nombreImagen = txtNombre.Text + "_" + DateTime.Now.ToString();

            var listaSuc = dgSuc.Items.OfType<Sucursal>();
            OfertaHasSucursal ohs = new OfertaHasSucursal();
            int contOK = 0;


            of.ImagenOferta = nombreImagen;
            of.MinProductos = int.Parse(txtMinProd.Text);
            of.MaxProductos = int.Parse(txtMaxProd.Text);
            of.PrecioAntes = int.Parse(txtPrecioAntes.Text);
            of.PrecioOferta = int.Parse(txtPrecio.Text);
            if (chPubOf.IsChecked == true)
            {
                of.EstadoOferta = char.Parse(1.ToString());
            }
            else
            {
                of.EstadoOferta = char.Parse(0.ToString());
            }
            of.FechaOferta = dpFecha.SelectedDate;
            of.IdSucursal = 1;

            of.CategoriaIdOferta = (int)cbCatOf.SelectedValue;
            of.Nombre = txtNombre.Text;
            of.Descripcion = txtDescOf.Text;
            of.OfertaDia = char.Parse("s");

            string json = of.Serializar();

            if (lblFechaOferta.Content.Equals("OK") && lblMaxProductos.Content.Equals("OK") && lblMinProductos.Content.Equals("OK") && lblNombre.Content.Equals("OK") && lblPrecioAnterior.Content.Equals("OK") && lblPrecioOferta.Content.Equals("OK"))
            {

            }
            else
            {
                if (lblFechaOferta.Content.Equals("OK"))
                {
                    lblFechaOferta.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblFechaOferta.Visibility = Visibility.Visible;
                }

                if (lblMaxProductos.Content.Equals("OK"))
                {
                    lblMaxProductos.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblMaxProductos.Visibility = Visibility.Visible;
                }

                if (lblMinProductos.Content.Equals("OK"))
                {
                    lblMinProductos.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblMinProductos.Visibility = Visibility.Visible;
                }

                if (lblNombre.Content.Equals("OK"))
                {
                    lblNombre.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblNombre.Visibility = Visibility.Visible;
                }

                if (lblPrecioAnterior.Content.Equals("OK"))
                {
                    lblPrecioAnterior.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblPrecioAnterior.Visibility = Visibility.Visible;
                }

                if (lblPrecioOferta.Content.Equals("OK"))
                {
                    lblPrecioOferta.Visibility = Visibility.Hidden;
                }
                else
                {
                    lblPrecioOferta.Visibility = Visibility.Visible;
                }

            }

            if (proxy.CrearOferta(json))
            {
                // inserta tablaaproducto has ofertas
                var list = dgProd.Items.OfType<Producto>();
                ProductoHasOferta pho = new ProductoHasOferta();
                foreach (var item in list)
                {
                    if (item.Selec == true)
                    {
                        pho.OfertaId = of.IdOferta;
                        pho.ProductoId = item.IdProducto;
                        string jerson = pho.Serializar();
                        proxy.CrearProductoHasOferta(jerson);
                    }
                }
                // inserta tabla Oferta Has sucursal
                foreach (var itemSuc in listaSuc)
                {
                    if (itemSuc.Selec == true)
                    {
                        ohs.OfertaId = of.IdOferta;
                        ohs.SucursalId = itemSuc.IdSucursal;
                        string jeson = ohs.Serializar();
                        proxy.CrearOfertaHasSucursal(jeson);
                        contOK++;
                    }
                }



                /*Envia por ftp imagen adjuntada*/

                string user = "******";
                string pw = "789456123";
                string FTP = "ftp://adonisweb.cl/" + nombreImagen;

                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTP);
                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(user, pw);
                request.UsePassive = true;
                request.UseBinary = true;
                request.KeepAlive = true;
                FileStream stream = File.OpenRead(rutaNombreImagenOferta);
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, buffer.Length);
                stream.Close();
                Stream reqStream = request.GetRequestStream();
                reqStream.Write(buffer, 0, buffer.Length);
                reqStream.Flush();
                reqStream.Close();


                if (contOK > 0)
                {
                    MessageBox.Show("OFERTA CREADA PARA " + contOK + "SUCURSALES!");
                }
                else
                {
                    MessageBox.Show("ERROR AL CREAR OFERTA!");
                }
                contOK = 0;
            } 

           
        }