Example #1
0
 private void button5_Click(object sender, EventArgs e)
 {
     try
     {
         DetallePedido detalleSeleccionado = (DetallePedido)dataGridView1.CurrentRow.DataBoundItem;
         total         = total - detalleSeleccionado.Subtotal;
         textBox9.Text = total.ToString();
         detalles.Remove(detalleSeleccionado);
     }
     catch (Exception) {
         MessageBox.Show("Debe seleccionar un detalle del pedido", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
     }
 }
        private void dgListaCli_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dgListaCli.SelectedItem != null)
            {
                //lblRut.Content = "RUT A BUSCAR: ";
                var          pedido_seleccionado = dgListaCli.SelectedItem;
                PropertyInfo pi_rut = pedido_seleccionado.GetType().GetProperty("RutCliente");
                int          rut    = (int)(pi_rut.GetValue(pedido_seleccionado, null));
                //txtRut.Text = Convert.ToString(rut);

                PropertyInfo pi_id_pedido = pedido_seleccionado.GetType().GetProperty("IdPedido");
                Byte         idPedido     = (Byte)(pi_id_pedido.GetValue(pedido_seleccionado, null));

                DetallePedido detalle_pedido = new DetallePedido(this, idPedido, rut);
                detalle_pedido.Show();
                //dgListaCli.ItemsSource = (IEnumerable)ped.filtroPedidosCliente(rut);
            }
        }
