📄 newsfabu.aspx.cs
字号:
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 newsfabu : System.Web.UI.Page
{
string name; //用户名
int i;
int j; //类别ID
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["news_manageConnectionString"].ConnectionString);
clsMdf cc;
protected void Page_Load(object sender, EventArgs e)
{
this.txtTime.Text = DateTime.Now.ToShortDateString();
this.txtPeople.Text = Session["UserName"].ToString();
cc = new clsMdf();
}
//保存按钮
protected void btnSave_Click(object sender, EventArgs e)
{
name = this.txtPeople.Text;
check2();
check1();
bool b = cc.check(this.txtTitle.Text, j, Convert.ToDateTime(this.txtTime.Text), this.txtWord.Text, this.txtSource.Text, this.txtText.Text, i);
if (b == true)
{
Response.Write("<script language=javascript> window.alert('恭喜你,添加成功!')</script>");
this.txtSource.Text = "";
this.txtTitle.Text = "";
this.txtWord.Text = "";
this.txtText.Text = "";
}
else
{
Response.Write("<script language=javascript> window.alert('抱歉,您添加失败!')</script>");
}
}
//判断用户是否存在
public void check2()
{
string s = "select count(*) from t_news_user where username='" + name + "'";
conn.Open();
SqlCommand comm = new SqlCommand(s, conn);
int j = Convert.ToInt32(comm.ExecuteScalar());
conn.Close();
if (i < 0)
{
Response.Write("<script language=javascript> window.alert('抱歉,没有此用户')</script>");
}
else
{
string str = "select userId from t_news_user where username='" + name + "'";
conn.Open();
SqlCommand com = new SqlCommand(str, conn);
i = Convert.ToInt32(com.ExecuteScalar());
conn.Close();
}
}
//取出类别ID
public void check1()
{
string str1 = "select classid from t_class where classname='" + this.ddlAttribute.Text + "'";
conn.Open();
SqlCommand com = new SqlCommand(str1, conn);
j = Convert.ToInt32(com.ExecuteScalar());
conn.Close();
}
//取消按钮
protected void btnCancel_Click(object sender, EventArgs e)
{
this.txtSource.Text = "";
this.txtText.Text = "";
this.txtTitle.Text = "";
this.txtWord.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -