コード例 #1
0
        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            /*string rut = txtRut.Text;
             * string nombre = txtNombre.Text;
             * string apellido = txtApellido.Text;
             * int edad = Convert.ToInt32(txtEdad.Text);
             * string direccion = txtDireccion.Text;
             * string comuna = cboComuna.SelectedItem.ToString();*/
            Cl_Persona cliente = new Cl_Persona();

            if (!validarRut(txtRut.Text.ToString()))
            {
                MessageBox.Show("Ingrese un RUT Valido");
                return;
            }
            else
            {
                cliente.rut = txtRut.Text;
            }

            if (txtNombre.Text.ToString().Length < 3)
            {
                MessageBox.Show("Ingrese un nombre con al menos 3 caracteres");
                return;
            }
            else
            {
                cliente.nombre = txtNombre.Text;
            }

            if (txtApellido.Text.ToString().Length < 3)
            {
                MessageBox.Show("Ingrese un apellido con al menos 3 caracteres");
                return;
            }
            else
            {
                cliente.apellido = txtApellido.Text;
            }
            if (txtEdad.Text.ToString().Equals(""))
            {
                MessageBox.Show("Ingrese una Edad");
                return;
            }
            else
            {
                int edad = Convert.ToInt32(txtEdad.Text);
                if (edad >= 18 && edad <= 80)
                {
                    cliente.edad = Convert.ToInt32(txtEdad.Text);
                }
                else
                {
                    MessageBox.Show("Ingrese una edad valida");
                    return;
                }
            }
            if (txtDireccion.Text.ToString().Length > 3)
            {
                cliente.direccion = txtDireccion.Text;
            }
            else
            {
                MessageBox.Show("Ingrese una direccion valida");
                return;
            }

            cliente.correo = txtCorreo.Text;
            cliente.comuna = cboComuna.SelectedItem.ToString();
            int despacho = 0;
            int tipoPago = 0;

            //servicio_cliente = new ServicioClient();
            if (cboTipoDespacho.SelectedItem != null)
            {
                if (cboTipoDespacho.SelectedItem.ToString().Equals("Domicilio"))
                {
                    despacho = 1;
                }
                else if (cboTipoDespacho.SelectedItem.ToString().Equals("Tienda"))
                {
                    despacho = 2;
                }
            }
            else
            {
                MessageBox.Show("Seleccione un tipo de despacho");
                return;
            }
            if (cboTipoPago.SelectedItem != null)
            {
                if (cboTipoPago.SelectedItem.ToString().Equals("Efectivo"))
                {
                    tipoPago = 1;
                }
                if (cboTipoPago.SelectedItem.ToString().Equals("Credito"))
                {
                    tipoPago = 2;
                }
                if (cboTipoPago.SelectedItem.ToString().Equals("Debito"))
                {
                    tipoPago = 3;
                }
            }
            else
            {
                MessageBox.Show("Seleccione un tipo de Pago");
                return;
            }

            int idVenta = daoVenta.insertarVenta(cliente, vendedor, totalVenta, despacho, tipoPago);

            foreach (var item in listaCarrito)
            {
                int totalProd = (item.precio * item.cantidad) - ((item.cantidad * item.precio) * (item.descuento / 100));
                int resp      = daoVenta.insertarDetalleVenta(idVenta, item.cantidad, totalProd, item.idProducto);
                if (resp != 1)
                {
                    MessageBox.Show("No se pudo insertar el detalle de la venta");
                    return;
                }
            }
            MessageBox.Show("La venta fue ingresada correctamente");
            vendControl.vaciarCarrito();
            vendControl.cargarProductos();
            this.Close();
        }