コード例 #1
0
        private void PopulatePickerList(List <string> itemParts)
        {
            string category;
            string name;
            string value;

            if (itemParts.Count == 3)
            {
                category = itemParts[0] + "|" + itemParts[1];
                name     = itemParts[2];
            }
            else if (itemParts.Count == 4)
            {
                category = itemParts[0] + "|" + itemParts[1] + "|" + itemParts[2];
                name     = itemParts[3];
            }
            else if (itemParts.Count == 5)
            {
                category = itemParts[0] + "|" + itemParts[1] + "|" + itemParts[2] + "|" + itemParts[3];
                name     = itemParts[4];
            }
            else
            {
                category = itemParts[0];
                name     = itemParts[1];
            }

            cbValuePicker.Items.Clear();
            cbValuePicker.Text = String.Empty;
            cbValuePicker.Refresh();

            DataTable pickerValuesDataTable = new DataTable();

            if (category.StartsWith("UserData|"))
            {
                pickerValuesDataTable = new UserDataDefinitionsDAO().GetUserDataPickerValues(name, category.Split('|')[1]);
            }
            else if (category.StartsWith("Asset Details"))
            {
                string columnName = String.Empty;

                switch (name)
                {
                case "Asset Name":
                    columnName = "_name";
                    break;

                case "Location":
                    columnName = "_locationid";
                    break;

                case "Date of last Audit":
                    columnName = "_lastaudit";
                    break;

                case "IP Address":
                    columnName = "_ipaddress";
                    break;

                case "MAC Address":
                    columnName = "_macaddress";
                    break;

                case "Make":
                    columnName = "_make";
                    break;

                case "Model":
                    columnName = "_model";
                    break;

                case "Serial Number":
                    columnName = "_serial_number";
                    break;

                case "Category":
                    columnName = "_category";
                    break;

                case "Type":
                    columnName = "_type";
                    break;

                case "Asset Tag":
                    columnName = "_assettag";
                    break;
                }

                if (columnName == "_category")
                {
                    pickerValuesDataTable = new AssetTypesDAO().GetAssetCategoriesPickerValues();
                }
                else if (columnName == "_lastaudit")
                {
                    pickerValuesDataTable = new AssetDAO().GetAssetPickerValuesForLastAudit();
                }
                else if (columnName == "_locationid")
                {
                    pickerValuesDataTable = new LocationsDAO().GetLocationPickerValues();
                }
                else if (columnName == "_type")
                {
                    pickerValuesDataTable = new AssetTypesDAO().GetAssetTypesPickerValues();
                }
                else
                {
                    pickerValuesDataTable = new AssetDAO().GetAssetPickerValues(columnName);
                }
            }
            else if (category.StartsWith("Operating Systems"))
            {
                switch (name)
                {
                case "Family":
                    pickerValuesDataTable = new ApplicationsDAO().GetOSPickerValues("_name");
                    break;

                case "Version":
                    pickerValuesDataTable = new ApplicationsDAO().GetOSPickerValues("_version");
                    break;

                case "CD Key":
                    pickerValuesDataTable = new ApplicationInstanceDAO().GetOSPickerValues("_cdkey");
                    break;

                case "Serial Number":
                    pickerValuesDataTable = new ApplicationInstanceDAO().GetOSPickerValues("_productid");
                    break;
                }
            }
            else
            {
                pickerValuesDataTable = lAuditedItemsDAO.GetPickerValue(category, name);
                lblUnits.Text         = lAuditedItemsDAO.GetDisplayUnitValue(category, name);
            }

            foreach (DataRow pickerValueRow in pickerValuesDataTable.Rows)
            {
                value = pickerValueRow.ItemArray[0].ToString();

                if (value != String.Empty)
                {
                    cbValuePicker.Items.Add(value);
                }
            }

            if (cbValuePicker.Items.Count > 0)
            {
                cbValuePicker.SelectedIndex = 0;
            }
        }
