-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_category.aspx.cs
106 lines (91 loc) · 3.51 KB
/
view_category.aspx.cs
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
using System;
using System.Configuration;
using System.Data;
using System.Web.UI;
using Npgsql;
using NpgsqlTypes;
namespace FooBlog
{
public partial class view_category : Page
{
protected void Page_Load(object sender, EventArgs e)
{
string catId = Request.QueryString["id"];
if (FooStringHelper.IsValidAlphanumeric(catId, 16))
{
Load_Forms(catId);
}
else
{
errorLabel.Text = "Invalid category.";
}
}
protected void Load_Forms(string catId)
{
try
{
using (var conn = new NpgsqlConnection())
{
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString;
conn.Open();
var cmd =
new NpgsqlCommand(
"SELECT catname FROM categories WHERE catid= @CATID ORDER BY catname",
conn);
var catParam = new NpgsqlParameter
{
ParameterName = "@CATID",
NpgsqlDbType = NpgsqlDbType.Varchar,
Size = 32,
Direction = ParameterDirection.Input,
Value = catId
};
cmd.Parameters.Add(catParam);
object catName = cmd.ExecuteScalar();
if (catName != null)
{
catLabel.Text = catName.ToString();
}
}
using (var conn = new NpgsqlConnection())
{
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["fooPostgreSQL"].ConnectionString;
conn.Open();
var cmd =
new NpgsqlCommand(
"SELECT T1.postid, T1.posttime, T1.catid AS queryid, T1.posttitle, T1.postbrief, T2.catid, T2.catname FROM posts AS T1 LEFT OUTER JOIN categories AS T2 ON T1.catid = T2.catid WHERE T2.catid= @CATID AND postenabled= true ORDER BY T1.posttime",
conn);
var catParam = new NpgsqlParameter
{
ParameterName = "@CATID",
NpgsqlDbType = NpgsqlDbType.Varchar,
Size = 32,
Direction = ParameterDirection.Input,
Value = catId
};
cmd.Parameters.Add(catParam);
var da = new NpgsqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
errorLabel.Text = "Empty category.";
}
else
{
postList.DataSource = ds;
postList.DataBind();
errorLabel.Text = "";
}
}
}
catch (Exception ex)
{
FooLogging.WriteLog(ex.ToString());
errorLabel.Text = "Something has gone wrong. A log has been forwarded to the site administrator.";
}
}
}
}