/// <summary> /// The user has selected an extractable thing in the catalogue and opted to include it in the extraction /// So we have to convert it to an <see cref="ExtractableColumn"/> (which has configuration specific stuff - and lets /// data analyst override stuff for this extraction only) /// /// <para>Then add it to the right hand list</para> /// </summary> /// <param name="columns"></param> private void Include(params IColumn[] columns) { olvSelected.BeginUpdate(); try { //for each column we are adding foreach (IColumn c in columns) { //make sure it is up to date with database IRevertable r = c as IRevertable; //if the column is out of date if (r != null && r.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent) { r.RevertToDatabaseState();//get a fresh copy } //add to the config ExtractableColumn addMe = _config.AddColumnToExtraction(_dataSet, c); //update on the UI olvSelected.AddObject(addMe); } } finally { olvSelected.EndUpdate(); } RefreshDisabledObjectStatus(); SortSelectedByOrder(); Publish(_config); }
/// <summary> /// The user has selected an extractable thing in the catalogue and opted to include it in the extraction /// So we have to convert it to an ExtractableColumn (which has configuration specific stuff - and lets /// data analyst override stuff for this extraction only) /// /// <para>Then add it to the right hand list</para> /// </summary> /// <param name="item"></param> private ExtractableColumn AddColumnToExtraction(IColumn item) { IRevertable r = item as IRevertable; //if the column is out of date if (r != null && r.HasLocalChanges().Evaluation == ChangeDescription.DatabaseCopyDifferent) { r.RevertToDatabaseState();//get a fresh copy } ExtractableColumn addMe = _config.AddColumnToExtraction(_dataSet, item); olvSelected.AddObject(addMe); RefreshDisabledObjectStatus(); SortSelectedByOrder(); return(addMe); }
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; }
private void btnNo_Click(object sender, EventArgs e) { _revertable.RevertToDatabaseState(); DialogResult = DialogResult.No; this.Close(); }