Beispiel #1
0
        private static void OtherConfigWatcher_OtherConfigChanged(object sender, EventArgs e)
        {
            List <CustomFieldDefinition> customFieldDefinitions = CustomFieldsManager.GetCustomFields();

            // Add new custom fields
            foreach (CustomFieldDefinition definition in customFieldDefinitions)
            {
                if (!customFields.Exists(delegate(CustomFieldGroupingType customFieldGroupingType)
                {
                    return(customFieldGroupingType.definition.Equals(definition));
                }))
                {
                    customFields.Add(new CustomFieldGroupingType(ObjectTypes.AllExcFolders, definition));
                }
            }

            // Remove old ones
            foreach (CustomFieldGroupingType customFieldGroupingType in customFields.ToArray())
            {
                if (!customFieldDefinitions.Exists(delegate(CustomFieldDefinition definition)
                {
                    return(customFieldGroupingType.definition.Equals(definition));
                }))
                {
                    customFields.Remove(customFieldGroupingType);
                    OnCustomFieldRemoved(customFieldGroupingType);
                }
            }
        }
Beispiel #2
0
 private bool IsDuplicate()
 {
     foreach (CustomFieldDefinition customFieldDefinition in CustomFieldsManager.GetCustomFields(connection))
     {
         if (customFieldDefinition.Name.Trim() == Definition.Name.Trim())
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #3
0
        private void Build()
        {
            lbCustomFields.BeginUpdate();

            try
            {
                lbCustomFields.Items.Clear();

                lbCustomFields.Items.AddRange(CustomFieldsManager.GetCustomFields(connection).ToArray());

                btnDelete.Enabled = false;
            }
            finally
            {
                lbCustomFields.EndUpdate();
            }
        }
Beispiel #4
0
        private static void AddCustomFieldsToRow(IXenObject o, GridRow row)
        {
            foreach (CustomFieldDefinition customFieldDefinition in CustomFieldsManager.GetCustomFields())
            {
                GridStringItem customFieldItem = new GridStringItem(
                    new CustomFieldWrapper(o, customFieldDefinition),
                    HorizontalAlignment.Center, VerticalAlignment.Middle,
                    false, false, TextBrush, Program.DefaultFont,
                    new EventHandler(delegate
                {
                    PropertiesDialog dialog = new PropertiesDialog(o);
                    dialog.SelectPage(dialog.CustomFieldsEditPage);
                    dialog.ShowDialog();
                }));

                row.AddItem(CustomFieldsManager.CUSTOM_FIELD + customFieldDefinition.Name, customFieldItem);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Add and/or remove custom columns to the grid.
        /// </summary>
        private void SetupCustomColumns()
        {
            List <CustomFieldDefinition> customFieldDefinitions = CustomFieldsManager.GetCustomFields();

            // Did the user remove a custom field?
            String[] columns = new String[Columns.Keys.Count];
            Columns.Keys.CopyTo(columns, 0);

            foreach (String column in columns)
            {
                // Skip default columns
                if (IsDefaultColumn(column))
                {
                    continue;
                }

                // Does the custom column in table exist in the custom fields
                // collection?  If not remove.
                if (!customFieldDefinitions.Exists(delegate(CustomFieldDefinition definition)
                {
                    return(definition.Name == column);
                }))
                {
                    RemoveColumn(column);
                }
            }

            // Add any new columns
            foreach (CustomFieldDefinition customFieldDefinition in customFieldDefinitions)
            {
                if (Columns.ContainsKey(customFieldDefinition.Name))
                {
                    continue;
                }

                ShowColumn(CustomFieldsManager.CUSTOM_FIELD + customFieldDefinition.Name);
            }

            BuildList();
        }
Beispiel #6
0
        private void ShowColumns(List <KeyValuePair <String, int> > columns)
        {
            List <String> columnKeys = new List <String>(Columns.Keys);

            if (columns == null)
            {
                // Show all columns
                foreach (String column in columnKeys)
                {
                    ShowColumn(column);
                }

                foreach (CustomFieldDefinition definition in CustomFieldsManager.GetCustomFields())
                {
                    ShowColumn(CustomFieldsManager.CUSTOM_FIELD + definition.Name);
                }

                return;
            }

            // Hide all columns which are currently visible but not in columns
            // (do not hide default columns)
            foreach (String column in columnKeys)
            {
                if (!IsMovableColumn(column))
                {
                    continue;
                }

                if (columns.Exists(delegate(KeyValuePair <String, int> kvp)
                {
                    return(kvp.Key == column);
                }))
                {
                    continue;
                }

                HideColumn(column);
            }

            ShowColumn("ha"); // force decision to show ha

            // Show appropriate columns
            int i = 0;

            foreach (GridHeaderItem item in HeaderRow.Items.Values)
            {
                if (!item.Immovable)
                {
                    break;
                }

                i++;
            }

            foreach (KeyValuePair <String, int> column in columns)
            {
                if (!IsMovableColumn(column.Key))
                {
                    continue;
                }

                String key =
                    (column.Key.StartsWith(CustomFieldsManager.CUSTOM_FIELD) || IsDefaultColumn(column.Key)) ?
                    column.Key : CustomFieldsManager.CUSTOM_FIELD + column.Key;

                ShowColumn(key);

                if (!HeaderRow.Items.ContainsKey(key))
                {
                    continue;
                }

                GridHeaderItem item = HeaderRow.Items[key] as GridHeaderItem;
                if (item == null)
                {
                    continue;
                }

                // Make the column the correct width;
                item.Width = column.Value;

                // Move the column to the correct place;
                GridHeaderRow.Columns.Remove(column.Key);
                GridHeaderRow.Columns.Insert(i, column.Key);
                i++;
            }
        }
Beispiel #7
0
        private void Rebuild(bool revertValues)
        {
            CustomFieldDefinition[] customFieldDefinitions = CustomFieldsManager.GetCustomFields(xenObject.Connection).ToArray();

            tableLayoutPanel.SuspendLayout();

            // Add new custom fields
            foreach (CustomFieldDefinition customFieldDefinition in customFieldDefinitions)
            {
                Object value = CustomFieldsManager.GetCustomFieldValue(xenObject, customFieldDefinition);

                if (!controls.ContainsKey(customFieldDefinition))
                {
                    // Create the display label
                    Label lblKey = new Label();
                    lblKey.Text         = customFieldDefinition.Name.EscapeAmpersands();
                    lblKey.Margin       = new Padding(3, 7, 3, 3);
                    lblKey.Font         = Program.DefaultFont;
                    lblKey.Width        = (int)tableLayoutPanel.ColumnStyles[0].Width;
                    lblKey.AutoEllipsis = true;
                    lblKey.AutoSize     = false;

                    tableLayoutPanel.Controls.Add(lblKey);

                    // Create value field
                    Control control;

                    switch (customFieldDefinition.Type)
                    {
                    case CustomFieldDefinition.Types.String:
                        TextBox textBox = new TextBox();
                        textBox.Text = (String)value;

                        tableLayoutPanel.Controls.Add(textBox);
                        tableLayoutPanel.SetColumnSpan(textBox, 2);
                        textBox.Dock = DockStyle.Fill;
                        control      = textBox;
                        break;

                    case CustomFieldDefinition.Types.Date:
                        DateTimePicker date = new DateTimePicker();
                        date.MinDate      = DateTime.MinValue;
                        date.MaxDate      = DateTime.MaxValue;
                        date.Dock         = DockStyle.Fill;
                        date.MinimumSize  = new Size(0, 24);
                        date.ShowCheckBox = true;
                        date.Format       = DateTimePickerFormat.Long;
                        if (value != null)
                        {
                            date.Value   = (DateTime)value;
                            date.Checked = true;
                        }
                        else
                        {
                            date.Checked = false;
                        }
                        tableLayoutPanel.Controls.Add(date);

                        DateTimePicker time = new DateTimePicker();
                        time.MinDate     = DateTime.MinValue;
                        time.MaxDate     = DateTime.MaxValue;
                        time.Dock        = DockStyle.Fill;
                        time.MinimumSize = new Size(0, 24);
                        time.Format      = DateTimePickerFormat.Time;
                        time.ShowUpDown  = true;
                        if (value != null)
                        {
                            time.Value   = (DateTime)value;
                            time.Enabled = true;
                        }
                        else
                        {
                            time.Enabled = false;
                        }
                        tableLayoutPanel.Controls.Add(time);
                        // Tag so we can remove this control later
                        date.Tag           = time;
                        date.ValueChanged += delegate(Object sender, EventArgs e)
                        {
                            time.Enabled = date.Checked;
                        };

                        control = date;
                        break;

                    default:
                        throw new InvalidEnumArgumentException();
                    }

                    controls[customFieldDefinition] = new KeyValuePair <Label, Control>(lblKey, control);
                }
                else if (revertValues)
                {
                    KeyValuePair <Label, Control> kvp = controls[customFieldDefinition];

                    SetValue(customFieldDefinition, kvp.Value, value);
                }
            }

            // Remove old ones
            CustomFieldDefinition[] definitions = new CustomFieldDefinition[controls.Keys.Count];
            controls.Keys.CopyTo(definitions, 0);

            foreach (CustomFieldDefinition definition in definitions)
            {
                if (Array.IndexOf <CustomFieldDefinition>(customFieldDefinitions, definition) > -1)
                {
                    continue;
                }

                KeyValuePair <Label, Control> kvp = controls[definition];

                tableLayoutPanel.Controls.Remove(kvp.Value);
                tableLayoutPanel.Controls.Remove(kvp.Key);

                DateTimePicker timeControl = kvp.Value.Tag as DateTimePicker;
                if (timeControl != null)
                {
                    tableLayoutPanel.Controls.Remove(timeControl);
                }

                controls.Remove(definition);

                kvp.Key.Dispose();
                kvp.Value.Dispose();
            }

            tableLayoutPanel.ResumeLayout();
        }