private void TaskForceAdminLevelStep_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                Localizer.TranslateControl(this);

                DemoRepository demo = new DemoRepository();
                var country = demo.GetCountry();
                var adminLevels = demo.GetAdminLevelByLevel(types[typeIndex].LevelNumber);

                foreach (var u in adminLevels)
                {
                    List<TaskForceAdminUnit> available = new List<TaskForceAdminUnit>();
                    if (u.ParentId == country.Id)
                        available = units.Where(x => x.LevelIndex == 0).ToList();
                    else
                        available = units.Where(x => x.LevelIndex == typeIndex && x.Parent.NadaId == u.ParentId).ToList();

                    // has value
                    if (!string.IsNullOrEmpty(u.TaskForceName))
                    {
                        existingIds.Add(u.TaskForceId);
                        var existing = available.FirstOrDefault(f => f.Id == u.TaskForceId);
                        existing.NadaId = u.Id;
                        continue;
                    }

                    var match = available.FirstOrDefault(a => a.Name.ToLower() == u.Name.ToLower());
                    if (match != null)
                    {
                        SaveMatch(match, u, demo);
                        continue;
                    }
                    else
                    {
                        var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                        var chooser = new AdminUnitMatcher(u, available);
                        chooser.Margin = new Padding(0, 5, 10, 5);
                        tblNewUnits.Controls.Add(chooser, 0, index);
                        matchers.Add(chooser);
                    }
                }

                if (matchers.Count == 0)
                    DoNextStep();
            }
        }
        public override ReportResult Run(SavedReport report)
        {
            EliminationReportOptions standardOpts = (EliminationReportOptions)report.StandardReportOptions;
            ReportOptions options = report.ReportOptions;
            DistributionReportGenerator gen = new DistributionReportGenerator();
            DiseaseRepository repo = new DiseaseRepository();
            DemoRepository demo = new DemoRepository();
            foreach (var disease in standardOpts.Diseases)
            {
                DiseaseDistroPc dd = repo.Create((DiseaseType)disease.Id);

                switch (disease.Id)
                {
                    case (int)DiseaseType.Lf:
                        AddIndicators(disease.Id, "DDLFDiseaseDistributionPcInterventions", dd, options);
                        break;
                    case (int)DiseaseType.Trachoma:
                        AddIndicators(disease.Id, "DDTraDiseaseDistributionPcInterventions", dd, options);
                        break;
                    case (int)DiseaseType.Oncho:
                        AddIndicators(disease.Id, "DDOnchoDiseaseDistributionPcInterventio", dd, options);
                        break;
                    case (int)DiseaseType.STH:
                        AddIndicators(disease.Id, "DDSTHDiseaseDistributionPcInterventions", dd, options);
                        break;
                    case (int)DiseaseType.Schisto:
                        AddIndicators(disease.Id, "DDSchistoDiseaseDistributionPcIntervent", dd, options);
                        break;
                    default:
                        break;
                }
            }

            // need to add the proper sumation stuff
            report.ReportOptions.IsByLevelAggregation = true;
            report.ReportOptions.IsCountryAggregation = false;
            report.ReportOptions.IsNoAggregation = false;
            report.ReportOptions.SelectedAdminLevels = demo.GetAdminLevelByLevel(standardOpts.DistrictType.LevelNumber).Where(a => a.LevelNumber == standardOpts.DistrictType.LevelNumber).ToList();

            // run report
            ReportResult result = gen.Run(report);

            Dictionary<string, DataRow> years = new Dictionary<string,DataRow>();
            DataTable summed = new DataTable();
            summed.Columns.Add(new DataColumn(TranslationLookup.GetValue("Location")));
            summed.Columns.Add(new DataColumn(TranslationLookup.GetValue("Year"), typeof(string)));
            summed.Columns.Add(new DataColumn(string.Format(TranslationLookup.GetValue("EliminationEndemicDistricts"), standardOpts.DistrictType.DisplayName), typeof(int)));
            summed.Columns.Add(new DataColumn(string.Format(TranslationLookup.GetValue("EliminationStoppedDistricts"), standardOpts.DistrictType.DisplayName), typeof(int)));
            
            foreach (DataRow row in result.DataTableResults.Rows)
            {
                string endemicty = "";
                int totalEndemic = 0, totalStopped = 0;
                if (result.DataTableResults.Columns.Contains(TranslationLookup.GetValue("DDLFDiseaseDistributionPcInterventions") + " - " + TranslationLookup.GetValue("LF")))
                {
                    endemicty = row[TranslationLookup.GetValue("DDLFDiseaseDistributionPcInterventions") + " - " + TranslationLookup.GetValue("LF")].ToString();
                    if (endemicty == TranslationLookup.GetValue("LfEnd1") || endemicty == TranslationLookup.GetValue("LfEndPending"))
                        totalEndemic++;
                    else if (endemicty == TranslationLookup.GetValue("LfEnd100"))
                        totalStopped++;
                }
                if (result.DataTableResults.Columns.Contains(TranslationLookup.GetValue("DDOnchoDiseaseDistributionPcInterventio") + " - " + TranslationLookup.GetValue("Oncho")))
                {
                    endemicty = row[TranslationLookup.GetValue("DDOnchoDiseaseDistributionPcInterventio") + " - " + TranslationLookup.GetValue("Oncho")].ToString();
                    if (endemicty == TranslationLookup.GetValue("Oncho1") || endemicty == TranslationLookup.GetValue("OnchoPending"))
                        totalEndemic++;
                    else if (endemicty == TranslationLookup.GetValue("Oncho100"))
                        totalStopped++;
                }
                if (result.DataTableResults.Columns.Contains(TranslationLookup.GetValue("DDSchistoDiseaseDistributionPcIntervent") + " - " + TranslationLookup.GetValue("Schisto")))
                {
                    endemicty = row[TranslationLookup.GetValue("DDSchistoDiseaseDistributionPcIntervent") + " - " + TranslationLookup.GetValue("Schisto")].ToString();
                    if (endemicty == TranslationLookup.GetValue("Sch1") || endemicty == TranslationLookup.GetValue("Sch2") || endemicty == TranslationLookup.GetValue("Sch2a") || endemicty == TranslationLookup.GetValue("Sch3") || endemicty == TranslationLookup.GetValue("Sch3a")
                        || endemicty == TranslationLookup.GetValue("Sch3b") || endemicty == TranslationLookup.GetValue("Sch20") || endemicty == TranslationLookup.GetValue("Sch30") || endemicty == TranslationLookup.GetValue("Sch40")
                        || endemicty == TranslationLookup.GetValue("SchPending"))
                        totalEndemic++;
                    else if (endemicty == TranslationLookup.GetValue("Sch100"))
                        totalStopped++;
                }

                if (result.DataTableResults.Columns.Contains(TranslationLookup.GetValue("DDSTHDiseaseDistributionPcInterventions") + " - " + TranslationLookup.GetValue("STH")))
                {
                    endemicty = row[TranslationLookup.GetValue("DDSTHDiseaseDistributionPcInterventions") + " - " + TranslationLookup.GetValue("STH")].ToString();
                    if (endemicty == TranslationLookup.GetValue("Sth2") || endemicty == TranslationLookup.GetValue("Sth3") || endemicty == TranslationLookup.GetValue("Sth10") || endemicty == TranslationLookup.GetValue("Sth20")
                        || endemicty == TranslationLookup.GetValue("Sth30") || endemicty == TranslationLookup.GetValue("Sth40") || endemicty == TranslationLookup.GetValue("SthPending"))
                        totalEndemic++;
                    else if (endemicty == TranslationLookup.GetValue("Sth100"))
                        totalStopped++;
                }
                if (result.DataTableResults.Columns.Contains(TranslationLookup.GetValue("DDTraDiseaseDistributionPcInterventions") + " - " + TranslationLookup.GetValue("Trachoma")))
                {
                    endemicty = row[TranslationLookup.GetValue("DDTraDiseaseDistributionPcInterventions") + " - " + TranslationLookup.GetValue("Trachoma")].ToString();
                    if (endemicty == TranslationLookup.GetValue("Tra1") || endemicty == TranslationLookup.GetValue("Tra4") || endemicty == TranslationLookup.GetValue("Tra5")
                        || endemicty == TranslationLookup.GetValue("TraPending"))
                        totalEndemic++;
                    else if (endemicty == TranslationLookup.GetValue("Tra100"))
                        totalStopped++;
                }

                if (!years.ContainsKey(row[TranslationLookup.GetValue("Year")].ToString()))
                {
                    DataRow dr = summed.NewRow();
                    dr[TranslationLookup.GetValue("Year")] = row[TranslationLookup.GetValue("Year")];
                    dr[string.Format(TranslationLookup.GetValue("EliminationEndemicDistricts"), standardOpts.DistrictType.DisplayName)] = totalEndemic;
                    dr[string.Format(TranslationLookup.GetValue("EliminationStoppedDistricts"), standardOpts.DistrictType.DisplayName)] = totalStopped;
                    years.Add(row[TranslationLookup.GetValue("Year")].ToString(), dr);
                    summed.Rows.Add(dr);
                }
                else
                {
                    years[row[TranslationLookup.GetValue("Year")].ToString()][string.Format(TranslationLookup.GetValue("EliminationEndemicDistricts"), standardOpts.DistrictType.DisplayName)] =
                        totalEndemic + (int)years[row[TranslationLookup.GetValue("Year")].ToString()][string.Format(TranslationLookup.GetValue("EliminationEndemicDistricts"), standardOpts.DistrictType.DisplayName)];
                    years[row[TranslationLookup.GetValue("Year")].ToString()][string.Format(TranslationLookup.GetValue("EliminationStoppedDistricts"), standardOpts.DistrictType.DisplayName)] =
                        totalStopped + (int)years[row[TranslationLookup.GetValue("Year")].ToString()][string.Format(TranslationLookup.GetValue("EliminationStoppedDistricts"), standardOpts.DistrictType.DisplayName)];
                }
            }

            result.DataTableResults = summed;
            result.ChartData = summed.Copy();
            report.ReportOptions.IsByLevelAggregation = false;
            report.ReportOptions.IsCountryAggregation = true; // to show only year

            return result;
        }
        private DataTable CreateInsertDataTable(AdminLevelType type)
        {
            DataTable data = new System.Data.DataTable();
            data.Columns.Add(new System.Data.DataColumn("* " + TranslationLookup.GetValue("Location") + "#"));
            data.Columns.Add(new System.Data.DataColumn("* " + TranslationLookup.GetValue("YearCensus")));
            data.Columns.Add(new System.Data.DataColumn("* " + TranslationLookup.GetValue("GrowthRate")));
            data.Columns.Add(new System.Data.DataColumn("* " + TranslationLookup.GetValue("TotalPopulation")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("Pop0Month")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("PopPsac")));
            data.Columns.Add(new System.Data.DataColumn("* " + TranslationLookup.GetValue("PopSac")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("Pop5yo")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("PopAdult")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("PopFemale")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("PopMale")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("PercentRural")));
            data.Columns.Add(new System.Data.DataColumn(TranslationLookup.GetValue("Notes")));

            DemoRepository drepo = new DemoRepository();
            var allUnits = drepo.GetAdminLevelByLevel(type.LevelNumber);
            foreach (AdminLevel l in allUnits)
            {
                DataRow row = data.NewRow();
                row["* " + TranslationLookup.GetValue("Location") + "#"] = l.Id; 

                List<AdminLevel> parents = demo.GetAdminLevelParentNames(l.Id);
                for (int i = 0; i < parents.Count; i++)
                {
                    if (!data.Columns.Contains("* " + parents[i].LevelName))
                    {
                        DataColumn dc = new DataColumn("* " + parents[i].LevelName);
                        data.Columns.Add(dc);
                        dc.SetOrdinal(i + 1);
                    }
                    row["* " + parents[i].LevelName] = parents[i].Name;
                }
                
                data.Rows.Add(row);
            }
            return data;
        }