Ejemplo n.º 1
0
        /// <summary>
        /// Called to delete the selected license type after confirmation
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bnDeleteLicenseType_Click(object sender, EventArgs e)
        {
            // Sanity check - ensure that we have an item selected
            if (lvLicenseTypes.SelectedItems.Count == 0)
            {
                return;
            }

            // Get the database object
            LicensesDAO lwDataAccess = new LicensesDAO();

            // First ensure that we do not have any references to this license type as we
            // cannot delete it if we have
            LicenseType deleteLicenseType = lvLicenseTypes.SelectedItems[0].Tag as LicenseType;
            DataTable   references        = lwDataAccess.EnumerateLicenses(deleteLicenseType);

            if (references.Rows.Count != 0)
            {
                MessageBox.Show("Cannot delete this license type as Licenses exist which refer to it.", "Delete Failed");
                return;
            }

            // No references but we should still confirm the delete
            if (MessageBox.Show("Are you certain that you want to delete this license type?", "Confirm Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                LicenseTypesDAO licensesTypesDAO = new LicenseTypesDAO();
                licensesTypesDAO.LicenseTypeDelete(deleteLicenseType);
            }

            this.RefreshView();
        }
        /// <summary>
        /// Called to show the list of applications for a specific publisher
        /// </summary>
        /// <param name="forPublisher"></param>
        public void ShowPublisher(string forPublisher)
        {
            // JML_LINDE
            if (forPublisher == null)
            {
                return;
            }

            try
            {
                _tabView.SuspendLayout();

                DataRow[] dataRows;
                // 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;

                // If we have not been supplied a publisher to display then flag that we are not displaying
                // a publisher at this time, regardless save the supplied publisher
                if (forPublisher == null)
                {
                    _isPublisherDisplayed = false;

                    // OK there is no explicit publisher but is there a general publisher filter that we
                    // will need to supply to reduce the number of Publishers reported?
                    if (wiController.PublisherFilter != "")
                    {
                        publisherFilter = wiController.PublisherFilter;
                    }
                }

                else
                {
                    _isPublisherDisplayed = true;
                    _currentPublisher     = forPublisher;
                    publisherFilter       = forPublisher;
                }

                // 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(forPublisher, 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  = (forPublisher == null) ? MiscStrings.AllPublishers : forPublisher;
                _tabView.HeaderImage = Properties.Resources.application_publisher_72;

                DataTable applicationInstancesTable = new ApplicationInstanceDAO().GetApplicationInstances(forPublisher);
                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

                    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);
                        }
                    }

                    // ...and add to the tab view
                    _tabView.AddApplication(thisApplication);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error in ShowPublisher()", ex);
            }
            finally
            {
                _tabView.ResumeLayout();
            }
        }
        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);
            }
        }