コード例 #1
0
        private static Validator CreateInitialisedValidatorWithNoPrimaryConstraint(SecondaryConstraint prediction)
        {
            var i = new ItemValidator();

            i.SecondaryConstraints.Add(prediction);

            var v = new Validator();

            v.AddItemValidator(i, "chi", typeof(string));
            return(v);
        }
コード例 #2
0
ファイル: ValidationSetupUI.cs プロジェクト: rkm/RDMP
        private void AddSecondaryConstraintControl(SecondaryConstraint secondaryConstriant)
        {
            tableLayoutPanel1.RowCount++;

            SecondaryConstraintUI toAdd = new SecondaryConstraintUI(Activator.RepositoryLocator.CatalogueRepository, secondaryConstriant, olvColumns.Objects.Cast <ExtractionInformation>().Select(c => c.GetRuntimeName()).ToArray());

            toAdd.Width            = splitContainer1.Panel2.Width;
            toAdd.Anchor           = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
            toAdd.RequestDeletion += SecondaryConstraintRequestDelete;
            tableLayoutPanel1.Controls.Add(toAdd, tableLayoutPanel1.RowCount - 1, 0);

            //this array always seems to be 1 element long..
            tableLayoutPanel1.RowStyles[0].SizeType = SizeType.AutoSize;
        }
コード例 #3
0
 public void AddSecondaryConstraint(SecondaryConstraint c)
 {
     SecondaryConstraints.Add(c);
 }
