Example #1
0
        public void ExportarExcel(object sender, System.EventArgs e)
        {
            if (Listado.SelectedItems.Count > 0)
            {
                int ID = int.Parse(Listado.SelectedItems[0].Text);


                SaveFileDialog DialogoGuardar = new SaveFileDialog();
                DialogoGuardar.OverwritePrompt = true;
                DialogoGuardar.ValidateNames   = true;
                DialogoGuardar.CheckPathExists = true;
                DialogoGuardar.DefaultExt      = ".xlsx";
                DialogoGuardar.Filter          = "Microsoft Excel 2007-2013|*.xlsx";
                DialogoGuardar.FileName        = this.Text.Replace(":", "");
                if (DialogoGuardar.ShowDialog() == DialogResult.OK)
                {
                    Lazaro.Pres.Spreadsheet.Workbook    Workbook = ToWorkbookDetalle(ID);
                    Lazaro.Pres.Spreadsheet.WorkBookLeo typeByte = new Lazaro.Pres.Spreadsheet.WorkBookLeo();
                    //typeByte.StartExcel();
                    string FileName = DialogoGuardar.FileName;
                    try
                    {
                        Workbook.SaveTo(FileName, Lazaro.Pres.Spreadsheet.SaveFormats.Excel);
                        //System.IO.File.WriteAllBytes(FileName, content);
                    }
                    catch (Exception ex)
                    {
                        Lfx.Workspace.Master.RunTime.Toast("No se puede guardar el archivo. " + ex.Message, "Error");
                    }
                }
            }
        }
Example #2
0
        public override Lfx.Types.OperationResult OnPrint(bool selectPrinter)
        {
            if (Listado.Items.Count == 0)
            {
                return(new Lfx.Types.FailureOperationResult("El listado está vacío"));
            }

            Lazaro.Pres.Spreadsheet.Workbook           Workbook = this.ToWorkbook();
            Lazaro.Base.Util.Impresion.ImpresorListado Impresor = new Lazaro.Base.Util.Impresion.ImpresorListado(Workbook.Sheets[0], null);

            if (selectPrinter)
            {
                using (Lui.Printing.PrinterSelectionDialog SeleccionarImpresroa = new Lui.Printing.PrinterSelectionDialog())
                {
                    if (SeleccionarImpresroa.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        Impresor.Impresora = SeleccionarImpresroa.SelectedPrinter;
                    }
                    else
                    {
                        return(new Lfx.Types.CancelOperationResult());
                    }
                }
                using (PageSetupDialog PreferenciasDeImpresion = new PageSetupDialog())
                {
                    //PreferenciasDeImpresion.PrinterSettings = Impresor.PrinterSettings;
                    PreferenciasDeImpresion.Document     = Impresor;
                    PreferenciasDeImpresion.AllowPrinter = true;
                    PreferenciasDeImpresion.AllowPaper   = true;
                    if (PreferenciasDeImpresion.ShowDialog(this) == DialogResult.OK)
                    {
                        return(Impresor.Imprimir());
                    }
                    else
                    {
                        return(new Lfx.Types.CancelOperationResult());
                    }
                }
            }
            else
            {
                // Sin diálogo de selección de impresora
                return(Impresor.Imprimir());
            }
        }
                public virtual Lazaro.Pres.Spreadsheet.Workbook ToWorkbook(Lazaro.Pres.FieldCollection useFields)
                {
                        Lazaro.Pres.Spreadsheet.Workbook Res = new Lazaro.Pres.Spreadsheet.Workbook();
                        Lazaro.Pres.Spreadsheet.Sheet Sheet = new Lazaro.Pres.Spreadsheet.Sheet(this.Text);
                        Res.Sheets.Add(Sheet);

                        // Exporto los encabezados de columna
                        if (this.Definicion.KeyColumn.Printable) {
                                Sheet.ColumnHeaders.Add(new Lazaro.Pres.Spreadsheet.ColumnHeader(this.Definicion.KeyColumn.Label, this.Definicion.KeyColumn.Width));
                                Sheet.ColumnHeaders[0].DataType = this.Definicion.KeyColumn.DataType;
                                Sheet.ColumnHeaders[0].Format = this.Definicion.KeyColumn.Format;
                                Sheet.ColumnHeaders[0].Printable = this.Definicion.KeyColumn.Printable;
                        }

                        int OrderColumn = -1;
                        if (useFields != null) {
                                for (int i = 0; i <= useFields.Count - 1; i++) {
                                        if (useFields[i].Printable) {
                                                Lazaro.Pres.Spreadsheet.ColumnHeader ColHead = new Lazaro.Pres.Spreadsheet.ColumnHeader(useFields[i].Label, useFields[i].Width);
                                                ColHead.Name = Lfx.Data.Field.GetNameOnly(useFields[i].Name);
                                                ColHead.TextAlignment = useFields[i].Alignment;
                                                ColHead.DataType = useFields[i].DataType;
                                                ColHead.Format = useFields[i].Format;
                                                ColHead.TotalFunction = useFields[i].TotalFunction;
                                                ColHead.Printable = useFields[i].Printable;
                                                Sheet.ColumnHeaders.Add(ColHead);

                                                if (ColHead.Name == this.Definicion.OrderBy)
                                                        OrderColumn = Sheet.ColumnHeaders.Count - 1;

                                                if (ColHead.Name == this.GroupingColumnName)
                                                        Sheet.ColumnHeaders.GroupingColumn = Sheet.ColumnHeaders.Count - 1;
                                        }
                                }
                        }

                        // Exporto los renglones
                        System.Data.DataTable Tabla = this.Connection.Select(this.SelectCommand());
                        foreach (System.Data.DataRow DtRow in Tabla.Rows) {
                                Lfx.Data.Row Registro = (Lfx.Data.Row)DtRow;

                                string NombreCampoId = Lfx.Data.Field.GetNameOnly(this.Definicion.KeyColumn.Name);
                                int ItemId = Registro.Fields[NombreCampoId].ValueInt;

                                Lazaro.Pres.Spreadsheet.Row Reng = this.FormatRow(ItemId, Registro, Sheet, useFields);

                                Sheet.Rows.Add(Reng);
                        }

                        if (OrderColumn >= 0) {
                                if (m_GroupingColumnName != null) {
                                        Sheet.SortByGroupAndColumn(OrderColumn, true);
                                } else {
                                        if (OrderColumn >= 0)
                                                Sheet.Sort(OrderColumn, true);
                                }
                        }

                        return Res;
                }
