main_msg_add.aspx.cs
上传用户:woolgirl
上传日期:2020-04-18
资源大小:243k
文件大小:7k
源码类别:

SCSI/ASPI

开发平台:

Others

  1. using System;
  2. using System.Data;
  3. using System.Data.OleDb;//ACCESS
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. public partial class main_msg_add : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)//头像列表
  17.         {
  18.             myimg.ImageUrl = "skins/1/face/Image01.gif";
  19.             myimg.AlternateText = "Image01.gif";
  20.             myfaces.Items.Clear();
  21.                    
  22.             OleDbConnection conn = liuyinconn.connstr();
  23.         
  24.             string TableName = "yl_message_face";
  25.         
  26.             string sql = "Select TOP 20 * FROM [" + TableName + "] ORDER BY yl_code ASC , yl_id ASC";
  27.             try
  28.             {
  29.                 conn.Open();//打开数据库链接 ;
  30.             }
  31.             catch
  32.             {
  33.                 Response.Write("参数错误!");
  34.                 Response.End();
  35.             }
  36.             
  37.        
  38.             OleDbCommand cmd = new OleDbCommand(sql, conn);
  39.             OleDbDataReader rs = cmd.ExecuteReader();
  40.             if (rs.HasRows)
  41.             {
  42.                 //myfaces.Items.Add("选择头像");
  43.                 while (rs.Read())
  44.                 {
  45.                     myfaces.Items.Add("" + rs["yl_face"].ToString() + "");
  46.                 }
  47.             }
  48.             rs.Close();  
  49.             conn.Close();
  50.         }
  51.     }
  52.     protected void msg_Click(object sender, EventArgs e)
  53.     //添加留言
  54.     {       
  55.           
  56.         try
  57.         {        
  58.             OleDbConnection conn = liuyinconn.connstr();
  59.             string TableName = "yl_message";
  60.             string sql = "Select * FROM [" + TableName + "]";
  61.             conn.Open();//打开数据库链接 ;
  62.             OleDbDataAdapter CMD = new OleDbDataAdapter(sql, conn);
  63.             OleDbCommandBuilder Mycmd = new OleDbCommandBuilder(CMD);
  64.             DataSet CMDset = new DataSet();
  65.             CMD.Fill(CMDset, "" + TableName + "");
  66.             DataRow rs;
  67.             rs = CMDset.Tables["" + TableName + ""].NewRow();
  68.             string names;
  69.             string title;
  70.             string body;
  71.             string tel;
  72.             string face;
  73.             string ip;
  74.             
  75.             if (Request.ServerVariables["HTTP_VIA"] != null)//穿过代理服务器取远程用户真实IP地址
  76.             {
  77.                 ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
  78.             }
  79.             else
  80.             {
  81.                 ip = Request.ServerVariables["REMOTE_ADDR"].ToString();
  82.             }
  83.             if (this.yl_name.Text.ToString() == "")
  84.             {
  85.                 names = "匿名";
  86.             }
  87.             else
  88.             {
  89.                 names = Server.HtmlEncode(this.yl_name.Text.ToString());
  90.             }
  91.             title = Server.HtmlEncode(this.yl_title.Text.ToString());
  92.             body = Server.HtmlEncode(this.yl_body.Text.ToString());
  93.             tel = Server.HtmlEncode(this.yl_tel.Text.ToString());
  94.             face = Server.HtmlEncode(this.myfaces.Text.ToString());
  95.             rs["yl_title"] = title;
  96.             rs["yl_body"] = body;
  97.             rs["yl_name"] = names;
  98.             rs["yl_tel"] = tel;
  99.             rs["yl_face"] = face;
  100.             rs["yl_ip"] = ip;
  101.             rs["yl_adddate"] = DateTime.Now;
  102.             rs["yl_count"] = 0;
  103.             rs["yl_sh"] = 0;
  104.             CMDset.Tables["" + TableName + ""].Rows.Add(rs);
  105.             CMD.Update(CMDset, "" + TableName + "");
  106.             CMDset.AcceptChanges();
  107.             CMDset.Tables["" + TableName + ""].AcceptChanges();
  108.             Response.Write("<div style="width:778px;">");
  109.             Response.Write("<meta http-equiv=refresh content=3;URL=Default.aspx>");
  110.             Response.Write("<ul>");
  111.             Response.Write("<li>");
  112.             Response.Write("添加成功!");
  113.             Response.Write("</li>");
  114.             Response.Write("<ul>");
  115.             Response.Write("<li>");
  116.             Response.Write("<font color=red><b> 3 </b></font><秒钟后系统将自动返回到首页...");
  117.             Response.Write("</li>");
  118.             Response.Write("</ul>");
  119.             
  120.             Response.Write("<li>");
  121.             Response.Write("<a href=Default.aspx>立即返回首页</a>");
  122.             Response.Write("</li>");
  123.            
  124.             Response.Write("<ul>");
  125.             Response.Write("</div>");
  126.             
  127.             conn.Close();//关闭数据库链接;
  128.            
  129.         }
  130.         catch
  131.       
  132.         {
  133.             Response.Write("参数错误!");
  134.         }
  135.         Response.End();
  136.     }
  137.     protected void my_click(object sender, EventArgs e)
  138.         //头像列表
  139.     {
  140.         OleDbConnection conn = liuyinconn.connstr();
  141.         string TableName = "yl_message_face";
  142.         string sql = "Select TOP 20 * FROM [" + TableName + "] ORDER BY yl_code ASC , yl_id ASC";
  143.         try
  144.         {
  145.             conn.Open();//打开数据库链接 ;
  146.         }
  147.         catch
  148.         {
  149.             Response.Write("参数错误!");
  150.             Response.End();
  151.         }
  152.             
  153.         OleDbCommand cmd = new OleDbCommand(sql, conn);
  154.         OleDbDataReader rs = cmd.ExecuteReader();
  155.         string faceall="";
  156.         if (rs.HasRows)
  157.         {
  158.             while (rs.Read())
  159.             {
  160.                 faceall += """ + rs["yl_url"].ToString() + "/" + rs["yl_face"].ToString() + "",";
  161.             }
  162.         }
  163.         int lens = faceall.Length;
  164.         string facealls = faceall.Substring(0, lens - 1);
  165.        // Response.Write(facealls);
  166.         string[] myarray = { "skins/1/face/Image01.gif","skins/1/face/Image02.gif", "skins/1/face/Image03.gif", "skins/1/face/Image04.gif", "skins/1/face/Image05.gif", "skins/1/face/Image06.gif", "skins/1/face/Image07.gif", "skins/1/face/Image08.gif", "skins/1/face/Image09.gif", "skins/1/face/Image10.gif", "skins/1/face/Image11.gif", "skins/1/face/Image12.gif", "skins/1/face/Image13.gif", "skins/1/face/Image14.gif", "skins/1/face/Image15.gif", "skins/1/face/Image16.gif", "skins/1/face/Image17.gif", "skins/1/face/Image18.gif", "skins/1/face/Image19.gif", "skins/1/face/Image20.gif" };
  167.         myimg.ImageUrl = myarray[myfaces.SelectedIndex];
  168.         myimg.AlternateText = myfaces.SelectedItem.Text;
  169.         rs.Close();
  170.         conn.Close();//关闭数据库链接;
  171.     }
  172.     override protected void OnInit(EventArgs e)
  173.     {
  174.         InitializeComponent();
  175.         base.OnInit(e);
  176.     }
  177.     private void InitializeComponent()
  178.     {
  179.         this.Load += new System.EventHandler(this.Page_Load);
  180.     }   
  181.     //头像列表
  182. }