/// <summary>
        /// Gets all available data values for the specifed USER DATA field.  In this case we need to know
        /// for each asset any value specified for the supplied User Data field.
        /// </summary>
        /// <param name="reportColumn"></param>
        protected void GetUserDataFieldValues(AssetList cachedAssetList, AuditDataReportColumn reportColumn)
        {
            // the user data field name is formatted as User Data | Category | Field
            List <string> fieldParts   = Utility.ListFromString(reportColumn.FieldName, '|', true);
            string        categoryName = fieldParts[1];
            string        fieldName    = fieldParts[2];
            //
            UserDataCategory userDataCategory = _cachedUserDataList.FindCategory(categoryName);

            if (userDataCategory == null)
            {
                return;
            }
            //
            UserDataField userDataField = userDataCategory.FindField(fieldName);

            if (userDataField == null)
            {
                return;
            }

            // Query the database for the possible values for this user defined data field
            userDataField.PopulateValues();

            // ...now loop through the assets and get the fiekld value for each where available
            foreach (Asset asset in cachedAssetList)
            {
                string value = userDataField.GetValueFor(asset.AssetID);
                reportColumn.Values.Add(new AuditDataReportColumnValue(value, asset.Name, asset.AssetID, asset.Location));
            }
        }
示例#2
0
        /// <summary>
        /// Called as we try an exit from this form - we need to ensure that the category name is unique
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bnOK_Click(object sender, EventArgs e)
        {
            // Update the asset type definition with any changes
            _category.Name = tbCategoryName.Text;
            _category.Icon = tbIconFile.Text;

            // Ensure that this Category does not duplicate an existing one
            UserDataCategoryList listCategories = new UserDataCategoryList(_category.Scope);

            listCategories.Populate();
            UserDataCategory existingCategory = listCategories.FindCategory(_category.Name);

            if ((existingCategory != null) && (existingCategory.CategoryID != _category.CategoryID))
            {
                MessageBox.Show("A User Defined Data Category with this name already exists, please enter a unique name for this category", "Category Exists");
                DialogResult = DialogResult.None;
                return;
            }

            if (!_editing)
            {
                _category.TabOrder = new UserDataDefinitionsDAO().GetCountUserDataCategories(UserDataCategory.SCOPE.Asset);
            }

            // ...Update or add the category
            _category.Add();
        }
        /// <summary>
        /// Refresh the list of Asset Types for the currently selected asset type category
        /// </summary>
        /// <param name="category"></param>
        private void RefreshList(UserDataCategory category)
        {
            ulvUserData.BeginUpdate();
            ulvUserData.Items.Clear();

            // Get the small icon which we will display
            Bitmap image = IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Small);

            // Add the items to the list
            foreach (UserDataField field in category)
            {
                // Subitems are type and description
                UltraListViewSubItem[] subItemArray = new UltraListViewSubItem[2];
                subItemArray[0] = new UltraListViewSubItem {
                    Value = field.TypeAsString
                };
                subItemArray[1] = new UltraListViewSubItem {
                    Value = field.Description()
                };
                //
                UltraListViewItem lvi = new UltraListViewItem(field.Name, subItemArray);
                lvi.Tag = field;
                lvi.Appearance.Image = image;
                ulvUserData.Items.Add(lvi);
            }
            ulvUserData.EndUpdate();
        }
示例#4
0
        /// <summary>
        /// this is the main display function called to display expanded information pertaining to the specified
        /// User Defined Data category - we need to display the fields and values within this category
        /// The User Defined Data Category itself is passed as the subObject - we identify the asset as it is the
        /// Tag within the Tree Node passed to us
        /// </summary>
        /// <param name="displayedNode">TreeNode which has been selected - its tag will identify the asset</param>
        /// <param name="subObject">This holds the User Defined Data Category that we are to display details of</param>
        public void Show(UltraTreeNode displayedNode, object subObject)
        {
            _displayedNode     = displayedNode;
            _displayedCategory = subObject as UserDataCategory;

            // Initialize the tab view
            InitializeTabView();

            // ...and add in the child groups and children
            tabView.Display(_displayedNode, _displayedCategory);
        }
