main_msg_add.aspx.cs
上传用户:woolgirl
上传日期:2020-04-18
资源大小:243k
文件大小:7k
- using System;
- using System.Data;
- using System.Data.OleDb;//ACCESS
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class main_msg_add : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)//头像列表
- {
- myimg.ImageUrl = "skins/1/face/Image01.gif";
- myimg.AlternateText = "Image01.gif";
- myfaces.Items.Clear();
-
- OleDbConnection conn = liuyinconn.connstr();
-
- string TableName = "yl_message_face";
-
- string sql = "Select TOP 20 * FROM [" + TableName + "] ORDER BY yl_code ASC , yl_id ASC";
- try
- {
- conn.Open();//打开数据库链接 ;
- }
- catch
- {
- Response.Write("参数错误!");
- Response.End();
- }
-
-
- OleDbCommand cmd = new OleDbCommand(sql, conn);
- OleDbDataReader rs = cmd.ExecuteReader();
- if (rs.HasRows)
- {
- //myfaces.Items.Add("选择头像");
- while (rs.Read())
- {
- myfaces.Items.Add("" + rs["yl_face"].ToString() + "");
- }
- }
- rs.Close();
- conn.Close();
- }
- }
- protected void msg_Click(object sender, EventArgs e)
- //添加留言
- {
-
- try
- {
- OleDbConnection conn = liuyinconn.connstr();
- string TableName = "yl_message";
- string sql = "Select * FROM [" + TableName + "]";
- conn.Open();//打开数据库链接 ;
- OleDbDataAdapter CMD = new OleDbDataAdapter(sql, conn);
- OleDbCommandBuilder Mycmd = new OleDbCommandBuilder(CMD);
- DataSet CMDset = new DataSet();
- CMD.Fill(CMDset, "" + TableName + "");
- DataRow rs;
- rs = CMDset.Tables["" + TableName + ""].NewRow();
- string names;
- string title;
- string body;
- string tel;
- string face;
- string ip;
-
- if (Request.ServerVariables["HTTP_VIA"] != null)//穿过代理服务器取远程用户真实IP地址
- {
- ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
- }
- else
- {
- ip = Request.ServerVariables["REMOTE_ADDR"].ToString();
- }
- if (this.yl_name.Text.ToString() == "")
- {
- names = "匿名";
- }
- else
- {
- names = Server.HtmlEncode(this.yl_name.Text.ToString());
- }
- title = Server.HtmlEncode(this.yl_title.Text.ToString());
- body = Server.HtmlEncode(this.yl_body.Text.ToString());
- tel = Server.HtmlEncode(this.yl_tel.Text.ToString());
- face = Server.HtmlEncode(this.myfaces.Text.ToString());
- rs["yl_title"] = title;
- rs["yl_body"] = body;
- rs["yl_name"] = names;
- rs["yl_tel"] = tel;
- rs["yl_face"] = face;
- rs["yl_ip"] = ip;
- rs["yl_adddate"] = DateTime.Now;
- rs["yl_count"] = 0;
- rs["yl_sh"] = 0;
- CMDset.Tables["" + TableName + ""].Rows.Add(rs);
- CMD.Update(CMDset, "" + TableName + "");
- CMDset.AcceptChanges();
- CMDset.Tables["" + TableName + ""].AcceptChanges();
- Response.Write("<div style="width:778px;">");
- Response.Write("<meta http-equiv=refresh content=3;URL=Default.aspx>");
- Response.Write("<ul>");
- Response.Write("<li>");
- Response.Write("添加成功!");
- Response.Write("</li>");
- Response.Write("<ul>");
- Response.Write("<li>");
- Response.Write("<font color=red><b> 3 </b></font><秒钟后系统将自动返回到首页...");
- Response.Write("</li>");
- Response.Write("</ul>");
-
- Response.Write("<li>");
- Response.Write("<a href=Default.aspx>立即返回首页</a>");
- Response.Write("</li>");
-
- Response.Write("<ul>");
- Response.Write("</div>");
-
- conn.Close();//关闭数据库链接;
-
- }
- catch
-
- {
- Response.Write("参数错误!");
- }
- Response.End();
- }
- protected void my_click(object sender, EventArgs e)
- //头像列表
- {
- OleDbConnection conn = liuyinconn.connstr();
- string TableName = "yl_message_face";
- string sql = "Select TOP 20 * FROM [" + TableName + "] ORDER BY yl_code ASC , yl_id ASC";
- try
- {
- conn.Open();//打开数据库链接 ;
- }
- catch
- {
- Response.Write("参数错误!");
- Response.End();
- }
-
- OleDbCommand cmd = new OleDbCommand(sql, conn);
- OleDbDataReader rs = cmd.ExecuteReader();
- string faceall="";
- if (rs.HasRows)
- {
- while (rs.Read())
- {
- faceall += """ + rs["yl_url"].ToString() + "/" + rs["yl_face"].ToString() + "",";
- }
- }
- int lens = faceall.Length;
- string facealls = faceall.Substring(0, lens - 1);
- // Response.Write(facealls);
- 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" };
- myimg.ImageUrl = myarray[myfaces.SelectedIndex];
- myimg.AlternateText = myfaces.SelectedItem.Text;
- rs.Close();
- conn.Close();//关闭数据库链接;
- }
- override protected void OnInit(EventArgs e)
- {
- InitializeComponent();
- base.OnInit(e);
- }
- private void InitializeComponent()
- {
- this.Load += new System.EventHandler(this.Page_Load);
- }
- //头像列表
- }