温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Handson简单新闻系统后台源码
当前文件:
HandsonNews/NewsClassManage/ClassAdd.aspx.cs[3K,2009-6-12 11:43:42],打开代码结构图
HandsonNews/NewsClassManage/ClassAdd.aspx.cs[3K,2009-6-12 11:43:42],打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class NewsClassManage_ClassAdd : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
//第一个文本框获得焦点 18
this.TxtClassName.Focus(); 19
20
} 21
protected void BtnSaveClass_Click(object sender, EventArgs e) 22
{ 23
//记录所影响的行数 24
int reader; 25
//建立连接 26
SqlConnection con = DataAccess.CreateConnection(); 27
//执行数据库insert语句 28
SqlCommand com = new SqlCommand("insert into t_class(classname,itemid,classdesc,classorder) values(@classname,@itemid,@classdesc,@classorder)", con); 29
//将文本框的值传入到数据库t_Class表中 30
com.Parameters.Add("@classname", SqlDbType.VarChar).Value = this.TxtClassName.Text; 31
com.Parameters.Add("@itemid",SqlDbType.VarChar).Value = this.DdlClassItemName.SelectedItem.Value; 32
com.Parameters.Add("@classdesc", SqlDbType.VarChar).Value = this.TxtClassDesc.Text; 33
com.Parameters.Add("@classorder", SqlDbType.VarChar).Value =this.TxtClassOrder.Text; 34
try 35
{ 36
//判断分类名称是否为空,为空给出提示,并把分类名称一栏设为焦点 37
if (this.TxtClassName.Text == "") 38
{ 39
//<script>window.alert</script>给出一个提示对话框 40
Response.Write("<script>window.alert('分类名称不能为空!')</script>"); 41
this.TxtClassName.Focus(); 42
} 43
else 44
{ 45
//判断分类顺序一栏输入的是否是整数 46
int a = int.Parse(this.TxtClassOrder.Text); 47
//打开数据连接 48
con.Open(); 49
//执行命令对象 50
reader = com.ExecuteNonQuery(); 51
//查看所影响行数,如果为零 52
if (reader == 0) 53
{ 54
Response.Write("<script>window.alert('操作失败!')</script>"); 55
} 56
else 57
{ 58
Response.Write("<script>window.alert('操作成功!')</script>"); 59
//把所有文本框置空 60
this.TxtClassName.Text = ""; 61
this.TxtClassDesc.Text = ""; 62
this.TxtClassOrder.Text = ""; 63
} 64
} 65
66
} 67
catch (FormatException) 68
{ 69
//给出提示,分类顺序一栏应输入整数 70
Response.Write("<script>window.alert('分类顺序一栏必须输入整数,请重新输入!')</script>"); 71
//分类顺序一栏获得焦点,同时把文本框的值置为零 72
this.TxtClassOrder.Focus(); 73
this.TxtClassOrder.Text = ""; 74
} 75
finally 76
{ 77
//关闭数据连接 78
con.Close(); 79
} 80
81
82
} 83
} 84






}
}