Exemple #1
0
    /// <summary>
    /// Create trend sheet
    /// </summary>
    private void createTrendSheet(TrendTransferContent type, int facilityid, string pollutantCode)
    {
        this.ucStackColumnTime.Visible    = false;
        this.ucStackColumnCompare.Visible = false;
        this.ucYearCompareSeries.Visible  = false;
        this.compareTable.Visible         = false;

        // Get time series data, used by all sub sheets
        List <TimeSeriesClasses.PollutantTransfers> data = getTimeSeriesData(facilityid, pollutantCode);

        // Time series sheet
        if (type == TrendTransferContent.TimeSeries)
        {
            ViewState[CONTENT_TYPE] = TrendTransferContent.TimeSeries;
            if (data != null && data.Count > 0)
            {
                this.ucStackColumnTime.Visible = true;

                Color[]           colors      = new Color[] { Global.ColorWasteWater };
                ChartHatchStyle[] hatchStyles = new ChartHatchStyle[] { ChartHatchStyle.None };

                this.ucStackColumnTime.Initialize(colors.Length, StackColumnType.TimeSeries, PollutantTransferTrend.CODE_KG, colors, hatchStyles, null);
                //this.ucStackColumnTime.Initialize(colors.Length, StackColumnType.TimeSeries, PollutantTransferTrend.CODE_TNE, colors, null);

                List <TimeSeriesUtils.BarData> bars = new List <TimeSeriesUtils.BarData>();

                foreach (var v in data)
                {
                    string[] tip = new string[] { String.Format("{0}: {1}", Resources.GetGlobal("Common", "Year"), v.Year),
                                                  String.Format("{0}: {1}", Resources.GetGlobal("Common", "Quantity"), QuantityFormat.Format(v.Quantity, v.QuantityUnit)) };

                    TimeSeriesUtils.BarData cd = new TimeSeriesUtils.BarData
                    {
                        Year    = v.Year,
                        Values  = new double?[] { v.Quantity },
                        ToolTip = ToolTipFormatter.FormatLines(tip)
                    };
                    bars.Add(cd);
                }
                this.ucStackColumnTime.Add(TimeSeriesUtils.InsertMissingYears(bars, showEPER));
            }
        }

        // comparison
        if (type == TrendTransferContent.Comparison)
        {
            ViewState[CONTENT_TYPE] = TrendTransferContent.Comparison;
            if (data != null && data.Count > 0)
            {
                this.compareTable.Visible = true;

                // Create chart
                this.ucStackColumnCompare.Visible = true;

                Color[]           colors      = new Color[] { Global.ColorWasteWater };
                ChartHatchStyle[] hatchStyles = new ChartHatchStyle[] { ChartHatchStyle.None };
                this.ucStackColumnCompare.Initialize(colors.Length, StackColumnType.Comparison, PollutantTransferTrend.CODE_KG, colors, hatchStyles, null);
                //this.ucStackColumnCompare.Initialize(colors.Length, StackColumnType.Comparison, PollutantTransferTrend.CODE_TNE, colors, null);

                // init year combo boxes
                this.ucYearCompareSeries.Visible = true;
                int year1 = this.ucYearCompareSeries.Year1;
                int year2 = this.ucYearCompareSeries.Year2;
                // reset
                resetLabels();

                TimeSeriesClasses.PollutantTransfers data1 = data.Where(d => d.Year == year1).DefaultIfEmpty(new TimeSeriesClasses.PollutantTransfers(year1)).Single();
                TimeSeriesClasses.PollutantTransfers data2 = data.Where(d => d.Year == year2).DefaultIfEmpty(new TimeSeriesClasses.PollutantTransfers(year2)).Single();

                bool dataFound = data1 != null || data2 != null;


                if (dataFound)
                {
                    TimeSeriesUtils.BarData dataFrom = new TimeSeriesUtils.BarData {
                        Year = year1
                    };
                    TimeSeriesUtils.BarData dataTo = new TimeSeriesUtils.BarData {
                        Year = year2
                    };

                    if (data1 != null)
                    {
                        dataFrom.Values = new double?[] { data1.Quantity };
                    }

                    if (data2 != null)
                    {
                        dataTo.Values = new double?[] { data2.Quantity };
                    }

                    // from and to bar
                    this.ucStackColumnCompare.Add(new List <TimeSeriesUtils.BarData>()
                    {
                        dataFrom, dataTo
                    });
                    updateTableLabels(data1, data2);
                }

                // display that no data found for the selected years
                this.lbNoDataForSelectedYears.Visible = !dataFound;
            }
        }
    }
    /// <summary>
    /// Create trend sheet
    /// </summary>
    private void createTrendSheet(TrendReleaseContent type, int facilityid, MediumFilter.Medium medium)
    {
        this.ucStackColumnTime.Visible    = false;
        this.ucStackColumnCompare.Visible = false;
        this.ucYearCompareSeries.Visible  = false;
        this.compareTable.Visible         = false;

        // Get time series data, used by all sub sheets
        List <TimeSeriesClasses.PollutantReleases> data = getTimeSeriesData(facilityid, medium);

        // Time series sheet
        if (type == TrendReleaseContent.TimeSeries)
        {
            ViewState[CONTENT_TYPE] = TrendReleaseContent.TimeSeries;
            if (data != null && data.Count > 0)
            {
                this.ucStackColumnTime.Visible = true;

                // initialize chart

                Color[]           colors      = getColors(medium);
                string[]          labelTexts  = new string[] { Resources.GetGlobal("Common", "Accidental"), Resources.GetGlobal("Common", "Controlled") };
                ChartHatchStyle[] hatchStyles = new ChartHatchStyle[] { ChartHatchStyle.None, ChartHatchStyle.None };
                this.ucStackColumnTime.Initialize(colors.Length, StackColumnType.TimeSeries, PollutantReleaseTrend.CODE_KG, colors, hatchStyles, labelTexts);

                List <TimeSeriesUtils.BarData> bars = new List <TimeSeriesUtils.BarData>();

                foreach (var v in data)
                {
                    string[] tip = new string[] { String.Format("{0}: {1}", Resources.GetGlobal("Common", "Year"), v.Year),
                                                  String.Format("{0}: {1}", Resources.GetGlobal("Pollutant", "ReleasesTotal"), QuantityFormat.Format(v.Quantity, v.QuantityUnit)),
                                                  String.Format("{0}: {1}", Resources.GetGlobal("Pollutant", "ReleasesAccidentalReleases"), QuantityFormat.Format(v.QuantityAccidental, v.QuantityAccidentalUnit)),
                                                  (v.AccidentalPercent > 0.0) ? String.Format("{0}: {1:F5}%", Resources.GetGlobal("Pollutant", "ReleasesAccidentalPercentValue"), v.AccidentalPercent) : String.Format("{0}: 0%", Resources.GetGlobal("Pollutant", "ReleasesAccidentalPercentValue")) };


                    TimeSeriesUtils.BarData cd = new TimeSeriesUtils.BarData
                    {
                        Year    = v.Year,
                        Values  = new double?[] { TimeSeriesUtils.RangeValue(v.QuantityAccidental), TimeSeriesUtils.RangeValue(v.Quantity) - TimeSeriesUtils.RangeValue(v.QuantityAccidental) },
                        ToolTip = ToolTipFormatter.FormatLines(tip)
                    };
                    bars.Add(cd);
                }

                if ((medium == MediumFilter.Medium.Air) || (medium == MediumFilter.Medium.Water))
                {
                    this.ucStackColumnTime.Add(TimeSeriesUtils.InsertMissingYears(bars, showEPER));
                }
                if (medium == MediumFilter.Medium.Soil)
                {
                    this.ucStackColumnTime.Add(TimeSeriesUtils.InsertMissingYearsTimeSeries(bars, showEPER));
                }
            }
        }

        // comparison
        if (type == TrendReleaseContent.Comparison)
        {
            ViewState[CONTENT_TYPE] = TrendReleaseContent.Comparison;

            if (data != null && data.Count > 0)
            {
                this.compareTable.Visible = true;

                // Create chart
                this.ucStackColumnCompare.Visible = true;

                Color[]           colors      = getColors(medium);
                ChartHatchStyle[] hatchStyles = new ChartHatchStyle[] { ChartHatchStyle.None, ChartHatchStyle.None };
                string[]          labelTexts  = new string[] { Resources.GetGlobal("Common", "Accidental"), Resources.GetGlobal("Common", "Controlled") };

                this.ucStackColumnCompare.Initialize(colors.Length, StackColumnType.Comparison, PollutantReleaseTrend.CODE_KG, colors, hatchStyles, labelTexts);
                //this.ucStackColumnCompare.Initialize(colors.Length, StackColumnType.Comparison, PollutantReleaseTrend.CODE_TNE, colors, labelTexts);

                // init year combo boxes
                this.ucYearCompareSeries.Visible = true;
                int year1 = this.ucYearCompareSeries.Year1;
                int year2 = this.ucYearCompareSeries.Year2;
                // reset
                resetLabels();

                TimeSeriesClasses.PollutantReleases data1 = data.Where(d => d.Year == year1).DefaultIfEmpty(new TimeSeriesClasses.PollutantReleases(year1)).Single();
                TimeSeriesClasses.PollutantReleases data2 = data.Where(d => d.Year == year2).DefaultIfEmpty(new TimeSeriesClasses.PollutantReleases(year2)).Single();

                bool dataFound = data1 != null || data2 != null;


                if (dataFound)
                {
                    TimeSeriesUtils.BarData dataFrom = new TimeSeriesUtils.BarData {
                        Year = year1
                    };
                    TimeSeriesUtils.BarData dataTo = new TimeSeriesUtils.BarData {
                        Year = year2
                    };

                    if (data1 != null)
                    {
                        dataFrom.Values = new double?[] { data1.QuantityAccidental, data1.Quantity - data1.QuantityAccidental };
                    }

                    if (data2 != null)
                    {
                        dataTo.Values = new double?[] { data2.QuantityAccidental, data2.Quantity - data2.QuantityAccidental };
                    }

                    // from and to bar
                    this.ucStackColumnCompare.Add(new List <TimeSeriesUtils.BarData>()
                    {
                        dataFrom, dataTo
                    });
                    updateTableLabels(data1, data2);
                }

                // display that no data found for the selected years
                this.lbNoDataForSelectedYears.Visible = !dataFound;
            }
        }
    }