示例#5
0
        public FormUserDataField(UserDataCategory category, UserDataField field, bool editing)
        {
            InitializeComponent();
            _category     = category;
            _field        = field;
            _editing      = editing;
            _existingType = field.Type;

            cbInteractiveInclude.Visible = cbMandatory.Visible = (_category.Scope != UserDataCategory.SCOPE.Application);

            InitializeForm();
        }
        private void userDataExplorerBar_ActiveItemChanged(object sender, Infragistics.Win.UltraWinExplorerBar.ItemEventArgs e)
        {
            // Display the sub-items
            _activeItem = e.Item;
            if (e.Item != null)
            {
                UserDataCategory selectedCategory = e.Item.Tag as UserDataCategory;
                RefreshList(selectedCategory);
            }

            bnEditUserCategory.Enabled = true;
        }
        /// <summary>
        /// Called to refresh the information displayed on the users tab
        /// </summary>
        protected void RefreshTab()
        {
            _listCategories.Scope = _currentScope;
            UserDataCategory dummy = new UserDataCategory(_currentScope);

            headerLabel.Text = "User Defined Data [" + dummy.ScopeAsString + "]";

            // Read the user defined data definitions from the database making sure that we set the
            // required scope first
            _listCategories.Populate();

            // Clear the list
            ulvUserData.Items.Clear();

            // Add the categories to the Explorer View
            userDataExplorerBar.BeginUpdate();
            userDataExplorerBar.Groups[0].Items.Clear();
            //
            foreach (UserDataCategory category in _listCategories)
            {
                UltraExplorerBarItem item = userDataExplorerBar.Groups[0].Items.Add(category.Name, category.Name);
                item.Settings.AppearancesLarge.Appearance.Image = IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Medium);
                item.Tag = category;
            }

            // If nothing is selected in the Explorer View then select the first entry if there are any
            if (userDataExplorerBar.Groups[0].Items.Count != 0)
            {
                if (_activeItem == null)
                {
                    userDataExplorerBar.ActiveItem = userDataExplorerBar.Groups[0].Items[0];
                    _activeItem = userDataExplorerBar.Groups[0].Items[0];
                }

                else
                {
                    // Can we find the item
                    int index = userDataExplorerBar.Groups[0].Items.IndexOf(_activeItem.Key);
                    if (index != -1)
                    {
                        userDataExplorerBar.ActiveItem = userDataExplorerBar.Groups[0].Items[index];
                    }
                    else
                    {
                        userDataExplorerBar.ActiveItem = userDataExplorerBar.Groups[0].Items[0];
                        _activeItem = userDataExplorerBar.Groups[0].Items[0];
                    }
                }
            }

            userDataExplorerBar.EndUpdate();
        }
        /// <summary>
        /// Add a new user data category
        /// </summary>
        protected void AddUserDataCategory()
        {
            UserDataCategory newCategory = new UserDataCategory();

            newCategory.Scope = _currentScope;
            newCategory.Name  = "<new category>";
            FormUserDataCategory form = new FormUserDataCategory(newCategory, false);

            if (form.ShowDialog() == DialogResult.OK)
            {
                RefreshTab();
            }
        }
        /// <summary>
        /// Edit the currently selected user data category definition
        /// </summary>
        protected void EditUserDataCategory()
        {
            if (_activeItem != null)
            {
                UserDataCategory userDataCategory = _activeItem.Tag as UserDataCategory;

                FormUserDataCategory form = new FormUserDataCategory(userDataCategory, true);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    RefreshTab();
                }
            }
        }
