예제 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string    id = Request.QueryString["id"];
        int       i  = 0;
        DataTable dt = new DataTable();

        if (id != null)
        {
            category cat  = new category();
            brand    brnd = new brand();
            products pro  = new products();
            dt = pro.getproductbyid(Convert.ToInt16(id));
            string pro_name = dt.Rows[0]["name"].ToString();


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


            DataTable pname   = pro.getpic(Convert.ToInt32(id));
            string    picname = "";

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

                HtmlGenericControl li_main = new HtmlGenericControl("li");
                HtmlAnchor         a       = new HtmlAnchor();
                a.Attributes.Add("href", "index.aspx");
                a.InnerText = "صفحه اصلی";
                li_main.Controls.Add(a);
                adres.Controls.Add(li_main);

                HtmlGenericControl li_shop_sp = new HtmlGenericControl("li");
                HtmlGenericControl a1_sp      = new HtmlGenericControl("span");
                a1_sp.Attributes.Add("class", "icon-chevron-left");
                a1_sp.InnerHtml = " ";
                li_shop_sp.Controls.Add(a1_sp);
                adres.Controls.Add(li_shop_sp);



                HtmlGenericControl li_shop = new HtmlGenericControl("li");
                HtmlAnchor         a2      = new HtmlAnchor();
                a2.Attributes.Add("href", "shop.aspx");
                a2.InnerText = "فروشگاه";
                li_shop.Controls.Add(a2);
                adres.Controls.Add(li_shop);


                HtmlGenericControl li_spliter2 = new HtmlGenericControl("li");
                HtmlGenericControl a_sp2       = new HtmlGenericControl("span");
                a_sp2.Attributes.Add("class", "icon-chevron-left");
                a_sp2.InnerHtml = " ";
                li_spliter2.Controls.Add(a_sp2);
                adres.Controls.Add(li_spliter2);


                HtmlGenericControl li_brand = new HtmlGenericControl("li");
                HtmlAnchor         a4       = new HtmlAnchor();
                a4.Attributes.Add("href", "shop.aspx?brand_id=" + dt.Rows[0]["brand_id"].ToString());
                a4.InnerText = brandname;
                li_brand.Controls.Add(a4);
                adres.Controls.Add(li_brand);



                HtmlGenericControl li_spliter1 = new HtmlGenericControl("li");
                HtmlGenericControl a_sp        = new HtmlGenericControl("span");
                a_sp.Attributes.Add("class", "icon-chevron-left");
                a_sp.InnerHtml = " ";
                li_spliter1.Controls.Add(a_sp);
                adres.Controls.Add(li_spliter1);



                HtmlGenericControl li_cat = new HtmlGenericControl("li");
                HtmlAnchor         a3     = new HtmlAnchor();
                a3.Attributes.Add("href", "shop.aspx?cat_id=" + dt.Rows[0]["cat_id"].ToString());
                a3.InnerText = catname;
                li_cat.Controls.Add(a3);
                adres.Controls.Add(li_cat);


                /*
                 *        <li><span class="icon-chevron-left"></span></li>
                 *        <li><a href="shop.aspx">فروشگاه</a> </li>
                 *        <li><span class="icon-chevron-left"></span></li>
                 *
                 */



                //--------------------
                foreach (DataRow list in pname.Rows)
                {
                    HtmlGenericControl divimg = new HtmlGenericControl("div");
                    if (i == 0)
                    {
                        divimg.Attributes.Add("class", "thumb active");
                    }
                    else
                    {
                        divimg.Attributes.Add("class", "thumb");
                    }
                    imgroot.Controls.Add(divimg);
                    HtmlGenericControl an = new HtmlGenericControl("a");
                    an.Attributes.Add("href", "#MainContent_mainPreviewImg");
                    an.Attributes.Add("alt", "");
                    divimg.Controls.Add(an);
                    HtmlGenericControl pimg = new HtmlGenericControl("img");
                    pimg.Attributes.Add("alt", "");
                    pimg.Attributes.Add("width", "940");
                    pimg.Attributes.Add("height", "940");
                    pimg.Attributes.Add("src", "images/Ppic/" + list["name"].ToString() + ".jpg");
                    an.Controls.Add(pimg);
                    i++;
                }
            }
            //--------------------
            else
            {
                picname = ("images/Ppic/" + "noimage" + ".jpg");
                HtmlGenericControl divimg = new HtmlGenericControl("div");
                divimg.Attributes.Add("class", "thumb active");
                imgroot.Controls.Add(divimg);
                HtmlGenericControl an = new HtmlGenericControl("a");
                an.Attributes.Add("href", "#MainContent_mainPreviewImg");
                an.Attributes.Add("alt", "");
                divimg.Controls.Add(an);
                HtmlGenericControl pimg = new HtmlGenericControl("img");
                pimg.Attributes.Add("alt", "");
                pimg.Attributes.Add("width", "940");
                pimg.Attributes.Add("height", "940");
                pimg.Attributes.Add("src", picname);
                an.Controls.Add(pimg);
            }


            mainPreviewImg.Src = (picname);

            product_detail.InnerText = dt.Rows[0]["detail"].ToString();
            product_price.InnerText  = string.Format("{0:#,##0}", dt.Rows[0]["price"]) + " ریال";
            product_name.InnerText   = catname + " " + brandname + " " + dt.Rows[0]["name"].ToString();

            HtmlGenericControl span_status = new HtmlGenericControl("span_status");


            if ((Int16.Parse(dt.Rows[0]["movjodi"].ToString())) >= 5)
            {
                span_status.Attributes.Add("class", "btn btn-success");
                span_status.InnerText = "موجود";
            }
            else if ((Int16.Parse(dt.Rows[0]["movjodi"].ToString())) >= 1)
            {
                span_status.Attributes.Add("class", "btn btn-warning");
                span_status.InnerText = "تماس بگیرید";
            }
            else
            {
                span_status.Attributes.Add("class", "btn btn-danger");
                span_status.InnerText = "اتمام موجودی";
            }

            product_status.Controls.Add(span_status);



            //foreach (DataRow list in pname.Rows)
            //{
            //    HtmlGenericControl divimg = new HtmlGenericControl("div");
            //    if (i == 0)
            //    {
            //        divimg.Attributes.Add("class", "thumb active");
            //    }
            //    else
            //    {
            //        divimg.Attributes.Add("class", "thumb");
            //    }
            //    imgroot.Controls.Add(divimg);

            //    HtmlGenericControl an = new HtmlGenericControl("a");
            //    an.Attributes.Add("href", "#MainContent_mainPreviewImg");
            //    an.Attributes.Add("alt", "");
            //    divimg.Controls.Add(an);

            //    HtmlGenericControl pimg = new HtmlGenericControl("img");
            //    pimg.Attributes.Add("alt", "");
            //    pimg.Attributes.Add("width", "940");
            //    pimg.Attributes.Add("height", "940");
            //    pimg.Attributes.Add("src", "images/Ppic/" + list["name"].ToString() + ".jpg");
            //    an.Controls.Add(pimg);
            //    i++;

            //}

            HtmlAnchor a_addtocart = new HtmlAnchor();
            a_addtocart.ID           = "addtocart" + dt.Rows[0]["id"].ToString();
            a_addtocart.HRef         = "#";
            a_addtocart.Name         = dt.Rows[0]["id"].ToString() + "," + dt.Rows[0]["price"].ToString() + "," + picname + "," + catname + " - " + brandname + " - " + dt.Rows[0]["name"].ToString();
            a_addtocart.ServerClick += new System.EventHandler(Addcart_Click);
            a_addtocart.Attributes.Add("class", "btn buy btn-danger");
            a_addtocart.Attributes.Add("onclick", "addtocart('MainContent_mainPreviewImg');");
            a_addtocart.InnerText = "اضافه به سبد خرید";
            UpdatePanel up = new UpdatePanel();
            up.ContentTemplateContainer.Controls.Add(a_addtocart);
            addtocart_detail.Controls.Add(up);
            set_related(pro_name, id);
        }
        else
        {
            Response.Redirect("shop.aspx");
        }
    }