Exemplo n.º 1
0
        protected void ctrl_btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(ctrl_txtCodigoFactura.Text))
                {
                    MensajeExito("Código factura obligatorio.");
                    return;
                }


                Entidades.Usuario  usuario  = (Entidades.Usuario)HttpContext.Current.Session["InfoUsuario"];
                Entidades.Empleado empleado = blEmpleado.ObtenerPorIdUsuario(usuario.IdUsuario);

                Entidades.Factura factura = new Entidades.Factura();
                factura.Codigo         = ctrl_txtCodigoFactura.Text;
                factura.IdCliente      = Convert.ToInt32(ctrl_ddlCliente.SelectedValue);
                factura.IdEmpleado     = empleado.IdEmpleado;
                factura.FechaVenta     = DateTime.Now;
                factura.IdPuntoDeVenta = 1;

                List <Entidades.DetalleFactura> guardados = (List <Entidades.DetalleFactura>)ViewState["lstDetalle"];

                if (guardados == null || guardados.Count <= 0)
                {
                    throw new Exception("No existe detalle en la factura");
                }

                factura.DetalleFacturas = guardados;

                double total = 0;

                foreach (Entidades.DetalleFactura detalle in guardados)
                {
                    total += detalle.Total;
                }

                Entidades.MedioPagoFactura medioPago = new Entidades.MedioPagoFactura();
                medioPago.IdMedioPago = 1;
                medioPago.Total       = total;

                List <Entidades.MedioPagoFactura> medioPagos = new List <Entidades.MedioPagoFactura>();
                medioPagos.Add(medioPago);

                factura.MedioPagoFacturas = medioPagos;

                factura = bl.Guardar(factura);

                MensajeExito("Factura guardada con éxito");
                Buscar();
                Limpiar();
            }
            catch (Exception ex)
            {
                MensajeError(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void Buscar()
        {
            Entidades.Factura factura = new Entidades.Factura();
            factura.Codigo = ctrl_txtCodigoFacturaFiltro.Text;

            ICollection <Entidades.Factura> facturas = bl.ObtenerPorFiltro(factura);

            ctrl_gvFacturas.DataSource = facturas;
            ctrl_gvFacturas.DataBind();
        }
Exemplo n.º 3
0
        private void GenerarXML(int id)
        {
            Entidades.Factura factura = bl.ObtenerPorId(id);

            StringWriter stringwriter = new StringWriter();

            XmlSerializer x = new XmlSerializer(factura.GetType());

            x.Serialize(stringwriter, factura);

            string xml = stringwriter.ToString();

            Byte[] bytes = Encoding.ASCII.GetBytes(xml);

            Session["downloadFile"] = bytes;

            String jsString = "<script type=text/javascript>finestraSecundaria('./DescargarArchivo.aspx');</script>";

            ScriptManager.RegisterStartupScript(this, typeof(Page), "ventana", jsString, false);
        }