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

 <!-- #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();
     int AdvListId;
 

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();
  //-------------------------
 
    AdvListId=Convert.ToInt32(Codeschar(Request.Params["AdvListId"].Trim()));
    strSQL="Select AdvList.AdvType as AdvType,AdvDetailed.id as id,AdvDetailed.AdvTitle as AdvTitle,AdvDetailed.width as width,AdvDetailed.height as height,AdvDetailed.ImgAddress as ImgAddress,AdvDetailed.Format as Format ,AdvDetailed.url as url,AdvDetailed.UrlParameter as UrlParameter,AdvDetailed.AcceptAppearance as AcceptAppearance From AdvDetailed,AdvList where AdvDetailed.AdvListId=AdvList.id and AdvDetailed.AdvUserName='"+AdvUserName+"'and AdvDetailed.IsTemp=1 and AdvDetailed.IsTemp=1 and AdvDetailed.AdvListId="+AdvListId;
 	da = new SqlDataAdapter(strSQL,strConn);   
	 if (!IsPostBack)
  {
	CmdDataBind();
   }
}



 protected void CmdDataBind()
  {
    ds.Clear();
    da.Fill(ds,"AdvDetailed");
    DataGrid1.DataSource=ds;
	DataGrid1.DataBind(); 
	//Console.WriteLine(ds.Tables["AdvDetailed"].Rows[1]);
	
	//DataGrid1.Tables[0].Rows[1].Page_Del.Enabled=false;	
   }

 protected string advvise(string AdvType,string ImgAddress,string width,string height,string Format,string url)
  {
   if(AdvType=="2")
    {
	return "弹出地址:"+url;
	}
	 else
	 {
	  switch(Format)
	  {
	   case "1":
	   return "<embed src=\""+ImgAddress+"\" quality=high pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+width+"\" height=\""+height+"\"></embed>";
	   break;  
	   case "2":
	   return "<img src="+ImgAddress+" width="+width+" height="+height+">";
	   break;  
	 default:return url;
	  break;
	   }
	 return url;
	 }
    
   } 
   
  protected string IsAcceptAppearance(string i)  
  { 
  switch(i)
  {
   case "1":
    return "<font color=#0000FF>通过审核</font>";
	break;
   case "2":
    return "<font color=#ff0000>等待审核</font>";
	break;
   case "3":
    return "<font color=#009900>修改挂起</font>";
	break;
   case "4":
    return "<font color=#FF6600>删除挂起</font>";
	break;
    default:
	return "未知";
	break;
   }
  }
  
 
  // 删除记录
 private void Del_DataSet(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)
 {
   if(e.CommandName.ToString()=="del")
   {
      //Response.Write(DataGrid1.DataKeys[e.Item.ItemIndex]);
	  SqlConnection cn = new SqlConnection(strConn);
	  string DeleteSql="update AdvDetailed set AcceptAppearance=4 where id="+ DataGrid1.DataKeys[e.Item.ItemIndex];
	  //Response.Write(DeleteSql);
	  SqlCommand cmd= new SqlCommand(DeleteSql,cn);
	  cn.Open();
	  try
	  {
	   cmd.ExecuteNonQuery();
	   span1.InnerHtml=msgbox_1("删除申请提交成功!!");
	   }
	    catch(Exception s)
		{
	     span1.InnerHtml=msgbox_1("操作失败!!");
		}
		cn.Close();
	    CmdDataBind();//重新绑定
    }
   if(e.CommandName.ToString()=="edit")
    {
	 Response.Redirect("AddAdvDetailed.aspx?Action=Edit&AdvListId="+AdvListId+"&id="+DataGrid1.DataKeys[e.Item.ItemIndex]);
	 Response.End();
	}
 } 
 
 //设置删除/编辑键不可用
 public void MyDataGrid_ItemDataBound(object sender, DataListItemEventArgs e)
{
  //Response.Write(e.Item.Cells[10].Text +"<br>");
  
　 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    { 
	 //Response.Write(((Label)e.Item.FindControl("AcceptAppearance")).Text.ToString());
	 if(((Label)e.Item.FindControl("AcceptAppearance")).Text.ToString()=="4"||((Label)e.Item.FindControl("AcceptAppearance")).Text.ToString()=="3")
	  {
	   //e.Item.Cells[9].Page_Del.Enabled=false;
        ((LinkButton)e.Item.FindControl("Page_Del")).Enabled=false;
        ((LinkButton)e.Item.FindControl("Page_Edit")).Enabled=false;
	   }
	 }

}
</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" />
<style type="text/css">
<!--
.td_1 {
	margin: 4px;
}
-->
</style>
</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"><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%">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30">
			<form runat="server">
			<asp:DataList 
			     ID="DataGrid1"
				 runat="server" 
				 ShowHeader="true" 
				 Width="950"
				 OnItemCommand="Del_DataSet"
				 DataKeyField="id"
				 OnItemDataBound="MyDataGrid_ItemDataBound"
				 >
              <itemtemplate>
                <table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E4E4E4" class="table_3">
                  <tr>
                    <td height="25"  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 height="25" bgcolor="#FFFFFF"><table width="50%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td>&nbsp; 尺寸: <font color="#0000ff"><%# DataBinder.Eval(Container.DataItem,"width").ToString() %> x <%# DataBinder.Eval(Container.DataItem,"height").ToString() %></font></td>
                          <td>状态: 
						  <%# IsAcceptAppearance(DataBinder.Eval(Container.DataItem,"AcceptAppearance").ToString()) %>
						  <asp:Label ID="AcceptAppearance" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem,"AcceptAppearance").ToString() %>'></asp:Label>
						  </td>
                          <td>类型: <font color="#0000ff"><%# DataBinder.Eval(Container.DataItem,"width").ToString() %> x <%# DataBinder.Eval(Container.DataItem,"height").ToString() %></font></td>
                          <td>&nbsp;</td>
                        </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td height="25" bgcolor="#FFFFFF"><div align="center" class="td_1"><%#advvise(DataBinder.Eval(Container.DataItem,"AdvType").ToString(),DataBinder.Eval(Container.DataItem,"ImgAddress").ToString(),DataBinder.Eval(Container.DataItem,"width").ToString(),DataBinder.Eval(Container.DataItem,"height").ToString(),DataBinder.Eval(Container.DataItem,"Format").ToString(),DataBinder.Eval(Container.DataItem,"url").ToString()) %><br />
                            <a href=<%# DataBinder.Eval(Container.DataItem,"url").ToString() %> target=_blank>链接地址:<font color="#0000ff"><%# DataBinder.Eval(Container.DataItem,"url").ToString() %></font></a> URL参数: <font color="#0000ff"><%# DataBinder.Eval(Container.DataItem,"UrlParameter").ToString() %> </font></div></td>
                  </tr>
                  <tr>
                    <td height="25" bgcolor="#F7F7F7"><div align="right">
					<asp:LinkButton ID="Page_Del" Text="删除" runat="server" CommandName="del"/> <asp:LinkButton ID="Page_Edit" Text="修改" runat="server" CommandName="edit"/> &nbsp;&nbsp;&nbsp;</div></td>
                  </tr>
                </table>
              </itemtemplate>
            </asp:DataList>
			</form>
              <table width="930" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E4E4E4" class=table_3>
				
              <tr>
                <td width="929" height="33" bgcolor="#F7F7F7"><div align="center"><a href="AddAdvDetailed.aspx?AdvListId=<%=Request.Params["AdvListId"].Trim()%>"><img src="images/addadvss.gif" width="127" height="24" border="0" /></a> </div></td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
          </tr>
        </table>	
          <SPAN id="span1" runat="server"></SPAN>		       
           </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>
