예제 #1
0
    public void set_related(string name, string id)
    {
        related.InnerHtml = "";
        products  p       = new products();
        DataTable dt      = new DataTable();
        category  cat     = new category();
        brand     brnd    = new brand();
        string    picname = null;

        // string brandname = null;

        dt = p.getproduct_related_top(name, id);;
        int i = 0;
        HtmlGenericControl divslide = null;
        HtmlGenericControl divrow   = null;

        if (dt.Rows.Count > 0)
        {
            //<div class="arrows">
            //            <a href="#" class="icon-chevron-right" id="featuredItemsRight"></a><a href="#" class="icon-chevron-left"
            //                id="featuredItemsLeft"></a>
            //        </div>


            HtmlGenericControl h = new HtmlGenericControl("h2");
            h.Attributes.Add("class", "title");

            HtmlGenericControl span = new HtmlGenericControl("span");
            span.Attributes.Add("class", "light");
            span.InnerText = "محصولات مرتبط";

            HtmlGenericControl divarrow = new HtmlGenericControl("div");
            divarrow.Attributes.Add("class", "arrows");

            HtmlGenericControl a_right_divarrow = new HtmlGenericControl("a");
            a_right_divarrow.Attributes.Add("class", "icon-chevron-right");
            a_right_divarrow.Attributes.Add("id", "featuredItemsRight");
            a_right_divarrow.Attributes.Add("href", "#");
            a_right_divarrow.ClientIDMode = ClientIDMode.Static;
            divarrow.Controls.Add(a_right_divarrow);

            HtmlGenericControl a_left_divarrow = new HtmlGenericControl("a");
            a_left_divarrow.Attributes.Add("class", "icon-chevron-left");
            a_left_divarrow.Attributes.Add("id", "featuredItemsLeft");
            a_left_divarrow.Attributes.Add("href", "#");
            a_left_divarrow.ClientIDMode = ClientIDMode.Static;
            divarrow.Controls.Add(a_left_divarrow);


            h.Controls.Add(span);

            title.Controls.Add(h);
            title.Controls.Add(divarrow);
        }


        foreach (DataRow dr in dt.Rows)
        {
            if (i % 3 == 0)
            {
                divslide = new HtmlGenericControl("div");
                divslide.Attributes.Add("class", "slide");
                divrow = new HtmlGenericControl("div");
                divrow.Attributes.Add("class", "row");
            }

            string catname   = cat.getcategory(dr["cat_id"].ToString()).Rows[0]["name"].ToString();
            string brandname = brnd.getbrandbyid(dr["brand_id"].ToString()).Rows[0]["name"].ToString();


            DataTable          pname    = p.getonepic(Convert.ToInt32(dr["id"]));
            HtmlGenericControl divspan4 = new HtmlGenericControl("div");
            divspan4.Attributes.Add("class", "span4");

            if (pname.Rows.Count != 0)
            {
                //imgpicture.Attributes.Add("src", "images/Ppic/" + pname.Rows[0]["name"].ToString() + ".jpg");
                picname = "images/Ppic/" + pname.Rows[0]["name"].ToString() + ".jpg";
            }
            else
            {
                //imgpicture.Attributes.Add("src", "images/Ppic/noimage.jpg");
                picname = "images/Ppic/noimage.jpg";
            }

            HtmlGenericControl divproduct = new HtmlGenericControl("div");
            divproduct.Attributes.Add("class", "product");


            HtmlGenericControl divproductimg = new HtmlGenericControl("div");
            divproductimg.Attributes.Add("class", "product-img featured");


            HtmlGenericControl divpicture = new HtmlGenericControl("div");
            divpicture.Attributes.Add("class", "picture");


            HtmlGenericControl imgpicture = new HtmlGenericControl("img");
            imgpicture.Attributes.Add("id", "p-img-f" + dr["id"].ToString());
            //img1.Attributes.Add("runat", "server");
            imgpicture.Attributes.Add("width", "518");
            imgpicture.Attributes.Add("height", "358");
            imgpicture.Attributes.Add("alt", "");

            imgpicture.Attributes.Add("src", picname);
            divpicture.Controls.Add(imgpicture);


            HtmlGenericControl divimgoverlay = new HtmlGenericControl("div");
            divimgoverlay.Attributes.Add("class", "img-overlay");


            HtmlGenericControl aimgoverlay = new HtmlGenericControl("a");
            aimgoverlay.Attributes.Add("href", "product.aspx?id=" + dr["id"].ToString());
            aimgoverlay.Attributes.Add("class", "btn more btn-primary");
            aimgoverlay.InnerText = "توضیحات بیشتر";
            divimgoverlay.Controls.Add(aimgoverlay);



            HtmlAnchor aimgoverlay2 = new HtmlAnchor();
            aimgoverlay2.ID           = "addtocart" + dr["id"].ToString();
            aimgoverlay2.HRef         = "#";
            aimgoverlay2.Name         = dr["id"].ToString() + "," + dr["price"].ToString() + "," + picname + "," + catname + " - " + brandname + " - " + dr["name"].ToString();
            aimgoverlay2.ServerClick += new System.EventHandler(Addcart_Click);
            aimgoverlay2.Attributes.Add("class", "btn buy btn-danger");
            aimgoverlay2.Attributes.Add("onclick", "addtocart('" + "p-img-f" + dr["id"].ToString() + "');");
            aimgoverlay2.InnerText = "اضافه به سبد خرید";

            UpdatePanel up = new UpdatePanel();
            up.ContentTemplateContainer.Controls.Add(aimgoverlay2);
            divimgoverlay.Controls.Add(up);
            divimgoverlay.Controls.Add(aimgoverlay);
            divpicture.Controls.Add(divimgoverlay);
            divproductimg.Controls.Add(divpicture);
            divproduct.Controls.Add(divproductimg);

            HtmlGenericControl divmaintitle = new HtmlGenericControl("div");
            divmaintitle.Attributes.Add("class", "main-titles");


            HtmlGenericControl h4maintitle = new HtmlGenericControl("h4");
            h4maintitle.Attributes.Add("class", "title");
            h4maintitle.InnerText = catname + "-" + brandname + " - " + dr["name"].ToString();
            divmaintitle.Controls.Add(h4maintitle);

            HtmlGenericControl h5maintitle = new HtmlGenericControl("h5");
            h5maintitle.Attributes.Add("class", "no-margin");
            h5maintitle.InnerText = String.Format("{0:#,##0}", dr["price"]) + " ریال"; //int.Parse(dr["price"].ToString()).ToString("N1",CultureInfo.InvariantCulture);
            divmaintitle.Controls.Add(h5maintitle);
            divproduct.Controls.Add(divmaintitle);

            HtmlGenericControl pdesc = new HtmlGenericControl("p");
            pdesc.Attributes.Add("class", "desc");
            pdesc.InnerText = dr["detail"].ToString();
            divproduct.Controls.Add(pdesc);

            divspan4.Controls.Add(divproduct);


            if (i % 3 < 3)
            {
                divrow.Controls.Add(divspan4);
                divslide.Controls.Add(divrow);
            }
            if (i % 3 == 2 || (i + 1) == dt.Rows.Count)
            {
                related.Controls.Add(divslide);
            }
            i++;
        }
    }