-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.aspx.cs
More file actions
124 lines (90 loc) · 4.45 KB
/
users.aspx.cs
File metadata and controls
124 lines (90 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class users : System.Web.UI.Page {
public const int RESULTS = 8;
protected void Page_Load(object sender, EventArgs e) {
}
protected void Page_Init(object sender, EventArgs e) {
if (Request.QueryString["mode"] == "browse") {
if (Request.QueryString["q"] != null) Response.Redirect(Request.Url.GetLeftPart(UriPartial.Path) + "?mode=browse&name=" + HttpUtility.UrlEncode(Request.QueryString["q"]));
if (Request.QueryString["name"] == null) Response.Redirect(Request.Url.GetLeftPart(UriPartial.Path));
int temp;
int page = Request.QueryString["page"] == null || !int.TryParse(Request.QueryString["page"], out temp) ? 1 : temp;
if (!this.IsPostBack) {
txtName.Text = Request.QueryString["name"];
resultRepeater.DataSource = global::User.FindUsers(Request.QueryString["name"], (page - 1) * RESULTS, RESULTS);
resultRepeater.DataBind();
}
int count = global::User.FindUsers(Request.QueryString["name"]).Count;
if (count > RESULTS) {
if (page > 1) {
LinkButton first = new LinkButton();
first.CommandName = "first";
first.Command += new CommandEventHandler(page_command);
first.Text = "<<";
first.ID = "firstPage";
LinkButton prev = new LinkButton();
prev.CommandName = "prev";
prev.Command += new CommandEventHandler(page_command);
prev.Text = "<";
prev.ID = "prevPage";
Pages.Controls.Add(first);
Pages.Controls.Add(prev);
}
for (int i = 1; i - 1 <= Math.Ceiling((double)(count - 1) / (double)RESULTS); i++) {
LinkButton pg = new LinkButton();
pg.CommandName = "page";
pg.CommandArgument = i.ToString();
pg.Command += new CommandEventHandler(page_command);
pg.Text = i.ToString();
pg.CssClass = "page";
if (i == page) pg.CssClass += " active";
pg.ID = "page" + i.ToString();
Pages.Controls.Add(pg);
}
if (page - 1 == Math.Ceiling((double)(count - 1) / (double)RESULTS)) {
LinkButton next = new LinkButton();
next.CommandName = "next";
next.Command += new CommandEventHandler(page_command);
next.Text = ">";
next.ID = "nextPage";
LinkButton last = new LinkButton();
last.CommandName = "last";
last.Command += new CommandEventHandler(page_command);
last.Text = ">>";
last.ID = "lastPage";
Pages.Controls.Add(next);
Pages.Controls.Add(last);
}
}
}
}
#region - Interaction -
protected void lnkRegister_Click(object sender, EventArgs e) {
Response.Redirect("register.aspx?type=user");
}
protected void lnkFilter_Click(object sender, EventArgs e) {
if (txtName.Text.Trim() != "") {
Response.Redirect(Request.Url.GetLeftPart(UriPartial.Path) + "?mode=browse&name=" + HttpUtility.UrlEncode(txtName.Text));
}
}
protected void page_command(object sender, CommandEventArgs e) {
int page = 1;
switch (e.CommandName) {
case "first": page = 1; break;
case "prev": page = Convert.ToInt32(Request.QueryString["page"]) - 1; break;
case "page": page = Convert.ToInt32(e.CommandArgument); break;
case "next": page = Convert.ToInt32(Request.QueryString["page"]) + 1; break;
case "last":
int count = global::User.FindUsers(Request.QueryString["name"]).Count;
page = Convert.ToInt32(Math.Ceiling((double)(count - 1) / (double)RESULTS));
break;
}
Response.Redirect(Request.Url.GetLeftPart(UriPartial.Path) + "?mode=browse&name=" + HttpUtility.UrlEncode(Request.QueryString["name"]) + "&page=" + page);
}
#endregion
}