<%@ Page Language="C#" ContentType="text/html" %>
<%@ Register TagPrefix="My" TagName="MyHead" Src="head.ascx" %>
<%@ Register TagPrefix="My" TagName="MyFoot" Src="foot.ascx" %>
<%@ Register TagPrefix="My" TagName="MyMessage" Src="message.ascx" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

 <!-- #INCLUDE file="../inc/Function.aspx" -->
<script runat="server">
     String strSQL;
	 String UserName;
     String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	 string AdvUserName;
	 DataSet ds=new DataSet();
     SqlDataAdapter da = new SqlDataAdapter();
	 string SearchDate;
	 
protected void Page_Load(Object Src, EventArgs E)
{
    //------判断用户是否登录---
     if(Session["Login_UserName"]==null || Session["IsLogin"]==null || Session["Userclass"]==null || Session["Login_UserName"]=="" || Session["IsLogin"].ToString().ToLower()!="true" )
   {   
      Response.Write("<script language=javascript>alert ('登录超时');document.location='../ ';<");
	  Response.Write("/script>");
	  Response.End();
    }
   AdvUserName=Session["Login_UserName"].ToString();
  //-------------------------


  if (!IsPostBack)
  {
   SetupSearch();
   }
   
  SearchDate=SearchYear.Text.ToString()+SearchMonth.Text.ToString()+SearchDay.Text.ToString();
  
  strSQL="Select * From AdvList where AdvUserName='"+AdvUserName+"' and IsTemp=1 and AdvAppearance<>0 order by id desc";  
   	da = new SqlDataAdapter(strSQL,strConn);   
     CmdDataBind();	 
}


 protected void CmdDataBind()
  {
    ds.Clear();
    da.Fill(ds,"AdvList");
    DataGrid1.DataSource=ds;
	DataGrid1.DataBind(); 
	//Console.WriteLine(ds.Tables["AdvDetailed"].Rows[1]);
	
	//DataGrid1.Tables[0].Rows[1].Page_Del.Enabled=false;	
   }
   
  //获取每个详细广告位的统计
 protected string GetAdvCount(int id)
  {
    string temp;
	string TempstrSQL;
	 temp="<table width=\"98%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"table_7\">";

	TempstrSQL="Select * From AdvDetailed where AdvListId="+id + " and IsTemp=1";
	  SqlConnection cn = new SqlConnection(strConn);
	  SqlCommand cmd= new SqlCommand(TempstrSQL,cn);
	  cn.Open();
	  SqlDataReader myReader=cmd.ExecuteReader();
	  while(myReader.Read())
	  {
     temp+= "               <tr>";
     temp+= "             <td width=\"40%\" height=\"62\"  bgcolor=\"#FBFBFF\"><div align=\"center\"><b>"+myReader["AdvTitle"] + "</b><br>规格:"+myReader["width"] + "*"+ myReader["height"]+"</div></td>";
     temp+= "                  <td width=\"60%\"><table width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
     temp+= "                     <tr>";
     temp+= "                       <td width=\"40%\" height=\"20\"><div align=\"center\">·点击数据:</div></td>";
     temp+= "                       <td width=\"60%\">&nbsp;"+ GetAdvCount_1((int)myReader["id"],"Quantity","AdvDetailed") +"</td>";
     temp+= "                    </tr>";
     temp+= "                     <tr>";
     temp+= "                       <td height=\"20\" bgcolor=\"#F9F9F9\"><div align=\"center\">·显示次数:</div></td>";
     temp+= "                       <td bgcolor=\"#F9F9F9\">&nbsp;"+ GetAdvCount_1((int)myReader["id"],"ShowQuantity","AdvDetailed") +"</td>";
     temp+= "                     </tr>";
     temp+= "                     <tr>";
     temp+= "                       <td height=\"20\"><div align=\"center\">·CPA销售量:</div></td>";
     temp+= "                       <td>&nbsp;"+ GetAdvCount_1((int)myReader["id"],"CPAQuantity","AdvDetailed") +"</td>";
     temp+="  </tr></table></td></tr>";
	 temp+=" <tr> <td height=\"5\" colspan=\"2\" bgcolor=\"#F6F6F6\"> </td></tr>";
	 }
	 
	 myReader.Close();
	 cn.Close();
	 temp+=" </table>";				
	return temp;
  }
  
 
 //显示某一广告详细广告在指定日内的统计数
 protected int GetAdvCount_1(int AdvDetailed,string sunitem,string obj)
  {
	string TempstrSQL;
	TempstrSQL="Select SUM("+sunitem+") From AdvCount where "+obj+"="+ AdvDetailed +" and CountDay='"+SearchDate+"'";
	  SqlConnection cn = new SqlConnection(strConn);
	  SqlCommand cmd= new SqlCommand(TempstrSQL,cn);
	  cn.Open();
	  string Temp=cmd.ExecuteScalar().ToString();
	  if(Temp==null || Temp=="")
	   {
	    return 0;
	   }else
	   {
	    return Convert.ToInt32(Temp);
	   }
	  cn.Close();
   }
   
   
