public static List<Tag> GetHotTags()
        {
            List<Tag> tagList = new List<Tag>();

            ISingleResult<getAllTagResult> result = dc.getAllTag();
            //for (int i = 1; i <= num; i++)
            foreach (getAllTagResult tagResult in result)
            {
                //getAllTagResult tagResult = new getAllTagResult();
                Tag tag = new Tag();
                tag.name = tagResult.id;
                tag.popularity = tagResult.popularity.Value;
                tagList.Add(tag);
            }

            return tagList;
        }
        //
        public Commodity GetCommodityByID(Guid id)
        {
            Commodity commodity = new Commodity();

            //List<Commodity> commodityList = new List<Commodity>();
            ISingleResult<getCommodityByIDResult> result = dc.getCommodityByID(id);
            foreach (getCommodityByIDResult singleCommodity in result)
            {

                commodity.description = singleCommodity.discription;
                commodity.EndTime = singleCommodity.endtime.Value;
                commodity.ID = singleCommodity.id;
                commodity.ImageUrl = singleCommodity.picturepath;
                commodity.kind = (CommodityKind)(singleCommodity.kind.Value);

                commodity.Name = singleCommodity.name;
                commodity.popularity = (int)singleCommodity.popularity;
                commodity.Price = singleCommodity.price.Value;
                commodity.StartTime = singleCommodity.starttime.Value;

                List<Tag> TagList = new List<Tag>();
                try
                {
                    ISingleResult<getTagByCommodityResult> TagResult = dc.getTagByCommodity(singleCommodity.id);

                    foreach (getTagByCommodityResult Newtag in TagResult)
                    {
                        Tag tag = new Tag();
                        tag.name = Newtag.id;
                        tag.popularity = Newtag.popularity.Value;
                        TagList.Add(tag);
                    }
                    commodity.tagList = TagList;
                }
                catch (Exception e)
                {
                    commodity = new Commodity();
                    commodity.Name = "";
                }

                commodity.UserName = singleCommodity.userfrom;
                //commodityList.Add(commodity);
            }
            return commodity;
        }
        //获得用户发布的商品列表24 OK
        public List<Commodity> GetUserPublishCommoditys(String UserName)
        {
            List<Commodity> commodityList = new List<Commodity>();
            //数据访存器
            DatabaseAccess.DataClasses1DataContext DBAccessor = new DataClasses1DataContext();

            try
            {
                ISingleResult<getCommodityByUserResult> resultList = DBAccessor.getCommodityByUser(UserName);

                foreach (getCommodityByUserResult result in resultList)
                {
                    Commodity commodity = new Commodity();

                    commodity.ID = result.id;
                    commodity.Name = result.name;
                    commodity.UserName = result.userfrom;
                    commodity.StartTime = (DateTime)result.starttime;   //等亮亮的返回参数
                    commodity.EndTime = (DateTime)result.endtime;
                    commodity.description = result.discription;
                    commodity.kind = (CommodityKind)((int)result.kind);
                    commodity.ImageUrl = result.picturepath;
                    commodity.Price = (double)result.price;
                    commodity.popularity = (int)result.popularity;
                    commodity.tagList = new List<Tag>();

                    //查找属于商品的Tag列表
                    ISingleResult<getTagByCommodityResult> TagList = DBAccessor.getTagByCommodity(result.id);
                    foreach (getTagByCommodityResult atag in TagList)
                    {
                        Tag tag = new Tag();
                        tag.name = atag.id;//id就是tag名数据库中做主码
                        tag.popularity = (int)atag.popularity;

                        commodity.tagList.Add(tag); //加入tag列表
                    }

                    commodityList.Add(commodity);   //加入商品列表
                }
            }
            catch (Exception e)
            {

            }

            return commodityList;
        }
        //获得用户的收藏19 ok
        public List<Commodity> GetUserCollectItems(String UserName)
        {
            List<Commodity> CommodityiList = new List<Commodity>();
            //数据访存器
            DatabaseAccess.DataClasses1DataContext DBAccessor = new DataClasses1DataContext();

            try
            {
                ISingleResult<getCollectByUserResult> resultList = DBAccessor.getCollectByUser(UserName);

                foreach (getCollectByUserResult result in resultList)
                {
                    Commodity commodity = new Commodity();
                    commodity.ID = result.id;
                    commodity.Name = result.name;
                    commodity.UserName = result.userfrom;
                    commodity.description = result.discription;
                    commodity.StartTime = (DateTime)result.starttime;
                    commodity.EndTime = (DateTime)result.endtime;
                    commodity.kind = (CommodityKind)(int)result.kind;
                    commodity.Price = (double)result.price;
                    commodity.ImageUrl = result.picturepath;
                    commodity.popularity = (int)result.popularity;
                    commodity.tagList = new List<Tag>();
                    //下面获得商品的Tag列表
                    ISingleResult<getTagByCommodityResult> TagResultList = DBAccessor.getTagByCommodity(result.id);

                    foreach (getTagByCommodityResult Tagresult in TagResultList)
                    {
                        Tag tag = new Tag();
                        tag.name = Tagresult.id;
                        tag.popularity = (int)Tagresult.popularity;
                        commodity.tagList.Add(tag);
                    }
                    CommodityiList.Add(commodity);
                }
            }
            catch(Exception e)
            {

            }

            return CommodityiList;
        }
        //获得发向用户的订单8 ok
        public List<Order> GetOreders(String UserID)
        {
            List<Order> OrderList = new List<Order>();
            //数据访存器
            DatabaseAccess.DataClasses1DataContext DBAccessor = new DataClasses1DataContext();

            try
            {
                ISingleResult<getOrderByUsertoResult> resultList = DBAccessor.getOrderByUserto(UserID);
                foreach (getOrderByUsertoResult result in resultList)
                {
                    Order order = new Order();
                    order.ID = result.id;
                    order.userTo.UserName = result.userto;

                    //下面获得发订单的用户
                    order.userFrom.UserName = result.userfrom;
                    //发订单用户的信息
                    ISingleResult<getUserByUserNameResult> UserInfoList = DBAccessor.getUserByUserName(result.userfrom);
                    foreach (getUserByUserNameResult UserInfo in UserInfoList)
                    {
                        order.userFrom.NickName = UserInfo.nickname;
                        order.userFrom.Phone = UserInfo.phone;
                        order.userFrom.Address = UserInfo.address;
                        order.userFrom.Email = UserInfo.email;
                        order.userFrom.City = UserInfo.city;
                        order.userFrom.Portrait = UserInfo.portraitPath;
                    }

                    //查找次订单所对应的所有商品
                    ISingleResult<getCommodityByOrederResult> commmodityListresult = DBAccessor.getCommodityByOreder(result.id);
                    //获得订单所对应的商品列表
                    foreach (getCommodityByOrederResult commmodityResult in commmodityListresult)
                    {
                        Commodity commodity = new Commodity();
                        commodity.ID = commmodityResult.id;
                        commodity.Name = commmodityResult.name;
                        commodity.UserName = commmodityResult.userfrom;
                        commodity.kind = (CommodityKind)(int)commodity.kind;
                        commodity.StartTime = (DateTime)commmodityResult.starttime;
                        commodity.EndTime = (DateTime)commmodityResult.endtime;
                        commodity.description = commmodityResult.discription;
                        commodity.ImageUrl = commmodityResult.picturepath;
                        commodity.Price = (int)commmodityResult.price;

                        //获得商品的tag列表
                        ISingleResult<getTagByCommodityResult> tagResultList = DBAccessor.getTagByCommodity(commmodityResult.id);
                        foreach (getTagByCommodityResult tagResult in tagResultList)
                        {
                            Tag tag = new Tag();
                            tag.name = tagResult.id;
                            tag.popularity = (int)tagResult.popularity;
                            //加入商品的Tag列表
                            commodity.tagList.Add(tag);
                        }
                        //把商品加入订单的商品列表
                        order.commodityList.Add(commodity);
                    }

                    //订单加入订单列表
                    OrderList.Add(order);
                }
            }
            catch (Exception e)
            {

            }
            return OrderList;
        }
        //通过给出用户id的到这个用户的商品列表
        public List<Commodity> GetOtherUserCommodity(string otherUserName)
        {
            List<Commodity> commodityList = new List<Commodity>();
            ISingleResult<getCommodityByUserResult> result = dc.getCommodityByUser(otherUserName);

            foreach (getCommodityByUserResult commodityByUserId in result)
            {
                Commodity userCommodity = new Commodity();
                userCommodity.description = commodityByUserId.discription;
                userCommodity.EndTime = commodityByUserId.endtime.Value;
                userCommodity.ID = commodityByUserId.id;
                userCommodity.ImageUrl = commodityByUserId.picturepath;
                userCommodity.kind = (CommodityKind)(commodityByUserId.kind.Value);
                userCommodity.Name = commodityByUserId.name;
                userCommodity.popularity = commodityByUserId.popularity.Value;
                userCommodity.Price = commodityByUserId.price.Value;
                userCommodity.StartTime = commodityByUserId.starttime.Value;
                ///////
                List<Tag> tagList = new List<Tag>();
                ISingleResult<getTagByCommodityResult> result2 = dc.getTagByCommodity(userCommodity.ID);
                foreach (getTagByCommodityResult tagResult in result2)
                {
                    Tag tag = new Tag();
                    tag.name = tagResult.id;
                    tag.popularity = tagResult.popularity.Value;
                    tagList.Add(tag);
                }
                userCommodity.tagList = tagList;

                userCommodity.UserName = commodityByUserId.userfrom;
                commodityList.Add(userCommodity);
            }
            return commodityList;
        }
        //搜索推荐商品   参数为查询字符串和种类。
        public List<Commodity> SearchPaymentCommodity(String quryString, CommodityKind kind)
        {
            //string SKind = null;
            //if (kind == null)
            //{
            //    //如果用户没有传递中了的参数则默认的传递ALL
            //    SKind = "ALL";
            //}
            //else
            //{
            //    SKind = kind.ToString();
            //}

            if (quryString == null)
            {
                quryString = "%";
            }
            else
            {}

            List<Commodity> commodityList = new List<Commodity>();
            ISingleResult<searchPaymentCommodityResult> result = dc.searchPaymentCommodity(quryString, (int)kind);
            foreach (searchPaymentCommodityResult singleCommodity in result)
            {
                Commodity commodity = new Commodity();
                commodity.description = singleCommodity.discription;
                commodity.EndTime = singleCommodity.endtime.Value;
                commodity.ID = singleCommodity.id;
                commodity.ImageUrl = singleCommodity.picturepath;
                //commodity.kind = (CommodityKind)Enum.Parse(typeof(CommodityKind),singleCommodity.kind.ToString(),true);
                commodity.kind = (CommodityKind)(singleCommodity.kind.Value);
                commodity.Name = singleCommodity.name;
                commodity.popularity = singleCommodity.popularity.Value;
                commodity.Price = (double)singleCommodity.price;
                commodity.StartTime = System.DateTime.Now;
                //得到商品的tag列表
                ///////
                //得到taglist
                try
                {
                    ISingleResult<getTagByCommodityResult> TagResult = dc.getTagByCommodity(singleCommodity.id);
                    List<Tag> TagList = new List<Tag>();
                    foreach (getTagByCommodityResult Newtag in TagResult)
                    {
                        Tag tag = new Tag();
                        tag.name = Newtag.id;
                        tag.popularity = Newtag.popularity.Value;
                        TagList.Add(tag);
                    }
                    commodity.tagList = TagList;
                }
                catch (Exception e)
                {
                    commodity = null;
                }

                ////////
                commodity.UserName = singleCommodity.userfrom;
                commodityList.Add(commodity);
            }
            return commodityList;
        }
        //搜索所有一般商品
        public List<Commodity> SearchNoPaymentCommodity(String quryString, CommodityKind kind)
        {
            //string SKind = kind.ToString();

            if (quryString == null)
            {
                quryString = "%";
            }
            else
            {}
            List<Commodity> commodityList = new List<Commodity>();
            ISingleResult<searchNoPaymentCommodityResult> result = dc.searchNoPaymentCommodity(quryString, (int)kind);
            foreach (searchNoPaymentCommodityResult singleCommodity in result)
            {
                Commodity commodity = new Commodity();
                commodity.description = singleCommodity.discription;
                commodity.EndTime = singleCommodity.endtime.Value;
                commodity.ID = singleCommodity.id;
                commodity.ImageUrl = singleCommodity.picturepath;
                commodity.kind = (CommodityKind)(singleCommodity.kind.Value);

                commodity.Name = singleCommodity.name;
                commodity.popularity = (int)singleCommodity.popularity;
                commodity.Price = singleCommodity.price.Value;
                commodity.StartTime = singleCommodity.starttime.Value ;
                ///////
                //得到taglist
                List<Tag> TagList = new List<Tag>();
                try
                {
                    ISingleResult<getTagByCommodityResult> TagResult = dc.getTagByCommodity(singleCommodity.id);

                    foreach (getTagByCommodityResult Newtag in TagResult)
                    {
                        Tag tag = new Tag();
                        tag.name = Newtag.id;
                        tag.popularity = Newtag.popularity.Value;
                        TagList.Add(tag);
                    }
                    commodity.tagList = TagList;
                }
                catch (Exception e)
                {
                    commodity = null;
                }

                ////////
                commodity.UserName = singleCommodity.userfrom;
                commodityList.Add(commodity);
            }
            return commodityList;
        }
        public static List<Commodity> GetTopPaymentCommodity()
        {
            List<Commodity> commodityList= new List<Commodity>();

            //getAllPayment commodity
            ISingleResult<searchPaymentCommodityResult> result = dc.searchPaymentCommodity("%", (int)CommodityKind.ALL);

            //for (int i = 1; i <= num; i++)
            foreach (searchPaymentCommodityResult commodityResult in result)
            {
                //searchPaymentCommodityResult commodityResult = new searchPaymentCommodityResult();
                Commodity commodity = new Commodity();
                commodity.description = commodityResult.discription;
                commodity.EndTime = commodityResult.endtime.Value;

                commodity.ID = commodityResult.id;
                commodity.ImageUrl = commodityResult.picturepath;
                commodity.kind = (CommodityKind)commodityResult.kind.Value;
                commodity.Name = commodityResult.name;
                commodity.popularity = commodityResult.popularity.Value;
                commodity.Price = commodityResult.price.Value;
                commodity.StartTime = commodityResult.starttime.Value;

                List<Tag> tagList = new List<Tag>();
                ISingleResult<getTagByCommodityResult> result2 = dc.getTagByCommodity(commodity.ID);
                foreach (getTagByCommodityResult tagResult in result2)
                {
                    Tag tag = new Tag();
                    tag.name = tagResult.id;
                    tag.popularity = tagResult.popularity.Value;
                    tagList.Add(tag);
                }
                commodity.tagList = tagList;
                commodity.UserName = commodityResult.userfrom;

                commodityList.Add(commodity);
            }
            return commodityList;
        }
        //发布商品
        protected void PublisButton_Click(object sender, EventArgs e)
        {
            List<Commodity> CommodityList = new List<Commodity>();
            Commodity commodity = new Commodity();
            commodity.ID = System.Guid.NewGuid();
            //commodity.UserName = ((RegistedUser)Session["User"]).UserName;
            commodity.Name = this.CommodityNameTextBox.Text.Trim();
            commodity.kind = (CommodityKind)Enum.Parse(typeof(CommodityKind), this.CommodityKindDropDownList.SelectedItem.ToString(), false);
            commodity.popularity = 0;
            //处理标签
            commodity.tagList = new List<Tag>();
            char[] Spiliter = new char[1];
            Spiliter[0] = ';';
            String[] Taglist = this.CommodityTagsTextBox.Text.Split(Spiliter, StringSplitOptions.None);
            foreach (String tag in Taglist)
            {
                Tag newtag = new Tag();
                newtag.name = tag;
                newtag.popularity = 0;
                commodity.tagList.Add(newtag);
            }
            commodity.StartTime = DateTime.Now;
            commodity.EndTime = DateTime.Parse(this.CommodityPeriodTextBox.Text.ToString());
            commodity.Price = Double.Parse(this.CommodityPriceTextBox.Text.Trim());
            commodity.description = this.CommodityDescriptionTextBox.Text.Trim();

            //处理上传的图片
            bool fileOk = false;
            String path = Server.MapPath("~/Images/user/commodity/");
            String fileExtension = "";
            if(this.CommodityImageFileUpload.HasFile)
            {
                //文件后缀名
                fileExtension = System.IO.Path.GetExtension(this.CommodityImageFileUpload.FileName).ToLower();
                String[] allowExtension = {".gif",".png",".jpeg",".jpg"};
                foreach(String extension in allowExtension)
                {
                    if(fileExtension.Trim() == extension)
                    {
                        fileOk = true;
                    }
                }
            }
            if(fileOk)
            {
                try
                {

                    this.CommodityImageFileUpload.SaveAs(path+commodity.ID.ToString()+ fileExtension);
                    commodity.ImageUrl = path+commodity.ID.ToString()+ fileExtension;
                    //发布商品
                    CommodityList.Add(commodity);

                    bool IsSucceed = (new RegisterUserService()).PublishCommodity(CommodityList);
                    if (IsSucceed)
                    {
                        this.SubmitInfoLabel.Text = "发布成功";
                    }
                    else
                    {
                        this.SubmitInfoLabel.Text = "发布失败,可能是商品已存在!";
                    }
                }
                catch(Exception ee)
                {
                    this.SubmitInfoLabel.Text = "发布失败商品图片无法上传,请检查图片文件格式!";
                }
            }
            //没有选择文件或者文件格式不正确
            else
            {
                this.SubmitInfoLabel.Text = "没有选择商品图片或者图片格式不正确!";
            }
            this.SubmitInfoLabel.Visible = true;
        }