<%@ 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" %>
<%@ Import Namespace="System.Web.Mail" %>

 <!-- #INCLUDE file="../inc/Function.aspx" -->

<script runat="server">
 string AdvUserName;
     String strSQL;
	 String UserName;
     String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	 DataSet ds=new DataSet();
     SqlDataAdapter da = new SqlDataAdapter();
	 
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();
  //-------------------------

  strSQL="Select ApplicationAdv.id as id, ApplicationAdv.WebUserName as WebUserName ,ApplicationAdv.RegData as RegData,Website.WebsiteName as WebsiteName, AdvList.AdvTitle as AdvTitle,Website.url as url From ApplicationAdv,AdvList,Website where AdvList.AdvUserName='"+AdvUserName+"' and AdvList.id=ApplicationAdv.AdvListId and ApplicationAdv.Appearance=2 and Website.id=ApplicationAdv.Websiteid";
 	da = new SqlDataAdapter(strSQL,strConn);
     CmdDataBind();
}


 protected void CmdDataBind()
  {
   
    ds.Clear();
    da.Fill(ds,"ApplicationAdv");
    DataGrid1.DataSource=ds;
	DataGrid1.DataBind(); 
   }


protected string CLWebsiteName(string id,string url,string WebsiteName)
 {
   string Temp="<span id='date_"+id+"' style='display:none'>";
   string[] allCharArray = url.Split('\r');
   
  foreach(string i in allCharArray)
  {
   Temp+= " · <a href='http://"+i+"' target='_blank' style=\"font-size:16px\">"+i+"</a><br>" ;
   }
   return "<a href='#' onclick=viewa('"+id+"')><font color=#009900><b>"+WebsiteName+"</b></font></a>"+"<br>"+Temp + "</span>";
 }


//处理当前记录
 private void Del_DataSet(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
    int i=1;
   if(e.CommandName.ToString()=="Pass" || e.CommandName.ToString()=="Brush")
    {
	  SqlConnection cn = new SqlConnection(strConn);
	  
	    if(e.CommandName.ToString()=="Brush"){i=3;}
	     strSQL="update ApplicationAdv set Appearance="+i+" where id="+e.Item.Cells[0].Text.ToString();
         SqlCommand SComm= new SqlCommand(strSQL,cn);
         cn.Open();
         SComm.ExecuteNonQuery();
		 cn.Close();
		 span1.InnerHtml=msgbox_1("处理成功");
		 
		 
		 //审核发送邮件
		 
		 String IsSendMail = ConfigurationSettings.AppSettings["IsSendMail"]; //是否发送邮件 1 发送 0 不发送
		 String MailSmtp = ConfigurationSettings.AppSettings["MailSmtp"]; //邮件服务器SMTP地址
		 String MailFrom = ConfigurationSettings.AppSettings["MailFrom"]; // 邮件发送者
		 String IsMailSmtp = ConfigurationSettings.AppSettings["IsMailSmtp"]; //smtp是否需要身份验证 1 需要 0 不需要
		 String sendusername = ConfigurationSettings.AppSettings["sendusername"]; //smtp用户名
		 String sendpassword = ConfigurationSettings.AppSettings["sendpassword"]; //-smtp密码
		 
		 if(IsSendMail=="1")
		 {
		   SB.ADOHelper help=new SB.ADOHelper();
           string MailBody=help.ReadTemplate(16); //编号 16
           MailBody=MailBody.Replace("#UserName# ",e.Item.Cells[1].Text.ToString());
           MailBody=MailBody.Replace("#AdvTitle#",e.Item.Cells[3].Text.ToString());
		   
		    if(i==1)
			 {
              MailBody=MailBody.Replace("#Appearance#","通过审核,请登录后台获取广告代码。"); 
			 }
			 else 
			 {
			  MailBody=MailBody.Replace("#Appearance#","被广告主拒绝，您还可以登录我们后台申请别的广告 。"); 
			 }
			 
			 string MailTo=help.SearchReadDataBas("WebsiteHost","UserName='"+e.Item.Cells[1].Text.ToString() + "'","Email");
			 
			help.Send_mail(MailBody,MailTo,MailFrom , e.Item.Cells[3].Text.ToString()+" 已审核!!",MailSmtp,IsMailSmtp,sendusername,sendpassword);
		    }
		 

		 if(i==1)
		 {
		  Write_News("您所申请的广告:"+e.Item.Cells[3].Text.ToString()+" 已经通过审核",1,AdvUserName,2,5,e.Item.Cells[1].Text.ToString(),"您申请的广告: "+e.Item.Cells[3].Text.ToString()+" 已经通过审核,您可以开始投放广告.");
		  }else
		  {
		  Write_News("您所申请的广告:"+e.Item.Cells[3].Text.ToString()+" 被拒绝",1,AdvUserName,2,5,e.Item.Cells[1].Text.ToString(),"很抱歉您所申请的广告: "+e.Item.Cells[3].Text.ToString()+" 被广告主拒绝,谢谢您的支持有任何问题可以联系我们广告客服,您还可以尝试申请别的广告,祝您好运！！");
		  }
		 
         CmdDataBind(); 
	}
   
   
  }
  
  
