Exemplo n.º 1
0
        /// <summary>
        /// 获取用户网站列表信息
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="pageSize"></param>
        /// <param name="isGetMessages">是否获取消息列表</param>
        /// <param name="isGetServices">是否获取服务列表</param>
        /// <param name="pageNumber"></param>
        /// <returns></returns>
        public override UserWebsiteCollection GetUserWebsites(int userID, int pageSize, int pageNumber, bool isGetMessages, bool isGetServices)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.Pager.TableName   = "Chinaz_UserWebsitesView";
                query.Pager.PageSize    = pageSize;
                query.Pager.PageNumber  = pageNumber;
                query.Pager.PrimaryKey  = "UserWebsiteID";
                query.Pager.SelectCount = true;
                query.Pager.SortField   = "UserWebsiteID";
                query.Pager.IsDesc      = true;

                query.Pager.Condition = "UserID = @UserID";

                query.CreateParameter <int>("@UserID", userID, SqlDbType.Int);

                UserWebsiteCollection result = new UserWebsiteCollection();
                using (XSqlDataReader reader = query.ExecuteReader())
                {
                    result = new UserWebsiteCollection(reader);
                    if (reader.NextResult())
                    {
                        while (reader.Next)
                        {
                            result.TotalRecords = reader.Get <int>(0);
                        }
                    }
                }



                if (isGetMessages || isGetServices)
                {
                    query.CommandText = "";
                    if (isGetMessages)
                    {
                        if (result.Count > 0)
                        {
                            WebsiteService service = null;
                            string         url;
                            foreach (UserWebsite web in result)
                            {
                                for (int i = 0; i < WebsiteServiceList.ServiceList.Count; i++)
                                {
                                    service = WebsiteServiceList.ServiceList[i];
                                    url     = RemoveUrlPrefix(web.Url);
                                    web.Services.Add(service.ID, new WebsiteService(service.ID, service.Content, string.Format(service.Url, url), service.LightImgPath, service.UnLightImgPath, service.IsPreView, service.OnLight));
                                }
                            }
                        }
                    }
                    if (isGetMessages)
                    {
                        query.CommandText += "SELECT *  FROM Chinaz_UserWebsiteMessages WHERE UserWebsiteID IN(@UserWebsiteIDs) Order BY UserWebsiteID;";
                    }

                    if (isGetServices)
                    {
                        query.CommandText += "SELECT *  FROM Chinaz_UserWebsiteServices WHERE UserWebsiteID IN(@UserWebsiteIDs) Order BY UserWebsiteID;";
                    }

                    query.CommandType = CommandType.Text;

                    query.CreateInParameter <int>("@UserWebsiteIDs", result.GetKeys());

                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        UserWebsite site = null;
                        if (isGetMessages)
                        {
                            while (reader.Next)
                            {
                                UserWebsiteMessage message = new UserWebsiteMessage(reader);
                                if (site != null && site.UserWebsiteID == message.UserWebsiteID)
                                {
                                    site.Messages.Add(message);
                                }
                                else
                                {
                                    site = result.GetValue(message.UserWebsiteID);
                                    site.Messages.Add(message);
                                }
                            }
                        }

                        if (isGetServices)
                        {
                            if (isGetMessages == false)
                            {
                                reader.NextResult();
                            }

                            int websiteid, serviceid;
                            while (reader.Next)
                            {
                                serviceid = reader.Get <int>("ServiceID");
                                websiteid = reader.Get <int>("UserWebsiteID");
                                if (site != null && site.UserWebsiteID == websiteid)
                                {
                                    site.Services[serviceid].OnLight = true;
                                }
                                else
                                {
                                    site = result.GetValue(websiteid);
                                    site.Services[serviceid].OnLight = true;
                                }
                            }
                        }
                    }
                }

                return(result);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取用户网站列表信息
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="pageSize"></param>
        /// <param name="isGetMessages">是否获取消息列表</param>
        /// <param name="isGetServices">是否获取服务列表</param>
        /// <param name="pageNumber"></param>
        /// <returns></returns>
        public override UserWebsiteCollection GetUserWebsites(int userID, int pageSize, int pageNumber, bool isGetMessages, bool isGetServices)
        {
            using (SqlQuery query = new SqlQuery())
            {
                query.Pager.TableName = "Chinaz_UserWebsitesView";
                query.Pager.PageSize = pageSize;
                query.Pager.PageNumber = pageNumber;
                query.Pager.PrimaryKey = "UserWebsiteID";
                query.Pager.SelectCount = true;
                query.Pager.SortField = "UserWebsiteID";
                query.Pager.IsDesc = true;

                query.Pager.Condition = "UserID = @UserID";

                query.CreateParameter<int>("@UserID", userID, SqlDbType.Int);

                UserWebsiteCollection result = new UserWebsiteCollection();
                using (XSqlDataReader reader = query.ExecuteReader())
                {  
                    result = new UserWebsiteCollection(reader);
                    if (reader.NextResult())
                    {
                        while (reader.Next)
                            result.TotalRecords = reader.Get<int>(0);
                    }
                }
                


                if (isGetMessages || isGetServices)
                {
                    query.CommandText = "";
                    if (isGetMessages)
                    {
                        if (result.Count > 0)
                        {
                            WebsiteService service = null;
                            string url;
                            foreach (UserWebsite web in result)
                            {
                                for (int i = 0; i < WebsiteServiceList.ServiceList.Count; i++)
                                {
                                    service = WebsiteServiceList.ServiceList[i];
                                    url = RemoveUrlPrefix(web.Url);
                                    web.Services.Add(service.ID, new WebsiteService(service.ID, service.Content, string.Format(service.Url, url), service.LightImgPath, service.UnLightImgPath, service.IsPreView, service.OnLight));
                                }
                            }

                        }
                    }
                    if (isGetMessages)
                    {
                        query.CommandText += "SELECT *  FROM Chinaz_UserWebsiteMessages WHERE UserWebsiteID IN(@UserWebsiteIDs) Order BY UserWebsiteID;";
                    }
                    
                    if(isGetServices)
                    {
                        query.CommandText += "SELECT *  FROM Chinaz_UserWebsiteServices WHERE UserWebsiteID IN(@UserWebsiteIDs) Order BY UserWebsiteID;";
                    }

                    query.CommandType = CommandType.Text;

                    query.CreateInParameter<int>("@UserWebsiteIDs", result.GetKeys());

                    using (XSqlDataReader reader = query.ExecuteReader())
                    {
                        UserWebsite site = null;
                        if (isGetMessages)
                        {
                            while (reader.Next)
                            {
                                UserWebsiteMessage message = new UserWebsiteMessage(reader);
                                if (site != null && site.UserWebsiteID == message.UserWebsiteID)
                                    site.Messages.Add(message);
                                else
                                {
                                    site = result.GetValue(message.UserWebsiteID);
                                    site.Messages.Add(message);
                                }
                            }
                        }

                        if (isGetServices)
                        {
                            if (isGetMessages == false)
                                reader.NextResult();

                            int websiteid, serviceid;
                            while (reader.Next)
                            {
                                serviceid = reader.Get<int>("ServiceID");
                                websiteid = reader.Get<int>("UserWebsiteID");
                                if (site != null && site.UserWebsiteID == websiteid)
                                    site.Services[serviceid].OnLight = true;
                                else
                                {
                                    site = result.GetValue(websiteid);
                                    site.Services[serviceid].OnLight = true;
                                }

                            }
                        }
                    }

                }

                return result;

            }
        }