public JsonResult user() { int id = Convert.ToInt32(Session["userid"]); UserHomeMODEL <UserinfoModel> userhomelist = UH_bl.UserHomeList(id); return(Json(userhomelist)); }
/// <summary> /// 用户界面显示 /// </summary> public UserHomeMODEL <UserinfoModel> UserHomeList(int id) { /// <summary> ///用户信息的显示 /// </summary> /// <returns></returns> string str = string.Format(@"SELECT [Userid] ,[Username] ,[Usercheng] FROM [dbo].[UserInfo] WHERE [Userid]='{0}'", id); SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand command = new SqlCommand(str, con); List <UserinfoModel> list = new List <UserinfoModel>(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { UserinfoModel mm = new UserinfoModel(); mm.Userid = Convert.ToInt32(reader["Userid"].ToString()); mm.Username = reader["Username"].ToString(); mm.Usercheng = reader["Usercheng"].ToString(); list.Add(mm); } con.Close(); //用户作品数量 SqlConnection workscountcon = new SqlConnection(conString); string workscountsql = string.Format(@"SELECT COUNT([Worksid]) FROM [Venus].[dbo].[Works] WHERE [Userid]='{0}'", id); SqlCommand workscountcommand = new SqlCommand(workscountsql, workscountcon); workscountcon.Open(); int workscount = Convert.ToInt32(workscountcommand.ExecuteScalar()); workscountcon.Close(); ///用户未审核作品数量 SqlConnection notworkscountcon = new SqlConnection(conString); string notworkscountsql = string.Format(@"SELECT COUNT([Worksid]) FROM [Venus].[dbo].[Works] WHERE [Userid]='{0}' and [Worksstate]=3", id); SqlCommand notworkscountcommand = new SqlCommand(notworkscountsql, notworkscountcon); notworkscountcon.Open(); int notworkscount = Convert.ToInt32(notworkscountcommand.ExecuteScalar()); notworkscountcon.Close(); ///用户已审核作品数量 SqlConnection auditworkscountcon = new SqlConnection(conString); string auditworkscountsql = string.Format(@"SELECT COUNT([Worksid]) FROM [Venus].[dbo].[Works] WHERE [Userid]='{0}' and [Worksstate]=4", id); SqlCommand auditworkscountcommand = new SqlCommand(auditworkscountsql, auditworkscountcon); auditworkscountcon.Open(); int auditworkscount = Convert.ToInt32(auditworkscountcommand.ExecuteScalar()); auditworkscountcon.Close(); ///用户收藏数量 SqlConnection collectcountcon = new SqlConnection(conString); string collectcountsql = string.Format(@"SELECT COUNT([collectid]) FROM [Venus].[dbo].[Collect] WHERE [Userid]='{0}'", id); SqlCommand collectcountcommand = new SqlCommand(collectcountsql, collectcountcon); collectcountcon.Open(); int collectcount = Convert.ToInt32(collectcountcommand.ExecuteScalar()); collectcountcon.Close(); ///用户评论数量 SqlConnection reviewcountcon = new SqlConnection(conString); string reviewcountsql = string.Format(@"SELECT COUNT([Reviewid]) FROM [Venus].[dbo].[Review] WHERE [Userid]='{0}'", id); SqlCommand reviewcountcommand = new SqlCommand(reviewcountsql, reviewcountcon); reviewcountcon.Open(); int reviewcount = Convert.ToInt32(reviewcountcommand.ExecuteScalar()); reviewcountcon.Close(); UserHomeMODEL <UserinfoModel> Userhome = new UserHomeMODEL <UserinfoModel>(); Userhome.datalist = list; Userhome.Workscount = workscount; Userhome.NotWorkscount = notworkscount; Userhome.auditWorkscount = auditworkscount; Userhome.Collectcount = collectcount; Userhome.Reviewcount = reviewcount; return(Userhome); }