public IndicatorValueItemAdd(IndicatorDropdownValue m, Indicator i)
     : base()
 {
     indicator = i;
     model = m;
     InitializeComponent();
 }
Exemplo n.º 2
0
 private void edit_OnSave(Indicator obj)
 {
     Indicator old = model.Indicators.Values.FirstOrDefault(i => i.Id == obj.Id);
     model.Indicators.Remove(old.DisplayName);
     model.Indicators.Add(obj.DisplayName, obj);
     lvIndicators.SetObjects(model.Indicators.Values.Where(i => i.IsEditable));
 }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
 public IndicatorAdd(IEnumerable<Indicator> vm, Indicator m)
     : base()
 {
     existingIndicators = vm;
     model = Util.DeepClone(m);
     InitializeComponent();
 }
Exemplo n.º 5
0
        public static Control CreateDate(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList)
        {
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new NullableDatePickerControl
            {
                Name = "dynamicDt" + indicator.Id.ToString(),
                Margin = new Padding(0, 5, 10, bottomPadding),
                ShowClear = !indicator.IsRequired,
                Value = DateTime.Now
            };
            // Add the Control to the DynamicContainer for reference
            container.Control = cntrl;
            container.IsValid = () =>
            {
                if (indicator.IsRequired && cntrl.GetValue() == DateTime.MinValue)
                {
                    indicatorErrors.SetError(cntrl, Translations.Required);
                    return false;
                }

                indicatorErrors.SetError(cntrl, "");
                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };
            DateTime dt = new DateTime();
            if(DateTime.TryParseExact(val, "MM/dd/yyyy", 
    				CultureInfo.InvariantCulture, 
    				DateTimeStyles.None, 
    				out dt))
                cntrl.Value = dt;
            else
                cntrl.Value = DateTime.MinValue;

            container.GetValue = () => 
            {
                if (cntrl.GetValue() == DateTime.MinValue)
                    return "";
                else
                    return cntrl.GetValue().ToString("MM/dd/yyyy"); 
            };
            controlList.Add(container);
            return cntrl;
        }
Exemplo n.º 6
0
        public static Control CreateDropdown(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList,
            IndicatorEntityType entityType, List<IndicatorDropdownValue> dropdownKeys)
        {
            List<IndicatorDropdownValue> availableValues = new List<IndicatorDropdownValue>();
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new ComboBox { Name = "dynamicCombo" + indicator.Id.ToString(), Width = 220, Margin = new Padding(0, 5, 10, bottomPadding), DropDownStyle = ComboBoxStyle.DropDownList };
            cntrl.MouseWheel += (s, e) => { ((HandledMouseEventArgs)e).Handled = true; };

            // Add the Control to the DynamicContainer for reference
            container.Control = cntrl;

            if (!indicator.IsRequired)
                cntrl.Items.Add(new IndicatorDropdownValue { DisplayName = "", Id = -1 });

            foreach (IndicatorDropdownValue v in dropdownKeys.Where(k => k.IndicatorId == indicator.Id).OrderBy(i => i.SortOrder))
            {
                cntrl.Items.Add(v);
                availableValues.Add(v);
            }
            cntrl.ValueMember = "Id";
            cntrl.DisplayMember = "DisplayName";
            if (availableValues.Count > 0)
                cntrl.DropDownWidth = BaseForm.GetDropdownWidth(availableValues.Select(a => a.DisplayName));
            if (!string.IsNullOrEmpty(val))
            {
                var valItem = availableValues.FirstOrDefault(a => a.TranslationKey == val);
                cntrl.SelectedItem = valItem;
            }

            container.IsValid = () =>
            {
                if (indicator.IsRequired && indicatorErrors != null)
                {
                    if (cntrl.Text == "" || cntrl.Text == null)
                    {
                        indicatorErrors.SetError(cntrl, Translations.Required);
                        return false;
                    }
                    else
                        indicatorErrors.SetError(cntrl, "");
                }
                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };

            container.GetValue = () =>
            {
                if (cntrl.SelectedItem == null || ((IndicatorDropdownValue)cntrl.SelectedItem).Id == -1)
                    return null;
                return ((IndicatorDropdownValue)cntrl.SelectedItem).TranslationKey;
            };
            controlList.Add(container);

            if (indicator.CanAddValues)
                return AddNewValLink(cntrl, indicator, entityType);
            else
                return cntrl;
        }
