private List <Post> getComments(int postId) { int tempUserID = Int32.Parse(Request.QueryString["userid"]); string tempUserName = Request.QueryString["username"]; int tempAdmin = Int32.Parse(Request.QueryString["admin"]); //Connect to the database and check to see if user already exists, if it does, compare the password string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); string query = "select TOP(20) * from postt p join users u on u.userid = p.puserid where p.puserid = " + tempUserID + " and p.commentid = " + postId.ToString() + ";"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); //Actually execute the query and return the results SqlDataReader reader = cmd.ExecuteReader(); string[] checkarray = new string[23]; List <Post> posts = new List <Post>(); while (reader.Read()) { checkarray[0] = reader[0].ToString(); //postid checkarray[1] = reader[1].ToString(); //ptext checkarray[2] = reader[2].ToString(); //ptimestamp checkarray[3] = reader[3].ToString(); //phascom checkarray[4] = reader[4].ToString(); //commentid checkarray[5] = reader[5].ToString(); //puserid checkarray[6] = reader[6].ToString(); //pgroupid checkarray[7] = reader[7].ToString(); //pcode checkarray[8] = reader[8].ToString(); //ppicfile checkarray[9] = reader[9].ToString(); //userid checkarray[10] = reader[10].ToString(); //username checkarray[11] = reader[11].ToString(); //userrealname checkarray[12] = reader[12].ToString(); //usergitname checkarray[13] = reader[13].ToString(); //useravatar checkarray[14] = reader[14].ToString(); //useremail checkarray[15] = reader[15].ToString(); //userpassword int id = Int32.Parse(checkarray[0]); DateTime time = SqlDateHelper.parseSqlDate(checkarray[2]); bool hasComments = bool.Parse(checkarray[3]); bool isComment = checkarray[4] != null && checkarray[4] != ""; string avatar = checkarray[13]; User user = new User(tempUserName, avatar, tempUserID, tempAdmin); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } reader.Close(); conn.Close(); return(posts); }
private List <Post> getPosts() { //Connect to the database and check to see if user already exists, if it does, compare the password string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); string query = "select TOP(20) * from postt p left join users u on u.userid = p.puserid left join groups g on g.groupid = p.pgroupid left join member m on m.mgroupid = g.groupid where (u.userid = p.puserid or m.muserid =" + Session["UserId"] + ") and commentid is null;"; SqlCommand cmd = new SqlCommand(query, conn); conn.Open(); //Actually execute the query and return the results SqlDataReader reader = cmd.ExecuteReader(); string[] checkarray = new string[22]; List <Post> posts = new List <Post>(); while (reader.Read()) { checkarray[0] = reader[0].ToString(); //postid checkarray[1] = reader[1].ToString(); //ptext checkarray[2] = reader[2].ToString(); //ptimestamp checkarray[3] = reader[3].ToString(); //phascom checkarray[4] = reader[4].ToString(); //commentid checkarray[5] = reader[5].ToString(); //puserid checkarray[6] = reader[6].ToString(); //pgroupid checkarray[7] = reader[7].ToString(); //pcode checkarray[8] = reader[8].ToString(); //ppicfile checkarray[9] = reader[9].ToString(); //userid checkarray[10] = reader[10].ToString(); //username checkarray[11] = reader[11].ToString(); //userrealname checkarray[12] = reader[12].ToString(); //usergitname checkarray[13] = reader[13].ToString(); //useravatar checkarray[14] = reader[14].ToString(); //useremail checkarray[15] = reader[15].ToString(); //userpassword checkarray[16] = reader[16].ToString(); //groupid checkarray[17] = reader[17].ToString(); //groupname checkarray[18] = reader[18].ToString(); //groupavatar checkarray[19] = reader[19].ToString(); //muserid checkarray[20] = reader[20].ToString(); //mgroupid checkarray[21] = reader[21].ToString(); //madmin int id = Int32.Parse(checkarray[0]); DateTime time = SqlDateHelper.parseSqlDate(checkarray[2]); bool hasComments = bool.Parse(checkarray[3]); bool isComment = checkarray[4] != null && checkarray[4] != ""; int admin = 0; if (checkarray[21] == "1") { admin = 1; } //Check to see if the post is group or user post if (checkarray[13] == "") { if (admin == 1) { User user = new User(checkarray[17], checkarray[18], Int32.Parse(checkarray[16]), admin); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } else { User user = new User(checkarray[17], checkarray[18], Int32.Parse(checkarray[16]), admin); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } } else { if (Int32.Parse(checkarray[9]) == Int32.Parse(Session["UserId"].ToString())) { User user = new User(checkarray[10], checkarray[13], Int32.Parse(checkarray[9]), 1); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } else { User user = new User(checkarray[10], checkarray[13], Int32.Parse(checkarray[9]), 0); Control post = addFooter(UserPost.makePost(user, checkarray[1], checkarray[8], checkarray[7], time, isComment), time, id, hasComments, isComment); post.ID = "post" + id; post.ClientIDMode = System.Web.UI.ClientIDMode.Static; // this supposedly makes client ID's the same as ASP ID's posts.Add(new Post(post, time)); } } } reader.Close(); conn.Close(); return(posts); }