public async Task <IList <LoansReport> > GetDataFromSql()
        {
            try
            {
                var connection = new SqliteConnection(_sourceConfig.Value.DatabaseConnection);
                connection.Open();
                string query   = "Select Amount, Count(Amount) as total from loans where amount is not null group by Amount order by Amount;";
                var    command = new SqliteCommand(query, connection);
                var    reader  = await command.ExecuteReaderAsync();

                while (reader.Read())
                {
                    var item = new LoansReport()
                    {
                        Amount       = reader["amount"].ToString() != "" ? $"£{reader["amount"]}" : null,
                        TotalRecords = int.Parse(reader["total"].ToString())
                    };
                    reportingList.Add(item);
                }
                connection.Close();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.Message, exception);
                throw new Exception("Something went wrong. Please check logs.");
            }

            return(reportingList);
        }
Ejemplo n.º 2
0
        private void FillReport(bool isInitial = false, bool throwException = true)
        {
            string rep_params        = vals.Text;
            ReportGenericRequest req = new ReportGenericRequest();

            req.paramString = rep_params;

            ListResponse <Model.Reports.RT401> resp = _reportsService.ChildGetAll <Model.Reports.RT401>(req);

            if (!resp.Success)
            {
                Common.ReportErrorMessage(resp, GetGlobalResourceObject("Errors", "Error_1").ToString(), GetGlobalResourceObject("Errors", "ErrorLogId").ToString());
            }

            resp.Items.ForEach(x => x.StatusString = GetLocalResourceObject("Status" + x.status.ToString()).ToString());
            Dictionary <string, string> parameters = Web.UI.Forms.Common.FetchReportParameters(texts.Text);
            LoansReport h = new LoansReport(parameters);

            h.RightToLeft       = _systemService.SessionHelper.CheckIfArabicSession() ? DevExpress.XtraReports.UI.RightToLeft.Yes : DevExpress.XtraReports.UI.RightToLeft.No;
            h.RightToLeftLayout = _systemService.SessionHelper.CheckIfArabicSession() ? DevExpress.XtraReports.UI.RightToLeftLayout.Yes : DevExpress.XtraReports.UI.RightToLeftLayout.No;
            h.DataSource        = resp.Items;

            //string from = DateTime.Parse(req.Parameters["_fromDate"]).ToString(_systemService.SessionHelper.GetDateformat());
            //string to = DateTime.Parse(req.Parameters["_toDate"]).ToString(_systemService.SessionHelper.GetDateformat());
            string user = _systemService.SessionHelper.GetCurrentUser();


            h.Parameters["User"].Value = user;
            //    h.Parameters["Filters"].Value = texts.Text;
            h.CreateDocument();


            ASPxWebDocumentViewer1.DataBind();
            ASPxWebDocumentViewer1.OpenReport(h);
        }
        public async Task <IList <LoansReport> > GetDataFromFile()
        {
            string[] records = await File.ReadAllLinesAsync($"{Environment.CurrentDirectory}{_sourceConfig.Value.FileLocation}");

            foreach (string record in records)
            {
                var loanId      = record.Substring(0, 19).Trim();
                var customerId  = record.Substring(20, 29).Trim();
                var loanAmount  = record.Substring(50, 10).Trim().TrimStart('0');
                var createdDate = record.Substring(60, 8).Trim();
                var item        = new LoansReport()
                {
                    Amount       = loanAmount != "" ? $"£{loanAmount}" : null,
                    TotalRecords = 0
                };
                reportingList.Add(item);
            }
            var results = reportingList.GroupBy(loan => loan.Amount)
                          .Select(loan => new LoansReport()
            {
                Amount       = loan.Key,
                TotalRecords = loan.Count()
            })
                          .OrderBy(x => x.Amount);

            return(results.ToList());
        }