Exemplo n.º 7
0
        public static Control CreateMulti(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList,
            IndicatorEntityType entityType, List<IndicatorDropdownValue> dropdownKeys)
        {
            List<IndicatorDropdownValue> availableValues = new List<IndicatorDropdownValue>();
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new ListBox { Name = "dynamicMulti" + indicator.Id.ToString(), Width = 220, Height = 100, Margin = new Padding(0, 5, 20, bottomPadding), SelectionMode = SelectionMode.MultiExtended };

            // Add the Control to the DynamicContainer for reference
            container.Control = cntrl;
            
            foreach (var v in dropdownKeys.Where(k => k.IndicatorId == indicator.Id).OrderBy(i => i.SortOrder))
            {
                cntrl.Items.Add(v);
                availableValues.Add(v);
            }
            cntrl.ValueMember = "Id";
            cntrl.DisplayMember = "DisplayName";
            if (!string.IsNullOrEmpty(val))
            {
                string[] vals = val.Split('|');
                cntrl.ClearSelected();
                foreach (var av in availableValues.Where(v => vals.Contains(v.TranslationKey)))
                    cntrl.SelectedItems.Add(av);
            }

            container.GetValue = () =>
            {
                List<string> selected = new List<string>();
                foreach (var i in cntrl.SelectedItems)
                    selected.Add((i as IndicatorDropdownValue).TranslationKey);
                return string.Join("|", selected.ToArray());
            };

            container.IsValid = () =>
            {
                if (indicator.IsRequired && indicatorErrors != null)
                {
                    if (string.IsNullOrEmpty(container.GetValue()))
                    {
                        indicatorErrors.SetError(cntrl, Translations.Required);
                        return false;
                    }
                    else
                        indicatorErrors.SetError(cntrl, "");
                }
                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };

            controlList.Add(container);

            if (indicator.CanAddValues)
                return AddNewValLink(cntrl, indicator, entityType);
            else
                return cntrl;
        }
Exemplo n.º 8
0
        public static Control CreateNumber(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList, IndicatorDataType type)
        {
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new TextBox { Name = "dynamicNum" + indicator.Id.ToString(), Text = val, Width = 220, Margin = new Padding(0, 5, 10, bottomPadding) };
            container.IsValid = () =>
            {
                double d = 0;
                int i = 0;
                if (indicator.IsRequired && (cntrl.Text == "" || cntrl.Text == null))
                {
                    indicatorErrors.SetError(cntrl, Translations.Required);
                    return false;
                }
                else if (!string.IsNullOrEmpty(cntrl.Text) && type == IndicatorDataType.Number && !Double.TryParse(cntrl.Text, out d))
                {
                    indicatorErrors.SetError(cntrl, Translations.MustBeNumber);
                    return false;
                }
                else if (!string.IsNullOrEmpty(cntrl.Text) && type == IndicatorDataType.Year && (!int.TryParse(cntrl.Text, out i) || (i > 2100 || i < 1900)))
                {
                    indicatorErrors.SetError(cntrl, Translations.ValidYear);
                    return false;
                }
                else if (!string.IsNullOrEmpty(cntrl.Text) && type == IndicatorDataType.Integer && (!int.TryParse(cntrl.Text, out i)))
                {
                    indicatorErrors.SetError(cntrl, Translations.MustBeWholeNumber);
                    return false;
                }

                indicatorErrors.SetError(cntrl, "");
                return true;
            };
            // Add the Control to the DynamicContainer for reference
            container.Control = cntrl;
            cntrl.Validating += (s, e) => { container.IsValid(); };
            container.GetValue = () => { return cntrl.Text; };
            controlList.Add(container);
            return cntrl;
        }
Exemplo n.º 9
0
        public static Control CreateYesNo(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList)
        {
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new CheckBox { Name = "dynamicChk" + indicator.Id.ToString() };
            container.IsValid = () => { return true; };
            cntrl.Checked = val == "1";

            // Add the Control to the DynamicContainer for reference
            container.Control = cntrl;

            container.GetValue = () => { return Convert.ToInt32(cntrl.Checked).ToString(); };
            controlList.Add(container);
            return cntrl;
        }
