Esempio n. 1
0
        protected override ReportLink LoadInternal(ISqlConnectionInfo connection, int id)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT " +
                             ReportLinkTable.GetColumnNames("[rl]") +
                             (this.Depth > 0 ? "," + ReportLinkGroupTable.GetColumnNames("[rl_rlg]") : string.Empty) +
                             " FROM [core].[ReportLink] AS [rl] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLinkGroup] AS [rl_rlg] ON [rl].[ReportLinkGroupID] = [rl_rlg].[ReportLinkGroupID] ";
                }
                sqlCmdText += "WHERE [rl].[ReportLinkID] = @ReportLinkID;";

                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                sqlCmd.Parameters.AddWithValue("@ReportLinkID", id);
                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rl", "loadinternal", "notfound"), "ReportLink could not be loaded by id as it was not found.", sqlCmdText, this, connection, id);
                    if (this.Logger.IsWarnEnabled)
                    {
                        this.Logger.Warn(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ReportLinkTable      rlTable     = new ReportLinkTable(query);
                ReportLinkGroupTable rl_rlgTable = (this.Depth > 0) ? new ReportLinkGroupTable(query) : null;


                ReportLinkGroup rl_rlgObject = (this.Depth > 0) ? rl_rlgTable.CreateInstance() : null;
                ReportLink      rlObject     = rlTable.CreateInstance(rl_rlgObject);
                sqlReader.Close();

                return(rlObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("rl", "loadinternal", "exception"), "ReportLink could not be loaded by id. See exception for details.", sqlCmdText, ex, this, connection, id);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "ReportLink", "Exception while loading ReportLink object from database. See inner exception for details.", ex);
            }
        }
Esempio n. 2
0
 public ReportLink CreateInstance(ReportLinkGroup reportLinkGroup)
 {
     if (!this.HasData)
     {
         return(null);
     }
     return(new ReportLink(this.ReportLinkID, reportLinkGroup ?? new ReportLinkGroup(this.ReportLinkGroupID), this.Url, this.IsActive, this.Updated, this.Created));
 }
Esempio n. 3
0
        public List <ReportLink> Load(ISqlConnectionInfo connection, ReportLinkGroup group)
        {
            SqlQueryParameters parameters = new SqlQueryParameters();

            parameters.Where = "[rl].ReportLinkGroupID=@ReportLinkGroupID";
            parameters.Arguments.Add("ReportLinkGroupID", group.ID);
            return(this.LoadMany(connection, parameters));
        }
Esempio n. 4
0
        public List <ReportLink> Load(IConnectionInfo connection, ReportLinkGroup group)
        {
            ISqlConnectionInfo sqlConnection = connection as ISqlConnectionInfo;

            if (sqlConnection != null)
            {
                return(this.Load(sqlConnection, group));
            }
            using (sqlConnection = new SqlConnectionInfo(connection, this.Type))
                return(this.Load(sqlConnection, group));
        }
Esempio n. 5
0
 public List <ReportLink> Load(ReportLinkGroup group)
 {
     using (SqlConnectionInfo connection = new SqlConnectionInfo(this.Type))
         return(this.Load(connection, group));
 }
Esempio n. 6
0
        public Report Load(ISqlConnectionInfo connection, SqlQueryParameters parameters)
        {
            IDatabase database = connection.Database;

            if (database == null)
            {
                throw new ArgumentNullException("database", "Error initializing database connection.");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            string sqlCmdText = string.Empty;

            try
            {
                sqlCmdText = "SELECT {0} " +
                             ReportTable.GetColumnNames("[r]") +
                             (this.Depth > 0 ? "," + ReportLinkTable.GetColumnNames("[r_rl]") : string.Empty) +
                             (this.Depth > 1 ? "," + ReportLinkGroupTable.GetColumnNames("[r_rl_rlg]") : string.Empty) +
                             " FROM [core].[Report] AS [r] ";
                if (this.Depth > 0)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLink] AS [r_rl] ON [r].[ReportLinkID] = [r_rl].[ReportLinkID] ";
                }
                if (this.Depth > 1)
                {
                    sqlCmdText += "INNER  JOIN [core].[ReportLinkGroup] AS [r_rl_rlg] ON [r_rl].[ReportLinkGroupID] = [r_rl_rlg].[ReportLinkGroupID] ";
                }


                parameters.Top = 1;
                sqlCmdText     = parameters.BuildQuery(sqlCmdText);
                SqlCommand sqlCmd = database.Add(sqlCmdText) as SqlCommand;
                foreach (KeyValuePair <string, object> argument in parameters.Arguments)
                {
                    sqlCmd.Parameters.AddWithValue("@" + argument.Key, argument.Value);
                }

                SqlDataReader sqlReader = database.Add(sqlCmd) as SqlDataReader;

                if (!sqlReader.HasRows || !sqlReader.Read())
                {
                    IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("r", "customload", "notfound"), "Report could not be loaded using custom logic as it was not found.", sqlCmdText, this, connection, parameters);
                    if (this.Logger.IsDebugEnabled)
                    {
                        this.Logger.Debug(builder.ToString());
                    }
                    sqlReader.Close();
                    return(null);
                }

                SqlQuery query = new SqlQuery(sqlReader);

                ReportTable          rTable        = new ReportTable(query);
                ReportLinkTable      r_rlTable     = (this.Depth > 0) ? new ReportLinkTable(query) : null;
                ReportLinkGroupTable r_rl_rlgTable = (this.Depth > 1) ? new ReportLinkGroupTable(query) : null;


                ReportLinkGroup r_rl_rlgObject = (this.Depth > 1) ? r_rl_rlgTable.CreateInstance() : null;
                ReportLink      r_rlObject     = (this.Depth > 0) ? r_rlTable.CreateInstance(r_rl_rlgObject) : null;
                Report          rObject        = rTable.CreateInstance(r_rlObject);
                sqlReader.Close();

                return(rObject);
            }
            catch (Exception ex)
            {
                database.HandleException(ex);
                IMessageBuilder builder = new DbLogMessageBuilder(new LogErrorCode("r", "customload", "exception"), "Report could not be loaded using custom logic. See exception for details.", sqlCmdText, ex, this, connection, parameters);
                if (this.Logger.IsErrorEnabled)
                {
                    this.Logger.Error(builder.ToString(), ex);
                }
                throw new DataOperationException(DataOperation.Load, "Report", "Exception while loading (custom/single) Report object from database. See inner exception for details.", ex);
            }
        }