示例#1
0
        public List <VotesPerRegionModelView> tableRegion()
        {
            SMSServersEntities             db = new SMSServersEntities();
            List <VotesPerRegionModelView> voteCollationModelView = new List <VotesPerRegionModelView>();


            List <spVotePerRegion_Result> lstCol = new List <spVotePerRegion_Result>();

            foreach (iCelerium.Models.Region Reg in db.Regions.ToList())
            {
                lstCol = db.spVotePerRegion().Where(c => c.RegionName.Equals(Reg.RegionName)).ToList();
                if (lstCol.Count() > 0)
                {
                    VotesPerRegionModelView vot = new VotesPerRegionModelView();
                    foreach (spVotePerRegion_Result col in lstCol)
                    {
                        switch (col.PARTY.Trim())
                        {
                        case "NDC":
                            vot.NDC += col.TOTAL;
                            break;

                        case "NPP":
                            vot.NPP += col.TOTAL;
                            break;

                        case "CPP":
                            vot.CPP += col.TOTAL;
                            break;

                        case "PPP":
                            vot.PPP += col.TOTAL;
                            break;

                        case "OTH":
                            vot.OTHERS += col.TOTAL;
                            break;

                        case "IRB":
                            vot.REJECTED += col.TOTAL;
                            break;
                        }
                        vot.Region = col.RegionName;

                        vot.NoConstituency = db.spNumberberOfConstituency().Where(c => c.RegionName.Equals(col.RegionName)).ToList().GroupBy(o => o.ConstituencyName).Select(group => group.First()).Count();
                    }

                    vot.TOTAL = vot.NDC + vot.NPP + vot.OTHERS + vot.PPP + vot.REJECTED + vot.CPP;
                    voteCollationModelView.Add(vot);
                }
            }



            return(voteCollationModelView.OrderByDescending(c => c.TOTAL).ToList());
        }
示例#2
0
        public Highcharts TransDailyBasicBar()
        {
            SMSServersEntities db        = new SMSServersEntities();
            List <string>      lstRegion = new List <string>();

            lstRegion = db.spVoteAvailableRegion().ToList();
            List <Series> lstSeries = new List <Series>();

            foreach (var party in db.Parties.ToList())
            {
                List <int> lstNumbers = new List <int>();

                foreach (var reg in lstRegion)
                {
                    foreach (spVotePerRegion_Result vot in db.spVotePerRegion().OrderBy(c => c.PARTY).Where(c => c.RegionName.Equals(reg) && c.PARTY.Equals((party.Abrev.Trim()))))
                    {
                        lstNumbers.Add(vot.TOTAL);
                    }
                }
                object[] ltl = new object[lstNumbers.Count()];
                for (int i = 0; i < lstNumbers.Count(); i++)
                {
                    ltl[i] = lstNumbers.ToArray()[i];
                }
                Series series = new Series {
                    Name = party.Abrev.Trim(), Data = new Data(ltl)
                };
                lstSeries.Add(series);
            }



            Highcharts chart = new Highcharts("chart1")
                               .InitChart(new Chart {
                DefaultSeriesType = ChartTypes.Bar
            })
                               .SetTitle(new Title {
                Text = "Historic Votes Collation by Region"
            })
                               .SetSubtitle(new Subtitle {
                Text = "Available regions only"
            })
                               .SetXAxis(new XAxis
            {
                Categories = lstRegion.ToArray(),
                Title      = new XAxisTitle {
                    Text = string.Empty
                }
            })
                               .SetYAxis(new YAxis
            {
                Min   = 0,
                Title = new YAxisTitle
                {
                    Text  = "Votes (Thousands)",
                    Align = AxisTitleAligns.High
                }
            })
                               .SetTooltip(new Tooltip {
                Formatter = "function() { return ''+ this.series.name +': '+ this.y ; }"
            })
                               .SetPlotOptions(new PlotOptions
            {
                Bar = new PlotOptionsBar
                {
                    DataLabels = new PlotOptionsBarDataLabels {
                        Enabled = true
                    }
                }
            })
                               .SetLegend(new Legend
            {
                Layout          = Layouts.Vertical,
                Align           = HorizontalAligns.Right,
                VerticalAlign   = VerticalAligns.Top,
                X               = -100,
                Y               = 100,
                Floating        = true,
                BorderWidth     = 1,
                BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFFFFF")),
                Shadow          = true
            })
                               .SetCredits(new Credits {
                Enabled = false
            })
                               .SetSeries(lstSeries.ToArray());

            return(chart);

            return(chart);
        }