Exemplo n.º 10
0
        private static Control AddNewValLink(Control cntrl, Indicator indicator, IndicatorEntityType entityType)
        {
            cntrl.Margin = new Padding(0, 5, 20, 0);
            TableLayoutPanel tblContainer = new TableLayoutPanel { AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, AutoScroll = true };
            tblContainer.RowStyles.Clear();
            tblContainer.ColumnStyles.Clear();
            int cRow = tblContainer.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            tblContainer.Controls.Add(cntrl, 0, cRow);
            int lRow = tblContainer.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            var lnk = new H3Link { Text = Translations.AddNewItemLink, Margin = new Padding(0, 5, 3, bottomPadding) };
            lnk.ClickOverride += () =>
            {
                IndicatorValueItemAdd form = new IndicatorValueItemAdd(new IndicatorDropdownValue { IndicatorId = indicator.Id, EntityType = entityType }, indicator);
                form.OnSave += (v) =>
                {
                    v.TranslationKey = v.DisplayName;
                    if (cntrl is ListBox)
                        (cntrl as ListBox).Items.Add(v);
                    else if (cntrl is ComboBox)
                        (cntrl as ComboBox).Items.Add(v);
                };
                form.ShowDialog();
            };
            tblContainer.Controls.Add(lnk, 0, lRow);

            return tblContainer;
        }
 private PickerControl CreateIndicatorControl(Indicator indicator, IndicatorEntityType entityType, List<IndicatorDropdownValue> dropdownKeys)
 {
     if (indicator.DataTypeId == (int)IndicatorDataType.Multiselect)
         return CreatePickerBox(indicator, entityType, dropdownKeys.Where(k => k.IndicatorId == indicator.Id).OrderBy(i => i.SortOrder).Cast<object>().ToList());
     if (indicator.DataTypeId == (int)IndicatorDataType.Partners)
     {
         IntvRepository repo = new IntvRepository();
         return CreatePickerBox(indicator, entityType, repo.GetPartners().Cast<object>().ToList());
     }
     return null;
 }
Exemplo n.º 12
0
 private void AddNewVal(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType)
 {
     IndicatorValueItemAdd form = new IndicatorValueItemAdd(new IndicatorDropdownValue { IndicatorId = indicator.Id, EntityType = entityType }, indicator);
     form.OnSave += (v) =>
     {
         cntrl.Items.Add(v);
     };
     form.ShowDialog();
 }
Exemplo n.º 13
0
        public static Control CreatePartners(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList)
        {
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new ListBox { Name = "dynamicPartners" + indicator.Id.ToString(), Width = 220, Height = 100, Margin = new Padding(0, 5, 20, bottomPadding), SelectionMode = SelectionMode.MultiExtended };

            List<Partner> partners = GetAndLoadPartners(cntrl);
            cntrl.ValueMember = "Id";
            cntrl.DisplayMember = "DisplayName";
            if (!string.IsNullOrEmpty(val))
            {
                string[] vals = val.Split('|');
                cntrl.ClearSelected();
                foreach (var av in partners.Where(v => vals.Contains(v.Id.ToString())))
                    cntrl.SelectedItems.Add(av);
            }

            container.GetValue = () =>
            {
                List<string> selected = new List<string>();
                foreach (var i in cntrl.SelectedItems)
                    selected.Add((i as Partner).Id.ToString());
                return string.Join("|", selected.ToArray());
            };

            container.IsValid = () =>
            {
                if (indicator.IsRequired && indicatorErrors != null)
                {
                    if (string.IsNullOrEmpty(container.GetValue()))
                    {
                        indicatorErrors.SetError(cntrl, Translations.Required);
                        return false;
                    }
                    else
                        indicatorErrors.SetError(cntrl, "");
                }
                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };

            // Add table container and link
            controlList.Add(container);
            cntrl.Margin = new Padding(0, 5, 20, 0);
            TableLayoutPanel tblContainer = new TableLayoutPanel { AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, AutoScroll = true };
            tblContainer.RowStyles.Clear();
            tblContainer.ColumnStyles.Clear();
            int cRow = tblContainer.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            tblContainer.Controls.Add(cntrl, 0, cRow);
            int lRow = tblContainer.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            var lnk = new H3Link { Text = Translations.AddNewItemLink, Margin = new Padding(0, 0, 3, bottomPadding) };
            lnk.ClickOverride += () =>
            {
                PartnerList list = new PartnerList();
                list.OnSave += () =>
                {
                    partners = GetAndLoadPartners(cntrl);
                };
                list.ShowDialog();
            };
            tblContainer.Controls.Add(lnk, 0, lRow);

            return tblContainer;
        }
Exemplo n.º 14
0
 public Control CreateListBox(Indicator indicator, Action<ListBox, List<IndicatorDropdownValue>> addValues,
     Action<ListBox, Indicator, IndicatorEntityType> onAddValue, IndicatorEntityType entityType, List<IndicatorDropdownValue> values)
 {
     return CreateListBox(indicator, addValues, onAddValue, entityType, values, "DisplayName");
 }