Example #4
0
        public virtual Lazaro.Pres.Spreadsheet.Workbook ToWorkbookDetalle(int IDComprobante)
        {
            Lbl.Comprobantes.Factura selComprobante = new Lbl.Comprobantes.Factura(this.Connection, IDComprobante);

            Lazaro.Pres.Spreadsheet.Workbook Res   = new Lazaro.Pres.Spreadsheet.Workbook();
            Lazaro.Pres.Spreadsheet.Sheet    Sheet = new Lazaro.Pres.Spreadsheet.Sheet(this.Text + " Comprobante");
            Res.Sheets.Add(Sheet);


            int OrderColumn = -1;

            if (selComprobante != null)
            {
                for (int i = 0; i < 9; i++)
                {
                    ExcelReg nexc = new ExcelReg();
                    switch (i)
                    {
                    case 0:
                        nexc.name      = "id_articulo";
                        nexc.desc      = "Código";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 100;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Integer;
                        break;

                    case 1:
                        nexc.name      = "nombre";
                        nexc.desc      = "Nombre";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 300;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Text;
                        break;

                    case 2:
                        nexc.name      = "descripcion";
                        nexc.desc      = "Descripción";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 150;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Text;
                        break;

                    case 3:
                        nexc.name      = "cantidad";
                        nexc.desc      = "Cantidad";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 80;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Numeric;
                        break;

                    case 4:
                        nexc.name      = "costo";
                        nexc.desc      = "Costo";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 90;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Currency;
                        break;

                    case 5:
                        nexc.name      = "precio";
                        nexc.desc      = "Precio Uni.";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 120;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Currency;
                        break;

                    case 6:
                        nexc.name      = "importe";
                        nexc.desc      = "Importe";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 120;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Currency;
                        break;

                    case 7:
                        nexc.name      = "recargo";
                        nexc.desc      = "Recargo";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 100;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Currency;
                        break;

                    case 8:
                        nexc.name      = "total";
                        nexc.desc      = "Total";
                        nexc.alig      = Lfx.Types.StringAlignment.Near;
                        nexc.width     = 120;
                        nexc.fieldtype = Lfx.Data.InputFieldTypes.Currency;

                        break;
                    }
                    Lazaro.Pres.Spreadsheet.ColumnHeader ColHead = new Lazaro.Pres.Spreadsheet.ColumnHeader(nexc.desc, nexc.width);
                    ColHead.Name          = Lazaro.Orm.Data.ColumnValue.GetNameOnly(nexc.name);
                    ColHead.TextAlignment = nexc.alig; ColHead.DataType = nexc.fieldtype; ColHead.Format = nexc.format; ColHead.Printable = true;
                    if (i == 8)
                    {
                        ColHead.TotalFunction = Lazaro.Pres.Spreadsheet.QuickFunctions.Sum;
                    }
                    Sheet.ColumnHeaders.Add(ColHead);
                    excReg.Add(nexc);
                }
            }

            // Exporto los renglones
            Lbl.Comprobantes.ColeccionDetalleArticulos detArt = selComprobante.Articulos;
            foreach (Lbl.Comprobantes.DetalleArticulo DtRow in detArt)
            {
                Lazaro.Pres.Spreadsheet.Row Reng = this.FormatArt(Sheet, DtRow);
                Sheet.Rows.Add(Reng);
            }

            if (OrderColumn >= 0)
            {
                if (m_GroupingColumnName != null)
                {
                    Sheet.SortByGroupAndColumn(OrderColumn, true);
                }
                else
                {
                    if (OrderColumn >= 0)
                    {
                        Sheet.Sort(OrderColumn, true);
                    }
                }
            }

            return(Res);
        }