//设置搜索日期列表框

 protected void SetupSearch()
  {
   int i;
   
   for( i=2005;i<=2008;i++)
   {
    SearchYear.Items.Add(i.ToString());
	}
	
   for(i=1;i<=12;i++)
   {
    if(i<10){
     SearchMonth.Items.Add("0"+i.ToString());
	}else
	{
     SearchMonth.Items.Add(i.ToString());
	 }
	}
	
   for( i=1;i<=31;i++)
   {
    if(i<10){
    SearchDay.Items.Add("0"+i.ToString());
	}else
	{
    SearchDay.Items.Add(i.ToString());
      }
	}
	
   SearchYear.SelectedValue=System.DateTime.Now.Year.ToString();
   
   if((int)System.DateTime.Now.Month<10)
    { 
	 SearchMonth.SelectedValue="0"+System.DateTime.Now.Month.ToString();
	 }
	 else
	{ 
     SearchMonth.SelectedValue=System.DateTime.Now.Month.ToString();
	}
   
   if((int)System.DateTime.Now.Day<10)
    { 
	 SearchDay.SelectedValue="0"+System.DateTime.Now.Day.ToString();
	 }
	 else
	{ 
     SearchDay.SelectedValue=System.DateTime.Now.Day.ToString();
	}

   
   }
   
 //设置搜索
 protected void OnSearch(Object Src, EventArgs E)
 {
   
  }
  
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<script language="JavaScript" type="text/javascript">

function viewa(day)
{
 var source=event.srcElement;
 if(eval("date_" + day + ".style.display")=="none")
   {
    eval("date_" + day + ".style.display=\"\"");
	source.title="隐藏详细列表";
    }
	else
    {
    eval("date_" + day + ".style.display=\"none\"");
	source.title="展开详细广告";
    }
 }

function hidea(day){
	eval("date_" + day + ".style.display=\"none\"");
	eval("view_" + day + ".style.display=\"\"");
	eval("hide_" + day + ".style.display=\"none\"");
}
</script>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>5507广告联盟 - 广告商管理后台 - 当日数据报表 </title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<my:MyHead runat="server"/>
<form runat="server">
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0" class="table_3">
  <tr>
    <td width="20" height="15"><img src="../web/images/body_1.gif" /></td>
    <td width="926" background="../web/images/body_2.gif"></td>
    <td width="20"><img src="../web/images/body_3.gif" width="20" height="15" /></td>
  </tr>
