Example #1
0
        public ReportInfo GetReportData(BillingExportFilter filter)
        {
            IDataReader dataReader = null;

            try
            {
                ReportInfo repInfo = new ReportInfo();

                List <string>  seriesNameList = new List <string>();
                List <string>  xValueList     = new List <string>();
                List <decimal> yValueList     = new List <decimal>();

                //Get all the xaxis date values for the selected date type
                DateTime fromDateValue;
                DateTime.TryParseExact(filter.FromDate.ToString().Trim(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDateValue);
                DateTime toDateValue;
                DateTime.TryParseExact(filter.ToDate.ToString().Trim(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out toDateValue);

                List <string> dateList = new List <string>();
                while (fromDateValue <= toDateValue)
                {
                    string formattedDate = fromDateValue.ToString("yyyyMMdd", CultureInfo.InvariantCulture);
                    dateList.Add(formattedDate);
                    string formattedDateString = fromDateValue.ToString("yyyy-MMM-dd", CultureInfo.InvariantCulture);
                    xValueList.Add(formattedDateString);
                    fromDateValue = fromDateValue.AddDays(1);
                }

                Database db = DatabaseFactory.CreateDatabase("DbConnection");

                if (filter.IsDrillDown)
                {
                    dataReader = BillingDAL.GetBillingItemPrice(db, filter.FromDate, filter.ToDate);
                }
                else
                {
                    dataReader = BillingDAL.GetTotalBillingPrice(db, filter.FromDate, filter.ToDate);
                }

                List <ReportData> reportDataList = new List <ReportData>();
                ReportData        reportData     = null;

                while (dataReader.Read())
                {
                    reportData            = new ReportData();
                    reportData.XValue     = Common.GetInt32(dataReader, "FXVALUE").ToString();
                    reportData.YValue     = Common.GetDecimal(dataReader, "FYVALUE");
                    reportData.SeriesName = Common.GetString(dataReader, "FSERIESNAME");
                    reportDataList.Add(reportData);

                    if (!seriesNameList.Contains(reportData.SeriesName))
                    {
                        seriesNameList.Add(reportData.SeriesName);
                    }
                }
                dataReader.Close();

                foreach (string seriesName in seriesNameList)
                {
                    yValueList = new List <decimal>();
                    foreach (string dateStr in dateList)
                    {
                        ReportData selReportData = reportDataList.FirstOrDefault(r => r.XValue == dateStr && r.SeriesName == seriesName);
                        if (selReportData != null)
                        {
                            yValueList.Add(selReportData.YValue);
                        }
                        else
                        {
                            yValueList.Add(0);
                        }
                    }
                    repInfo.YValues.Add(yValueList);
                }

                repInfo.XValues     = xValueList;
                repInfo.SeriesNames = seriesNameList;

                return(repInfo);
            }
            catch (Exception ex)
            {
                Common.LogException(ex);
                throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError);
            }
            finally
            {
                if (dataReader != null && !dataReader.IsClosed)
                {
                    dataReader.Close();
                }
            }
        }