Beispiel #1
0
        private void btn_aceptar_Click(object sender, EventArgs e)
        {
            if (txt_nombre.Text != "")
            {
                Cliente c = new Cliente();

                if (txt_calle.Text != "")
                {
                    c.Direccion = txt_calle.Text;
                }
                else
                {
                    c.Direccion = " ";
                }

                if (txt_ciudad.Text != "")
                {
                    c.Ciudad = txt_ciudad.Text;
                }
                else
                {
                    c.Ciudad = " ";
                }

                if (txt_email.Text != "")
                {
                    c.Email = txt_email.Text;
                }
                else
                {
                    c.Email = " ";
                }

                if (txt_numero_doc.Text != "")
                {
                    c.Documento = txt_numero_doc.Text;
                }
                else
                {
                    c.Documento = " ";
                }

                if (txt_telefono_numero.Text != "")
                {
                    c.Telefono = txt_telefono_numero.Text;
                }
                else
                {
                    c.Telefono = " ";
                }
                if (txt_rut.Text != "")
                {
                    c.RUT = txt_rut.Text;
                }
                else
                {
                    c.RUT = " ";
                }
                if (cbox_pais.SelectedItem != null)
                {
                    c.id_Pais = ((Pais)cbox_pais.SelectedItem).Id_pais;
                }

                else
                {
                    c.id_Pais = DatosPais.obtener_id_pais_maximo();
                }
                c.Nacimiento = date_cumple.Value;
                c.Nombre     = txt_nombre.Text;
                if (modificar == false)
                {
                    DatosCliente.NuevoCliente(c);
                }
                else
                {
                    c.Id_cliente = cli.Id_cliente;
                    DatosCliente.ModificarCliente(c);
                }

                this.Close();
            }

            else
            {
                MessageBox.Show(this, "Debe ingresar el nombre de cliente", "¡Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #2
0
        public void guardar_imprimir(bool imprime)
        {
            //verifico si hay items en el carrito


            if (listacarrito.Count > 0)
            {
                this.Cursor = Cursors.WaitCursor;
                int conteo;
                for (conteo = listacarrito.Count; conteo > 0;)
                {
                    conteo = conteo - factura.Items_max;

                    cant_facturas = cant_facturas + 1;
                }


                factura_numero_conteo = factura.Factura_numero_dato;

                // verifico si el cliente es nuevo
                if (cbox_cliente.SelectedItem == null)
                {
                    if (txt_rut.Text == "")
                    {
                        txt_rut.Text = " ";
                    }


                    id_pais = DatosPais.obtener_id_pais_maximo();


                    Cliente c = new Cliente(0, cbox_cliente.Text, txt_n_documento.Text, " ", " ", " ", " ", id_pais, txt_rut.Text, Convert.ToDateTime("1/1/2000"));
                    DatosCliente.NuevoCliente(c);
                    id_cliente = DatosCliente.obtener_id_cliente_maximo();
                }
                //verifico si hay un cliente seleccionado en el cbox_cliente
                else
                {
                    id_cliente = ((Cliente)cbox_cliente.SelectedItem).Id_cliente;
                }
                int impre = 0;
                //creo una nueva venta en la bdd
                Int64 id_venta;
                if (imprime == true)
                {
                    impre = 1;
                }
                else
                {
                    txt_factura_num.Text = " ";
                    txt_venta_num.Text   = " ";
                }
                if (txt_observaciones.Text == "")
                {
                    txt_observaciones.Text = " ";
                }
                Venta v = new Venta(0, id_cliente, DateTime.Now, Convert.ToDecimal(txt_total_pesos.Text), impre, txt_venta_num.Text, " ", tipo, "Pago", 1, 1, 1, 1, 0, 0, 0, 0, descuento_monto, Convert.ToDecimal(Principal.iva), txt_observaciones.Text, Convert.ToDecimal(txt_enPesos.Text));
                DatosVenta.NuevaVenta(v);


                // obtengo el id max de venta
                try
                {
                    id_venta = DatosVenta.obtener_id_venta();
                }
                catch
                {
                    id_venta = 0;
                }


                //agrego items a Venta_producto en la bdd
                for (int i = 0; i < listacarrito.Count; i++)
                {
                    Venta_Producto vp = new Venta_Producto(0, id_venta, ((Producto)listacarrito[i]).Id_producto, ((Producto)listacarrito[i]).Total, ((Producto)listacarrito[i]).Stock);
                    DatosVenta_Producto.NuevaVentaProducto(vp);
                    for (Int32 h = 0; h < listaInicial.Count; h++)
                    {
                        if (((Producto)listacarrito[i]).Id_producto == ((Producto)listainicial2[h]).Id_producto)
                        {
                            DatosProducto.CambiarStock(((Producto)listacarrito[i]).Id_producto, ((Producto)listainicial2[h]).Stock - ((Producto)listacarrito[i]).Stock);
                        }
                    }
                }
                if (imprime == true)
                {
                    for (int y = 0; y < cant_facturas; y++)
                    {
                        Factura fa = new Factura(factura.Factura_Prefijo_dato + (factura.Factura_numero_dato + y).ToString(), 0, id_venta);
                        Datos_Factura.NuevaFacura(fa);
                    }
                    Clases.Configuracion_factura factura_guardar = new Clases.Configuracion_factura();
                    factura_guardar = factura;
                    factura_guardar.Factura_numero_dato = factura.Factura_numero_dato + cant_facturas;
                    factura_guardar.Venta_numero_dato   = factura.Venta_numero_dato + 1;
                    Conex.Modificar_Factura(factura_guardar);
                    try
                    {
                        PrintAString(0);
                    }
                    catch
                    {
                        MessageBox.Show(this, "Error al imprimir factura", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }


                tipo    = null;
                detalle = null;


                Font   printFont   = null;
                string printString = null;
                clientes      = null;
                listaVacia    = null;
                listaInicial  = null;
                listacarrito  = null;
                listainicial2 = null;
                factura       = null;


                Principal.cerrar_ventana_generar_venta = false;
                this.Close();
            }
            else
            {
                MessageBox.Show(this, "No hay items en el carrito", "¡Aviso!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txt_codigo2.Focus();
            }
        }