예제 #1
0
        /// <summary>
        /// Exporta los datos a un documento de Excel.
        /// </summary>
        /// <history>
        /// [edgrodriguez] 28/Abr/2016 Created
        /// </history>
        private async void BtnPrint_OnClick(object sender, RoutedEventArgs e)
        {
            biWait.IsBusy = true;
            if (dgvLoginsLog.Items.Count <= 0)
            {
                return;
            }
            biWait.BusyContent = "Loading Report...";

            string message = ValidateFields();

            if (message != "")
            {
                UIHelper.ShowMessage(message); return;
            }

            DataTable dtRptLoginsLog = TableHelper.GetDataTableFromList(lstLoginsLog.View.Cast <RptLoginLog>().ToList(), true,
                                                                        false, true);

            List <Tuple <string, string> > filters = new List <Tuple <string, string> >
            {
                Tuple.Create("Date Range",
                             DateHelper.DateRange(dtmStart.Value.Value, dtmEnd.Value.Value)),
                Tuple.Create("Location", cbLocation.SelectedValue.ToString()),
                Tuple.Create("Personnel", cbPersonnel.SelectedValue.ToString()),
                Tuple.Create("PC Name", cbPcName.SelectedValue.ToString())
            };

            string strReportName = "Logins Log";
            string dateFileName  = DateHelper.DateRangeFileName(dtmStart.Value.Value, dtmEnd.Value.Value);

            string fileFullPath = ReportBuilder.CreateEmptyExcel(strReportName, dateFileName);

            frmReportQ.AddReport(fileFullPath, strReportName);
            try
            {
                var finfo = await ReportBuilder.CreateCustomExcelAsync(dtRptLoginsLog, filters, strReportName, string.Empty, clsFormatReport.RptLoginsLog(), isRptQueue : true, filePath : fileFullPath, addEnumeration : true);

                if (finfo == null)
                {
                    finfo = ReportBuilder.CreateNoInfoRptExcel(filters, strReportName, fileFullPath);
                }
                frmDocumentViewer frmDocumentViewver = new frmDocumentViewer(finfo, Context.User.HasPermission(EnumPermission.RptExcel, EnumPermisionLevel.ReadOnly));
                frmDocumentViewver.Show();
                frmReportQ.SetExist(finfo.FullName, finfo);
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
                biWait.IsBusy = false;
            }
            biWait.IsBusy = false;
        }