Example #5
0
        public override Lazaro.Pres.Spreadsheet.Workbook ToWorkbook(Lazaro.Pres.FieldCollection useFields)
        {
            Lazaro.Pres.Spreadsheet.Workbook Res   = new Lazaro.Pres.Spreadsheet.Workbook();
            Lazaro.Pres.Spreadsheet.Sheet    Sheet = new Lazaro.Pres.Spreadsheet.Sheet(this.Text);
            Res.Sheets.Add(Sheet);

            // Exporto los encabezados de columna
            if (this.Definicion.KeyColumn.Printable)
            {
                Sheet.ColumnHeaders.Add(new Lazaro.Pres.Spreadsheet.ColumnHeader(this.Definicion.KeyColumn.Label, this.Definicion.KeyColumn.Width));
                Sheet.ColumnHeaders[0].DataType  = this.Definicion.KeyColumn.DataType;
                Sheet.ColumnHeaders[0].Format    = this.Definicion.KeyColumn.Format;
                Sheet.ColumnHeaders[0].Printable = this.Definicion.KeyColumn.Printable;
            }

            int OrderColumn = -1;

            if (useFields != null)
            {
                for (int i = 0; i <= useFields.Count - 1; i++)
                {
                    if (useFields[i].Printable)
                    {
                        Lazaro.Pres.Spreadsheet.ColumnHeader ColHead = new Lazaro.Pres.Spreadsheet.ColumnHeader(useFields[i].Label, useFields[i].Width);
                        ColHead.Name          = Lazaro.Orm.Data.ColumnValue.GetNameOnly(useFields[i].Name);
                        ColHead.TextAlignment = useFields[i].Alignment;
                        ColHead.DataType      = useFields[i].DataType;
                        ColHead.Format        = useFields[i].Format;
                        ColHead.TotalFunction = useFields[i].TotalFunction;
                        ColHead.Printable     = useFields[i].Printable;
                        Sheet.ColumnHeaders.Add(ColHead);

                        if (ColHead.Name == this.Definicion.OrderBy)
                        {
                            OrderColumn = Sheet.ColumnHeaders.Count - 1;
                        }

                        if (ColHead.Name == this.GroupingColumnName)
                        {
                            Sheet.ColumnHeaders.GroupingColumn = Sheet.ColumnHeaders.Count - 1;
                        }
                    }
                }
            }

            // Exporto los renglones
            System.Data.DataTable Tabla = this.Connection.Select(this.SelectCommand());
            int lastItemId = -1;

            foreach (System.Data.DataRow DtRow in Tabla.Rows)
            {
                Lfx.Data.Row Registro = (Lfx.Data.Row)DtRow;

                string NombreCampoId = Lazaro.Orm.Data.ColumnValue.GetNameOnly(this.Definicion.KeyColumn.Name);
                int    ItemId        = Registro.Fields[NombreCampoId].ValueInt;
                lastItemId = ItemId;
                Lazaro.Pres.Spreadsheet.Row Reng = this.FormatRow(ItemId, Registro, Sheet, useFields);

                Sheet.Rows.Add(Reng);
            }

            Lazaro.Pres.Spreadsheet.Row RengSum = this.FormatRowSum(Sheet, useFields);

            Sheet.Rows.Add(RengSum);

            if (OrderColumn >= 0)
            {
                if (m_GroupingColumnName != null)
                {
                    Sheet.SortByGroupAndColumn(OrderColumn, true);
                }
                else
                {
                    if (OrderColumn >= 0)
                    {
                        Sheet.Sort(OrderColumn, true);
                    }
                }
            }
            //Sheet.Workbook.Sheets.Find("").Rows.tot

            return(Res);
        }
