using System;
using System.Data;
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;
using System.Data.SqlClient;
public partial class log : System.Web.UI.Page
{
string strcnn = "server=;database=space;uid=sa;pwd=sa2005";
//public System.Web.UI.WebControls.Button Tx_sub1;
protected void Page_Load(object sender, EventArgs e)
{
//Tx_Head.Focus();
Tx_sub.Focus();
NowTime.Text =System.DateTime.Now.ToString();
if (Request.Cookies["time"] == null)
{
UpdateTime.Text = DateTime.Now.ToString();
}
else
{
UpdateTime.Text = Request.Cookies["time"].Value;
}
if (Request.Cookies["UrlName"] == null)
{
LogImage.ImageUrl = "~/Space/img1/285ed8fa95c0db45034f56c5.jpg";
}
else
{
LogImage.ImageUrl = Request.Cookies["UrlName"].Value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
//读代码
private void readnewID()
{
SqlConnection con = new SqlConnection(strcnn);
con.Open();
SqlCommand comand = new SqlCommand("select * from Logger where ID in(select max(ID) from Logger)", con);
SqlDataReader read = comand.ExecuteReader();
while (read.Read())
{
Response.Cookies["countID"].Value = read[0].ToString();
}
con.Close();
}
public int insertmessage(int ID, string N_title, string N_content, string N_time, int N_hits, int N_type, int N_limits)
{
SqlConnection con = new SqlConnection(strcnn);
try
{
//System.DateTime mytime = System.DateTime.Now;
con.Open();
SqlCommand command = new SqlCommand("insert into Logger values(@ID,@N_title,@N_content,@N_time,@N_hits,@N_type,@N_limits)", con);
command.Parameters.Add("@ID", System.Data.SqlDbType.Int).Value = ID;
command.Parameters.Add("@N_title", System.Data.SqlDbType.VarChar).Value = N_title;
command.Parameters.Add("@N_content", System.Data.SqlDbType.VarChar).Value = N_content;
command.Parameters.Add("@N_time", System.Data.SqlDbType.VarChar).Value = N_time;
command.Parameters.Add("@N_hits", System.Data.SqlDbType.Int).Value = N_hits;
command.Parameters.Add("@N_type", System.Data.SqlDbType.Int).Value = N_type;
command.Parameters.Add("@N_limits", System.Data.SqlDbType.Int).Value = N_limits;
int cout = command.ExecuteNonQuery();
if(cout>0)
{
Response.Write("<script>alert('日志发表成功!')</script>");
}
return cout;
}
catch (SqlException ex)
{
return -1;
}
finally
{
con.Close();
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
}
protected void Type2_SelectedIndexChanged(object sender, EventArgs e)
{
Tx_sub.Focus();
}
protected void Tx_sub_Click(object sender, EventArgs e)
{
}
protected void Tx_sub_Click1(object sender, EventArgs e)
{
string time = DateTime.Now.ToString();
Response.Cookies["time"].Value = time;
Response.Cookies["time"].Expires = DateTime.Now.AddYears(1);
int x,y,z;
x = 0;
y = 0;
z = 0;
int i=0;
readnewID();
i =int.Parse(Request.Cookies["countID"].Value.ToString())+1;
if (Type2.SelectedIndex == 0)
{
y = 0;
}
if (Type2.SelectedIndex == 1)
{
y = 1;
}
if (Type2.SelectedIndex == 2)
{
y = 2;
}
if (Type2.SelectedIndex == 3)
{
y = 3;
}
if (Limite.SelectedIndex == 0)
{
z = 0;
}
if (Limite.SelectedIndex == 1)
{
z= 1;
}
if (Tx_Head.Text.Trim() == "")
{
Response.Write("<script>alert('你还没有写日志标题呢!')</script>");
//Response.Write("<script>alert('你还没有写日志标题呢!');window.location.href ='log.aspx'</script>");
//Tx_sub.Attributes.Add("onclick", "return confirm('你还没有写日志标题呢!');");
//Response.Redirect("log.aspx");
}
else
{
if (Tx_content.Text.Trim() == "")
{
Response.Write("<script>alert('你还没有写任何日志正文呢!')</script>");
//Response.Write("<script>alert('你还没有写任何日志正文呢!');window.location.href ='log.aspx'</script>");
//Tx_sub.Attributes.Add("onclick", "return confirm('你还没有写任何日志正文呢!');");
}
else
{
insertmessage(i, Tx_Head.Text, Tx_content.Text, time, x, y, z);
Response.Write("<script>alert('日志发表成功!');window.location.href ='Index.aspx'</script>");
}
}
}
}
测试一下吧!
最新推荐文章于 2023-03-05 17:23:04 发布