コード例 #1
0
    // Count Group Posts
    public static int Count_Activities(string term, string UserName, int Month, int Year, string order, int records, int datefilter)
    {
        // generate sql query
        string        logic = ActivityBLL.Process_Activity_V3_Logic(term, UserName, Month, Year, datefilter);
        StringBuilder query = new StringBuilder();

        query.Append("Select count(p.activityid) from useractivities as p " + logic);

        return(Convert.ToInt32(SqlHelper.ExecuteScalar(Config.ConnectionString, CommandType.Text, query.ToString(), new SqlParameter("@username", UserName))));
    }
コード例 #2
0
    // The following function load specific number of records without any pagination. e.g Fetching top 8 recently added photos
    // Non Cache Version
    public static List <UserActivity_Struct> Fetch_Activities(string term, string UserName, int Month, int Year, string order, int records, int datefilter, int PageNumber)
    {
        SqlConnection con = new SqlConnection(Config.ConnectionString);

        if (con.State != ConnectionState.Open)
        {
            con.Open();
        }
        List <UserActivity_Struct> _items = new List <UserActivity_Struct>();
        UserActivity_Struct        _item;

        // generate sql query
        string        logic = ActivityBLL.Process_Activity_V3_Logic(term, UserName, Month, Year, datefilter);
        StringBuilder str   = new StringBuilder();
        StringBuilder query = new StringBuilder();

        query.Append("u.picturename,p.activityid,p.username,p.poster_username,p.activity,p.title,p.added_date,p.liked,p.disliked,u.picturename,p.comments FROM useractivities as p Inner join users as u on u.username=p.poster_username " + logic);

        switch (Site_Settings.Pagination_Type)
        {
        case 0:
            // SQL SERVER 2005 or Later Supported Query
            str.Append(Pagination_Process.Prepare_SQLSERVER2005_Pagination(query.ToString(), order, PageNumber, records));
            break;

        case 1:
            // MySQL Supported Query
            string mysql_query = "SELECT " + query.ToString() + " ORDER BY " + order;
            str.Append(Pagination_Process.Prepare_MySQL_Pagination(mysql_query, PageNumber, records));
            break;

        case 2:
            // SQL SERVER 2000 Supported Query
            string normal_query = "SELECT " + query.ToString() + " ORDER BY " + order;
            str.Append(normal_query);
            break;
        }
        // execute sql query
        SqlCommand cmd = new SqlCommand(str.ToString(), con);

        cmd.Parameters.Add(new SqlParameter("@username", UserName));
        SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

        while (reader.Read())
        {
            _item            = new UserActivity_Struct();
            _item.ActivityID = (long)reader["activityid"];

            _item.UserName       = reader["username"].ToString();
            _item.Title          = reader["title"].ToString();
            _item.Activity       = reader["activity"].ToString();
            _item.Added_Date     = (DateTime)reader["added_date"];
            _item.Liked          = Convert.ToInt32(reader["liked"]);
            _item.Disliked       = Convert.ToInt32(reader["disliked"]);
            _item.Comments       = Convert.ToInt32(reader["comments"]);
            _item.PictureName    = reader["picturename"].ToString();
            _item.PosterUserName = reader["poster_username"].ToString();
            _items.Add(_item);
        }
        reader.Close();
        con.Close(); con.Dispose();

        return(_items);
    }