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.Reflection;
using System.Data.SqlClient;
using SqlOperate;

public partial class Search_Compare : System.Web.UI.Page
{
    string str = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string str1=Base.BasePage.GetCookie("offerId");

        str = Request.QueryString["cpid"].ToString();
       if (str == "" || str == null)
           Base.BasePage.ShowMessage("至少选择一条信息", "");
       else
           BuildTable(GetTable(str));
        
    }

    /// <summary>
    /// 取得比较数据
    /// </summary>
    /// <returns></returns>
    private static DataTable GetTable(string CompareID)
    {
        string str = "where ID in ("+CompareID.ToString()+") ";   
        SqlParameter[] param = new SqlParameter[] 
        {
             new SqlParameter("@strwhere", str),
            new SqlParameter("@strtableName", "C_Supply"), 
            new SqlParameter("@strOrder", " order by AddDate  desc,ID desc") 
        };
        return SqlHelper.ExecuteTable(CommandType.StoredProcedure, "SP_SelectByWhere", param);

    }



    /// <summary>
    /// 创建目录列表 
    /// </summary>
    private void BuildTable(DataTable ReTable)
    {
        string[] restr ={ "ID", "Thumbnail", "Name" };
        int count = restr.Length;
        // 清除原有的行
        this.TblDirList.Rows.Clear();
        
        // 显示"移除/收藏"
        TableRow top = new TableRow();
        TblDirList.Rows.Add(top);
        TableCell t1 = new TableCell();
        top.Cells.Add(t1);
        for (int j = 0; j < ReTable.Rows.Count; j++)
        {
            // 添加TD
            TableCell TCell = new TableCell();
            string strID = "";
            if (str.IndexOf(',') > 0)
            {
                if (j != ReTable.Rows.Count-1)
                    strID = str.Replace(ReTable.Rows[j]["ID"].ToString() + ",", "");
                else 
                    strID = str.Replace("," + ReTable.Rows[j]["ID"].ToString(), "");
            }
            string s1 = "<a href='Compare.aspx?offerID=" + strID + "'>";
            string s2 = "<a href=''>";
            TCell.Text = s1 + "移除</a>" +  "/" +  "收藏</a>";
            top.Cells.Add(TCell);
        }

        //显示比较信息
        for (int i = 0; i < count; i++)
        {
            // 添加表格的标题
            TableRow tr = new TableRow();
           
            TblDirList.Rows.Add(tr);
            TableCell tt = new TableCell();
            tt.Text = restr[i].ToString();
            tr.Cells.Add(tt);
            for (int j = 0; j < ReTable.Rows.Count; j++)
            {
                // 添加TD
                TableCell iconCell = new TableCell();
                iconCell.Text =ReTable.Rows[j][restr[i].ToString()].ToString();
                tr.Cells.Add(iconCell);
            }
        }
    }

   
}
