using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

public partial class member_ShopTemplate :nspBase.MemberBasePge
{
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!CheckCookies())
          {
              Response.Redirect("../../login/login.aspx");
          }
          else
          {
              if (!IsPostBack)
              {
                  bind(1);
              }
          }
      }
    protected string intParam1 = "";
    protected string intParam2 = "";
    private  void bind(int page)
    {
        string str = "";
        Base.XMLProcess xp = new Base.XMLProcess("xml/Template.xml");
        System.Xml.XmlNodeList nodeList = xp.ReadAllChild("/template/shop");
        int count = 0;
        count=nodeList.Count%4>0?nodeList.Count/4+1:nodeList.Count/4;

        this.intParam1 = Convert.ToString(page - 1); 
        this.intParam2 = Convert.ToString(page + 1);
        for (int i = 0; i < count; i++)
        {
            TableRow tRow = new TableRow();
            this.Table1.Rows.Add(tRow);
            for (int j = 0; j < 4; j++)
            {
                if (nodeList.Count <= i * 4 + j) break;
                TableCell tCel = new TableCell();
                
                //商铺图片
                Image img = new Image();
                img.ImageUrl = nodeList.Item(i * 4 + j).Attributes["img"].Value.ToString();
                tCel.Controls.Add(img);

                RadioButton rad = new RadioButton();
                rad.Text = nodeList.Item(i * 4 + j).Attributes["value"].Value.ToString();
                tCel.Controls.Add(rad);

                string img1 = nodeList.Item(i * 4 + j).Attributes["img"].Value.ToString();
                string name = nodeList.Item(i * 4 + j).Attributes["value"].Value.ToString();
                string url = nodeList.Item(i * 4 + j).Attributes["url"].Value.ToString();
                ////商铺名称
                //Label lab = new Label();
                //lab.Text = nodeList.Item(i * 4 + j).Attributes["value"].Value.ToString();
                //tCel.Controls.Add(lab);
                tCel.Text = "<div style=' float: left; width:130px; border: 3px #CCC solid; margin-bottom: 5px;'><img src='../../ShopTemplate/" + url + "/" + img1 + "' width='130' height='100'></div><div style=' float: left; width: 130px; text-align: center'><input name='select1' type='radio'   value='" + name + "'>"+ name +"</div>";
                 
                tRow.Cells.Add(tCel);
            }
        }
            
        HiddenField hidparam=new HiddenField();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        string str = Request.Form["select1"];
        if (Base.BasePage.GetCookie("UserID").ToString() != "")
        {
            int ID = Convert.ToInt32(Base.BasePage.GetCookie("UserID").ToString());
            UserInfo.RUserInfo ruser = new UserInfo.RUserInfo();

            if (ruser.UpdateTemplate(str, ID) == 1)
                ShowMessage("修改成功！", "index.aspx");
            else
            {
                ShowMessage("修改失败！", "index.aspx");
            }
        }
        else
        {
            HttpContext.Current.Response.Redirect("/login/login.aspx");
        }
    }
}

