-
Notifications
You must be signed in to change notification settings - Fork 0
/
Site.Master.cs
69 lines (63 loc) · 2.5 KB
/
Site.Master.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace medium_clone
{
public partial class SiteMaster : MasterPage
{
public DataTable data_table = new DataTable();
public void isLoggedIn()
{
if (Session["isLoggedIn"] != null)
{
Response.Redirect("/");
}
}
public void isRemember()
{
if (Request.Cookies["remember_me"] != null)
{
Session.Add("isLoggedIn", "true");
Response.Redirect("/");
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
isLoggedIn();
isRemember();
}
SqlConnection connect = new SqlConnection(@"Data Source=.\SqlExpress;Initial Catalog=Blog;Integrated Security=True");
connect.Open();
SqlCommand command = new SqlCommand("SELECT Posts.id, Users.id, name, title, content, read_time, avatar, DATENAME(day, created_at) +' '+ DATENAME(month, created_at) AS 'date_name' from Posts, Users WHERE author_id=Users.id", connect);
SqlDataReader read = command.ExecuteReader();
data_table.Columns.Add("id", typeof(int));
data_table.Columns.Add("author_id", typeof(int));
data_table.Columns.Add("author", typeof(string));
data_table.Columns.Add("title", typeof(string));
data_table.Columns.Add("content", typeof(string));
data_table.Columns.Add("read_time", typeof(int));
data_table.Columns.Add("avatar", typeof(string));
data_table.Columns.Add("date_name", typeof(string));
while (read.Read())
{
DataRow data_row = data_table.NewRow();
data_row["id"] = read.GetValue(0);
data_row["author_id"] = read.GetValue(1);
data_row["author"] = read.GetValue(2);
data_row["title"] = read.GetValue(3);
data_row["content"] = read.GetValue(4);
data_row["read_time"] = read.GetValue(5);
data_row["avatar"] = read.GetValue(6);
data_row["date_name"] = read.GetValue(7);
data_table.Rows.Add(data_row);
}
}
}
}