温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:库存管理系统V1.0源码
当前文件:
StoreManage/Editpancun.aspx.cs,打开代码结构图
StoreManage/Editpancun.aspx.cs,打开代码结构图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 Editpancun : System.Web.UI.Page 14
{ 15
16
private readonly string SqlConnectionString = ConfigurationSettings.AppSettings["ConnectionString"].ToString(); 17
private string BID; 18
private int strID 19
{ 20
get 21
{ 22
return Convert.ToInt32(ViewState["_BID"]); 23
} 24
set 25
{ 26
ViewState["_BID"] = Request.QueryString["BID"]; 27
} 28
} 29
protected void Page_Load(object sender, EventArgs e) 30
{ 31
if (!IsPostBack) 32
{ 33
BID = Request["BID"].ToString(); 34
BindData(BID); 35
} 36
} 37
private void BindData(string BID) 38
{ 39
string sqlstr; 40
sqlstr = "select * from pancun where huoID='" + BID + "'"; 41
SqlConnection scon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); 42
SqlCommand scm = new SqlCommand(sqlstr, scon); 43
//打开数据库并执行查询操作 44
scon.Open(); 45
SqlDataReader dr = scm.ExecuteReader(); 46
if (dr.Read()) 47
{ 48
this.TextBox1.Text = dr["huoName"].ToString(); 49
this.TextBox2.Text = dr["bianma"].ToString(); 50
this.TextBox3.Text = dr["huoDanwei"].ToString(); 51
this.TextBox4.Text = dr["pancun"].ToString(); 52
this.DropDownList1.Text = dr["cfck"].ToString(); 53
54
} 55
//关闭数据库的连接 56
dr.Close(); 57
scon.Close(); 58
} 59
private bool kong() 60
{ 61
if (this.TextBox1.Text == "") 62
{ 63
Response.Write("<script language='javascript'>alert('其他不能为空!');</script>"); 64
return false; 65
} 66
else 67
{ 68
if (this.TextBox2.Text == "") 69
{ 70
Response.Write("<script language='javascript'>alert('其他不能为空!');</script>"); 71
return false; 72
} 73
else 74
{ 75
if (this.TextBox3.Text == "") 76
{ 77
Response.Write("<script language='javascript'>alert('其他不能为空!');</script>"); 78
return false; 79
} 80
else 81
{ 82
if (this.TextBox4.Text == "") 83
{ 84
Response.Write("<script language='javascript'>alert('其他不能为空!');</script>"); 85
return false; 86
} 87
else 88
{ 89
return true; 90
} 91
} 92
} 93
} 94
} 95
protected void Button1_Click(object sender, EventArgs e) 96
{ 97
if (kong()) 98
{ 99
//定义变量 100
string bbb = Request.QueryString["BID"]; 101
string aa, bb, cc, dd, ee; 102
aa = this.TextBox1.Text; 103
bb = this.TextBox2.Text; 104
cc = this.TextBox3.Text; 105
dd = this.TextBox4.Text; 106
ee = this.DropDownList1.Text; 107
SqlConnection scon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); 108
scon.Open(); 109
SqlCommand scmd = new SqlCommand("update pancun set huoName='" + aa + "',bianma='" + bb + "',huoDanwei='" + cc + "',cfck='" + ee + "',pancun='" + dd + "' where huoID='" + bbb + "'", scon); 110
scmd.ExecuteNonQuery(); 111
scmd.Dispose(); 112
scon.Close(); 113
Response.Write("<script language='javascript'>alert('更新成功!');</script>"); 114
Server.Transfer("Managepancun.aspx"); 115
} 116
} 117
protected void Button2_Click(object sender, EventArgs e) 118
{ 119
Server.Transfer("Managepancun.aspx"); 120
} 121
} 122
123





}
}