示例#10
0
        private void UpdateCategoriesTabOrder()
        {
            UserDataDefinitionsDAO lUserDataDefinitionsDao = new UserDataDefinitionsDAO();

            for (int i = 0; i < userDataExplorerBar.Groups[0].Items.Count; i++)
            {
                UserDataCategory userDataCategory = userDataExplorerBar.Groups[0].Items[i].Tag as UserDataCategory;
                if (userDataCategory != null)
                {
                    userDataCategory.TabOrder = i;
                    lUserDataDefinitionsDao.UserDataCategoryUpdate(userDataCategory);
                }
            }
        }
        /// <summary>
        /// Add a user defined data field and its value.
        ///
        /// First locate the specified asset (or create a new one if this does not exist)
        /// Locate the user defined data field (or create a new one if this does not exist)
        /// Set the value for the field given its ID and asset
        ///
        /// </summary>
        /// <param name="lvi"></param>
        private void AddUserDataField(UltraListViewItem lvi)
        {
            AssetDAO lwDataAccess = new AssetDAO();

            // Recover the data fields
            string assetName = lvi.Text;
            string category  = lvi.SubItems[2].Text;

            if (category == "Asset Data")
            {
                category = "General";
            }
            string fieldName  = lvi.SubItems[0].Text;
            string fieldValue = lvi.SubItems[1].Text;

            // Does the Asset exist?
            // Note that as we only have an asset name we can only possibly match on that
            int assetID = lwDataAccess.AssetFind(assetName);

            // If the asset exists then add the history record for it
            if (assetID != 0)
            {
                // Does the User Data Category exist?  If not create it also
                UserDataCategory parentCategory = _listCategories.FindCategory(category);
                if (parentCategory == null)
                {
                    parentCategory      = new UserDataCategory(UserDataCategory.SCOPE.Asset);
                    parentCategory.Name = category;
                    parentCategory.Add();
                    _listCategories.Add(parentCategory);
                }


                // Now look at the User Data Field and see if we have one already with this name
                UserDataField thisField = parentCategory.FindField(fieldName);
                if (thisField == null)
                {
                    // No existing field of this name in the General Category so add it
                    thisField          = new UserDataField();
                    thisField.ParentID = parentCategory.CategoryID;
                    thisField.Name     = fieldName;
                    thisField.Add();
                    parentCategory.Add(thisField);
                }

                // ...and set the value for the asset both here and in the database
                thisField.SetValueFor(assetID, fieldValue, true);
            }
        }
示例#12
0
        public FormUserDataCategory(UserDataCategory category, bool editing)
        {
            InitializeComponent();
            _category = category;
            _editing  = editing;

            SetHeaderText();

            tbCategoryName.Text = category.Name;
            tbAppliesTo.Text    = category.AppliesToName;
            tbIconFile.Text     = category.Icon;

            // If we are NOT scope asset then we disable the 'Applies To' fields
            lblAppliesTo.Enabled = (_category.Scope == UserDataCategory.SCOPE.Asset);
            tbAppliesTo.Enabled  = (_category.Scope == UserDataCategory.SCOPE.Asset);
            bnSelect.Enabled     = (_category.Scope == UserDataCategory.SCOPE.Asset);
        }
示例#13
0
        /// <summary>
        /// Add a new User Data Field
        /// </summary>
        protected void AddUserDataField()
        {
            if (_activeItem != null)
            {
                UserDataCategory userDataCategory = _activeItem.Tag as UserDataCategory;
                UserDataField    field            = new UserDataField();
                field.Name        = "<new field>";
                field.ParentID    = userDataCategory.CategoryID;
                field.ParentScope = userDataCategory.Scope;

                // ...and display a foerm to create this new field
                FormUserDataField form = new FormUserDataField(userDataCategory, field, false);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    RefreshTab();
                }
            }
        }
示例#14
0
        private void HideNotApplicableTabs()
        {
            foreach (UltraTab tab in dataTabControl.Tabs)
            {
                tab.Visible = true;

                UserDataCategory category = (UserDataCategory)tab.Tag;

                if (category == null)
                {
                    continue;
                }

                if (!CategoryAppliesTo(category, _asset))
                {
                    tab.Visible = false;
                }
            }
        }
