Пример #1
0
        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            if (txtCódigo.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Debe ingresar la identificación del cliente");
                txtCódigo.Focus();
                return;
            }

            if (txtNombre.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Debe ingresar el nombre del cliente");
                txtNombre.Focus();
                return;
            }

            if (txtApellidos.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Debe ingresar los apellidos del cliente");
                txtApellidos.Focus();
                return;
            }
            if (chkFacturaElectronica.IsChecked == true)
            {
                if (txtEmail.Text == "")
                {
                    MessageBox.Show("Debe ingresar el correo electroníco. Ej: [email protected]");
                    txtApellidos.Focus();
                    return;
                }
                else if (!check_email(txtEmail.Text))
                {
                    MessageBox.Show("Formato incorrecto en el campo de correo electroníco. Ej: [email protected]");
                    txtApellidos.Focus();
                    return;
                }
            }


            string caseSwitch = cmbTipoId.Text;
            short  tipoid;

            switch (caseSwitch)
            {
            case "Física":
                tipoid = 1;
                break;

            case "Jurídica":
                tipoid = 2;
                break;

            case "DIMEX":
                tipoid = 3;
                break;

            case "NITE":
                tipoid = 4;
                break;

            default:
                tipoid = 5;
                break;
            }

            using (var bd = new EmpeñosDataContext())
            {
                Cliente = bd.Clientes.SingleOrDefault(c => c.Código == txtCódigo.Value.ToString());

                if (Cliente == null && códigoCliente2 == "")
                {
                    Cliente = new Cliente {
                        TipoIdentificación = tipoid, Código = txtCódigo.Value.ToString()
                    };
                    bd.Clientes.InsertOnSubmit(Cliente);
                }
                else if (códigoCliente2 != "")
                {
                    try
                    {
                        bd.updateIDs(txtCódigo.Value.ToString(), códigoCliente2);
                        códigoCliente2 = "";
                        Cliente        = bd.Clientes.SingleOrDefault(c => c.Código == txtCódigo.Value.ToString());
                    }
                    catch (Exception t)
                    {
                        System.Windows.MessageBox.Show("Error al actualizar.  Ya existe un cliente con esta identificación.\n" + t.Message, "Error", MessageBoxButton.OK);
                    }
                }

                Cliente.TipoIdentificación = tipoid;
                Cliente.Nombre             = txtNombre.Text.Trim();
                Cliente.Apellidos          = txtApellidos.Text.Trim();
                Cliente.Género             = rbMasculino.IsChecked.Value ? 'M' : 'F';
                Cliente.Teléfono           = txtTeléfono.Text;
                Cliente.Email = txtEmail.Text;
                Cliente.RecibirNotificaciones  = chkRecibirNotificaciones.IsChecked.Value;
                Cliente.FacturacionElectronica = chkFacturaElectronica.IsChecked.Value;
                Cliente.Dirección = txtDirección.Text;
                Cliente.Notas     = txtNotas.Text;

                if (imgFoto.Source != null && !imgFoto.Source.ToString().StartsWith("pack"))
                {
                    using (var stream = new MemoryStream())
                    {
                        var encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(imgFoto.Source as BitmapSource));
                        encoder.Save(stream);
                        Cliente.Foto = stream.ToArray();
                    }
                }
                else
                {
                    Cliente.Foto = null;
                }

                this.DialogResult = true;


                bd.SubmitChanges();
            }
        }
