<%@ Page Language="C#" ContentType="text/html" validateRequest="false" %>
<%@ 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 AdvUserName;
     String strSQL;
	 String UserName;
     String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	 string Action;
	 int id;
	 string tempContents="";

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();
  //-------------------------
  Action=Codeschar(Request.Params["Action"]);

  if(Action=="Edit")
  {
   id=Convert.ToInt32(Request.Params["id"]);
   strSQL="select * From News where NewsType=4 and UserName='"+AdvUserName+"' and id="+id;
	 SqlConnection cn = new SqlConnection(strConn);
     cn.Open();
     SqlCommand cmd=new SqlCommand(strSQL,cn);
	 SqlDataReader myReader=cmd.ExecuteReader();
	 if(!myReader.Read())
	  {
	   myReader.Close();
	   cn.Close();
	   errmsg("记录不存在");
	   }
	   
    if (!IsPostBack)
    {
      Title.Text=myReader["Title"].ToString();
	  tempContents=Server.HtmlDecode(myReader["Contents"].ToString());
	  Button1.Text=" 修 改 ";
	  myReader.Close();
	  cn.Close();
     }
	
   }
  
 
}

 protected void save_bbs(Object Src, EventArgs E)
 {
  string title;
  string contents;
   title=Title.Text.ToString();
   contents=Request.Params["content"];
   if (contents==null || contents=="")
    {
	 errmsg("请输入公告内容");
	 }
	contents=Server.HtmlEncode(contents);
	 strSQL="select * From News";
	 
	 if(Action=="Edit")
	 
	 {strSQL+=" where id="+id;}
	  
	 
	DataSet ds=new DataSet();
    SqlConnection cn = new SqlConnection(strConn);	
	cn.Open();
	SqlDataAdapter da= new SqlDataAdapter(strSQL,cn);
    SqlCommandBuilder scb=new SqlCommandBuilder(da);//
	da.Fill(ds,"News");
	
	if(Action=="Edit")
	 {
	   DataRow newRow=ds.Tables[0].Rows[0];
	   newRow.BeginEdit();
	   newRow["Title"]=title;
	   newRow["Appearance"]=2;
	   newRow["Contents"]=contents;
	   newRow.EndEdit();
	  }
	  else
	  {
	 DataRow newRow=ds.Tables[0].NewRow();
	 newRow["Title"]=title;
	 newRow["Appearance"]=2;
	 newRow["UserName"]=AdvUserName;
	 newRow["Affairs"]=2;
	 newRow["NewsType"]=4;
	 newRow["ToUserName"]="";
	 newRow["Contents"]=contents;
	 newRow["AddTima"]=System.DateTime.Now;
	 newRow["hits"]=0;
	 ds.Tables["News"].Rows.Add(newRow);
	 }
	 
	 da.Update(ds,"News");
	 cn.Close();
	alertmsg(Button1.Text.ToString().Replace(" ","")+"操作成功!! ","advNews.Aspx");
  }
  
  
</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">
<!--
.tex {
	display: none;
}
-->
</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">
		<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="30%"><strong>发布公告</strong></td>
                <td width="64%">&nbsp;</td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30"><table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E4E4E4">
              <tr>
                <td height="25" colspan="2" background="../web/images/top_img.gif" bgcolor="#FFFFFF"><div align="center">发布广告</div></td>
                </tr>
              <tr>
                <td width="25%" height="32" bgcolor="#FFFFFF"><div align="right">新闻标题:</div></td>
                <td width="75%" bgcolor="#FFFFFF"><asp:TextBox ID="Title" runat="server" Columns="30" />
                  *
				  <asp:RequiredFieldValidator ControlToValidate="Title" Display="Dynamic" runat="server" Text="请输入标题" />
				  </td>
                </tr>
              <tr>
                <td height="29" bgcolor="#FFFFFF"><div align="right">新闻内容：</div></td>
                <td bgcolor="#FFFFFF">	
				<textarea name="content" class="tex" ><%=tempContents%></textarea>
				<iframe class="table_7" src='../webedit/ewebeditor.htm?id=content' frameborder=0 scrolling=no width='500' HEIGHT='300'></iframe>
				
				
				</td>
                </tr>
              <tr>
                <td height="25" colspan="2" bgcolor="#F7F7F7"><div align="center">
                  <asp:Button ID="Button1" runat="server" Text=" 添 加 " OnClick="save_bbs" /></div></td>
                </tr>
            </table></td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
          </tr>
        </table>
		
		</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>