Example #6
0
        protected override void ShowExportDialog()
        {
            if (Listado.Items.Count == 0)
            {
                Lfx.Workspace.Master.RunTime.Toast("No se puede imprimir o exportar el listado porque no contiene datos.", "Listado");
                return;
            }

            using (Lfc.FormularioListadoExportar FormExportar = new Lfc.FormularioListadoExportar())
            {
                if (FormExportar.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    FormatoExportar Formato = FormExportar.SaveFormat;
                    if (Formato == FormatoExportar.Imprimir)
                    {
                        this.OnPrint(false);
                    }
                    else if (Formato == FormatoExportar.ImprimirAvanzado)
                    {
                        this.OnPrint(true);
                    }
                    else
                    {
                        SaveFileDialog DialogoGuardar = new SaveFileDialog();
                        DialogoGuardar.OverwritePrompt = true;
                        DialogoGuardar.ValidateNames   = true;
                        DialogoGuardar.CheckPathExists = true;
                        switch (Formato)
                        {
                        case FormatoExportar.Html:
                            DialogoGuardar.DefaultExt = ".html";
                            DialogoGuardar.Filter     = "Formato HTML|*.htm;*.html";
                            break;

                        case FormatoExportar.Excel:
                            DialogoGuardar.DefaultExt = ".xlsx";
                            DialogoGuardar.Filter     = "Microsoft Excel 2007-2013|*.xlsx";
                            break;
                        }

                        DialogoGuardar.FileName = this.Text.Replace(":", "");
                        if (DialogoGuardar.ShowDialog() == DialogResult.OK)
                        {
                            Lazaro.Pres.Spreadsheet.Workbook Workbook = this.ToWorkbook();
                            string FileName = DialogoGuardar.FileName;
                            this.OnExport(FileName, Formato);
                            try
                            {
                                switch (Formato)
                                {
                                case FormatoExportar.Html:
                                    Workbook.SaveTo(FileName, Lazaro.Pres.Spreadsheet.SaveFormats.Html);
                                    break;

                                case FormatoExportar.Excel:
                                    Workbook.SaveTo(FileName, Lazaro.Pres.Spreadsheet.SaveFormats.Excel);
                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                Lfx.Workspace.Master.RunTime.Toast("No se puede guardar el archivo. " + ex.Message, "Error");
                            }
                        }
                    }
                }
            }
        }