测试一下吧!

  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>");
}
}

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值