Exemplo n.º 15
0
        public Control CreateListBox(Indicator indicator, Action<ListBox, List<IndicatorDropdownValue>> addValues, 
            Action<ListBox, Indicator, IndicatorEntityType> onAddValue, IndicatorEntityType entityType, List<IndicatorDropdownValue> values,
            string displayMember)
        {
            var cntrl = new ListBox { Name = "dynamicMulti" + indicator.Id.ToString(), Width = 220, Height = 100, Margin = new Padding(0, 5, 20, bottomPadding), 
                SelectionMode = SelectionMode.None };
            addValues(cntrl, values);
            cntrl.ValueMember = "Id";
            cntrl.DisplayMember = displayMember;

            cntrl.Margin = new Padding(0, 5, 20, 0);
            TableLayoutPanel tblContainer = new TableLayoutPanel { AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, AutoScroll = true };
            tblContainer.RowStyles.Clear();
            tblContainer.ColumnStyles.Clear();
            int cRow = tblContainer.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            tblContainer.Controls.Add(cntrl, 0, cRow);
            int lRow = tblContainer.RowStyles.Add(new RowStyle { SizeType = SizeType.AutoSize });
            var lnk = new H3Link { Text = Translations.AddNewItemLink, Margin = new Padding(0, 5, 3, bottomPadding) };
            lnk.ClickOverride += () =>
            {
                onAddValue(cntrl, indicator, entityType);
            };
            tblContainer.Controls.Add(lnk, 0, lRow);

            return tblContainer;
        }
Exemplo n.º 16
0
 private Control CreateIndicatorControl(Indicator indicator, IndicatorEntityType entityType, List<IndicatorDropdownValue> dropdownKeys)
 {
     if (indicator.DataTypeId == (int)IndicatorDataType.Dropdown || indicator.DataTypeId == (int)IndicatorDataType.Multiselect)
         return CreateListBox(indicator, AddValues, AddNewVal, entityType, dropdownKeys.Where(k => k.IndicatorId == indicator.Id).OrderBy(i => i.SortOrder).ToList());
     if (indicator.DataTypeId == (int)IndicatorDataType.EvaluationUnit)
         return CreateListBox(indicator, AddValues, AddNewVal, IndicatorEntityType.EvaluationUnit, settings.GetEvaluationUnits());
     if (indicator.DataTypeId == (int)IndicatorDataType.EcologicalZone)
         return CreateListBox(indicator, AddValues, AddNewVal, IndicatorEntityType.EcologicalZone, settings.GetEcologicalZones());
     if (indicator.DataTypeId == (int)IndicatorDataType.EvalSubDistrict)
         return CreateListBox(indicator, AddValues, AddNewVal, IndicatorEntityType.EvalSubDistrict, settings.GetEvalSubDistricts());
     if (indicator.DataTypeId == (int)IndicatorDataType.EvaluationSite)
         return CreateListBox(indicator, AddValues, AddNewVal, IndicatorEntityType.EvalSite, settings.GetEvalSites());
     if (indicator.DataTypeId == (int)IndicatorDataType.SentinelSite)
         return CreateListBox(indicator, AddSites, AddSentinelSite, entityType, dropdownKeys, "SiteName");
     if (indicator.DataTypeId == (int)IndicatorDataType.Partners)
         return CreateListBox(indicator, AddPartners, AddPartner, entityType, dropdownKeys);
     return null;
 }
Exemplo n.º 17
0
 void add_OnSave(Indicator obj)
 {
     viewModel.Indicators.Add(obj.DisplayName, obj);
     viewModel.DoSaveType(null);
     lvIndicators.SetObjects(viewModel.Indicators.Values.Where(i => i.IsEditable));
 }
        public PickerControl CreatePickerBox(Indicator indicator, IndicatorEntityType entityType, List<object> values)
        {
            if (values.Count < 7)
                return null;

            var cntrl = new PickerControl();
            cntrl.LoadLists(values, "DisplayName");
            cntrl.Margin = new Padding(0, 5, 20, 0);
            return cntrl;
        }
Exemplo n.º 19
0
        public static Control CreateDynamicNameVal(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList,
           IndicatorEntityType entityType, List<IndicatorDropdownValue> values)
        {
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new ComboBox { Name = "dynamicCombo" + indicator.Id.ToString(), Width = 220, Margin = new Padding(0, 5, 10, bottomPadding), DropDownStyle = ComboBoxStyle.DropDownList };
            foreach (IndicatorDropdownValue v in values)
                cntrl.Items.Add(v);
            cntrl.ValueMember = "Id";
            cntrl.DisplayMember = "DisplayName";
            if (values.Count > 0)
                cntrl.DropDownWidth = BaseForm.GetDropdownWidth(values.Select(a => a.DisplayName));
            if (!string.IsNullOrEmpty(val))
            {
                var valItem = values.FirstOrDefault(a => a.Id == Convert.ToInt32(val));
                cntrl.SelectedItem = valItem;
            }

            container.IsValid = () =>
            {
                if (indicator.IsRequired && indicatorErrors != null)
                {
                    if (cntrl.Text == "" || cntrl.Text == null)
                    {
                        indicatorErrors.SetError(cntrl, Translations.Required);
                        return false;
                    }
                    else
                        indicatorErrors.SetError(cntrl, "");
                }
                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };

            container.GetValue = () =>
            {
                if (cntrl.SelectedItem == null)
                    return null;
                return ((IndicatorDropdownValue)cntrl.SelectedItem).Id.ToString();
            };
            controlList.Add(container);

            if (indicator.CanAddValues)
                return AddNewValLink(cntrl, indicator, entityType);
            else
                return cntrl;
        }
Exemplo n.º 20
0
        protected int AddValueToCell(Microsoft.Office.Interop.Excel.Worksheet xlsWorksheet, Microsoft.Office.Interop.Excel.Worksheet validation, int c, int r,
            string value, Indicator indicator, CultureInfo currentCulture, bool isUpdate)
        {
            if (options.IndicatorValuesSublist.ContainsKey(indicator.DisplayName))
            {
                if (options.IndicatorValuesSublist[indicator.DisplayName].Count > 6)
                {
                    int optionNumber = 1;
                    foreach (string opt in options.IndicatorValuesSublist[indicator.DisplayName])
                    {
                        AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", options.IndicatorValuesSublist[indicator.DisplayName], currentCulture);
                        c++;
                        optionNumber++;
                    }
                    c--; // remove last increment
                }
                else
                    AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", Util.ProduceEnumeration(options.IndicatorValuesSublist[indicator.DisplayName]),
                        currentCulture);
            }
            else if (indicator.DataTypeId == (int)IndicatorDataType.Partners)
            {
                if (!isUpdate)
                    AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", Util.ProduceEnumeration(partners.Select(p => p.DisplayName).ToList()),
                        currentCulture);
            }
            else if (indicator.DataTypeId == (int)IndicatorDataType.EvaluationUnit)
                AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", eus.Select(p => p.DisplayName).ToList(), currentCulture);
            else if (indicator.DataTypeId == (int)IndicatorDataType.EvaluationSite)
                AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", ess.Select(p => p.DisplayName).ToList(), currentCulture);
            else if (indicator.DataTypeId == (int)IndicatorDataType.EvalSubDistrict)
                AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", subdistricts.Select(p => p.DisplayName).ToList(), currentCulture);
            else if (indicator.DataTypeId == (int)IndicatorDataType.EcologicalZone)
                AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", ezs.Select(p => p.DisplayName).ToList(), currentCulture);
            else if (indicator.DataTypeId == (int)IndicatorDataType.Multiselect)
            {
                if (!isUpdate)
                    AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "",
                        Util.ProduceEnumeration(DropDownValues.Where(i => i.IndicatorId == indicator.Id).Select(p => p.DisplayName).ToList()), currentCulture);
            }
            else if (indicator.DataTypeId == (int)IndicatorDataType.Dropdown)
                AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "",
                    DropDownValues.Where(i => i.IndicatorId == indicator.Id).Select(p => p.DisplayName).ToList(), currentCulture);
            else if (indicator.DataTypeId == (int)IndicatorDataType.Month)
                AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "", months.Select(p => p.Name).ToList(), currentCulture);
            else if (indicator.DataTypeId == (int)IndicatorDataType.DiseaseMultiselect)
            {
                if (!isUpdate)
                    AddDataValidation(xlsWorksheet, validation, Util.GetExcelColumnName(c), r, "", "",
                       Util.ProduceEnumeration(DropDownValues.Where(i => i.IndicatorId == indicator.Id && selectedDiseases.Contains(i.DisplayName)).Select(p => p.DisplayName).ToList()),
                       currentCulture);
            }
            else
                xlsWorksheet.Cells[r, c] = value;


            if (!string.IsNullOrEmpty(value))
            {
                object parsedVal = valueParser.Parse(indicator.DataTypeId, indicator.Id, value);
                if (parsedVal != null)
                    xlsWorksheet.Cells[r, c] = parsedVal;
            }

            return c;
        }
Exemplo n.º 21
0
 /// <summary>
 /// Builds an instance of a ValidationRule
 /// </summary>
 /// <param name="mapping">The ValidationMapping</param>
 /// <param name="indicator">The indicator to validate gainst</param>
 /// <param name="values">The values to validate against</param>
 /// <returns></returns>
 public static ValidationRule BuildRule(ValidationMapping mapping, Indicator indicator, List<IndicatorValue> values)
 {
     switch (mapping.ValidationType)
     {
         case ValidationRuleType.GreaterThanSum:
             return new GreaterThanSumRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.GreaterThanEqualToSum:
             return new GreaterThanEqualToSumRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.LessThanSum:
             return new LessThanSumRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.LessThanEqualToSum:
             return new LessThanEqualToSumRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.EqualToSum:
             return new EqualToSumRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.DateEarlierThan:
             return new DateEarlierThanRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.DateLaterThan:
             return new DateLaterThanRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         case ValidationRuleType.DateHasSameYear:
             return new DateHasSameYearRule(indicator, values, mapping.IndicatorsToCompareAgainst.ToList());
         default:
             return null;
     }
 }
        private Control CreateControl(Indicator indicator, string val)
        {
            var container = new DynamicContainer { Indicator = indicator };
            if (indicator.DataTypeId == (int)IndicatorDataType.Date)
            {
                DateTime d;
                var cntrl = new NullableDatePickerControl
                {
                    Name = "dynamicDt" + indicator.Id.ToString(),
                    ShowClear = true
                };
                container.IsValid = () =>
                {
                    if (indicator.IsRequired)
                    {
                        if (cntrl.Text == "" || cntrl.Text == null)
                        {
                            indicatorErrors.SetError(cntrl, Translations.Required);
                            return false;
                        }
                        else if (!DateTime.TryParse(cntrl.Text, out d))
                        {
                            indicatorErrors.SetError(cntrl, Translations.MustBeDate);
                            return false;
                        }
                        else
                            indicatorErrors.SetError(cntrl, "");
                    }
                    return true;
                };
                cntrl.Validating += (s, e) => { container.IsValid(); };
                DateTime dt = new DateTime();
                if (DateTime.TryParseExact(val, "MM/dd/yyyy",
                        CultureInfo.InvariantCulture,
                        DateTimeStyles.None,
                        out dt))
                    cntrl.Value = dt;
                else
                    cntrl.Value = DateTime.MinValue;

                container.GetValue = () =>
                {
                    if (cntrl.GetValue() == DateTime.MinValue)
                        return "";
                    else
                        return cntrl.GetValue().ToString("MM/dd/yyyy");
                };
                controlList.Add(container);
                return cntrl;
            }
            else if (indicator.DataTypeId == (int)IndicatorDataType.Number)
            {
                double d = 0;
                var cntrl = new TextBox { Name = "dynamicNum" + indicator.Id.ToString(), Text = val };
                container.IsValid = () =>
                {
                    if (indicator.IsRequired)
                    {
                        if (cntrl.Text == "" || cntrl.Text == null)
                        {
                            indicatorErrors.SetError(cntrl, Translations.Required);
                            return false;
                        }
                        else if (!Double.TryParse(cntrl.Text, out d))
                        {
                            indicatorErrors.SetError(cntrl, Translations.MustBeNumber);
                            return false;
                        }
                        else
                            indicatorErrors.SetError(cntrl, "");
                    }
                    return true;
                };
                cntrl.Validating += (s, e) => { container.IsValid(); };
                
                container.GetValue = () => { return cntrl.Text; };
                controlList.Add(container);
                return cntrl;
            }
            else if (indicator.DataTypeId == (int)IndicatorDataType.YesNo)
            {
                var cntrl = new CheckBox { Name = "dynamicChk" + indicator.Id.ToString() };
                container.IsValid = () => { return true; };
                bool isChecked = false;
                if (Boolean.TryParse(val, out isChecked))
                    cntrl.Checked = isChecked;

                container.GetValue = () => { return Convert.ToInt32(cntrl.Checked).ToString(); };
                controlList.Add(container);
                return cntrl;
            }
            else
            {
                var cntrl = new TextBox { Name = "dynamicTxt" + indicator.Id.ToString(), Text = val };
                container.IsValid = () => {
                    if (indicator.IsRequired)
                    {
                        if (cntrl.Text == "" || cntrl.Text == null)
                        {
                            indicatorErrors.SetError(cntrl, Translations.Required);
                            return false;
                        }
                        else
                            indicatorErrors.SetError(cntrl, "");
                    }
                    return true;
                };
                cntrl.Validating += (s, e) => { container.IsValid(); };

                container.GetValue = () => { return cntrl.Text; };
                controlList.Add(container);
                return cntrl;
            }
        }
Exemplo n.º 23
0
        public static Control CreateText(Indicator indicator, string val, ErrorProvider indicatorErrors, List<DynamicContainer> controlList, int height, bool isMultiLine)
        {
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new TextBox { Name = "dynamicTxt" + indicator.Id.ToString(), Text = val, Width = 220, Height = height, Multiline = isMultiLine, Margin = new Padding(0, 5, 10, bottomPadding) };

            // Add the Control to the DynamicContainer for reference
            container.Control = cntrl;
            
            container.IsValid = () =>
            {
                if (indicator.IsRequired)
                {
                    if (cntrl.Text == "" || cntrl.Text == null)
                    {
                        indicatorErrors.SetError(cntrl, Translations.Required);
                        return false;
                    }
                    else
                        indicatorErrors.SetError(cntrl, "");
                }
                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };

            container.GetValue = () => { return cntrl.Text; };
            controlList.Add(container);
            return cntrl;
        }
