예제 #1
0
        private void CreateLine(IArgumentHost parent, IArgument argument, RequiredPropertyInfo required, float maxArgNameWidth)
        {
            Label name = new Label();

            HelpIcon helpIcon = new HelpIcon();

            helpIcon.SetHelpText(GetSystemTypeName(argument.GetSystemType()) ?? "Unrecognised Type:" + argument.Type, required.Demand.Description);
            helpIcon.Dock = DockStyle.Right;

            string spaceSeparatedArgumentName = UsefulStuff.PascalCaseStringToHumanReadable(argument.Name);

            name.Height    = helpIcon.Height;
            name.Text      = spaceSeparatedArgumentName;
            name.TextAlign = ContentAlignment.MiddleLeft;
            name.Dock      = DockStyle.Left;
            name.Width     = (int)maxArgNameWidth + 3 /*padding*/;

            RAGSmiley ragSmiley = new RAGSmiley();

            if (required.Demand.Mandatory && string.IsNullOrWhiteSpace(argument.Value))
            {
                ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
            }

            var args = new ArgumentValueUIArgs();

            args.Parent      = parent;
            args.Type        = argument.GetSystemType();
            args.ContextText = required.Demand.ContextText;

            try
            {
                args.InitialValue = argument.GetValueAsSystemType();
            }
            catch (Exception e)
            {
                //add the text value value and report the error
                if (_valueUisFactory.CanHandleInvalidStringData(args.Type))
                {
                    args.InitialValue = argument.Value;
                }
                else
                {
                    args.InitialValue = null;
                }

                ragSmiley.Fatal(e);
            }


            args.Required            = required;
            args.CatalogueRepository = (ICatalogueRepository)argument.Repository;
            args.Setter = (v) =>
            {
                ragSmiley.Reset();

                try
                {
                    argument.SetValue(v);
                    argument.SaveToDatabase();

                    argument.GetValueAsSystemType();

                    if (required.Demand.Mandatory && (v == null || string.IsNullOrWhiteSpace(v.ToString())))
                    {
                        ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
                    }
                }
                catch (Exception ex)
                {
                    ragSmiley.OnCheckPerformed(new CheckEventArgs("Failed to set property properly", CheckResult.Fail, ex));
                }
            };
            args.Fatal = ragSmiley.Fatal;

            var valueui = (Control)_valueUisFactory.Create(_activator, args);

            valueui.Dock = DockStyle.Fill;

            Panel p = new Panel();

            p.Height = Math.Max(Math.Max(lblClassName.Height, helpIcon.Height), valueui.Height);
            p.Dock   = DockStyle.Top;

            name.Location = new Point(0, 0);
            p.Controls.Add(name);

            helpIcon.Left = name.Right;
            p.Controls.Add(helpIcon);

            ragSmiley.Dock = DockStyle.Right;
            p.Controls.Add(ragSmiley);
            p.Controls.Add(valueui);

            name.Height = p.Height;

            Label hr = new Label();

            hr.AutoSize    = false;
            hr.BorderStyle = BorderStyle.FixedSingle;
            hr.Height      = 1;
            hr.Dock        = DockStyle.Bottom;
            p.Controls.Add(hr);

            valueui.BringToFront();
            pArguments.Controls.Add(p);
        }
예제 #2
0
        private void CreateLine(IArgumentHost parent, IArgument argument, RequiredPropertyInfo required)
        {
            Label name = new Label();

            HelpIcon helpIcon = new HelpIcon();

            helpIcon.SetHelpText(GetSystemTypeName(argument.GetSystemType()) ?? "Unrecognised Type:" + argument.Type, required.Demand.Description);
            helpIcon.Anchor = AnchorStyles.Top | AnchorStyles.Left;

            string spaceSeparatedArgumentName = UsefulStuff.PascalCaseStringToHumanReadable(argument.Name);

            name.Height    = helpIcon.Height;
            name.Text      = spaceSeparatedArgumentName;
            name.TextAlign = ContentAlignment.MiddleLeft;
            name.AutoSize  = true;
            name.Anchor    = AnchorStyles.Top | AnchorStyles.Left;

            RAGSmiley ragSmiley = new RAGSmiley();

            if (required.Demand.Mandatory && string.IsNullOrWhiteSpace(argument.Value))
            {
                ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
            }

            var args = new ArgumentValueUIArgs();

            args.Parent = parent;
            args.Type   = argument.GetSystemType();

            try
            {
                args.InitialValue = argument.GetValueAsSystemType();
            }
            catch (Exception e)
            {
                //add the text value value and report the error
                if (_valueUisFactory.CanHandleInvalidStringData(args.Type))
                {
                    args.InitialValue = argument.Value;
                }
                else
                {
                    args.InitialValue = null;
                }

                ragSmiley.Fatal(e);
            }


            args.Required            = required;
            args.CatalogueRepository = (ICatalogueRepository)argument.Repository;
            args.Setter = (v) =>
            {
                ragSmiley.Reset();

                try
                {
                    argument.SetValue(v);
                    argument.SaveToDatabase();

                    argument.GetValueAsSystemType();

                    if (required.Demand.Mandatory && (v == null || string.IsNullOrWhiteSpace(v.ToString())))
                    {
                        ragSmiley.Fatal(new Exception("Property " + argument.Name + " is Mandatory"));
                    }
                }
                catch (Exception ex)
                {
                    ragSmiley.OnCheckPerformed(new CheckEventArgs("Failed to set property properly", CheckResult.Fail, ex));
                }
            };
            args.Fatal = ragSmiley.Fatal;

            var valueui = (Control)_valueUisFactory.Create(args);

            valueui.Anchor = name.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            _valueUIs.Add(valueui);

            Panel p = new Panel();

            p.Height      = Math.Max(Math.Max(lblClassName.Height, helpIcon.Height), valueui.Height);
            p.Width       = pArguments.ClientRectangle.Width;
            p.Anchor      = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            p.BorderStyle = BorderStyle.FixedSingle;
            p.Location    = new Point(0, _currentY);
            _currentY    += p.Height;

            name.Location = new Point(0, 0);
            p.Controls.Add(name);

            helpIcon.Left = name.Right;
            p.Controls.Add(helpIcon);

            ragSmiley.Left   = p.Width - ragSmiley.Width;
            ragSmiley.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            p.Controls.Add(ragSmiley);

            valueui.Left    = helpIcon.Right;
            valueui.Width   = p.Width - (helpIcon.Right + ragSmiley.Left);
            _maxValueUILeft = Math.Max(_maxValueUILeft, valueui.Left);
            p.Controls.Add(valueui);
            p.MinimumSize = new Size(ragSmiley.Right, p.Height);

            name.Height = p.Height;

            pArguments.Controls.Add(p);
        }