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.Data.SqlClient;

public partial class uc_news_styte3 : System.Web.UI.UserControl
{
    private string id;
    private string rss;
    private int strlength;
    private string showdate;
    private string TIT;
    Label l1;
    public string Id
    {
        set
        {
            this.id = value.ToString().Trim();
        }
    }
    public string Rss
    {
        set
        {
            this.rss = value.ToString().Trim();
        }
    }
    public int StrLength
    {
        set
        {
            this.strlength =Convert.ToInt32(value.ToString().Trim());
        }
    }
    public string ShowDate
    {
        set
        {
            this.showdate = value.ToString().Trim();
        }
    }
    public string titl
    {
        set
        {
            TIT = value.ToString().Trim();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.databind();
    }

    protected void databind()
    {
        this.nlink.NavigateUrl = "~/china/NewsGroup.aspx?id="+id;
        this.titna.Text = TIT.ToString();
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select top "+rss+" * from news where biglbid=" + id + " and isfp='y' order by adddate DESC", conn);
        DataSet ds=new DataSet();
        sda.Fill(ds,"cu");
        this.GridView1.DataSource=ds;
        this.GridView1.DataKeyNames = new string[] { "id" };
        this.GridView1.DataBind();
        if (this.showdate == "y")
        {
            SqlCommand smddate;
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                smddate = new SqlCommand("select adddate from news where id="+this.GridView1.DataKeys[i].Value, conn);
                l1 = (Label)GridView1.Rows[i].FindControl("ldate");
                l1.Visible = true;
                l1.Text ="["+Convert.ToString(Convert.ToDateTime(smddate.ExecuteScalar()).ToString("yy-MM-dd"))+"]";
            }
        }
        SqlCommand sad2;
        Image img1=new Image();
        SqlDataReader sdrj;
        HyperLink hyj;
        string gIntro;
        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            DataRowView drvw = ds.Tables["cu"].DefaultView[i];
            sad2 = new SqlCommand("select * from news where id=" + GridView1.DataKeys[i].Value, conn);
            sdrj = sad2.ExecuteReader();
            sdrj.Read();
            string isok = sdrj["picsmall"].ToString();
            img1 = (Image)GridView1.Rows[i].FindControl("img1");
            img1.ImageUrl = "~/images/pic/" + isok;
            //字符过长加省略号
            gIntro = sdrj["title"].ToString(); ;//所要处理的字段
            hyj = (HyperLink)GridView1.Rows[i].Cells[1].FindControl("HyperLink1");
            hyj.Text = SubStr(gIntro, strlength);
            if (sdrj["ischange"].ToString() == "y")
            {
                hyj.NavigateUrl = sdrj["changeurl"].ToString();
                hyj.Target = "_blank";
            }
            else
            {
                hyj.NavigateUrl = "~/china/newscenter.aspx?id=" + sdrj["id"].ToString();
                hyj.Target = "_blank";
            }
            sdrj.Close();

        }
            conn.Close();
    }
    public string SubStr(string sString, int nLeng)
    {
        if (sString.Length <= nLeng)
        {
            return sString;
        }
        string sNewStr = sString.Substring(0, nLeng);
        string sy="";
        switch (xmlwebconfig.GetXMLvalue("news", "indexnew", "", "yicstyle"))
        { 
            case "0":
                sy = "...";
                break;
            case "1":
                sy = "。。。";
                break;
            case "2":
                sy = ">>>";
                break;
            case "3":
                sy = "'''";
                break;
            case "4":
                sy = "---";
                break;
        }
        sNewStr = sNewStr + sy;
        return sNewStr;
    }





}