示例#15
0
        /// <summary>
        /// Delete the selected user data field(s)
        /// </summary>
        protected void DeleteUserDataField()
        {
            if (ulvUserData.SelectedItems.Count == 0)
            {
                return;
            }

            // Confirm the deletion
            if (MessageBox.Show(
                    "Are you sure that you want to delete this User Data Field? " + Environment.NewLine + Environment.NewLine +
                    "Deleting the field will remove the definition and will delete all instances of this field from all assets.",
                    "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) !=
                DialogResult.Yes)
            {
                return;
            }

            // Delete this user data field
            UltraListViewItem lvi   = ulvUserData.SelectedItems[0];
            UserDataField     field = lvi.Tag as UserDataField;

            if (field != null)
            {
                if (!field.Delete())
                {
                    MessageBox.Show("Failed to delete the selected User Data Field", "Delete Failed");
                }
                else
                {
                    if (_activeItem != null)
                    {
                        UserDataCategory userDataCategory = _activeItem.Tag as UserDataCategory;
                        if (userDataCategory != null)
                        {
                            userDataCategory.Remove(field);
                            RefreshList(userDataCategory);
                            UpdateFieldsTabOrder();
                        }
                    }
                }
            }
        }
示例#16
0
        /// <summary>
        /// Delete the currently selected user data category
        /// </summary>
        protected void DeleteUserDataCategory()
        {
            if (_activeItem == null)
            {
                return;
            }

            UserDataCategory userDataCategory = _activeItem.Tag as UserDataCategory;

            if (userDataCategory != null)
            {
                if (userDataCategory.Count == 0)
                {
                    if (MessageBox.Show("Are you sure that you want to delete this User Data Category?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
                    {
                        return;
                    }
                }
                else
                {
                    if (MessageBox.Show("Are you sure that you want to delete this User Data Category?  Deleting the category will also delete all User Data Fields defined within this category.", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
                    {
                        return;
                    }
                }

                // Delete this user data category and any sub-types
                if (!userDataCategory.Delete())
                {
                    MessageBox.Show("Failed to delete the selected category.", "Delete Failed");
                }
                else
                {
                    UpdateCategoriesTabOrder();
                }
            }

            _activeItem = null;

            // We should still refresh as we have partially deleted the category
            RefreshTab();
        }
示例#17
0
        public bool CategoryAppliesTo(UserDataCategory category, Asset asset)
        {
            // Is this category specific to an asset type?
            if (category.AppliesTo != 0)
            {
                // OK - does the category apply specifically to this asset type?
                if (category.AppliesTo != asset.AssetTypeID)
                {
                    // No - we need to get the parent category of this asset type and check that also then
                    AssetType parentType = _listAssetTypes.FindByName(asset.TypeAsString);
                    if ((parentType == null) || (category.AppliesTo != parentType.ParentID))
                    {
                        return(false);
                    }
                }
            }

            // User data category applies to this type of asset so return true
            return(true);
        }
示例#18
0
        /// <summary>
        /// </summary>
        /// <param name="displayedNode">The selected UltraTreeNode for which we shall be displaying details
        /// The Tag property holds the Asset being displayed</param>
        /// <param name="displayedCategory">The uSer Defined Data Category to be displayed</param>
        public void Display(UltraTreeNode displayedNode, UserDataCategory displayedCategory)
        {
            _displayedCategory = displayedCategory;
            HeaderText         = _displayedCategory.Name;

            // Single or ALL assets?
            if (displayedNode.Tag is UserDataCategory)
            {
                DisplayForAsset(displayedNode);
            }

            else
            {
                DisplayForAllAssets(displayedNode);
            }

            UltraGridColumn gridItemColumn = this.auditGridView.DisplayLayout.Bands[0].Columns[0];

            gridItemColumn.Width = 200;
        }
示例#19
0
        /// <summary>
        /// Called to edit the currently selected user data field definition
        /// </summary>
        protected void EditUserDataField()
        {
            if (ulvUserData.SelectedItems.Count == 0)
            {
                return;
            }

            // Get the currently selected user data field
            if (_activeItem != null)
            {
                UserDataCategory  userDataCategory = _activeItem.Tag as UserDataCategory;
                UltraListViewItem lvi   = ulvUserData.SelectedItems[0];
                UserDataField     field = lvi.Tag as UserDataField;

                // ...and display it's properties
                FormUserDataField form = new FormUserDataField(userDataCategory, field, true);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    RefreshTab();
                }
            }
        }
示例#20
0
 public FormUserDataEdit(Asset asset, UserDataCategory category)
 {
     InitializeComponent();
     _asset    = asset;
     _category = category;
 }
示例#21
0
        /// <summary>
        /// Add a new tab to the tab control for the specified category and add controls to the tab
        /// for the fields within the category
        /// </summary>
        /// <param name="category"></param>
        protected void AddCategory(UserDataCategory category)
        {
            // Create the objects required to add a tab
            UltraTab newTab = new UltraTab();

            newTab.Tag = category;
            Infragistics.Win.Appearance newAppearance = new Infragistics.Win.Appearance();

            // Add the new tab to the control
            this.dataTabControl.Tabs.Add(newTab);

            // Set the tab appearance
            newAppearance.Image = IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Small);
            newTab.Appearance   = newAppearance;
            newTab.Text         = category.Name;

            // Create a Table Layout Panel which will fit on the tab
            TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();

            //
            // tableLayoutPanel
            //
            tableLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                             | System.Windows.Forms.AnchorStyles.Left)
                                                                            | System.Windows.Forms.AnchorStyles.Right)));
            //tableLayoutPanel.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            tableLayoutPanel.Location = new System.Drawing.Point(10, 10);
            tableLayoutPanel.Padding  = new System.Windows.Forms.Padding(5);
            tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F));
            tableLayoutPanel.TabIndex = 0;

            // How many rows do we need?  We will try and limit to 12 rows but we may need to increase this depending on
            // how many fields there are.
            if (category.Count > 30)
            {
                tableLayoutPanel.RowCount = (category.Count / 2);
            }
            else
            {
                tableLayoutPanel.RowCount = 12;
            }

            // Either one or two sets of columns
            if (tableLayoutPanel.RowCount <= 12)
            {
                tableLayoutPanel.ColumnCount = 2;
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 70F));
            }
            else
            {
                tableLayoutPanel.ColumnCount = 5;
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 15F));
                tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
            }


            // Add this to the tab
            newTab.TabPage.Controls.Add(tableLayoutPanel);
            Size containerSize = newTab.TabPage.Size;
            Size tableSize     = new Size(containerSize.Width - 20, containerSize.Height - 20);

            tableLayoutPanel.Size = tableSize;


            // Get the list of fields which form this category
            List <Control> listControls = new List <Control>();

            foreach (UserDataField dataField in category)
            {
                Label   label   = null;
                Control control = null;

                switch ((int)dataField.Type)
                {
                //case (int)UserDataField.FieldType.boolean:
                //	CreateBooleanField(dataField, out label, out control);
                //	break;

                //case (int)UserDataField.FieldType.date:
                //	CreateDateField(dataField, out label, out control);
                //	break;

                case (int)UserDataField.FieldType.Number:
                    CreateNumberField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Picklist:
                    CreatePicklistField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Text:
                    CreateTextField(dataField, out label, out control);
                    break;

                default:
                    CreateTextField(dataField, out label, out control);
                    break;
                }

                // Add the controls to the panel
                listControls.Add(label);
                control.Tag = dataField;
                listControls.Add(control);

                // Ensure that the user data field knows about its display control
                dataField.Tag = control;
            }

            // Suspend Layout of the table as we add the rows
            tableLayoutPanel.SuspendLayout();

            // Now add the controls as pairs to the table
            int row    = 0;
            int column = 0;

            for (int isub = 0; isub < listControls.Count; isub += 2)
            {
                // Get the controls
                Label   label   = (Label)listControls[isub];
                Control control = listControls[isub + 1];

                // Ensure that the controls will align at the top, left of their cell
                label.Anchor     = AnchorStyles.Left | AnchorStyles.Top;
                label.Location   = new Point(0, 0);
                control.Anchor   = AnchorStyles.Left | AnchorStyles.Top;
                control.Location = new Point(0, 0);

                // Are we at the end of the rows?  If so reset to row 0 but now start at column 3
                if (row >= tableLayoutPanel.RowCount)
                {
                    row    = 0;
                    column = 3;
                }

                // Add the data to the row
                tableLayoutPanel.Controls.Add(label, column, row);
                tableLayoutPanel.Controls.Add(control, column + 1, row);

                // next row
                row++;
            }

            // Resume and perform the layout
            tableLayoutPanel.ResumeLayout();
            tableLayoutPanel.PerformLayout();
        }
