Example #1
0
        private void BuscarRomaneo()
        {
            CooperativaProduccionEntities Context = new CooperativaProduccionEntities();

            List <GridRomaneo> lista = new List <GridRomaneo>();

            Expression <Func <Vw_Romaneo, bool> > pred = x => true;

            pred = pred.And(x => x.FechaRomaneo >= dpDesdeRomaneo.Value.Date &&
                            x.FechaRomaneo <= dpHastaRomaneo.Value.Date);

            if (ProductorId != Guid.Empty)
            {
                pred = pred.And(x => x.ProductorId == ProductorId);
            }

            pred = pred.And(x => x.Tabaco == cbTabaco.Text);

            var liquidaciones =
                (from a in Context.Vw_Romaneo
                 .Where(pred)
                 select new
            {
                ID = a.PesadaId,
                FECHA = a.FechaRomaneo,
                FET = a.nrofet,
                PRODUCTOR = a.NOMBRE,
                PROVINCIA = a.Provincia,
                TABACO = a.Tabaco
            })
                .OrderByDescending(x => x.FECHA)
                .ThenBy(x => x.FET)
                .ToList();

            foreach (var liquidacion in liquidaciones)
            {
                var liquidacionDetalle =
                    (from pd in Context.PesadaDetalle
                     .Where(x => x.PesadaId == liquidacion.ID)
                     join p in Context.Vw_Clase
                     on pd.ClaseId equals p.ID
                     join c in Context.Vw_Clase
                     on pd.ReclasificacionId equals c.ID into romaneo
                     from r in romaneo.DefaultIfEmpty()
                     select new
                {
                    Id = pd.Id,
                    Clase = p.NOMBRE,
                    Fardo = pd.NumFardo,
                    Kilos = pd.Kilos,
                    Reclasificacion = r.NOMBRE
                })
                    .ToList();

                var rowsDetalle = liquidacionDetalle.Select(x =>
                                                            new GridRomaneoDetalle()
                {
                    Id              = x.Id,
                    Clase           = x.Clase,
                    Fardos          = x.Fardo,
                    Kilos           = x.Kilos,
                    Reclasificacion = x.Reclasificacion
                })
                                  .OrderBy(x => x.Fardos)
                                  .ToList();

                var rowRomaneo = new GridRomaneo();
                rowRomaneo.PesadaId     = liquidacion.ID;
                rowRomaneo.FechaRomaneo = liquidacion.FECHA.Value.ToShortDateString();
                rowRomaneo.nrofet       = liquidacion.FET;
                rowRomaneo.NOMBRE       = liquidacion.PRODUCTOR;
                rowRomaneo.Provincia    = liquidacion.PROVINCIA;
                rowRomaneo.Tabaco       = liquidacion.TABACO;
                rowRomaneo.Detalle      = rowsDetalle;
                lista.Add(rowRomaneo);
            }

            gridControlRomaneo.DataSource      = new BindingList <GridRomaneo>(lista);
            gridViewRomaneo.Columns[0].Visible = false;
            gridViewRomaneo.Columns[1].Caption = "Fecha de Romaneo";
            gridViewRomaneo.Columns[1].Width   = 60;
            gridViewRomaneo.Columns[1].AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gridViewRomaneo.Columns[1].AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Center;
            gridViewRomaneo.Columns[2].Caption = "FET";
            gridViewRomaneo.Columns[2].Width   = 60;
            gridViewRomaneo.Columns[2].AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Center;
            gridViewRomaneo.Columns[2].AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gridViewRomaneo.Columns[3].Caption = "Productor";
            gridViewRomaneo.Columns[3].Width   = 200;
            gridViewRomaneo.Columns[4].Caption = "Provincia";
            gridViewRomaneo.Columns[4].Width   = 70;
            gridViewRomaneo.Columns[4].AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Center;
            gridViewRomaneo.Columns[4].AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
            gridViewRomaneo.Columns[5].Caption = "Tabaco";
            gridViewRomaneo.Columns[5].Width   = 90;
            gridViewRomaneo.Columns[5].AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Center;
            gridViewRomaneo.Columns[5].AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;

            for (var i = 0; i <= gridViewRomaneo.RowCount; i++)
            {
                gridViewRomaneo.SelectRow(i);
            }
        }
        private void ExportarListaRomaneoClases()
        {
            string path = @"C:\SystemDocumentsCooperativa";

            CreateIfMissing(path);

            path = @"C:\SystemDocumentsCooperativa\ExcelRomaneoConClases";

            CreateIfMissing(path);

            var Hora = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff",
                                             CultureInfo.InvariantCulture).Replace(":", "").Replace(".", "")
                       .Replace("-", "").Replace(" ", "");

            string fileName = @"C:\SystemDocumentsCooperativa\ExcelRomaneoConClases\" + Hora + " - ExcelRomaneoConClases.xls";

            var reporte = new ListaRomaneoConClasesReport();

            List <GridRomaneo> lista = new List <GridRomaneo>();

            Expression <Func <Vw_Romaneo, bool> > pred = x => true;

            pred = pred.And(x => x.FechaRomaneo >= dpDesdeRomaneo.Value.Date &&
                            x.FechaRomaneo <= dpHastaRomaneo.Value.Date);

            if (ProductorId != Guid.Empty)
            {
                pred = pred.And(x => x.ProductorId == ProductorId);
            }

            pred = pred.And(x => x.Tabaco == cbTabaco.Text);

            var liquidaciones =
                (from a in Context.Vw_Romaneo
                 .Where(pred)
                 select new
            {
                ID = a.PesadaId,
                FECHA = a.FechaRomaneo,
                NUMROMANEO = a.NumRomaneo,
                PRODUCTOR = a.NOMBRE,
                CUIT = a.CUIT,
                FET = a.nrofet,
                PROVINCIA = a.Provincia,
                TOTALKG = a.TotalKg,
                IMPORTEBRUTO = a.ImporteBruto,
                TABACO = a.Tabaco
            })
                .OrderByDescending(x => x.FECHA)
                .ThenBy(x => x.FET)
                .ToList();

            foreach (var liquidacion in liquidaciones)
            {
                var liquidacionDetalle =
                    (from pd in Context.PesadaDetalle
                     .Where(x => x.PesadaId == liquidacion.ID)
                     join p in Context.Vw_Clase
                     on pd.ClaseId equals p.ID
                     group pd by new
                {
                    Clase = p.NOMBRE
                } into g
                     select new
                {
                    Clase = g.Key.Clase,
                    Fardos = g.Count(),
                    Kilos = g.Sum(x => x.Kilos)
                })
                    .ToList();

                var rowsDetalle = liquidacionDetalle.Select(x =>
                                                            new GridRomaneoResumenCompraDetalle()
                {
                    Clase  = x.Clase,
                    Fardos = x.Fardos,
                    Kilos  = x.Kilos
                })
                                  .OrderBy(x => x.Fardos)
                                  .ToList();

                var rowRomaneo = new GridRomaneo();
                rowRomaneo.PesadaId             = liquidacion.ID;
                rowRomaneo.FechaRomaneo         = liquidacion.FECHA.Value.ToShortDateString();
                rowRomaneo.NumRomaneo           = liquidacion.NUMROMANEO.Value.ToString();
                rowRomaneo.NOMBRE               = liquidacion.PRODUCTOR;
                rowRomaneo.CUIT                 = liquidacion.CUIT;
                rowRomaneo.nrofet               = liquidacion.FET;
                rowRomaneo.Provincia            = liquidacion.PROVINCIA;
                rowRomaneo.TotalKg              = liquidacion.TOTALKG.Value.ToString();
                rowRomaneo.ImporteBruto         = liquidacion.IMPORTEBRUTO.Value.ToString();
                rowRomaneo.Tabaco               = liquidacion.TABACO;
                rowRomaneo.ResumenCompraDetalle = rowsDetalle;
                lista.Add(rowRomaneo);
            }
            reporte.DataSource = new BindingList <GridRomaneo>(lista);

            XlsExportOptions xlsOptions = reporte.ExportOptions.Xls;

            // Set XLS-specific export options.
            xlsOptions.ShowGridLines  = true;
            xlsOptions.TextExportMode = TextExportMode.Value;

            // Export the report to XLS.
            reporte.ExportToXls(fileName);

            // Show the result.
            StartProcess(fileName);
        }