コード例 #4
0
ファイル: SecondaryConstraintUI.cs プロジェクト: lulzzz/RDMP
        public SecondaryConstraintUI(ICatalogueRepository repository, SecondaryConstraint secondaryConstriant, string[] otherColumns)
        {
            const int rowHeight = 30;
            //the amount of additional space required to accomodate description labels
            int inflation = 0;

            _repository = repository;
            this.SecondaryConstriant = secondaryConstriant;

            _otherColumns = otherColumns;

            InitializeComponent();

            if (repository == null)
            {
                return;
            }

            cbxConsequence.DataSource   = Enum.GetValues(typeof(Consequence));
            cbxConsequence.SelectedItem = secondaryConstriant.Consequence;

            //put the name of the secondary constraint into the header
            this.lblType.Text = SecondaryConstriant.GetType().Name;

            lblConsequence.Left = lblType.Right + 5;
            cbxConsequence.Left = lblConsequence.Right + 5;

            //work out what properties can be set on this constraint and create the relevant controls using reflection
            _requiredProperties = secondaryConstriant.GetType().GetProperties().Where(p =>
                                                                                      p.CanRead && p.CanWrite && p.GetSetMethod(true).IsPublic

                                                                                      && p.Name != "Name" &&//skip this one, it is Writeable in order to support XMLSerialization...
                                                                                      p.Name != "Consequence" &&//skip this one because it is dealt with explicitly
                                                                                      !p.IsDefined(typeof(HideOnValidationUI), true)
                                                                                      ).ToArray();

            for (int i = 0; i < _requiredProperties.Length; i++)
            {
                var currentRowPanel = new Panel();
                currentRowPanel.Bounds = new Rectangle(0, 0, tableLayoutPanel1.Width, rowHeight);
                currentRowPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                currentRowPanel.Margin = Padding.Empty;

                tableLayoutPanel1.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;

                tableLayoutPanel1.Controls.Add(currentRowPanel, 0, i + 1);


                Label lblName = new Label();
                lblName.Text     = _requiredProperties[i].Name;
                lblName.AutoSize = true;

                object currentValue = _requiredProperties[i].GetValue(SecondaryConstriant, null);


                //Hard Typed properties - Bool
                if (_requiredProperties[i].PropertyType == typeof(bool))
                {
                    CheckBox boolControl = new CheckBox();
                    boolControl.Text    = _requiredProperties[i].Name;
                    boolControl.Tag     = i;
                    boolControl.Checked = (bool)currentValue;

                    boolControl.CheckStateChanged += (s, e) => _requiredProperties[(int)boolControl.Tag].SetValue(SecondaryConstriant, boolControl.Checked, null);
                    currentRowPanel.Controls.Add(boolControl);
                }
                else
                if (_requiredProperties[i].PropertyType == typeof(PredictionRule))    //Hard Typed property PredictionRule
                {
                    //for prediction rules fields
                    ComboBox cbx = new ComboBox();
                    cbx.Items.AddRange(Validator.GetPredictionExtraTypes());
                    cbx.Items.Add("");
                    cbx.DropDownStyle         = ComboBoxStyle.DropDownList;
                    cbx.DisplayMember         = "Name";
                    cbx.Tag                   = i;
                    cbx.SelectedIndexChanged += (s, e) => _requiredProperties[(int)cbx.Tag].SetValue(SecondaryConstriant, cbx.SelectedItem is Type ? Activator.CreateInstance((Type)cbx.SelectedItem) : null);
                    cbx.Width                 = 200;

                    //The dropdown box is a list of Types but we are actually instantiating a value when user selects it (for XML Serialization).  Consequently we must now get the Type for selection purposes
                    if (currentValue != null)
                    {
                        cbx.SelectedItem = currentValue.GetType();
                    }

                    currentRowPanel.Controls.Add(lblName);

                    cbx.Left = lblName.Right + 5;
                    currentRowPanel.Controls.Add(cbx);
                }
                else
                {
                    //it's a value control (basically anything that can be represented by text (i.e. not a boolean))
                    Control valueControl;

                    //if it is expects a column then create a dropdown box
                    if (_requiredProperties[i].IsDefined(typeof(ExpectsColumnNameAsInput), true))
                    {
                        //for column fields
                        ComboBox cbx = new ComboBox();
                        cbx.Items.AddRange(_otherColumns);
                        cbx.Items.Add("");
                        cbx.DropDownStyle         = ComboBoxStyle.DropDownList;
                        cbx.Tag                   = i;
                        cbx.SelectedIndexChanged += (s, e) => _requiredProperties[(int)cbx.Tag].SetValue(SecondaryConstriant, Convert.ChangeType(cbx.SelectedItem, _requiredProperties[(int)cbx.Tag].PropertyType), null);
                        cbx.Width                 = 350;

                        valueControl = cbx;
                    }
                    else
                    if (typeof(IMapsDirectlyToDatabaseTable).IsAssignableFrom(_requiredProperties[i].PropertyType))//it is a Catalogue type
                    {
                        ComboBox dd = new ComboBox();
                        dd.Tag   = i;
                        dd.Width = 350;
                        dd.AutoCompleteSource = AutoCompleteSource.ListItems;
                        dd.AutoCompleteMode   = AutoCompleteMode.Suggest;
                        var entities = _repository.GetAllObjects(_requiredProperties[i].PropertyType).ToArray();

                        if (!entities.Any())
                        {
                            if (_requiredProperties[i].PropertyType == typeof(StandardRegex))
                            {
                                MessageBox.Show("You currently do not have any standard regex concepts in your database.  These can be created from the Table(Advanced) collection.",
                                                "No StandardRegex configured in your Catalogue");
                            }
                            else
                            {
                                MessageBox.Show("You currently do not have any " + _requiredProperties[i].PropertyType + " in your database", "Catalogue Entity Collection Empty");
                            }
                        }
                        else
                        {
                            dd.Items.Add("<<Clear>>");
                            dd.Items.AddRange(entities);
                            dd.SelectedIndexChanged += (s, e) => _requiredProperties[(int)dd.Tag].SetValue(SecondaryConstriant, dd.SelectedItem as IMapsDirectlyToDatabaseTable, null);
                        }

                        //See if it has a value
                        IRevertable v = _requiredProperties[i].GetValue(SecondaryConstriant, null) as IRevertable;

                        //It has a value, this is a dropdown control right here though so if the revertable state out of date then it means someone else made a change to the database while we were picking columns
                        if (v != null)
                        {
                            v.RevertToDatabaseState();
                        }

                        valueControl = dd;
                    }
                    else //otherwise create a textbox
                    {
                        //for string fields
                        valueControl = new TextBox();

                        //if they edit this then write it to the SecondaryConstraint... we can't put i in directly because it goes out of scope so instead we stuff it into Tag and then
                        //get it back at delegate execution time when they change the text.
                        valueControl.Tag          = i;
                        valueControl.TextChanged += setTextOrParseableProperty;

                        if (_requiredProperties[i].IsDefined(typeof(ExpectsLotsOfText), true))
                        {
                            valueControl.Width = 300;
                        }
                    }

                    if (currentValue != null)
                    {
                        valueControl.Text = _requiredProperties[i].GetValue(SecondaryConstriant, null).ToString().Replace("00:00:00", "");
                    }

                    currentRowPanel.Controls.Add(lblName);

                    valueControl.Left = lblName.Right + 5;
                    currentRowPanel.Controls.Add(valueControl);
                }

                var desc = _requiredProperties[i].GetCustomAttribute <DescriptionAttribute>();

                if (desc != null)
                {
                    var lbl = new Label();

                    lbl.AutoSize = true;
                    lbl.Text     = desc.Description;

                    lbl.Font = new Font(lbl.Font, FontStyle.Italic);

                    //make some space for it
                    inflation += lbl.Height - 7;
                    lbl.Top    = rowHeight - 7;

                    currentRowPanel.Controls.Add(lbl);
                    currentRowPanel.Height = rowHeight + lbl.Height;
                }
            }

            //first row
            tableLayoutPanel1.RowStyles[0].SizeType = SizeType.AutoSize;

            Height = (_requiredProperties.Length * rowHeight) + 35 + inflation;

            loadingComplete = true;
        }