private void btnIngresar_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (cbxProveedor.SelectedValue != null)
         {
             if (cbxSucursal.SelectedValue != null)
             {
                 if (cbxMoneda.SelectedValue != null)
                 {
                     if (cbxEmpleado.SelectedValue != null)
                     {
                         OrdenPedidoNEG ordenPedidoNEG  = new OrdenPedidoNEG();
                         int            proveedor       = int.Parse(cbxProveedor.SelectedValue.ToString());
                         int            sucursal        = int.Parse(cbxSucursal.SelectedValue.ToString());
                         string         emailSucursal   = txtEmailSucursal.Text.ToString();
                         int            tipoMultimoneda = int.Parse(cbxMoneda.SelectedValue.ToString());
                         int            empleado        = int.Parse(cbxEmpleado.SelectedValue.ToString());
                         string         emailProveedor  = txtEmailProveedor.Text.ToString();
                         DataTable      tabla           = ((DataView)dgProductos.ItemsSource).ToTable();
                         string         respuesta       = ordenPedidoNEG.CrearOrdenPedido(proveedor, sucursal, emailSucursal, tipoMultimoneda, empleado, emailProveedor, tabla);
                         if (respuesta == "creado")
                         {
                             Limpiar();
                             MessageBox.Show("La orden de pedido ha sido ingresada satisfactoriamente. La orden se encuentra en espera de aprobación para ser enviada");
                         }
                         else
                         {
                             MessageBox.Show(respuesta);
                         }
                     }
                     else
                     {
                         MessageBox.Show("Debe seleccionar un empleado");
                     }
                 }
                 else
                 {
                     MessageBox.Show("Debe seleccionar una moneda");
                 }
             }
             else
             {
                 MessageBox.Show("Debe seleccionar una sucursal");
             }
         }
         else
         {
             MessageBox.Show("Debe seleccionar un proveedor");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
     }
 }
Beispiel #2
0
        public void CargarTablaOrdenesPedido()
        {
            dgOrdenPedido.ItemsSource = null;
            DataTable      tabla          = new DataTable();
            OrdenPedidoNEG ordenPedidoNEG = new OrdenPedidoNEG();

            try
            {
                List <OrdenPedidoVIEW> lista = ordenPedidoNEG.ListarTodasOrdenesPedidos();
                tabla.Columns.Add("ID");
                tabla.Columns.Add("FOLIO");
                tabla.Columns.Add("FECHA CREACION");
                tabla.Columns.Add("SUCURSAL");
                tabla.Columns.Add("RUT PROVEEDOR");
                tabla.Columns.Add("PROVEEDOR");
                tabla.Columns.Add("MONTO TOTAL");
                tabla.Columns.Add("CANTIDAD ART");
                tabla.Columns.Add("FECHA ENTREGA");
                tabla.Columns.Add("ESTADO");
                tabla.Columns.Add("EMPLEADO RESPONSABLE");
                tabla.Columns.Add("MONEDA");
                tabla.Columns.Add("TOTAL MONEDA");
                tabla.Columns.Add("FECHA ACTUALIZACION");

                if (lista.Count > 0)
                {
                    foreach (var x in lista)
                    {
                        string folio = x.ID.ToString();
                        for (int i = 0; i < 9; i++)
                        {
                            if (folio.Length < 8)
                            {
                                folio = "0" + folio;
                            }
                        }
                        string cantidad = x.CANTIDAD_TOTAL.ToString();
                        string costo1   = string.Format("{0:n2}", x.MONTO_TOTAL);
                        string costo2   = string.Format("{0:n2}", (Math.Truncate((Convert.ToDecimal(x.MONTO_TOTAL) / Convert.ToDecimal(x.VALOR_MULTIMONEDA)))));
                        tabla.Rows.Add(x.ID, folio, x.FECHA_CREACION, x.SUCURSAL, x.NUMID_PROVEEDOR + "-" + x.DIVID_PROVEEDOR, x.PROVEEDOR,
                                       costo1, cantidad, x.FECHA_ENTREGA, x.ESTADO_ORDEN_PEDIDO, x.NOMBRE_EMPLEADO + " " + x.APELLIDO_EMPLEADO + " " + x.NUMID_EMPLEADO + "-" + x.DIVID_EMPLEADO,
                                       x.MULTI_MONEDA, costo2, x.FECHA_ULTIMO_UPDATE);
                    }
                }
                dgOrdenPedido.ItemsSource = tabla.DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
            }
        }
