Example #1
0
 private void btoSalida_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("COMPLETO"))
         {
             PedidoCompletoE p = (PedidoCompletoE)dgvPedidos.CurrentRow.Cells[0].Value;
             p.HoraSalidaBodega = dtpSalida.Value;
             pl.GuardarPedidoCompletoBodega(p);
         }
         else if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("SOLO SERVICIO"))
         {
             PedidoSoloServicioE p = (PedidoSoloServicioE)dgvPedidos.CurrentRow.Cells[0].Value;
             p.HoraSalidaBodega = dtpSalida.Value;
             pl.GuardarPedidoSoloServicioBodega(p);
         }
         else if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("CLIENTE"))
         {
             PedidoClienteE p = (PedidoClienteE)dgvPedidos.CurrentRow.Cells[0].Value;
             p.HoraSalidaBodega = dtpSalida.Value;
             p.Estado           = "ENVIADO";
             pl.GuardarPedidoClienteBodega(p);
         }
         CargarPedidos();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Agregando Hora Salida", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 /// <summary>
 /// Updates an order selected by the builder or the carrier on to the database
 /// </summary>
 /// <param name="pc">
 /// Instance of the class PedidoCompleto
 /// </param>
 /// <returns>
 /// True if the order is updated
 /// </returns>
 public bool GuardarPedidoCompletoBodega(PedidoCompletoE pc)
 {
     using (FerreteriaEntities db = new FerreteriaEntities())
     {
         return(db.Database.ExecuteSqlCommand("sp_upedido_completo_bodega @p0, @p1, @p2",
                                              pc.Id, pc.HoraRecibidoBodega, pc.HoraSalidaBodega) > 0);
     }
 }
 /// <summary>
 /// Updates an order selected by the cashier on to the database
 /// </summary>
 /// <param name="pc">
 /// Instance of the class PedidoCompleto
 /// </param>
 /// <returns>
 /// True if the order is updated
 /// </returns>
 public bool GuardarPedidoCompletoFactura(PedidoCompletoE pc)
 {
     using (FerreteriaEntities db = new FerreteriaEntities())
     {
         return(db.Database.ExecuteSqlCommand("sp_upedido_completo_factura @p0, @p1, @p2, @p3",
                                              pc.Id, pc.FechaFactura, pc.CodigoCajero, pc.PagaSoloProducto) > 0);
     }
 }
 /// <summary>
 /// Updates an order selected by the carrier on to the database
 /// </summary>
 /// <param name="pc">
 /// Instance of the class PedidoCompleto
 /// </param>
 /// <returns>
 /// True if the order is updated
 /// </returns>
 public bool GuardarPedidoCompletoTransporte(PedidoCompletoE pc)
 {
     using (FerreteriaEntities db = new FerreteriaEntities())
     {
         return(db.Database.ExecuteSqlCommand("sp_upedido_completo_transporte @p0, @p1, @p2, @p3",
                                              pc.Id, pc.CodigoConductor, pc.HoraIniciaTransporte, pc.HoraFinalizaTransporte) > 0);
     }
 }
 /// <summary>
 /// Saves a new order made by the seller on to the database
 /// </summary>
 /// <param name="pc">
 /// Instance of the class PedidoCompleto
 /// </param>
 /// <returns>
 /// True if the order is saved
 /// </returns>
 public bool GuardarPedidoCompletoVendedor(PedidoCompletoE pc)
 {
     using (FerreteriaEntities db = new FerreteriaEntities())
     {
         return(db.Database.ExecuteSqlCommand("sp_ipedido_completo_vendedor @p0, @p1, @p2, @p3, @p4, @p5, @p6",
                                              pc.CodigoVendedor, pc.CedulaCliente, pc.HoraAtencion, pc.HoraVenta,
                                              pc.SubTotal, pc.IVA, pc.Total) > 0);
     }
 }
        private void btoRealizarCompra_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtCedulaCliente.Text))
                {
                    throw new ArgumentNullException("Debe ingresar un número de cédula del cliente");
                }
                pc = new PedidoCompletoE();
                pc.CodigoVendedor = u.Codigo;
                pc.CedulaCliente  = txtCedulaCliente.Text.Trim();
                pc.HoraAtencion   = horaAtencion;
                pc.HoraVenta      = DateTime.Now;
                pc.SubTotal       = subtotal;
                pc.IVA            = iva;
                pc.Total          = total;
                pl.GuardarPedidoCompletoVendedor(pc);

                List <PedidoCompletoE> pedidos = pl.CargarPedidoCompleto();
                int last = pedidos.Count - 1;
                pc.Id = pedidos[last].Id;

                foreach (PedidoCompletoProductoE p in productos)
                {
                    foreach (ProductoE i in prl.CargarProducto("", ""))
                    {
                        if (p.IdVenta == i.Id)
                        {
                            i.Cantidad -= p.Cantidad;
                            break;
                        }
                    }
                    p.IdPedido = pc.Id;
                    pl.GuardarPedidoCompletoProducto(p);
                }

                foreach (PedidoCompletoServicioE p in servicios)
                {
                    p.IdPedido = pc.Id;
                    pl.GuardarPedidoCompletoServicio(p);
                }

                MessageBox.Show(pc.CedulaCliente + "\n" + DateTime.Now.TimeOfDay, "Notificación",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                Limpiar();
                Activar(false);
            }
            catch (ArgumentNullException ex)
            {
                MessageBox.Show(ex.Message, "Realizando Compra", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Realizando Compra", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #7
0
        private void btnAgregarInicio_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvTransportes.CurrentRow.Cells[1].Value.Equals("COMPLETO"))
                {
                    PedidoCompletoE p = (PedidoCompletoE)dgvTransportes.CurrentRow.Cells[0].Value;
                    p.CodigoConductor      = u.Codigo;
                    p.HoraIniciaTransporte = dtpInicia.Value;
                    pl.GuardarPedidoCompletoTransporte(p);
                }
                else if (dgvTransportes.CurrentRow.Cells[1].Value.Equals("SOLO SERVICIO"))
                {
                    PedidoSoloServicioE p = (PedidoSoloServicioE)dgvTransportes.CurrentRow.Cells[0].Value;
                    p.CodigoConductor      = u.Codigo;
                    p.HoraIniciaTransporte = dtpInicia.Value;
                    pl.GuardarPedidoSoloServicioTransporte(p);
                }
                else if (dgvTransportes.CurrentRow.Cells[1].Value.Equals("CLIENTE"))
                {
                    PedidoClienteE p = (PedidoClienteE)dgvTransportes.CurrentRow.Cells[0].Value;
                    p.CodigoConductor      = u.Codigo;
                    p.HoraIniciaTransporte = dtpInicia.Value;
                    pl.GuardarPedidoClienteTransporte(p);
                }
                CargarPedidosTransporte();

                foreach (TransporteE t in tl.CargarTransportes())
                {
                    if (t.CodigoConductor == u.Codigo)
                    {
                        t.Disponible = false;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Agregando Hora Inicio", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
        /// <summary>
        /// Generates a bill for the products and services sold
        /// </summary>
        /// <param name="tipoFactura">
        /// string bill type: only the products or everything
        /// </param>
        private void Factura(string tipoFactura)
        {
            try
            {
                DialogResult result = MessageBox.Show("¿Seguro que desea realizar el pago seleccionado?",
                                                      "Realizando Pago", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    decimal subtotal = 0;
                    decimal iva      = 0;
                    decimal total    = 0;

                    if (tipoFactura.Equals("Productos"))
                    {
                        if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("COMPLETO"))
                        {
                            PedidoCompletoE p = (PedidoCompletoE)dgvPedidos.CurrentRow.Cells[0].Value;
                            p.CodigoCajero     = u.Codigo;
                            p.FechaFactura     = dtpFecha.Value;
                            p.PagaSoloProducto = true;
                            pl.GuardarPedidoCompletoFactura(p);

                            WindowReceipt factura = new WindowReceipt();
                            factura.lblNumeroFacturaT.Text = p.Id.ToString();
                            factura.lblFechaT.Text         = p.FechaFactura.ToString();
                            factura.lblCedulaClienteT.Text = p.CedulaCliente;

                            foreach (UsuarioE i in ul.CargarUsuario())
                            {
                                if (i.Codigo == p.CodigoCajero)
                                {
                                    factura.lblCajeroT.Text = i.Nombre;
                                }
                            }

                            foreach (PedidoCompletoProductoE i in pl.CargarPedidoCompletoProducto())
                            {
                                if (i.IdPedido == p.Id)
                                {
                                    foreach (ProductoE pr in prl.CargarProducto("", ""))
                                    {
                                        if (pr.Id == i.IdPedido)
                                        {
                                            subtotal += (pr.Precio * i.Cantidad);
                                            factura.txtVentas.Text += "\n" + pr.Nombre + "\n" + i.Cantidad
                                                                      + "\t" + pr.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                            break;
                                        }
                                    }
                                }
                            }

                            iva   = subtotal * (decimal)0.13;
                            total = subtotal + iva;

                            factura.lblSubtotalT.Text = subtotal.ToString();
                            factura.lblIVAT.Text      = iva.ToString();
                            factura.lblTotalT.Text    = total.ToString();

                            factura.ShowDialog();
                        }
                        else if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("CLIENTE"))
                        {
                            PedidoClienteE p = (PedidoClienteE)dgvPedidos.CurrentRow.Cells[0].Value;
                            p.CodigoCajero     = u.Codigo;
                            p.FechaFactura     = dtpFecha.Value;
                            p.PagaSoloProducto = true;
                            pl.GuardarPedidoClienteFactura(p);

                            WindowReceipt factura = new WindowReceipt();
                            factura.lblNumeroFacturaT.Text = p.Id.ToString();
                            factura.lblFechaT.Text         = p.FechaFactura.ToString();
                            factura.lblCedulaClienteT.Text = p.CedulaCliente;

                            foreach (UsuarioE i in ul.CargarUsuario())
                            {
                                if (i.Codigo == p.CodigoCajero)
                                {
                                    factura.lblCajeroT.Text = i.Nombre;
                                }
                            }

                            foreach (PedidoClienteProductoE i in pl.CargarPedidoClienteProducto())
                            {
                                if (i.IdPedido == p.Id)
                                {
                                    foreach (ProductoE pr in prl.CargarProducto("", ""))
                                    {
                                        if (pr.Id == i.IdPedido)
                                        {
                                            subtotal += (pr.Precio * i.Cantidad);
                                            factura.txtVentas.Text += "\n" + pr.Nombre + "\n" + i.Cantidad
                                                                      + "\t" + pr.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                            break;
                                        }
                                    }
                                }
                            }

                            iva   = subtotal * (decimal)0.13;
                            total = subtotal + iva;

                            factura.lblSubtotalT.Text = subtotal.ToString();
                            factura.lblIVAT.Text      = iva.ToString();
                            factura.lblTotalT.Text    = total.ToString();

                            factura.ShowDialog();
                        }
                    }
                    else
                    {
                        if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("COMPLETO"))
                        {
                            PedidoCompletoE p = (PedidoCompletoE)dgvPedidos.CurrentRow.Cells[0].Value;
                            p.CodigoCajero = u.Codigo;
                            p.FechaFactura = dtpFecha.Value;


                            WindowReceipt factura = new WindowReceipt();
                            factura.lblNumeroFacturaT.Text = p.Id.ToString();
                            factura.lblFechaT.Text         = p.FechaFactura.ToString();
                            factura.lblCedulaClienteT.Text = p.CedulaCliente;

                            foreach (UsuarioE i in ul.CargarUsuario())
                            {
                                if (i.Codigo == p.CodigoCajero)
                                {
                                    factura.lblCajeroT.Text = i.Nombre;
                                }
                            }

                            if (p.PagaSoloProducto != true)
                            {
                                foreach (PedidoCompletoProductoE i in pl.CargarPedidoCompletoProducto())
                                {
                                    if (i.IdPedido == p.Id)
                                    {
                                        foreach (ProductoE pr in prl.CargarProducto("", ""))
                                        {
                                            if (pr.Id == i.IdPedido)
                                            {
                                                subtotal += (pr.Precio * i.Cantidad);
                                                factura.txtVentas.Text += "\n" + pr.Nombre + "\n" + i.Cantidad
                                                                          + "\t" + pr.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            foreach (PedidoCompletoServicioE i in pl.CargarPedidoCompletoServicio())
                            {
                                if (i.IdPedido == p.Id)
                                {
                                    foreach (ServicioE se in sel.CargarServicio("", ""))
                                    {
                                        if (se.Id == i.IdPedido)
                                        {
                                            subtotal += (se.Precio * i.Cantidad);
                                            factura.txtVentas.Text += "\n" + se.Nombre + "\n" + i.Cantidad
                                                                      + "\t" + se.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                            break;
                                        }
                                    }
                                }
                            }

                            iva   = subtotal * (decimal)0.13;
                            total = subtotal + iva;

                            p.PagaSoloProducto = false;
                            pl.GuardarPedidoCompletoFactura(p);

                            factura.lblSubtotalT.Text = subtotal.ToString();
                            factura.lblIVAT.Text      = iva.ToString();
                            factura.lblTotalT.Text    = total.ToString();

                            factura.ShowDialog();
                        }
                        else if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("SOLO SERVICIO"))
                        {
                            PedidoSoloServicioE p = (PedidoSoloServicioE)dgvPedidos.CurrentRow.Cells[0].Value;
                            p.CodigoCajero = u.Codigo;
                            p.FechaFactura = dtpFecha.Value;
                            pl.GuardarPedidoSoloServicioFactura(p);

                            WindowReceipt factura = new WindowReceipt();
                            factura.lblNumeroFacturaT.Text = p.Id.ToString();
                            factura.lblFechaT.Text         = p.FechaFactura.ToString();
                            factura.lblCedulaClienteT.Text = p.CedulaCliente;

                            foreach (UsuarioE i in ul.CargarUsuario())
                            {
                                if (i.Codigo == p.CodigoCajero)
                                {
                                    factura.lblCajeroT.Text = i.Nombre;
                                }
                            }

                            foreach (PedidoSoloServicioServicioE i in pl.CargarPedidoSoloServicioServicio())
                            {
                                if (i.IdPedido == p.Id)
                                {
                                    foreach (ServicioE se in sel.CargarServicio("", ""))
                                    {
                                        if (se.Id == i.IdPedido)
                                        {
                                            factura.txtVentas.Text += "\n" + se.Nombre + "\n" + i.Cantidad
                                                                      + "\t" + se.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                            break;
                                        }
                                    }
                                }
                            }

                            factura.lblSubtotalT.Text = p.SubTotal.ToString();
                            factura.lblIVAT.Text      = p.IVA.ToString();
                            factura.lblTotalT.Text    = p.Total.ToString();

                            factura.ShowDialog();
                        }
                        else if (dgvPedidos.CurrentRow.Cells[1].Value.Equals("CLIENTE"))
                        {
                            PedidoClienteE p = (PedidoClienteE)dgvPedidos.CurrentRow.Cells[0].Value;
                            p.CodigoCajero = u.Codigo;
                            p.FechaFactura = dtpFecha.Value;

                            WindowReceipt factura = new WindowReceipt();
                            factura.lblNumeroFacturaT.Text = p.Id.ToString();
                            factura.lblFechaT.Text         = p.FechaFactura.ToString();
                            factura.lblCedulaClienteT.Text = p.CedulaCliente;

                            foreach (UsuarioE i in ul.CargarUsuario())
                            {
                                if (i.Codigo == p.CodigoCajero)
                                {
                                    factura.lblCajeroT.Text = i.Nombre;
                                }
                            }

                            if (p.PagaSoloProducto != true)
                            {
                                foreach (PedidoClienteProductoE i in pl.CargarPedidoClienteProducto())
                                {
                                    if (i.IdPedido == p.Id)
                                    {
                                        foreach (ProductoE pr in prl.CargarProducto("", ""))
                                        {
                                            if (pr.Id == i.IdPedido)
                                            {
                                                subtotal += (pr.Precio * i.Cantidad);
                                                factura.txtVentas.Text += "\n" + pr.Nombre + "\n" + i.Cantidad
                                                                          + "\t" + pr.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            foreach (PedidoClienteServicioE i in pl.CargarPedidoClienteServicio())
                            {
                                if (i.IdPedido == p.Id)
                                {
                                    foreach (ServicioE se in sel.CargarServicio("", ""))
                                    {
                                        if (se.Id == i.IdPedido)
                                        {
                                            subtotal += (se.Precio * i.Cantidad);
                                            factura.txtVentas.Text += "\n" + se.Nombre + "\n" + i.Cantidad
                                                                      + "\t" + se.Precio.ToString("0.00") + "\t" + i.PrecioTotal.ToString("0.00") + "\n";
                                            break;
                                        }
                                    }
                                }
                            }

                            iva   = subtotal * (decimal)0.13;
                            total = subtotal + iva;

                            p.PagaSoloProducto = false;
                            pl.GuardarPedidoClienteFactura(p);

                            factura.lblSubtotalT.Text = subtotal.ToString();
                            factura.lblIVAT.Text      = iva.ToString();
                            factura.lblTotalT.Text    = total.ToString();

                            factura.ShowDialog();
                        }
                    }
                    CargarPedidos();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Generando Factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }