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 WTOSYSadmin_market_markeing : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }

        this.online.Text = Application["online"].ToString();
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from MtjIP where  DATEPART(month,adddate)="+DateTime.Now.Month.ToString()+" order by adddate", conn);
        DataSet ds = new DataSet();
        sda.Fill(ds,"cu");
        this.GridView1.DataSource = ds;
        this.GridView1.DataKeyNames = new string[] {"id"};
        this.GridView1.DataBind();
        Image hpl;
        Label l1;
        HyperLink h1;
        if (GridView1.Rows.Count != 0)
        {
            SqlCommand smdC = new SqlCommand("select sum(iptj) from MtjIP where  DATEPART(month,adddate)=" + DateTime.Now.Month.ToString(), conn);
            double Count = Convert.ToInt32(smdC.ExecuteScalar());

            for (int i = 0; i < this.GridView1.Rows.Count; i++)
            {
                DataRowView drv = ds.Tables["cu"].DefaultView[i];
                SqlCommand cmd2 = new SqlCommand("select iptj,adddate,id from MtjIP where id=" + this.GridView1.DataKeys[i].Value, conn);
                SqlDataReader sdr5 = cmd2.ExecuteReader();
                sdr5.Read();
                hpl = (Image)GridView1.Rows[i].FindControl("Image1");
                hpl.ImageUrl = "~/SYSadmin/image/Zxt.jpg";
                hpl.Width = sdr5.GetInt32(0);

                hpl.Height = 15;
                l1 = (Label)GridView1.Rows[i].FindControl("Label1");
                l1.Text = Convert.ToString(Math.Round(sdr5.GetInt32(0) / Count * 100, 2)) + "%";
                h1 = (HyperLink)GridView1.Rows[i].FindControl("HyperLink1");
                h1.NavigateUrl = "~/SYSadmin/market/timefx.aspx?id=" + sdr5.GetInt32(2);
                sdr5.Close();
            }

        }
        else
        {
            this.Label2.Visible = true;
        }



        SqlCommand smd = new SqlCommand("select iptj from MtjIP where adddate='" + DateTime.Now.Date + "'", conn);
        this.daytj.Text = Convert.ToString(smd.ExecuteScalar());
        if (this.daytj.Text == "")
        {
            daytj.Text = "0";
        }
        SqlCommand smd2 = new SqlCommand("select iptj from MtjIP where adddate='" + DateTime.Now.Date.AddDays(-1) + "'", conn);
        this.tomtj.Text = Convert.ToString(smd2.ExecuteScalar());
        if (this.tomtj.Text == "")
        {
            tomtj.Text = "0";
        }
        SqlCommand smd3 = new SqlCommand("select ytj from YtjIP where adddate='" + DateTime.Now.Year.ToString() + "年" + DateTime.Now.Month.ToString() + "月份" + "'", conn);
        this.mtj.Text = Convert.ToString(smd3.ExecuteScalar());
        if (this.mtj.Text == "")
        {
            mtj.Text = "0";
        }

        SqlCommand smd4 = new SqlCommand("select ipint from ZIP where adddate='" + DateTime.Now.Year + "年" + "'", conn);
        this.ytj.Text = Convert.ToString(smd4.ExecuteScalar());
        if (this.ytj.Text == "")
        {
            ytj.Text = "0";
        }
        conn.Close();
    }

    protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        # region 行变色
        int i;
        int g = 0;
        //执行循环，保证每条数据都可以更新
        for (i = 0; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
            g++;
        }
        //如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //鼠标经过时，行背景色变 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
            //鼠标移出时，行背景色变 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
        # endregion
        //如果是绑定数据行 

    }

}