Пример #2
0
        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            if (pnlDetalleArtículo.IsVisible)
            {
                if (!GuardarArtículo())
                {
                    return;
                }
            }

            if (ValidarCompra())
            {
                using (var bd = new EmpeñosDataContext())
                {
                    bool insertando = false;

                    var compra = bd.Compras.SingleOrDefault(em => em.Código == txtCódigo.AsInt);

                    if (compra == null)
                    {
                        compra = new Compra {
                            Código = txtCódigo.AsInt
                        };
                        bd.Compras.InsertOnSubmit(compra);
                        insertando = true;
                    }

                    compra.Código_Cliente = ((KeyValuePair <string, string>)txtClientes.SelectedItem).Key;
                    compra.Fecha          = dtpFecha.SelectedDate.Value;
                    compra.CostoTotal     = txtTotalCostoCompra.AsInt;
                    compra.Notas          = txtNotas.Text;

                    if (compra.Estado != (byte)EstadosEmpeño.Quedado)
                    {
                        if (!insertando)
                        {
                            foreach (var detalle in compra.ComprasDetalles)
                            {
                                bd.Artículos_Características.DeleteAllOnSubmit(detalle.Artículo.Artículos_Características);
                                bd.Artículos.DeleteOnSubmit(detalle.Artículo);
                                bd.ComprasDetalles.DeleteOnSubmit(detalle);
                            }
                        }

                        for (int cont = 0; cont < lstArtículos.Items.Count; cont++)
                        {
                            var art = lstArtículos.Items[cont] as Artículo;

                            var nuevoArtículo = new Artículo
                            {
                                Código           = "C" + txtCódigo.AsInt.ToString() + "-" + (cont + 1).ToString(),
                                Nombre           = art.Nombre,
                                Código_Categoría = art.Código_Categoría,
                                Costo            = art.Costo,
                                Estado           = art.Estado,
                                Notas            = art.Notas
                            };

                            foreach (var caract in art.Artículos_Características)
                            {
                                nuevoArtículo.Artículos_Características.Add(new Artículos_Característica {
                                    Código_Característica = caract.Código_Característica, Valor = caract.Valor
                                });
                            }

                            compra.ComprasDetalles.Add(new ComprasDetalle {
                                Artículo = nuevoArtículo
                            });
                        }
                    }

                    bd.SubmitChanges();

                    /*if (chkImprimirAlGuardar.IsChecked == true) {
                     *  Recibos.Imprimir.
                     * }*/

                    this.DialogResult = true;
                }
            }
        }