Beispiel #3
0
        private void CargarOrdenPedido(DataRow dataRow)
        {
            int            idOrden        = int.Parse(dataRow["ID"].ToString());
            OrdenPedidoNEG ordenPedidoNEG = new OrdenPedidoNEG();

            ordenPedidoCarga = ordenPedidoNEG.CargarOrdenPedido(idOrden);
            if (ordenPedidoCarga.ESTADO_ORDEN_PEDIDO_ID == 3 || ordenPedidoCarga.ESTADO_ORDEN_PEDIDO_ID == 4)
            {
                btnAgregaProducto.IsEnabled = false;
                btnQuitarProducto.IsEnabled = false;
                btnEnviar.IsEnabled         = false;
                btnRechazar.IsEnabled       = false;
                btnEliminar.IsEnabled       = false;
            }
        }
Beispiel #4
0
 private void btnGuadar_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (cbxMoneda.SelectedValue != null)
         {
             if (cbxEmpleado.SelectedValue != null)
             {
                 OrdenPedidoNEG ordenPedidoNEG     = new OrdenPedidoNEG();
                 int            proveedor          = ordenPedidoCarga.PROVEEDOR_ID;
                 int            sucursal           = ordenPedidoCarga.SUCURSAL_ID;
                 string         emailSucursal      = txtEmailSucursal.Text.ToString();
                 int            tipoMultimoneda    = int.Parse(cbxMoneda.SelectedValue.ToString());
                 int            empleado           = int.Parse(cbxEmpleado.SelectedValue.ToString());
                 string         emailProveedor     = txtEmailProveedor.Text.ToString();
                 DateTime       fechaActualizacion = Convert.ToDateTime(dpkFechaModificacion.SelectedDate);
                 DataTable      tabla     = ((DataView)dgProductos.ItemsSource).ToTable();
                 string         respuesta = ordenPedidoNEG.ActualizarOrdenPedido(ordenPedidoCarga, proveedor, sucursal, emailSucursal, tipoMultimoneda, empleado, emailProveedor, fechaActualizacion, tabla);
                 if (respuesta == "actualizado")
                 {
                     MessageBox.Show("La orden de pedido ha sido actualizada satisfactoriamente");
                 }
                 else
                 {
                     MessageBox.Show(respuesta);
                 }
             }
             else
             {
                 MessageBox.Show("Debe seleccionar un empleado");
             }
         }
         else
         {
             MessageBox.Show("Debe seleccionar una moneda");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
     }
 }
Beispiel #5
0
 private void btnRechazar_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MessageBox.Show("Espere mientras se rechaza la orden de pedido. Presione 'Aceptar' para comenzar");
         OrdenPedidoNEG ordenPedidoNEG = new OrdenPedidoNEG();
         string         respuesta      = ordenPedidoNEG.RechazarOrdenPedido(ordenPedidoCarga.ID);
         if (respuesta == "rechazada")
         {
             ordenPedidoCarga.ESTADO_ORDEN_PEDIDO_ID = 2;
             modificarPedido.CargarTablaOrdenesPedido();
             MessageBox.Show("La orden de pedido ha sido rechazada satisfactoriamente");
         }
         else
         {
             MessageBox.Show(respuesta);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
     }
 }
Beispiel #6
0
 private void btnEliminar_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         MessageBox.Show("Espere mientras se elimina la orden de pedido. Presione 'Aceptar' para comenzar");
         OrdenPedidoNEG ordenPedidoNEG = new OrdenPedidoNEG();
         string         respuesta      = ordenPedidoNEG.EliminarOrdenPedido(ordenPedidoCarga.ID);
         if (respuesta == "eliminado")
         {
             modificarPedido.CargarTablaOrdenesPedido();
             MessageBox.Show("La orden de pedido ha sido eliminada satisfactoriamente");
             this.Close();
         }
         else
         {
             MessageBox.Show(respuesta);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
     }
 }