コード例 #2
0
        public void ShowPublisher(int aCompliantType)
        {
            try
            {
                // Get the work item controller
                ApplicationsWorkItemController wiController = _tabView.WorkItem.Controller as ApplicationsWorkItemController;

                // ...and from there settings which alter what we display in this view
                bool   showIncluded    = wiController.ShowIncludedApplications;
                bool   showIgnored     = wiController.ShowIgnoredApplications;
                string publisherFilter = wiController.PublisherFilter;

                _isPublisherDisplayed = false;
                _currentPublisher     = null;

                // Initialize the tab view now that we know what we are displaying
                InitializeTabView();

                // Call database function to return list of applications (for the specified publisher)
                ApplicationsDAO lwDataAccess      = new ApplicationsDAO();
                DataTable       applicationsTable = lwDataAccess.GetApplications(publisherFilter, showIncluded, showIgnored);

                // Set the header text and image for the tab view based on whether we are displaying
                // all (possibly filtered) publishers or a sepcific publisher
                _tabView.HeaderText  = "Generating report data, please wait...";
                _tabView.HeaderImage = Properties.Resources.application_publisher_72;

                _tabView.Refresh();

                DataTable applicationInstancesTable = new ApplicationInstanceDAO().GetApplicationInstances();
                DataTable applicationLicensesTable  = new LicensesDAO().GetApplicationLicenses();

                // get a list of aliased applications - will save processing time later
                List <int> aliasedToApplicationsList = new List <int>();

                foreach (DataRow dataRow in lwDataAccess.GetAliasedToApplications().Rows)
                {
                    aliasedToApplicationsList.Add(Convert.ToInt32(dataRow[0]));
                }

                // ...the create InstalledApplication objects for each returned and add to the view
                foreach (DataRow row in applicationsTable.Rows)
                {
                    InstalledApplication thisApplication = new InstalledApplication(row);

                    // Read instances/licenses of this application
                    DataRow[] dataRows = applicationInstancesTable.Select("_APPLICATIONID = " + thisApplication.ApplicationID);
                    thisApplication.LoadInstances1(dataRows);

                    dataRows = applicationLicensesTable.Select("_APPLICATIONID = " + thisApplication.ApplicationID);
                    thisApplication.LoadLicenses1(dataRows);

                    // find any applications which are aliased to this application as we also need their licenses
                    if (aliasedToApplicationsList.Contains(thisApplication.ApplicationID))
                    {
                        foreach (DataRow dataRow in lwDataAccess.GetAliasedApplicationsByApplicationId(thisApplication.ApplicationID).Rows)
                        {
                            dataRows = applicationLicensesTable.Select("_APPLICATIONID = " + dataRow[0]);
                            thisApplication.LoadLicenses1(dataRows);
                        }
                    }

                    //thisApplication.LoadData();

                    if (CheckApplicationState(aCompliantType, thisApplication))
                    {
                        // ...and add to the tab view
                        _tabView.AddApplication(thisApplication);
                    }
                }

                switch (aCompliantType)
                {
                case 1:
                    _tabView.HeaderText = "Compliant Applications";
                    break;

                case 2:
                    _tabView.HeaderText = "Non-compliant Applications";
                    break;

                default:
                    _tabView.HeaderText = "All Applications";
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in ShowPublisher()", ex);
            }
        }
コード例 #3
0
        private void AliasPublisher(List <string> aSourcePublisher, string aTargetPublisher)
        {
            ApplicationsDAO        lApplicationsDAO        = new ApplicationsDAO();
            ApplicationInstanceDAO lApplicationInstanceDAO = new ApplicationInstanceDAO();

            // insert a record into the PUBLISHER_ALIAS table
            foreach (string lSourcePublisher in aSourcePublisher)
            {
                int lPublisherAliasID = new PublisherAliasDAO().Insert(lSourcePublisher, aTargetPublisher);

                // confirm record entered ok?
                if (lPublisherAliasID != -1)
                {
                    DataTable sourcePublisherApplicationsDataTable = lApplicationsDAO.SelectApplicationByPublisherName(lSourcePublisher);

                    foreach (DataRow applicationRow in sourcePublisherApplicationsDataTable.Rows)
                    {
                        // check if the proposed new application already exists
                        // it is possible (but unlikely) that an application name and version combo already exist
                        int    lSourceApplicationId = (int)applicationRow.ItemArray[0];
                        string lApplicationName     = applicationRow.ItemArray[2].ToString();
                        string lApplicationVersion  = applicationRow.ItemArray[3].ToString();

                        int lExisitingApplicationId = lApplicationsDAO.SelectIdByPublisherNameVersion(aTargetPublisher, lApplicationName, lApplicationVersion);

                        if (lExisitingApplicationId > 0)
                        {
                            // found a match
                            // need to get the original applicationid and update all of the application_instances for this application

                            // one final issue is whether the application is aliased
                            // if it is, we need to update the application_instances so that the base applicationid is the original app id
                            // and the _applicationid is the aliased_toid
                            int lBaseApplicationId = 0;
                            int lAliasedToId       = lApplicationsDAO.SelectAliasedToIdByApplicationId(lExisitingApplicationId);

                            if (lAliasedToId != 0)
                            {
                                lBaseApplicationId      = lExisitingApplicationId;
                                lExisitingApplicationId = lAliasedToId;
                            }

                            lApplicationInstanceDAO.UpdateApplicationInstanceByApplicationId(lExisitingApplicationId, lBaseApplicationId, lSourceApplicationId);

                            // final step will be to delete the application we are aliasing. This will mean that if the user tries to revert
                            // this alias they won't be able to do so
                            lApplicationsDAO.DeleteByApplicationId(lSourceApplicationId);
                        }
                        else
                        {
                            // publiser, name, version combo doesn;t already exist so we can just update the publisher name
                            // enter a record into the PUBLISHER_ALIAS_APP table, this will allow us to revert the alias later if needed
                            new PublisherAliasAppDAO().Insert(lSourceApplicationId, lPublisherAliasID);

                            // finally updated the application to reflect the new publisher
                            lApplicationsDAO.UpdateAliasedPublishers(aTargetPublisher, lSourceApplicationId);
                        }
                    }
                }
            }
        }