Exemplo n.º 24
0
        public DateHasSameYearRule(Indicator indicator, List<IndicatorValue> values, List<string> indicatorNames)
            : base(indicator, values, indicatorNames)
        {

        }
Exemplo n.º 25
0
 private void AddPartner(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType)
 {
     PartnerList list = new PartnerList();
     list.OnSave += () =>
     {
         AddPartners(cntrl, null);
     };
     list.ShowDialog();
 }
Exemplo n.º 26
0
 void add_OnSave(Indicator obj)
 {
     model.Indicators.Add(obj.DisplayName, obj);
     lvIndicators.SetObjects(model.Indicators.Values.Where(i => i.IsEditable));
 }
Exemplo n.º 27
0
        protected string GetValueAndValidate(Indicator indicator, ref string val, string name)
        {
            double d = 0;
            int i = 0;
            DateTime dt = new DateTime();

            if (indicator.IsRequired && string.IsNullOrEmpty(val))
                return name + ": " + TranslationLookup.GetValue("IsRequired") + Environment.NewLine;

            switch (indicator.DataTypeId)
            {
                case (int)IndicatorDataType.Date:
                    if (string.IsNullOrEmpty(val))
                        return val;
                    else if (val.Length > 0 && !DateTime.TryParse(val, out dt))
                        return name + ": " + TranslationLookup.GetValue("MustBeDate") + Environment.NewLine;
                    else
                        val = dt.ToString("MM/dd/yyyy");
                    break;
                case (int)IndicatorDataType.Number:
                    if (val.Length > 0 && !Double.TryParse(val, out d))
                        return name + ": " + TranslationLookup.GetValue("MustBeNumber") + Environment.NewLine;
                    break;
                case (int)IndicatorDataType.Year:
                    if (val.Length > 0 && (!int.TryParse(val, out i) || (i > 2100 || i < 1900)))
                        return name + ": " + TranslationLookup.GetValue("ValidYear") + Environment.NewLine;
                    break;
                case (int)IndicatorDataType.Integer:
                    if (val.Length > 0 && (!int.TryParse(val, out i)))
                    {
                        if (Double.TryParse(val, out d))
                        {
                            val = Math.Round(d).ToString();
                        }
                        else
                        {
                            return name + ": " + TranslationLookup.GetValue("MustBeWholeNumber") + Environment.NewLine;
                        }
                    }
                    break;
                case (int)IndicatorDataType.YesNo:
                    bool isChecked = false;
                    if (val.ToLower() == "no")
                        val = "false";
                    else if (val.ToLower() == "yes")
                        val = "true";
                    if (val.Length > 0 && !Boolean.TryParse(val, out isChecked))
                        return name + ": " + TranslationLookup.GetValue("MustBeYesNo") + Environment.NewLine;
                    val = isChecked.ToString();
                    break;
                case (int)IndicatorDataType.Multiselect:
                    List<string> translationKeys = new List<string>();
                    foreach (string displayName in val.Replace(Util.EnumerationDelinator, "|").Split('|'))
                    {
                        IndicatorDropdownValue idv = DropDownValues.FirstOrDefault(a => a.IndicatorId == indicator.Id && a.DisplayName == displayName);
                        if (idv != null)
                            translationKeys.Add(idv.TranslationKey);
                        else
                            translationKeys.Add(displayName);
                    }
                    if (!string.IsNullOrEmpty(val) && translationKeys.Count == 0)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = string.Join("|", translationKeys.ToArray());
                    break;
                case (int)IndicatorDataType.DiseaseMultiselect:
                    List<string> translationKeys2 = new List<string>();
                    foreach (string displayName in val.Replace(Util.EnumerationDelinator, "|").Split('|'))
                    {
                        IndicatorDropdownValue idv = DropDownValues.FirstOrDefault(a => a.IndicatorId == indicator.Id && a.DisplayName == displayName);
                        if (idv != null)
                            translationKeys2.Add(idv.TranslationKey);
                        else
                            translationKeys2.Add(displayName);
                    }
                    if (!string.IsNullOrEmpty(val) && translationKeys2.Count == 0)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = string.Join("|", translationKeys2.ToArray());
                    break;
                case (int)IndicatorDataType.Dropdown:
                    string selectedVal = val;
                    IndicatorDropdownValue ival = DropDownValues.FirstOrDefault(a => a.IndicatorId == indicator.Id && a.DisplayName == selectedVal);
                    if (!string.IsNullOrEmpty(val) && ival == null)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = ival == null ? null : ival.TranslationKey;
                    break;
                case (int)IndicatorDataType.Partners:
                    List<string> partnerIds = new List<string>();
                    string p = val.Replace(Util.EnumerationDelinator, "|");
                    string[] ps = p.Split('|');
                    foreach (var partner in partners.Where(v => ps.Contains(v.DisplayName)))
                        partnerIds.Add(partner.Id.ToString());
                    if (!string.IsNullOrEmpty(val) && partnerIds.Count == 0)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = string.Join("|", partnerIds.ToArray());
                    break;
                case (int)IndicatorDataType.Month:
                    string month = val;
                    var monthItem = months.FirstOrDefault(v => v.Name == month);
                    if (!string.IsNullOrEmpty(val) && monthItem == null)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = monthItem == null ? null : monthItem.Id.ToString();
                    break;
                case (int)IndicatorDataType.EvaluationUnit:
                    string euVal = val;
                    var eu = eus.FirstOrDefault(v => v.DisplayName == euVal);
                    if (!string.IsNullOrEmpty(val) && eu == null)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = eu == null ? null : eu.Id.ToString();
                    break;
                case (int)IndicatorDataType.EcologicalZone:
                    var evVal = val;
                    var ez = ezs.FirstOrDefault(v => v.DisplayName == evVal);
                    if (!string.IsNullOrEmpty(val) && ez == null)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = ez == null ? null : ez.Id.ToString();
                    break;
                case (int)IndicatorDataType.EvaluationSite:
                    var esVal = val;
                    var es = ess.FirstOrDefault(v => v.DisplayName == esVal);
                    if (!string.IsNullOrEmpty(val) && es == null)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = es == null ? null : es.Id.ToString();
                    break;
                case (int)IndicatorDataType.EvalSubDistrict:
                    var sdVal = val;
                    var sd = subdistricts.FirstOrDefault(v => v.DisplayName == sdVal);
                    if (!string.IsNullOrEmpty(val) && sd == null)
                        return name + ": " + TranslationLookup.GetValue("ValidDropdown") + Environment.NewLine;
                    val = sd == null ? null : sd.Id.ToString();
                    break;
            }

            // Values are manipulated in the above loop, double check if now they are required because invalid.
            if (indicator.IsRequired && string.IsNullOrEmpty(val))
                return name + ": " + TranslationLookup.GetValue("IsRequired") + Environment.NewLine;

            return "";
        }
