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.Text;

public partial class admin_model_document_attribute : Fm.Bussiness.BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            StringBuilder where = new StringBuilder();
            if (Request.QueryString["items"] != null)
            {
                Fm.Bussiness.public_select ps=new Fm.Bussiness.public_select();
                DataTable tab = new DataTable();
                DataColumn dc = new DataColumn();
                dc.ColumnName = "head";
                tab.Columns.Add(dc);
                DataColumn dc1 = new DataColumn();
                dc1.ColumnName = "map";
                tab.Columns.Add(dc1);
                DataColumn dc2 = new DataColumn();
                dc2.ColumnName = "flash";
                tab.Columns.Add(dc2);
                DataColumn dc3 = new DataColumn();
                dc3.ColumnName = "commend";
                tab.Columns.Add(dc3);
                DataColumn dc4 = new DataColumn();
                dc4.ColumnName = "docid";
                tab.Columns.Add(dc4);
                string items = Request.QueryString["items"].ToString();
                string[] docid = items.Substring(0,items.Length-1).Split(',');
                DataView dv=new DataView();
                for (int i = 0; i < docid.Length; i++)
                {
                    DataRow row = tab.NewRow();
                    dv = ps.Getps("Fm_model_main","docid,head,map,flash,commend","docid="+docid[i]);
                    row["head"] = dv[0]["head"].ToString();
                    row["map"] = dv[0]["map"].ToString();
                    row["flash"] = dv[0]["flash"].ToString();
                    row["commend"] = dv[0]["commend"].ToString();
                    row["docid"] = dv[0]["docid"].ToString();
                    tab.Rows.Add(row);
                }
                //绑定
                Repeater1.DataSource = tab;
                Repeater1.DataBind();
                //循环显示多选属性
                foreach (RepeaterItem item in Repeater1.Items)
                {
                    //查找多选列表控件
                    CheckBoxList ch = item.FindControl("CheckBoxList_Att") as CheckBoxList;
                    HtmlContainerControl html = item.FindControl("docid") as HtmlContainerControl;
                    foreach (DataRow row in tab.Rows)
                    {
                        if (row["docid"].ToString() == html.InnerText)
                        {
                            ch.Items[0].Selected = bool.Parse(row["head"].ToString());
                            ch.Items[1].Selected = bool.Parse(row["map"].ToString());
                            ch.Items[2].Selected = bool.Parse(row["flash"].ToString());
                            ch.Items[3].Selected = bool.Parse(row["commend"].ToString());
                        }
                    }

                }
            }
        }
    }
    //保存相关属性
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Fm.Bussiness.public_select ps = new Fm.Bussiness.public_select();

       
        foreach (RepeaterItem item in Repeater1.Items)
        {
            //循环保存多选属性
            int head = 0;
            int map = 0;
            int flash = 0;
            int commend = 0;
            //查找多选列表控件
            CheckBoxList ch = item.FindControl("CheckBoxList_Att") as CheckBoxList;
            HtmlContainerControl html = item.FindControl("docid") as HtmlContainerControl;
            //保存属性数据
            if (ch.Items[0].Selected)
            {
                head = 1;
            }
            if (ch.Items[1].Selected)
            {
                map = 1;
            }
            if (ch.Items[2].Selected)
            {
                flash = 1;
            }
            if (ch.Items[3].Selected)
            {
                commend = 1;
            }
            ps.Queryps("update Fm_model_main set head="+head+",map="+map+",flash="+flash+",commend="+commend+" where docid="+html.InnerText);
        }
        Response.Redirect("Erro.aspx?eid=所选文章属性保存成功!&url=model_document.aspx", false);
    }
}
