Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] != null)
            {
                ttbar_login_server.Text = "欢迎,<a style='color:red;'>" + Session["name"].ToString() + "</a>";
            }

            string key = Request.QueryString["key"];                                                 // 关键词
            string typeLevel = Request.QueryString["level"];                                         // 类别等级
            string typeID = Request.QueryString["type"];                                             // 类别
            string typeName = Request.QueryString["typeName"];                                       // 类别名称
            string price_u = Request.QueryString["priceu"], price_t = Request.QueryString["pricet"]; // 价格区间
            string page = Request.QueryString["page"];                                               // 页数

            if (IsNullorEmpty(key) && IsNullorEmpty(typeID) && IsNullorEmpty(typeName) && IsNullorEmpty(typeName))
            {
                J_searchWrap.InnerHtml = "<div class=\"notice-search\"><div class=\"ns-wrap clearfix info\"><span class=\"ns-icon\"></span><div class=\"ns-content\"><span>抱歉,没有找到与“<em></em>”相关的商品</span></div></div></div>";
                return;
            }

            try
            {
                if (key != null && key != "")
                {
                    server_qbjg.Text = key;
                }
                else if (typeID != null && typeID != "")
                {
                    server_qbjg.Text = BLL_GoodsType.QueryTypeName(3, typeID).TypeName;
                }
                else if (typeName != null && typeName != "")
                {
                    server_qbjg.Text = typeName;
                }
                int pos = 0;
                if (page != null && page != "")
                {
                    int _page = Convert.ToInt32(page);
                    pos = (_page - 1) * 20;
                }
                else
                {
                    page = "1";
                }
                bool   _f_type = true;
                string _type   = "";
                if (typeID != null && typeID != "")
                {
                    _type = typeID;
                }
                else if (typeName != null && typeName != "")
                {
                    _type = BLL_GoodsType.QueryTypeID(3, typeName).ElementAt(0).TypeID;
                }
                else
                {
                    _f_type = false;
                }
                int _f_price = 0;
                if (price_u != null && price_u != "")
                {
                    _f_price++;
                }
                if (price_t != null && price_t != "")
                {
                    _f_price += 2;
                }
                var list  = BLL_Goods.QueryGoodsKeyList(key, true, pos, 20, _f_type, _type, _f_price, Convert.ToInt32(price_u), Convert.ToInt32(price_t));
                int count = BLL_Goods.QueryGoodsKeyCount(key, _f_type, _type, _f_price, Convert.ToInt32(price_u), Convert.ToInt32(price_t));
                server_count.Text = count.ToString();
                server_page.Text  = "<b>" + page + "</b><em>/</em><i>" + (count % 20 == 0 ? count / 20 : (count / 20 + 1)).ToString() + "</i>";

                string text = "";
                foreach (var item in list)
                {
                    text += "<li class=\"gl-item\">";
                    text += "<div class=\"gl-i-wrap\">";
                    text += "<div class=\"p-img\">";
                    text += "<a target=\"_blank\" title=\"" + item.Name + "\" href=\"/detail.aspx?id=" + item.Id + "\" onclick=\"javascript:;\">";
                    text += "<img width=\"220\" height=\"220\" class=\"err-product\" data-img=\"1\" src=\"" + item.ImageName + "\" />";
                    text += "</a>";
                    text += "</div>";
                    text += "<div class=\"p-price\">";
                    text += "<strong class=\"J_2457023\" data-price=\"" + item.UnitPrice + "\"><em>¥</em><i>" + item.UnitPrice + "</i></strong>";
                    text += "</div>";
                    text += "<div class=\"p-name p-name-type-2\">";
                    text += "<a target=\"_blank\" title=\"" + item.Name + "\" href=\"/detail.aspx?id=\"" + item.Id + "onclick=\"searchlog(1,2457023,1,1,'','flagsClk=1614811784')\">";
                    text += "<em>" + (key != null && key != ""?item.Name.Replace(key, "<font class=\"skcolor_ljg\">" + key + "</font>"):item.Name) + "<font class=\"skcolor_ljg\" /></em>";
                    text += "<i class=\"promo-words\" id=\"J_AD_2457023\"></i>";
                    text += "</a>";
                    text += "</div>";
                    text += "<div class=\"p-shop\" data-selfware=\"1\" data-score=\"5\" data-reputation=\"96\" data-shopid=\"1000001772\"><a title=\"" + item.Desctipt + "\">" + item.Desctipt + "</a></div>";
                    text += "<div class=\"p-operate\">";
                    text += "<a class=\"p-o-btn contrast J_contrast\" data-sku=\"" + item.Id + "\" href=\"javascript:;\" onclick=\"javascript:;\"><i></i>对比</a>";
                    text += "<a class=\"p-o-btn focus J_focus\" data-sku=\"" + item.Id + "\" href=\"javascript:;\" onclick=\"javascript:;\"><i></i>关注</a>";
                    text += "<a class=\"p-o-btn addcart\" data-stock=\"" + item.Id + "\" data-stock-val=\"1\" data-disable-notice=\"0\" data-presale=\"0\" href=\"#\" data-limit=\"0\"><i></i>加入购物车</a>";
                    text += "</div>";
                    text += "</div>";
                    text += "</li>";
                }
                server_goods.Text = text;
            }
            catch (Exception ex)
            {
                server_goods.Text = "ERROR" + ex.Message;
            }
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"] != null)
            {
                ttbar_login_server.Text = "欢迎,<a style='color:red;'>" + Session["name"].ToString() + "</a>";
            }
            try
            {
                string id = Request.QueryString["id"];
                if (id == null || id == "")
                {
                    Response.Redirect("/index.aspx");
                    return;
                }
                var good        = BLL_Goods.QueryGood(id);
                var type        = BLL_GoodsType.QueryTypeName(3, good.TypeID);
                var type_second = BLL_GoodsType.QueryTypeName(2, type.ParentTypeID);
                var type_top    = BLL_GoodsType.QueryTypeName(1, type_second.ParentTypeID);
                cate_first.InnerHtml  = "<a href='/search.aspx?type=" + type_top.TypeID + "'>" + type_top.TypeName + "</a>";
                cate_second.InnerHtml = "<a href='/search.aspx?type=" + type_second.TypeID + "'>" + type_second.TypeName + "</a>";
                cate_third.InnerHtml  = "<a href='/search.aspx?type=" + type.TypeID + "'>" + type.TypeName + "</a>";
                cate_ellipsis.Attributes.Add("title", good.Name);
                cate_ellipsis.InnerHtml = good.Name;
                server_follow.Attributes.Add("data-id", good.Id);
                server_sku_name.InnerText = good.Name;
                server_price.InnerText    = Math.Round(good.UnitPrice, 2).ToString();
                InitCartUrl.Attributes.Add("sku-id", good.Id);

                // 从京东获取展示图片、详细信息
                var res   = GetHttpWebRequest("http://search.jd.com/Search?keyword=" + good.Name + "&enc=utf-8");
                var regex = new Regex("<a target=\\\"_blank\\\" title=\\\"[^\"]*\\\" href=\\\"[/.\\w\\d]*\\\" onclick=\\\"searchlog[^\\\"]*\\\">");
                var match = regex.Match(res);
                res   = match.Value;
                regex = new Regex("href=\\\"[/.\\w\\d]*\\\"");
                match = regex.Match(res);
                res   = match.Value;
                regex = new Regex("\".*\"");
                match = regex.Match(res);
                res   = match.Value.Replace("\"", "");
                var rreess = res;
                regex = new Regex("/\\d*\\.");
                match = regex.Match(res);
                res   = match.Value.Substring(1, match.Value.Length - 2);
                res   = GetHttpWebRequest("https://cd.jd.com/description/channel?enc=utf-8&skuId=" + res + "&mainSkuId=" + res);
                glofot.Attributes.Add("style", "display:none;");
                glofot.InnerText = res.Replace("data-lazyload", "src");
                //return;
                res   = GetHttpWebRequest("http:" + rreess);
                regex = new Regex("<img alt='[^']*' src='[^']*' data-url='[^']*' data-img='[^']*' width='\\d*' height='\\d*'>");
                var matches = regex.Matches(res);
                spec_img.Attributes.Add("src", Regex.Match(matches[0].ToString().Replace("/n5/", "/n1/"), "src='[^']*'").Value.Replace("src='", "").Replace("'", "").Replace("s54x54", "s450x450")); spec_img.Attributes.Add("alt", good.Name);
                foreach (var item in matches)
                {
                    server_img_lh.InnerHtml += "<li>" + item.ToString() + "</li>\n";
                }
            }
            catch
            {
                Response.Write("<script>alert('从京东获取数据失败,图片和详细商品描述将不可用。');</script>");
            }
        }