Exemplo n.º 28
0
 private void AddSentinelSite(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType)
 {
     SentinelSiteAdd form = new SentinelSiteAdd(options.AdminLevels);
     form.OnSave += (v) =>
     {
         cntrl.Items.Add(v);
     };
     form.ShowDialog();
 }
Exemplo n.º 29
0
        private Control CreateDropdown(Indicator indicator, List<IndicatorDropdownValue> dropdownKeys)
        {
            List<IndicatorDropdownValue> availableValues = new List<IndicatorDropdownValue>();
            var container = new DynamicContainer { Indicator = indicator };
            var cntrl = new ComboBox { Name = "dynamicCombo" + indicator.Id.ToString(), Width = 220, Margin = new Padding(0, 5, 10, 5), DropDownStyle = ComboBoxStyle.DropDownList };
            cntrl.MouseWheel += (s, e) => { ((HandledMouseEventArgs)e).Handled = true; };

            cntrl.Items.Add(new IndicatorDropdownValue { DisplayName = "", Id = -1 });
            foreach (IndicatorDropdownValue v in dropdownKeys)
            {
                cntrl.Items.Add(v);
                availableValues.Add(v);
            }
            cntrl.ValueMember = "WeightedValue";
            cntrl.DisplayMember = "DisplayName";
            if (availableValues.Count > 0)
                cntrl.DropDownWidth = BaseForm.GetDropdownWidth(availableValues.Select(a => a.DisplayName));

            container.IsValid = () =>
            {
                if (cntrl.Text == "" || cntrl.Text == null)
                    return false;

                return true;
            };
            cntrl.Validating += (s, e) => { container.IsValid(); };

            container.GetValue = () =>
            {
                if (cntrl.SelectedItem == null || ((IndicatorDropdownValue)cntrl.SelectedItem).Id == -1)
                    return null;
                return ((IndicatorDropdownValue)cntrl.SelectedItem).WeightedValue.ToString();
            };

            containers.Add(container);
            return cntrl;
        }
Exemplo n.º 30
0
        public DateLaterThanRule(Indicator indicator, List<IndicatorValue> values, List<string> indicatorNames)
            : base(indicator, values, indicatorNames)
        {

        }