public IndicatorValueItemAdd(IndicatorDropdownValue m, Indicator i) : base() { indicator = i; model = m; InitializeComponent(); }
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)); }
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; } }
public IndicatorAdd(IEnumerable<Indicator> vm, Indicator m) : base() { existingIndicators = vm; model = Util.DeepClone(m); InitializeComponent(); }
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; }
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; }
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; }
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; }
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; }
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; }
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(); }
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; }
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"); }
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; }
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; }
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; }
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; }
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; }
/// <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; } }
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; }
public DateHasSameYearRule(Indicator indicator, List<IndicatorValue> values, List<string> indicatorNames) : base(indicator, values, indicatorNames) { }
private void AddPartner(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType) { PartnerList list = new PartnerList(); list.OnSave += () => { AddPartners(cntrl, null); }; list.ShowDialog(); }
void add_OnSave(Indicator obj) { model.Indicators.Add(obj.DisplayName, obj); lvIndicators.SetObjects(model.Indicators.Values.Where(i => i.IsEditable)); }
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 ""; }
private void AddSentinelSite(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType) { SentinelSiteAdd form = new SentinelSiteAdd(options.AdminLevels); form.OnSave += (v) => { cntrl.Items.Add(v); }; form.ShowDialog(); }
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; }
public DateLaterThanRule(Indicator indicator, List<IndicatorValue> values, List<string> indicatorNames) : base(indicator, values, indicatorNames) { }