private string Generate_Pagination_Links(int TotalPages) { StringBuilder str = new StringBuilder(); int firstbound = 0; int lastbound = 0; string ToolTip = ""; ArrayList arr = Pagination_Process.Return_Pagination_Link_v2(TotalPages, this.PageNumber); if (arr.Count > 0) { int i = 0; for (i = 0; i <= arr.Count - 1; i++) { firstbound = ((int.Parse(arr[i].ToString()) - 1) * this.PageSize) + 1; lastbound = firstbound + this.PageSize - 1; if (lastbound > this.TotalRecords) { lastbound = this.TotalRecords; } ToolTip = showing + " " + firstbound + " - " + lastbound + " " + records + " " + Resources.vsk.of + " " + this.TotalRecords + " " + records; string _css = ""; if (arr[i].ToString() == this.PageNumber.ToString()) { _css = " class=\"active\""; } str.Append("<li" + _css + "><a id=\"pg_" + arr[i].ToString() + "\" href=\"#\" class=\"pagination-css\" title=\"" + ToolTip + "\">" + arr[i].ToString() + "</a></li>\n"); } } return(str.ToString()); }
public static string Ajax_Pagination_V2(int total_records, int pagesize, int selectedpage) { StringBuilder str = new StringBuilder(); int total_pages = (int)Math.Ceiling((double)total_records / pagesize); if (total_pages <= 1) { return(""); } str.Append("<div class=\"pagination\">\n"); ArrayList arr = Pagination_Process.Return_Pagination_Link(total_pages, 7, selectedpage); int i = 0; string _css = ""; for (i = 0; i <= arr.Count - 1; i++) { if (Convert.ToInt32(arr[i]) == selectedpage) { _css = " class=\"active\""; } else { _css = ""; } str.Append("<li" + _css + "><a href=\"#\" id=\"apg_" + arr[i].ToString() + "\" class=\"apagination-css\">" + arr[i].ToString() + "</a>"); } str.Append("</div>\n"); return(str.ToString()); }
// Pagination Script version 3.0, support VSK 5.3 listing (SQL SERVER 2005, MySQL compatible) // Compatible with both MySQL / SQL SERVER. // Support Advance Pagination public static void Process_Pagination_v3(Repeater _rept, HyperLink _prev, HyperLink _next, int _size, int _pagenumber, int _totalrecords) { // MySQL Compatible int total_pages = (int)Math.Ceiling((double)_totalrecords / _size); if (total_pages > 1) { // Previous Link Scripting if (_pagenumber > 1) { _prev.Visible = true; int firstbound = (((_pagenumber - 1) - 1) * _size) + 1; if (firstbound < 0) { firstbound = 1; } int lastbound = firstbound + _size - 1; _prev.ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + _totalrecords + " records"; } else { _prev.Visible = false; } // Next Link Scripting if (_pagenumber < total_pages) { _next.Visible = true; int firstbound = (((_pagenumber + 1) - 1) * _size) + 1; int lastbound = firstbound + _size - 1; if (lastbound > _totalrecords) { lastbound = _totalrecords; } _next.ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + _totalrecords + " records"; } else { _next.Visible = false; } // main pagination links ArrayList arr = Pagination_Process.Return_Pagination_Link_v2(total_pages, _pagenumber); _rept.Visible = true; _rept.DataSource = arr; _rept.DataBind(); } else { _rept.Visible = false; _next.Visible = false; _prev.Visible = false; } }
// Fetch all video comments public static List <Comment_Struct> Fetch_Comments(long id, int type, int PageNumber, int PageSize) { SqlConnection con = new SqlConnection(Config.ConnectionString); con.Open(); System.Collections.Generic.List <Comment_Struct> items = new System.Collections.Generic.List <Comment_Struct>(); Comment_Struct str_ct = default(Comment_Struct); //// generate query StringBuilder str = new StringBuilder(); StringBuilder query = new StringBuilder(); query.Append("commentid,username,_comment,videoid,added_date,points from comments WHERE VideoID=" + id + " AND type=" + type + " AND isenabled=1 AND isApproved=1"); // implement paging script for differnt data sources. switch (Site_Settings.Pagination_Type) { case 0: // SQL SERVER 2005 or Later Supported Query str.Append(Pagination_Process.Prepare_SQLSERVER2005_Pagination(query.ToString(), "commentid DESC", PageNumber, PageSize)); break; case 1: // MySQL Supported Query string mysql_query = "SELECT " + query.ToString() + " ORDER BY commentid DESC"; str.Append(Pagination_Process.Prepare_MySQL_Pagination(mysql_query, PageNumber, PageSize)); break; case 2: // SQL SERVER 2000 Supported Query string normal_query = "SELECT " + query.ToString() + " ORDER BY commentid DESC"; str.Append(normal_query); break; } SqlCommand cmd = new SqlCommand(str.ToString(), con); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { str_ct = new Comment_Struct(); str_ct.CommentID = (long)reader["CommentID"]; str_ct.UserName = reader["username"].ToString(); str_ct.Added_Date = (DateTime)reader["added_date"]; str_ct.Comment = reader["_comment"].ToString(); str_ct.VideoID = Convert.ToInt64(reader["videoid"]); str_ct.Points = (int)reader["points"]; items.Add(str_ct); } reader.Close(); con.Close(); return(items); }
private void BindList() { int pagesize = Convert.ToInt32(drp_pagesize.SelectedValue); string search = ""; if (txt_search.Text != "") { search = txt_search.Text; } //if (this.TotalRecords == 0) this.TotalRecords = CommentsBLL.Count_Comments(search, this.UserName, drp_type.SelectedValue, Convert.ToInt32(drp_isenable.SelectedValue), Convert.ToInt32(drp_approve.SelectedValue), Convert.ToInt32(drp_filter.SelectedValue)); if (this.TotalRecords == 0) { // no record exist pnl_main.Visible = false; pnl_norecord.Visible = true; lbl_records.InnerHtml = "<h4>0 records found</h4>"; return; } List <Comment_Struct> list = CommentsBLL.Load_Comments(search, this.UserName, drp_type.SelectedValue, Convert.ToInt32(drp_isenable.SelectedValue), Convert.ToInt32(drp_approve.SelectedValue), Convert.ToInt32(drp_filter.SelectedValue), drp_order.SelectedValue, this.PageNumber, pagesize); if (list.Count > 0) { ViewState["script_value"] = ""; //int count = int.Parse(list.Count.ToString()); if (this.TotalRecords > 1) { lbl_records.InnerHtml = "<h4>" + this.TotalRecords + " records found</h4>"; } else { lbl_records.InnerHtml = this.TotalRecords + " record found"; } // setup pagination Pagination_Process.Process_Pagination(MyList, rptPages, lnk_Prev, lnk_Next, pagesize, this.PageNumber, list, this.TotalRecords); pnl_main.Visible = true; pnl_norecord.Visible = false; } else { pnl_main.Visible = false; pnl_norecord.Visible = true; lbl_records.InnerHtml = "<h4>0 records found</h4>"; } }
private void BindList() { DataSet ds = AdsBLL.Load_Ads(int.Parse(drp_sorttype.SelectedValue)); if (ds.Tables[0].Rows.Count > 0) { Pagination_Process.Process_Pagination(MyList, rptPages, lnk_Prev, lnk_Next, 40, this.PageNumber, ds.Tables[0].DefaultView); pnl_main.Visible = true; pnl_norecord.Visible = false; } else { pnl_main.Visible = false; pnl_norecord.Visible = true; } }
private string Generate_Pagination_Links(int TotalPages, string _rooturl) { StringBuilder str = new StringBuilder(); int firstbound = 0; int lastbound = 0; string ToolTip = ""; ArrayList arr = Pagination_Process.Return_Pagination_Link_v2(TotalPages, this.PageNumber); if (arr.Count > 0) { int i = 0; string LinkURL = ""; string Item = ""; for (i = 0; i <= arr.Count - 1; i++) { Item = arr[i].ToString(); firstbound = ((int.Parse(Item) - 1) * this.PageSize) + 1; lastbound = firstbound + this.PageSize - 1; if (lastbound > this.TotalRecords) lastbound = this.TotalRecords; ToolTip = showing + " " + firstbound + " - " + lastbound + " " + records + " " + Resources.vsk.of + " " + this.TotalRecords + " " + records; // url settings // normal search if (Item == "1") { if (this.isFilter) // videos/MostViewed/ThisWeek.aspx LinkURL = Config.GetUrl() + "" + this.Filter_Default_Url; else // videos/MostViewed.aspx LinkURL = Config.GetUrl() + "" + this.Default_Url; } else { if (this.isFilter) // videos/MostViewed/232/ThisWeek.aspx LinkURL = Config.GetUrl() + "" + UtilityBLL.Add_PageNumber(this.Filter_Pagination_Url, Item); else // videos/232/MostViewed.aspx LinkURL = Config.GetUrl() + "" + UtilityBLL.Add_PageNumber(this.Pagination_Url, Item); } string _css = ""; if (arr[i].ToString() == this.PageNumber.ToString()) _css = "class=\"active\""; str.Append("<li " + _css + "><a href=\"" + LinkURL + "\" title=\"" + ToolTip + "\">" + arr[i].ToString() + "</a></li>\n"); } } return str.ToString(); }
//// Load Administrators private void BindList() { DataSet ds = ErrorLgBLL.Load_Log(); if (ds.Tables[0].Rows.Count > 0) { Pagination_Process.Process_Pagination(MyList, rptPages, lnk_Prev, lnk_Next, 20, this.PageNumber, ds.Tables[0].DefaultView); //Process_Pagination(ds); pnl_main.Visible = true; pnl_norecord.Visible = false; } else { pnl_main.Visible = false; pnl_norecord.Visible = true; } }
private void BindList() { string search = "all"; if (txt_search.Text != "") { search = txt_search.Text; } this.TotalRecords = members.Count_Members(search, drp_gender.SelectedValue, "0", drp_countries.SelectedValue, drp_isenabled.SelectedValue, drp_type.SelectedValue, Convert.ToInt32(drp_filter.SelectedValue)); // no record found if (this.TotalRecords == 0) { pnl_main.Visible = false; pnl_norecord.Visible = true; lbl_records.Text = "0 records found"; return; } List <Member_Struct> _lst = members.Load_Members(search, drp_gender.SelectedValue, "0", drp_countries.SelectedValue, drp_isenabled.SelectedValue, drp_type.SelectedValue, Convert.ToInt32(drp_filter.SelectedValue), ViewState["order"].ToString(), ViewState["direction"].ToString(), this.PageNumber, this.PageSize); if (_lst.Count > 0) { if (this.TotalRecords > 0) { lbl_records.Text = _lst.Count + " records found"; } else { lbl_records.Text = _lst.Count + " record found"; } Pagination_Process.Process_Pagination(MyList, rptPages, lnk_Prev, lnk_Next, this.PageSize, this.PageNumber, _lst); pnl_main.Visible = true; pnl_norecord.Visible = false; } else { pnl_main.Visible = false; pnl_norecord.Visible = true; lbl_records.Text = "0 records found"; } }
// Load photos in admin section public static List <Comment_Struct> Load_Comments(string search, string username, string type, int isEnabled, int isApproved, int filteroption, string order, int PageNumber, int PageSize) { SqlConnection con = new SqlConnection(Config.ConnectionString); if (con.State != ConnectionState.Open) { con.Open(); } List <Comment_Struct> _items = new List <Comment_Struct>(); Comment_Struct _item; // Query Building StringBuilder str = new StringBuilder(); StringBuilder query = new StringBuilder(); string logic = CommentsBLL.Return_Comment_Admin_Logic(search, username, type, isEnabled, isApproved, filteroption); query.Append("commentid,videoid,username,_comment,added_date,isenabled,type,points,isapproved,replyid,profileid FROM comments" + logic); // implement paging script for differnt data sources. 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, PageSize)); 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, PageSize)); 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 video_cmd = new SqlCommand(str.ToString(), con); video_cmd.Parameters.Add(new SqlParameter("@search", search)); video_cmd.Parameters.Add(new SqlParameter("@username", username)); video_cmd.Parameters.Add(new SqlParameter("@type", type)); video_cmd.Parameters.Add(new SqlParameter("@isenabled", isEnabled)); video_cmd.Parameters.Add(new SqlParameter("@isapproved", isApproved)); SqlDataReader reader = video_cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { _item = new Comment_Struct(); _item.CommentID = (long)reader["commentid"]; _item.Comment = reader["_comment"].ToString(); _item.UserName = reader["username"].ToString(); _item.VideoID = (long)reader["videoid"]; _item.isEnabled = Convert.ToInt32(reader["isenabled"]); _item.isApproved = Convert.ToInt32(reader["isapproved"]); _item.Type = Convert.ToInt32(reader["type"]); _item.ReplyID = (long)reader["replyid"]; _item.Points = Convert.ToInt32(reader["points"]); _item.Added_Date = (DateTime)reader["added_date"]; _item.ProfileID = reader["profileid"].ToString(); _items.Add(_item); } reader.Close(); con.Close(); con.Dispose(); return(_items); }
// Fetch Comments With User Profile Picture public static List <Comment_Struct> Fetch_Comments_V2(long id, string profileid, int type, int PageNumber, int PageSize, string Order, bool ShowAuthoImage) { SqlConnection con = new SqlConnection(Config.ConnectionString); con.Open(); System.Collections.Generic.List <Comment_Struct> items = new System.Collections.Generic.List <Comment_Struct>(); Comment_Struct str_ct = default(Comment_Struct); //// generate query StringBuilder str = new StringBuilder(); StringBuilder query = new StringBuilder(); //// generate query string _filter = ""; if (profileid != "") { _filter = "c.profileid=@profileid"; //_filter = "c.profileid=" + profileid.Replace("'",""); } else { _filter = "c.videoid=@id"; // _filter = "c.videoid=" + id; } query.Append("c.commentid,c.username,c._comment,c.videoid,c.added_date,c.points,c.replyid"); // remove , if (ShowAuthoImage) { query.Append(",u.picturename"); // remove, } query.Append(" FROM comments c "); // WHERE p.videoid=555 ORDER BY level; if (ShowAuthoImage) { query.Append("inner join users as u on u.username=c.username "); } query.Append(" WHERE " + _filter + " AND c.type=@type AND c.isenabled=1 AND c.isApproved=1"); // implement paging script for differnt data sources. 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, PageSize)); 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, PageSize)); break; case 2: // SQL SERVER 2000 Supported Query string normal_query = "SELECT " + query.ToString() + " ORDER BY " + Order; str.Append(normal_query); break; } SqlParameter profileparam = new SqlParameter("@profileid", profileid); SqlParameter contentidparam = new SqlParameter("@id", id); SqlParameter typeparam = new SqlParameter("@type", type); SqlCommand cmd = new SqlCommand(str.ToString(), con); cmd.Parameters.Add(profileparam); cmd.Parameters.Add(contentidparam); cmd.Parameters.Add(typeparam); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { str_ct = new Comment_Struct(); str_ct.CommentID = (long)reader["CommentID"]; str_ct.UserName = reader["username"].ToString(); str_ct.Added_Date = (DateTime)reader["added_date"]; str_ct.Comment = reader["_comment"].ToString(); str_ct.VideoID = Convert.ToInt64(reader["videoid"]); str_ct.Points = (int)reader["points"]; str_ct.ReplyID = Convert.ToInt64(reader["replyid"]); if (ShowAuthoImage) { str_ct.PictureName = reader["picturename"].ToString(); } items.Add(str_ct); } reader.Close(); con.Close(); return(items); }
// 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); }
// Process Pagination ver 2.0 // Compatible with Hyperlinks // Compatible with both MySQL / SQL SERVER. // Support Advance Pagination public static void Process_Pagination_v2(DataList _list, Repeater _rept, HyperLink _prev, HyperLink _next, int _size, int _pagenumber, IEnumerable _source, int _totalrecords) { if (Site_Settings.Pagination_Type == 1) { // MySQL Compatible int total_pages = (int)Math.Ceiling((double)_totalrecords / _size); if (total_pages > 1) { // Previous Link Scripting if (_pagenumber > 1) { _prev.Visible = true; int firstbound = (((_pagenumber - 1) - 1) * _size) + 1; if (firstbound < 0) { firstbound = 1; } int lastbound = firstbound + _size - 1; _prev.ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + _totalrecords + " records"; } else { _prev.Visible = false; } // Next Link Scripting if (_pagenumber < total_pages) { _next.Visible = true; int firstbound = (((_pagenumber + 1) - 1) * _size) + 1; int lastbound = firstbound + _size - 1; if (lastbound > _totalrecords) { lastbound = _totalrecords; } _next.ToolTip = "Showing " + firstbound + " - " + lastbound + " records of " + _totalrecords + " records"; } else { _next.Visible = false; } // main pagination links ArrayList arr = Pagination_Process.Return_Pagination_Link_v2(total_pages, _pagenumber); _rept.Visible = true; _rept.DataSource = arr; _rept.DataBind(); } else { _rept.Visible = false; _next.Visible = false; _prev.Visible = false; } _list.DataSource = _source; _list.DataBind(); } else { // SQL SERVER Compatible PagedDataSource objPds = new PagedDataSource(); objPds.DataSource = _source; objPds.AllowPaging = true; objPds.PageSize = _size; objPds.CurrentPageIndex = (_pagenumber - 1); if (!objPds.IsFirstPage) { _prev.Visible = true; int firstbound = (((_pagenumber - 1) - 1) * _size) + 1; if (firstbound < 0) { firstbound = 1; } int lastbound = firstbound + _size - 1; _prev.ToolTip = "Showing previous " + firstbound + " - " + lastbound + " records of " + _totalrecords + " records"; } else { _prev.Visible = false; } if (!objPds.IsLastPage) { int firstbound = (((_pagenumber + 1) - 1) * _size) + 1; int lastbound = firstbound + _size - 1; if (lastbound > _totalrecords) { lastbound = _totalrecords; } _next.ToolTip = "Showing next " + firstbound + " - " + lastbound + " records of " + _totalrecords + " records"; _next.Visible = true; } else { _next.Visible = false; } ArrayList arr = Pagination_Process.Return_Pagination_Link_v2(objPds.PageCount, _pagenumber); if (objPds.PageCount > 1) { _rept.Visible = true; _rept.DataSource = arr; _rept.DataBind(); } else { _rept.Visible = false; } _list.DataSource = objPds; _list.DataBind(); } }