<%@ 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 AdvUserName;
     String strSQL;
	 String UserName;
     String strConn = ConfigurationSettings.AppSettings["ConnectionString"];
	 string Action;
	 int id;
	 
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==null || Action=="")
    {
	 Action="New";
	 }
  
 id=Convert.ToInt32(Request.Params["id"]);
 
 if (!IsPostBack)
  {

  SetupReplyToAffairs();
 switch (Action)
  {
   case "Read":
    ReadNews();
    reg2.Visible=false;
	break;
	
   case "Reply":
    ReadNews();
	reg1.Visible=true;
    reg2.Visible=true;
	break;
	
   case "Ask":
	reg1.Visible=false;
    reg2.Visible=true;
	ReplyToUserName.Text="5507";
	ReplyToAffairs.SelectedIndex =1;
	break;

   default:
    reg1.Visible=false;
    reg2.Visible=true;
    break;
  }
 }
 
}



//读消息
protected void ReadNews()
{
   strSQL="Select * From News where ToUserName='"+AdvUserName+"' and ToAffairs=2 and NewsType=5 and id="+id;
     //Response.Write(strSQL);
	 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("记录不存在");
	   }
	    	   
	  SendUserName.Text=myReader["UserName"].ToString();
	  SendTitle.Text=myReader["Title"].ToString();
	  SendContents.Text=myReader["Contents"].ToString();
	  SendAddTima.Text=myReader["AddTima"].ToString();
	  
	  ReplyToUserName.Text=myReader["UserName"].ToString();
	  ReplyTitle.Text="Re:"+myReader["Title"].ToString();
	  Reply.NavigateUrl="ReplyNews.Aspx?Action=Reply&id="+id;
	  
	  ReplyToAffairs.SelectedValue=myReader["Affairs"].ToString();
	  
	  
	  myReader.Close();
	  
	SqlDataAdapter da= new SqlDataAdapter(strSQL,cn);
    SqlCommandBuilder scb=new SqlCommandBuilder(da);//
		//修改当前记录
	 DataSet ds=new DataSet();
	  da.Fill(ds,"News");
	  DataRow newRow=ds.Tables[0].Rows[0];
	   newRow.BeginEdit();
	   newRow["hits"]=(int)newRow["hits"]+1;
	   newRow.EndEdit();
	   da.Update(ds,"News");
	//修改阅读次数
	  cn.Close();
	   
 }

//回复消息


//保存消息
protected void Save(Object Src, EventArgs E)
 {
 
   strSQL="Select * From News";
     //Response.Write(strSQL);
	 SqlConnection cn = new SqlConnection(strConn);
     cn.Open();
	 
	SqlDataAdapter da= new SqlDataAdapter(strSQL,cn);
    SqlCommandBuilder scb=new SqlCommandBuilder(da);//
		//修改当前记录
	 DataSet ds=new DataSet();
	  da.Fill(ds,"News");
	  
	 DataRow newRow=ds.Tables[0].NewRow();
	 newRow["Title"]=ReplyTitle.Text.ToString();
	 newRow["Appearance"]=1;
	 newRow["UserName"]=AdvUserName;
	 newRow["Affairs"]=2;
	 newRow["NewsType"]=5;
	 newRow["ToUserName"]=ReplyToUserName.Text.ToString();
	 
	 newRow["ToAffairs"]=Convert.ToInt32(ReplyToAffairs.SelectedItem.Value);
	 
	 newRow["Contents"]=ReplyContents.Text.ToString();
	 newRow["AddTima"]=System.DateTime.Now;
	 newRow["hits"]=0;
	 ds.Tables["News"].Rows.Add(newRow);
     da.Update(ds,"News");
	//修改阅读次数
	cn.Close();
	alertmsg("提交成功","sendNews.Aspx");
  
	}


//设置接收者身份
protected void SetupReplyToAffairs()
{
  ReplyToAffairs.Items.Add(new ListItem("网站主", "1"));
  ReplyToAffairs.Items.Add(new ListItem("管理员", "3"));
 }
</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">
<!--
.STYLE1 {color: #FF0000}
-->
</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>
			<asp:panel id="reg1" Runat="server">
          <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="26%" height="25" bgcolor="#FFFFFF"><div align="right">发件人:</div></td>
                <td width="74%" bgcolor="#FFFFFF"><asp:Label ID="SendUserName" runat="server" />                </td>
                </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">标题:</div></td>
                <td bgcolor="#FFFFFF"><asp:Label Font-Bold="true" ForeColor="#0000FF" ID="SendTitle" runat="server" /></td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">短信内容:</div></td>
                <td bgcolor="#FFFFFF" class="text_20"><asp:Label ID="SendContents" runat="server" /></td>
                </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">发件时间:</div></td>
                <td bgcolor="#FFFFFF"><asp:Label ID="SendAddTima" runat="server" /></td>
              </tr>
              <tr>
                <td height="25" colspan="2" bgcolor="#F9F9F9"><div align="center"><asp:HyperLink ID="Reply" runat="server" Text="回复"> </asp:HyperLink> 
                  <a href="sendNews.Aspx">返回</a> <a href="#" onclick="window.close();">关闭窗口</a> </div></td>
                </tr>
              
            </table>		
			</td>	
          </tr>
		  </asp:panel>
		  
	     <asp:panel id="reg2" Runat="server">
          <tr>
            <td height="30"><table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#E4E4E4" class="table_3">
              <tr>
                <td height="25" colspan="2" background="../web/images/top_img.gif" bgcolor="#FFFFFF"><div align="center">发送消息</div></td>
              </tr>
              <tr>
                <td width="26%" height="25" bgcolor="#FFFFFF"><div align="right">接收人</div></td>
                <td width="74%" bgcolor="#FFFFFF"><asp:TextBox ID="ReplyToUserName" runat="server" />
				
                  <asp:DropDownList ID="ReplyToAffairs" runat="server"></asp:DropDownList>
				  
                  <span class="STYLE1">*</span>
				  <asp:RequiredFieldValidator ControlToValidate="ReplyToUserName" Display="Dynamic" ErrorMessage="接收人不能为空" runat="server" />
				  <a href="###" OnClick="ReplyToUserName.value='5507';ReplyToAffairs.selectedIndex=1">[有问必答]</a></td>
                </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">标题:</div></td>
                <td bgcolor="#FFFFFF"><asp:TextBox ID="ReplyTitle" runat="server" Columns="30" />
                  <span class="STYLE1">*</span>
				  <asp:RequiredFieldValidator ControlToValidate="ReplyTitle" Display="Dynamic" ErrorMessage="标题不能为空" runat="server" />
				  </td>
              </tr>
              <tr>
                <td height="25" bgcolor="#FFFFFF"><div align="right">内容:</div></td>
                <td bgcolor="#FFFFFF"><asp:TextBox ID="ReplyContents" runat="server" TextMode="MultiLine" Rows="10" Columns="50" />
                  <span class="STYLE1">*</span>
				  <asp:RequiredFieldValidator ControlToValidate="ReplyContents" Display="Dynamic" ErrorMessage="内容不能为空" runat="server" />
				  </td>
                </tr>
              <tr>
                <td height="25" colspan="2" bgcolor="#F7F7F7"><div align="center">
                <asp:Button ID="Button1" Text="发送" runat="server" OnClick="Save"/></div></td>
              </tr>
            </table></td>
          </tr>
		  </asp:panel>
		  
        </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>
