public void LoadIndicators(Dictionary<string, Indicator> indicators, List<IndicatorValue> values, List<IndicatorDropdownValue> keys, IndicatorEntityType eType) { entityType = eType; dropdownKeys = keys; tblContainer.Visible = false; this.SuspendLayout(); controlList = new List<DynamicContainer>(); LoadCustom(indicators, values); LoadStatic(indicators, values); this.ResumeLayout(); tblContainer.Visible = true; }
public List<IndicatorDropdownValue> GetIndicatorDropdownValues(OleDbConnection connection, OleDbCommand command, IndicatorEntityType type, List<string> ids) { List<IndicatorDropdownValue> values = new List<IndicatorDropdownValue>(); if (ids.Count == 0) return values; command = new OleDbCommand(@"Select ID, IndicatorId, DropdownValue, TranslationKey, SortOrder, EntityType, WeightedValue FROM IndicatorDropdownValues WHERE (EntityType=@EntityType AND IndicatorId in (" + String.Join(", ", ids.ToArray()) + ")) ORDER BY SortOrder", connection); command.Parameters.Add(new OleDbParameter("@EntityType", (int)type)); using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string name = reader.GetValueOrDefault<string>("DropdownValue"); string transKey = reader.GetValueOrDefault<string>("TranslationKey"); if (!string.IsNullOrEmpty(transKey)) name = TranslationLookup.GetValue(transKey); else transKey = name; values.Add(new IndicatorDropdownValue { Id = reader.GetValueOrDefault<int>("ID"), IndicatorId = reader.GetValueOrDefault<int>("IndicatorId"), SortOrder = reader.GetValueOrDefault<int>("SortOrder"), DisplayName = name, TranslationKey = transKey, EntityType = (IndicatorEntityType)reader.GetValueOrDefault<int>("EntityType"), WeightedValue = reader.GetValueOrDefault<int>("WeightedValue"), }); } reader.Close(); } return values; }
public static IndicatorValue Merge(IndicatorValue existingInd, IndicatorValue newInd, List<IndicatorDropdownValue> dropdownOptions, IndicatorEntityType entityType) { newInd.CalcByRedistrict = true; newInd.Indicator = existingInd.Indicator; newInd.IndicatorId = existingInd.IndicatorId; if (existingInd.Indicator.MergeRuleId == (int)MergingRule.CaseFindingStrategy) newInd.DynamicValue = MergeCaseFindingStrategy(existingInd, newInd); else if ((existingInd.Indicator.DataTypeId == (int)IndicatorDataType.Number || existingInd.Indicator.DataTypeId == (int)IndicatorDataType.Year || existingInd.Indicator.DataTypeId == (int)IndicatorDataType.Month || existingInd.Indicator.DataTypeId == (int)IndicatorDataType.Integer) && (existingInd.Indicator.MergeRuleId == (int)MergingRule.Average || existingInd.Indicator.MergeRuleId == (int)MergingRule.Min || existingInd.Indicator.MergeRuleId == (int)MergingRule.Max || existingInd.Indicator.MergeRuleId == (int)MergingRule.Sum)) newInd.DynamicValue = MergeNumber(existingInd, newInd, existingInd.Indicator.MergeRuleId); else if (existingInd.Indicator.DataTypeId == (int)IndicatorDataType.Date && (existingInd.Indicator.MergeRuleId == (int)MergingRule.Min || existingInd.Indicator.MergeRuleId == (int)MergingRule.Max)) newInd.DynamicValue = MergeDate(existingInd, newInd, existingInd.Indicator.MergeRuleId); else if (existingInd.Indicator.MergeRuleId == (int)MergingRule.ListAll) newInd.DynamicValue = Combine(existingInd, newInd); else if (existingInd.Indicator.DataTypeId == (int)IndicatorDataType.Dropdown && (existingInd.Indicator.MergeRuleId == (int)MergingRule.WorstCase || existingInd.Indicator.MergeRuleId == (int)MergingRule.BestCase || existingInd.Indicator.MergeRuleId == (int)MergingRule.Other)) newInd.DynamicValue = MergeDropdown(existingInd, newInd, dropdownOptions, entityType); else //defaultblank/tbd/leaveblank53/leaveblank59 newInd.DynamicValue = ""; return newInd; }
private void MergeIndicators(List<IndicatorValue> existing, Dictionary<int, IndicatorValue> newValues, IndicatorEntityType entityType, List<IndicatorDropdownValue> dropdownOptions) { foreach (var e in existing) { if (!newValues.ContainsKey(e.IndicatorId)) { newValues.Add(e.IndicatorId, e); continue; } newValues[e.IndicatorId] = IndicatorMerger.Merge(e, newValues[e.IndicatorId], dropdownOptions, entityType); } }
private List<IndicatorDropdownValue> GetValues(IndicatorEntityType indType, int indId) { RepositoryBase repo = new RepositoryBase(); OleDbConnection connection = new OleDbConnection(DatabaseData.Instance.AccessConnectionString); using (connection) { connection.Open(); OleDbCommand command = new OleDbCommand(); return repo.GetIndicatorDropdownValues(connection, command, indType, new List<string> { indId.ToString() }); } }
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; }
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; }
private static void AddCustomIndicators(List<Indicator> indicators, OleDbCommand command, IndicatorEntityType entityType) { using (OleDbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { indicators.Add(new Indicator { Id = reader.GetValueOrDefault<int>("ID"), RedistrictRuleId = reader.GetValueOrDefault<int>("RedistrictRuleId"), MergeRuleId = reader.GetValueOrDefault<int>("MergeRuleId"), DisplayName = TranslationLookup.GetValue(reader.GetValueOrDefault<string>("TName"), reader.GetValueOrDefault<string>("TName")) + " > " + reader.GetValueOrDefault<string>("DisplayName"), EntityId = (int)entityType, DataTypeId = reader.GetValueOrDefault<int>("DataTypeId") }); } reader.Close(); } }
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 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; }
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"); }
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; }
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; }
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 static string MergeDropdown(IndicatorValue existingInd, IndicatorValue newInd, List<IndicatorDropdownValue> dropdownOptions, IndicatorEntityType entityType) { if (string.IsNullOrEmpty(existingInd.DynamicValue) && string.IsNullOrEmpty(newInd.DynamicValue)) return ""; if (string.IsNullOrEmpty(newInd.DynamicValue)) return existingInd.DynamicValue; if (string.IsNullOrEmpty(existingInd.DynamicValue)) return newInd.DynamicValue; // Training category other rule if (existingInd.DynamicValue == newInd.DynamicValue) return newInd.DynamicValue; var ind1option = dropdownOptions.FirstOrDefault(i => i.IndicatorId == newInd.IndicatorId && i.EntityType == entityType && i.TranslationKey == newInd.DynamicValue); var ind2option = dropdownOptions.FirstOrDefault(i => i.IndicatorId == existingInd.IndicatorId && i.EntityType == entityType && i.TranslationKey == existingInd.DynamicValue); if (ind1option == null) return existingInd.DynamicValue; if (ind2option == null) return newInd.DynamicValue; if (newInd.Indicator.MergeRuleId == (int)MergingRule.BestCase) { if (ind1option.WeightedValue <= ind2option.WeightedValue) return newInd.DynamicValue; else return existingInd.DynamicValue; } if (newInd.Indicator.MergeRuleId == (int)MergingRule.WorstCase) { if (ind1option.WeightedValue >= ind2option.WeightedValue) return newInd.DynamicValue; else return existingInd.DynamicValue; } return TranslationLookup.GetValue("NA", "NA"); ; }
public void InsertRedistrictForm(OleDbCommand command, OleDbConnection connection, int userId, int redistrictId, int sourceId, int destId, IndicatorEntityType entityType) { command = new OleDbCommand(@"Insert Into RedistrictForms (EntityId, EntityTypeId, RelationshipId, RedistrictEventId) VALUES (@EntityId, @EntityTypeId, @RelationshipId, @RedistrictEventId)", connection); command.Parameters.Add(new OleDbParameter("@EntityId", sourceId)); command.Parameters.Add(new OleDbParameter("@EntityTypeId", (int)entityType)); command.Parameters.Add(new OleDbParameter("@RelationshipId", (int)RedistrictingRelationship.Mother)); command.Parameters.Add(new OleDbParameter("@RedistrictEventId", redistrictId)); command.ExecuteNonQuery(); command = new OleDbCommand(@"Insert Into RedistrictForms (EntityId, EntityTypeId, RelationshipId, RedistrictEventId) VALUES (@EntityId, @EntityTypeId, @RelationshipId, @RedistrictEventId)", connection); command.Parameters.Add(new OleDbParameter("@EntityId", destId)); command.Parameters.Add(new OleDbParameter("@EntityTypeId", (int)entityType)); command.Parameters.Add(new OleDbParameter("@RelationshipId", (int)RedistrictingRelationship.Daughter)); command.Parameters.Add(new OleDbParameter("@RedistrictEventId", redistrictId)); command.ExecuteNonQuery(); }
private void AddPartner(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType) { PartnerList list = new PartnerList(); list.OnSave += () => { AddPartners(cntrl, null); }; list.ShowDialog(); }
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; }
private void AddSentinelSite(ListBox cntrl, Indicator indicator, IndicatorEntityType entityType) { SentinelSiteAdd form = new SentinelSiteAdd(options.AdminLevels); form.OnSave += (v) => { cntrl.Items.Add(v); }; form.ShowDialog(); }
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; }
private void AddInds(DataTable table, List<ReportIndicator> indicators, string formName, IndicatorEntityType type) { foreach (var ind in indicators) { var dr = table.NewRow(); dr["Indicator Id"] = ind.ID; dr["Type Id"] = (int)type; dr["Type Name"] = type.ToString(); dr["Form Name"] = formName; dr["Indicator Name"] = ind.Name; if (table.Columns.Contains("Indicator Type")) dr["Indicator Type"] = ((IndicatorDataType)ind.DataTypeId).ToString(); if (table.Columns.Contains("IsDisabled")) dr["IsDisabled"] = ind.IsDisabled.ToString(); if (table.Columns.Contains("Is Required")) dr["Is Required"] = ind.IsRequired.ToString(); if (table.Columns.Contains("Aggregation Rule")) { dr["Aggregation Rule"] = ((IndicatorAggType)ind.AggregationRuleId).ToString(); dr["Aggregation Rule ID"] = (ind.AggregationRuleId).ToString(); } if (table.Columns.Contains("Merge Rule")) { dr["Merge Rule"] = ((MergingRule)ind.MergeRule).ToString(); dr["Merge Rule ID"] = (ind.MergeRule).ToString(); } if (table.Columns.Contains("Split Rule")) { dr["Split Rule"] = ((RedistrictingRule)ind.SplitRule).ToString(); dr["Split Rule ID"] = (ind.SplitRule).ToString(); } table.Rows.Add(dr); } }
private void AddOptions(DataTable table, IEnumerable<ReportIndicator> indicators, string formName, IndicatorEntityType type) { foreach (var ind in indicators) { foreach (var val in GetValues(type, ind.ID)) { if (ind.ID == 0) continue; var dr = table.NewRow(); dr["Indicator Id"] = ind.ID; dr["Type Id"] = (int)type; dr["Type Name"] = type.ToString(); dr["Form Name"] = formName; dr["Indicator Name"] = ind.Name; dr["Indicator Option ID"] = val.Id; dr["Indicator Option"] = val.DisplayName; dr["Weighted Ranking"] = val.WeightedValue; table.Rows.Add(dr); } } }
public void LoadIndicators(Dictionary<string, Indicator> indicators, List<IndicatorDropdownValue> keys, IndicatorEntityType eType) { LoadIndicators(indicators, new List<IndicatorValue>(), keys, eType); }