public DashboardTabs(AdminLevel adminLevel, AdminLevelType t)
     : base()
 {
     this.adminlevelType = t;
     this.adminLevel = adminLevel;
     InitializeComponent();
 }
 public StepAdminLevelImport(AdminLevelType type, IWizardStep p, DateTime d, bool isImport)
     : base()
 {
     isSingleImport = isImport;
     demoDate = d;
     Init(type, p, true, null);
 }
 private void fieldLink1_OnClick()
 {
     int max = types.Max(t => t.LevelNumber);
     AdminLevelType type = new AdminLevelType { LevelNumber = max + 1 };
     AdminLevelTypeAdd add = new AdminLevelTypeAdd(type);
     // Tell the control if is being launched from StartUp
     add.IsStartUp = IsStartUp;
     add.OnSave += () => { RefreshList(); };
     add.ShowDialog();
 }
 private void Init(AdminLevelType type, IWizardStep step, bool demoOnly, int? cid)
 {
     countryDemoId = cid;
     isDemoOnly = demoOnly;
     locationType = type;
     prev = step;
     SettingsRepository settings = new SettingsRepository();
     DemoRepository demo = new DemoRepository();
     if (!isDemoOnly)
         demoDate = demo.GetCountryDemoRecent().DateDemographyData;
     if (!isSingleImport)
     {
         nextType = settings.GetNextLevel(locationType.LevelNumber);
         stepTitle = isDemoOnly ? Translations.UpdateDemography + " - " + locationType.DisplayName : Translations.ImportAdminLevels + locationType.DisplayName;
         importer = new AdminLevelDemoImporter(locationType, countryDemoId);
     }
     else
         stepTitle = Translations.Demography + " - " + locationType.DisplayName;
     updater = new AdminLevelDemoUpdater(locationType, countryDemoId);
     InitializeComponent();
 }
        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;
        }
Beispiel #6
0
        public void DoLoad()
        {
            if (model.Id > 0)
            {
                treeAvailable.Enabled = false;
                lblParent.Enabled = false;
            }

            if (model.LatWho.HasValue)
                model.BindingLat = model.LatWho.Value.ToString();
            if (model.LngWho.HasValue)
                model.BindingLng = model.LngWho.Value.ToString();

            Localizer.TranslateControl(this);
            bindingSource1.DataSource = model;
            lblParent.SetMaxWidth(500);

            var levels = settings.GetAllAdminLevelsWithCountry().OrderByDescending(l => l.LevelNumber).ToList();
            int levelTypeId = 0;
            if (childLevel == 0)
                levelTypeId = levels.ToArray()[1].Id;
            else
            {
                var child = levels.FirstOrDefault(l => l.LevelNumber == childLevel);
                parentType = levels.ToArray()[levels.IndexOf(child) + 1];
                levelTypeId = parentType.Id;
            }

            var t = repo.GetAdminLevelTree(levelTypeId, 0, true);
            treeAvailable.CanExpandGetter = m => ((AdminLevel)m).Children.Count > 0;
            treeAvailable.ChildrenGetter = delegate(object m)
            {
                return ((AdminLevel)m).Children;
            };
            treeAvailable.SetObjects(t);
        }
 public AdminLevelTypeAdd(AdminLevelType m)
     : base()
 {
     model = m;
     InitializeComponent();
 }
Beispiel #8
0
        public virtual void CreateImportFile(string filename, List<AdminLevel> adminLevels, AdminLevelType adminLevelType, ImportOptions opts)
        {
            options = opts;
            ReloadDropdownValues();
            LoadRelatedLists();
            System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            Microsoft.Office.Interop.Excel.Application xlsApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
            Microsoft.Office.Interop.Excel.Workbook xlsWorkbook;
            Microsoft.Office.Interop.Excel.Workbooks xlsWorkbooks;
            Microsoft.Office.Interop.Excel.Sheets xlsWorksheets;
            Microsoft.Office.Interop.Excel.Worksheet xlsWorksheet;
            Microsoft.Office.Interop.Excel.Worksheet xlsValidation;
            object oMissing = System.Reflection.Missing.Value;
            validationRanges = new Dictionary<string, string>();

            //Create new workbook
            xlsWorkbooks = xlsApp.Workbooks;
            xlsWorkbook = xlsWorkbooks.Add(true);
            xlsWorksheets = xlsWorkbook.Worksheets;

            //Get the first worksheet
            xlsWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)(xlsWorkbook.Worksheets[1]);

            // add hidden validation worksheet
            xlsValidation = (Microsoft.Office.Interop.Excel.Worksheet)xlsWorksheets.Add(oMissing, xlsWorksheet, oMissing, oMissing);
            xlsValidation.Name = validationSheetName;
            xlsValidation.Visible = Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetHidden;

            // row 1 column headers
            DemoRepository repo = new DemoRepository();
            List<string> names = adminLevelType == null? new List<string>() : repo.GetAdminLevelTypeNames(adminLevelType.Id);

            if (options.SurveyNames.Count > 0) // Multiple admin units for surveys
                xlsWorksheet.Cells[1, 1] = "* " + TranslationLookup.GetValue("SurveyName");
            else
                xlsWorksheet.Cells[1, 1] = "* " + TranslationLookup.GetValue("ID");
            
            for (int i = 0; i < names.Count; i++)
                xlsWorksheet.Cells[1, 2 + i] = "* " + names[i];
            int locationCount = names.Count + 1;
            int xlsColCount = names.Count + 1; // add one for id;
            xlsColCount = AddTypeSpecific(xlsWorksheet, xlsColCount);
            int colCountAfterStatic = xlsColCount;

            foreach (var item in Indicators)
            {
                if (item.Value.DataTypeId == (int)IndicatorDataType.SentinelSite || item.Value.IsCalculated || item.Value.IsMetaData)
                    continue;
                string isReq = "";
                if (item.Value.IsRequired)
                    isReq = "* ";

                // if the filtered list still has more than 7 possible multiselect values, do some weird shit.
                if (options.IndicatorValuesSublist.ContainsKey(item.Value.DisplayName) && options.IndicatorValuesSublist[item.Value.DisplayName].Count > 6)
                {
                    int optionNumber = 1;
                    foreach (string opt in options.IndicatorValuesSublist[item.Value.DisplayName])
                    {
                        xlsColCount++;
                        xlsWorksheet.Cells[1, xlsColCount] = isReq + TranslationLookup.GetValue(item.Key, item.Key) + Translations.ImportSelectionOption + optionNumber;
                        optionNumber++;
                    }
                }
                else
                {
                    xlsColCount++;
                    xlsWorksheet.Cells[1, xlsColCount] = isReq + TranslationLookup.GetValue(item.Key, item.Key);
                }
            }
            //xlsWorksheet.Cells[1, xlsColCount + 1] = TranslationLookup.GetValue("Notes");

            // row 2+ admin levels
            int xlsRowCount = 2;
            if (options.SurveyNames.Count > 0) // Multiple admin units for surveys
            {
                foreach (var survey in options.SurveyNames.OrderBy(a => a.DisplayName))
                {
                    xlsWorksheet.Cells[xlsRowCount, 1] = survey.DisplayName;
                    AddTypeSpecificLists(xlsWorksheet, xlsValidation, 0, xlsRowCount, oldCI, locationCount);
                    xlsRowCount = AddIndicatorColumns(oldCI, xlsWorksheet, xlsValidation, colCountAfterStatic, xlsRowCount);
                }
            }
            else
            {
                foreach (AdminLevel l in adminLevels.OrderBy(a => a.SortOrder))
                {
                    xlsWorksheet.Cells[xlsRowCount, 1] = l.Id;
                    List<AdminLevel> parents = repo.GetAdminLevelParentNames(l.Id);
                    int aCol = 2;
                    foreach (AdminLevel adminlevel in parents)
                    {
                        xlsWorksheet.Cells[xlsRowCount, aCol] = adminlevel.Name;
                        aCol++;
                    }
                    AddTypeSpecificLists(xlsWorksheet, xlsValidation, l.Id, xlsRowCount, oldCI, locationCount);
                    xlsRowCount = AddIndicatorColumns(oldCI, xlsWorksheet, xlsValidation, colCountAfterStatic, xlsRowCount);
                }
            }

            // Auto fit
            var last = xlsWorksheet.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
            var range = xlsWorksheet.get_Range("A1", last);
            range.Columns.AutoFit();

            // Save and display
            xlsApp.DisplayAlerts = false;
            xlsWorkbook.SaveAs(filename, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, oMissing,
                oMissing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
                Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlUserResolution, true,
                oMissing, oMissing, oMissing);
            xlsApp.Visible = true;
            Marshal.ReleaseComObject(xlsWorksheets);
            Marshal.ReleaseComObject(xlsWorksheet);
            Marshal.ReleaseComObject(xlsValidation);
            Marshal.ReleaseComObject(xlsWorkbooks);
            Marshal.ReleaseComObject(xlsWorkbook);
            Marshal.ReleaseComObject(xlsApp);
            System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
        }
        private int GetParams()
        {
            if (locationType.LevelNumber > 2)
                filterByType = settings.GetAdminLevelTypeByLevel(locationType.LevelNumber - 2);

            if (locationType.LevelNumber > 1)
            {
                dropdownBy = settings.GetAdminLevelTypeByLevel(locationType.LevelNumber - 1);
                var levels = demo.GetAdminLevelByLevel(locationType.LevelNumber - 1);
                if (filterBy != null)
                {
                    dropdownValues = levels.Where(a => a.ParentId == filterBy.Id).Select(a => a.Name).ToList();
                    return 2;
                }
                else
                {
                    dropdownValues = levels.Select(a => a.Name).ToList();
                    return 1;
                }
            }
            return -1;
        }
 public AdminLevelDemoImporter(AdminLevelType l, int? cid)
     : base()
 {
     countryDemoId = cid;
     locationType = l;
 }
 public StepAdminLevelImport(AdminLevelType type, IWizardStep p, bool demoOnly, DateTime d, int? cid)
     : base()
 {
     demoDate = d;
     Init(type, p, demoOnly, cid);
 }
 public StepAdminLevelImport(AdminLevelType type, IWizardStep p, int? cid)
     : base()
 {
     Init(type, p, false, cid);
 }
 private void LoadTrees()
 {
     if (cbLevels.SelectedItem == null)
         return;
     SelectedAdminLevelType = (AdminLevelType)cbLevels.SelectedItem;
     available = demography.GetAdminLevelTree(SelectedAdminLevelType.Id, showRedistricted);
     selected = new List<AdminLevel>();
     treeAvailable.SetObjects(available.ToList());
     treeSelected.SetObjects(selected.OrderBy(i => i.Name).ToList());
 }