コード例 #1
0
ファイル: LicensesDAO.cs プロジェクト: windygu/AW-master
        /// <summary>
        /// Return a table containing all of the license types that have been declared
        /// </summary>
        /// <returns></returns>
        public DataTable EnumerateLicenses(LicenseType aLicenseType)
        {
            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " in");
            }

            DataTable licensesTable = new DataTable(TableNames.LICENSES);

            if (compactDatabaseType)
            {
                try
                {
                    using (SqlCeConnection conn = DatabaseConnection.CreateOpenCEConnection())
                    {
                        string commandText =
                            "SELECT _LICENSEID ,_LICENSETYPEID ,_APPLICATIONID ,_COUNT " +
                            "FROM LICENSES";

                        if (aLicenseType != null)
                        {
                            commandText += " WHERE _LICENSETYPEID = @nLicenseTypeID";
                        }

                        using (SqlCeCommand command = new SqlCeCommand(commandText, conn))
                        {
                            if (aLicenseType != null)
                            {
                                command.Parameters.AddWithValue("@nLicenseTypeID", aLicenseType.LicenseTypeID);
                            }

                            new SqlCeDataAdapter(command).Fill(licensesTable);
                        }
                    }
                }
                catch (SqlCeException ex)
                {
                    Utility.DisplayErrorMessage("A database error has occurred in AuditWizard." + Environment.NewLine + Environment.NewLine +
                                                "Please see the log file for further details.");
                    logger.Error("Exception in " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
                }
                catch (Exception ex)
                {
                    Utility.DisplayErrorMessage("A database error has occurred in AuditWizard." + Environment.NewLine + Environment.NewLine +
                                                "Please see the log file for further details.");

                    logger.Error("Exception in " + System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
                }
            }
            else
            {
                AuditWizardDataAccess lAuditWizardDataAccess = new AuditWizardDataAccess();
                licensesTable = lAuditWizardDataAccess.EnumerateLicenses(aLicenseType);
            }

            if (isDebugEnabled)
            {
                logger.Debug(System.Reflection.MethodBase.GetCurrentMethod().Name + " out");
            }
            return(licensesTable);
        }