Example #1
0
        //Controller to get all Actions and GatheringUsers
        public async Task <IActionResult> MyReport()
        {
            var user = await GetCurrentUserAsync();

            MyReport myReport = new MyReport
            {
                activities = await _context.Activity.Include(a => a.Location).Where(a => a.EndTime < DateTime.Now).ToListAsync(),

                gatheringUsers = await _context.GatheringUser.Include(gu => gu.Gathering).ThenInclude(g => g.Location).Where(gu => gu.Gathering.EndTime < DateTime.Now).ToListAsync()
            };

            List <string> users = new List <string>();

            //Get all of the activities that have ended for the user that is logged in.
            myReport.myActivityHistory = myReport.activities.Where(a => a.UserId == user.Id).ToList();

            //Get all of the gatherings the logged-in user has attended that have ended.
            myReport.myGatheringHistory = myReport.gatheringUsers.Where(gu => gu.UserId == user.Id).ToList();

            //For each activity, get the hours between the start time and end time and store them in the TotalCampaignHours property.
            myReport.activities.ForEach(a =>
            {
                TimeSpan diff = a.EndTime - a.StartTime;
                double hours  = diff.TotalHours;
                users.Add(a.UserId);

                if (a.UserId == user.Id)
                {
                    myReport.MyHours += hours;
                }

                myReport.TotalCampaignHours += hours;
            });

            myReport.gatheringUsers.ForEach(gu =>
            {
                TimeSpan diff = gu.Gathering.EndTime - gu.Gathering.StartTime;
                double hours  = diff.TotalHours;
                users.Add(gu.UserId);

                if (gu.UserId == user.Id)
                {
                    myReport.MyHours += hours;
                }

                myReport.TotalCampaignHours += hours;
            });

            //Get the number of distinct users that are active(Have completed at an Activity or attended a Gathering).
            List <string> distinctUsers    = users.Distinct().ToList();
            int           ActiveUsersCount = distinctUsers.Count();

            myReport.MyHours          = Math.Round(myReport.MyHours, 2);
            myReport.AverageUserHours = Math.Round(myReport.TotalCampaignHours / ActiveUsersCount, 2);

            return(View(myReport));
        }
        public JsonResult SaveDatabaseReport(string ReportName, string sqlQuery)
        {
            string msg = "Report saved successfully";

            try
            {
                StringBuilder             csvContent       = new StringBuilder();
                List <DatabaseAttributes> lstTableFeatures = mainDAL.SearchDatabase(sqlQuery);

                for (int i = 0; i < lstTableFeatures.Count; i++)
                {
                    if (i == 0)
                    {
                        csvContent.AppendLine(CreateCsvLine(lstTableFeatures[i], true));
                        csvContent.AppendLine(CreateCsvLine(lstTableFeatures[i], false));
                    }
                    else
                    {
                        csvContent.AppendLine(CreateCsvLine(lstTableFeatures[i], false));
                    }
                }

                string targetFolder = Server.MapPath("~/Reports");
                string fileName     = ReportName + "_" + DateTime.Now.Ticks.ToString() + ".csv";
                string targetPath   = Path.Combine(targetFolder, fileName);

                System.IO.File.AppendAllText(targetPath, csvContent.ToString());

                MyReport myReport = new MyReport()
                {
                    Username   = GlobalVariables.GetFromCookie("NYCUser", "Username"),
                    ReportName = ReportName,
                    FileName   = fileName
                };
                db.MyReports.Add(myReport);
                db.SaveChanges();

                return(Json(new { msg }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(Json(new { msg }, JsonRequestBehavior.AllowGet));
            }
        }
        public static List <object> ConvertToChartData(WidgetModel widgetModel, ResultValue resultValue, List <MetricTypeModel> metricsCache)
        {
            var datas   = new ObservableCollection <string>();
            var series  = new ObservableCollection <MyReport>();
            var axisDic = new Dictionary <string, Tuple <string, string> >();
            var values  = new List <decimal>();

            var metrics = widgetModel.Metrics.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var metric in metrics)
            {
                var metricX = metricsCache.FirstOrDefault(m => m.SystemTypeId == widgetModel.SystemTypeId && m.EnName == metric);
                datas.Add(metricX.CnName);

                axisDic.Add(metric, new Tuple <string, string>(metricX.CnName, "Y"));
            }

            #region

            var label = string.Empty;
            switch (widgetModel.DataType)
            {
            case "1":
                label = "所有节目";
                break;

            case "2":
                label = "指定节目";
                break;

            case "3":
                label = "节目类型";
                break;

            case "4":
                label = "赞助级别";
                break;

            case "5":
                label = "电视台";
                break;

            case "6":
                label = "视频网站自制";
                break;

            case "7":
                label = "品牌品类";
                break;
            }

            switch (widgetModel.DateTypeId)
            {
            case 5:
                label += "-本期";
                break;

            case 6:
                label += "-上期";
                break;

            case 7:
                label += "-历史";
                break;
            }

            #endregion

            var report = new MyReport();
            report.Label = label;

            var  data       = new ObservableCollection <C1Data>();
            Type systemType = typeof(SponsorData);
            var  resultX    = JsonConvert.DeserializeObject <SponsorData>(resultValue.Value);

            foreach (var metric in metrics)
            {
                PropertyInfo mPropertyInfo = systemType.GetProperty(metric.Substring(0, 1).ToUpperInvariant() + metric.Substring(1, metric.Length - 1).TrimEnd());

                decimal value;
                if (mPropertyInfo.GetValue(resultX, null) == null)
                {
                    value = 0;
                }
                else
                {
                    if (mPropertyInfo.GetValue(resultX, null) is int)
                    {
                        value = Convert.ToInt32(mPropertyInfo.GetValue(resultX, null));
                    }
                    else if (mPropertyInfo.GetValue(resultX, null) is double || mPropertyInfo.GetValue(resultX, null) is decimal)
                    {
                        value = Convert.ToDecimal(mPropertyInfo.GetValue(resultX, null));
                    }
                    else
                    {
                        value = 0;
                    }
                }
                data.Add(new C1Data {
                    Value = value
                });
                values.Add(value);
            }

            report.Data = data;
            series.Add(report);

            return(new List <object> {
                datas, series, axisDic, values
            });
        }
Example #4
0
        private void btnConferenciaEstoque_Click(object sender, EventArgs e)
        {

            try
            {
                espere = new Espere();
                espere.Start(MostrarMensagemEspera);
                string fileName = "estoqueConferencia.rdlc";
                RelatorioEstoqueConferenciaRepositorio estoqueConferenciaRepositorio = new RelatorioEstoqueConferenciaRepositorio();
                var table = estoqueConferenciaRepositorio.GetRelatorioConferencia();
                MyReport report = new MyReport(table, fileName.GetFullPath(), "EstoqueConferencia", ProcessingMode.Local);
                report.GerarRelatoriosComParametrosEQueryDefinidosNaQueryPDF(new System.Collections.Generic.List<ReportParameter>
                {
                    new ReportParameter("NomeConf",Usuarios.NomeCompletoStatic)

                });
                espere.CancelarTask();
                if (espere.Cancel.IsCancellationRequested)
                    frmEspera?.Close();
            }
            catch (CustomException error)
            {
                DialogMessage.MessageFullComButtonOkIconeDeInformacao(message: error.Message, title: "Aviso");
            }
            catch (Exception error)
            {
                SaveErroInTxt.RecordInTxt(error, this.GetType().Name);
                DialogMessage.MessageFullComButtonOkIconeDeInformacao(message: error.Message, title: "Aviso");
            }
            finally
            {
                espere.CancelarTask();
                if (espere.Cancel.IsCancellationRequested)
                    frmEspera?.Close();
            }
        }
Example #5
0
        private void btnRelatorioCompra_Click(object sender, EventArgs e)
        {
            try
            {
                espere = new Espere();
                espere.Start(MostrarMensagemEspera);
                _DbContext banco = new _DbContext();
                string fileName = "rpvCompras.rdlc";
                RelatorioCompraRepositorio relatorio = new RelatorioCompraRepositorio();
                var table = relatorio.GerarRelatorioDeVendas();
                MyReport report = new MyReport(table, fileName.GetFullPath(), "Compras", ProcessingMode.Local);
                report.GerarRelatoriosComParametrosDefinidosNaQueryPDF();
                espere.CancelarTask();
                if (espere.Cancel.IsCancellationRequested)
                    frmEspera?.Close();

            }
            catch (CustomException error)
            {
                DialogMessage.MessageFullComButtonOkIconeDeInformacao(message: error.Message, title: "Aviso");
            }
            catch (Exception error)
            {
                SaveErroInTxt.RecordInTxt(error, this.GetType().Name);
                DialogMessage.MessageFullComButtonOkIconeDeInformacao(message: error.Message, title: "Aviso");
            }
            finally
            {
                espere.CancelarTask();
                if (espere.Cancel.IsCancellationRequested)
                    frmEspera?.Close();
            }
        }
Example #6
0
 private void ConcluirVendaComCreditar()
 {
     try
     {
         if (cbbTipoDePagamento.Text == EnumTipoPagamento.Creditar.ToString())
         {
             if (VendaComCreditar() == false)
             {
                 _vendaRepositorio.ExcluirUltimaVenda();
                 DialogMessage.MessageFullComButtonOkIconeDeInformacao("Para concluir a venda no modo CREDITAR é necessário selecionar o cliente.", "Aviso");
             }
             else
             {
                 if (DialogMessage.MessageFullQuestion("Deseja imprimir o comprovante de compra?", "Aviso") == DialogResult.Yes)
                 {
                     espere = new Espere();
                     espere.Start(MostrarMensagem);
                     string fileName = "rpvFiado.rdlc";
                     RelatorioFiadoViewModel relatorioFiado = null;
                     List<RelatorioFiadoViewModel> relatorioFiadoList = new List<RelatorioFiadoViewModel>();
                     foreach (ListViewItem item in ltvProdutos.Items)
                     {
                         relatorioFiado = new RelatorioFiadoViewModel();
                         relatorioFiado.Produto = item.SubItems[0].Text;
                         relatorioFiado.Quantidade = item.SubItems[2].Text;
                         relatorioFiado.Valor = Convert.ToDecimal(item.SubItems[3].Text);
                         relatorioFiadoList.Add(relatorioFiado);
                     }
                     var table = new RelatorioFiadoRepositorio().GerarRelatorioDeFiado(relatorioFiadoList);
                     MyReport report = new MyReport(table, fileName.GetFullPath(), "Fiado", Microsoft.Reporting.WebForms.ProcessingMode.Local);
                     report.GerarRelatoriosComParametrosEQueryDefinidosNaQueryPDF(new List<ReportParameter>
                     {
                          new ReportParameter("NomeCliente",new ClienteRepositorio().GetClientePorID(Cliente.ClienteIDStatic).Nome),
                          new ReportParameter("NomeVendedor",Usuarios.NomeCompletoStatic)
                     });
                 }
                 DarBaixaNoEstoque();
                 PosSalvamentoPadrao();
                 FocarNoTxt(txt: txtCodigoDoProduto);
             }
         }
     }
     catch (CustomException erro)
     {
         DialogMessage.MessageFullComButtonOkIconeDeInformacao(erro.Message, "Aviso");
     }
     catch (Exception erro)
     {
         SaveErroInTxt.RecordInTxt(erro, this.GetType().Name);
         DialogMessage.MessageComButtonOkIconeErro(erro.Message, "Erro");
     }
     finally
     {
         if (espere != null)
         {
             espere.CancelarTask();
             if (espere.Cancel.IsCancellationRequested)
             {
                 mensagem?.Close();
             }
         }
     }
 }