//添加新闻或短消息
 private void  Write_News(string Title,int Appearance,string UserName,int Affairs,int NewsType,string ToUserName,string Contents)
 {
   string NewsSql;
    String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	NewsSql="insert into News(Title,Appearance,UserName,Affairs,NewsType,ToUserName,Contents,AddTima,hits) values (";
	NewsSql+="'"+Title+"',";
	NewsSql+=Appearance+",";
	NewsSql+="'"+UserName+"',";
	NewsSql+=Affairs+",";
	NewsSql+=NewsType+",";
	NewsSql+="'"+ToUserName+"',";
	NewsSql+="'"+Contents+"',";
	NewsSql+="'"+System.DateTime.Now+"',";
	NewsSql+=0+")";
	//Response.Write(NewsSql);
	//Response.End();
	SqlConnection cn = new SqlConnection(strConn);
    SqlCommand SComm= new SqlCommand(NewsSql,cn);
     cn.Open();
     SComm.ExecuteNonQuery();
     cn.Close();
  }


</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">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>5507广告联盟 - 广告商管理后台 - 投放申请审核 </title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">

function viewa(day)
{
 if(eval("date_" + day + ".style.display")=="none")
   {
    eval("date_" + day + ".style.display=\"\"");
    }
	else
    {
    eval("date_" + day + ".style.display=\"none\"");
    }
 }

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

</script>


</head>
<body>
<my:MyHead 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">
		<form runat=server>
		<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="16%"><strong>投放申请审核</strong></td>
                <td width="78%">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30">
			
			 <asp:DataGrid 
			 AutoGenerateColumns="false"
			 AllowSorting="True"
			 BackColor="#ffffff"
			  BorderColor="#dddddd" 
			  BorderWidth="1" 
			  Height="25" 
			  ID="DataGrid1" 
			   runat="server" 
			   ShowFooter="false" 
			   ShowHeader="true" 
			   HeaderStyle-Height="25"
			   FooterStyle-ForeColor="#EAEAEA"
			   HeaderStyle-BackColor="#F3F3F3"
			   HeaderStyle-HorizontalAlign="Center"
			   DataKeyField="id"
			   Width="98%" 
			   gridline="Both"
			   AlternatingItemStyle-BackColor="#F7F7F7"
			   OnItemCommand="Del_DataSet"
				>
			  <columns>
			   <asp:boundcolumn datafield="id" ItemStyle-Width="30" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="NO"/>
			   
			   <asp:boundcolumn datafield="WebUserName" ItemStyle-Width="80" ItemStyle-Height="25" ItemStyle-HorizontalAlign="Center" HeaderText="网站主"/>
			   
               <asp:TemplateColumn HeaderText="申请网站" ItemStyle-Width="180"> 
                <itemtemplate>
				<%# CLWebsiteName(DataBinder.Eval(Container.DataItem,"id").ToString(),DataBinder.Eval(Container.DataItem,"url").ToString(),DataBinder.Eval(Container.DataItem,"WebsiteName").ToString()) %>				
				</itemtemplate>
              </asp:TemplateColumn>
			  
			   
			   <asp:boundcolumn datafield="AdvTitle"  ItemStyle-HorizontalAlign="Center" HeaderText="申请的广告"/>
			   
			   <asp:boundcolumn datafield="RegData"  ItemStyle-HorizontalAlign="Center" HeaderText="申请时间"/>
			   
			   <asp:TemplateColumn HeaderText="处理" ItemStyle-Width="80" ItemStyle-HorizontalAlign="Center">
                <itemtemplate>
				 <asp:LinkButton ID="Pass" Text="通过" runat="server" CommandName="Pass"/>
				 <asp:LinkButton ID="Brush" Text="拒绝" runat="server" CommandName="Brush"/>
				</itemtemplate>
              </asp:TemplateColumn>	   
			   </columns>
			</asp:DataGrid>
			
			</td>
          </tr>
          <tr>
            <td height="30"><span class="text_20">注:只有当您在广告投放的时候设置了广告是必须经过审核才能投放的时候,网站主在申请广告投放的时候就必须通过您的审核后才能投放。</span></td>
          </tr>
        </table>
		<SPAN id="span1" runat="server"></SPAN>
		</form>
		
		</td>
        <td width="220" valign="top"><my:MyMessage runat="server"/></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>

<my:MyFoot runat="server"/>

</body>
</html>
