예제 #1
0
    public void set_newproduct()
    {
        category cat     = new category();
        brand    brnd    = new brand();
        string   picname = null;

        new_product.InnerHtml = "";
        products  p  = new products();
        DataTable dt = new DataTable();

        dt = p.getproduct_new();
        int i = 0;

        foreach (DataRow dr in dt.Rows)
        {
            DataTable          pname    = p.getonepic(Convert.ToInt32(dr["id"]));
            HtmlGenericControl divspan3 = new HtmlGenericControl("div");
            divspan3.Attributes.Add("class", "span3");

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

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

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

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

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

            HtmlGenericControl imgpicture = new HtmlGenericControl("img");
            imgpicture.Attributes.Add("id", "p-img-new" + dr["id"].ToString());
            imgpicture.Attributes.Add("width", "540");
            imgpicture.Attributes.Add("height", "374");
            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-new" + 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 no-margin");


            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);

            divspan3.Controls.Add(divproduct);

            new_product.Controls.Add(divspan3);
            if (i != 0 && i % 3 == 0)
            {
                HtmlGenericControl divclearfix = new HtmlGenericControl("div");
                divclearfix.Attributes.Add("class", "clearfix");
                new_product.Controls.Add(divclearfix);
            }
            i++;
        }
    }