Beispiel #7
0
        private void btnEnviar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cbxFolio.SelectedValue != null)
                {
                    string motivo   = txtMotivo.Text;
                    string emailPro = txtEmailProveedor.Text;
                    string emailSuc = txtEmailSucursal.Text;
                    if (motivo.Trim().Length >= 10)
                    {
                        if (emailPro.Trim().Length >= 5)
                        {
                            if (emailSuc.Trim().Length >= 5)
                            {
                                MessageBox.Show("Espere mientras el documento es generado. Presione 'Aceptar' para comenzar");
                                int    idFolio = int.Parse(cbxFolio.SelectedValue.ToString());
                                string folio   = idFolio.ToString();
                                for (int i = 0; i < 9; i++)
                                {
                                    if (folio.Length < 8)
                                    {
                                        folio = "0" + folio;
                                    }
                                }
                                ExportarArchivos      pdf                   = new ExportarArchivos();
                                PDF_ModeloDevolucion  modelo                = new PDF_ModeloDevolucion();
                                OrdenPedidoNEG        ordenPedidoNEG        = new OrdenPedidoNEG();
                                OrdenPedidoVIEW       orden                 = new OrdenPedidoVIEW();
                                DetalleOrdenPedidoNEG detalleOrdenPedidoNEG = new DetalleOrdenPedidoNEG();
                                orden                     = ordenPedidoNEG.CargarOrdenPedido(idFolio);
                                modelo.Sucursal           = orden.SUCURSAL;
                                modelo.Folio              = folio;
                                modelo.NombreProveedor    = orden.PROVEEDOR;
                                modelo.RolProveedor       = orden.NUMID_PROVEEDOR + "-" + orden.DIVID_PROVEEDOR;
                                modelo.Motivo             = motivo;
                                modelo.EmailProveedor     = emailPro;
                                modelo.EmailSucursal      = emailSuc;
                                modelo.DetalleOrdenPedido = detalleOrdenPedidoNEG.CargarlistaDetalleOrden(idFolio);

                                ServerCorreo abrir_server = new ServerCorreo();
                                Correo       correoM      = new Correo();
                                //parametriza el servidor STMP para enviar el correo
                                SmtpClient server = abrir_server.InstanciaServer();

                                string respuesta = pdf.DevolucionPedidoPDF(modelo);

                                //Instancia la libreria que permite armar correo electronico y llama el metodo que lo crea
                                MailMessage email = correoM.CorreoDevolucionPedido(respuesta, emailSuc, emailPro, modelo.NombreProveedor, folio, motivo);
                                //envia el correo
                                server.Send(email);


                                MessageBox.Show("El documento se genero correctamente. Ubíquelo en 'Mis Documentos'");
                            }
                            else
                            {
                                MessageBox.Show("Debe indicar un correo de la sucursal");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Debe indicar un correo del proveedor");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Debe indicar un motivo de la menos 10 caracteres");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar solo una fila");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
            }
        }
Beispiel #8
0
        private void btnBuscar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cbxTipoBusqueda.SelectedValue != null)
                {
                    if (cbxTextoBusqueda.SelectedValue != null)
                    {
                        string tipo  = cbxTipoBusqueda.Text;
                        int    valor = int.Parse(cbxTextoBusqueda.SelectedValue.ToString());
                        dgOrdenPedido.ItemsSource = null;
                        DataTable              tabla          = new DataTable();
                        OrdenPedidoNEG         ordenPedidoNEG = new OrdenPedidoNEG();
                        List <OrdenPedidoVIEW> lista          = ordenPedidoNEG.FiltrarOrdenesPedidos(tipo, valor);
                        tabla.Columns.Add("ID");
                        tabla.Columns.Add("FOLIO");
                        tabla.Columns.Add("FECHA CREACION");
                        tabla.Columns.Add("SUCURSAL");
                        tabla.Columns.Add("RUT PROVEEDOR");
                        tabla.Columns.Add("PROVEEDOR");
                        tabla.Columns.Add("MONTO TOTAL");
                        tabla.Columns.Add("CANTIDAD ART");
                        tabla.Columns.Add("FECHA ENTREGA");
                        tabla.Columns.Add("ESTADO");
                        tabla.Columns.Add("EMPLEADO RESPONSABLE");
                        tabla.Columns.Add("MONEDA");
                        tabla.Columns.Add("TOTAL MONEDA");
                        tabla.Columns.Add("FECHA ACTUALIZACION");

                        if (lista.Count > 0)
                        {
                            foreach (var x in lista)
                            {
                                string folio = x.ID.ToString();
                                for (int i = 0; i < 9; i++)
                                {
                                    if (folio.Length < 8)
                                    {
                                        folio = "0" + folio;
                                    }
                                }
                                string cantidad = x.CANTIDAD_TOTAL.ToString();
                                string costo1   = string.Format("{0:n2}", x.MONTO_TOTAL);
                                string costo2   = string.Format("{0:n2}", (Math.Truncate((Convert.ToDecimal(x.MONTO_TOTAL) / Convert.ToDecimal(x.VALOR_MULTIMONEDA)))));
                                tabla.Rows.Add(x.ID, folio, x.FECHA_CREACION, x.SUCURSAL, x.NUMID_PROVEEDOR + "-" + x.DIVID_PROVEEDOR, x.PROVEEDOR,
                                               costo1, cantidad, x.FECHA_ENTREGA, x.ESTADO_ORDEN_PEDIDO, x.NOMBRE_EMPLEADO + " " + x.APELLIDO_EMPLEADO + " " + x.NUMID_EMPLEADO + "-" + x.DIVID_EMPLEADO,
                                               x.MULTI_MONEDA, costo2, x.FECHA_ULTIMO_UPDATE);
                            }
                        }
                        else
                        {
                            MessageBox.Show("No existen ordenes de pedidos registrados para los filtros indicados");
                        }
                        dgOrdenPedido.ItemsSource = tabla.DefaultView;
                    }
                    else
                    {
                        MessageBox.Show("Debe seleccionar el filtro de busqueda");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un tipo de busqueda");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
            }
        }