示例#22
0
        /// <summary>
        /// Add a new tab to the tab control for the specified category and add controls to the tab
        /// for the fields within the category
        /// </summary>
        /// <param name="category"></param>
        protected void AddCategory(UserDataCategory category)
        {
            UltraTab selectedTab = dataTabControl.SelectedTab;

            // Create the objects required to add a tab
            UltraTab newTab = new UltraTab();

            newTab.Tag              = category;
            newTab.Key              = "UDD:" + category.Name;
            newTab.Text             = category.Name;
            newTab.ToolTipText      = "Display User Defined Data for " + category.Name;
            newTab.Appearance.Image = IconMapping.LoadIcon(category.Icon, IconMapping.Iconsize.Small);

            // Add the new tab to the control
            dataTabControl.Tabs.Add(newTab);



            if (selectedTab != null)
            {
                foreach (UltraTab tab in dataTabControl.Tabs)
                {
                    if (tab.Key != selectedTab.Key)
                    {
                        continue;
                    }

                    dataTabControl.SelectedTab = tab;
                    break;
                }
            }

            // Create a Table Layout Panel which will fit on the tab
            TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();

            tableLayoutPanel.Anchor   = ((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right;
            tableLayoutPanel.Location = new Point(10, 10);
            tableLayoutPanel.Padding  = new Padding(10);
            tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
            tableLayoutPanel.TabIndex    = 0;
            tableLayoutPanel.RowCount    = 12;
            tableLayoutPanel.ColumnCount = 2;
            tableLayoutPanel.Dock        = DockStyle.Fill;

            GroupBox gb = new GroupBox
            {
                Text     = category.Name,
                Location = new Point(12, 20),
                Size     = new Size(800, 400),
                Padding  = new Padding(15, 15, 15, 15)
            };

            gb.Controls.Add(tableLayoutPanel);
            newTab.TabPage.Controls.Add(gb);

            Size containerSize = newTab.TabPage.Size;
            Size tableSize     = new Size(containerSize.Width - 20, containerSize.Height - 20);

            tableLayoutPanel.Size       = tableSize;
            tableLayoutPanel.AutoScroll = true;

            // Get the list of fields which form this category
            List <Control> listControls = new List <Control>();

            foreach (UserDataField dataField in category)
            {
                Label   label;
                Control control;

                switch ((int)dataField.Type)
                {
                case (int)UserDataField.FieldType.Number:
                    CreateNumberField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Picklist:
                    CreatePicklistField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Date:
                    CreateDateField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Currency:
                    CreateCurrencyField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Registry:
                    CreateEnvironmentOrRegistryField(dataField, out label, out control);
                    break;

                case (int)UserDataField.FieldType.Environment:
                    CreateEnvironmentOrRegistryField(dataField, out label, out control);
                    break;

                default:
                    CreateTextField(dataField, out label, out control);
                    break;
                }

                // Add the controls to the panel
                listControls.Add(label);
                control.Tag = dataField;
                listControls.Add(control);

                // Ensure that the user data field knows about its display control
                dataField.Tag = control;
            }

            // Suspend Layout of the table as we add the rows
            tableLayoutPanel.SuspendLayout();

            // Now add the controls as pairs to the table
            int row    = 0;
            int column = 0;

            for (int isub = 0; isub < listControls.Count; isub += 2)
            {
                // Get the controls
                Label   label   = (Label)listControls[isub];
                Control control = listControls[isub + 1];

                // Ensure that the controls will align at the top, left of their cell
                label.Anchor     = AnchorStyles.Left | AnchorStyles.None;
                label.Location   = new Point(0, 0);
                label.TextAlign  = ContentAlignment.MiddleCenter;
                label.Padding    = new Padding(5);
                control.Anchor   = AnchorStyles.Left | AnchorStyles.None;
                control.Padding  = new Padding(5);
                control.Location = new Point(0, 0);

                // Are we at the end of the rows?  If so reset to row 0 but now start at column 3
                if (row >= tableLayoutPanel.RowCount)
                {
                    row    = 0;
                    column = 3;
                }

                // Add the data to the row
                tableLayoutPanel.Controls.Add(label, column, row);
                tableLayoutPanel.Controls.Add(control, column + 1, row);

                // next row
                row++;
            }

            // Resume and perform the layout
            tableLayoutPanel.ResumeLayout();
            tableLayoutPanel.PerformLayout();
        }
示例#23
0
        /// <summary>
        /// Save the data entered into the underlying UserDataField object
        /// </summary>
        private void SaveData()
        {
            // Have we changed the category?
            UserDataCategory parentCategory = cbCategories.SelectedItem.DataValue as UserDataCategory;

            if (parentCategory == null)
            {
                return;
            }

            _field.ParentID = parentCategory.CategoryID;

            // Update the asset type definition with any changes
            _field.Name = tbFieldName.Text;

            if (!_editing)
            {
                _field.TabOrder = parentCategory.Count;
            }

            // if we are dealing with an asset, set the specific type based on the interactive checkbox
            if (_field.ParentScope != UserDataCategory.SCOPE.Application)
            {
                _field.ParentScope = (!cbInteractiveInclude.Checked) ? UserDataCategory.SCOPE.NonInteractiveAsset : UserDataCategory.SCOPE.Asset;
            }

            _field.IsMandatory = cbMandatory.Checked;
            _field.Type        = (UserDataField.FieldType)cbFieldType.SelectedItem.DataValue;

            // Save the data back to the underlying field definition
            switch ((int)_field.Type)
            {
            // For text fields we need to save the length (as Value1) and the Case (as value2)
            case (int)UserDataField.FieldType.Text:
                _field.InputCase = InputCase.SelectedItem.DataValue.ToString();
                break;

            // Numeric fields save the minimum and maximum values as Value1 and Value2 respectively
            case (int)UserDataField.FieldType.Number:
                break;

            // Picklist - save the name of the picklist as Value1
            case (int)UserDataField.FieldType.Picklist:
                if (Picklist.SelectedItem != null)
                {
                    _field.Picklist = ((PickList)Picklist.SelectedItem.DataValue).Name;
                }
                break;

            // Environment Variable - save the length as Value1 and the name of the variable as Value2
            case (int)UserDataField.FieldType.Environment:
                _field.EnvironmentVariable = tbEnvironmentVariableName.Text;
                break;

            // Registry Key - Save key as Value1 and the value as Value2
            case (int)UserDataField.FieldType.Registry:
                _field.RegistryKey   = tbRegistryKey.Text;
                _field.RegistryValue = tbRegistryValue.Text;
                break;

            // Date - no additional fields required
            case (int)UserDataField.FieldType.Date:
                break;

            // Currency - no additional fields required
            case (int)UserDataField.FieldType.Currency:
                break;

                // No additional values required for boolean
                //case (int)UserDataField.FieldType.boolean:
                //    break;
            }

            // ...and save the field
            _field.Add();
        }