</table>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" background="../web/images/body_7.gif" bgcolor="#FFFFFF"><p>&nbsp;</p>
        <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p></td>
    <td width="953" valign="top" bgcolor="#FFFFFF"><table width="950" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="140" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="30"><table width="98%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%"><div align="center"><img src="../images/adv_list.gif" width="25" height="25" /></div></td>
                <td width="13%"><strong>当日数据报表</strong></td>
                <td width="81%">按日查询:
                  <asp:DropDownList ID="SearchYear" runat="server"></asp:DropDownList>
                  年
                  <asp:DropDownList ID="SearchMonth" runat="server"></asp:DropDownList>
                  月
                  <asp:DropDownList ID="SearchDay" runat="server"></asp:DropDownList>
                  日 
                  <asp:Button ID="Button1" Text="查询" runat="server" OnClick="OnSearch"/></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30"><asp:DataList 
	ID="DataGrid1"
	 RepeatLayout="Flow"
	 runat="server" 
	 ShowHeader="true" 
	 Width="950"
        >
              <itemtemplate>
                <table width="950" border="0" cellpadding="0" cellspacing="1" bgcolor="#E4E4E4">
                  <tr>
                    <td height="25" colspan="3" background="../web/images/top_img.gif" bgcolor="#FFFFFF">&nbsp;&nbsp;
                      NO: <%# DataBinder.Eval(Container.DataItem,"id").ToString() %> 广告名称: <b> <%# DataBinder.Eval(Container.DataItem,"AdvTitle").ToString() %></b> </td>
                  </tr>
                  <tr>
                    <td width="22%" height="77" bgcolor="#FFFFFF"><div align="center"><img src="../web/images/default.gif" /><br />
                          <%=SearchDate%></div></td>
                    <td  width="40%" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="31%" height="40"><div align="center"> <a href="#" title="显示详细广告" onclick="viewa('<%# DataBinder.Eval(Container.DataItem,"id").ToString() %>')"><img src="../images/mx.gif" width="75" height="14" border="0" /></a> </div></td>
                          <td width="69%"><table width="90%" border="0" cellpadding="0" cellspacing="0" class="table_7">
                              <tr>
                                <td width="28%" height="20"><div align="right">投放金额: </div></td>
                                <td width="72%">&nbsp;<font color="#ff0000"><%# DataBinder.Eval(Container.DataItem,"TotalMoney").ToString() %></font></td>
                              </tr>
                              <tr>
                                <td height="20" bgcolor="#F6F6F6"><div align="right">可用金额: </div></td>
                                <td bgcolor="#F6F6F6">&nbsp;<font color="#ff0000"><%# DataBinder.Eval(Container.DataItem,"GotoMoney").ToString() %></font></td>
                              </tr>
                              <tr>
                                <td height="20"><div align="right">点弹数量:</div></td>
                                <td>&nbsp;<font color="#ff0000"><%# DataBinder.Eval(Container.DataItem,"Total").ToString() %></font></td>
                              </tr>
                          </table></td>
                        </tr>
                        <tr>
                          <td colspan="2" id="date_<%# DataBinder.Eval(Container.DataItem,"id").ToString() %>" style="display:none"><%# GetAdvCount((int)DataBinder.Eval(Container.DataItem,"id")) %> </td>
                        </tr>
                    </table></td>
                    <td width="37%" bgcolor="#FFFFFF" valign="top"><table width="282" border="0" align="center" cellpadding="0" cellspacing="0" class="table_7">
                        <tr>
                          <td width="86" height="20"><div align="right">当日总点击:</div></td>
                          <td width="194">&nbsp;<font color="0000ff"><%#GetAdvCount_1((int)DataBinder.Eval(Container.DataItem,"id"),"Quantity","AdvListId")%></font></td>
                        </tr>
                        <tr>
                          <td height="20" bgcolor="#F6F6F6"><div align="right">当日总显示:</div></td>
                          <td bgcolor="#F6F6F6">&nbsp;<font color="0000ff"><%#GetAdvCount_1((int)DataBinder.Eval(Container.DataItem,"id"),"ShowQuantity","AdvListId")%></font></td>
                        </tr>
                        <tr>
                          <td height="20"><div align="right">当日CPA销售:</div></td>
                          <td>&nbsp;<font color="0000ff"><%#GetAdvCount_1((int)DataBinder.Eval(Container.DataItem,"id"),"CPAQuantity","AdvListId")%></font></td>
                        </tr>
                    </table></td>
                  </tr>
                </table>
              </itemtemplate>
            </asp:DataList></td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
          </tr>
        </table></td>
        </tr>
    </table></td>
    <td width="15" background="../web/images/body_8.gif" bgcolor="#FFFFFF">&nbsp;</td>
  </tr>
</table>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20"><img src="../web/images/body_4.gif" width="20" /></td>
    <td width="926" background="../web/images/body_5.gif">&nbsp;</td>
    <td width="20"><div align="right"><img src="../web/images/body_6.gif" width="20" height="20" /></div></td>
  </tr>
</table>
</form>	
<my:MyFoot runat="server"/>

</body>
</html>
