Example #1
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;
        }
Example #2
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;
        }
Example #3
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;
        }
Example #4
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;
        }
Example #5
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;
        }
Example #6
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;
        }
Example #7
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;
        }
Example #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;
        }