Beispiel #9
0
        private void btnEnviar_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (cbxMoneda.SelectedValue != null)
                {
                    if (cbxEmpleado.SelectedValue != null)
                    {
                        MessageBox.Show("Espere mientras se realiza en envío de la orden de pedido. Presione 'Aceptar' para comenzar con el envío");

                        OrdenPedidoNEG ordenPedidoNEG = new OrdenPedidoNEG();
                        int            proveedor      = ordenPedidoCarga.PROVEEDOR_ID;
                        int            sucursal       = ordenPedidoCarga.SUCURSAL_ID;
                        ordenPedidoCarga.ESTADO_ORDEN_PEDIDO_ID = 3;
                        string    emailSucursal      = txtEmailSucursal.Text.ToString();
                        int       tipoMultimoneda    = int.Parse(cbxMoneda.SelectedValue.ToString());
                        int       empleado           = int.Parse(cbxEmpleado.SelectedValue.ToString());
                        string    emailProveedor     = txtEmailProveedor.Text.ToString();
                        DateTime  fechaActualizacion = Convert.ToDateTime(dpkFechaModificacion.SelectedDate);
                        DataTable tabla     = ((DataView)dgProductos.ItemsSource).ToTable();
                        string    respuesta = ordenPedidoNEG.ActualizarOrdenPedido(ordenPedidoCarga, proveedor, sucursal, emailSucursal, tipoMultimoneda, empleado, emailProveedor, fechaActualizacion, tabla);
                        if (respuesta == "actualizado")
                        {
                            ServerCorreo     abrir_server = new ServerCorreo();
                            Correo           correoM      = new Correo();
                            ExportarArchivos pdf          = new ExportarArchivos();
                            //parametriza el servidor STMP para enviar el correo
                            SmtpClient server = abrir_server.InstanciaServer();

                            //cargar modelo solicitud
                            PDF_ModeloOrdenPedido modelo = new PDF_ModeloOrdenPedido();
                            modelo.Folio             = dataRow["FOLIO"].ToString();
                            modelo.NombreProveedor   = ordenPedidoCarga.PROVEEDOR;
                            modelo.RolProveedor      = ordenPedidoCarga.NUMID_PROVEEDOR + "-" + ordenPedidoCarga.DIVID_PROVEEDOR;
                            modelo.FechaSolicitud    = ordenPedidoCarga.FECHA_CREACION.ToString();
                            modelo.FechaModificacion = dpkFechaModificacion.SelectedDate.ToString();
                            modelo.Sucursal          = ordenPedidoCarga.SUCURSAL;
                            modelo.Direccion         = txtDireccion.Text;
                            modelo.Telefono          = txtTelFijo.Text;
                            modelo.EmailSucursal     = txtEmailSucursal.Text;
                            foreach (DataRow fila in tabla.Rows)
                            {
                                DETALLE_ORDEN_PEDIDO deta = new DETALLE_ORDEN_PEDIDO();
                                deta.PRODUCTO_ID     = int.Parse(fila.ItemArray[0].ToString());
                                deta.NOMBRE_PRODUCTO = fila.ItemArray[1].ToString();
                                deta.CANTIDAD        = int.Parse(fila.ItemArray[2].ToString());
                                deta.PRECIO_COMPRA   = decimal.Parse(fila.ItemArray[3].ToString());
                                deta.MONTO_TOTAL     = decimal.Parse(fila.ItemArray[4].ToString());
                                modelo.DetalleOrdenPedido.Add(deta);
                            }
                            modelo.Moneda         = cbxMoneda.Text;
                            modelo.CostoTotal     = txtCostoTotal.Text;
                            modelo.ConstoMoneda   = txtCostoMoneda.Text;
                            modelo.CodigoEmpleado = cbxEmpleado.Text;
                            modelo.NombreEMpleado = txtNombreEmpleado.Text;
                            modelo.EmailProveedor = txtEmailProveedor.Text;

                            string nombreRutaDoc = pdf.OrdenPedidoPDF(modelo);

                            //Instancia la libreria que permite armar correo electronico y llama el metodo que lo crea
                            MailMessage email = correoM.CorreoConfirmacionEnvioPedido(nombreRutaDoc, modelo.EmailSucursal, modelo.NombreEMpleado, modelo.EmailProveedor, modelo.NombreProveedor);
                            //envia el correo
                            server.Send(email);
                            ordenPedidoNEG.EnviarOrdenPedido(ordenPedidoCarga.ID);
                            modificarPedido.CargarTablaOrdenesPedido();
                            MessageBox.Show("La orden de pedido ha sido enviada satisfactoriamente");
                        }
                        else
                        {
                            MessageBox.Show(respuesta);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Debe seleccionar un empleado");
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar una moneda");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n" + ex.TargetSite + "\n" + ex.Message.ToString());
            }
        }