Пример #3
0
        private void Guardar(bool cerrar)
        {
            if (pnlDetalleArtículo.IsVisible)
            {
                if (!GuardarArtículo())
                {
                    return;
                }
            }

            if (ValidarEmpeño())
            {
                using (var bd = new EmpeñosDataContext())
                {
                    bool insertando = false;

                    var empeño = bd.Empeños.SingleOrDefault(em => em.Código == txtCódigo.AsInt);

                    if (empeño == null)
                    {
                        empeño = new Empeño
                        {
                            Código             = txtCódigo.AsInt,
                            PorcentajeInterés  = txtPorcentajeIntereses.AsDecimal,
                            TotalMontoPréstamo = txtTotalMontoPréstamo.AsInt
                        };
                        bd.Empeños.InsertOnSubmit(empeño);
                        insertando = true;
                    }

                    empeño.Estado = Convert.ToByte(cmbEstado.SelectedIndex);

                    if (empeño.Estado != (byte)EstadosEmpeño.Quedado)
                    {
                        string códigoCliente = ((KeyValuePair <string, string>)txtClientes.SelectedItem).Key;

                        if (!insertando && empeño.Código_Cliente != códigoCliente && MessageBox.Show(string.Format("El cliente del empeño cambió, antes era {0:G} y ahora {1:G}, está seguro?", empeño.Código_Cliente, códigoCliente), "Pregunta", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                        {
                            return;
                        }

                        empeño.Código_Cliente = códigoCliente;
                        empeño.Fecha          = dtpFecha.SelectedDate.Value;
                        empeño.Plazo          = txtPlazo.AsInt;
                        empeño.Notas          = txtNotasEmpeño.Text;

                        if (inkFirma.NumberOfTabletPoints() == 0)
                        {
                            empeño.Firma = null;
                        }
                        else
                        {
                            empeño.Firma = inkFirma.GetSigString();
                        }

                        if (!insertando)
                        {
                            foreach (var detalle in empeño.EmpeñosDetalles)
                            {
                                bd.Artículos_Características.DeleteAllOnSubmit(detalle.Artículo.Artículos_Características);
                                bd.Artículos.DeleteOnSubmit(detalle.Artículo);
                                bd.EmpeñosDetalles.DeleteOnSubmit(detalle);
                            }
                            bd.EmpeñosPagos.DeleteAllOnSubmit(empeño.EmpeñosPagos);
                        }

                        for (int cont = 0; cont < lstArtículos.Items.Count; cont++)
                        {
                            var art = lstArtículos.Items[cont] as Artículo;

                            var nuevoArtículo = new Artículo
                            {
                                Código           = "E" + txtCódigo.AsInt.ToString() + "-" + (cont + 1).ToString(),
                                Nombre           = art.Nombre,
                                Código_Categoría = art.Código_Categoría,
                                Costo            = art.Costo,
                                Estado           = art.Estado,
                                Notas            = art.Notas
                            };

                            foreach (var caract in art.Artículos_Características)
                            {
                                nuevoArtículo.Artículos_Características.Add(new Artículos_Característica {
                                    Código_Característica = caract.Código_Característica, Valor = caract.Valor
                                });
                            }

                            empeño.EmpeñosDetalles.Add(new EmpeñosDetalle {
                                Artículo = nuevoArtículo
                            });
                        }

                        int cuota = 0;
                        foreach (var pago in pagos)
                        {
                            empeño.EmpeñosPagos.Add(new EmpeñosPago {
                                Cuota = ++cuota, FechaPago = pago.FechaPago, FechaCuota = pago.FechaCuota, Intereses = pago.Intereses, Abono = pago.Abono, Firma = pago.Firma?.Length > 0 ? pago.Firma : null
                            });
                        }
                    }

                    bd.SubmitChanges();

                    if (cerrar)
                    {
                        this.DialogResult = true;
                    }
                }
            }
        }
Пример #4
0
        private void btnGuardar_Click(object sender, RoutedEventArgs e)
        {
            if (ValidarVenta())
            {
                using (var bd = new EmpeñosDataContext())
                {
                    bool insertando = false;

                    var venta = bd.Ventas.SingleOrDefault(v => v.Código == txtCódigo.AsInt);

                    if (venta == null)
                    {
                        venta = new Venta {
                            Código = txtCódigo.AsInt
                        };
                        bd.Ventas.InsertOnSubmit(venta);
                        insertando = true;
                    }

                    venta.Código_Cliente = ((KeyValuePair <string, string>)txtClientes.SelectedItem).Key;
                    venta.Fecha          = dtpFecha.SelectedDate.Value;
                    venta.Notas          = txtNotasVentas.Text;
                    venta.Estado         = Convert.ToByte(cmbEstado.SelectedIndex);

                    if (!insertando)
                    {
                        bd.VentasDetalles.DeleteAllOnSubmit(venta.VentasDetalles);
                        bd.VentasAbonos.DeleteAllOnSubmit(venta.VentasAbonos);
                    }

                    for (int cont = 0; cont < listaArtículos.Count; cont++)
                    {
                        Artículo art = bd.Artículos.SingleOrDefault(a => a.Código == listaArtículos[cont].Código);

                        if (art != null)
                        {
                            art.Precio = listaArtículos[cont].Precio;
                            art.Estado = (byte)EstadosActículos.Vendido;

                            venta.VentasDetalles.Add(new VentasDetalle {
                                Código_Venta = venta.Código, Código_Artículo = art.Código
                            });
                        }
                        else
                        {
                            MessageBox.Show("El artículo " + listaArtículos[cont].Código + " ya no existe en la base de datos");
                            return;
                        }
                    }

                    int cuota = 0;
                    venta.VentasAbonos.Add(new VentasAbono {
                        Cuota = ++cuota, Fecha = DateTime.Now, Monto = txtTotalMontoVenta.AsInt
                    });
                    venta.Impuesto = txtIVA.AsDecimal;
                    venta.Total    = (int)txtMontoAPagar.AsDecimal;

                    bd.SubmitChanges();

                    this.DialogResult = true;
                }
            }
        }