예제 #2
0
        /// <summary>
        /// Muestra el reporte de Sales Room Seleccionado
        /// </summary>
        /// <param name="rptRoomSales"></param>
        /// <param name="clsFilter"></param>
        /// <history>
        /// [ecanul] 05/05/2016 Created
        /// </history>
        private async void ShowReportBySalesRoom(EnumRptSalesRoom rptRoomSales, ClsFilter clsFilter)
        {
            FileInfo file = null;

            //Deberia validarse con
            #region Datos del reporte
            string dateRange = _multiDate
           ? string.Join("; ", clsFilter.LstMultiDate.Select(x => $"{x.SalesRoom}  {DateHelper.DateRange(x.DtStart, x.DtEnd)}"))
           : DateHelper.DateRange(clsFilter.DtmStart, clsFilter.DtmEnd);
            string dateRangeFileName = _multiDate
          ? string.Join("; ", clsFilter.LstMultiDate.Select(x => $"{x.SalesRoom}  {DateHelper.DateRange(x.DtStart, x.DtEnd)}"))
         : DateHelper.DateRangeFileName(clsFilter.DtmStart, clsFilter.DtmEnd);
            string reporteName = EnumToListHelper.GetEnumDescription(rptRoomSales);
            #endregion

            #region Filtro(s)
            List <Tuple <string, string> > filters = new List <Tuple <string, string> >
            {
                new Tuple <string, string>("Date Range", dateRange)
            };
            //Si es cualquier reporte menos Concentrate Daily Sales o Multidate (porque sus grids son diferentes) se agrega de manera comun
            if (rptRoomSales != EnumRptSalesRoom.ConcerntrateDailySales && rptRoomSales != EnumRptSalesRoom.StatsBySegmentsCategoriesMultiDatesRanges)
            {
                //Si es de solo un registro El sales Room es unico, si no Se toma por Todos o por los seleccionados
                if (_onlyOnRegister)
                {
                    filters.Add(new Tuple <string, string>("Sales Room", clsFilter.LstSalesRooms.First()));
                }
                else
                {
                    filters.Add(new Tuple <string, string>("Sales Room",
                                                           _frmFilter.dtgSalesRoom.Items.Count == clsFilter.LstSalesRooms.Count ? "All" : string.Join(",", clsFilter.LstSalesRooms)));
                }
            }
            if (rptRoomSales == EnumRptSalesRoom.StatsByCloser || rptRoomSales == EnumRptSalesRoom.StatsByExitCloser || rptRoomSales == EnumRptSalesRoom.StatsByFtb)
            {
                filters.Add(Tuple.Create("Programs", EnumToListHelper.GetEnumDescription(clsFilter.EnumProgram)));
                filters.Add(Tuple.Create("Segments", clsFilter.BlnAllSegments ? "ALL" : string.Join(",", clsFilter.LstSegments)));
            }

            #endregion

            List <dynamic> list         = new List <dynamic>();
            string         fileFullPath = ReportBuilder.CreateEmptyExcel(reporteName, dateRangeFileName);
            _frmReportQueue.AddReport(fileFullPath, reporteName);
            try
            {
                switch (rptRoomSales)
                {
                    #region Manifest
                case EnumRptSalesRoom.Manifest:

                    list.AddRange(await BRReportsBySalesRoom.GetRptManiest(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptManifest(reporteName, fileFullPath, filters, list.Cast <RptManifest>().ToList(), clsFilter.DtmStart, clsFilter.DtmEnd);
                    }
                    break;
                    #endregion

                    #region StatsByLocation
                case EnumRptSalesRoom.StatsByLocation:
                    list.AddRange(await BRReportsBySalesRoom.GetRptStatisticsByLocation(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptStatisticsByLocation(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByLocation>().ToList());
                    }
                    break;
                    #endregion

                    #region StatsByLocationMonthly
                case EnumRptSalesRoom.StatsByLocationMonthly:
                    list.AddRange(await BRReportsBySalesRoom.GetRptStaticsByLocationMonthly(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptStaticsByLocationMonthly(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByLocationMonthly>().ToList());
                    }
                    break;
                    #endregion

                    #region SalesByLocationMonthly
                case EnumRptSalesRoom.SalesByLocationMonthly:
                    list.AddRange(await BRReportsBySalesRoom.GetRptSalesByLocationMonthly(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptSalesByLocationMonthly(reporteName, fileFullPath, filters, list.Cast <RptSalesByLocationMonthly>().ToList());
                    }
                    break;
                    #endregion

                    #region StatsByLocationAndSalesRoom
                case EnumRptSalesRoom.StatsByLocationAndSalesRoom:
                    list.AddRange(await BRReportsBySalesRoom.GetRptStatisticsBySalesRoomLocation(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptStatisticsBySalesRoomLocation(reporteName, fileFullPath, filters, list.Cast <RptStatisticsBySalesRoomLocation>().ToList());
                    }
                    break;
                    #endregion

                    #region ConcerntrateDailySales
                case EnumRptSalesRoom.ConcerntrateDailySales:
                    #region FiltroSalesRoomConcentrate
                    clsFilter.LstSalesRooms.AddRange(clsFilter.LstGoals.Select(c => c.SalesRoomByUser.srID));
                    filters.Add(new Tuple <string, string>("Sales Room", string.Join("/", clsFilter.LstGoals.Select(c => c.SalesRoomByUser.srID).ToList())));
                    #endregion

                    list.AddRange(await BRReportsBySalesRoom.GetRptConcentrateDailySales(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstGoals.Select(c => c.SalesRoomByUser.srID).ToList()));

                    if (list.Count > 0)
                    {
                        file = await Reports.RptConcentrateDailySales(reporteName, fileFullPath, clsFilter.DtmEnd, filters,
                                                                      list.Cast <RptConcentrateDailySales>().ToList(), clsFilter.LstGoals);
                    }
                    break;
                    #endregion

                    #region DailySales
                case EnumRptSalesRoom.DailySales:
                    list.AddRange(await BRReportsBySalesRoom.GetRptDailySalesDetail(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    List <RptDailySalesHeader> lstHeader = await BRReportsBySalesRoom.GetRptDailySalesHeader(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms);

                    if (list.Count > 0 && lstHeader.Count > 0)
                    {
                        file = await Reports.RptDailySales(reporteName, dateRange, fileFullPath, filters, list.Cast <RptDailySalesDetail>().ToList(),
                                                           lstHeader, clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.Goal);
                    }
                    break;
                    #endregion

                    #region FTM In & Out House
                case EnumRptSalesRoom.FtmInAndOutHouse:
                    list.AddRange(await BRReportsBySalesRoom.GetRptFTMInOutHouse(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptFTMInOutHouse(reporteName, fileFullPath, filters, list.Cast <RptFTMInOutHouse>().ToList(), clsFilter.DtmStart, clsFilter.DtmEnd);
                    }
                    break;
                    #endregion

                    #region Stats by Segments

                case EnumRptSalesRoom.StatsBySegments:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsBySegments(new[] { clsFilter.DtmStart }, new[] { clsFilter.DtmEnd }, clsFilter.LstSalesRooms, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsBySegments(reporteName, fileFullPath, filters, list.Cast <RptStatisticsBySegments>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion Stats by Segments

                    #region Stats by Segments (OWN)
                case EnumRptSalesRoom.StatsBySegmentsOwn:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsBySegments(new[] { clsFilter.DtmStart }, new[] { clsFilter.DtmEnd }, clsFilter.LstSalesRooms, own: true, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));

                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsBySegments(reporteName, fileFullPath, filters, list.Cast <RptStatisticsBySegments>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion Stats by Segments (OWN)

                    #region Stats by Segments Categories
                case EnumRptSalesRoom.StatsBySegmentsCategories:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsBySegments(new[] { clsFilter.DtmStart }, new[] { clsFilter.DtmEnd }, clsFilter.LstSalesRooms, bySegmentsCategories: true,
                                                                                     includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsBySegments(reporteName, fileFullPath, filters, list.Cast <RptStatisticsBySegments>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion Stats by Segments Categories

                    #region Stats by Segments Categories (OWN)
                case EnumRptSalesRoom.StatsBySegmentsCategoriesOwn:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsBySegments(new[] { clsFilter.DtmStart }, new[] { clsFilter.DtmEnd }, clsFilter.LstSalesRooms, bySegmentsCategories: true,
                                                                                     own: true, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsBySegments(reporteName, fileFullPath, filters, list.Cast <RptStatisticsBySegments>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion Stats by Segments Categories (OWN)

                    #region Stats by Segments Categories (Multi Date Ranges)
                case EnumRptSalesRoom.StatsBySegmentsCategoriesMultiDatesRanges:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsBySegments(clsFilter.LstMultiDate.Select(x => x.DtStart), clsFilter.LstMultiDate.Select(x => x.DtEnd),
                                                                                     clsFilter.LstMultiDate.Select(x => x.SalesRoom), bySegmentsCategories: true, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsBySegments(reporteName, fileFullPath, filters, list.Cast <RptStatisticsBySegments>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion Stats by Segments Categories (Multi Date Ranges)

                    #region Stats by Closer
                case EnumRptSalesRoom.StatsByCloser:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsByCloser(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms.First(),
                                                                                   program: clsFilter.EnumProgram, segments: clsFilter.BlnAllSegments ? null : clsFilter.LstSegments, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen, groupByTeams: clsFilter.BlnGroupedByTeams));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsByCloser(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByCloser>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion

                    #region Stats by Exit Closer
                case EnumRptSalesRoom.StatsByExitCloser:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsByExitCloser(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms.First(),
                                                                                       program: clsFilter.EnumProgram, segments: clsFilter.BlnAllSegments ? null : clsFilter.LstSegments, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsByExitCloser(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByExitCloser>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion

                    #region Self Gen & Self Gen Team
                case EnumRptSalesRoom.SelfGenAndSelfGenTeam:
                    list.AddRange(await BRReportsBySalesRoom.GetRptSelfGenAndSelfGenTeam(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms));
                    if (list.Count > 0)
                    {
                        file = await Reports.RptSelfGenAndSelfGenTeam(reporteName, fileFullPath, filters, list.Cast <RptSelfGenTeam>().ToList(), clsFilter.DtmStart, clsFilter.DtmEnd);
                    }
                    break;
                    #endregion

                    #region Stats by F.T.B
                case EnumRptSalesRoom.StatsByFtb:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsByFTB(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms.First(),
                                                                                program: clsFilter.EnumProgram, segments: clsFilter.BlnAllSegments ? null : clsFilter.LstSegments, groupByTeam: clsFilter.BlnGroupedByTeams, includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsByFTB(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByFTB>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion

                    #region Stats by F.T.B. & Locations
                case EnumRptSalesRoom.StatsByFtbAndLocatios:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsByFTBLocations(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms.First(), groupByTeam: clsFilter.BlnGroupedByTeams,
                                                                                         includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsByFTBByLocations(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByFTBLocations>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion

                    #region Stats by F.T.B. & Locations Categories
                case EnumRptSalesRoom.StatsByFtbAndLocatiosCategories:
                    list.AddRange(await BRReportsBySalesRoom.GetStatisticsByFTBCategories(clsFilter.DtmStart, clsFilter.DtmEnd, clsFilter.LstSalesRooms.First(), groupByTeam: clsFilter.BlnGroupedByTeams,
                                                                                          includeAllSalesmen: clsFilter.BlnIncludeAllSalesmen));
                    if (list.Any())
                    {
                        file = await Reports.RptStatisticsByFTBByCategories(reporteName, fileFullPath, filters, list.Cast <RptStatisticsByFTBCategories>().ToList(), clsFilter.BlnGroupedByTeams);
                    }
                    break;
                    #endregion

                    #region Efficiency Weekly
                case EnumRptSalesRoom.EfficiencyWeekly:
                    list.AddRange(await BRReportsBySalesRoom.GetRptEfficiencyWeekly(clsFilter.lstEfficiency.Select(x => x.efDateFrom), clsFilter.lstEfficiency.Select(x => x.efDateTo),
                                                                                    clsFilter.LstSalesRooms.First().ToString()));
                    if (list.Any())
                    {
                        file = await Reports.RptEfficiencyWeekly(reporteName, fileFullPath, filters, list.Cast <RptEfficiencyWeekly>().ToList(), clsFilter);
                    }
                    break;
                    #endregion
                }
                if (file == null)
                {
                    file = ReportBuilder.CreateNoInfoRptExcel(filters, reporteName, fileFullPath);
                }
                frmDocumentViewer frmDocumentViewver = new frmDocumentViewer(file, Context.User.HasPermission(EnumPermission.RptExcel, EnumPermisionLevel.ReadOnly));
                frmDocumentViewver.Show();
                _frmReportQueue.SetExist(file.FullName, file);
                _frmReportQueue.Activate();
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }