public static Control CreateLabel(Indicator indicator, bool isStatic)
 {
     var text = indicator.DisplayName;
     if (isStatic)
         text = TranslationLookup.GetValue(indicator.DisplayName, indicator.DisplayName);
     if (indicator.IsRequired)
     {
         var required = new H3Required
         {
             Text = text,
             Name = "ciLabel_" + indicator.Id,
             AutoSize = true,
             Anchor = (AnchorStyles.Bottom | AnchorStyles.Left),
             TabStop = false
         };
         required.SetMaxWidth(370);
         return required;
     }
     else
     {
         var lbl = new H3bLabel
         {
             Text = text,
             Name = "ciLabel_" + indicator.Id,
             AutoSize = true,
             Anchor = (AnchorStyles.Bottom | AnchorStyles.Left),
             TabStop = false
         };
         lbl.SetMaxWidth(370);
         return lbl;
     }
 }
        private void StepCategory_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                Localizer.TranslateControl(this);
                h3bLabel1.MakeBold();
                h3bLabel2.MakeBold();
                h3bLabel3.MakeBold();

                for (int i = 0; i < options.SplitIntoNumber.Value; i++)
                {
                    var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                    var lblName = new H3bLabel { AutoSize = true, Text = options.MergeSources[i].Name, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lblName, 0, index);
                    string pop = "0";
                    if (options.MergeSources[i].CurrentDemography.TotalPopulation.HasValue)
                        pop = Convert.ToDouble(options.MergeSources[i].CurrentDemography.TotalPopulation.Value * 
                            (options.SplitDestinations[i].Percent / 100)).ToString("N");
                    var label = new H3bLabel { AutoSize = true, Text = pop, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(label, 1, index);
                    string villages = "N/A";
                    if(options.MergeDestination.Children.FirstOrDefault(a => a.ParentId == options.MergeSources[i].Id) != null)
                        villages = String.Join(", ", options.MergeDestination.Children.Where(a => a.ParentId == options.MergeSources[i].Id).Select(b => b.Name).ToArray());
                    var lblVillages = new H3bLabel { AutoSize = true, Text = villages, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lblVillages, 2, index);
                }
            }
        }
Beispiel #3
0
        private void StepCategory_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                Localizer.TranslateControl(this);


                Dictionary<int, Disease> diseases = new Dictionary<int, Disease>();
                foreach (var distro in options.DistrosCm)
                    if (!diseases.ContainsKey(distro.Disease.Id))
                        diseases.Add(distro.Disease.Id, distro.Disease);
                foreach (var distro in options.DistrosPc)
                    if (!diseases.ContainsKey(distro.Disease.Id))
                        diseases.Add(distro.Disease.Id, distro.Disease);

                if (diseases.Count == 0)
                    DoNext();

                foreach (var disease in diseases.Values.OrderBy(d => d.DisplayName))
                {
                    var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                    var lblName = new H3bLabel { AutoSize = true, Text = disease.DisplayName, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lblName, 0, index);

                    var lnk = new H3Link { Text = Translations.DownloadImportFile, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lnk, 1, index);
                    lnk.ClickOverride += () =>
                    {
                        List<IHaveDynamicIndicatorValues> forms = new List<IHaveDynamicIndicatorValues>();
                        if (disease.DiseaseType == "CM")
                            forms = options.DistrosCm.Where(d => d.Disease.Id == disease.Id).Cast<IHaveDynamicIndicatorValues>().ToList();
                        else
                            forms = options.DistrosPc.Where(d => d.Disease.Id == disease.Id).Cast<IHaveDynamicIndicatorValues>().ToList();
                        DistroImporter importer = new DistroImporter();
                        importer.SetType(disease.Id);
                        var payload = new WorkerPayload
                        {
                            FileName = Util.CleanFilename(disease.DisplayName) + "_" + options.SplitType.ToString() + DateTime.Now.ToString("yyyyMMdd") + ".xlsx",
                            Importer = importer,
                            Forms = forms
                        };
                        CreateDownload(payload);
                    };
                    var lnk2 = new H3Link { Text = Translations.UploadImportFile, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lnk2, 2, index);
                    lnk2.ClickOverride += () =>
                    {
                        Upload(disease);
                    };
                }
            }
        }
Beispiel #4
0
        private void StepCategory_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                Localizer.TranslateControl(this);


                Dictionary<int, SurveyType> surveys = new Dictionary<int, SurveyType>();
                foreach (var survey in options.Surveys)
                    if (!surveys.ContainsKey(survey.TypeOfSurvey.Id))
                        surveys.Add(survey.TypeOfSurvey.Id, survey.TypeOfSurvey);

                if (surveys.Count == 0 || options.SplitType == SplittingType.Merge)
                {
                    DoNext();
                    return;
                }

                MessageBox.Show(Translations.SplittingSurveyWarning, Translations.ValidationErrorTitle);

                foreach (var t in surveys.Values)
                {
                    var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                    var lblName = new H3bLabel { AutoSize = true, Text = t.SurveyTypeName, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lblName, 0, index);

                    var lnk = new H3Link { Text = Translations.DownloadImportFile, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lnk, 1, index);
                    lnk.ClickOverride += () =>
                    {
                        List<IHaveDynamicIndicatorValues> forms = options.Surveys.Where(s => s.TypeOfSurvey.Id == t.Id).Cast<IHaveDynamicIndicatorValues>().ToList();
                        SurveyImporter importer = new SurveyImporter();
                        importer.SetType(t.Id);
                        var payload = new SplitDistro.WorkerPayload
                        {
                            FileName = Util.CleanFilename(t.SurveyTypeName) + "_" + options.SplitType.ToString() + DateTime.Now.ToString("yyyyMMdd") + ".xlsx",
                            Importer = importer,
                            Forms = forms
                        };
                        SplitDistro.CreateDownload(payload);
                    };

                    var lnk2 = new H3Link { Text = Translations.UploadImportFile, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lnk2, 2, index);
                    lnk2.ClickOverride += () =>
                    {
                        Upload(t);
                    };
                }
            }
        }
        private void AddRuleControls(List<Indicator> indicators, SplittingType splitType)
        {
            for (int i = 0; i < indicators.Count; i++)
            {
                var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });

                // Add control to screen
                var label = new H3bLabel { AutoSize = true, Text = indicators[i].DisplayName, Margin = new Padding(0, 5, 10, 5) };
                label.MakeBold();
                tblNewUnits.Controls.Add(label, 0, index);
                var cntrl = CreateDropdown(indicators[i], GetRuleValues(splitType, indicators[i].DataTypeId));
                tblNewUnits.Controls.Add(cntrl, 1, index);
            }
        }
Beispiel #6
0
        private void StepCategory_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                Localizer.TranslateControl(this);

                Dictionary<int, IntvType> types = new Dictionary<int, IntvType>();
                foreach (var form in options.Intvs)
                    if (!types.ContainsKey(form.IntvType.Id))
                        types.Add(form.IntvType.Id, form.IntvType);

                if (types.Count == 0)
                    DoNext();

                foreach (var t in types.Values)
                {
                    var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                    var lblName = new H3bLabel { AutoSize = true, Text = t.IntvTypeName, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lblName, 0, index);

                    var lnk = new H3Link { Text = Translations.DownloadImportFile, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lnk, 1, index); 
                    lnk.ClickOverride += () =>
                    {
                        List<IHaveDynamicIndicatorValues> forms = options.Intvs.Where(s => s.IntvType.Id == t.Id).Cast<IHaveDynamicIndicatorValues>().ToList();
                        IntvImporter importer = new IntvImporter();
                        importer.SetType(t.Id);
                        var payload = new SplitDistro.WorkerPayload
                        {
                            FileName = Util.CleanFilename(t.IntvTypeName) + "_" + options.SplitType.ToString() + DateTime.Now.ToString("yyyyMMdd") + ".xlsx",
                            Importer = importer,
                            Forms = forms
                        };
                        SplitDistro.CreateDownload(payload);
                    };
                    var lnk2 = new H3Link { Text = Translations.UploadImportFile, Margin = new Padding(0, 5, 10, 5) };
                    tblNewUnits.Controls.Add(lnk2, 2, index);
                    lnk2.ClickOverride += () =>
                    {
                        Upload(t);
                    };
                }
            }
        }
        private void SplittingAdminLevel_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                Localizer.TranslateControl(this);
                int levelNumber = 0;
                
                if (options.SplitType == SplittingType.SplitCombine)
                    levelNumber = options.MergeSources[0].LevelNumber;
                else
                    levelNumber = options.Source.LevelNumber;

                for (int i = 0; i < options.SplitIntoNumber.Value; i++)
                {
                    var index = tblNewUnits.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });

                    var cntrl = new TextBox { Width = 100, Margin = new Padding(0, 5, 10, 5), Tag = i };
                    var chooser = new AdminUnitChooser(levelNumber);
                    chooser.Margin = new Padding(0, 5, 10, 5);
                    AdminLevel source = null;
                    if (options.SplitType == SplittingType.SplitCombine)
                    {
                        chooser.HideNewLink();
                        chooser.Select(options.MergeSources[i], true);
                        options.MergeSources[i].Children = repo.GetAdminLevelChildren(options.MergeSources[i].Id);
                        options.MergeSources[i].CurrentDemography = repo.GetRecentDemography(options.MergeSources[i].Id);
                        source = options.MergeSources[i];
                    }
                    else if (options.SplitType == SplittingType.Split)
                    {
                        if (options.SplitDestinations.Count() >= i + 1)
                        {
                            chooser.Select(options.SplitDestinations[i].Unit, true);
                            cntrl.Text = options.SplitDestinations[i].Percent.ToString();
                        }
                        source = options.Source;
                    }

                    // Add control to screen
                    choosers.Add(new ChooseAdminLevel { Chooser = chooser, Source = source });
                    tblNewUnits.Controls.Add(chooser, 0, index);
                    var label = new H3bLabel { AutoSize = true, Text = "0", Margin = new Padding(0, 5, 10, 5) };
                    label.MakeBold();
                    labels.Add(label);
                    tblNewUnits.Controls.Add(label, 2, index);
                    cntrl.TextChanged += cntrl_TextChanged;
                    percents.Add(cntrl);
                    tblNewUnits.Controls.Add(cntrl, 1, index);
                }
            }
        }
        private void validationWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (this.IsDisposed)
                return;

            // Get the validation results
            List<ValidationResult> validationResults = (List<ValidationResult>)e.Result;

            // Hide and clear the validation results container while it is being populated
            tlpValidationResults.Visible = false;
            this.SuspendLayout();
            tlpValidationResults.Controls.Clear();

            // Display each result
            foreach (ValidationResult result in validationResults)
            {
                // Add a new row
                int labelRowIndex = tlpValidationResults.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                int controlRowIndex = tlpValidationResults.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });

                // Add label
                tlpValidationResults.Controls.Add(
                    new H3bLabel {
                        Text = TranslationLookup.GetValue(result.ValidationRule.Indicator.DisplayName,
                        result.ValidationRule.Indicator.DisplayName),
                        Name = "ciLabel_" + result.ValidationRule.Indicator.DisplayName,
                        AutoSize = true
                    },
                    0, labelRowIndex);

                // Add val
                var label = new H3bLabel { 
                    Text = result.Message,
                    Name = "ciLabel_Val" + result.ValidationRule.Indicator.DisplayName,
                    AutoSize = true
                };
                // Set the validation message text color
                if (result.IsSuccess)
                    label.TextColor = Color.FromArgb(0, 160, 0);
                else
                {
                    if (result.HadMissingValues)
                        label.TextColor = Color.FromArgb(0, 0, 160);
                    else
                        label.TextColor = Color.FromArgb(160, 0, 0);
                }
                label.MakeBold();
                tlpValidationResults.Controls.Add(label, 0, controlRowIndex);
            }

            this.ResumeLayout();
            tlpValidationResults.Visible = true;
            loadingIndicator.Visible = false;
            lnkValidateLink.Enabled = true;
        }
        private void LoadSavedReports()
        {
            ReportRepository repo = new ReportRepository();
            var reports = repo.GetCustomReports();
            tblReportBuilder.Visible = false;
            this.SuspendLayout();
            tblReportBuilder.Controls.Clear();
            int rowIndex = tblReportBuilder.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            var tblNew = new TableLayoutPanel { AutoSize = true, AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink };
            tblNew.RowStyles.Clear();
            tblNew.ColumnStyles.Clear();
            tblNew.ColumnStyles.Add(new ColumnStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
            tblNew.ColumnStyles.Add(new ColumnStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
            tblNew.RowStyles.Add(new RowStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
            var name2 = new H3bLabel { Text = Translations.CustomReport, Name = "rpt_cr", AutoSize = true, };
            name2.SetMaxWidth(400);
            var edit2 = new H3Link { Text = Translations.NewLink, Margin = new Padding(0, 2, 0, 0) };
            edit2.ClickOverride += () =>
            {
                WizardForm wiz = new WizardForm(new StepCategory(), Translations.CustomReportBuilder);
                wiz.Height = 695;
                wiz.OnRunReport = RunCustomReport;
                wiz.Show();
            };
            tblNew.Controls.Add(name2, 0, 0);
            tblNew.Controls.Add(edit2, 1, 0);
            tblReportBuilder.Controls.Add(tblNew, 0, rowIndex);

            foreach (var report in reports)
            {
                rowIndex = tblReportBuilder.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                var tbl = new TableLayoutPanel { AutoSize = true, AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink };
                tbl.RowStyles.Clear();
                tbl.ColumnStyles.Clear();
                tbl.ColumnStyles.Add(new ColumnStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
                tbl.ColumnStyles.Add(new ColumnStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
                tbl.ColumnStyles.Add(new ColumnStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
                tbl.RowStyles.Add(new RowStyle { SizeType = System.Windows.Forms.SizeType.AutoSize });
                var name = new H3bLabel { Text = report.DisplayName, Name = "rpt_" + report.DisplayName, AutoSize = true, };
                name.SetMaxWidth(400);
                var edit = new H3Link { Text = Translations.Edit + "...", Margin = new Padding(0, 2, 0, 0) };
                edit.ClickOverride += () =>
                {
                    WizardForm wiz = new WizardForm(new StepIndicators(report), Translations.CustomReportBuilder);
                    wiz.Height = 695;
                    wiz.OnRunReport = RunCustomReport;
                    wiz.Show();
                };
                var delete = new H3Link { Text = Translations.Delete + "...", Margin = new Padding(0, 2, 0, 0) };
                delete.ClickOverride += () => 
                {
                    DeleteConfirm confirm = new DeleteConfirm(Translations.Delete, Translations.DeleteConfirmMessage);
                    if (confirm.ShowDialog() == DialogResult.OK)
                    {
                        repo.DeleteCustomReport(report, ApplicationData.Instance.GetUserId());
                        LoadSavedReports();
                    }
                };
                tbl.Controls.Add(name, 0, 0);
                tbl.Controls.Add(edit, 1, 0);
                tbl.Controls.Add(delete, 2, 0);
                tblReportBuilder.Controls.Add(tbl, 0, rowIndex);
            }
            this.ResumeLayout();
            tblReportBuilder.Visible = true;
        }
Beispiel #10
0
        void calcWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (this.IsDisposed)
                return;

            List<KeyValuePair<string, string>> calculationResults = (List<KeyValuePair<string, string>>)e.Result;

            tblIndicators.Visible = false;
            this.SuspendLayout();
            tblIndicators.Controls.Clear();
            int count = 0;
            int labelRowIndex = tblIndicators.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            int controlRowIndex = tblIndicators.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            int columnCount = 0;

            if (calculationResults.Count == 0)
                this.Visible = false;

            foreach (var item in calculationResults)
            {
                if (count % 2 == 0)
                {
                    labelRowIndex = tblIndicators.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                    controlRowIndex = tblIndicators.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
                    columnCount = 0;
                }

                // Add label
                tblIndicators.Controls.Add(
                    new H3bLabel { Text = TranslationLookup.GetValue(item.Key, item.Key), Name = "ciLabel_" + item.Key, AutoSize = true, },
                    columnCount, labelRowIndex);

                // Add val
                var label = new H3bLabel { Text = item.Value, Name = "ciLabel_Val" + item.Key, AutoSize = true, };
                label.MakeBold();
                tblIndicators.Controls.Add(label, columnCount, controlRowIndex);

                count++;
                columnCount = columnCount + 2;
            }

            this.ResumeLayout();
            tblIndicators.Visible = true;
            lblCalculating.Visible = false;
            OnFocus();
        }