Example #3
0
        private void CargarGrillaDetalleOrdenYTotal(int numero)
        {
            DetallePedido          detalle       = new DetallePedido();
            List <V_DETALLE_ORDEN> listadoModelo = new List <V_DETALLE_ORDEN>();

            listadoModelo = detalle.ListarDetallePorOrden(numero);
            decimal totalPedido = 0;

            foreach (V_DETALLE_ORDEN item in listadoModelo)
            {
                string  codigo   = item.PRODUCTO_CODIGO;
                string  nombre   = item.NOMBRE;
                int     cantidad = (int)item.CANTIDAD;
                decimal total    = (decimal)item.TOTAL;
                totalPedido += total;
                grdOrden.Rows.Add(codigo, nombre, cantidad, total);
            }
            txtTotalOrden.Text = totalPedido.ToString();
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox5.Text))
            {
                MessageBox.Show("Debe seleccionar un producto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
            }
            if (String.IsNullOrWhiteSpace(textBox8.Text))
            {
                MessageBox.Show("Debe ingresar una cantidad", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
            }
            if (textBox8.ForeColor == Color.Red)
            {
                MessageBox.Show("Cantidad invalida", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
            }
            if (Convert.ToInt32(textBox8.Text) == 0)
            {
                MessageBox.Show("Cantidad debe ser mayor a cero", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
            }
            DetallePedido d = new DetallePedido();

            d.Producto = this.productoSeleccionado;
            d.Cantidad = Convert.ToInt32(textBox8.Text);
            d.Subtotal = d.Cantidad * Convert.ToSingle(textBox7.Text);

            this.estadoBotones(2);
            total         = total + d.Subtotal;
            textBox9.Text = total.ToString();

            foreach (DetallePedido de in detalles)
            {
                if (d.Producto.Id == de.Producto.Id)
                {
                    de.Cantidad = de.Cantidad + d.Cantidad;
                    de.Subtotal = de.Subtotal + d.Subtotal;
                    this.estadoBotones(2);
                    dataGridView1.Update();
                    dataGridView1.Refresh();
                    return;
                }
            }
            detalles.Add(d);
        }
Example #5
0
 public void ModificarOrdenPedidoParaDescargar()
 {
     if (decimal.Parse(txtTotalOrden.Text) > 0)
     {
         int       numeroOrden = int.Parse(lblNumeroOrden.Text);
         decimal   total       = decimal.Parse(txtTotalOrden.Text);
         Proveedor proveedor   = new Proveedor();
         proveedor.Rut = (int)cmbProveedor.SelectedValue;
         EstadoOrden estadoOrden = new EstadoOrden();
         estadoOrden.Id = 2;//<--debe ser ENVIADA
         Usuario usuario = new Usuario();
         usuario.RunUsuario = Global.RunUsuarioActivo;
         OrdenPedido orden = new OrdenPedido(numeroOrden, total, proveedor, estadoOrden, usuario);
         if (orden.ModificarOrdenPedido(orden))
         {
             DetallePedido detalle = new DetallePedido();
             bool          eliminarDetalleAnteriores = detalle.EliminarDetalleEnCascada(numeroOrden);
             if (eliminarDetalleAnteriores)
             {
                 foreach (DataGridViewRow row in grdOrden.Rows)
                 {
                     string codigo   = row.Cells[0].Value.ToString();
                     int    cantidad = int.Parse(row.Cells[2].Value.ToString());
                     detalle.NumeroOrden    = numeroOrden;
                     detalle.CodigoProducto = codigo;
                     detalle.Cantidad       = cantidad;
                     detalle.AgregarDetallePedido();
                 }
                 MessageBox.Show("Orden de Pedido N°" + numeroOrden + " ha sido modificada.");
                 this.Dispose();
             }
             else
             {
                 MessageBox.Show("Problema al eliminar detalles anteriores");
             }
         }
     }
 }
Example #6
0
        private void btn_guardar_Click(object sender, EventArgs e)
        {
            int idPedido = 0;

            if (dtp_fecha_necesidad.Value.Date >= DateTime.Now.Date)
            {
                if (dgv_detalle.Rows.Count >= 1)
                {
                    List <DetallePedido> detalle = new List <DetallePedido>();


                    for (int c = 0; c < dgv_detalle.RowCount; c++)
                    {
                        DetallePedido de  = new DetallePedido();
                        Producto      p   = new Producto();
                        Estado        est = new Estado();

                        p.idProducto = (int)dgv_detalle.Rows[c].Cells["idProductodetalle"].Value;
                        p.precio     = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value;

                        de.cantidad = Convert.ToDouble(dgv_detalle.Rows[c].Cells["cantidad"].Value);
                        de.precio   = (double)dgv_detalle.Rows[c].Cells["preciodetalle"].Value;
                        if (dgv_detalle.Rows[c].Cells["reservado"].Value.ToString() == "NO")
                        {
                            de.reservado         = false;
                            de.cantidadReservada = 0;
                            est.idEstado         = 26;
                            if (estadoFormulario == estados.modificar && dgv_detalle.Rows[c].Cells["idestado"].Value != null)
                            {
                                est.idEstado = (int)dgv_detalle.Rows[c].Cells["idestado"].Value;
                            }
                            de.Estado = est;
                        }
                        else
                        {
                            de.reservado         = true;
                            de.cantidadReservada = de.cantidad;
                            est.idEstado         = 25;
                            de.Estado            = est;
                        }

                        de.producto = p;

                        detalle.Add(de);
                    }
                    if (estadoFormulario == estados.nuevo)
                    {
                        gestor.clienteSeleccionado(resultado);
                        gestor.tomarProductosSeleccionados(detalle);
                        gestor.fechaDeNecesidadTomada(dtp_fecha_necesidad.Value.Date);
                        gestor.dirEntregaTomada(txt_dir_entrega.Text);

                        if (!estanTodosReservados())
                        {
                            gestor.estado(1);
                        }
                        else
                        {
                            gestor.estado(5);
                        }


                        try
                        {
                            List <Producto> productosConPocaMP = new List <Producto>();
                            idPedido = gestor.confirmacionTomada(productosConPocaMP);
                            ////////////// MOSTRAR LOS PRODUCTOS CON BAJO STOCK
                            if (productosConPocaMP.Count > 0)
                            {
                                string          mensaje          = "";
                                List <Producto> prodConPocoStock = new List <Producto>();
                                Boolean         MPRepetida       = false;
                                foreach (Producto Prod in productosConPocaMP)
                                {
                                    foreach (Producto P in prodConPocoStock)
                                    {
                                        if (P.idProducto == Prod.idProducto)
                                        {
                                            MPRepetida = true;
                                            break;
                                        }
                                    }
                                    if (MPRepetida == false)
                                    {
                                        mensaje += Environment.NewLine + Prod.Nombre.ToString();
                                        prodConPocoStock.Add(Prod);
                                    }
                                }
                                MessageBox.Show("Los siguientes productos estan con bajo stock: " + mensaje, "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            /////////////////////////////////////////////////////////////
                            MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                            limpiarCampos();
                        }
                        catch (ApplicationException ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }
                    }
                    else
                    {
                        if (estadoFormulario == estados.modificar)
                        {
                            //foreach (Producto  pro in productosEliminados )
                            //{

                            //    ProductoDAO.UpdateStockReservadoYDisponibleEliminado(pro.idProducto,pro.cantidadProductos );

                            //}



                            gestor.tomarProductosSeleccionados(detalle);
                            gestor.fechaDeNecesidadTomada(dtp_fecha_necesidad.Value.Date);
                            gestor.dirEntregaTomada(txt_dir_entrega.Text);

                            if (!estanTodosReservados())
                            {
                                gestor.estado(1);
                            }
                            else
                            {
                                gestor.estado(5);
                            }

                            try
                            {
                                List <Producto> productosConPocaMP = new List <Producto>();
                                gestor.modificacionConfirmada(tablaAModificar, productosConPocaMP);
                                ////////////// MOSTRAR LOS PRODUCTOS CON BAJO STOCK
                                if (productosConPocaMP.Count > 0)
                                {
                                    string          mensaje          = "";
                                    List <Producto> prodConPocoStock = new List <Producto>();
                                    Boolean         MPRepetida       = false;
                                    foreach (Producto Prod in productosConPocaMP)
                                    {
                                        foreach (Producto P in prodConPocoStock)
                                        {
                                            if (P.idProducto == Prod.idProducto)
                                            {
                                                MPRepetida = true;
                                                break;
                                            }
                                        }
                                        if (MPRepetida == false)
                                        {
                                            mensaje += Environment.NewLine + Prod.Nombre.ToString();
                                            prodConPocoStock.Add(Prod);
                                        }
                                    }
                                    MessageBox.Show("Los siguientes productos estan con bajo stock: " + mensaje, "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                /////////////////////////////////////////////////////////////
                                MessageBox.Show("Registrado con Exito", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                                limpiarCampos();
                            }
                            catch (ApplicationException ex)
                            {
                                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            }
                        }
                    }
                    cargarGrillaProductos();
                }
                else
                {
                    MessageBox.Show("Agrege productos al pedido", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                MessageBox.Show("La fecha de necesidad no puede ser anterior a la actual", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            }
        }
Example #7
0
        public void RecepcionarOrden()
        {
            if (_numeroOrdenSeleccionado != 0)
            {
                OrdenPedido orden = new OrdenPedido();
                orden = orden.ObtenerOrdenPedido(_numeroOrdenSeleccionado);

                EstadoOrden estado = new EstadoOrden();
                estado = estado.ObtenerEstadoOrden(orden.Estado.Id);
                string descripcion = estado.Descripcion;
                if (orden.OrdenPedidoEnviada(orden))
                {
                    estado.Id = (int)cmbEstadoOrden.SelectedValue;
                    if (estado.Id != 1)
                    {
                        if (estado.Id != 2)
                        {
                            if (estado.Id != 6)
                            {
                                DateTime fechaRecepcion = DateTime.Now.Date;
                                orden.Estado         = estado;
                                orden.FechaRecepcion = fechaRecepcion;
                                if (estado.Id == 4)
                                {
                                    bool          ordenRecepcionada = orden.RecepcionarOrdenPedido(orden);
                                    DetallePedido detalle           = new DetallePedido();
                                    bool          stockAgregado     = detalle.AgregarStockOrdenRecepcionada(orden.Numero);
                                    if (stockAgregado && ordenRecepcionada)
                                    {
                                        LimpiarGrillaDetalle();
                                        MessageBox.Show("Se ha recepcionado y agregado el stock correctamente.");
                                        _numeroOrdenSeleccionado = 0;
                                    }
                                    else
                                    {
                                        MessageBox.Show("No se ha podido agregar la recepcion.");
                                    }
                                }
                                else if (estado.Id == 3 || estado.Id == 5)
                                {
                                    bool ordenRecepcionada = orden.RecepcionarOrdenPedido(orden);
                                    if (ordenRecepcionada)
                                    {
                                        LimpiarGrillaDetalle();
                                        MessageBox.Show("Se ha guardado la recepcion de la orden de pedido.");
                                        _numeroOrdenSeleccionado = 0;
                                    }
                                    else
                                    {
                                        MessageBox.Show("No se ha guardado la recepcion.");
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("No se puede anular la orden desde aqui, intente con el boton anular.");
                            }
                        }
                        else
                        {
                            MessageBox.Show("La orden ya ha sido enviada");
                        }
                    }
                    else
                    {
                        MessageBox.Show("La orden de pedido ya ha sido enviada, no puede volver a estado guardada.");
                    }
                }
                else
                {
                    MessageBox.Show("La orden seleccionada se encuentra " + descripcion + " , no se puede recepcionar.");
                }
            }
        }
        private void dgv_pedidos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgv_pedidos.CurrentCell is DataGridViewButtonCell)
            {
                int idPedido    = Convert.ToInt32(dgv_pedidos.Rows[dgv_pedidos.CurrentRow.Index].Cells["idPedido"].Value);
                int estadoDesde = Convert.ToInt32(dgv_pedidos.Rows[dgv_pedidos.CurrentRow.Index].Cells["idestado"].Value);
                int estadoHasta = estadoDesde;

                switch (estadoDesde)
                {
                case 2:
                    estadoHasta = 5;
                    if (tieneProductosFinalizados())
                    {
                        try
                        {
                            PedidoDAO.UpdateEstados(idPedido, estadoHasta);
                            MessageBox.Show("Fin Preparación ", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                            cargarGrilla();
                        }
                        catch (ApplicationException ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Faltan Productos Por Preparar ", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }
                    break;

                case 5:
                    estadoHasta = 6;

                    //Abrir Interface de Factura

                    int idPed = (int)dgv_pedidos.CurrentRow.Cells["idPedido"].Value;
                    RegistrarFactura factura = new RegistrarFactura();
                    factura._idPedido = idPed;
                    factura.ShowDialog();
                    //Si se registro la factura hacer
                    if (factura._estado == estados.guardado)
                    {
                        try
                        {
                            //PedidoDAO.UpdateEstados(idPedido, estadoHasta);
                            MessageBox.Show("Factura Registrada", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                            cargarGrilla();
                        }
                        catch (ApplicationException ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }


                        Emitir_Factura fact = new Emitir_Factura();

                        fact.ShowDialog();
                    }


                    break;

                case 6:
                    estadoHasta = 7;


                    if (pagaronLaFactura(idPedido))
                    {
                        try
                        {
                            for (int i = 0; i < dgv_detalle_pedido.Rows.Count; i++)
                            {
                                DetallePedido det = new DetallePedido();
                                det.producto = new Producto()
                                {
                                    idProducto = (int)dgv_detalle_pedido.Rows[i].Cells["idProd"].Value
                                };
                                det.cantidad = (double)dgv_detalle_pedido.Rows[i].Cells["cant"].Value;


                                ProductoDAO.UpdateStockReservadoYActualdePedidoEntregado(det, idPedido, estadoHasta);
                            }

                            MessageBox.Show("Registro de Entrega Completado ", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                            cargarGrilla();
                        }
                        catch (ApplicationException ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Falta el Pago de la Factura ", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                    }


                    break;
                }
            }
        }