<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Globalization " %>
<%@ Import Namespace="System.Data.SqlClient" %>

<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();
   AdvHostUserName.Text=AdvUserName;
   readNews();
   readAdvHost();
   Message.Text=GetMessage(" News where NewsType=5 and ToUserName='"+AdvUserName+"' and hits=0 and ToAffairs=2").ToString();
   
 }
 
 
 //读取新闻
 
 protected void readNews()
 {
  strSQL="select top 5 * From News where NewsType=2 order by id desc";
  da = new SqlDataAdapter(strSQL,strConn);
  da.Fill(ds,"News");
  DataGridAdvNews.DataSource=ds;
  DataGridAdvNews.DataBind(); 
  
  }
  
 //读用户资料
 protected void readAdvHost()
 {
  strSQL="select * From AdvHost where UserName='"+AdvUserName+"'";
    SqlConnection cn = new SqlConnection(strConn);
    SqlCommand cmd= new SqlCommand(strSQL,cn);
	cn.Open();
	 SqlDataReader myReader=cmd.ExecuteReader();
	  if (!myReader.Read())
	  {
	   myReader.Close();
	   cn.Close();
	   Response.Redirect("../");   
	  }
	  AdvHostHostMoney.Text=string.Format("{0:c}",myReader["Money"]);
	  AdvName.Text=myReader["Name"].ToString();
	  myReader.Close();
	  cn.Close();
   
  }

 
 protected string FormatChLong(string str,int strlen)
 {
	int l=str.Length;
    int t=0;
	int c=0;
	char temp;  
	for(int i=0;i<=l-1;i++)
	{
	 temp=Convert.ToChar(str.Substring(i,1));
	 
	 c=(int)Convert.ToUInt32(temp);
	 if(c>255)
	  {
	   t=t+2;
	   }else
	   {
	    t++;
	   }
	  if(t==strlen)
	   {
	    return str.Substring(1,i) + "..";
		break;
	   }
	 } 
  //Response.Write(t);
  return str;
}


 //查询用户新短信的条数
 protected int GetMessage(string obj)
  {
	string TempstrSQL;
	TempstrSQL="Select count(*) From "+obj;
	
	  //Response.Write(TempstrSQL);
	  //Response.End();
	  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();
   }


</script>

<table width="220" border="0" cellspacing="0" cellpadding="0" class="table_News">
  <tr>
    <td width="999" height="43" colspan="2"><img src="../images/advinfourmt.gif" width="220" height="50" /></td>
  </tr>
  <tr>
    <td height="79" colspan="2" background="../images/advinfourmt1.gif"><table width="208" border="0" align="center" cellpadding="0" cellspacing="0" class="table_4">
      <tr>
        <td width="208" height="76" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#F5FEFE">
          <tr>
            <td width="35%" height="25" bgcolor="#FFFFFF"><div align="right">用 户 名:</div></td>
            <td width="65%" bgcolor="#FFFFFF">
              <asp:Label ID="AdvHostUserName" runat="server" />            
            </td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF"><div align="right">用户姓名:</div></td>
            <td bgcolor="#FFFFFF">
              <asp:Label ID="AdvName" runat="server" />            
            </td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF"><div align="right">账户余额:</div></td>
            <td bgcolor="#FFFFFF"><asp:Label ID="AdvHostHostMoney" runat="server" /></td>
          </tr>
          <tr>
            <td height="25" colspan="2" bgcolor="#FFFFFF"><div align="center">
			
			<img src="../images/mail.gif" width="14" height="10" /> <a href="sendNews.Aspx">您有 
                <asp:Label ForeColor="#FF0000" ID="Message" runat="server" />
              条新消息 !!</a></div>
			  </td>
            </tr>
          <tr>
            <td height="20" colspan="2" bgcolor="#FFFFFF"><div align="center"> <a href="Exit.aspx"><img src="../images/exit.gif" width="74" height="25" border="0" /></a>&nbsp;&nbsp;<a href="EditInformation.aspx"><img src="../images/Editimfor.gif" width="74" height="25" border="0" /></a></div></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="7" colspan="2"><img src="../images/advinfourmt2.gif" width="220" height="7" /></td>
  </tr>
</table>


<table width="220" border="0" cellspacing="0" cellpadding="0" class="table_News">
      <tr>
        <td width="219"><img src="../images/advNews.gif" width="220" height="50" /></td>
      </tr>
      <tr>
        <td height="66" background="../images/advinfourmt1.gif">
		<table width="208" border="0" align="center" cellpadding="0" cellspacing="0" class="table_4">
          <tr>
            <td width="208" height="76">
			<asp:DataGrid AutoGenerateColumns="false" BorderWidth="0" CellPadding="1" HorizontalAlign="Center" 
			ID="DataGridAdvNews" 
			runat="server" 
			ShowFooter="false" 
			ShowHeader="false" 
			Width="100%" gridline="None">
			
			  <columns>
			  
               <asp:TemplateColumn HeaderText="投放网站" ItemStyle-Width="2" ItemStyle-Height="25"> 
                <itemtemplate>
				 ·
				</itemtemplate>
              </asp:TemplateColumn>
			  		  
               <asp:TemplateColumn HeaderText="标题"> 
                <itemtemplate>
				 <%# FormatChLong(DataBinder.Eval(Container.DataItem,"Title").ToString(),20) %>
				</itemtemplate>
              </asp:TemplateColumn>   
			    
			</columns>
			</asp:DataGrid>
			</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="10" valign="top"><img src="../images/advinfourmt2.gif" width="220" height="7" /></td>
      </tr>
</table>
<table width="220" border="0" cellspacing="0" cellpadding="0" class="table_News">
  <tr>
    <td width="999" height="43" colspan="2"><img src="../images/mess.gif" width="220" height="50" /></td>
  </tr>
  <tr>
    <td height="79" colspan="2" background="../images/advinfourmt1.gif"><table width="208" border="0" align="center" cellpadding="0" cellspacing="0" class="table_4">
      <tr>
        <td width="208" height="76" valign="top"><table width="200" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="32" height="25"><div align="center"><img src="../images/qq_er.gif" width="20" height="20" /></div></td>
            <td width="168">客服一: 160845 </td>
          </tr>
          <tr>
            <td height="25"><div align="center"><img src="../images/qq_er.gif" width="20" height="20" /></div></td>
            <td>客服二: 11752290 </td>
          </tr>
          <tr>
            <td height="25"><div align="center"><img src="../images/qq_er.gif" width="20" height="20" /></div></td>
            <td>客服三: 11752290 </td>
          </tr>
          <tr>
            <td height="25"><div align="center"><img src="../images/msn_er.gif" width="20" height="20" /></div></td>
            <td>Hncj@msn.com</td>
          </tr>
          <tr>
            <td height="25"><div align="center"><img src="../images/tel_er.gif" width="20" height="20" /></div></td>
            <td>027 - 88393260 </td>
          </tr>
          <tr>
            <td height="25" colspan="2"><div align="center">有任任问题可以与我们联系</div></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="7" colspan="2"><img src="../images/advinfourmt2.gif" width="220" height="7" /></td>
  </tr>
</table>
